瀏覽代碼

Merge remote-tracking branch 'origin/master' into master

zlisen 4 年之前
父節點
當前提交
addeffbe5e

+ 26
- 8
src/main/java/com/shigongli/controller/TaHouseSurroundController.java 查看文件

5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.shigongli.common.BaseController;
6
 import com.shigongli.common.BaseController;
7
 import com.shigongli.common.ResponseBean;
7
 import com.shigongli.common.ResponseBean;
8
+import com.shigongli.constants.StatusConstant;
9
+import com.shigongli.entity.TaPerson;
10
+import com.shigongli.entity.TaShopKeeper;
11
+import com.shigongli.service.ITaHouseService;
12
+import com.shigongli.service.ITaShopKeeperService;
8
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiOperation;
10
 import io.swagger.annotations.ApiParam;
15
 import io.swagger.annotations.ApiParam;
20
 import com.shigongli.entity.TaHouseSurround;
25
 import com.shigongli.entity.TaHouseSurround;
21
 import org.springframework.web.bind.annotation.RestController;
26
 import org.springframework.web.bind.annotation.RestController;
22
 
27
 
28
+import javax.servlet.http.HttpServletRequest;
23
 import java.util.List;
29
 import java.util.List;
24
 
30
 
25
 /**
31
 /**
41
     @Autowired
47
     @Autowired
42
     public ITaHouseSurroundService iTaHouseSurroundService;
48
     public ITaHouseSurroundService iTaHouseSurroundService;
43
 
49
 
50
+    @Autowired
51
+    ITaHouseService iTaHouseService;
52
+
44
 
53
 
45
     /**
54
     /**
46
      * 分页查询房源周边, 不传房源则代表所有周边
55
      * 分页查询房源周边, 不传房源则代表所有周边
79
      * 根据id删除对象
88
      * 根据id删除对象
80
      * @param id  实体ID
89
      * @param id  实体ID
81
      */
90
      */
82
-    @RequestMapping(value="/taHouseSurround/{id}", method= RequestMethod.DELETE)
91
+    @RequestMapping(value="/ma/taHouseSurround/{id}", method= RequestMethod.DELETE)
83
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
92
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taHouseSurroundDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaHouseSurroundService.removeById(id)){
86
-            return ResponseBean.success("success");
87
-        }else {
88
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
93
+    public ResponseBean taHouseSurroundDelete(@ApiParam("对象ID") @PathVariable String id,
94
+                                              HttpServletRequest request) throws Exception{
95
+        TaPerson taPerson = getPerson(request);
96
+        TaHouseSurround taHouseSurround = iTaHouseSurroundService.getById(id);
97
+        if (null == taHouseSurround || StatusConstant.DELETE.equals(taHouseSurround.getStatus())) {
98
+            return ResponseBean.error("删除数据不存在, 请重试", ResponseBean.ERROR_ILLEGAL_PARAMS);
89
         }
99
         }
100
+
101
+        if (!iTaHouseService.isOwner(taPerson.getPersonId(), taHouseSurround.getHouseId())) {
102
+            return ResponseBean.error("您无权进行当前操作", ResponseBean.ERROR_ILLEGAL_PARAMS);
103
+        }
104
+
105
+        taHouseSurround.setStatus(StatusConstant.DELETE);
106
+
107
+        return taHouseSurroundUpdate(id, taHouseSurround);
90
     }
108
     }
91
 
109
 
92
     /**
110
     /**
97
      */
115
      */
98
     @RequestMapping(value="/taHouseSurround/{id}",method= RequestMethod.PUT)
116
     @RequestMapping(value="/taHouseSurround/{id}",method= RequestMethod.PUT)
