瀏覽代碼

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

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

+ 11
- 0
src/main/java/com/shigongli/controller/LoginController.java 查看文件

@@ -6,8 +6,10 @@ import com.shigongli.common.*;
6 6
 import com.shigongli.constants.StatusConstant;
7 7
 import com.shigongli.entity.SysUser;
8 8
 import com.shigongli.entity.TaPerson;
9
+import com.shigongli.entity.TaShopKeeper;
9 10
 import com.shigongli.service.ISysUserService;
10 11
 import com.shigongli.service.ITaPersonService;
12
+import com.shigongli.service.ITaShopKeeperService;
11 13
 import me.chanjar.weixin.mp.api.WxMpService;
12 14
 import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
13 15
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam;
20 22
 import org.springframework.web.bind.annotation.RestController;
21 23
 
22 24
 import java.util.HashMap;
25
+import java.util.List;
23 26
 import java.util.Map;
24 27
 
25 28
 
@@ -33,6 +36,9 @@ public class LoginController extends BaseController {
33 36
     @Autowired
34 37
     ITaPersonService iTaPersonService;
35 38
 
39
+    @Autowired
40
+    ITaShopKeeperService iTaShopKeeperService;
41
+
36 42
     @Autowired
37 43
     WxUtils wxUtils;
38 44
 
@@ -90,6 +96,11 @@ public class LoginController extends BaseController {
90 96
         }
91 97
         taPerson.setSessionKey(sessionInfo.getSessionKey());
92 98
 
99
+        List<TaShopKeeper> shopKeeperList = iTaShopKeeperService.getByPerson(taPerson.getPersonId());
100
+        if (null != shopKeeperList && shopKeeperList.size() > 0) {
101
+            taPerson.setShopKeeperList(shopKeeperList);
102
+        }
103
+
93 104
         // 生成 token
94 105
         Map<String, Object> claims = new HashMap<>();
95 106
         claims.put("userId", taPerson.getPersonId());

+ 37
- 2
src/main/java/com/shigongli/controller/TaHouseController.java 查看文件

@@ -5,8 +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.common.StringUtils;
8 9
 import com.shigongli.constants.StatusConstant;
9 10
 import com.shigongli.entity.TaPerson;
11
+import com.shigongli.entity.TaShopKeeper;
12
+import com.shigongli.service.ITaShopKeeperService;
10 13
 import io.swagger.annotations.Api;
11 14
 import io.swagger.annotations.ApiOperation;
12 15
 import io.swagger.annotations.ApiParam;
@@ -23,6 +26,7 @@ import com.shigongli.entity.TaHouse;
23 26
 import org.springframework.web.bind.annotation.RestController;
24 27
 
25 28
 import javax.servlet.http.HttpServletRequest;
29
+import java.util.List;
26 30
 
27 31
 /**
28 32
  * <p>
@@ -43,6 +47,9 @@ public class TaHouseController extends BaseController {
43 47
     @Autowired
44 48
     public ITaHouseService iTaHouseService;
45 49
 
50
+    @Autowired
51
+    ITaShopKeeperService iTaShopKeeperService;
52
+
46 53
 //
47 54
 //    /**
48 55
 //     * 分页查询列表
@@ -94,11 +101,36 @@ public class TaHouseController extends BaseController {
94 101
      */
95 102
     @RequestMapping(value="/ma/taHouse",method= RequestMethod.POST)
96 103
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
97
-    public ResponseBean taHouseAdd(@ApiParam("保存内容") @RequestBody TaHouse taHouse) throws Exception{
104
+    public ResponseBean taHouseAdd(@ApiParam("保存内容") @RequestBody TaHouse taHouse,
105
+                                   HttpServletRequest request) throws Exception{
106
+        TaPerson taPerson = getPerson(request);
107
+        List<TaShopKeeper> shopKeeperList = iTaShopKeeperService.getByPerson(taPerson.getPersonId());
108
+        if (null == shopKeeperList || shopKeeperList.size() < 1) {
109
+            return ResponseBean.error("您无权新增房源", ResponseBean.ERROR_UNAVAILABLE);
110
+        }
111
+
112
+        if (!StringUtils.isEmpty(taHouse.getShopId())) {
113
+            boolean found = false;
114
+            for (TaShopKeeper keeper: shopKeeperList) {
115
+                if (taHouse.getShopId().equals(keeper.getShopId())) {
116
+                    found = true;
117
+                }
118
+            }
119
+
120
+            if (!found) {
121
+                return ResponseBean.error("您无权新增房源, 或房源所属民宿出错", ResponseBean.ERROR_UNAVAILABLE);
122
+            }
123
+        } else {
124
+            if (shopKeeperList.size() > 1) {
125
+                return ResponseBean.error("请设置房源所属民宿", ResponseBean.ERROR_UNAVAILABLE);
126
+            }
127
+
128
+            taHouse.setShopId(shopKeeperList.get(0).getShopId());
129
+        }
98 130
 
99 131
         if (iTaHouseService.save(taHouse)){
100 132
             return ResponseBean.success(taHouse);
101
-        }else {
133
+        } else {
102 134
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
103 135
         }
104 136
     }
@@ -131,6 +163,9 @@ public class TaHouseController extends BaseController {
131 163
     public ResponseBean taHouseUpdate(@ApiParam("对象ID") @PathVariable String id,
132 164
                                         @ApiParam("更新内容") @RequestBody TaHouse taHouse) throws Exception{
133 165
 
166
+        // 不允许修改所属民宿
167
+        taHouse.setShopId(null);
168
+
134 169
         if (iTaHouseService.updateById(taHouse)){
135 170
             return ResponseBean.success(iTaHouseService.getById(id));
136 171
         }else {

+ 8
- 0
src/main/java/com/shigongli/controller/TaPersonController.java 查看文件

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
6 6
 import com.baomidou.mybatisplus.core.metadata.IPage;
7 7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
8 8
 import com.shigongli.common.*;
9
+import com.shigongli.entity.TaShopKeeper;
9 10
 import com.shigongli.service.ITaShopKeeperService;
10 11
 import com.shigongli.vo.AuthPhoneParams;
11 12
 import io.swagger.annotations.Api;
@@ -21,6 +22,7 @@ import com.shigongli.entity.TaPerson;
21 22
 
22 23
 import javax.servlet.http.HttpServletRequest;
23 24
 import java.util.HashMap;
25
+import java.util.List;
24 26
 import java.util.Map;
25 27
 
26 28
 /**
@@ -70,6 +72,12 @@ public class TaPersonController extends BaseController {
70 72
         // 绑定店主
71 73
         iTaShopKeeperService.bindPerson(taPerson);
72 74
 
75
+        // 关联的店主一起返回
76
+        List<TaShopKeeper> shopKeeperList = iTaShopKeeperService.getByPerson(taPerson.getPersonId());
77
+        if (null != shopKeeperList && shopKeeperList.size() > 0) {
78
+            taPerson.setShopKeeperList(shopKeeperList);
79
+        }
80
+
73 81
         return ResponseBean.success(taPerson);
74 82
     }
75 83
 

+ 5
- 0
src/main/java/com/shigongli/entity/TaPerson.java 查看文件

@@ -6,6 +6,8 @@ import java.time.LocalDateTime;
6 6
 import com.baomidou.mybatisplus.annotation.TableField;
7 7
 import com.baomidou.mybatisplus.annotation.TableId;
8 8
 import java.io.Serializable;
9
+import java.util.List;
10
+
9 11
 import io.swagger.annotations.ApiModel;
10 12
 import io.swagger.annotations.ApiModelProperty;
11 13
 import lombok.Data;
@@ -58,4 +60,7 @@ public class TaPerson implements Serializable {
58 60
 
59 61
     @TableField(exist = false)
60 62
     private String sessionKey;
63
+
64
+    @TableField(exist = false)
65
+    private List<TaShopKeeper> shopKeeperList;
61 66
 }

+ 4
- 1
src/main/java/com/shigongli/entity/TaShopKeeper.java 查看文件

@@ -2,6 +2,8 @@ package com.shigongli.entity;
2 2
 
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5 7
 import com.baomidou.mybatisplus.annotation.TableId;
6 8
 import java.io.Serializable;
7 9
 import io.swagger.annotations.ApiModel;
@@ -48,5 +50,6 @@ public class TaShopKeeper implements Serializable {
48 50
     @ApiModelProperty(value = "创建时间")
49 51
     private LocalDateTime createDate;
50 52
 
51
-
53
+    @TableField(exist = false)
54
+    private TaShop taShop;
52 55
 }

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

@@ -19,4 +19,6 @@ public interface ITaShopKeeperService extends IService<TaShopKeeper> {
19 19
     void bindPerson(TaPerson taPerson);
20 20
 
21 21
     List<TaShopKeeper> getByPhone(String phone);
22
+
23
+    List<TaShopKeeper> getByPerson(String personId);
22 24
 }

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

@@ -1,12 +1,16 @@
1 1
 package com.shigongli.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.shigongli.common.StringUtils;
4 5
 import com.shigongli.constants.StatusConstant;
5 6
 import com.shigongli.entity.TaPerson;
7
+import com.shigongli.entity.TaShop;
6 8
 import com.shigongli.entity.TaShopKeeper;
7 9
 import com.shigongli.mapper.TaShopKeeperMapper;
8 10
 import com.shigongli.service.ITaShopKeeperService;
9 11
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12
+import com.shigongli.service.ITaShopService;
13
+import org.springframework.beans.factory.annotation.Autowired;
10 14
 import org.springframework.stereotype.Service;
11 15
 
12 16
 import java.util.List;
@@ -22,6 +26,9 @@ import java.util.List;
22 26
 @Service
23 27
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
24 28
 
29
+    @Autowired
30
+    ITaShopService iTaShopService;
31
+
25 32
     @Override
26 33
     public void bindPerson(TaPerson taPerson) {
27 34
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
@@ -44,4 +51,24 @@ public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaS
44 51
 
45 52
         return list(queryWrapper);
46 53
     }
54
+
55
+    @Override
56
+    public List<TaShopKeeper> getByPerson(String personId) {
57
+        if (StringUtils.isEmpty(personId)) {
58
+            return null;
59
+        }
60
+
61
+        QueryWrapper<TaShopKeeper> queryWrapper = new QueryWrapper<TaShopKeeper>()
62
+                .eq("person_id", personId)
63
+                .eq("status", StatusConstant.NORMAL);
64
+
65
+        List<TaShopKeeper> list = list(queryWrapper);
66
+        if (null != list && list.size() > 0) {
67
+            for (TaShopKeeper keeper: list) {
68
+                keeper.setTaShop(iTaShopService.getById(keeper.getShopId()));
69
+            }
70
+        }
71
+
72
+        return list;
73
+    }
47 74
 }