Просмотр исходного кода

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 лет назад
Родитель
Сommit
2d87c23ef9

+ 24 - 0
src/main/java/com/template/api/SmartAuthorGroupControllerAPI.java

@@ -29,6 +29,30 @@ public interface SmartAuthorGroupControllerAPI {
     @ApiOperation(value = "编辑权限组数据", notes = "编辑权限组数据", httpMethod = "POST")
     CommonResult updateSmartAuthorGroup(@Validated @RequestBody JSONObject jsonObject, Integer samePower) throws ParseException;
 
+    @RequestMapping(value = "/addSmartAuthorGroup")
+    @ApiOperation(value = "添加权限组", notes = "添加权限组数据", httpMethod = "POST")
+    public CommonResult addSmartAuthorGroup(@Validated @RequestBody JSONObject jsonObject) throws ParseException;
+
+    @RequestMapping(value = "/delSmartAuthorGroup")
+    @ApiOperation(value = "删除权限组", notes = "删除权限组数据", httpMethod = "POST")
+    public CommonResult delSmartAuthorGroup(Integer id);
+
+    @RequestMapping(value = "/operateSmartAuthorGroupUser")
+    @ApiOperation(value = "操作管理员", notes = "操作管理员", httpMethod = "POST")
+    public CommonResult operateSmartAuthorGroupUser(Integer id, String userId) throws ParseException;
+
+    @RequestMapping(value = "/operateSmartAuthorGroupApply")
+    @ApiOperation(value = "操作管理员", notes = "操作管理员", httpMethod = "POST")
+    public CommonResult operateSmartAuthorGroupApply(Integer id, String applyId);
+
+    @RequestMapping(value = "/getSmartAuthorGroupManager")
+    @ApiOperation(value = "查看管理组编辑数据", notes = "查看管理组编辑数据", httpMethod = "POST")
+    public CommonResult getSmartAuthorGroupManager(String groupId);
+
+    @RequestMapping(value = "/operateSmartAuthorDepartment")
+    @ApiOperation(value = "修改权限组权限", notes = "修改权限组权限", httpMethod = "POST")
+    public CommonResult operateSmartAuthorDepartment(@Validated @RequestBody JSONObject jsonObject);
+
     @RequestMapping(value = "/queryUserAuthor")
     @ApiOperation(value = "查看用户个人权限", notes = "编辑权限组数据", httpMethod = "POST")
     public CommonResult queryUserAuthor(@RequestParam String userId);

+ 195 - 0
src/main/java/com/template/controller/SmartAuthorGroupController.java

@@ -365,6 +365,201 @@ public class SmartAuthorGroupController implements SmartAuthorGroupControllerAPI
         return CommonResult.errorMsg("参数格式错误");
     }
 
