|
@@ -1,15 +1,23 @@
|
1
|
1
|
package com.yunzhi.marketing.xlk.controller;
|
2
|
2
|
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
3
|
4
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
5
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
6
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
7
|
import com.yunzhi.marketing.base.BaseController;
|
7
|
8
|
import com.yunzhi.marketing.base.ResponseBean;
|
|
9
|
+import com.yunzhi.marketing.entity.TaBuilding;
|
|
10
|
+import com.yunzhi.marketing.service.ITaBuildingService;
|
|
11
|
+import com.yunzhi.marketing.xlk.dto.BrandDTO;
|
|
12
|
+import io.swagger.annotations.Api;
|
|
13
|
+import io.swagger.annotations.ApiOperation;
|
8
|
14
|
import org.slf4j.Logger;
|
9
|
15
|
import org.slf4j.LoggerFactory;
|
|
16
|
+import org.springframework.beans.BeanUtils;
|
10
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
18
|
import org.springframework.web.bind.annotation.PathVariable;
|
12
|
19
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
20
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
13
|
21
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
22
|
import org.springframework.web.bind.annotation.RequestMethod;
|
15
|
23
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -18,6 +26,10 @@ import com.yunzhi.marketing.xlk.service.IBrandService;
|
18
|
26
|
import com.yunzhi.marketing.xlk.entity.Brand;
|
19
|
27
|
import org.springframework.web.bind.annotation.RestController;
|
20
|
28
|
|
|
29
|
+import javax.servlet.http.HttpServletRequest;
|
|
30
|
+import java.time.LocalDateTime;
|
|
31
|
+import java.util.List;
|
|
32
|
+
|
21
|
33
|
/**
|
22
|
34
|
* <p>
|
23
|
35
|
* 品牌开发商表 前端控制器
|
|
@@ -27,7 +39,8 @@ import org.springframework.web.bind.annotation.RestController;
|
27
|
39
|
* @since 2021-05-13
|
28
|
40
|
*/
|
29
|
41
|
@RestController
|
30
|
|
-@RequestMapping("/")
|
|
42
|
+@RequestMapping("/api")
|
|
43
|
+@Api(value = "品牌开发商表", tags = "xlk-品牌开发商表")
|
31
|
44
|
public class BrandController extends BaseController {
|
32
|
45
|
|
33
|
46
|
private final Logger logger = LoggerFactory.getLogger(BrandController.class);
|
|
@@ -35,6 +48,9 @@ public class BrandController extends BaseController {
|
35
|
48
|
@Autowired
|
36
|
49
|
public IBrandService iBrandService;
|
37
|
50
|
|
|
51
|
+ @Autowired
|
|
52
|
+ private ITaBuildingService taBuildingService;
|
|
53
|
+
|
38
|
54
|
|
39
|
55
|
/**
|
40
|
56
|
* 分页查询列表
|
|
@@ -42,15 +58,17 @@ public class BrandController extends BaseController {
|
42
|
58
|
* @param pageSize
|
43
|
59
|
* @return
|
44
|
60
|
*/
|
45
|
|
- @RequestMapping(value="/brand",method= RequestMethod.GET)
|
|
61
|
+ @ApiOperation(value = "品牌开发商表列表", notes = "品牌开发商表列表")
|
|
62
|
+ @RequestMapping(value="/admin/brand",method= RequestMethod.GET)
|
46
|
63
|
public ResponseBean brandList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
47
|
|
- @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
|
|
64
|
+ @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize, @RequestHeader("authorization") String token,HttpServletRequest request){
|
48
|
65
|
ResponseBean responseBean = new ResponseBean();
|
49
|
66
|
try {
|
50
|
67
|
//使用分页插件
|
51
|
68
|
IPage<Brand> pg = new Page<>(pageNum, pageSize);
|
52
|
|
- QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
|
53
|
|
- queryWrapper.orderByDesc("create_date");
|
|
69
|
+ LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
|
|
70
|
+ queryWrapper.eq(Brand::getOrgId,getOrgId(request));
|
|
71
|
+ queryWrapper.orderByDesc(Brand::getCreatedTime);
|
54
|
72
|
|
55
|
73
|
IPage<Brand> result = iBrandService.page(pg, queryWrapper);
|
56
|
74
|
responseBean.addSuccess(result);
|
|
@@ -64,13 +82,19 @@ public class BrandController extends BaseController {
|
64
|
82
|
|
65
|
83
|
/**
|
66
|
84
|
* 保存对象
|
67
|
|
- * @param brand 实体对象
|
|
85
|
+ * @param brandDTO 实体对象
|
68
|
86
|
* @return
|
69
|
87
|
*/
|
70
|
|
- @RequestMapping(value="/brand",method= RequestMethod.POST)
|
71
|
|
- public ResponseBean brandAdd(@RequestBody Brand brand){
|
|
88
|
+ @ApiOperation(value = "添加品牌开发商表", notes = "添加品牌开发商表")
|
|
89
|
+ @RequestMapping(value="/admin/brand",method= RequestMethod.POST)
|
|
90
|
+ public ResponseBean brandAdd(@RequestBody BrandDTO brandDTO, @RequestHeader("authorization") String token, HttpServletRequest request){
|
72
|
91
|
ResponseBean responseBean = new ResponseBean();
|
73
|
92
|
try {
|
|
93
|
+ Brand brand = new Brand();
|
|
94
|
+ BeanUtils.copyProperties(brandDTO,brand);
|
|
95
|
+ brand.setCreatedTime(LocalDateTime.now());
|
|
96
|
+ brand.setCreatedBy(getUserId(request));
|
|
97
|
+ brand.setOrgId(getOrgId(request));
|
74
|
98
|
if (iBrandService.save(brand)){
|
75
|
99
|
responseBean.addSuccess(brand);
|
76
|
100
|
}else {
|
|
@@ -88,12 +112,21 @@ public class BrandController extends BaseController {
|
88
|
112
|
* 根据id删除对象
|
89
|
113
|
* @param id 实体ID
|
90
|
114
|
*/
|
91
|
|
- @ResponseBody
|
92
|
|
- @RequestMapping(value="/brand/{id}", method= RequestMethod.DELETE)
|
93
|
|
- public ResponseBean brandDelete(@PathVariable Integer id){
|
|
115
|
+ @ApiOperation(value = "删除品牌开发商表", notes = "删除品牌开发商表")
|
|
116
|
+ @RequestMapping(value="/admin/brand/{id}", method= RequestMethod.DELETE)
|
|
117
|
+ public ResponseBean brandDelete(@PathVariable String id, @RequestHeader("authorization") String token){
|
94
|
118
|
ResponseBean responseBean = new ResponseBean();
|
95
|
119
|
try {
|
96
|
120
|
if(iBrandService.removeById(id)){
|
|
121
|
+ // 同时更新项目里面的品牌商id和name为空
|
|
122
|
+ LambdaQueryWrapper<TaBuilding> queryWrapper = new LambdaQueryWrapper<>();
|
|
123
|
+ queryWrapper.eq(TaBuilding::getBrandId,id);
|
|
124
|
+ List<TaBuilding> list = taBuildingService.list(queryWrapper);
|
|
125
|
+ list.forEach(e -> {
|
|
126
|
+ e.setBrandId(null);
|
|
127
|
+ e.setBrandName(null);
|
|
128
|
+ taBuildingService.updateById(e);
|
|
129
|
+ });
|
97
|
130
|
responseBean.addSuccess("success");
|
98
|
131
|
}else {
|
99
|
132
|
responseBean.addError("fail");
|
|
@@ -108,16 +141,28 @@ public class BrandController extends BaseController {
|
108
|
141
|
|
109
|
142
|
/**
|
110
|
143
|
* 修改对象
|
111
|
|
- * @param id 实体ID
|
112
|
|
- * @param brand 实体对象
|
|
144
|
+ * @param brandDTO 实体对象
|
113
|
145
|
* @return
|
114
|
146
|
*/
|
115
|
|
- @RequestMapping(value="/brand/{id}",method= RequestMethod.PUT)
|
116
|
|
- public ResponseBean brandUpdate(@PathVariable Integer id,
|
117
|
|
- @RequestBody Brand brand){
|
|
147
|
+ @ApiOperation(value = "修改品牌开发商表", notes = "修改品牌开发商表")
|
|
148
|
+ @RequestMapping(value="/admin/brand/{id}",method= RequestMethod.PUT)
|
|
149
|
+ public ResponseBean brandUpdate(@PathVariable("id") String id,@RequestBody BrandDTO brandDTO,@RequestHeader("authorization") String token,HttpServletRequest request){
|
118
|
150
|
ResponseBean responseBean = new ResponseBean();
|
119
|
151
|
try {
|
|
152
|
+ Brand brand = new Brand();
|
|
153
|
+ BeanUtils.copyProperties(brandDTO,brand);
|
|
154
|
+ brand.setBrandId(id);
|
|
155
|
+ brand.setUpdatedBy(getUserId(request));
|
|
156
|
+ brand.setUpdatedTime(LocalDateTime.now());
|
120
|
157
|
if (iBrandService.updateById(brand)){
|
|
158
|
+ // 同时更新项目里面的品牌商id和name为更新后的名称
|
|
159
|
+ LambdaQueryWrapper<TaBuilding> queryWrapper = new LambdaQueryWrapper<>();
|
|
160
|
+ queryWrapper.eq(TaBuilding::getBrandId,brand.getBrandId());
|
|
161
|
+ List<TaBuilding> list = taBuildingService.list(queryWrapper);
|
|
162
|
+ list.forEach(e -> {
|
|
163
|
+ e.setBrandName(brand.getBrandName());
|
|
164
|
+ taBuildingService.updateById(e);
|
|
165
|
+ });
|
121
|
166
|
responseBean.addSuccess(brand);
|
122
|
167
|
}else {
|
123
|
168
|
responseBean.addError("fail");
|
|
@@ -134,8 +179,9 @@ public class BrandController extends BaseController {
|
134
|
179
|
* 根据id查询对象
|
135
|
180
|
* @param id 实体ID
|
136
|
181
|
*/
|
137
|
|
- @RequestMapping(value="/brand/{id}",method= RequestMethod.GET)
|
138
|
|
- public ResponseBean brandGet(@PathVariable Integer id){
|
|
182
|
+ @ApiOperation(value = "获取品牌开发商表详情数据", notes = "获取品牌开发商表详情数据")
|
|
183
|
+ @RequestMapping(value="/admin/brand/{id}",method= RequestMethod.GET)
|
|
184
|
+ public ResponseBean brandGet(@PathVariable String id, @RequestHeader("authorization") String token){
|
139
|
185
|
ResponseBean responseBean = new ResponseBean();
|
140
|
186
|
try {
|
141
|
187
|
responseBean.addSuccess(iBrandService.getById(id));
|