InboundOtherService.java 38 KB

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