姜永辉 пре 1 година
родитељ
комит
95984f3338

+ 19 - 1
src/main/java/com/dk/mdm/feign/CompanyFeign.java

@@ -4,6 +4,7 @@ package com.dk.mdm.feign;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.common.response.ResponseResultVO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 
 
@@ -14,7 +15,7 @@ import java.util.Map;
  * @desc : OauthServerFeign
  * @desc : OauthServerFeign
  * @date : 2024-038-10 10:56
  * @date : 2024-038-10 10:56
  */
  */
-@FeignClient(name = Constant.OAUTH_PREFIX + Constant.SERVER, path = Constant.COMPANY, contextId = "company")
+@FeignClient(name = Constant.OAUTH_PREFIX + Constant.SERVER , path = Constant.COMPANY, contextId = "company")
 public interface CompanyFeign {
 public interface CompanyFeign {
     /**
     /**
      * @desc   : 体验产品
      * @desc   : 体验产品
@@ -24,4 +25,21 @@ public interface CompanyFeign {
     @PostMapping({"/feign_update_wx_user_company"})
     @PostMapping({"/feign_update_wx_user_company"})
     ResponseResultVO<Boolean> updateWxUserCompany(@RequestBody Map<String, Object> collectQuery) ;
     ResponseResultVO<Boolean> updateWxUserCompany(@RequestBody Map<String, Object> collectQuery) ;
 
 
+    /**
+     * @desc   : 更新公司的当前人数
+     * @author : 姜永辉
+     * @date   : 2023-11-02 16:27
+     */
+    @PostMapping({"/feign_update_company_cur_staff_num"})
+    ResponseResultVO<Boolean> updateCompanyCurStaffNum(@RequestBody Map<String, Object> collectQuery) ;
+
+
+    /**
+     * @desc   : 可以绑定微信的员工人数  人数上限
+     * @author : 姜永辉
+     * @date   : 2023-11-02 16:27
+     */
+    @PostMapping({"/get_company_max_staff_num/{id}"})
+    ResponseResultVO<?> getCompanyMaxStaffNum(@PathVariable Integer id) ;
+
 }
 }

+ 1 - 1
src/main/java/com/dk/mdm/feign/UserFeign.java

@@ -31,6 +31,6 @@ public interface UserFeign {
      * @date   : 2023-11-02 16:27
      * @date   : 2023-11-02 16:27
      */
      */
     @PostMapping({"/update_clear_openid_feign"})
     @PostMapping({"/update_clear_openid_feign"})
-    ResponseResultVO<?> updateClearOpenidFeign(@RequestBody Map<String, Object> collectQuery) ;
+    ResponseResultVO<Integer> updateClearOpenidFeign(@RequestBody Map<String, Object> collectQuery) ;
 
 
 }
 }

+ 3 - 0
src/main/java/com/dk/mdm/mapper/mst/StaffMapper.xml

@@ -66,6 +66,9 @@
             <if test="flgValid != null">
             <if test="flgValid != null">
                 AND t.flg_valid = #{flgValid}
                 AND t.flg_valid = #{flgValid}
             </if>
             </if>
+            <if test="flgCanLogin != null">
+                AND t.flg_can_login = #{flgCanLogin}
+            </if>
             <if test="cpId != null" >
             <if test="cpId != null" >
                 AND t.cp_id = #{cpId}
                 AND t.cp_id = #{cpId}
             </if>
             </if>

+ 93 - 19
src/main/java/com/dk/mdm/service/mst/StaffService.java

@@ -157,6 +157,27 @@ public class StaffService extends BaseService<Staff> {
         if (staffResponses != null && staffResponses.size() > 0) {
         if (staffResponses != null && staffResponses.size() > 0) {
             return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_CODE_EXIST);
             return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_CODE_EXIST);
         }
         }
+        //可以绑定微信的员工人数  人数上限
+        if (staffVO.getFlgCanLogin()) {
+            ResponseResultVO<?> resultMaxnum = companyFeign.getCompanyMaxStaffNum(cpId);
+            if (resultMaxnum.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
+                // 无用户
+                throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
+                        ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
+            } else {
+                Map<String, Object> mp = (Map<String, Object>) resultMaxnum.getData();
+                int intMaxnum = Integer.parseInt(mp.get("maxStaffNum") + "");
+                staffQuery = new StaffQuery();
+                staffQuery.setFlgCanLogin(true);
+                staffQuery.setCpId(cpId);
+                List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQuery);
+                if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 && intMaxnum < staffResponsesFlgCanLogin.size() + 1) {
+                    // 无用户
+                    throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_STAFF_ERROR.getCode(),
+                            ErrorCodeEnum.USER_MAX_STAFF_ERROR.getMessage());
+                }
+            }
+        }
 
 
         // 获取编码和主键UuId
         // 获取编码和主键UuId
         Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), false);
         Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), false);
