InboundOtherService.java 36 KB

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