hudingbo 5 лет назад
Родитель
Сommit
8cee51b93c

+ 12 - 8
whepi-web/src/main/java/com/bofeng/controller/WxUserOpenController.java

@@ -5,6 +5,7 @@ import com.bofeng.entity.*;
 import com.bofeng.service.HomeService;
 import com.bofeng.service.WxUserOpenService;
 import com.yvan.Model;
+import com.yvan.ModelOps;
 import com.yvan.platform.JsonWapper;
 import com.yvan.platform.StringUtils;
 import com.yvan.springmvc.HttpParameterParser;
@@ -52,8 +53,8 @@ public class WxUserOpenController {
     }
 
     @ApiOperation("用户注册页面点登录")
-    @GetMapping("/userOpen/login")
-    public Model<Long> login() {
+    @PostMapping("/userOpen/login")
+    public Model<UserOpen> login(JsonWapper jsonWapper) {
         val parser = HttpParameterParser.newInstance(HttpUtils.currentRequest());
         String openId = parser.getString("openId");
         String code = parser.getString("code");
@@ -63,7 +64,10 @@ public class WxUserOpenController {
 //        String code = Conv.NS(map.get("code"));
 
         if (StringUtils.isNullOrEmpty(code)) {
-            return Model.newFail("code为空");
+            code = jsonWapper.asObject(String.class, "code");
+            if (StringUtils.isNullOrEmpty(code)) {
+                return Model.newFail("code为空");
+            }
         }
         UserOpen userOpen = homeService.getUserOpenByCode(code);
         if (userOpen == null) {
@@ -71,7 +75,7 @@ public class WxUserOpenController {
         }
         //成功返回用户Id
         try {
-            return Model.newSuccess(userOpen.getUserId());
+            return Model.newSuccess(userOpen);
         } catch (Exception e) {
             return Model.newFail(e.getMessage());
         }
@@ -151,16 +155,16 @@ public class WxUserOpenController {
 
     @ApiOperation("创建业委会资格")
     @PostMapping("/userOpen/createYWHRule")
-    public Model<Long> createYWHRule(JsonWapper jsonWapper) throws Exception {
+    public ModelOps createYWHRule(JsonWapper jsonWapper) throws Exception {
         Long userId = jsonWapper.asObject(Long.class, "userId");
         if (userId == null || userId == 0L) {
-            return Model.newFail("用户不存在");
+            return ModelOps.newFail("用户不存在");
         }
         //成功返回用户Id
         try {
-            return Model.newSuccess(wxUserOpenService.createYWHRule(userId));
+            return ModelOps.newSuccess(wxUserOpenService.createYWHRule(userId));
         } catch (Exception e) {
-            return Model.newFail(e.getMessage());
+            return ModelOps.newFail(e.getMessage());
         }
     }
 

+ 2 - 0
whepi-web/src/main/java/com/bofeng/dao/SysUptownUnitMapper.java

@@ -17,4 +17,6 @@ public interface SysUptownUnitMapper extends BaseMapper<sysUptownUnit> {
     @Select("select * from sys_uptown_unit where status = 1 and unit_id = #{unitId}")
     List<UptownUnit> selectByUnitId(@Param("unitId") Long unitId);
 
+    @Select("SELECT uptown_id FROM sys_uptown_unit where unit_id=(select unit_id from sys_uptown_house where house_id=#{houseId} limit 1) limit 1 ")
+    Long getUptownIdByHouseId(@Param("houseId") Long houseId);
 }

+ 25 - 10
whepi-web/src/main/java/com/bofeng/service/WxUserOpenService.java

@@ -186,7 +186,7 @@ public class WxUserOpenService {
     }
 
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
-    public Long createYWHRule(Long userId) throws Exception {
+    public int createYWHRule(Long userId) throws Exception {
         /** 创建业委会资格
          *  1.当前用户有无家庭角色,无则退出
          *  2.小区已有业委会,退出
@@ -199,12 +199,13 @@ public class WxUserOpenService {
         boolean hasFamily = false;
         Long myUptownId = 0L;
         Long myOwnerId = 0L;
+        Long myHouseId = 0L;
         if (lstUserRole.size() > 0) {
             //判断该用户是否创建了业委会的角色
             for (UserRole item : lstUserRole) {
                 if (item.getRoleId() == 1L) {
                     hasFamily = true;
-                    myUptownId = item.getPropertyId();
+                    myHouseId = item.getPropertyId();
                 }
                 if (item.getRoleId() == 2L) {
                     myOwnerId = item.getPropertyId();
@@ -214,8 +215,13 @@ public class WxUserOpenService {
         if (!hasFamily) {
             throw new Exception("请先完善家庭地址!");
         }
+        if (myHouseId == 0L) {
+            throw new Exception("家庭地址中尚未生成门牌号!");
+        }
+        //根据门牌找小区id
+        myUptownId = sysUptownUnitMapper.getUptownIdByHouseId(myHouseId);
         if (myUptownId == 0L) {
-            throw new Exception("家庭地址中尚未选择小区!");
+            throw new Exception("家庭所在小区未找到!");
         }
         //判断业委会是否已经建立
         List<Owner> lstSysOwner = ownerMapper.getOwnerByUptownId(myUptownId);
@@ -223,13 +229,13 @@ public class WxUserOpenService {
             for (Owner item : lstSysOwner) {
                 if (item.getUserId() == sysUserId && item.getType() == 1) {
                     //业委会负责人的绑定用户是自己
-                    return 1L;  //该小区已成立业委会,且业委会负责人的绑定用户是自己,可以进入编辑
+                    return 1;  //该小区已成立业委会,且业委会负责人的绑定用户是自己,可以进入编辑
 //                    break;
                 }
             }
             throw new Exception("小区业委会已建立,非业委会负责人不能编辑!");
         } else {
-            return 1L;  //该小区没有成立业委会,可以进入新增
+            return 1;  //该小区没有成立业委会,可以进入新增
         }
     }
 
@@ -244,6 +250,7 @@ public class WxUserOpenService {
          * */
         Long sysUserId = queryUser(userId);
         Long myUptownId = 0L;
+        Long myHouseId = 0L;
         if (uptownId <= 0L) {
             throw new Exception("小区id为空!");
         }
@@ -263,13 +270,19 @@ public class WxUserOpenService {
                     throw new Exception("业委会用户角色已存在!");   //todo 暂时只允许一个用户角色绑定一个业委会
                 }
                 if (item.getRoleId() == 1L) {
-                    myUptownId = item.getPropertyId();
+
+                    myHouseId = item.getPropertyId();
                 }
             }
         }
-        if (myUptownId == 0L) {
+        if (myHouseId == 0L) {
             throw new Exception("请先创建家庭用户!");
         }
+        //根据门牌找小区id
+        myUptownId = sysUptownUnitMapper.getUptownIdByHouseId(myHouseId);
+        if (myUptownId == 0L) {
+            throw new Exception("家庭所在小区未找到!");
+        }
         if (myUptownId != uptownId) {
             throw new Exception("家庭所在小区和业委会所在小区不一致!");
         }
@@ -456,8 +469,7 @@ public class WxUserOpenService {
     }
 
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
-    public Long editFamily(Long userId, Long unitId, String doorPlate, String linkMan, Integer helpNum, String
-            phone, Long urId) throws Exception {
+    public Long editFamily(Long userId, Long unitId, String doorPlate, String linkMan, Integer helpNum, String phone, Long urId) throws Exception {
         Long sysUserId = queryUser(userId);
         if (urId == 0L) {
             throw new Exception("尚未建立家庭用户角色,无法编辑");
@@ -480,7 +492,10 @@ public class WxUserOpenService {
         if (uptownHouse == null) {
             throw new Exception("尚未创建门牌号");
         }
-        if (uptownHouse.getUnitId() != unitId || uptownHouse.getDoorplate() != doorPlate) {
+        if (uptownHouse.getUnitId() != unitId) {
+            throw new Exception("小区选择后不允许修改");
+        }
+        if (uptownHouse.getDoorplate() != doorPlate) {
             //查找更换之后的单元、门牌是否被占用
             List<UptownHouse> lstUptownHouse = uptownHouseMapper.getUptownHouseBy(unitId, doorPlate);
             if (lstUptownHouse != null && lstUptownHouse.size() > 0) {