| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package com.template.services.impl;
- import com.alibaba.fastjson.JSONObject;
- 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.*;
- import com.template.model.pojo.SmartAuthorGroup;
- import com.template.mapper.SmartAuthorGroupMapper;
- import com.template.model.result.PageUtils;
- import com.template.model.weixin.AuthorListGroup;
- import com.template.services.SmartAuthorGroupService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.StringUtils;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author ceshi
- * @since 2023-12-04
- */
- @Service
- public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMapper, SmartAuthorGroup> implements SmartAuthorGroupService {
- @Autowired
- private SmartAuthorGroupMapper smartAuthorGroupMapper;
- @Autowired
- public SmartUserMapper smartUserMapper;
- @Autowired
- public SmartApplyMapper smartApplyMapper;
- @Autowired
- public SmartDepartmentMapper smartDepartmentMapper;
- @Override
- public int insertSmartAuthorGroup(SmartAuthorGroup sa) {
- int result = smartAuthorGroupMapper.insert(sa);
- return result;
- }
- @Override
- public int updateSmartAuthorGroup(SmartAuthorGroup sa) {
- int result = smartAuthorGroupMapper.updateById(sa);
- return result;
- }
- @Override
- public PageUtils<SmartAuthorGroup> queryPageSmartAuthorGroups(int currentPage, int pageCount, String name) {
- Page<SmartAuthorGroup> page = new Page<>(currentPage, pageCount);
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- //queryWrapper.like(StringUtils.hasText(name), "name", name);
- IPage<SmartAuthorGroup> result = smartAuthorGroupMapper.selectPage(page,queryWrapper);
- return new PageUtils<>(result);
- }
- @Override
- public int deleteSmartAuthorGroupById(int id) {
- int result = smartAuthorGroupMapper.deleteById(id);
- return result;
- }
- @Override
- public SmartAuthorGroup getSmartById(int id) {
- SmartAuthorGroup result = smartAuthorGroupMapper.selectById(id);
- return result;
- }
- @Override
- public List<SmartAuthorGroup> getAuthorGroupList() {
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", 0);
- List<SmartAuthorGroup> result = smartAuthorGroupMapper.selectList(queryWrapper);
- return result;
- }
- @Override
- public List<SmartAuthorGroup> getAuthorGroupByKey(QueryWrapper<SmartAuthorGroup> queryWrapper) {
- List<SmartAuthorGroup> result = smartAuthorGroupMapper.selectList(queryWrapper);
- return result;
- }
- @Override
- public List<SmartAuthorGroup> smartAuthorGroup(Integer userId){
- List<SmartAuthorGroup> result = smartAuthorGroupMapper.smartAuthorGroup(userId);
- return result;
- }
- @Override
- public List<AuthorListGroup> queryCommentTreeRecords(Integer pid, List<SmartAuthorGroup> lists) {
- List<AuthorListGroup> newTrees = new ArrayList<>();
- List<SmartAuthorGroup> datas = lists.stream().filter(e -> e.getParentId().equals(pid)).collect(Collectors.toList());
- for (SmartAuthorGroup data : datas) {
- QueryWrapper<SmartUser> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("deleted", 0);
- List<String> userIds = Arrays.asList(data.getUserId().split(","));
- queryWrapper1.in("id", userIds);
- List<SmartUser> list1 = smartUserMapper.selectList(queryWrapper1);
- JSONObject jsonObject1 = new JSONObject();
- jsonObject1.put("data", list1);
- QueryWrapper<SmartApply> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("deleted", 0);
- List<String> applyIds = Arrays.asList(data.getApplyId().split(","));
- queryWrapper2.in("id", applyIds);
- List<SmartApply> list2 = smartApplyMapper.selectList(queryWrapper2);
- JSONObject jsonObject2 = new JSONObject();
- jsonObject2.put("data", list2);
- AuthorListGroup item = AuthorListGroup.builder()
- .id(data.getId())
- .parentId(data.getParentId())
- .name(data.getName())
- .userId(jsonObject1.toJSONString())
- .applyId(jsonObject2.toJSONString())
- .updateTime(data.getUpdateTime())
- .createUser(data.getCreateUser())
- .updateUser(data.getUpdateUser())
- .deleted(data.getDeleted())
- .build();
- List<AuthorListGroup> news = queryCommentTreeRecords(item.getId(), lists);
- if (news == null || news.size() == 0) {
- newTrees.add(item);
- continue;
- } else {
- item.setAuthorListGroups(news);
- newTrees.add(item);
- }
- }
- 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<>();
- if (list1.size()>0){
- 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<>();
- if (list1.size()>0){
- 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;
- }
- }
|