Your Name 4 anni fa
parent
commit
655ab0d24b

+ 26
- 8
src/main/java/com/shigongli/controller/TaHouseSurroundController.java Vedi File

@@ -5,6 +5,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.shigongli.common.BaseController;
7 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 13
 import io.swagger.annotations.Api;
9 14
 import io.swagger.annotations.ApiOperation;
10 15
 import io.swagger.annotations.ApiParam;
@@ -20,6 +25,7 @@ import com.shigongli.service.ITaHouseSurroundService;
20 25
 import com.shigongli.entity.TaHouseSurround;
21 26
 import org.springframework.web.bind.annotation.RestController;
22 27
 
28
+import javax.servlet.http.HttpServletRequest;
23 29
 import java.util.List;
24 30
 
25 31
 /**
@@ -41,6 +47,9 @@ public class TaHouseSurroundController extends BaseController {
41 47
     @Autowired
42 48
     public ITaHouseSurroundService iTaHouseSurroundService;
43 49
 
50
+    @Autowired
51
+    ITaHouseService iTaHouseService;
52
+
44 53
 
45 54
     /**
46 55
      * 分页查询房源周边, 不传房源则代表所有周边
@@ -79,14 +88,23 @@ public class TaHouseSurroundController extends BaseController {
79 88
      * 根据id删除对象
80 89
      * @param id  实体ID
81 90
      */
82
-    @RequestMapping(value="/taHouseSurround/{id}", method= RequestMethod.DELETE)
91
+    @RequestMapping(value="/ma/taHouseSurround/{id}", method= RequestMethod.DELETE)
83 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,8 +115,8 @@ public class TaHouseSurroundController extends BaseController {
97 115
      */
98 116
     @RequestMapping(value="/taHouseSurround/{id}",method= RequestMethod.PUT)
99 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 121
         if (iTaHouseSurroundService.updateById(taHouseSurround)){
104 122
             return ResponseBean.success(iTaHouseSurroundService.getById(id));

+ 2
- 0
src/main/java/com/shigongli/service/ITaHouseService.java Vedi File

@@ -16,4 +16,6 @@ import com.shigongli.entity.TaPerson;
16 16
 public interface ITaHouseService extends IService<TaHouse> {
17 17
 
18 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 Vedi File

@@ -1,14 +1,22 @@
1 1
 package com.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.shigongli.common.StringUtils;
6
+import com.shigongli.constants.StatusConstant;
4 7
 import com.shigongli.entity.TaHouse;
5 8
 import com.shigongli.entity.TaPerson;
9
+import com.shigongli.entity.TaShopKeeper;
6 10
 import com.shigongli.mapper.TaHouseMapper;
7 11
 import com.shigongli.service.ITaHouseService;
8 12
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13
+import com.shigongli.service.ITaShopKeeperService;
9 14
 import org.springframework.beans.factory.annotation.Autowired;
10 15
 import org.springframework.stereotype.Service;
11 16
 
17
+import java.util.ArrayList;
18
+import java.util.List;
19
+
12 20
 /**
13 21
  * <p>
14 22
  * 房源 服务实现类
@@ -23,9 +31,36 @@ public class TaHouseServiceImpl extends ServiceImpl<TaHouseMapper, TaHouse> impl
23 31
     @Autowired
24 32
     TaHouseMapper taHouseMapper;
25 33
 
34
+    @Autowired
35
+    ITaShopKeeperService iTaShopKeeperService;
36
+
26 37
     @Override
27 38
     public IPage<TaHouse> getHousesOfKeeper(IPage<TaHouse> pg, TaPerson taPerson) {
28 39
 
29 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 Vedi File

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