| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.GroupMenu; |
| | | import com.moral.api.entity.UserGroup; |
| | | import com.moral.api.mapper.GroupMapper; |
| | | import com.moral.api.mapper.GroupMenuMapper; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.service.GroupService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.ConvertUtils; |
| | | import com.moral.util.TokenUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService { |
| | | |
| | | @Autowired |
| | | private GroupMapper groupMapper; |
| | | |
| | | @Autowired |
| | | private GroupMenuMapper groupMenuMapper; |
| | | |
| | | @Autowired |
| | | private UserGroupMapper userGroupMapper; |
| | | |
| | | @Autowired |
| | | private OperationLogUtils operationLogUtils; |
| | | |
| | | @Override |
| | | public Map<String, Object> addGroup(Group group) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | Integer orgId = (Integer) orgInfo.get("id"); |
| | | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("group_name", group.getGroupName()) |
| | | .eq("organization_id", orgId) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | if (groupMapper.selectOne(queryWrapper) != null) { |
| | | result.put("code", ResponseCodeEnum.GROUP_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.GROUP_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | group.setOrganizationId(orgId); |
| | | groupMapper.insert(group); |
| | | |
| | | //日志 |
| | | String content = "添加了组:" + group.getGroupName(); |
| | | operationLogUtils.insertLog(content, Constants.INSERT_OPERATE_TYPE); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteGroup(Integer id) { |
| | | //逻辑删除group |
| | | UpdateWrapper<Group> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", id).set("is_delete", Constants.DELETE); |
| | | groupMapper.update(null, updateWrapper); |
| | | //删除group_menu |
| | | UpdateWrapper<GroupMenu> deleteGroupWrapper = new UpdateWrapper<>(); |
| | | deleteGroupWrapper.eq("group_id", id); |
| | | groupMenuMapper.delete(deleteGroupWrapper); |
| | | //删除user_group |
| | | UpdateWrapper<UserGroup> deleteUserGroupWrapper = new UpdateWrapper<>(); |
| | | deleteUserGroupWrapper.eq("group_id", id); |
| | | userGroupMapper.delete(deleteUserGroupWrapper); |
| | | //日志 |
| | | String content = "删除了组:" + groupMapper.selectById(id).getGroupName(); |
| | | operationLogUtils.insertLog(content, Constants.DELETE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> updateGroup(Group group) { |
| | | String before = groupMapper.selectById(group.getId()).getGroupName(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | Integer orgId = (Integer) orgInfo.get("id"); |
| | | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.ne("id", group.getId()) |
| | | .eq("group_name", group.getGroupName()) |
| | | .eq("is_delete", Constants.NOT_DELETE) |
| | | .eq("organization_id", orgId); |
| | | if (groupMapper.selectOne(queryWrapper) != null) { |
| | | result.put("code", ResponseCodeEnum.GROUP_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.GROUP_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | group.setOrganizationId(orgId); |
| | | groupMapper.updateById(group); |
| | | //日志 |
| | | String content = "修改了组:" + before + "=>" + group.getGroupName(); |
| | | operationLogUtils.insertLog(content, Constants.UPDATE_OPERATE_TYPE); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Page<Group> selectGroups(Map<String, Object> parameters) { |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); |
| | | Integer orgId = (Integer) orgInfo.get("id"); |
| | | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("organization_id", orgId) |
| | | .eq("is_delete", Constants.NOT_DELETE) |
| | | .ne("group_name", "admin"); |
| | | Object order = parameters.get("order"); |
| | | Object orderType = parameters.get("orderType"); |
| | | Object groupName = parameters.get("groupName"); |
| | | //模糊查询参数 |
| | | if (groupName != null) { |
| | | queryWrapper.like("group_name", groupName); |
| | | } |
| | | |
| | | int page = Integer.parseInt(parameters.get("page").toString()); |
| | | int size = Integer.parseInt(parameters.get("size").toString()); |
| | | Page<Group> pageData = new Page<>(page, size); |
| | | //排序参数,默认create_time降序 |
| | | if (order != null && orderType != null) { |
| | | if (Constants.ORDER_ASC.equals(orderType)) { |
| | | queryWrapper.orderByAsc(ConvertUtils.toLine(order.toString())); |
| | | } else { |
| | | queryWrapper.orderByDesc(ConvertUtils.toLine(order.toString())); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByDesc("create_time"); |
| | | } |
| | | groupMapper.selectPage(pageData, queryWrapper); |
| | | return pageData; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getGroup(Integer userId) { |
| | | return groupMapper.selectUserGroup(userId); |
| | | } |
| | | } |