Browse Source

代理默认部门及父级代理

mingfu 1 month ago
parent
commit
69a38ea6ac

+ 6 - 2
ie-admin/src/main/java/com/ruoyi/web/controller/dz/DzAgentController.java

@@ -124,8 +124,12 @@ public class DzAgentController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody DzAgent dzAgent)
     {
-        if(UserTypeEnum.isAgent(SecurityUtils.getLoginUser().getUser().getUserType())) {
-            dzAgent.setParentId(SecurityUtils.getLoginUser().getUser().getUserTypeId());
+        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
+        if(UserTypeEnum.isAgent(sysUser.getUserType()) && null != sysUser.getUserTypeId()) {
+            dzAgent.setParentId(sysUser.getUserTypeId());
+        }
+        if(null == dzAgent.getDeptId()) {
+            dzAgent.setDeptId(sysUser.getDeptId());
         }
         setSchools(dzAgent);
         return toAjax(dzAgentService.insertDzAgent(dzAgent));

+ 4 - 2
ie-admin/src/main/java/com/ruoyi/web/controller/dz/DzCardsController.java

@@ -4,8 +4,10 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.ValidationException;
 
+import cn.hutool.core.util.NumberUtil;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.ExamType;
+import com.ruoyi.common.utils.NumberUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.dz.domain.DzAgent;
 import com.ruoyi.dz.service.IDzAgentService;
@@ -153,9 +155,9 @@ public class DzCardsController extends BaseController
             if (!sysUser.getDeptId().equals(agent.getDeptId())) {
                 throw new ValidationException("只能分配给下级代理");
             }
-            dzCardsService.assignCard(null == agent.getParentId() ? agentId : agent.getParentId(), agentId, begin, end, location, examType, schoolId);
+            dzCardsService.assignCard(!NumberUtils.isPositive(agent.getParentId()) ? agentId : agent.getParentId(), agentId, begin, end, location, examType, schoolId);
         } else { // 平台指定, TODO 暂只支持二级代理
-            dzCardsService.assignCard(null == agent.getParentId() ? agentId : agent.getParentId(), agentId, begin, end, location, examType, schoolId);
+            dzCardsService.assignCard(!NumberUtils.isPositive(agent.getParentId()) ? agentId : agent.getParentId(), agentId, begin, end, location, examType, schoolId);
         }
         return AjaxResult.success();
     }

+ 4 - 0
ie-common/src/main/java/com/ruoyi/common/utils/NumberUtils.java

@@ -31,6 +31,10 @@ public class NumberUtils {
         return true;
     }
 
+    public static boolean isPositive(Number v) {
+        return null != v && !v.equals(0);
+    }
+
     public static void main(String[] args) {
         System.out.println(getRandom1(8));
         System.out.println(getRandom(8));

+ 1 - 0
ie-system/src/main/java/com/ruoyi/dz/service/impl/DzAgentServiceImpl.java

@@ -73,6 +73,7 @@ public class DzAgentServiceImpl implements IDzAgentService
         SysUser user = new SysUser();
         user.setUserId(userId);
         user.setUserName(String.valueOf(dzAgent.getAgentId()));
+        user.setUserTypeId(dzAgent.getAgentId());
         userService.updateUserInfo(user);
 
         return iRet;