IntroduceInfoFacade.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.diagbot.facade;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.diagbot.entity.IntroduceDetail;
  5. import com.diagbot.entity.IntroduceInfo;
  6. import com.diagbot.service.impl.IntroduceDetailServiceImpl;
  7. import com.diagbot.service.impl.IntroduceInfoServiceImpl;
  8. import com.diagbot.util.UserUtils;
  9. import com.diagbot.vo.IntroduceDetailVO;
  10. import com.diagbot.vo.IntroducePageVO;
  11. import com.diagbot.vo.IntroduceVO;
  12. import com.google.common.collect.Lists;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Arrays;
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @Description:
  21. * @Author:zhaops
  22. * @time: 2018/11/16 14:30
  23. */
  24. @Component
  25. public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
  26. @Autowired
  27. IntroduceMapFacade introduceMapFacade;
  28. @Autowired
  29. IntroduceDetailFacade introduceDetailFacade;
  30. @Autowired
  31. IntroduceDetailServiceImpl introduceDetailServiceImpl;
  32. /**
  33. * 保存提示信息(新增or修改)
  34. *
  35. * @param introduceVO
  36. * @return
  37. */
  38. public Boolean saveIntroduce(IntroduceVO introduceVO) {
  39. IntroduceInfo introduceInfo = new IntroduceInfo();
  40. if (!(introduceVO.getId() == null)) {
  41. introduceInfo = this.getById(introduceVO.getId());
  42. //introduceInfo.setModifier(UserUtils.getCurrentPrincipleID());
  43. introduceInfo.setGmtModified(new Date());
  44. } else {
  45. //introduceInfo.setCreator(UserUtils.getCurrentPrincipleID());
  46. introduceInfo.setGmtCreate(new Date());
  47. }
  48. introduceInfo.setName(introduceVO.getName());
  49. introduceInfo.setRemark(introduceVO.getRemark());
  50. //更新提示信息
  51. this.saveOrUpdate(introduceInfo);
  52. //明细信息不更新,每次都删除重新插入
  53. //删除已有明细,物理删除
  54. if (!(introduceInfo.getId() == null)) {
  55. QueryWrapper<IntroduceDetail> detailQueryWrapper = new QueryWrapper<>();
  56. detailQueryWrapper.eq("introduce_id", introduceInfo.getId());
  57. introduceDetailFacade.remove(detailQueryWrapper);
  58. }
  59. List<IntroduceDetail> introduceDetailList = Lists.newArrayList();
  60. for (IntroduceDetailVO detailVO : introduceVO.getDetailVOList()) {
  61. IntroduceDetail detail = new IntroduceDetail();
  62. detail.setIntroduceId(introduceInfo.getId());
  63. //detail.setCreator(UserUtils.getCurrentPrincipleID());
  64. detail.setGmtCreate(new Date());
  65. detail.setContent(detailVO.getContent());
  66. detail.setText(detailVO.getText());
  67. detail.setTitle(detailVO.getTitle());
  68. detail.setOrderNo(detailVO.getOrderNo());
  69. detail.setPosition(detailVO.getPosition());
  70. introduceDetailList.add(detail);
  71. }
  72. //插入新的明细记录
  73. introduceDetailServiceImpl.saveBatch(introduceDetailList);
  74. return true;
  75. }
  76. /**
  77. * 单条删除提示信息 物理删除
  78. *
  79. * @param id
  80. * @return
  81. */
  82. public Boolean deleteRecord(Long id) {
  83. //删除明细
  84. QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
  85. introduceDetailQueryWrapper.eq("introduce_id", id);
  86. introduceDetailFacade.remove(introduceDetailQueryWrapper);
  87. //删除提示信息
  88. this.removeById(id);
  89. return true;
  90. }
  91. /**
  92. * 批量删除提示信息 物理删除
  93. *
  94. * @param ids
  95. * @return
  96. */
  97. public Boolean deleteRecords(Long[] ids) {
  98. //删除明细
  99. QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
  100. introduceDetailQueryWrapper.in("introduce_id", ids);
  101. introduceDetailFacade.remove(introduceDetailQueryWrapper);
  102. //删除提示信息
  103. this.removeByIds(Arrays.asList(ids));
  104. return true;
  105. }
  106. /**
  107. * 分页查询提示信息,可带等于条件
  108. *
  109. * @param introducePageVO
  110. * @return
  111. */
  112. public IPage<IntroduceInfo> getPageByMap(IntroducePageVO introducePageVO) {
  113. QueryWrapper<IntroduceInfo> introduceInfoQueryWrapper = new QueryWrapper<>();
  114. for (Map.Entry<String, Object> entry : introducePageVO.getMap().entrySet()) {
  115. introduceInfoQueryWrapper.eq(entry.getKey(), entry.getValue());
  116. }
  117. IPage<IntroduceInfo> introduceInfoIPage = this.page(introducePageVO, introduceInfoQueryWrapper);
  118. return introduceInfoIPage;
  119. }
  120. /**
  121. * 带条件查询
  122. *
  123. * @param map
  124. * @return
  125. */
  126. public List<IntroduceInfo> getByMap(Map<String, Object> map) {
  127. QueryWrapper<IntroduceInfo> introduceInfoQueryWrapper = new QueryWrapper<>();
  128. for (Map.Entry<String, Object> entry : map.entrySet()) {
  129. introduceInfoQueryWrapper.eq(entry.getKey(), entry.getValue());
  130. }
  131. return this.list(introduceInfoQueryWrapper);
  132. }
  133. }