+    /**
+     * 新增权限组
+     *
+     * @param
+     * @param
+     * @return
+     */
+    @Override
+    @PassToken
+    @DESRespondSecret(validated = true)
+    public CommonResult addSmartAuthorGroup(JSONObject jsonObject) throws ParseException {
+        AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
+        SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
+        sa.setId((int) UUIDUtil.generateID());
+        // 相关判断
+        QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("deleted", "0");
+        queryWrapper.eq("parent_id", sa.getParentId());
+        queryWrapper.eq("name", sa.getName());
+        List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
+        if (querySmartGroup.size() > 0) {
+            return CommonResult.fail("该管理员已存在,请勿重复添加");
+        }
+        sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
+        sa.setCreateUser("admin");
+        sa.setUpdateUser("admin");
+        sa.setDeleted(0);
+        int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
+        return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
+    }
+
+    /**
+     * 删除权限组
+     *
+     * @param
+     * @param
+     * @return
+     */
+    @Override
+    @PassToken
+    @DESRespondSecret(validated = true)
+    public CommonResult delSmartAuthorGroup(Integer id) {
+        SmartAuthorGroup rns = new SmartAuthorGroup();
+        rns.setId(id);
+        rns.setDeleted(1);
+        int result = smartAuthorGroupService.updateSmartAuthorGroup(rns);
+        SmartAuthority smartAuthority = new SmartAuthority();
+        smartAuthority.setDeleted(1);
+        QueryWrapper<SmartAuthority> queryWrapperA = new QueryWrapper<>();
+        queryWrapperA.eq("group_id", id);
+        boolean m = smartAuthorityService.update(smartAuthority,queryWrapperA);
+        return result > 0 && m ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
+    }
+
+    /**
+     * 操作管理员
+     *
+     * @param
+     * @param
+     * @return
+     */
+    @Override
+    @PassToken
+    @DESRespondSecret(validated = true)
+    public CommonResult operateSmartAuthorGroupUser(Integer id, String userId) throws ParseException {
+        if (id==null){
+            return CommonResult.fail("id不能为空");
+        }
+        if (userId==null){
+            userId="";
+        }
+        SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
+        if (sa==null){
+            return CommonResult.fail("当前权限组不存在");
+        }
+        if (sa.getUserId()==null){
+            sa.setUserId("");
+        }
+        String[] oldUserId = sa.getUserId().split(",");
+        String[] newUserId = userId.split(",");
+        List<String> userList = Arrays.asList(newUserId);
+        Set<String> set = new HashSet<>(userList);
+        if (userList.size() != set.size()) {
+            return CommonResult.fail("请勿选择重复用户");
+        }
+        QueryWrapper<SmartAuthority> queryWrapperA = new QueryWrapper<>();
+        List<String> typeList = Arrays.asList(newUserId);
+        queryWrapperA.in("user_id", typeList);
+        queryWrapperA.eq("deleted", 0);
+        queryWrapperA.ne("group_id", sa.getId());
+        List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapperA);
+        if (querySmart.size() > 0) {
+            return CommonResult.fail("该用户已分配其他权限组");
+        }
+        QueryWrapper<SmartUser> queryWrapperB = new QueryWrapper<>();
+        List<String> users = Arrays.asList(newUserId);
+        queryWrapperB.in("id", users);
+        queryWrapperB.eq("deleted", 0);
+        List<SmartUser> ulist = smartUserService.list(queryWrapperB);
+        if (ulist.isEmpty() || ulist.size()!=newUserId.length){
+            return CommonResult.fail("有用户已删除");
+        }
+        for (int i = 0; i < oldUserId.length; i++) {
+            if (!oldUserId[i].equals("") && !userList.contains(oldUserId[i])) {
+                QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
+                queryWrapper1.eq("deleted", 0);
+                queryWrapper1.eq("user_id", Integer.parseInt(oldUserId[i]));
+                List<SmartAuthority> smartAuthority1 = smartAuthorityService.getAuthorByKey(queryWrapper1);
+                if (smartAuthority1.size() > 0) {
+                    SmartAuthority smartAuthority = smartAuthority1.get(0);
+                    smartAuthority.setDeleted(1);
+                    smartAuthorityService.updateSmartAuthority(smartAuthority);
+                }
+            }
+        }
+        for (int i = 0; i < newUserId.length; i++) {
+            if (!newUserId[i].equals("")){
+                QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
+                queryWrapper2.eq("deleted", 0);
+                queryWrapper2.eq("user_id", Integer.parseInt(newUserId[i]));
+                List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper2);
+                if (smartAuthoritys.size() <= 0) {
+                    SmartAuthority smartAuthority = new SmartAuthority();
+                    smartAuthority.setUserId(Integer.parseInt(newUserId[i]));
+                    smartAuthority.setGroupId(sa.getId());
+                    smartAuthority.setDepartmentView("");
+                    smartAuthority.setDepartmentManage("");
+                    smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
+                    smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
+                    smartAuthority.setCreateUser("admin");
+                    smartAuthority.setUpdateUser("admin");
+                    smartAuthority.setDeleted(0);
+                    smartAuthorityService.insertSmartAuthority(smartAuthority);
+                }
+            }
+        }
+        sa.setUserId(userId);
+        int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
+        return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+    }
+
+    /**
+     * 操作菜单权限
+     *
+     * @param
+     * @param
+     * @return
+     */
+    @Override
+    @PassToken
+    @DESRespondSecret(validated = true)
+    public CommonResult operateSmartAuthorGroupApply(Integer id, String applyId) {
+        if (id==null){
+            return CommonResult.fail("id不能为空");
+        }
+        if (applyId==null){
+            applyId="";
+        }
+        SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
+        if (sa==null){
+            return CommonResult.fail("当前权限组不存在");
+        }
+        sa.setApplyId(applyId);
+        int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
+        return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+    }
+
+    @PassToken
+    @Override
+    @DESRespondSecret(validated = false)
+    public CommonResult getSmartAuthorGroupManager(String groupId) {
+        List<SmartAuthorGroupManager> list = smartAuthorGroupService.getSmartAuthorGroupManager(groupId);
+        return CommonResult.ok(list);
+    }
+
+    @PassToken
+    @Override
+    public CommonResult operateSmartAuthorDepartment(JSONObject jsonObject) {
+        Integer id = jsonObject.getInteger("id");
+        String departmentView = jsonObject.getString("departmentView");
+        String departmentManage = jsonObject.getString("departmentManage");
+        if (id==null){
+            return CommonResult.fail("请传入ID");
+        }
+        SmartAuthority smartAuthority = smartAuthorityService.getSmartById(id);
+        if (departmentView!=null ){
+            smartAuthority.setDepartmentView(departmentView);
+        }
+        if (departmentManage!=null){
+            smartAuthority.setDepartmentManage(departmentManage);
+        }
+        smartAuthorityService.updateSmartAuthority(smartAuthority);
+        return CommonResult.ok("修改成功");
+    }
+
     @PassToken
     @Override
     @DESRespondSecret(validated = true)

