|
|
@@ -0,0 +1,191 @@
|
|
|
+package com.template.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.template.annotation.PassToken;
|
|
|
+import com.template.api.SmartAuthorGroupControllerAPI;
|
|
|
+import com.template.common.utils.TimeExchange2;
|
|
|
+import com.template.common.utils.TreeRecordsUtil;
|
|
|
+import com.template.common.utils.UUIDUtil;
|
|
|
+import com.template.model.pojo.SmartAuthorGroup;
|
|
|
+import com.template.model.pojo.SmartAuthority;
|
|
|
+import com.template.model.result.CommonResult;
|
|
|
+import com.template.model.weixin.AuthorAndGroup;
|
|
|
+import com.template.model.weixin.AuthorAndGroup2;
|
|
|
+import com.template.model.weixin.AuthorListGroup;
|
|
|
+import com.template.model.weixin.userAuthor;
|
|
|
+import com.template.services.SmartAuthorGroupService;
|
|
|
+import com.template.services.SmartAuthorityService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ceshi
|
|
|
+ * @since 2023-12-04
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+public class SmartAuthorGroupController implements SmartAuthorGroupControllerAPI {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SmartAuthorGroupService smartAuthorGroupService;
|
|
|
+ @Autowired
|
|
|
+ public SmartAuthorityService smartAuthorityService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增权限组
|
|
|
+ * @param
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PassToken
|
|
|
+ public CommonResult insertSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
|
|
|
+ if (samePower==null){
|
|
|
+ return CommonResult.errorMsg("samePower不能为空");
|
|
|
+ }
|
|
|
+ // 所有管理员权限一样
|
|
|
+ if (samePower==1){
|
|
|
+ AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
|
|
|
+ SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
|
|
|
+ sa.setId((int) UUIDUtil.generateID());
|
|
|
+ String[] userId = sa.getUserId().split(",");
|
|
|
+ for (int i = 0; i < userId.length; i++) {
|
|
|
+ SmartAuthority smartAuthority = new SmartAuthority();
|
|
|
+ smartAuthority.setUserId(Integer.parseInt(userId[i]));
|
|
|
+ smartAuthority.setGroupId(sa.getId());
|
|
|
+ smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
|
|
|
+ smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
|
|
|
+ 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.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ sa.setCreateUser("admin");
|
|
|
+ sa.setUpdateUser("admin");
|
|
|
+ int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
|
|
|
+ return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
|
|
|
+ }
|
|
|
+ // 每个管理员权限不一样
|
|
|
+ if (samePower==2){
|
|
|
+ AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
|
|
|
+ SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
|
|
|
+ sa.setId((int) UUIDUtil.generateID());
|
|
|
+ List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
|
|
|
+ for (int i = 0; i < userAuthors.size(); i++) {
|
|
|
+ SmartAuthority smartAuthority = new SmartAuthority();
|
|
|
+ smartAuthority.setUserId(userAuthors.get(i).getUserId());
|
|
|
+ smartAuthority.setGroupId(sa.getId());
|
|
|
+ smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
|
|
|
+ smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
|
|
|
+ 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.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ sa.setCreateUser("admin");
|
|
|
+ sa.setUpdateUser("admin");
|
|
|
+ int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
|
|
|
+ return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
|
|
|
+ }
|
|
|
+ return CommonResult.errorMsg("参数格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新权限组
|
|
|
+ * @param
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CommonResult updateSmartAuthorGroupById(JSONObject jsonObject, Integer samePower) throws ParseException {
|
|
|
+ if (samePower==null){
|
|
|
+ return CommonResult.errorMsg("samePower不能为空");
|
|
|
+ }
|
|
|
+ // 所有管理员权限一样
|
|
|
+ if (samePower==1){
|
|
|
+ AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
|
|
|
+ SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
|
|
|
+ String[] userId = sa.getUserId().split(",");
|
|
|
+ for (int i = 0; i < userId.length; i++) {
|
|
|
+ SmartAuthority smartAuthority = smartAuthorityService.getSmartById(Integer.parseInt(userId[i]));
|
|
|
+ smartAuthority.setGroupId(sa.getId());
|
|
|
+ smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
|
|
|
+ smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
|
|
|
+ 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.updateSmartAuthority(smartAuthority);
|
|
|
+ }
|
|
|
+ int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
|
|
|
+ return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
|
|
|
+ }
|
|
|
+ // 每个管理员权限不一样
|
|
|
+ if (samePower==2){
|
|
|
+ AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
|
|
|
+ SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
|
|
|
+ List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
|
|
|
+ for (int i = 0; i < userAuthors.size(); i++) {
|
|
|
+ SmartAuthority smartAuthority = smartAuthorityService.getSmartById(userAuthors.get(i).getUserId());
|
|
|
+ smartAuthority.setUserId(userAuthors.get(i).getUserId());
|
|
|
+ smartAuthority.setGroupId(sa.getId());
|
|
|
+ smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
|
|
|
+ smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
|
|
|
+ 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(userAuthors.get(i).getDeleted());
|
|
|
+ smartAuthorityService.updateSmartAuthority(smartAuthority);
|
|
|
+ }
|
|
|
+ int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
|
|
|
+ return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
|
|
|
+ }
|
|
|
+ return CommonResult.errorMsg("参数格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看权限列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CommonResult queryAuthorListGroupList(Integer authorGroupId) {
|
|
|
+ List<SmartAuthorGroup> smartAuthorGroups = smartAuthorGroupService.getAuthorGroupList();
|
|
|
+ List<AuthorListGroup> authorListGroupList = null;
|
|
|
+ if (smartAuthorGroups.size()>0) {
|
|
|
+ authorListGroupList = TreeRecordsUtil.queryCommentTreeRecords(authorGroupId, smartAuthorGroups);
|
|
|
+ }
|
|
|
+ return CommonResult.ok(authorListGroupList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult deleteSmartAuthorGroupById(int id) {
|
|
|
+
|
|
|
+ SmartAuthorGroup data = smartAuthorGroupService.getSmartById(id);
|
|
|
+
|
|
|
+ if(data == null){
|
|
|
+ return CommonResult.fail("当前数据不存在,删除失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ int result = smartAuthorGroupService.deleteSmartAuthorGroupById(id);
|
|
|
+
|
|
|
+ return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|