dongxin 1 год назад
Родитель
Сommit
643e886794

+ 7 - 34
src/main/java/com/ydtech/modules/admin/controller/SysChannelGradeController.java

@@ -1,23 +1,14 @@
 package com.ydtech.modules.admin.controller;
 package com.ydtech.modules.admin.controller;
 
 
-import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageResult;
 import com.ydtech.core.page.PageResult;
 import com.ydtech.modules.admin.constants.UserConstants;
 import com.ydtech.modules.admin.constants.UserConstants;
-import com.ydtech.modules.admin.model.SysArea;
+import com.ydtech.modules.admin.model.SysDept;
 import com.ydtech.modules.admin.model.po.*;
 import com.ydtech.modules.admin.model.po.*;
 import com.ydtech.modules.admin.model.vo.*;
 import com.ydtech.modules.admin.model.vo.*;
-import com.ydtech.modules.admin.service.SysAreaService;
-import com.ydtech.modules.admin.service.SysChannelAreaRelationService;
-import com.ydtech.modules.admin.service.SysChannelGradeService;
-import com.ydtech.modules.admin.service.SysChannelGroupInfoService;
-import com.ydtech.modules.admin.service.impl.SysAreaServiceImpl;
-import com.ydtech.modules.admin.service.impl.SysChannelAreaRelationServiceImpl;
-import com.ydtech.modules.admin.service.impl.SysChannelGroupInfoServiceImpl;
-import com.ydtech.modules.admin.service.impl.SysChannelGroupServiceImpl;
+import com.ydtech.modules.admin.service.*;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.protocol.utils.AssertionUtils;
 import com.ydtech.modules.protocol.utils.AssertionUtils;
 import com.ydtech.utils.JudgeUtils;
 import com.ydtech.utils.JudgeUtils;
@@ -25,7 +16,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.validation.Valid;
 import javax.validation.Valid;
