IntroduceInfoFacade.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package com.diagbot.facade;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.diagbot.client.UserServiceClient;
  6. import com.diagbot.dto.IntroducePageDTO;
  7. import com.diagbot.dto.QuestionShortDTO;
  8. import com.diagbot.dto.RespDTO;
  9. import com.diagbot.entity.IntroduceDetail;
  10. import com.diagbot.entity.IntroduceInfo;
  11. import com.diagbot.entity.IntroduceMap;
  12. import com.diagbot.entity.QuestionInfo;
  13. import com.diagbot.enums.IsDeleteEnum;
  14. import com.diagbot.service.IntroduceDetailService;
  15. import com.diagbot.service.IntroduceMapService;
  16. import com.diagbot.service.impl.IntroduceInfoServiceImpl;
  17. import com.diagbot.util.BeanUtil;
  18. import com.diagbot.util.DateUtil;
  19. import com.diagbot.util.UserUtils;
  20. import com.diagbot.vo.IntroduceDetailVO;
  21. import com.diagbot.vo.IntroduceMapVO;
  22. import com.diagbot.vo.IntroducePageVO;
  23. import com.diagbot.vo.IntroduceVO;
  24. import com.google.common.collect.Lists;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Qualifier;
  27. import org.springframework.stereotype.Component;
  28. import java.util.Date;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.stream.Collectors;
  32. /**
  33. * @Description:
  34. * @Author:zhaops
  35. * @time: 2018/11/16 14:30
  36. */
  37. @Component
  38. public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
  39. @Autowired
  40. IntroduceMapFacade introduceMapFacade;
  41. @Autowired
  42. IntroduceDetailFacade introduceDetailFacade;
  43. @Autowired
  44. @Qualifier("introduceDetailServiceImpl")
  45. IntroduceDetailService introduceDetailService;
  46. @Autowired
  47. @Qualifier("introduceMapServiceImpl")
  48. IntroduceMapService introduceMapService;
  49. @Autowired
  50. UserServiceClient userServiceClient;
  51. @Autowired
  52. QuestionInfoFacade questionInfoFacade;
  53. /**
  54. * 保存提示信息(新增or修改)
  55. *
  56. * @param introduceVO
  57. * @return
  58. */
  59. public Boolean saveIntroduce(IntroduceVO introduceVO) {
  60. IntroduceInfo introduceInfo = new IntroduceInfo();
  61. if (!(introduceVO.getId() == null||introduceInfo.getId().equals(0))) {
  62. introduceInfo = this.getById(introduceVO.getId());
  63. introduceInfo.setModifier(UserUtils.getCurrentPrincipleID());
  64. introduceInfo.setGmtModified(DateUtil.now());
  65. }
  66. Date now = DateUtil.now();
  67. String userId = UserUtils.getCurrentPrincipleID();
  68. introduceInfo.setCreator(userId);
  69. introduceInfo.setGmtCreate(now);
  70. introduceInfo.setModifier(userId);
  71. introduceInfo.setGmtModified(now);
  72. introduceInfo.setName(introduceVO.getName());
  73. introduceInfo.setRemark(introduceVO.getRemark());
  74. //更新提示信息
  75. this.saveOrUpdate(introduceInfo);
  76. //明细信息不更新,每次都删除重新插入
  77. //删除已有明细,逻辑删除
  78. if (!(introduceInfo.getId() == null)) {
  79. UpdateWrapper<IntroduceDetail> detailUpdateWrapper = new UpdateWrapper<>();
  80. detailUpdateWrapper.eq("introduce_id", introduceInfo.getId()).
  81. eq("is_deleted", IsDeleteEnum.N.getKey()).
  82. set("is_deleted", IsDeleteEnum.Y.getKey()).
  83. set("modifier", UserUtils.getCurrentPrincipleID()).
  84. set("gmt_modified", DateUtil.now());
  85. introduceDetailFacade.update(new IntroduceDetail(), detailUpdateWrapper);
  86. }
  87. List<IntroduceDetail> introduceDetailList = Lists.newArrayList();
  88. for (IntroduceDetailVO detailVO : introduceVO.getDetailVOList()) {
  89. IntroduceDetail detail = new IntroduceDetail();
  90. detail.setIntroduceId(introduceInfo.getId());
  91. detail.setCreator(UserUtils.getCurrentPrincipleID());
  92. detail.setGmtCreate(DateUtil.now());
  93. detail.setContent(detailVO.getContent());
  94. detail.setText(detailVO.getText());
  95. detail.setTitle(detailVO.getTitle());
  96. detail.setOrderNo(detailVO.getOrderNo());
  97. detail.setPosition(detailVO.getPosition());
  98. detail.setIsReason(detailVO.getIsReason());
  99. introduceDetailList.add(detail);
  100. }
  101. //插入新的明细记录
  102. introduceDetailService.saveBatch(introduceDetailList);
  103. //更新映射关系
  104. //删除已有映射关系
  105. UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
  106. introduceMapUpdateWrapper.eq("introduce_id", introduceInfo.getId()).
  107. eq("is_deleted", IsDeleteEnum.N.getKey()).
  108. set("is_deleted", IsDeleteEnum.Y.getKey()).
  109. set("modifier", UserUtils.getCurrentPrincipleID()).
  110. set("gmt_modified", DateUtil.now());
  111. introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
  112. //插入新的映射关系
  113. List<IntroduceMap> introduceMapList = Lists.newLinkedList();
  114. for (IntroduceMapVO introduceMapVO : introduceVO.getMapVOList()) {
  115. IntroduceMap introduceMap = new IntroduceMap();
  116. BeanUtil.copyProperties(introduceMapVO, introduceMap);
  117. introduceMap.setIntroduceId(introduceInfo.getId());
  118. introduceMapList.add(introduceMap);
  119. }
  120. introduceMapService.saveBatch(introduceMapList);
  121. return true;
  122. }
  123. /**
  124. * 单条删除提示信息 逻辑删除
  125. *
  126. * @param id
  127. * @return
  128. */
  129. public Boolean deleteRecord(Long id) {
  130. //删除已有映射关系
  131. UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
  132. introduceMapUpdateWrapper.eq("introduce_id", id).
  133. eq("is_deleted", IsDeleteEnum.N.getKey()).
  134. set("is_deleted", IsDeleteEnum.Y.getKey()).
  135. set("modifier", UserUtils.getCurrentPrincipleID()).
  136. set("gmt_modified", DateUtil.now());
  137. introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
  138. //删除明细
  139. UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
  140. introduceDetailUpdateWrapper.eq("introduce_id", id).
  141. eq("is_deleted", IsDeleteEnum.N.getKey()).
  142. set("is_deleted", IsDeleteEnum.Y.getKey()).
  143. set("modifier", UserUtils.getCurrentPrincipleID()).
  144. set("gmt_modified", DateUtil.now());
  145. introduceDetailFacade.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
  146. //删除提示信息
  147. UpdateWrapper<IntroduceInfo> introduceInfoUpdateWrapper = new UpdateWrapper<>();
  148. introduceInfoUpdateWrapper.eq("id", id).
  149. eq("is_deleted", IsDeleteEnum.N.getKey()).
  150. set("is_deleted", IsDeleteEnum.Y.getKey()).
  151. set("modifier", UserUtils.getCurrentPrincipleID()).
  152. set("gmt_modified", DateUtil.now());
  153. this.update(new IntroduceInfo(), introduceInfoUpdateWrapper);
  154. return true;
  155. }
  156. /**
  157. * 批量删除提示信息 逻辑删除
  158. *
  159. * @param ids
  160. * @return
  161. */
  162. public Boolean deleteRecords(Long[] ids) {
  163. //删除已有映射关系
  164. UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
  165. introduceMapUpdateWrapper.in("introduce_id", ids).
  166. eq("is_deleted", IsDeleteEnum.N.getKey()).
  167. set("is_deleted", IsDeleteEnum.Y.getKey()).
  168. set("modifier", UserUtils.getCurrentPrincipleID()).
  169. set("gmt_modified", DateUtil.now());
  170. introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
  171. //删除明细
  172. UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
  173. introduceDetailUpdateWrapper.in("introduce_id", ids).
  174. eq("is_deleted", IsDeleteEnum.N.getKey()).
  175. set("is_deleted", IsDeleteEnum.Y.getKey()).
  176. set("modifier", UserUtils.getCurrentPrincipleID()).
  177. set("gmt_modified", DateUtil.now());
  178. introduceDetailFacade.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
  179. //删除提示信息
  180. UpdateWrapper<IntroduceInfo> introduceInfoUpdateWrapper = new UpdateWrapper<>();
  181. introduceInfoUpdateWrapper.in("id", ids).
  182. eq("is_deleted", IsDeleteEnum.N.getKey()).
  183. set("is_deleted", IsDeleteEnum.Y.getKey()).
  184. set("modifier", UserUtils.getCurrentPrincipleID()).
  185. set("gmt_modified", DateUtil.now());
  186. this.update(new IntroduceInfo(), introduceInfoUpdateWrapper);
  187. return true;
  188. }
  189. /**
  190. * 获取提示信息分页信息,带条件
  191. *
  192. * @param introducePageVO
  193. * @return
  194. */
  195. public IPage<IntroducePageDTO> getIntroducePageByMap(IntroducePageVO introducePageVO) {
  196. IPage<IntroducePageDTO> introducePageDTOIPage = this.getIntroducePage(introducePageVO);
  197. List<IntroducePageDTO> records = introducePageDTOIPage.getRecords();
  198. for (IntroducePageDTO introducePageDTO : records) {
  199. introducePageDTO.setOperator(introducePageDTO.getModifier());
  200. introducePageDTO.setGmtOperate(introducePageDTO.getGmtModified());
  201. }
  202. List<String> userIds = records.stream().map(introduceList -> introduceList.getOperator()).collect(Collectors.toList());
  203. RespDTO<Map<String, String>> userInfos = userServiceClient.getUserInfoByIds(userIds);
  204. if (userInfos != null) {
  205. Map<String, String> userInfoMap = userInfos.data;
  206. for (IntroducePageDTO introducePageDTO : records) {
  207. if (userInfoMap.containsKey(introducePageDTO.getOperator())) {
  208. introducePageDTO.setOperatorName(userInfoMap.get(introducePageDTO.getOperator()));
  209. }
  210. }
  211. }
  212. introducePageDTOIPage.setRecords(records);
  213. return introducePageDTOIPage;
  214. }
  215. /**
  216. * 带条件查询
  217. *
  218. * @param map
  219. * @return
  220. */
  221. public List<IntroduceInfo> getByMap(Map<String, Object> map) {
  222. QueryWrapper<IntroduceInfo> introduceInfoQueryWrapper = new QueryWrapper<>();
  223. for (Map.Entry<String, Object> entry : map.entrySet()) {
  224. introduceInfoQueryWrapper.eq(entry.getKey(), entry.getValue());
  225. }
  226. return this.list(introduceInfoQueryWrapper);
  227. }
  228. /**
  229. * 根据id获取提示信息
  230. *
  231. * @param id
  232. * @return
  233. */
  234. public IntroducePageDTO getIntroduceById(Long id) {
  235. IntroducePageDTO introducePageDTO = new IntroducePageDTO();
  236. IntroduceInfo introduceInfo = this.getById(id);
  237. BeanUtil.copyProperties(introduceInfo, introducePageDTO);
  238. QueryWrapper<IntroduceMap> introduceMapQueryWrapper = new QueryWrapper<>();
  239. introduceMapQueryWrapper.eq("introduce_id", id).eq("is_deleted", IsDeleteEnum.N.getKey());
  240. List<IntroduceMap> introduceMapList = introduceMapFacade.list(introduceMapQueryWrapper);
  241. List<Long> questionIds = introduceMapList.stream().map(introduceMap -> introduceMap.getQuestionId()).collect(Collectors.toList());
  242. QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
  243. questionInfoQueryWrapper.in("id", questionIds).eq("is_deleted", IsDeleteEnum.N.getKey());
  244. List<QuestionInfo> questionInfoList = questionInfoFacade.list(questionInfoQueryWrapper);
  245. List<QuestionShortDTO> questionShortDTOList = Lists.newLinkedList();
  246. String tagName = "";
  247. for (QuestionInfo questionInfo : questionInfoList) {
  248. QuestionShortDTO questionShortDTO = new QuestionShortDTO();
  249. BeanUtil.copyProperties(questionInfo, questionShortDTO);
  250. questionShortDTOList.add(questionShortDTO);
  251. tagName += questionInfo.getTagName() + ",";
  252. }
  253. if (tagName.endsWith(",")) {
  254. tagName = tagName.substring(0, tagName.length() - 1);
  255. }
  256. introducePageDTO.setTagName(tagName);
  257. introducePageDTO.setQuestionList(questionShortDTOList);
  258. //未关联的标签
  259. QueryWrapper<QuestionInfo> unRelatedQuestionWrapper = new QueryWrapper<>();
  260. unRelatedQuestionWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).notIn("id", questionIds);
  261. List<QuestionInfo> unRelatedQuestionList = questionInfoFacade.list(unRelatedQuestionWrapper);
  262. List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
  263. for (QuestionInfo questionInfo : unRelatedQuestionList) {
  264. QuestionShortDTO questionShortDTO = new QuestionShortDTO();
  265. BeanUtil.copyProperties(questionInfo, questionShortDTO);
  266. unRelatedQuestionDTOList.add(questionShortDTO);
  267. }
  268. introducePageDTO.setUnRelatedQuestionList(unRelatedQuestionDTOList);
  269. return introducePageDTO;
  270. }
  271. /**
  272. * 获取未关联标签列表
  273. *
  274. * @return
  275. */
  276. public List<QuestionShortDTO> getAllQuestionList() {
  277. QueryWrapper<QuestionInfo> unRelatedQuestionWrapper = new QueryWrapper<>();
  278. unRelatedQuestionWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  279. List<QuestionInfo> unRelatedQuestionList = questionInfoFacade.list(unRelatedQuestionWrapper);
  280. List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
  281. for (QuestionInfo questionInfo : unRelatedQuestionList) {
  282. QuestionShortDTO questionShortDTO = new QuestionShortDTO();
  283. BeanUtil.copyProperties(questionInfo, questionShortDTO);
  284. unRelatedQuestionDTOList.add(questionShortDTO);
  285. }
  286. return unRelatedQuestionDTOList;
  287. }
  288. }