ScaleContentFacade.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. *
  3. */
  4. package com.diagbot.facade;
  5. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.diagbot.client.UserServiceClient;
  8. import com.diagbot.dto.QuestionPageDTO;
  9. import com.diagbot.dto.RespDTO;
  10. import com.diagbot.dto.ScaleContentDTO;
  11. import com.diagbot.entity.QuestionInfo;
  12. import com.diagbot.entity.ScaleContent;
  13. import com.diagbot.enums.IsDeleteEnum;
  14. import com.diagbot.exception.CommonErrorCode;
  15. import com.diagbot.exception.CommonException;
  16. import com.diagbot.service.ScaleContentService;
  17. import com.diagbot.service.impl.ScaleContentServiceImpl;
  18. import com.diagbot.util.BeanUtil;
  19. import com.diagbot.util.DateUtil;
  20. import com.diagbot.util.UserUtils;
  21. import com.diagbot.vo.DeleteScaleVO;
  22. import com.diagbot.vo.QuestionPageVO;
  23. import com.diagbot.vo.ScaleContentSaveVO;
  24. import com.diagbot.vo.ScaleContentVO;
  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.ArrayList;
  29. import java.util.Date;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.stream.Collectors;
  33. /**
  34. * @author zhoutg
  35. * @Description
  36. * @time 2018年12月5日下午4:53:59
  37. */
  38. @Component
  39. public class ScaleContentFacade extends ScaleContentServiceImpl {
  40. @Autowired
  41. @Qualifier("scaleContentServiceImpl")
  42. ScaleContentService scaleContentService;
  43. @Autowired
  44. UserServiceClient userServiceClient;
  45. @Autowired
  46. QuestionFacade questionFacade;
  47. /**
  48. * 量表内容新增或更新
  49. *
  50. * @param scaleContentSaveVO
  51. */
  52. public void insertOrUpdate(ScaleContentSaveVO scaleContentSaveVO) {
  53. Long scaleId = scaleContentSaveVO.getScaleId();
  54. Date now = DateUtil.now();
  55. String userId = UserUtils.getCurrentPrincipleID();
  56. // 更新修改信息
  57. questionFacade.update(new QuestionInfo(), new UpdateWrapper<QuestionInfo>()
  58. .eq("id", scaleId)
  59. .set("gmt_modified", now)
  60. .set("modifier", userId)
  61. );
  62. // 删除原关联内容
  63. if (scaleId != null) {
  64. this.update(new ScaleContent(), new UpdateWrapper<ScaleContent>()
  65. .eq("scale_id", scaleId)
  66. .eq("is_deleted", IsDeleteEnum.N.getKey())
  67. .set("gmt_modified", now)
  68. .set("modifier", userId)
  69. .set("is_deleted", IsDeleteEnum.Y.getKey()));
  70. }
  71. // 新增关联内容
  72. List<ScaleContent> list = new ArrayList<>();
  73. List<ScaleContentVO> scaleContentVOS = scaleContentSaveVO.getContent();
  74. for (ScaleContentVO scaleContentVO : scaleContentVOS) {
  75. ScaleContent bean = new ScaleContent();
  76. BeanUtil.copyProperties(scaleContentVO, bean);
  77. bean.setScaleId(scaleId);
  78. bean.setModifier(userId);
  79. bean.setCreator(userId);
  80. bean.setGmtCreate(now);
  81. bean.setGmtModified(now);
  82. list.add(bean);
  83. }
  84. scaleContentService.saveBatch(list);
  85. }
  86. /**
  87. * 量表列表
  88. *
  89. * @param questionPageVO
  90. * @return
  91. */
  92. public IPage<QuestionPageDTO> getListFac(QuestionPageVO questionPageVO) {
  93. IPage<QuestionPageDTO> res = this.getList(questionPageVO);
  94. if (res.getTotal() <= 0) {
  95. return res;
  96. }
  97. List<String> personIds = res.getRecords().stream().map(row -> row.getModifier()).collect(Collectors.toList());
  98. RespDTO<Map<String, String>> mapRespDTO = userServiceClient.getUserInfoByIds(personIds);
  99. if (mapRespDTO == null || !CommonErrorCode.OK.getCode().equals(mapRespDTO.code)) {
  100. throw new CommonException(CommonErrorCode.RPC_ERROR, "获取操作人失败");
  101. }
  102. for (QuestionPageDTO bean : res.getRecords()) {
  103. bean.setModifier(mapRespDTO.data.get(bean.getModifier()));
  104. }
  105. return res;
  106. }
  107. /**
  108. * 量表列表
  109. *
  110. * @param scaleId
  111. * @return
  112. */
  113. public List<ScaleContentDTO> getByParamFac(Long scaleId) {
  114. return this.getByParam(scaleId);
  115. }
  116. /**
  117. * 量表列表
  118. *
  119. * @param deleteScaleVO
  120. * @return
  121. */
  122. public void delete(DeleteScaleVO deleteScaleVO) {
  123. Date now = DateUtil.now();
  124. String person = UserUtils.getCurrentPrincipleID();
  125. List<Long> ids = deleteScaleVO.getIds();
  126. for(Long id : ids) {
  127. this.update(new ScaleContent(), new UpdateWrapper<ScaleContent>()
  128. .eq("scale_id", id)
  129. .eq("is_deleted", IsDeleteEnum.N.getKey())
  130. .set("gmt_modified", now)
  131. .set("modifier", person)
  132. .set("is_deleted", IsDeleteEnum.Y.getKey()));
  133. }
  134. }
  135. }