|
@@ -0,0 +1,87 @@
|
|
|
|
+package com.management.platform.controller;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.entity.UserGroup;
|
|
|
|
+import com.management.platform.mapper.UserGroupMapper;
|
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
|
+import com.management.platform.service.UserGroupService;
|
|
|
|
+import com.management.platform.service.UserService;
|
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 前端控制器
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Seyason
|
|
|
|
+ * @since 2024-07-29
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/user-group")
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
+public class UserGroupController {
|
|
|
|
+
|
|
|
|
+ private final UserGroupService userGroupService;
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
|
+ private final HttpServletRequest request;
|
|
|
|
+ private final UserService userService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/addOrUpdate")
|
|
|
|
+ public HttpRespMsg addOrUpdate(UserGroup userGroup){
|
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
|
+ userGroup.setCompanyId(companyId);
|
|
|
|
+ Integer count;
|
|
|
|
+ if(userGroup.getId()==null){
|
|
|
|
+ count=userGroupService.count(new LambdaQueryWrapper<UserGroup>().eq(UserGroup::getCompanyId,companyId).eq(UserGroup::getGroupName,userGroup.getGroupName()));
|
|
|
|
+ }else {
|
|
|
|
+ count=userGroupService.count(new LambdaQueryWrapper<UserGroup>().ne(UserGroup::getId,userGroup.getId()).eq(UserGroup::getCompanyId,companyId).eq(UserGroup::getGroupName,userGroup.getGroupName()));
|
|
|
|
+ }
|
|
|
|
+ if(count>0){
|
|
|
|
+ msg.setError("分组:"+userGroup.getGroupName()+"已存在");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ userGroupService.saveOrUpdate(userGroup);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/delete")
|
|
|
|
+ public HttpRespMsg delete(Integer id){
|
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getUserGroupId, id));
|
|
|
|
+ if(count>0){
|
|
|
|
+ msg.setError("存在处于当前分组的人员,无法删除");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ if(!userGroupService.removeById(id)){
|
|
|
|
+ msg.setError("验证失败");
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/list")
|
|
|
|
+ public HttpRespMsg list(){
|
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
|
+ LambdaQueryWrapper<UserGroup> wrapper = new LambdaQueryWrapper<UserGroup>().eq(UserGroup::getCompanyId, companyId);
|
|
|
|
+ List<UserGroup> list = userGroupService.list(wrapper);
|
|
|
|
+ msg.setData(list);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|