@@ -208,6 +229,7 @@ public class StaffService extends BaseService<Staff> {
                 Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
                 Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
         staff.setStaffId(codeMap.get("outId").toString());
         staff.setStaffId(codeMap.get("outId").toString());
         staff.setStaffCode(codeMap.get("outNote").toString());
         staff.setStaffCode(codeMap.get("outNote").toString());
+        staff.setFlgCanLogin(true);
         super.insert(staff);
         super.insert(staff);
         return ResponseResultUtil.success(staff);
         return ResponseResultUtil.success(staff);
     }
     }
@@ -228,11 +250,11 @@ public class StaffService extends BaseService<Staff> {
         List<Map<String, Object>> listRoles = map.get("roles");
         List<Map<String, Object>> listRoles = map.get("roles");
         List<Role> listR = new ArrayList<>();
         List<Role> listR = new ArrayList<>();
         String roleid = "";
         String roleid = "";
-        Integer cpId = Integer.parseInt(listCom.get(0).get("cpId").toString()) ;
+        Integer cpId = Integer.parseInt(listCom.get(0).get("cpId").toString());
         String staffId = listCom.get(0).get("staffId").toString();
         String staffId = listCom.get(0).get("staffId").toString();
 
 
         // 插入常用功能 标准版 插入 销售出库 库存查询 商品档案
         // 插入常用功能 标准版 插入 销售出库 库存查询 商品档案
-        if(Constant.STD.equals(gradeCode)){
+        if (Constant.STD.equals(gradeCode)) {
             List<String> objectCodeList = new ArrayList<>();
             List<String> objectCodeList = new ArrayList<>();
             // 销售出库
             // 销售出库
             objectCodeList.add("order-out");
             objectCodeList.add("order-out");
@@ -249,7 +271,7 @@ public class StaffService extends BaseService<Staff> {
             List<SettingValue> settingValueList = new ArrayList<>();
             List<SettingValue> settingValueList = new ArrayList<>();
             // 自动办理
             // 自动办理
             settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_001.getValue())
             settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_001.getValue())
-                                .setSettingValue("true"));
+                    .setSettingValue("true"));
             // 欠货销售
             // 欠货销售
             settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_002.getValue())
             settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_002.getValue())
                     .setSettingValue("true"));
                     .setSettingValue("true"));
@@ -259,7 +281,7 @@ public class StaffService extends BaseService<Staff> {
             Map<String, Object> m = listRoles.get(i);
             Map<String, Object> m = listRoles.get(i);
             Role role = new Role();
             Role role = new Role();
             //设置编码
             //设置编码
-            Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.ROLE.getName(),cpId, false);
+            Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.ROLE.getName(), cpId, false);
             if (Constant.ROLE_DATA.equals(m.get("roleCode").toString())) {
             if (Constant.ROLE_DATA.equals(m.get("roleCode").toString())) {
                 roleid = uniqueNoteCode.get("outId").toString();
                 roleid = uniqueNoteCode.get("outId").toString();
             }
             }
