InboundPurchaseService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. package com.dk.mdm.service.ivt.inbound;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.dk.common.exception.BaseBusinessException;
  4. import com.dk.common.infrastructure.annotaiton.Pagination;
  5. import com.dk.common.infrastructure.constant.Constant;
  6. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  7. import com.dk.common.mapper.BaseMapper;
  8. import com.dk.common.model.pojo.PageList;
  9. import com.dk.common.response.ResponseCodeEnum;
  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.mapper.pur.PurchaseItemMapper;
  18. import com.dk.mdm.mapper.pur.PurchaseMapper;
  19. import com.dk.mdm.model.pojo.ivt.Inbound;
  20. import com.dk.mdm.model.pojo.ivt.InboundItem;
  21. import com.dk.mdm.model.pojo.pur.Purchase;
  22. import com.dk.mdm.model.pojo.pur.PurchaseItem;
  23. import com.dk.mdm.model.query.ivt.InboundItemQuery;
  24. import com.dk.mdm.model.query.ivt.InboundQuery;
  25. import com.dk.mdm.model.response.ivt.InboundItemResponse;
  26. import com.dk.mdm.model.response.ivt.InboundResponse;
  27. import com.dk.mdm.model.response.pur.PurchaseItemResponse;
  28. import com.dk.mdm.model.response.pur.PurchaseResponse;
  29. import com.dk.mdm.model.vo.ivt.InboundItemVO;
  30. import com.dk.mdm.model.vo.ivt.InboundVO;
  31. import com.dk.mdm.service.common.CommonService;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import java.math.BigDecimal;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. import java.util.Map;
  39. import java.util.UUID;
  40. /**
  41. * @desc : 采购入库业务层
  42. * @date : 2024/3/7 14:11
  43. * @author : 寇珊珊
  44. */
  45. @Service
  46. public class InboundPurchaseService extends BaseService<Inbound> {
  47. @Override
  48. public BaseMapper<Inbound> getRepository() {
  49. return inboundMapper;
  50. }
  51. @Autowired
  52. private InboundMapper inboundMapper;
  53. @Autowired
  54. private InboundConvert inboundConvert;
  55. @Autowired
  56. private InboundItemMapper inboundItemMapper;
  57. @Autowired
  58. private InboundItemConvert inboundItemConvert;
  59. @Autowired
  60. private PurchaseMapper purchaseMapper;
  61. @Autowired
  62. private PurchaseItemMapper purchaseItemMapper;
  63. @Autowired
  64. private CommonService commonService;
  65. /**
  66. * @desc : 条件查询
  67. * @date : 2024/3/7 14:12
  68. * @author : 寇珊珊
  69. */
  70. @Pagination
  71. public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
  72. return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
  73. inboundMapper.countByCond(inboundQuery));
  74. }
  75. /**
  76. * @desc : 查询明细
  77. * @date : 2024/3/9 15:43
  78. * @author : 寇珊珊
  79. */
  80. @Pagination
  81. public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
  82. Map<String, Object> result = new HashMap<>();
  83. // 商品明细
  84. List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
  85. result.put("itemList", inboundItemResponses);
  86. // 收款
  87. // 附件
  88. return ResponseResultUtil.success(result);
  89. }
  90. /**
  91. * @desc : 采购入库新建
  92. * @date : 2024/3/7 14:13
  93. * 入库中数量/金额 已入库数量/金额 由调用方传入
  94. * @author : 寇珊珊
  95. */
  96. @Transactional(rollbackFor = {Exception.class})
  97. public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
  98. //region 总单
  99. //获取 id/单号
  100. Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(),false);
  101. inboundVO.setIntoId(codeMap.get("outId").toString()).
  102. setIntoNo(codeMap.get("outNote").toString());
  103. //入库类型
  104. inboundVO.setIntoType(Constant.IntoType.SALE.getName());
  105. //自动入库标识
  106. if (inboundVO.getAutomaticFlg()) {
  107. //已入库
  108. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  109. } else {
  110. //入库中
  111. inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
  112. }
  113. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  114. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  115. inboundVO.setIntoQty(inboundVO.getIntoingQty())
  116. .setIntoAmt(inboundVO.getIntoingAmt())
  117. .setIntoingQty(BigDecimal.ZERO)
  118. .setIntoingAmt(BigDecimal.ZERO)
  119. ;
  120. }else{
  121. inboundVO.setIntoQty(BigDecimal.ZERO)
  122. .setIntoAmt(BigDecimal.ZERO)
  123. ;
  124. }
  125. //实体转换
  126. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  127. inboundMapper.insert(inbound);
  128. //endregion
  129. //region 采购总单
  130. if(inboundVO.getFromId()!=null){
  131. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  132. Purchase purchaseUpdate = new Purchase();
  133. purchaseUpdate.setPurId(inboundVO.getFromId());
  134. //已入库
  135. if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
  136. purchaseUpdate.setIntoingQty(inboundVO.getIntoQty().negate());
  137. purchaseUpdate.setIntoingAmt(inboundVO.getIntoAmt().negate());
  138. purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
  139. purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
  140. }
  141. //入库中
  142. else{
  143. purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty());
  144. purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt());
  145. }
  146. //根据id查询
  147. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  148. //入库状态
  149. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
  150. purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()));
  151. purchaseUpdate.setIntoStatus(intoStatus);
  152. //修改
  153. int countRow = purchaseMapper.updateById(purchaseUpdate);
  154. //数量超出
  155. if (countRow == 0) {
  156. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  157. }
  158. }
  159. //endregion
  160. //region 明细
  161. //校验明细
  162. if (inboundVO.getItemList().size() == 0) {
  163. return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  164. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  165. }
  166. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  167. //总单id
  168. inboundItemVO.setIntoId(inboundVO.getIntoId());
  169. //入库类型
  170. inboundItemVO.setIntoType(inboundVO.getIntoType());
  171. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  172. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  173. inboundItemVO
  174. .setIntoQty(inboundItemVO.getIntoingQty())
  175. .setIntoAmt(inboundItemVO.getIntoingAmt())
  176. .setIntoingQty(BigDecimal.ZERO)
  177. .setIntoingAmt(BigDecimal.ZERO)
  178. .setCostPrice(inboundItemVO.getPriceInto())
  179. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  180. ;
  181. }else{
  182. inboundItemVO
  183. .setIntoQty(BigDecimal.ZERO)
  184. .setIntoAmt(BigDecimal.ZERO);
  185. }
  186. //入库状态
  187. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  188. //实体转换
  189. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  190. inboundItemMapper.insert(inboundItem);
  191. //endregion
  192. //region 采购明细
  193. if(inboundItemVO.getFromItemId()!=null){
  194. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  195. PurchaseItem purchaseItem = new PurchaseItem();
  196. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  197. //已入库
  198. if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
  199. purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
  200. purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
  201. purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
  202. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
  203. }
  204. //入库中
  205. else{
  206. purchaseItem.setIntoingQty(inboundItemVO.getIntoQty());
  207. purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt());
  208. }
  209. //根据id查询
  210. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  211. //入库状态
  212. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  213. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
  214. purchaseItem.setIntoStatus(intoStatus);
  215. int countRow = purchaseItemMapper.updateById(purchaseItem);
  216. //数量超出
  217. if (countRow == 0) {
  218. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  219. }
  220. }
  221. //endregion
  222. }
  223. //endregion
  224. //todo 如果是已入库 调用库存 后续写库存这里补上
  225. //region 库存
  226. //endregion
  227. return ResponseResultUtil.success(inboundVO);
  228. }
  229. /**
  230. * @desc : 采购入库办理
  231. * @date : 2024/3/7 15:47
  232. * @author : 寇珊珊
  233. */
  234. @Transactional(rollbackFor = {Exception.class})
  235. public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
  236. //region 编辑明细
  237. //校验明细
  238. if (inboundVO.getItemList().size() == 0) {
  239. return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  240. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  241. }
  242. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  243. if (inboundItemVO.getIntoId() != null) {
  244. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  245. //编辑明细
  246. inboundItemVO
  247. .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
  248. .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
  249. .setIntoQty(inboundItemResponse.getOutQty().add(inboundItemVO.getIntoQty()))
  250. .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()))
  251. .setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
  252. .setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
  253. .setCostPrice(inboundItemVO.getPriceInto())
  254. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  255. ;
  256. //入库状态
  257. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  258. inboundItemVO.setIntoStatus(intoStatus);
  259. //实体转换
  260. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  261. //修改
  262. inboundItemMapper.update(inboundItem,
  263. new UpdateWrapper<InboundItem>().lambda()
  264. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  265. );
  266. }
  267. //endregion
  268. //region 新建明细
  269. else {
  270. inboundItemVO
  271. .setIntoQty(inboundItemVO.getIntoingQty())
  272. .setIntoAmt(inboundItemVO.getIntoingAmt())
  273. .setIntoId(inboundVO.getIntoId())
  274. .setCostPrice(inboundItemVO.getPriceInto())
  275. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  276. .setIntoType(Constant.IntoType.SALE.getName());
  277. //入库状态
  278. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  279. inboundItemVO.setIntoStatus(intoStatus);
  280. //实体转换
  281. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  282. //新建
  283. inboundItemMapper.insert(inboundItem);
  284. }
  285. //region 采购
  286. //采购明细
  287. if (inboundItemVO.getFromItemId() != null) {
  288. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  289. PurchaseItem purchaseItem = new PurchaseItem();
  290. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  291. purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
  292. purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
  293. purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
  294. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
  295. //根据id查询
  296. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  297. //入库状态
  298. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  299. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
  300. purchaseItem.setIntoStatus(intoStatus);
  301. int countRow = purchaseItemMapper.updateById(purchaseItem);
  302. //数量超出
  303. if (countRow == 0) {
  304. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  305. }
  306. }
  307. //endregion
  308. }
  309. //endregion
  310. //region 删除明细 todo 2024年3月20日13:14:20 这里可能用不到
  311. // BigDecimal sumDelIntoQty = BigDecimal.ZERO;
  312. // BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
  313. // BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
  314. // BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
  315. // if (inboundVO.getDeleteItemList() != null) {
  316. // sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  317. // sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  318. // sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  319. // sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  320. // for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
  321. // if (inboundItemVO.getItemId() != null) {
  322. // InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  323. // inboundItem.setFlgValid(false);
  324. // //修改
  325. // inboundItemMapper.update(inboundItem,
  326. // new UpdateWrapper<InboundItem>().lambda()
  327. // .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  328. // );
  329. // }
  330. // //region 采购
  331. // if (inboundItemVO.getFromItemId() != null) {
  332. // //region 采购订单明细
  333. // //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  334. // PurchaseItem purchaseItem = new PurchaseItem();
  335. // purchaseItem.setItemId(inboundItemVO.getFromItemId());
  336. // purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
  337. // purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
  338. // purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
  339. // purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
  340. // //根据id查询
  341. // PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  342. // //入库状态
  343. // String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  344. // purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
  345. // purchaseItem.setIntoStatus(intoStatus);
  346. // int countRow = purchaseItemMapper.updateById(purchaseItem);
  347. // //数量超出
  348. // if (countRow == 0) {
  349. // throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  350. // }
  351. // //endregion
  352. // }
  353. // //endregion
  354. //
  355. // }
  356. // }
  357. //endregion
  358. //region 编辑总单
  359. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  360. BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  361. BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  362. inboundVO.setIntoQty(sumIntoQty);
  363. inboundVO.setIntoAmt(sumIntoAmt);
  364. inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
  365. inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
  366. //入库状态
  367. String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
  368. inboundVO.setIntoStatus(intoStatus);
  369. //实体转换
  370. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  371. //修改
  372. inboundMapper.update(inbound,
  373. new UpdateWrapper<Inbound>().lambda()
  374. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  375. );
  376. //endregion
  377. //region 修改采购订单
  378. if (inboundVO.getFromId() != null) {
  379. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  380. Purchase purchase = new Purchase();
  381. purchase.setPurId(inboundVO.getFromId());
  382. //region todo 2024年3月20日13:14:51 这里可能用不到
  383. // purchase.setIntoQty(sumIntoQty.subtract(sumDelIntoQty));
  384. // purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
  385. // purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
  386. // purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
  387. //endregion
  388. purchase.setIntoQty(sumIntoQty);
  389. purchase.setIntoAmt(sumIntoAmt);
  390. purchase.setIntoingQty(sumIntoQty.negate());
  391. purchase.setIntoingAmt(sumIntoAmt.negate());
  392. //根据id查询
  393. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  394. //入库状态
  395. String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  396. purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
  397. purchase.setIntoStatus(purIntoStatus);
  398. //修改
  399. int countRow = purchaseMapper.updateById(purchase);
  400. //数量超出
  401. if (countRow == 0) {
  402. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  403. }
  404. }
  405. //endregion
  406. //todo 如果是已入库 调用库存 后续写库存这里补上
  407. //region 修改库存
  408. //endregion
  409. return ResponseResultUtil.success(inboundVO);
  410. }
  411. /**
  412. * @desc : 采购入库撤销
  413. * @date : 2024/3/7 17:06
  414. * @author : 寇珊珊
  415. */
  416. @Transactional(rollbackFor = {Exception.class})
  417. public ResponseResultVO<?> purchaseInboundCancel(InboundVO inboundVO) {
  418. //region 查询入库总单数据信息
  419. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  420. //endregion
  421. //region 修改订单数据信息
  422. if (inboundResponse.getFromId() != null) {
  423. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  424. Purchase purchase = new Purchase();
  425. purchase.setPurId(inboundResponse.getFromId());
  426. purchase.setIntoQty(inboundResponse.getIntoQty().negate());
  427. purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
  428. purchase.setIntoingQty(inboundResponse.getIntoQty());
  429. purchase.setIntoingAmt(inboundResponse.getIntoAmt());
  430. //根据id查询
  431. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  432. //入库状态
  433. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  434. purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
  435. purchase.setIntoStatus(intoStatus);
  436. int countRow = purchaseMapper.updateById(purchase);
  437. //数量超出
  438. if (countRow == 0) {
  439. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  440. }
  441. }
  442. //endregion
  443. //region 修改总单数据信息
  444. Inbound inbound = new Inbound();
  445. inbound.setIntoId(inboundVO.getIntoId());
  446. inbound.setIntoDate(null);
  447. inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
  448. inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
  449. inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
  450. inbound.setIntoQty(BigDecimal.ZERO);
  451. inbound.setIntoAmt(BigDecimal.ZERO);
  452. //修改
  453. inboundMapper.update(inbound,
  454. new UpdateWrapper<Inbound>().lambda()
  455. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  456. );
  457. //endregion
  458. //region 明细数据
  459. //根据总单id查明细
  460. List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
  461. for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
  462. //region 修改采购明细数据信息
  463. if(inboundItemResponse.getFromItemId()!=null){
  464. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  465. PurchaseItem purchaseItem = new PurchaseItem();
  466. purchaseItem.setItemId(inboundItemResponse.getFromItemId());
  467. purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
  468. purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  469. purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
  470. purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
  471. //根据id查询
  472. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
  473. //入库状态
  474. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  475. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
  476. purchaseItem.setIntoStatus(intoStatus);
  477. //修改
  478. int countRow = purchaseItemMapper.updateById(purchaseItem);
  479. //数量超出
  480. if (countRow == 0) {
  481. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  482. }
  483. }
  484. //endregion
  485. //region修改入库明细信息
  486. InboundItem inboundItem = new InboundItem();
  487. inboundItem
  488. .setIntoId(inbound.getIntoId())
  489. .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
  490. .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
  491. .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
  492. .setIntoQty(BigDecimal.ZERO)
  493. .setIntoAmt(BigDecimal.ZERO)
  494. .setCostPrice(BigDecimal.ZERO)
  495. .setCostAmt(BigDecimal.ZERO)
  496. .setItemId(inboundItemResponse.getItemId());
  497. //修改
  498. inboundItemMapper.update(inboundItem,
  499. new UpdateWrapper<InboundItem>().lambda()
  500. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  501. );
  502. //endregion
  503. }
  504. //endregion
  505. //todo 调用库存 后续写库存这里补上
  506. //region 修改库存
  507. //endregion
  508. return ResponseResultUtil.success();
  509. }
  510. /**
  511. * @desc : 入库状态通用(目前本页面)
  512. * @date : 2024/3/9 8:59
  513. * @author : 寇珊珊
  514. */
  515. public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
  516. //入库状态
  517. String intoStatus = null;
  518. //已入库数量>0 入库中数量>0
  519. if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
  520. //入库中
  521. intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
  522. }
  523. //已入库数量=0 入库中数量=0
  524. else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  525. //待入库
  526. intoStatus = Constant.IntoStatus.DAIRUKU.getName();
  527. }
  528. //已入库数量>0 入库中数量=0
  529. else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
  530. //已入库
  531. intoStatus = Constant.IntoStatus.YIRUKU.getName();
  532. }
  533. return intoStatus;
  534. }
  535. }