+ 3 - 0
src/main/java/com/template/mapper/SmartAuthorGroupMapper.java

@@ -2,6 +2,7 @@ package com.template.mapper;
 
 import com.template.model.pojo.SmartAuthorGroup;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.template.model.pojo.SmartAuthorGroupManager;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -20,4 +21,6 @@ public interface SmartAuthorGroupMapper extends BaseMapper<SmartAuthorGroup> {
 
     List<SmartAuthorGroup> smartAuthorGroup(@Param("userId") Integer userId);
 
+    List<SmartAuthorGroupManager> getSmartAuthorGroupManager(@Param("groupId") String groupId);
+
 }

+ 27 - 0
src/main/java/com/template/model/pojo/SmartAuthorGroupManager.java

@@ -0,0 +1,27 @@
+package com.template.model.pojo;
+
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="SmartAuthorGroupManager", description="")
+public class SmartAuthorGroupManager {
+
+    public Integer id;
+    public String groupId;
+    public String userId;
+    public String cardNo;
+    public String userName;
+    public String departmentManage;
+    public String departmentView;
+    public List<JSONObject> departmentManageJson;
+    public List<JSONObject> departmentViewJson;
+
+}

+ 4 - 0
src/main/java/com/template/services/SmartAuthorGroupService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.template.model.pojo.SmartAuthorGroupManager;
 import com.template.model.result.PageUtils;
 import com.template.model.weixin.AuthorListGroup;
 
@@ -35,4 +36,7 @@ public interface SmartAuthorGroupService extends IService<SmartAuthorGroup> {
     List<SmartAuthorGroup> smartAuthorGroup(Integer userId);
 
     public List<AuthorListGroup> queryCommentTreeRecords(Integer pid, List<SmartAuthorGroup> lists);
+
+    public List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId);
+
 }

+ 44 - 3
src/main/java/com/template/services/impl/SmartAuthorGroupServiceImpl.java

@@ -5,11 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.template.mapper.*;
-import com.template.model.pojo.SmartApply;
-import com.template.model.pojo.SmartAuthorGroup;
+import com.template.model.pojo.*;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.template.mapper.SmartAuthorGroupMapper;
-import com.template.model.pojo.SmartUser;
 import com.template.model.result.PageUtils;
 import com.template.model.weixin.AuthorListGroup;
 import com.template.services.SmartAuthorGroupService;
