OtherReceivableService.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.dk.mdm.service.mac;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.dk.common.infrastructure.annotaiton.Pagination;
  4. import com.dk.common.infrastructure.constant.Constant;
  5. import com.dk.common.model.pojo.PageList;
  6. import com.dk.common.response.ResponseResultUtil;
  7. import com.dk.common.response.ResponseResultVO;
  8. import com.dk.mdm.infrastructure.convert.mac.OtherReceivableConvert;
  9. import com.dk.mdm.infrastructure.convert.mac.OtherReceivableItemConvert;
  10. import com.dk.mdm.mapper.mac.OtherReceivableItemMapper;
  11. import com.dk.mdm.model.pojo.mac.*;
  12. import com.dk.mdm.mapper.mac.OtherReceivableMapper;
  13. import com.dk.common.service.BaseService;
  14. import com.dk.common.mapper.BaseMapper;
  15. import com.dk.mdm.model.query.mac.OtherReceivableItemQuery;
  16. import com.dk.mdm.model.query.mac.OtherReceivableQuery;
  17. import com.dk.mdm.model.response.mac.OtherReceivableItemResponse;
  18. import com.dk.mdm.model.response.mac.OtherReceivableResponse;
  19. import com.dk.mdm.model.vo.mac.OtherReceivableItemVO;
  20. import com.dk.mdm.model.vo.mac.OtherReceivableVO;
  21. import com.dk.mdm.service.common.CommonService;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.transaction.annotation.Transactional;
  25. import java.util.*;
  26. import java.util.stream.Collectors;
  27. @Service
  28. @Transactional
  29. public class OtherReceivableService extends BaseService<OtherReceivable> {
  30. @Override
  31. public String getPrimaryKey() {
  32. return "receivable_id";
  33. }
  34. @Override
  35. public BaseMapper<OtherReceivable> getRepository() {
  36. return otherReceivableMapper;
  37. }
  38. @Autowired
  39. private OtherReceivableMapper otherReceivableMapper;
  40. @Autowired
  41. private OtherReceivableItemMapper otherReceivableItemMapper;
  42. @Autowired
  43. private OtherReceivableItemService otherReceivableItemService;
  44. @Autowired
  45. private CommonService commonService;
  46. @Autowired
  47. private OtherReceivableConvert otherReceivableConvert;
  48. @Autowired
  49. private OtherReceivableItemConvert otherReceivableItemConvert;
  50. /**
  51. * @desc : 条件查询
  52. * @author : 付斌
  53. * @date : 2023/1/9 10:40
  54. */
  55. @Pagination
  56. public ResponseResultVO<PageList<OtherReceivableResponse>> selectByCond(OtherReceivableQuery otherReceivableQuery) {
  57. return super.mergeListWithCount(otherReceivableQuery, otherReceivableMapper.selectByCond(otherReceivableQuery),
  58. otherReceivableMapper.countByCond(otherReceivableQuery));
  59. }
  60. /**
  61. * @desc : 查询订单明细(货物、收款、附件)
  62. * @author : 付斌
  63. * @date : 2024-02-28 13:25
  64. */
  65. @Pagination
  66. public ResponseResultVO<Map<String, Object>> selectOtherReceivableInfoById(String id) {
  67. Map<String, Object> result = new HashMap<>();
  68. // 商品明细
  69. List<OtherReceivableItemResponse> otherReceivableItem = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
  70. result.put("otherReceivableItem", otherReceivableItem);
  71. // 附件
  72. return ResponseResultUtil.success(result);
  73. }
  74. /**
  75. * @desc : 新建方法
  76. * @author : 付斌
  77. * @date : 2023/1/9 10:49
  78. */
  79. @Transactional(
  80. rollbackFor = {Exception.class}
  81. )
  82. public ResponseResultVO<?> insert(OtherReceivableVO otherReceivableVO) {
  83. // 获取单号
  84. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.ORDER.getName(), false);
  85. otherReceivableVO.setReceivableId(codeMap.get("outId").toString()).setReceivableNo(codeMap.get("outNote").toString())
  86. .setObjectType(Constant.ObjectType.CUS.getName());
  87. // 转化实体
  88. OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
  89. // 订单总单保存
  90. super.insert(otherReceivable);
  91. // 订单明细保存
  92. if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
  93. for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
  94. OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
  95. otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId());
  96. otherReceivableItemMapper.insert(otherReceivableItem);
  97. }
  98. }
  99. return ResponseResultUtil.success();
  100. }
  101. /**
  102. * @desc : 编辑方法
  103. * @author : 付斌
  104. * @date : 2023/1/9 10:49
  105. */
  106. @Transactional(
  107. rollbackFor = {Exception.class}
  108. )
  109. public ResponseResultVO<?> update(OtherReceivableVO otherReceivableVO) {
  110. // 明细实体(避免并发,需要再查一遍)
  111. OtherReceivableItem otherReceivableItemForUpdate;
  112. // 转化实体
  113. OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
  114. //删除的
  115. List<OtherReceivableItemVO> deleteOtherReceivableItemVOList = otherReceivableVO.getDeleteItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
  116. if (deleteOtherReceivableItemVOList.size() > 0) {
  117. for (OtherReceivableItemVO otherReceivableItemVO : deleteOtherReceivableItemVOList) {
  118. otherReceivableItemMapper.deleteById(otherReceivableItemVO.getItemId());
  119. }
  120. }
  121. // 新增的
  122. List<OtherReceivableItemVO> insertOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() == null).collect(Collectors.toList());
  123. for (OtherReceivableItemVO otherReceivableItemVO : insertOtherReceivableItemVOList) {
  124. OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
  125. otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId());
  126. otherReceivableItemMapper.insert(otherReceivableItem);
  127. }
  128. // 编辑的
  129. List<OtherReceivableItemVO> editOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
  130. for (OtherReceivableItemVO otherReceivableItemVO : editOtherReceivableItemVOList) {
  131. otherReceivableItemForUpdate = otherReceivableItemMapper.selectByIdForUpdate(otherReceivableItemVO.getItemId());
  132. OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
  133. otherReceivableItemService.updateByUuid(otherReceivableItem);
  134. }
  135. return ResponseResultUtil.success(super.update(otherReceivable, new UpdateWrapper<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
  136. UUID.fromString(otherReceivable.getReceivableId()))));
  137. }
  138. }