Your Name 4 years ago
parent
commit
8d3302a34b

+ 11
- 0
src/main/java/com/shigongli/controller/LoginController.java View File

6
 import com.shigongli.constants.StatusConstant;
6
 import com.shigongli.constants.StatusConstant;
7
 import com.shigongli.entity.SysUser;
7
 import com.shigongli.entity.SysUser;
8
 import com.shigongli.entity.TaPerson;
8
 import com.shigongli.entity.TaPerson;
9
+import com.shigongli.entity.TaShopKeeper;
9
 import com.shigongli.service.ISysUserService;
10
 import com.shigongli.service.ISysUserService;
10
 import com.shigongli.service.ITaPersonService;
11
 import com.shigongli.service.ITaPersonService;
12
+import com.shigongli.service.ITaShopKeeperService;
11
 import me.chanjar.weixin.mp.api.WxMpService;
13
 import me.chanjar.weixin.mp.api.WxMpService;
12
 import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
14
 import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
13
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
15
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
20
 import org.springframework.web.bind.annotation.RestController;
22
 import org.springframework.web.bind.annotation.RestController;
21
 
23
 
22
 import java.util.HashMap;
24
 import java.util.HashMap;
25
+import java.util.List;
23
 import java.util.Map;
26
 import java.util.Map;
24
 
27
 
25
 
28
 
33
     @Autowired
36
     @Autowired
34
     ITaPersonService iTaPersonService;
37
     ITaPersonService iTaPersonService;
35
 
38
 
39
+    @Autowired
40
+    ITaShopKeeperService iTaShopKeeperService;
41
+
36
     @Autowired
42
     @Autowired
37
     WxUtils wxUtils;
43
     WxUtils wxUtils;
38
 
44
 
90
         }
96
         }
91
         taPerson.setSessionKey(sessionInfo.getSessionKey());
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
         // 生成 token
104
         // 生成 token
94
         Map<String, Object> claims = new HashMap<>();
105
         Map<String, Object> claims = new HashMap<>();
95
         claims.put("userId", taPerson.getPersonId());
106
         claims.put("userId", taPerson.getPersonId());

+ 37
- 2
src/main/java/com/shigongli/controller/TaHouseController.java View File

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.common.StringUtils;
8
 import com.shigongli.constants.StatusConstant;
9
 import com.shigongli.constants.StatusConstant;
9
 import com.shigongli.entity.TaPerson;
10
 import com.shigongli.entity.TaPerson;
11
+import com.shigongli.entity.TaShopKeeper;
12
+import com.shigongli.service.ITaShopKeeperService;
10
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
15
 import io.swagger.annotations.ApiParam;
23
 import org.springframework.web.bind.annotation.RestController;
26
 import org.springframework.web.bind.annotation.RestController;
24
 
27
 
25
 import javax.servlet.http.HttpServletRequest;
28
 import javax.servlet.http.HttpServletRequest;
29
+import java.util.List;
26
 
30
 
27
 /**
31
 /**
28
  * <p>
32
  * <p>
43
     @Autowired
47
     @Autowired
44
     public ITaHouseService iTaHouseService;
48
     public ITaHouseService iTaHouseService;
45
 
49
 
50
+    @Autowired
51
+    ITaShopKeeperService iTaShopKeeperService;
52
+
46
 //
53
 //
47
 //    /**
54
 //    /**
48
 //     * 分页查询列表
55
 //     * 分页查询列表
94
      */
101
      */
95
     @RequestMapping(value="/ma/taHouse",method= RequestMethod.POST)
102
     @RequestMapping(value="/ma/taHouse",method= RequestMethod.POST)
96
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
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
         if (iTaHouseService.save(taHouse)){
131
         if (iTaHouseService.save(taHouse)){
100
             return ResponseBean.success(taHouse);
132
             return ResponseBean.success(taHouse);
101
-        }else {
133
+        } else {
102
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
134
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
103
         }
135
         }
104
     }
136
     }
