SmartAuthorGroupServiceImpl.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.template.services.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.template.mapper.*;
  7. import com.template.model.pojo.*;
  8. import com.template.model.pojo.SmartAuthorGroup;
  9. import com.template.mapper.SmartAuthorGroupMapper;
  10. import com.template.model.result.PageUtils;
  11. import com.template.model.weixin.AuthorListGroup;
  12. import com.template.services.SmartAuthorGroupService;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.util.StringUtils;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import java.util.stream.Collectors;
  21. /**
  22. * <p>
  23. * 服务实现类
  24. * </p>
  25. *
  26. * @author ceshi
  27. * @since 2023-12-04
  28. */
  29. @Service
  30. public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMapper, SmartAuthorGroup> implements SmartAuthorGroupService {
  31. @Autowired
  32. private SmartAuthorGroupMapper smartAuthorGroupMapper;
  33. @Autowired
  34. public SmartUserMapper smartUserMapper;
  35. @Autowired
  36. public SmartApplyMapper smartApplyMapper;
  37. @Autowired
  38. public SmartDepartmentMapper smartDepartmentMapper;
  39. @Override
  40. public int insertSmartAuthorGroup(SmartAuthorGroup sa) {
  41. int result = smartAuthorGroupMapper.insert(sa);
  42. return result;
  43. }
  44. @Override
  45. public int updateSmartAuthorGroup(SmartAuthorGroup sa) {
  46. int result = smartAuthorGroupMapper.updateById(sa);
  47. return result;
  48. }
  49. @Override
  50. public PageUtils<SmartAuthorGroup> queryPageSmartAuthorGroups(int currentPage, int pageCount, String name) {
  51. Page<SmartAuthorGroup> page = new Page<>(currentPage, pageCount);
  52. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  53. //queryWrapper.like(StringUtils.hasText(name), "name", name);
  54. IPage<SmartAuthorGroup> result = smartAuthorGroupMapper.selectPage(page,queryWrapper);
  55. return new PageUtils<>(result);
  56. }
  57. @Override
  58. public int deleteSmartAuthorGroupById(int id) {
  59. int result = smartAuthorGroupMapper.deleteById(id);
  60. return result;
  61. }
  62. @Override
  63. public SmartAuthorGroup getSmartById(int id) {
  64. SmartAuthorGroup result = smartAuthorGroupMapper.selectById(id);
  65. return result;
  66. }
  67. @Override
  68. public List<SmartAuthorGroup> getAuthorGroupList() {
  69. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  70. queryWrapper.eq("deleted", 0);
  71. List<SmartAuthorGroup> result = smartAuthorGroupMapper.selectList(queryWrapper);
  72. return result;
  73. }
  74. @Override
  75. public List<SmartAuthorGroup> getAuthorGroupByKey(QueryWrapper<SmartAuthorGroup> queryWrapper) {
  76. List<SmartAuthorGroup> result = smartAuthorGroupMapper.selectList(queryWrapper);
  77. return result;
  78. }
  79. @Override
  80. public List<SmartAuthorGroup> smartAuthorGroup(Integer userId){
  81. List<SmartAuthorGroup> result = smartAuthorGroupMapper.smartAuthorGroup(userId);
  82. return result;
  83. }
  84. @Override
  85. public List<AuthorListGroup> queryCommentTreeRecords(Integer pid, List<SmartAuthorGroup> lists) {
  86. List<AuthorListGroup> newTrees = new ArrayList<>();
  87. List<SmartAuthorGroup> datas = lists.stream().filter(e -> e.getParentId().equals(pid)).collect(Collectors.toList());
  88. for (SmartAuthorGroup data : datas) {
  89. QueryWrapper<SmartUser> queryWrapper1 = new QueryWrapper<>();
  90. queryWrapper1.eq("deleted", 0);
  91. List<String> userIds = Arrays.asList(data.getUserId().split(","));
  92. queryWrapper1.in("id", userIds);
  93. List<SmartUser> list1 = smartUserMapper.selectList(queryWrapper1);
  94. JSONObject jsonObject1 = new JSONObject();
  95. jsonObject1.put("data", list1);
  96. QueryWrapper<SmartApply> queryWrapper2 = new QueryWrapper<>();
  97. queryWrapper2.eq("deleted", 0);
  98. List<String> applyIds = Arrays.asList(data.getApplyId().split(","));
  99. queryWrapper2.in("id", applyIds);
  100. List<SmartApply> list2 = smartApplyMapper.selectList(queryWrapper2);
  101. JSONObject jsonObject2 = new JSONObject();
  102. jsonObject2.put("data", list2);
  103. AuthorListGroup item = AuthorListGroup.builder()
  104. .id(data.getId())
  105. .parentId(data.getParentId())
  106. .name(data.getName())
  107. .userId(jsonObject1.toJSONString())
  108. .applyId(jsonObject2.toJSONString())
  109. .updateTime(data.getUpdateTime())
  110. .createUser(data.getCreateUser())
  111. .updateUser(data.getUpdateUser())
  112. .deleted(data.getDeleted())
  113. .build();
  114. List<AuthorListGroup> news = queryCommentTreeRecords(item.getId(), lists);
  115. if (news == null || news.size() == 0) {
  116. newTrees.add(item);
  117. continue;
  118. } else {
  119. item.setAuthorListGroups(news);
  120. newTrees.add(item);
  121. }
  122. }
  123. return newTrees;
  124. }
  125. @Override
  126. public List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId){
  127. List<SmartAuthorGroupManager> list = smartAuthorGroupMapper.getSmartAuthorGroupManager(groupId);
  128. if (list.size()>0){
  129. for (int i = 0; i < list.size(); i++) {
  130. SmartAuthorGroupManager smartAuthorGroupManager = list.get(i);
  131. if (smartAuthorGroupManager.getDepartmentManage()!=null && !smartAuthorGroupManager.getDepartmentManage().equals("")){
  132. String[] manageId = smartAuthorGroupManager.getDepartmentManage().split(",");
  133. QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
  134. queryWrapper1.eq("deleted", 0);
  135. queryWrapper1.in("id", Arrays.asList(manageId));
  136. List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
  137. List<JSONObject> departmentManageJson = new ArrayList<>();
  138. if (list1.size()>0){
  139. for (int j = 0; j < list1.size(); j++) {
  140. JSONObject jsonObject1 = new JSONObject();
  141. jsonObject1.put("id", list1.get(i).getId());
  142. jsonObject1.put("name", list1.get(i).getName());
  143. departmentManageJson.add(jsonObject1);
  144. }
  145. }
  146. list.get(i).setDepartmentManageJson(departmentManageJson);
  147. }
  148. if (smartAuthorGroupManager.getDepartmentView()!=null && !smartAuthorGroupManager.getDepartmentView().equals("")){
  149. String[] viewId = smartAuthorGroupManager.getDepartmentView().split(",");
  150. QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
  151. queryWrapper1.eq("deleted", 0);
  152. queryWrapper1.in("id", Arrays.asList(viewId));
  153. List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
  154. List<JSONObject> departmentViewJson = new ArrayList<>();
  155. if (list1.size()>0){
  156. for (int j = 0; j < list1.size(); j++) {
  157. JSONObject jsonObject1 = new JSONObject();
  158. jsonObject1.put("id", list1.get(i).getId());
  159. jsonObject1.put("name", list1.get(i).getName());
  160. departmentViewJson.add(jsonObject1);
  161. }
  162. }
  163. list.get(i).setDepartmentViewJson(departmentViewJson);
  164. }
  165. }
  166. }
  167. return list;
  168. }
  169. }