FengChaoYu il y a 3 semaines
Parent
commit
82644f0ade

+ 1 - 1
src/main/java/com/gree/mall/manager/bean/admin/AdminUserCom.java

@@ -20,7 +20,7 @@ public class AdminUserCom extends AdminUser {
     @ApiModelProperty("商家集合")
     private List<String> adminWebsitIds;
 
-    @ApiModelProperty("部门集合(没有逻辑)")
+    @ApiModelProperty("部门集合")
     private List<String> adminDeptIds;
 
     @ApiModelProperty("只读帐号(没有逻辑)")

+ 4 - 1
src/main/java/com/gree/mall/manager/bean/admin/reqDto/AdminUserAddReqBean.java

@@ -13,6 +13,9 @@ import java.util.List;
 @ApiModel(value="AdminUserAddBean对象", description="新增用户对象")
 public class AdminUserAddReqBean extends AdminUser {
 
-    @ApiModelProperty("数据权限集合")
+    @ApiModelProperty("部门集合")
+    private List<AdminUserPermissions> deptList;
+
+    @ApiModelProperty("商家权限集合")
     private List<AdminUserPermissions> permissions;
 }

+ 6 - 8
src/main/java/com/gree/mall/manager/controller/admin/AdminDeptController.java

@@ -10,7 +10,6 @@ import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.helper.ResponseHelper;
 import com.gree.mall.manager.logic.admin.AdminDeptLogic;
 import com.gree.mall.manager.plus.entity.AdminDept;
-import com.gree.mall.manager.plus.entity.AdminDeptWebsit;
 import com.gree.mall.manager.utils.excel.ExcelUtils;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
@@ -18,7 +17,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -46,12 +44,12 @@ public class AdminDeptController {
         return ResponseHelper.success(tree);
     }
 
-//    @GetMapping("/treeWebsit")
-//    @ApiOperation("部门树合并网点")
-//    public ResponseHelper<AdminDeptTree> treeWebsit(HttpServletRequest request) {
-//        List<AdminDeptTree> tree = adminDeptLogic.treeWebsit(request);
-//        return ResponseHelper.success(tree);
-//    }
+    @GetMapping("/treeWebsit")
+    @ApiOperation("部门树合并网点")
+    public ResponseHelper<AdminDeptTree> treeWebsit(HttpServletRequest request) {
+        List<AdminDeptTree> tree = adminDeptLogic.treeWebsit(request);
+        return ResponseHelper.success(tree);
+    }
 
 
     @ZfireList

+ 39 - 23
src/main/java/com/gree/mall/manager/logic/admin/AdminUserLogic.java

@@ -173,16 +173,10 @@ public class AdminUserLogic {
     @Transactional
     public void save(AdminUserAddReqBean adminUser, HttpServletRequest request) throws RemoteServiceException {
 
-        boolean isAdd = true;
-        if (StringUtils.isNotBlank(adminUser.getAdminUserId())) {
-            isAdd = false;
-        }
+        boolean isAdd = !StringUtils.isNotBlank(adminUser.getAdminUserId());
 
         AdminUserCom curLoginAmin = commonLogic.getAdminUser(request);
 
-        // 检查账号参数
-        this.checkCreateAdminUserParams(adminUser, curLoginAmin, isAdd);
-
         if (StringUtils.isEmpty(adminUser.getUserName())
                 || (isAdd && StringUtils.isEmpty(adminUser.getPassword()))) {
             throw new RemoteServiceException("参数错误");
@@ -195,13 +189,13 @@ public class AdminUserLogic {
             throw new RemoteServiceException("帐号已被注册");
         }
 
-        if (isAdd) {
-            // 新增账号产生id
-            adminUser.setAdminUserId(IdWorker.getIdStr());
-        }
+        // 检查账号参数
+        this.checkCreateAdminUserParams(adminUser, curLoginAmin, isAdd);
 
         // 数据权限
-        this.dataPermissionsHandle(adminUser, adminUser.getPermissions());
+        if (!"admin".equals(adminUser.getUserName())) {
+            this.dataPermissionsHandle(adminUser, adminUser.getPermissions(), adminUser.getDeptList());
+        }
 
         if (isAdd || StringUtils.isNotBlank(adminUser.getPassword())) {
             adminUser.setPassword(MD5Utils.md5(adminUser.getPassword()));
@@ -211,6 +205,11 @@ public class AdminUserLogic {
     }
 
     private void checkCreateAdminUserParams(AdminUserAddReqBean adminUser, AdminUserCom curLoginAmin, boolean isAdd) {
+        if (!isAdd
+                && adminUser.getAdminUserId().equals(curLoginAmin.getAdminUserId())
+                && curLoginAmin.getUserName().equals("admin")) {
+            throw new RemoteServiceException("不允许修改账号");
+        }
         // 检查账号类型
         if (curLoginAmin.getType() == 2 || curLoginAmin.getType() == 4) {
             // 如果创建人账号是商家, 所建账号为“商家类型”
@@ -218,12 +217,18 @@ public class AdminUserLogic {
                 // 新增账号设值4=商家
                 adminUser.setType(4);
             }
+            if (CollectionUtil.isEmpty(adminUser.getPermissions())) {
+                throw new RemoteServiceException("账号类型为“商家账号”, 请选择至少1个商家");
+            }
         } else if (curLoginAmin.getType() == 1 || curLoginAmin.getType() == 3) {
             // 如果创建人账号是商户, 所建账号为“商户类型”或“商家类型”
             if (adminUser.getType() == 0) {
                 // 创建人账号不能选择平台
                 throw new RemoteServiceException("创建者不能选择账号类型为“平台账号”");
             }
+            if (CollectionUtil.isEmpty(adminUser.getDeptList()) && CollectionUtil.isEmpty(adminUser.getPermissions())) {
+                throw new RemoteServiceException("账号类型为“商户账号”, 请选择至少1个部门或者1个商家");
+            }
         }
         // 检查角色
         AdminRole addUserRole;
@@ -245,31 +250,29 @@ public class AdminUserLogic {
         }
 
         adminUser.setRoleName(addUserRole.getName());
-    }
-
-    private void dataPermissionsHandle(AdminUserAddReqBean adminUser, List<AdminUserPermissions> permissions) {
-        if (CollectionUtil.isEmpty(permissions)) {
-            throw new RemoteServiceException("请选择至少1个数据权限");
+        if (isAdd) {
+            // 新增账号产生id
+            adminUser.setAdminUserId(IdWorker.getIdStr());
         }
+    }
 
-        final List<String> deptList = permissions.stream()
-                .filter(AdminUserPermissions::getIsDept)
+    private void dataPermissionsHandle(AdminUserAddReqBean adminUser, List<AdminUserPermissions> permissions, List<AdminUserPermissions> deptList) {
+        final List<String> deptIdList = deptList.stream()
                 .map(AdminUserPermissions::getAdminUserPermissionsId)
                 .collect(Collectors.toList());
 
         List<AdminDept> deptExistList = new ArrayList<>();
-        if (CollectionUtil.isNotEmpty(deptList)) {
+        if (CollectionUtil.isNotEmpty(deptIdList)) {
             deptExistList = adminDeptService.lambdaQuery()
-                    .in(AdminDept::getAdminDeptId, deptList)
+                    .in(AdminDept::getAdminDeptId, deptIdList)
                     .list();
 
-            if (deptExistList.size() < deptList.size()) {
+            if (deptExistList.size() < deptIdList.size()) {
                 throw new RemoteServiceException("选择里有异常部门");
             }
         }
 
         final List<String> websitList = permissions.stream()
-                .filter(v -> !v.getIsDept())
                 .map(AdminUserPermissions::getAdminUserPermissionsId)
                 .collect(Collectors.toList());
 
@@ -449,7 +452,20 @@ public class AdminUserLogic {
         final List<AdminUserPermissionsRela> permissionsRelas = adminUserPermissionsRelaService.lambdaQuery()
                 .eq(AdminUserPermissionsRela::getAdminUserId, adminUser.getAdminUserId())
                 .list();
+
+        final List<String> deptList = permissionsRelas.stream()
+                .filter(AdminUserPermissionsRela::getIsDept)
+                .map(AdminUserPermissionsRela::getAdminUserPermissionsId)
+                .collect(Collectors.toList());
+
+        final List<String> websitList = permissionsRelas.stream()
+                .filter(v -> !v.getIsDept())
+                .map(AdminUserPermissionsRela::getAdminUserPermissionsId)
+                .collect(Collectors.toList());
+
         adminUserBean.setPermissions(permissionsRelas);
+        adminUserBean.setAdminDeptIds(deptList);
+        adminUserBean.setAdminWebsitIds(websitList);
 
         return adminUserBean;
     }