131
     public ResponseBean taHouseUpdate(@ApiParam("对象ID") @PathVariable String id,
163
     public ResponseBean taHouseUpdate(@ApiParam("对象ID") @PathVariable String id,
132
                                         @ApiParam("更新内容") @RequestBody TaHouse taHouse) throws Exception{
164
                                         @ApiParam("更新内容") @RequestBody TaHouse taHouse) throws Exception{
133
 
165
 
166
+        // 不允许修改所属民宿
167
+        taHouse.setShopId(null);
168
+
134
         if (iTaHouseService.updateById(taHouse)){
169
         if (iTaHouseService.updateById(taHouse)){
135
             return ResponseBean.success(iTaHouseService.getById(id));
170
             return ResponseBean.success(iTaHouseService.getById(id));
136
         }else {
171
         }else {

+ 8
- 0
src/main/java/com/shigongli/controller/TaPersonController.java View File

6
 import com.baomidou.mybatisplus.core.metadata.IPage;
6
 import com.baomidou.mybatisplus.core.metadata.IPage;
7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
8
 import com.shigongli.common.*;
8
 import com.shigongli.common.*;
9
+import com.shigongli.entity.TaShopKeeper;
9
 import com.shigongli.service.ITaShopKeeperService;
10
 import com.shigongli.service.ITaShopKeeperService;
10
 import com.shigongli.vo.AuthPhoneParams;
11
 import com.shigongli.vo.AuthPhoneParams;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.Api;
21
 
22
 
22
 import javax.servlet.http.HttpServletRequest;
23
 import javax.servlet.http.HttpServletRequest;
23
 import java.util.HashMap;
24
 import java.util.HashMap;
25
+import java.util.List;
24
 import java.util.Map;
26
 import java.util.Map;
25
 
27
 
26
 /**
28
 /**
70
         // 绑定店主
72
         // 绑定店主
71
         iTaShopKeeperService.bindPerson(taPerson);
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
         return ResponseBean.success(taPerson);
81
         return ResponseBean.success(taPerson);
74
     }
82
     }
75
 
83
 

+ 5
- 0
src/main/java/com/shigongli/entity/TaPerson.java View File

6
 import com.baomidou.mybatisplus.annotation.TableField;
6
 import com.baomidou.mybatisplus.annotation.TableField;
7
 import com.baomidou.mybatisplus.annotation.TableId;
7
 import com.baomidou.mybatisplus.annotation.TableId;
8
 import java.io.Serializable;
8
 import java.io.Serializable;
9
+import java.util.List;
10
+
9
 import io.swagger.annotations.ApiModel;
11
 import io.swagger.annotations.ApiModel;
10
 import io.swagger.annotations.ApiModelProperty;
12
 import io.swagger.annotations.ApiModelProperty;
11
 import lombok.Data;
13
 import lombok.Data;
58
 
60
 
59
     @TableField(exist = false)
61
     @TableField(exist = false)
60
     private String sessionKey;
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 View File

2
 
2
 
3
 import com.baomidou.mybatisplus.annotation.IdType;
3
 import com.baomidou.mybatisplus.annotation.IdType;
4
 import java.time.LocalDateTime;
4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5
 import com.baomidou.mybatisplus.annotation.TableId;
7
 import com.baomidou.mybatisplus.annotation.TableId;
6
 import java.io.Serializable;
8
 import java.io.Serializable;
7
 import io.swagger.annotations.ApiModel;
9
 import io.swagger.annotations.ApiModel;
48
     @ApiModelProperty(value = "创建时间")
50
     @ApiModelProperty(value = "创建时间")
49
     private LocalDateTime createDate;
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 View File

19
     void bindPerson(TaPerson taPerson);
19
     void bindPerson(TaPerson taPerson);
20
 
20
 
21
     List<TaShopKeeper> getByPhone(String phone);
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 View File

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.conditions.query.QueryWrapper;
4
+import com.shigongli.common.StringUtils;
4
 import com.shigongli.constants.StatusConstant;
5
 import com.shigongli.constants.StatusConstant;
5
 import com.shigongli.entity.TaPerson;
6
 import com.shigongli.entity.TaPerson;
7
+import com.shigongli.entity.TaShop;
6
 import com.shigongli.entity.TaShopKeeper;
8
 import com.shigongli.entity.TaShopKeeper;
7
 import com.shigongli.mapper.TaShopKeeperMapper;
9
 import com.shigongli.mapper.TaShopKeeperMapper;
8
 import com.shigongli.service.ITaShopKeeperService;
10
 import com.shigongli.service.ITaShopKeeperService;
9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12
+import com.shigongli.service.ITaShopService;
13
+import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.stereotype.Service;
14
 import org.springframework.stereotype.Service;
11
 
15
 
12
 import java.util.List;
16
 import java.util.List;
22
 @Service
26
 @Service
23
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
27
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
24
 
28
 
29
+    @Autowired
30
+    ITaShopService iTaShopService;
31
+
25
     @Override
32
     @Override
26
     public void bindPerson(TaPerson taPerson) {
33
     public void bindPerson(TaPerson taPerson) {
27
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
34
         List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
44
 
51
 
45
         return list(queryWrapper);
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
 }