From 64b432916af9c9218ab3f3eca614e26c542142ae Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 07 十一月 2023 15:47:13 +0800
Subject: [PATCH] bug

---
 server/src/main/java/doumeemes/biz/system/impl/SystemUserBizImpl.java |   44 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/doumeemes/biz/system/impl/SystemUserBizImpl.java b/server/src/main/java/doumeemes/biz/system/impl/SystemUserBizImpl.java
index e14e811..f6ea8f1 100644
--- a/server/src/main/java/doumeemes/biz/system/impl/SystemUserBizImpl.java
+++ b/server/src/main/java/doumeemes/biz/system/impl/SystemUserBizImpl.java
@@ -10,6 +10,7 @@
 import doumeemes.core.utils.DateUtil;
 import doumeemes.core.utils.Utils;
 import doumeemes.core.utils.excel.EasyExcelUtil;
+import doumeemes.dao.business.CompanyMapper;
 import doumeemes.dao.business.CompanyPositionMapper;
 import doumeemes.dao.business.dto.AutoLoginUserDTO;
 import doumeemes.dao.business.dto.CompanyInitDataDTO;
@@ -78,6 +79,9 @@
     private DepartmentExtService departmentExtService;
     @Autowired
     private CompanyUserExtMapper companyUserExtMapper;
+
+    @Autowired
+    private CompanyMapper companyMapper;
 
     @Override
     public void deleteById(Integer id) {
@@ -162,6 +166,18 @@
         if(plansList == null || plansList.size()==0){
             throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "瀵煎叆鏁版嵁鍐呭鏈夎锛�");
         }
+        //娣诲姞浼佷笟鍛樺伐鍏宠仈鍏崇郴
+        CompanyUser cuw = new CompanyUser();
+        cuw.setDeleted(Constants.ZERO);
+        cuw.setRootDepartId(user.getRootDepartment().getId());
+        Company company = companyMapper.selectById(user.getCompany().getId());
+        if(company.getOpenUserNum() > 0){
+            //浜烘暟闄愬埗杈撳叆0锛岃〃绀轰笉闄愬埗浜烘暟
+            if(companyUserExtMapper.selectCount(new QueryWrapper<>(cuw)) + plansList.size() > company.getOpenUserNum() ){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛鏁伴噺瓒呰繃璐拱鏁伴噺锛岃鑱旂郴涓氬姟缁忕悊缁喘!");
+            }
+        }
+
         CompanyPosition cp = new CompanyPosition();
         cp.setDeleted(Constants.ZERO);
         cp.setCompanyId(user.getCompany().getId());
@@ -213,10 +229,13 @@
                 throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝绗��"+index+"銆戣銆愭墜鏈哄彿銆戝憳宸ヨ处鍙峰凡缁忓瓨锛�");
             }
             cuu.setPhone(null);
-            cuu.setCode(p.getNo());
-            if(companyUserService.findOne(cuu) !=null){
-                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝绗��"+index+"銆戣銆愬伐鍙枫�戝凡缁忓瓨锛�");
+            if (StringUtils.isNotBlank(p.getNo())){
+                cuu.setCode(p.getNo());
+                if(companyUserService.findOne(cuu) !=null){
+                    throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝绗��"+index+"銆戣銆愬伐鍙枫�戝凡缁忓瓨锛�");
+                }
             }
+
             SystemUser systemUser = new SystemUser();
             systemUser.setUsername(cu.getPhone());
             systemUser.setDeleted(Boolean.FALSE);
@@ -543,10 +562,11 @@
             cu.setDeleted(Constants.ZERO);
             cu.setRootDepartId(loginUser.getRootDepartment().getId());
             //闄愬埗浜烘暟
-            int limitUserNum = Constants.formatIntegerNum(loginUser.getCompany().getOpenUserNum());
-            if(limitUserNum > 0){
+//            int limitUserNum = Constants.formatIntegerNum(loginUser.getCompany().getOpenUserNum());
+            Company company = companyMapper.selectById(loginUser.getCompany().getId());
+            if(company.getOpenUserNum() > 0){
                 //浜烘暟闄愬埗杈撳叆0锛岃〃绀轰笉闄愬埗浜烘暟
-                if(companyUserExtMapper.selectCount(new QueryWrapper<>(cu)) +1 > limitUserNum ){
+                if(companyUserExtMapper.selectCount(new QueryWrapper<>(cu)) +1 > company.getOpenUserNum() ){
                     throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛鏁伴噺瓒呰繃璐拱鏁伴噺锛岃鑱旂郴涓氬姟缁忕悊缁喘!");
                 }
             }
@@ -570,10 +590,14 @@
                     throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "鎵嬫満鍙峰凡瀛樺湪锛�");
                 }
             }
-            cu.setCode(systemUser.getEmpNo());
-            if(companyUserService.findOne(cu) !=null){
-                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "宸ュ彿宸插瓨鍦�");
+            //瀛樺湪宸ュ彿闇�瑕佸敮涓�鍒ゆ柇
+            if (StringUtils.isNotBlank(systemUser.getEmpNo())){
+                cu.setCode(systemUser.getEmpNo());
+                if(companyUserService.findOne(cu) !=null){
+                    throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "宸ュ彿宸插瓨鍦�");
+                }
             }
+
             cu.setUserId(userId);
             cu.setComDepartId(loginUser.getComDepartment().getId());
             cu.setCreateUser(loginUser.getId());
@@ -689,6 +713,8 @@
                 if (codeUser != null && !codeUser.getId().equals(cu.getId())) {
                     throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "宸ュ彿宸插瓨鍦�");
                 }
+            }else if (StringUtils.isBlank(systemUser.getEmpNo())) {
+                u.setCode(systemUser.getEmpNo());
             }
             u.setId(cu.getId());
             u.setName(systemUser.getRealname());

--
Gitblit v1.9.3