|
|
@@ -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)
|