InboundCheckService.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 = new HashMap<>();
  85. // 盘盈入库
  86. if(Constant.IntoType.PROFIT.getName().equals(inboundVO.getIntoType())){
  87. codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYPROFITINBOUND.getName(), false);
  88. }
  89. //仓库调整
  90. else{
  91. codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.MOVE.getName(), false);
  92. }
  93. inboundVO.setIntoId(codeMap.get("outId").toString()).
  94. setIntoNo(codeMap.get("outNote").toString());
  95. //todo 入库类型可能是盘盈可能是库位移动 调用的时候传
  96. // //入库类型
  97. // inboundVO.setIntoType(Constant.IntoType.PROFIT.getName());
  98. //已入库
  99. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  100. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  101. inboundVO.setIntoQty(inboundVO.getIntoingQty())
  102. .setIntoAmt(inboundVO.getIntoingAmt())
  103. .setIntoingQty(BigDecimal.ZERO)
  104. .setIntoingAmt(BigDecimal.ZERO)
  105. ;
  106. //实体转换
  107. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  108. inboundMapper.insert(inbound);
  109. //endregion
  110. //region 明细
  111. //校验明细
  112. if (inboundVO.getItemList().size() == 0) {
  113. throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  114. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  115. }
  116. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  117. //region 明细
  118. //总单id
  119. inboundItemVO.setIntoId(inboundVO.getIntoId());
  120. //入库类型
  121. inboundItemVO.setIntoType(inboundVO.getIntoType());
  122. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  123. inboundItemVO
  124. .setIntoQty(inboundItemVO.getIntoingQty())
  125. .setIntoAmt(inboundItemVO.getIntoingAmt())
  126. .setIntoingQty(BigDecimal.ZERO)
  127. .setIntoingAmt(BigDecimal.ZERO)
  128. .setCostPrice(inboundItemVO.getPriceInto())
  129. .setCostAmt(inboundItemVO.getIntoQty()
  130. .multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  131. ;
  132. //入库状态
  133. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  134. //实体转换
  135. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  136. inboundItemMapper.insert(inboundItem);
  137. inboundItemVO.setItemId(inboundItem.getItemId());
  138. //endregion
  139. //region 将库存需要的参数赋值
  140. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  141. //盘盈入库
  142. if(Constant.IntoType.PROFIT.getName().equals(inboundVO.getIntoType())){
  143. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
  144. }
  145. //期初入库
  146. if(Constant.IntoType.BEGIN.getName().equals(inboundVO.getIntoType())){
  147. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_BEGIN.getValue());
  148. }
  149. //仓库调整
  150. else{
  151. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.MOVE.getValue());
  152. }
  153. inboundItemVO.setAddOrEditFlag(true);
  154. //endregion
  155. }
  156. //endregion
  157. //region 修改库存
  158. Map<String, Object> invMap = new HashMap<>();
  159. invMap.put("intoDetail", inboundVO.getItemList());
  160. inventoryService.operatingInventoryInformation(invMap);
  161. //endregion
  162. return inboundVO;
  163. }
  164. /**
  165. * @desc : 作废
  166. * @date : 2024/4/16 13:27
  167. * @author : 寇珊珊
  168. */
  169. @Transactional(rollbackFor = {Exception.class})
  170. public ResponseResultVO<?> inboundRepeal(String fromId) {
  171. //region 查询总单 查询明细
  172. //根据来源id查询 此条入库单的数据还未更改前的数据
  173. InboundResponse inboundResponse = inboundMapper.selectByFromId(fromId);
  174. //根据总单id查询
  175. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
  176. //endregion
  177. //region 修改明细
  178. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  179. //region 将库存需要的参数赋值
  180. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  181. //盘盈入库
  182. if(Constant.IntoType.PROFIT.getName().equals(inboundItemResponse.getIntoType())){
  183. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
  184. }
  185. //仓库调整
  186. else{
  187. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.MOVE.getValue());
  188. }
  189. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  190. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  191. //endregion
  192. //赋值
  193. InboundItem inboundItem = new InboundItem();
  194. inboundItem.setItemId(inboundItemResponse.getItemId());
  195. inboundItem.setFlgValid(false);
  196. //修改
  197. inboundItemMapper.update(inboundItem,
  198. new UpdateWrapper<InboundItem>().lambda()
  199. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  200. );
  201. }
  202. //endregion
  203. //region 修改入库总单
  204. Inbound inbound = new Inbound();
  205. inbound.setIntoId(inboundResponse.getIntoId());
  206. inbound.setFlgValid(false);
  207. //修改
  208. inboundMapper.update(inbound,
  209. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  210. );
  211. //endregion
  212. //region 库存
  213. Map<String, Object> map = new HashMap<>();
  214. map.put("delIntoDetail", inboundItemResponseList);
  215. inventoryService.operatingInventoryInformation(map);
  216. //endregion
  217. return ResponseResultUtil.success();
  218. }
  219. }