@@ -39,6 +37,8 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
     public SmartUserMapper smartUserMapper;
     @Autowired
     public SmartApplyMapper smartApplyMapper;
+    @Autowired
+    public SmartDepartmentMapper smartDepartmentMapper;
 
     @Override
     public int insertSmartAuthorGroup(SmartAuthorGroup sa) {
@@ -135,4 +135,45 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
         }
         return newTrees;
     }
+
+    @Override
+    public List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId){
+        List<SmartAuthorGroupManager> list = smartAuthorGroupMapper.getSmartAuthorGroupManager(groupId);
+        if (list.size()>0){
+            for (int i = 0; i < list.size(); i++) {
+                SmartAuthorGroupManager smartAuthorGroupManager = list.get(i);
+                if (smartAuthorGroupManager.getDepartmentManage()!=null && !smartAuthorGroupManager.getDepartmentManage().equals("")){
+                    String[] manageId = smartAuthorGroupManager.getDepartmentManage().split(",");
+                    QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
+                    queryWrapper1.eq("deleted", 0);
+                    queryWrapper1.in("id", Arrays.asList(manageId));
+                    List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
+                    List<JSONObject> departmentManageJson = new ArrayList<>();
+                    for (int j = 0; j < list1.size(); j++) {
+                        JSONObject jsonObject1 = new JSONObject();
+                        jsonObject1.put("id", list1.get(i).getId());
+                        jsonObject1.put("name", list1.get(i).getName());
+                        departmentManageJson.add(jsonObject1);
+                    }
+                    list.get(i).setDepartmentManageJson(departmentManageJson);
+                }
+                if (smartAuthorGroupManager.getDepartmentView()!=null && !smartAuthorGroupManager.getDepartmentView().equals("")){
+                    String[] viewId = smartAuthorGroupManager.getDepartmentView().split(",");
+                    QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
+                    queryWrapper1.eq("deleted", 0);
+                    queryWrapper1.in("id", Arrays.asList(viewId));
+                    List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
+                    List<JSONObject> departmentViewJson = new ArrayList<>();
+                    for (int j = 0; j < list1.size(); j++) {
+                        JSONObject jsonObject1 = new JSONObject();
+                        jsonObject1.put("id", list1.get(i).getId());
+                        jsonObject1.put("name", list1.get(i).getName());
+                        departmentViewJson.add(jsonObject1);
+                    }
+                    list.get(i).setDepartmentViewJson(departmentViewJson);
+                }
+            }
+        }
+        return list;
+    }
 }

+ 16 - 0
src/main/resources/mapper/template/SmartAuthorGroupMapper.xml

@@ -8,6 +8,16 @@
         <result property="userId" column="user_id"/>
         <result property="applyId" column="apply_id"/>
     </resultMap>
+
+    <resultMap type="com.template.model.pojo.SmartAuthorGroupManager" id="smartAuthorGroupManager">
+        <result property="groupId" column="group_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="cardNo" column="card_no"/>
+        <result property="userName" column="user_name"/>
+        <result property="departmentManage" column="department_manage"/>
+        <result property="departmentView" column="department_view"/>
+    </resultMap>
+
     <select id="smartAuthorGroup" resultType="com.template.model.pojo.SmartAuthorGroup" resultMap="smartAuthorGroupMap">
         SELECT * FROM `smart_author_group`
         where deleted = 0
@@ -15,4 +25,10 @@
             and FIND_IN_SET(#{userId},user_id)
         </if>
     </select>
+
+    <select id="getSmartAuthorGroupManager" resultType="com.template.model.pojo.SmartAuthorGroupManager" resultMap="smartAuthorGroupManager">
+        select a.`id`,a.`group_id`,a.`user_id`,b.card_no,b.`name` as user_name,a.`department_manage`,a.`department_view`
+            from `smart_authority` a left join `smart_user` b on a.`user_id`=b.id
+            where group_id=#{groupId}
+    </select>
 </mapper>