OutboundCheckService.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package com.dk.mdm.service.ivt.outbound;
  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.OutboundConvert;
  14. import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
  15. import com.dk.mdm.mapper.ivt.OutboundItemMapper;
  16. import com.dk.mdm.mapper.ivt.OutboundMapper;
  17. import com.dk.mdm.model.pojo.ivt.Outbound;
  18. import com.dk.mdm.model.pojo.ivt.OutboundItem;
  19. import com.dk.mdm.model.query.ivt.OutboundItemQuery;
  20. import com.dk.mdm.model.response.ivt.OutboundItemResponse;
  21. import com.dk.mdm.model.response.ivt.OutboundResponse;
  22. import com.dk.mdm.model.vo.ivt.OutboundItemVO;
  23. import com.dk.mdm.model.vo.ivt.OutboundVO;
  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. /**
  35. * @author : 寇珊珊
  36. * @desc : 其他出库业务层
  37. * @date : 2024/3/18 15:33
  38. */
  39. @Service
  40. public class OutboundCheckService extends BaseService<Outbound> {
  41. @Override
  42. public BaseMapper<Outbound> getRepository() {
  43. return outboundMapper;
  44. }
  45. @Autowired
  46. private CommonService commonService;
  47. @Autowired
  48. private OutboundMapper outboundMapper;
  49. @Autowired
  50. private OutboundConvert outboundConvert;
  51. @Autowired
  52. private OutboundItemMapper outboundItemMapper;
  53. @Autowired
  54. private OutboundItemConvert outboundItemConvert;
  55. @Autowired
  56. private InventoryService inventoryService;
  57. /**
  58. * @desc : 其他出库新建
  59. * @date : 2024/3/7 14:13
  60. * @author : 寇珊珊
  61. */
  62. @Transactional(rollbackFor = {Exception.class})
  63. public OutboundVO otherOutboundInsert(Map<String, Object> map) {
  64. //region map转json
  65. JSONObject total = new JSONObject();
  66. JSONArray detail = new JSONArray();
  67. //总单
  68. if (map.get("total") != null) {
  69. total = (JSONObject) JSON.toJSON(map.get("total"));
  70. }
  71. //明细
  72. if (map.get("total") != null) {
  73. detail = (JSONArray) JSON.toJSON(map.get("detail"));
  74. }
  75. OutboundVO outboundVO = new OutboundVO();
  76. outboundVO = total.toJavaObject(OutboundVO.class);
  77. List<OutboundItemVO> outboundItemVOList = detail.toJavaList(OutboundItemVO.class);
  78. outboundVO.setItemList(outboundItemVOList);
  79. //endregion
  80. //region 总单
  81. //获取 id/单号
  82. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYLOSEOUTBOUND.getName(), false);
  83. outboundVO.setOutId(codeMap.get("outId").toString()).
  84. setOutNo(codeMap.get("outNote").toString());
  85. //todo 出库类型可能是盘亏可能是库位移动 调用的时候传
  86. //出库类型
  87. // outboundVO.setOutType(Constant.OutType.INVENTORY_LOSS.getName());
  88. //已出库
  89. outboundVO.setOutStatus(Constant.OutStatus.YICHUKU.getName());
  90. //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
  91. outboundVO
  92. .setOutQty(outboundVO.getOutingQty())
  93. .setOutAmt(outboundVO.getOutingAmt())
  94. .setOutingQty(BigDecimal.ZERO)
  95. .setOutingAmt(BigDecimal.ZERO)
  96. ;
  97. //实体转换
  98. Outbound outbound = outboundConvert.convertToPo(outboundVO);
  99. outboundMapper.insert(outbound);
  100. //endregion
  101. //region 明细
  102. //校验明细
  103. if (outboundVO.getItemList().size() == 0) {
  104. throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
  105. ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
  106. }
  107. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  108. //region 将库存需要的参数赋值
  109. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  110. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_LOSS.getValue());
  111. //endregion
  112. //总单id
  113. outboundItemVO.setOutId(outboundVO.getOutId());
  114. //出库类型
  115. outboundItemVO.setOutType(outboundVO.getOutType());
  116. //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
  117. outboundItemVO
  118. .setOutQty(outboundItemVO.getOutingQty())
  119. .setOutAmt(outboundItemVO.getOutingAmt())
  120. .setOutingQty(BigDecimal.ZERO)
  121. .setOutingAmt(BigDecimal.ZERO)
  122. .setCostPrice(outboundItemVO.getPriceOut())
  123. .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  124. ;
  125. //入库状态
  126. outboundItemVO.setOutStatus(outboundVO.getOutStatus());
  127. //实体转换
  128. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  129. outboundItemMapper.insert(outboundItem);
  130. //endregion
  131. }
  132. //endregion
  133. //region 修改库存
  134. // Map<String, Object> invMap = new HashMap<>();
  135. // invMap.put("outDetail",outboundVO.getItemList());
  136. // inventoryService.operatingInventoryInformation(invMap);
  137. //endregion
  138. //1.入库需要的值 附上 掉用接口
  139. //2.接收接口返回体
  140. return outboundVO;
  141. }
  142. /**
  143. * @desc : 作废
  144. * @date : 2024/4/16 13:32
  145. * @author : 寇珊珊
  146. */
  147. @Transactional(rollbackFor = {Exception.class})
  148. public ResponseResultVO<?> outboundRepeal(String fromId) {
  149. //region 查询总单 查询明细
  150. //根据来源id查询 此条出库单的数据还未更改前的数据
  151. OutboundResponse outboundResponse = outboundMapper.selectByFromId(fromId);
  152. //根据总单id查询
  153. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
  154. //endregion
  155. //region 修改明细
  156. for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
  157. //region 将库存需要的参数赋值
  158. outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  159. outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
  160. outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
  161. outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt().negate());
  162. //endregion
  163. //赋值
  164. OutboundItem outboundItem = new OutboundItem();
  165. outboundItem.setItemId(outboundItemResponse.getItemId());
  166. outboundItem.setFlgValid(false);
  167. //修改
  168. outboundItemMapper.update(outboundItem,
  169. new UpdateWrapper<OutboundItem>().lambda()
  170. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  171. );
  172. }
  173. //endregion
  174. //region 修改出库总单
  175. Outbound outbound = new Outbound();
  176. outbound.setOutId(outboundResponse.getOutId());
  177. outbound.setFlgValid(false);
  178. //修改
  179. outboundMapper.update(outbound,
  180. new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  181. );
  182. //endregion
  183. //region 修改库存
  184. Map<String, Object> map = new HashMap<>();
  185. map.put("outDetail", outboundItemResponseList);
  186. inventoryService.operatingInventoryInformation(map);
  187. //endregion
  188. return ResponseResultUtil.success();
  189. }
  190. }