InboundCheckService.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package com.dk.mdm.service.ivt.inbound;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  6. import com.dk.common.exception.BaseBusinessException;
  7. import com.dk.common.infrastructure.constant.Constant;
  8. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  9. import com.dk.common.mapper.BaseMapper;
  10. import com.dk.common.response.ResponseResultUtil;
  11. import com.dk.common.response.ResponseResultVO;
  12. import com.dk.common.service.BaseService;
  13. import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
  14. import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
  15. import com.dk.mdm.mapper.ivt.InboundItemMapper;
  16. import com.dk.mdm.mapper.ivt.InboundMapper;
  17. import com.dk.mdm.model.pojo.ivt.Inbound;
  18. import com.dk.mdm.model.pojo.ivt.InboundItem;
  19. import com.dk.mdm.model.query.ivt.InboundItemQuery;
  20. import com.dk.mdm.model.response.ivt.InboundItemResponse;
  21. import com.dk.mdm.model.response.ivt.InboundResponse;
  22. import com.dk.mdm.model.vo.ivt.InboundItemVO;
  23. import com.dk.mdm.model.vo.ivt.InboundVO;
  24. import com.dk.mdm.service.common.CommonService;
  25. import com.dk.mdm.service.ivt.inventory.InventoryService;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33. import java.util.UUID;
  34. import java.util.stream.Collectors;
  35. /**
  36. * @author : 寇珊珊
  37. * @desc : 盘盈入库业务层
  38. * @date : 2024/3/7 14:11
  39. */
  40. @Service
  41. public class InboundCheckService extends BaseService<Inbound> {
  42. @Override
  43. public BaseMapper<Inbound> getRepository() {
  44. return inboundMapper;
  45. }
  46. @Autowired
  47. private InboundMapper inboundMapper;
  48. @Autowired
  49. private InboundConvert inboundConvert;
  50. @Autowired
  51. private InboundItemMapper inboundItemMapper;
  52. @Autowired
  53. private InboundItemConvert inboundItemConvert;
  54. @Autowired
  55. private CommonService commonService;
  56. @Autowired
  57. private InventoryService inventoryService;
  58. /**
  59. * @desc : 盘盈入库新建、库存调整-入库
  60. * @date : 2024/3/7 14:13
  61. * 入库中数量/金额 已入库数量/金额 由调用方传入
  62. * @author : 寇珊珊
  63. */
  64. @Transactional(rollbackFor = {Exception.class})
  65. public InboundVO checkInboundInsert(Map<String, Object> map) {
  66. //region map转json
  67. JSONObject total = new JSONObject();
  68. JSONArray detail = new JSONArray();
  69. //总单
  70. if (map.get("total") != null) {
  71. total = (JSONObject) JSON.toJSON(map.get("total"));
  72. }
  73. //明细
  74. if (map.get("total") != null) {
  75. detail = (JSONArray) JSON.toJSON(map.get("detail"));
  76. }
  77. InboundVO inboundVO = new InboundVO();
  78. inboundVO = total.toJavaObject(InboundVO.class);
  79. List<InboundItemVO> inboundItemVOList = detail.toJavaList(InboundItemVO.class);
  80. inboundVO.setItemList(inboundItemVOList);
  81. //endregion
  82. //region 总单
  83. //获取 id/单号
  84. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYPROFITINBOUND.getName(), false);
  85. inboundVO.setIntoId(codeMap.get("outId").toString()).
  86. setIntoNo(codeMap.get("outNote").toString());
  87. //todo 入库类型可能是盘盈可能是库位移动 调用的时候传
  88. // //入库类型
  89. // inboundVO.setIntoType(Constant.IntoType.PROFIT.getName());
  90. //已入库
  91. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  92. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  93. inboundVO.setIntoQty(inboundVO.getIntoingQty())
  94. .setIntoAmt(inboundVO.getIntoingAmt())
  95. .setIntoingQty(BigDecimal.ZERO)
  96. .setIntoingAmt(BigDecimal.ZERO)
  97. ;
  98. //实体转换
  99. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  100. inboundMapper.insert(inbound);
  101. //endregion
  102. //region 明细
  103. //校验明细
  104. if (inboundVO.getItemList().size() == 0) {
  105. throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  106. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  107. }
  108. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  109. //region 将库存需要的参数赋值
  110. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  111. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
  112. //endregion
  113. //总单id
  114. inboundItemVO.setIntoId(inboundVO.getIntoId());
  115. //入库类型
  116. inboundItemVO.setIntoType(inboundVO.getIntoType());
  117. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  118. inboundItemVO
  119. .setIntoQty(inboundItemVO.getIntoingQty())
  120. .setIntoAmt(inboundItemVO.getIntoingAmt())
  121. .setIntoingQty(BigDecimal.ZERO)
  122. .setIntoingAmt(BigDecimal.ZERO)
  123. .setCostPrice(inboundItemVO.getPriceInto())
  124. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  125. ;
  126. //入库状态
  127. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  128. //实体转换
  129. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  130. inboundItemMapper.insert(inboundItem);
  131. //endregion
  132. }
  133. //endregion
  134. //region 修改库存
  135. // Map<String, Object> invMap = new HashMap<>();
  136. // invMap.put("intoDetail", inboundVO.getItemList());
  137. // inventoryService.operatingInventoryInformation(invMap);
  138. //endregion
  139. return inboundVO;
  140. }
  141. /**
  142. * @desc : 作废
  143. * @date : 2024/4/16 13:27
  144. * @author : 寇珊珊
  145. */
  146. @Transactional(rollbackFor = {Exception.class})
  147. public ResponseResultVO<?> inboundRepeal(String fromId) {
  148. //region 查询总单 查询明细
  149. //根据来源id查询 此条入库单的数据还未更改前的数据
  150. InboundResponse inboundResponse = inboundMapper.selectByFromId(fromId);
  151. //根据总单id查询
  152. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
  153. //endregion
  154. //region 修改明细
  155. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  156. //region 将库存需要的参数赋值
  157. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  158. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  159. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  160. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  161. //endregion
  162. //赋值
  163. InboundItem inboundItem = new InboundItem();
  164. inboundItem.setItemId(inboundItemResponse.getItemId());
  165. inboundItem.setFlgValid(false);
  166. //修改
  167. inboundItemMapper.update(inboundItem,
  168. new UpdateWrapper<InboundItem>().lambda()
  169. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  170. );
  171. }
  172. //endregion
  173. //region 修改入库总单
  174. Inbound inbound = new Inbound();
  175. inbound.setIntoId(inboundResponse.getIntoId());
  176. inbound.setFlgValid(false);
  177. //修改
  178. inboundMapper.update(inbound,
  179. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  180. );
  181. //endregion
  182. //region 库存
  183. Map<String, Object> map = new HashMap<>();
  184. map.put("intoDetail", inboundItemResponseList);
  185. inventoryService.operatingInventoryInformation(map);
  186. //endregion
  187. return ResponseResultUtil.success();
  188. }
  189. }