|
@@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.huiju.estateagents.base.ResponseBean;
|
|
7
|
+import com.huiju.estateagents.common.CommConstant;
|
|
8
|
+import com.huiju.estateagents.common.JWTUtils;
|
7
|
9
|
import com.huiju.estateagents.entity.TaPolicy;
|
|
10
|
+import com.huiju.estateagents.entity.TdCity;
|
8
|
11
|
import com.huiju.estateagents.service.ITaPolicyService;
|
|
12
|
+import com.huiju.estateagents.service.ITdCityService;
|
9
|
13
|
import org.slf4j.Logger;
|
10
|
14
|
import org.slf4j.LoggerFactory;
|
11
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -18,6 +22,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
18
|
22
|
import org.springframework.web.bind.annotation.RestController;
|
19
|
23
|
import com.huiju.estateagents.base.BaseController;
|
20
|
24
|
|
|
25
|
+import javax.servlet.http.HttpServletRequest;
|
|
26
|
+import java.time.LocalDateTime;
|
|
27
|
+
|
21
|
28
|
/**
|
22
|
29
|
* <p>
|
23
|
30
|
* 购房政策表 前端控制器
|
|
@@ -35,6 +42,9 @@ public class TaPolicyController extends BaseController {
|
35
|
42
|
@Autowired
|
36
|
43
|
public ITaPolicyService iTaPolicyService;
|
37
|
44
|
|
|
45
|
+ @Autowired
|
|
46
|
+ private ITdCityService iTdCityService;
|
|
47
|
+
|
38
|
48
|
|
39
|
49
|
/**
|
40
|
50
|
* 分页查询列表
|
|
@@ -52,7 +62,8 @@ public class TaPolicyController extends BaseController {
|
52
|
62
|
IPage<TaPolicy> pg = new Page<>(pageNum, pageSize);
|
53
|
63
|
QueryWrapper<TaPolicy> queryWrapper = new QueryWrapper<>();
|
54
|
64
|
queryWrapper.eq(null != cityId,"city_id",cityId);
|
55
|
|
- queryWrapper.orderByDesc("create_date");
|
|
65
|
+ queryWrapper.orderByDesc("weight", "create_date");
|
|
66
|
+ queryWrapper.eq("status", 1);
|
56
|
67
|
|
57
|
68
|
IPage<TaPolicy> result = iTaPolicyService.page(pg, queryWrapper);
|
58
|
69
|
responseBean.addSuccess(result);
|
|
@@ -96,9 +107,21 @@ public class TaPolicyController extends BaseController {
|
96
|
107
|
* @return
|
97
|
108
|
*/
|
98
|
109
|
@RequestMapping(value="/admin/taPolicy",method= RequestMethod.POST)
|
99
|
|
- public ResponseBean taPolicyAdd(@RequestBody TaPolicy taPolicy){
|
|
110
|
+ public ResponseBean taPolicyAdd(@RequestBody TaPolicy taPolicy, HttpServletRequest request){
|
100
|
111
|
ResponseBean responseBean = new ResponseBean();
|
101
|
112
|
try {
|
|
113
|
+
|
|
114
|
+ if(taPolicy.getPublishStatus().equals(CommConstant.IS_PUBLISH)){
|
|
115
|
+ taPolicy.setPublishDate(LocalDateTime.now());
|
|
116
|
+ String personId = JWTUtils.getSubject(request);
|
|
117
|
+ taPolicy.setPublishUser(personId);
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ TdCity tdCity = iTdCityService.getById(taPolicy.getCityId());
|
|
121
|
+ taPolicy.setCityName(tdCity.getName());
|
|
122
|
+
|
|
123
|
+ taPolicy.setStatus(1);
|
|
124
|
+ taPolicy.setCreateDate(LocalDateTime.now());
|
102
|
125
|
if (iTaPolicyService.save(taPolicy)){
|
103
|
126
|
responseBean.addSuccess(taPolicy);
|
104
|
127
|
}else {
|
|
@@ -120,7 +143,9 @@ public class TaPolicyController extends BaseController {
|
120
|
143
|
public ResponseBean taPolicyDelete(@PathVariable Integer id){
|
121
|
144
|
ResponseBean responseBean = new ResponseBean();
|
122
|
145
|
try {
|
123
|
|
- if(iTaPolicyService.removeById(id)){
|
|
146
|
+ TaPolicy policy=iTaPolicyService.getById(id);
|
|
147
|
+ policy.setStatus(CommConstant.STATUS_DELETE);
|
|
148
|
+ if(iTaPolicyService.updateById(policy)){
|
124
|
149
|
responseBean.addSuccess("success");
|
125
|
150
|
}else {
|
126
|
151
|
responseBean.addError("fail");
|
|
@@ -140,9 +165,20 @@ public class TaPolicyController extends BaseController {
|
140
|
165
|
*/
|
141
|
166
|
@RequestMapping(value="/admin/taPolicy/{id}",method= RequestMethod.PUT)
|
142
|
167
|
public ResponseBean taPolicyUpdate(@PathVariable Integer id,
|
143
|
|
- @RequestBody TaPolicy taPolicy){
|
|
168
|
+ @RequestBody TaPolicy taPolicy,
|
|
169
|
+ HttpServletRequest request){
|
144
|
170
|
ResponseBean responseBean = new ResponseBean();
|
145
|
171
|
try {
|
|
172
|
+
|
|
173
|
+ if(taPolicy.getPublishStatus().equals(CommConstant.IS_PUBLISH)){
|
|
174
|
+ taPolicy.setPublishDate(LocalDateTime.now());
|
|
175
|
+ String personId = JWTUtils.getSubject(request);
|
|
176
|
+ taPolicy.setPublishUser(personId);
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ TdCity tdCity = iTdCityService.getById(taPolicy.getCityId());
|
|
180
|
+ taPolicy.setCityName(tdCity.getName());
|
|
181
|
+
|
146
|
182
|
if (iTaPolicyService.updateById(taPolicy)){
|
147
|
183
|
responseBean.addSuccess(taPolicy);
|
148
|
184
|
}else {
|