|
@@ -0,0 +1,161 @@
|
|
1
|
+package com.yunzhi.marketing.xlk.controller;
|
|
2
|
+
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
5
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
6
|
+import com.yunzhi.marketing.base.BaseController;
|
|
7
|
+import com.yunzhi.marketing.base.ResponseBean;
|
|
8
|
+import com.yunzhi.marketing.xlk.entity.SearchHouse;
|
|
9
|
+import com.yunzhi.marketing.xlk.service.ISearchHouseService;
|
|
10
|
+import io.swagger.annotations.Api;
|
|
11
|
+import io.swagger.annotations.ApiOperation;
|
|
12
|
+import org.slf4j.Logger;
|
|
13
|
+import org.slf4j.LoggerFactory;
|
|
14
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
15
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
16
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
17
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
18
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
19
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
20
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
21
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
22
|
+import org.springframework.web.bind.annotation.RestController;
|
|
23
|
+
|
|
24
|
+import javax.servlet.http.HttpServletRequest;
|
|
25
|
+
|
|
26
|
+/**
|
|
27
|
+ * <p>
|
|
28
|
+ * 帮我找房 前端控制器
|
|
29
|
+ * </p>
|
|
30
|
+ *
|
|
31
|
+ * @author jobob
|
|
32
|
+ * @since 2021-05-19
|
|
33
|
+ */
|
|
34
|
+@RestController
|
|
35
|
+@RequestMapping("/api")
|
|
36
|
+@Api(value = "帮我找房", tags = "xlk-帮我找房")
|
|
37
|
+public class SearchHouseController extends BaseController {
|
|
38
|
+
|
|
39
|
+ private final Logger logger = LoggerFactory.getLogger(SearchHouseController.class);
|
|
40
|
+
|
|
41
|
+ @Autowired
|
|
42
|
+ public ISearchHouseService iSearchHouseService;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+ /**
|
|
46
|
+ * 分页查询列表
|
|
47
|
+ * @param pageNum
|
|
48
|
+ * @param pageSize
|
|
49
|
+ * @return
|
|
50
|
+ */
|
|
51
|
+ @ApiOperation(value = "获取帮我找房列表", notes = "获取帮我找房列表")
|
|
52
|
+ @RequestMapping(value="/searchHouse",method= RequestMethod.GET)
|
|
53
|
+ public ResponseBean searchHouseList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
|
54
|
+ @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
|
|
55
|
+ @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
56
|
+ ResponseBean responseBean = new ResponseBean();
|
|
57
|
+ try {
|
|
58
|
+ //使用分页插件
|
|
59
|
+ IPage<SearchHouse> pg = new Page<>(pageNum, pageSize);
|
|
60
|
+ LambdaQueryWrapper<SearchHouse> queryWrapper = new LambdaQueryWrapper<>();
|
|
61
|
+ queryWrapper.orderByDesc(SearchHouse::getCreatedTime);
|
|
62
|
+
|
|
63
|
+ IPage<SearchHouse> result = iSearchHouseService.page(pg, queryWrapper);
|
|
64
|
+ responseBean.addSuccess(result);
|
|
65
|
+ }catch (Exception e){
|
|
66
|
+ e.printStackTrace();
|
|
67
|
+ logger.error("searchHouseList -=- {}",e.toString());
|
|
68
|
+ responseBean.addError(e.getMessage());
|
|
69
|
+ }
|
|
70
|
+ return responseBean;
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ /**
|
|
74
|
+ * 保存对象
|
|
75
|
+ * @param searchHouse 实体对象
|
|
76
|
+ * @return
|
|
77
|
+ */
|
|
78
|
+ @ApiOperation(value = "保存帮我找房需求", notes = "保存帮我找房需求")
|
|
79
|
+ @RequestMapping(value="/searchHouse",method= RequestMethod.POST)
|
|
80
|
+ public ResponseBean searchHouseAdd(@RequestBody SearchHouse searchHouse, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
81
|
+ ResponseBean responseBean = new ResponseBean();
|
|
82
|
+ try {
|
|
83
|
+ if (iSearchHouseService.save(searchHouse)){
|
|
84
|
+ responseBean.addSuccess(searchHouse);
|
|
85
|
+ }else {
|
|
86
|
+ responseBean.addError("fail");
|
|
87
|
+ }
|
|
88
|
+ }catch (Exception e){
|
|
89
|
+ e.printStackTrace();
|
|
90
|
+ logger.error("searchHouseAdd -=- {}",e.toString());
|
|
91
|
+ responseBean.addError(e.getMessage());
|
|
92
|
+ }
|
|
93
|
+ return responseBean;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ /**
|
|
97
|
+ * 根据id删除对象
|
|
98
|
+ * @param id 实体ID
|
|
99
|
+ */
|
|
100
|
+ @ApiOperation(value = "根据id删除帮我找房需求", notes = "根据id删除帮我找房需求")
|
|
101
|
+ @ResponseBody
|
|
102
|
+ @RequestMapping(value="/searchHouse/{id}", method= RequestMethod.DELETE)
|
|
103
|
+ public ResponseBean searchHouseDelete(@PathVariable Integer id, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
104
|
+ ResponseBean responseBean = new ResponseBean();
|
|
105
|
+ try {
|
|
106
|
+ if(iSearchHouseService.removeById(id)){
|
|
107
|
+ responseBean.addSuccess("success");
|
|
108
|
+ }else {
|
|
109
|
+ responseBean.addError("fail");
|
|
110
|
+ }
|
|
111
|
+ }catch (Exception e){
|
|
112
|
+ e.printStackTrace();
|
|
113
|
+ logger.error("searchHouseDelete -=- {}",e.toString());
|
|
114
|
+ responseBean.addError(e.getMessage());
|
|
115
|
+ }
|
|
116
|
+ return responseBean;
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ /**
|
|
120
|
+ * 修改对象
|
|
121
|
+ * @param id 实体ID
|
|
122
|
+ * @param searchHouse 实体对象
|
|
123
|
+ * @return
|
|
124
|
+ */
|
|
125
|
+ @ApiOperation(value = "修改帮我找房需求", notes = "修改帮我找房需求")
|
|
126
|
+ @RequestMapping(value="/searchHouse/{id}",method= RequestMethod.PUT)
|
|
127
|
+ public ResponseBean searchHouseUpdate(@PathVariable Integer id,
|
|
128
|
+ @RequestBody SearchHouse searchHouse, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
129
|
+ ResponseBean responseBean = new ResponseBean();
|
|
130
|
+ try {
|
|
131
|
+ if (iSearchHouseService.updateById(searchHouse)){
|
|
132
|
+ responseBean.addSuccess(searchHouse);
|
|
133
|
+ }else {
|
|
134
|
+ responseBean.addError("fail");
|
|
135
|
+ }
|
|
136
|
+ }catch (Exception e){
|
|
137
|
+ e.printStackTrace();
|
|
138
|
+ logger.error("searchHouseUpdate -=- {}",e.toString());
|
|
139
|
+ responseBean.addError(e.getMessage());
|
|
140
|
+ }
|
|
141
|
+ return responseBean;
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ /**
|
|
145
|
+ * 根据id查询对象
|
|
146
|
+ * @param id 实体ID
|
|
147
|
+ */
|
|
148
|
+ @ApiOperation(value = "根据id查询帮我找房需求详情", notes = "根据id查询帮我找房需求详情")
|
|
149
|
+ @RequestMapping(value="/searchHouse/{id}",method= RequestMethod.GET)
|
|
150
|
+ public ResponseBean searchHouseGet(@PathVariable Integer id, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
151
|
+ ResponseBean responseBean = new ResponseBean();
|
|
152
|
+ try {
|
|
153
|
+ responseBean.addSuccess(iSearchHouseService.getById(id));
|
|
154
|
+ }catch (Exception e){
|
|
155
|
+ e.printStackTrace();
|
|
156
|
+ logger.error("searchHouseDelete -=- {}",e.toString());
|
|
157
|
+ responseBean.addError(e.getMessage());
|
|
158
|
+ }
|
|
159
|
+ return responseBean;
|
|
160
|
+ }
|
|
161
|
+}
|