InboundOtherService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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.common.CommonMapper;
  16. import com.dk.mdm.mapper.ivt.InboundItemMapper;
  17. import com.dk.mdm.mapper.ivt.InboundMapper;
  18. import com.dk.mdm.model.pojo.ivt.Inbound;
  19. import com.dk.mdm.model.pojo.ivt.InboundItem;
  20. import com.dk.mdm.model.pojo.pur.Purchase;
  21. import com.dk.mdm.model.pojo.pur.PurchaseItem;
  22. import com.dk.mdm.model.query.ivt.InboundItemQuery;
  23. import com.dk.mdm.model.query.ivt.InboundQuery;
  24. import com.dk.mdm.model.response.ivt.InboundItemResponse;
  25. import com.dk.mdm.model.response.ivt.InboundResponse;
  26. import com.dk.mdm.model.vo.ivt.InboundItemVO;
  27. import com.dk.mdm.model.vo.ivt.InboundVO;
  28. import com.dk.mdm.service.common.CommonService;
  29. import com.dk.mdm.service.ivt.inventory.InventoryService;
  30. import io.swagger.annotations.ApiOperation;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.stereotype.Service;
  33. import org.springframework.transaction.annotation.Transactional;
  34. import org.springframework.web.bind.annotation.PostMapping;
  35. import org.springframework.web.bind.annotation.RequestBody;
  36. import javax.validation.Valid;
  37. import java.math.BigDecimal;
  38. import java.util.HashMap;
  39. import java.util.List;
  40. import java.util.Map;
  41. import java.util.UUID;
  42. /**
  43. * @desc : 其他入库业务层
  44. * @date : 2024/3/7 14:11
  45. * @author : 寇珊珊
  46. */
  47. @Service
  48. public class InboundOtherService extends BaseService<Inbound> {
  49. @Override
  50. public BaseMapper<Inbound> getRepository() {
  51. return inboundMapper;
  52. }
  53. @Autowired
  54. private InboundMapper inboundMapper;
  55. @Autowired
  56. private InboundConvert inboundConvert;
  57. @Autowired
  58. private InboundItemMapper inboundItemMapper;
  59. @Autowired
  60. private InboundItemConvert inboundItemConvert;
  61. @Autowired
  62. private CommonService commonService;
  63. @Autowired
  64. private CommonMapper commonMapper;
  65. @Autowired
  66. private InventoryService inventoryService;
  67. /**
  68. * @desc : 条件查询
  69. * @date : 2024/3/7 14:12
  70. * @author : 寇珊珊
  71. */
  72. @Pagination
  73. public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
  74. return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
  75. inboundMapper.countByCond(inboundQuery));
  76. }
  77. /**
  78. * @desc : 查询明细
  79. * @date : 2024/3/9 15:43
  80. * @author : 寇珊珊
  81. */
  82. @Pagination
  83. public ResponseResultVO<Map<String, Object>> selectOtherInboundItemInfoById(String id) {
  84. Map<String, Object> result = new HashMap<>();
  85. // 商品明细
  86. List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
  87. result.put("itemList", inboundItemResponses);
  88. // 收款
  89. // 附件
  90. return ResponseResultUtil.success(result);
  91. }
  92. /**
  93. * @desc : 其他入库新建
  94. * @date : 2024/3/7 14:13
  95. * @author : 寇珊珊
  96. */
  97. @Transactional(rollbackFor = {Exception.class})
  98. public ResponseResultVO<?> otherInboundInsert(InboundVO inboundVO) {
  99. //region 查询当前公司的系统参数 自动办理信息 并赋值
  100. Map<String, Object> map = new HashMap<>();
  101. map.put("cpId", inboundVO.getCpId());
  102. map.put("code", "IVT_001");
  103. //自动办理标识
  104. String flgHandleSetting = commonMapper.getSettingValue(map);
  105. //自动办理标识为1 自动办理入库
  106. if(Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)){
  107. inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
  108. inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
  109. }
  110. //endregion
  111. //region 总单
  112. //获取 id/单号
  113. Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(),false);
  114. inboundVO.setIntoId(codeMap.get("outId").toString()).
  115. setIntoNo(codeMap.get("outNote").toString());
  116. //入库类型
  117. inboundVO.setIntoType(Constant.IntoType.OTHER.getName());
  118. //自动入库标识
  119. if (inboundVO.getFlgAutoHandle()) {
  120. //已入库
  121. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  122. } else {
  123. //入库中
  124. inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
  125. }
  126. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  127. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  128. inboundVO.setIntoQty(inboundVO.getIntoingQty())
  129. .setIntoAmt(inboundVO.getIntoingAmt())
  130. .setIntoingQty(BigDecimal.ZERO)
  131. .setIntoingAmt(BigDecimal.ZERO)
  132. ;
  133. }else{
  134. inboundVO.setIntoQty(BigDecimal.ZERO)
  135. .setIntoAmt(BigDecimal.ZERO)
  136. ;
  137. }
  138. //实体转换
  139. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  140. inboundMapper.insert(inbound);
  141. //endregion
  142. //region 明细
  143. //校验明细
  144. if (inboundVO.getItemList().size() == 0) {
  145. return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  146. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  147. }
  148. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  149. //region 将库存需要的参数赋值
  150. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  151. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
  152. //endregion
  153. //总单id
  154. inboundItemVO.setIntoId(inboundVO.getIntoId());
  155. //入库类型
  156. inboundItemVO.setIntoType(inboundVO.getIntoType());
  157. //出库数量
  158. inboundItemVO.setOutQty(BigDecimal.ZERO);
  159. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  160. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  161. inboundItemVO
  162. .setIntoQty(inboundItemVO.getIntoingQty())
  163. .setIntoAmt(inboundItemVO.getIntoingAmt())
  164. .setIntoingQty(BigDecimal.ZERO)
  165. .setIntoingAmt(BigDecimal.ZERO)
  166. .setCostPrice(inboundItemVO.getPriceInto())
  167. .setCostAmt(inboundItemVO.getOutQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  168. ;
  169. }else{
  170. inboundItemVO
  171. .setIntoQty(BigDecimal.ZERO)
  172. .setIntoAmt(BigDecimal.ZERO);
  173. }
  174. //入库状态
  175. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  176. //实体转换
  177. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  178. inboundItemMapper.insert(inboundItem);
  179. }
  180. //endregion
  181. //todo 如果是已入库 调用库存 后续写库存这里补上
  182. //region 库存
  183. if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
  184. Map<String, Object> invMap = new HashMap<>();
  185. map.put("intoDetail",inboundVO.getItemList());
  186. inventoryService.updateInventoryInformation(invMap);
  187. }
  188. //endregion
  189. return ResponseResultUtil.success(inboundVO);
  190. }
  191. /**
  192. * @desc : 其他入库编辑
  193. * @date : 2024/3/25 16:25
  194. * @author : 寇珊珊
  195. */
  196. @Transactional(rollbackFor = {Exception.class})
  197. public ResponseResultVO<?> otherInboundUpdate(InboundVO inboundVO) {
  198. //region 明细数量金额 求和
  199. BigDecimal sumQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  200. BigDecimal sumAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  201. //endregion
  202. //region 自动办理参数为true 已入库编辑
  203. //自动办理参数为true
  204. if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) {
  205. //region 修改明细
  206. List<InboundItemVO> itemList = inboundVO.getItemList();
  207. for (InboundItemVO inboundItemVO : itemList) {
  208. //根据id查询
  209. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  210. //region 将库存需要的参数赋值
  211. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  212. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  213. //编辑之前的数
  214. inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
  215. inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
  216. //编辑之后的数
  217. inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
  218. inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
  219. //endregion
  220. //赋值
  221. InboundItem inboundItem = new InboundItem();
  222. inboundItem.setItemId(inboundItemVO.getItemId());
  223. inboundItem.setIntoQty(inboundItemVO.getIntoingQty());
  224. inboundItem.setIntoAmt(inboundItemVO.getIntoingAmt());
  225. inboundItem.setCostPrice(inboundItemVO.getPriceInto());
  226. inboundItem.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(6, BigDecimal.ROUND_HALF_UP));
  227. //修改
  228. inboundItemMapper.update(inboundItem,
  229. new UpdateWrapper<InboundItem>().lambda()
  230. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  231. );
  232. }
  233. //endregion
  234. //region 修改入库总单
  235. Inbound inbound = new Inbound();
  236. inbound.setIntoId(inboundVO.getIntoId());
  237. inbound.setIntoQty(sumQty);
  238. inbound.setIntoAmt(sumAmt);
  239. //修改
  240. inboundMapper.update(inbound,
  241. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  242. );
  243. //endregion
  244. //region todo调用库存
  245. Map<String, Object> map = new HashMap<>();
  246. map.put("intoDetail", inboundVO.getItemList());
  247. inventoryService.updateInventoryInformation(map);
  248. //endregion
  249. }
  250. //endregion
  251. //region 自动办理参数false 入库中编辑
  252. //自动办理标识为false 并且 自动办理参数为false 入库中
  253. if (!inboundVO.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(inboundVO.getFlgHandleSetting())) {
  254. //region 修改明细
  255. List<InboundItemVO> itemList = inboundVO.getItemList();
  256. for (InboundItemVO inboundItemVO : itemList) {
  257. //赋值
  258. InboundItem inboundItem = new InboundItem();
  259. inboundItem.setItemId(inboundItemVO.getItemId());
  260. inboundItem.setIntoingQty(inboundItemVO.getIntoingQty());
  261. inboundItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
  262. //修改
  263. inboundItemMapper.update(inboundItem,
  264. new UpdateWrapper<InboundItem>().lambda()
  265. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  266. );
  267. }
  268. //endregion
  269. //region 修改入库总单
  270. Inbound inbound = new Inbound();
  271. inbound.setIntoId(inboundVO.getIntoId());
  272. inbound.setIntoingQty(sumQty);
  273. inbound.setIntoingAmt(sumAmt);
  274. //修改
  275. inboundMapper.update(inbound,
  276. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  277. );
  278. //endregion
  279. }
  280. //endregion
  281. return ResponseResultUtil.success(inboundVO);
  282. }
  283. /**
  284. * @desc : 其他入库作废
  285. * @date : 2024/3/25 16:25
  286. * @author : 寇珊珊
  287. */
  288. @Transactional(rollbackFor = {Exception.class})
  289. public ResponseResultVO<?> otherInboundRepeal(String intoId) {
  290. //region 查询总单 查询明细
  291. //根据id查询 此条入库单的数据还未更改前的数据
  292. InboundResponse inboundResponse = inboundMapper.selectById(intoId);
  293. //根据总单id查询
  294. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
  295. //endregion
  296. //region 自动办理参数为true 已入库编辑
  297. //自动办理参数为true
  298. if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundResponse.getFlgHandleSetting())) {
  299. //region todo 退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作
  300. if (inboundResponse.getReceivableId() != null) {
  301. }
  302. //endregion
  303. //region 修改明细
  304. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  305. //region 将库存需要的参数赋值
  306. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  307. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  308. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  309. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  310. //endregion
  311. //赋值
  312. InboundItem inboundItem = new InboundItem();
  313. inboundItem.setItemId(inboundItemResponse.getItemId());
  314. inboundItem.setFlgValid(false);
  315. //修改
  316. inboundItemMapper.update(inboundItem,
  317. new UpdateWrapper<InboundItem>().lambda()
  318. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  319. );
  320. }
  321. //endregion
  322. //region 修改入库总单
  323. Inbound inbound = new Inbound();
  324. inbound.setIntoId(inboundResponse.getIntoId());
  325. inbound.setFlgValid(false);
  326. //修改
  327. inboundMapper.update(inbound,
  328. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  329. );
  330. //endregion
  331. //region
  332. Map<String, Object> map = new HashMap<>();
  333. map.put("intoDetail", inboundItemResponseList);
  334. inventoryService.updateInventoryInformation(map);
  335. //endregion
  336. }
  337. //endregion
  338. //region 自动办理参数false 入库中编辑
  339. //自动办理标识为false 并且 自动办理参数为false 入库中
  340. if (!inboundResponse.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(inboundResponse.getFlgHandleSetting())) {
  341. //region 修改明细
  342. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  343. //赋值
  344. InboundItem inboundItem = new InboundItem();
  345. inboundItem.setItemId(inboundItemResponse.getItemId());
  346. inboundItem.setIntoingQty(BigDecimal.ZERO);
  347. inboundItem.setIntoingAmt(BigDecimal.ZERO);
  348. //修改
  349. inboundItemMapper.update(inboundItem,
  350. new UpdateWrapper<InboundItem>().lambda()
  351. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  352. );
  353. }
  354. //endregion
  355. //region 修改入库总单
  356. Inbound inbound = new Inbound();
  357. inbound.setIntoId(inboundResponse.getIntoId());
  358. inbound.setIntoingQty(BigDecimal.ZERO);
  359. inbound.setIntoAmt(BigDecimal.ZERO);
  360. //修改
  361. inboundMapper.update(inbound,
  362. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  363. );
  364. //endregion
  365. }
  366. //endregion
  367. return ResponseResultUtil.success();
  368. }
  369. /**
  370. * @desc : 其他入库办理
  371. * @date : 2024/3/7 15:47
  372. * @author : 寇珊珊
  373. */
  374. @Transactional(rollbackFor = {Exception.class})
  375. public ResponseResultVO<?> otherHandleInbound(InboundVO inboundVO) {
  376. //region 编辑明细
  377. //校验明细
  378. if (inboundVO.getItemList().size() == 0) {
  379. return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  380. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  381. }
  382. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  383. //region 将库存需要的参数赋值
  384. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  385. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
  386. //endregion
  387. //region 修改明细
  388. if (inboundItemVO.getIntoId() != null) {
  389. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  390. //region 校验数量是否超出
  391. if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoQty()) > 0) {
  392. return ResponseResultUtil.error(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
  393. ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
  394. }
  395. //endregion
  396. //region 编辑明细
  397. inboundItemVO
  398. .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
  399. .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
  400. .setIntoingQty(BigDecimal.ZERO)
  401. .setIntoingAmt(BigDecimal.ZERO)
  402. .setCostPrice(inboundItemVO.getPriceInto())
  403. .setCostPrice(inboundItemVO.getIntoQty().subtract(inboundItemVO.getCostPrice()).setScale(2, BigDecimal.ROUND_HALF_UP))
  404. ;
  405. //入库状态
  406. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  407. inboundItemVO.setIntoStatus(intoStatus);
  408. //实体转换
  409. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  410. //修改
  411. inboundItemMapper.update(inboundItem,
  412. new UpdateWrapper<InboundItem>().lambda()
  413. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  414. );
  415. //endregion
  416. }
  417. //endregion
  418. //region 新建明细
  419. else {
  420. inboundItemVO
  421. .setIntoQty(inboundItemVO.getIntoingQty())
  422. .setIntoAmt(inboundItemVO.getIntoingAmt())
  423. .setIntoId(inboundVO.getIntoId())
  424. .setCostPrice(inboundItemVO.getPriceInto())
  425. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  426. .setIntoType(Constant.IntoType.OTHER.getName())
  427. .setIntoingQty(BigDecimal.ZERO)
  428. .setIntoingAmt(BigDecimal.ZERO)
  429. ;
  430. //入库状态
  431. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  432. inboundItemVO.setIntoStatus(intoStatus);
  433. //实体转换
  434. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  435. //新建
  436. inboundItemMapper.insert(inboundItem);
  437. }
  438. //endregion
  439. }
  440. //endregion
  441. //region 删除明细
  442. if (inboundVO.getDeleteItemList() != null) {
  443. for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
  444. if (inboundItemVO.getItemId() != null) {
  445. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  446. inboundItem.setFlgValid(false);
  447. //修改
  448. inboundItemMapper.update(inboundItem,
  449. new UpdateWrapper<InboundItem>().lambda()
  450. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  451. );
  452. }
  453. }
  454. }
  455. //endregion
  456. //region 编辑总单
  457. BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  458. BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  459. inboundVO.setIntoQty(sumIntoQty);
  460. inboundVO.setIntoAmt(sumIntoAmt);
  461. inboundVO.setIntoingQty(BigDecimal.ZERO);
  462. inboundVO.setIntoingAmt(BigDecimal.ZERO);
  463. //入库状态
  464. String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
  465. inboundVO.setIntoStatus(intoStatus);
  466. //实体转换
  467. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  468. //修改
  469. inboundMapper.update(inbound,
  470. new UpdateWrapper<Inbound>().lambda()
  471. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  472. );
  473. //endregion
  474. //region 修改库存
  475. Map<String, Object> map = new HashMap<>();
  476. map.put("intoDetail", inboundVO.getItemList());
  477. inventoryService.updateInventoryInformation(map);
  478. //endregion
  479. return ResponseResultUtil.success(inboundVO);
  480. }
  481. /**
  482. * @desc : 其它入库撤销
  483. * @date : 2024/3/7 17:06
  484. * @author : 寇珊珊
  485. */
  486. @Transactional(rollbackFor = {Exception.class})
  487. public ResponseResultVO<?> otherInboundCancel(InboundVO inboundVO) {
  488. //region 总单数据信息
  489. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  490. Inbound inbound = new Inbound();
  491. inbound.setIntoId(inboundResponse.getIntoId())
  492. .setIntoDate(null)
  493. .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
  494. .setIntoingQty(inboundResponse.getIntoQty())
  495. .setIntoingAmt(inboundResponse.getIntoAmt())
  496. .setIntoQty(BigDecimal.ZERO)
  497. .setIntoAmt(BigDecimal.ZERO);
  498. //修改
  499. inboundMapper.update(inbound,
  500. new UpdateWrapper<Inbound>().lambda()
  501. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  502. );
  503. //endregion
  504. //region 明细数据
  505. InboundItemQuery inboundItemQuery = new InboundItemQuery().setIntoId(inbound.getIntoId());
  506. //根据总单查明细
  507. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(inboundItemQuery);
  508. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  509. //region 将库存需要的参数赋值
  510. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  511. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
  512. //region
  513. InboundItem inboundItem = new InboundItem();
  514. inboundItem
  515. .setIntoId(inbound.getIntoId())
  516. .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
  517. .setIntoingQty(inboundItemResponse.getInvQty())
  518. .setIntoingAmt(inboundItemResponse.getIntoAmt())
  519. .setIntoQty(BigDecimal.ZERO)
  520. .setIntoAmt(BigDecimal.ZERO)
  521. .setCostPrice(BigDecimal.ZERO)
  522. .setCostAmt(BigDecimal.ZERO)
  523. .setItemId(inboundItemResponse.getItemId());
  524. //修改
  525. inboundItemMapper.update(inboundItem,
  526. new UpdateWrapper<InboundItem>().lambda()
  527. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  528. );
  529. //数量金额取反 用于给库存使用
  530. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  531. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  532. }
  533. //endregion
  534. //region 修改库存
  535. Map<String, Object> map = new HashMap<>();
  536. map.put("intoDetail", inboundItemResponseList);
  537. inventoryService.updateInventoryInformation(map);
  538. //endregion
  539. return ResponseResultUtil.success();
  540. }
  541. /**
  542. * @desc : 入库状态通用(目前本页面)
  543. * @date : 2024/3/9 8:59
  544. * @author : 寇珊珊
  545. */
  546. public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
  547. //入库状态
  548. String intoStatus = null;
  549. //已入库数量>=0 入库中数量>0
  550. if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
  551. //入库中
  552. intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
  553. }
  554. //已入库数量=0 入库中数量=0
  555. else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  556. //待入库
  557. intoStatus = Constant.IntoStatus.DAIRUKU.getName();
  558. }
  559. //已入库数量>0 入库中数量=0
  560. else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
  561. //已入库
  562. intoStatus = Constant.IntoStatus.YIRUKU.getName();
  563. }
  564. return intoStatus;
  565. }
  566. /**
  567. * @desc : 条件查询 --- web端入库办理用
  568. * @date : 2024/3/23 9:24
  569. * @author : 寇珊珊
  570. */
  571. @Pagination
  572. public ResponseResultVO<PageList<InboundResponse>> selectInbound(InboundQuery inboundQuery) {
  573. return super.mergeListWithCount(inboundQuery, inboundMapper.selectInbound(inboundQuery),
  574. inboundMapper.selectInboundCond(inboundQuery));
  575. }
  576. /**
  577. * @desc : 查询明细查询 --- web端入库办理用
  578. * @date : 2024/3/9 15:43
  579. * @author : 寇珊珊
  580. */
  581. public ResponseResultVO<Map<String, Object>> selectInboundItem(String id) {
  582. Map<String, Object> result = new HashMap<>();
  583. // 商品明细
  584. List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectInboundItem(new InboundItemQuery().setIntoId(id));
  585. result.put("itemList", inboundItemResponses);
  586. // 收款
  587. // 附件
  588. return ResponseResultUtil.success(result);
  589. }
  590. }