@@ -40,11 +30,9 @@ public class SysChannelGradeController  extends BaseController {
     @Autowired
     @Autowired
     private SysChannelGradeService sysChannelGradeService;
     private SysChannelGradeService sysChannelGradeService;
     @Autowired
     @Autowired
-    private SysAreaService sysAreaService;
+    private SysDeptService sysDeptService;
     @Autowired
     @Autowired
     private SysChannelGroupInfoService sysChannelGroupInfoService;
     private SysChannelGroupInfoService sysChannelGroupInfoService;
-    @Autowired
-    private SysChannelAreaRelationService sysChannelAreaRelationService;
 
 
     @PostMapping(value = "/queryList")
     @PostMapping(value = "/queryList")
     @ApiOperation(value = "渠道分组列表")
     @ApiOperation(value = "渠道分组列表")
@@ -134,31 +122,16 @@ public class SysChannelGradeController  extends BaseController {
     public HttpResult authorized(@RequestBody @Valid AuthSysChannelGradeVo authSysChannelGradeVo) {
     public HttpResult authorized(@RequestBody @Valid AuthSysChannelGradeVo authSysChannelGradeVo) {
         // 查询该机构是否有授权
         // 查询该机构是否有授权
         List<String> areaIdList = authSysChannelGradeVo.getAreaIdList();
         List<String> areaIdList = authSysChannelGradeVo.getAreaIdList();
-        if(CollUtil.isEmpty(areaIdList)){
-            // 删除所有已经授权机构
-            QueryWrapper<SysChannelAreaRelation> wrapper = new QueryWrapper<>();
-            LambdaQueryWrapper<SysChannelAreaRelation> lqw = new LambdaQueryWrapper<>();
-            lqw.eq(SysChannelAreaRelation::getGradeId, authSysChannelGradeVo.getId());
-            sysChannelAreaRelationService.remove(wrapper);
-            return HttpResult.ok("授权成功");
-        }
-
         LambdaQueryWrapper<SysChannelGrade> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<SysChannelGrade> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.in(SysChannelGrade::getId, areaIdList);
         queryWrapper.in(SysChannelGrade::getId, areaIdList);
         long count = sysChannelGradeService.count(queryWrapper);
         long count = sysChannelGradeService.count(queryWrapper);
         AssertionUtils.isFail(count > 0,"已授权的机构不能重复授权");
         AssertionUtils.isFail(count > 0,"已授权的机构不能重复授权");
 
 
-        LambdaQueryWrapper<SysArea> areaWrapper = new LambdaQueryWrapper<>();
-        areaWrapper.in(SysArea::getId, areaIdList);
-        List<SysArea> areas = sysAreaService.list(areaWrapper);
-        AssertionUtils.isFail(areas.size() > 0, "勾选机构不存在");
+        LambdaQueryWrapper<SysDept> areaWrapper = new LambdaQueryWrapper<>();
+        areaWrapper.in(SysDept::getId, areaIdList);
+        List<SysDept> areas = sysDeptService.list(areaWrapper);
+        AssertionUtils.isFail(areas.size() <= 0, "勾选机构不存在");
 
 
-        for (int i = 0; i < areas.size(); i++) {
-            LambdaQueryWrapper<SysArea> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(SysArea::getUpperCode, areas.get(i).getAreaCode());
-            long areaCount = sysAreaService.count(wrapper);
-            AssertionUtils.isFail(areaCount <= 0,"非末级机构,不允许授权!");
-        }
         sysChannelGradeService.authArea(authSysChannelGradeVo);
         sysChannelGradeService.authArea(authSysChannelGradeVo);
         return HttpResult.ok("授权成功");
         return HttpResult.ok("授权成功");
     }
     }

+ 17 - 9
src/main/java/com/ydtech/modules/admin/service/impl/SysChannelGradeServiceImpl.java

@@ -64,19 +64,20 @@ public class SysChannelGradeServiceImpl extends ServiceImpl<SysChannelGradeMappe
     @Transactional
     @Transactional
     public void authArea(AuthSysChannelGradeVo authSysChannelGradeVo) {
     public void authArea(AuthSysChannelGradeVo authSysChannelGradeVo) {
         // 删除所有已经授权机构
         // 删除所有已经授权机构
-        QueryWrapper<SysChannelAreaRelation> wrapper = new QueryWrapper<>();
         LambdaQueryWrapper<SysChannelAreaRelation> lqw = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<SysChannelAreaRelation> lqw = new LambdaQueryWrapper<>();
         lqw.eq(SysChannelAreaRelation::getGradeId, authSysChannelGradeVo.getId());
         lqw.eq(SysChannelAreaRelation::getGradeId, authSysChannelGradeVo.getId());
-        sysChannelAreaRelationService.remove(wrapper);
+        sysChannelAreaRelationService.remove(lqw);
         List<String> areaIdList = authSysChannelGradeVo.getAreaIdList();
         List<String> areaIdList = authSysChannelGradeVo.getAreaIdList();
         List<SysChannelAreaRelation> relations = new ArrayList<>();
         List<SysChannelAreaRelation> relations = new ArrayList<>();
-        for (String areaId : areaIdList) {
-            SysChannelAreaRelation sysChannelAreaRelation = new SysChannelAreaRelation();
-            sysChannelAreaRelation.setGradeId(authSysChannelGradeVo.getId());
-            sysChannelAreaRelation.setAreaId(areaId);
-            relations.add(sysChannelAreaRelation);
+        if (CollUtil.isNotEmpty(areaIdList)) {
+            for (String areaId : areaIdList) {
+                SysChannelAreaRelation sysChannelAreaRelation = new SysChannelAreaRelation();
+                sysChannelAreaRelation.setGradeId(authSysChannelGradeVo.getId());
+                sysChannelAreaRelation.setAreaId(areaId);
+                relations.add(sysChannelAreaRelation);
+            }
+            sysChannelAreaRelationService.saveBatch(relations);
         }
         }
-        sysChannelAreaRelationService.saveBatch(relations);
     }
     }
 
 
     @Override
     @Override
@@ -115,7 +116,14 @@ public class SysChannelGradeServiceImpl extends ServiceImpl<SysChannelGradeMappe
     @Override
     @Override
     public List<SysChannelAreaRelation> queryRelation(SysChannelVo sysChannelVo) {
     public List<SysChannelAreaRelation> queryRelation(SysChannelVo sysChannelVo) {
         List<SysChannelAreaRelation> relationList = sysChannelAreaRelationService.queryRelationList(sysChannelVo);
         List<SysChannelAreaRelation> relationList = sysChannelAreaRelationService.queryRelationList(sysChannelVo);
-        return relationList;
+        if(CollUtil.isEmpty(relationList)){
+            return relationList;
+        }else{
+            for (SysChannelAreaRelation sysChannelAreaRelation : relationList) {
+                sysChannelAreaRelation.setName(sysChannelAreaRelation.getName() + "--" + sysChannelAreaRelation.getAreaId());
+            }
+            return relationList;
+        }
     }
     }
 
 
     @Override
     @Override