99
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
117
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taHouseSurroundUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaHouseSurround taHouseSurround) throws Exception{
118
+    public ResponseBean taHouseSurroundUpdate(@ApiParam("对象ID") @PathVariable String id,
119
+                                              @ApiParam("更新内容") @RequestBody TaHouseSurround taHouseSurround) throws Exception{
102
 
120
 
103
         if (iTaHouseSurroundService.updateById(taHouseSurround)){
121
         if (iTaHouseSurroundService.updateById(taHouseSurround)){
104
             return ResponseBean.success(iTaHouseSurroundService.getById(id));
122
             return ResponseBean.success(iTaHouseSurroundService.getById(id));

+ 2
- 0
src/main/java/com/shigongli/service/ITaHouseService.java 查看文件

16
 public interface ITaHouseService extends IService<TaHouse> {
16
 public interface ITaHouseService extends IService<TaHouse> {
17
 
17
 
18
     IPage<TaHouse> getHousesOfKeeper(IPage<TaHouse> pg, TaPerson taPerson);
18
     IPage<TaHouse> getHousesOfKeeper(IPage<TaHouse> pg, TaPerson taPerson);
19
+
20
+    boolean isOwner(String personId, String houseId);
19
 }
21
 }

+ 35
- 0
src/main/java/com/shigongli/service/impl/TaHouseServiceImpl.java 查看文件

1
 package com.shigongli.service.impl;
1
 package com.shigongli.service.impl;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.shigongli.common.StringUtils;
6
+import com.shigongli.constants.StatusConstant;
4
 import com.shigongli.entity.TaHouse;
7
 import com.shigongli.entity.TaHouse;
5
 import com.shigongli.entity.TaPerson;
8
 import com.shigongli.entity.TaPerson;
9
+import com.shigongli.entity.TaShopKeeper;
6
 import com.shigongli.mapper.TaHouseMapper;
10
 import com.shigongli.mapper.TaHouseMapper;
7
 import com.shigongli.service.ITaHouseService;
11
 import com.shigongli.service.ITaHouseService;
8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13
+import com.shigongli.service.ITaShopKeeperService;
9
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.stereotype.Service;
15
 import org.springframework.stereotype.Service;
11
 
16
 
17
+import java.util.ArrayList;
18
+import java.util.List;
19
+
12
 /**
20
 /**
13
  * <p>
21
  * <p>
14
  * 房源 服务实现类
22
  * 房源 服务实现类
23
     @Autowired
31
     @Autowired
24
     TaHouseMapper taHouseMapper;
32
     TaHouseMapper taHouseMapper;
25
 
33
 
34
+    @Autowired
35
+    ITaShopKeeperService iTaShopKeeperService;
36
+
26
     @Override
37
     @Override
27
     public IPage<TaHouse> getHousesOfKeeper(IPage<TaHouse> pg, TaPerson taPerson) {
38
     public IPage<TaHouse> getHousesOfKeeper(IPage<TaHouse> pg, TaPerson taPerson) {
28
 
39
 
29
         return taHouseMapper.getHousesOfKeeper(pg, taPerson.getPersonId());
40
         return taHouseMapper.getHousesOfKeeper(pg, taPerson.getPersonId());
30
     }
41
     }
42
+
43
+    @Override
44
+    public boolean isOwner(String personId, String houseId) {
45
+        if (StringUtils.isEmpty(personId) || StringUtils.isEmpty(houseId)) {
46
+            return false;
47
+        }
48
+
49
+        List<TaShopKeeper> keeperList = iTaShopKeeperService.getByPerson(personId);
50
+        if (null == keeperList || keeperList.size() < 1) {
51
+            return false;
52
+        }
53
+
54
+        List<String> shopIdList = new ArrayList<>();
55
+        for (TaShopKeeper keeper: keeperList) {
56
+            shopIdList.add(keeper.getShopId());
57
+        }
58
+
59
+        QueryWrapper<TaHouse> queryWrapper = new QueryWrapper<TaHouse>()
60
+                .eq("house_id", houseId)
61
+                .in("shop_id", shopIdList)
62
+                .eq("status", StatusConstant.NORMAL);
63
+
64
+        return count(queryWrapper) > 0;
65
+    }
31
 }
66
 }

+ 1
- 1
src/main/resources/mapper/TaHouseSurroundMapper.xml 查看文件

15
             AND t.house_id = #{houseId}
15
             AND t.house_id = #{houseId}
16
         </if>
16
         </if>
17
         ORDER BY
17
         ORDER BY
18
-            t.create_date DESC;
18
+            t.create_date DESC
19
     </select>
19
     </select>
20
 </mapper>
20
 </mapper>