@@ -350,19 +372,19 @@ public class StaffService extends BaseService<Staff> {
         for (int i = 0; i < listGoodsCategorys.size(); i++) {
         for (int i = 0; i < listGoodsCategorys.size(); i++) {
             Map<String, Object> m = listGoodsCategorys.get(i);
             Map<String, Object> m = listGoodsCategorys.get(i);
             GoodsCategory goodsCategory = new GoodsCategory();
             GoodsCategory goodsCategory = new GoodsCategory();
-            goodsCategory.setCatCode(m.get("catCode")+ "");
-            goodsCategory.setCatName(m.get("catName")+ "");
-            if (m.get("parentId")!=null){
-                goodsCategory.setParentId(m.get("parentId")+ "");
+            goodsCategory.setCatCode(m.get("catCode") + "");
+            goodsCategory.setCatName(m.get("catName") + "");
+            if (m.get("parentId") != null) {
+                goodsCategory.setParentId(m.get("parentId") + "");
             }
             }
-            if (m.get("topId")!=null){
-                goodsCategory.setTopId(m.get("topId")+ "");
+            if (m.get("topId") != null) {
+                goodsCategory.setTopId(m.get("topId") + "");
             }
             }
-            if (m.get("levelUpper")!=null){
-                goodsCategory.setLevelUpper(m.get("levelUpper")+ "");
+            if (m.get("levelUpper") != null) {
+                goodsCategory.setLevelUpper(m.get("levelUpper") + "");
             }
             }
-            if (m.get("levelLower")!=null){
-                goodsCategory.setLevelLower(m.get("levelLower")+ "");
+            if (m.get("levelLower") != null) {
+                goodsCategory.setLevelLower(m.get("levelLower") + "");
             }
             }
             goodsCategory.setLevelLeaf((Boolean) m.get("levelLeaf"));
             goodsCategory.setLevelLeaf((Boolean) m.get("levelLeaf"));
             goodsCategory.setLevelNo((Integer) m.get("levelNo"));
             goodsCategory.setLevelNo((Integer) m.get("levelNo"));
@@ -384,7 +406,7 @@ public class StaffService extends BaseService<Staff> {
             printLayout.setLayoutName(m.get("layoutName") + "");
             printLayout.setLayoutName(m.get("layoutName") + "");
             printLayout.setLayoutData(JSONObject.parseObject(JSONObject.toJSONString(m.get("layoutData"))));
             printLayout.setLayoutData(JSONObject.parseObject(JSONObject.toJSONString(m.get("layoutData"))));
             printLayout.setDisplayNo((Integer) m.get("displayNo"));
             printLayout.setDisplayNo((Integer) m.get("displayNo"));
-            printLayout.setDocName(m.get("docName")+ "" );
+            printLayout.setDocName(m.get("docName") + "");
             printLayout.setCpId(cpId);
             printLayout.setCpId(cpId);
             printLayout.setOpCreateUserId(m.get("opCreateUserId").toString());
             printLayout.setOpCreateUserId(m.get("opCreateUserId").toString());
             listP.add(printLayout);
             listP.add(printLayout);
@@ -441,7 +463,59 @@ public class StaffService extends BaseService<Staff> {
     public ResponseResultVO<Boolean> update(StaffVO staffVO) {
     public ResponseResultVO<Boolean> update(StaffVO staffVO) {
         // 转化实体
         // 转化实体
         Staff staff = staffConvert.convertToPo(staffVO);
         Staff staff = staffConvert.convertToPo(staffVO);
-        return super.updateByUuid(staff);
+        // 查询原来的getFlgCanLogin
+        StaffResponse staffResponseOld = staffMapper.selectById(staffVO.getStaffId());
+
+        super.updateByUuid(staff);
+        // 获取当前公司的cpId
+        Integer cpId = authUtils.getStaff().getCpId();
+        //可以绑定微信的员工人数  人数上限
+        if (staffVO.getFlgCanLogin()) {
+            ResponseResultVO<?> resultMaxnum = companyFeign.getCompanyMaxStaffNum(cpId);
+            if (resultMaxnum.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
+                // 无用户
+                throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
+                        ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
+            } else {
+                Map<String, Object> mp = (Map<String, Object>) resultMaxnum.getData();
+                int intMaxnum = Integer.parseInt(mp.get("maxStaffNum") + "");
+                StaffQuery staffQuery = new StaffQuery();
+                staffQuery.setFlgCanLogin(true);
+                staffQuery.setCpId(cpId);
+                List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQuery);
+                if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 && intMaxnum < staffResponsesFlgCanLogin.size()) {
+                    // 无用户
+                    throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_STAFF_ERROR.getCode(),
+                            ErrorCodeEnum.USER_MAX_STAFF_ERROR.getMessage());
+                }
+            }
+            if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
+                // 增加一个可以cur_staff_num
+                Map<String, Object> m = new HashMap<>();
+                m.put("curStaffNum", 1);
+                m.put("cpId", cpId);
+                ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
+                if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
+                    // 无用户
+                    throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
+                            ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
+                }
+            }
+        } else {
+            if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
+                // 减少一个可以cur_staff_num
+                Map<String, Object> m = new HashMap<>();
+                m.put("curStaffNum", -1);
+                m.put("cpId", cpId);
+                ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
+                if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
+                    // 无用户
+                    throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
+                            ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
+                }
+            }
+        }
+        return ResponseResultUtil.success();
     }
     }
 
 
     /**
     /**
@@ -549,11 +623,11 @@ public class StaffService extends BaseService<Staff> {
         StaffResponse staff = staffMapper.selectByUserId(param.get("userId").toString(), Integer.parseInt(param.get("cpId").toString()));
         StaffResponse staff = staffMapper.selectByUserId(param.get("userId").toString(), Integer.parseInt(param.get("cpId").toString()));
         if (staff != null) {
         if (staff != null) {
             // 提示不允许登录
             // 提示不允许登录
-            if(staff.getFlgCanLogin() == null || !staff.getFlgCanLogin()){
+            if (staff.getFlgCanLogin() == null || !staff.getFlgCanLogin()) {
                 return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CAN_NOT_LOGIN.getMessage());
                 return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CAN_NOT_LOGIN.getMessage());
             }
             }
             // 离职状态不允许登录
             // 离职状态不允许登录
-            if(staff.getHrStatus() != 1){
+            if (staff.getHrStatus() != 1) {
                 return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_OUT_NOT_LOGIN.getMessage());
                 return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_OUT_NOT_LOGIN.getMessage());
             }
             }
             // 存Redis
             // 存Redis
@@ -595,7 +669,7 @@ public class StaffService extends BaseService<Staff> {
     )
     )
     public ResponseResultVO<Boolean> logout(Map<String, Object> param) {
     public ResponseResultVO<Boolean> logout(Map<String, Object> param) {
         // 更新员工登录状态
         // 更新员工登录状态
-        this.updateByUuid(new Staff().setStaffId(param.get("staffId").toString()).setFlgCanLogin(false));
+//        this.updateByUuid(new Staff().setStaffId(param.get("staffId").toString()).setFlgCanLogin(false));
         return ResponseResultUtil.success(true);
         return ResponseResultUtil.success(true);
     }
     }
 }
 }