InboundPurchaseService.java 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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.model.vo.AnnexVO;
  10. import com.dk.common.response.ResponseCodeEnum;
  11. import com.dk.common.response.ResponseResultUtil;
  12. import com.dk.common.response.ResponseResultVO;
  13. import com.dk.common.service.BaseService;
  14. import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
  15. import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
  16. import com.dk.mdm.mapper.common.CommonMapper;
  17. import com.dk.mdm.mapper.ivt.InboundItemMapper;
  18. import com.dk.mdm.mapper.ivt.InboundMapper;
  19. import com.dk.mdm.mapper.pur.PurchaseItemMapper;
  20. import com.dk.mdm.mapper.pur.PurchaseMapper;
  21. import com.dk.mdm.model.pojo.ivt.Inbound;
  22. import com.dk.mdm.model.pojo.ivt.InboundItem;
  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.response.pur.PurchaseItemResponse;
  30. import com.dk.mdm.model.response.pur.PurchaseResponse;
  31. import com.dk.mdm.model.vo.ivt.InboundItemVO;
  32. import com.dk.mdm.model.vo.ivt.InboundVO;
  33. import com.dk.mdm.service.common.CommonService;
  34. import com.dk.mdm.service.ivt.inventory.InventoryService;
  35. import com.dk.mdm.service.mac.AccountService;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.stereotype.Service;
  38. import org.springframework.transaction.annotation.Transactional;
  39. import java.math.BigDecimal;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. import java.util.Map;
  43. import java.util.UUID;
  44. /**
  45. * @author : 寇珊珊
  46. * @desc : 采购入库业务层
  47. * @date : 2024/3/7 14:11
  48. */
  49. @Service
  50. public class InboundPurchaseService extends BaseService<Inbound> {
  51. @Override
  52. public BaseMapper<Inbound> getRepository() {
  53. return inboundMapper;
  54. }
  55. @Autowired
  56. private InboundMapper inboundMapper;
  57. @Autowired
  58. private InboundConvert inboundConvert;
  59. @Autowired
  60. private InboundItemMapper inboundItemMapper;
  61. @Autowired
  62. private InboundItemConvert inboundItemConvert;
  63. @Autowired
  64. private PurchaseMapper purchaseMapper;
  65. @Autowired
  66. private PurchaseItemMapper purchaseItemMapper;
  67. @Autowired
  68. private CommonService commonService;
  69. @Autowired
  70. private CommonMapper commonMapper;
  71. @Autowired
  72. private InventoryService inventoryService;
  73. @Autowired
  74. private AccountService accountService;
  75. /**
  76. * @desc : 条件查询
  77. * @date : 2024/3/7 14:12
  78. * @author : 寇珊珊
  79. */
  80. @Pagination
  81. public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
  82. return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
  83. inboundMapper.countByCond(inboundQuery));
  84. }
  85. /**
  86. * @desc : 查询明细
  87. * @date : 2024/3/9 15:43
  88. * @author : 寇珊珊
  89. */
  90. @Pagination
  91. public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
  92. Map<String, Object> result = new HashMap<>();
  93. // 商品明细
  94. List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
  95. result.put("itemList", inboundItemResponses);
  96. // 收款
  97. // 附件
  98. return ResponseResultUtil.success(result);
  99. }
  100. /**
  101. * @desc : 查询入库价
  102. * @date : 2024/7/1 11:29
  103. * @author : 寇珊珊
  104. */
  105. @Transactional(rollbackFor = {Exception.class})
  106. public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) {
  107. List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId())
  108. .setNonStdCode(inboundItemVO.getNonStdCode())
  109. .setWhId(inboundItemVO.getWhId()));
  110. if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
  111. return inboundItemResponses.get(0);
  112. }
  113. return null;
  114. }
  115. /**
  116. * @desc : 采购入库新建
  117. * @date : 2024/3/7 14:13
  118. * 入库中数量/金额 已入库数量/金额 由调用方传入
  119. * @author : 寇珊珊
  120. */
  121. @Transactional(rollbackFor = {Exception.class})
  122. public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
  123. //region 校验明细
  124. if (inboundVO.getItemList().size() == 0) {
  125. throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  126. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  127. }
  128. //endregion
  129. //region 查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
  130. Boolean priceIntoFlag = false;
  131. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  132. if(inboundItemVO.getPriceInto() == null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){
  133. priceIntoFlag = true;
  134. //查询库存批次最近一条入库价
  135. InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
  136. inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO);
  137. inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
  138. inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO);
  139. inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
  140. }
  141. }
  142. if(priceIntoFlag){
  143. BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  144. inboundVO.setIntoingAmt(intoingAmt);
  145. }
  146. //endregion
  147. //region 查询当前公司的系统参数 自动办理信息 并赋值
  148. Map<String, Object> map = new HashMap<>();
  149. map.put("cpId", inboundVO.getCpId());
  150. map.put("code", Constant.SystemConstant.IVT_001.getValue());
  151. //自动办理标识
  152. String flgHandleSetting = commonMapper.getSettingValue(map);
  153. //自动办理标识为1 自动办理入库
  154. if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
  155. inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
  156. inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
  157. }
  158. //endregion
  159. //region 总单
  160. //获取 id/单号
  161. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(), false);
  162. inboundVO.setIntoId(codeMap.get("outId").toString()).
  163. setIntoNo(codeMap.get("outNote").toString());
  164. //入库类型
  165. inboundVO.setIntoType(Constant.IntoType.SALE.getName());
  166. //自动入库标识
  167. if (inboundVO.getFlgAutoHandle()) {
  168. //已入库
  169. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  170. } else {
  171. //入库中
  172. inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
  173. }
  174. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  175. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  176. inboundVO.setIntoQty(inboundVO.getIntoingQty())
  177. .setIntoAmt(inboundVO.getIntoingAmt())
  178. .setIntoingQty(BigDecimal.ZERO)
  179. .setIntoingAmt(BigDecimal.ZERO)
  180. ;
  181. } else {
  182. inboundVO.setIntoQty(BigDecimal.ZERO)
  183. .setIntoAmt(BigDecimal.ZERO)
  184. ;
  185. }
  186. //实体转换
  187. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  188. inboundMapper.insert(inbound);
  189. //endregion
  190. //region 采购总单
  191. if (inboundVO.getFromId() != null) {
  192. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  193. Purchase purchaseUpdate = new Purchase();
  194. purchaseUpdate.setPurId(inboundVO.getFromId());
  195. //根据id查询
  196. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  197. //已入库
  198. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  199. purchaseUpdate.setIntoingQty(BigDecimal.ZERO);
  200. purchaseUpdate.setIntoingAmt(BigDecimal.ZERO);
  201. purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
  202. purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
  203. }
  204. //入库中
  205. else {
  206. purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty());
  207. purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt());
  208. purchaseUpdate.setIntoQty(BigDecimal.ZERO);
  209. purchaseUpdate.setIntoAmt(BigDecimal.ZERO);
  210. }
  211. //入库状态
  212. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
  213. purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()), purchaseResponse.getSumQuantity());
  214. purchaseUpdate.setIntoStatus(intoStatus);
  215. //修改
  216. int countRow = purchaseMapper.updateById(purchaseUpdate);
  217. //数量超出
  218. if (countRow == 0) {
  219. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  220. }
  221. }
  222. //endregion
  223. //region 明细
  224. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  225. //region 将库存需要的参数赋值
  226. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  227. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  228. inboundItemVO.setAddOrEditFlag(true);
  229. //endregion
  230. //总单id
  231. inboundItemVO.setIntoId(inboundVO.getIntoId());
  232. //入库类型
  233. inboundItemVO.setIntoType(inboundVO.getIntoType());
  234. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  235. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  236. inboundItemVO
  237. .setIntoQty(inboundItemVO.getIntoingQty())
  238. .setIntoAmt(inboundItemVO.getIntoingAmt())
  239. .setIntoingQty(BigDecimal.ZERO)
  240. .setIntoingAmt(BigDecimal.ZERO)
  241. .setCostPrice(inboundItemVO.getPriceInto())
  242. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  243. ;
  244. } else {
  245. inboundItemVO
  246. .setIntoQty(BigDecimal.ZERO)
  247. .setIntoAmt(BigDecimal.ZERO);
  248. }
  249. //入库状态
  250. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  251. //实体转换
  252. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  253. inboundItemMapper.insert(inboundItem);
  254. inboundItemVO.setItemId(inboundItem.getItemId());
  255. //endregion
  256. //region 采购明细
  257. if (inboundItemVO.getFromItemId() != null) {
  258. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  259. PurchaseItem purchaseItem = new PurchaseItem();
  260. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  261. //根据id查询
  262. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  263. //已入库
  264. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  265. purchaseItem.setIntoingQty(BigDecimal.ZERO);
  266. purchaseItem.setIntoingAmt(BigDecimal.ZERO);
  267. purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
  268. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
  269. }
  270. //入库中
  271. else {
  272. purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
  273. purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
  274. purchaseItem.setIntoQty(BigDecimal.ZERO);
  275. purchaseItem.setIntoAmt(BigDecimal.ZERO);
  276. }
  277. //入库状态
  278. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  279. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  280. purchaseItem.setIntoStatus(intoStatus);
  281. int countRow = purchaseItemMapper.updateById(purchaseItem);
  282. //数量超出
  283. if (countRow == 0) {
  284. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  285. }
  286. }
  287. //endregion
  288. }
  289. //endregion
  290. //region 入账
  291. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  292. accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  293. }
  294. //endregion
  295. //region 库存
  296. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
  297. Map<String, Object> invMap = new HashMap<>();
  298. invMap.put("intoDetail", inboundVO.getItemList());
  299. inventoryService.operatingInventoryInformation(invMap);
  300. }
  301. //endregion
  302. return ResponseResultUtil.success(inboundVO);
  303. }
  304. /**
  305. * @desc : 采购入库编辑
  306. * @date : 2024/3/25 16:25
  307. * @author : 寇珊珊
  308. */
  309. @Transactional(rollbackFor = {Exception.class})
  310. public ResponseResultVO<?> purchaseInboundUpdate(InboundVO inboundVO) {
  311. //region 小编辑
  312. if (!inboundVO.getLimitEdit()) {
  313. Inbound inbound = new Inbound();
  314. inbound.setIntoId(inboundVO.getIntoId());
  315. inbound.setRemarks(inboundVO.getRemarks());
  316. inbound.setAnnexPaths(inboundVO.getAnnexPaths());
  317. inboundMapper.update(inbound,
  318. new UpdateWrapper<Inbound>().lambda()
  319. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  320. );
  321. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  322. InboundItem inboundItem = new InboundItem();
  323. inboundItem.setItemId(inboundItemVO.getItemId());
  324. if (inboundItemVO.getRemarks() != null && inboundItemVO.getRemarks() != "") {
  325. inboundItem.setRemarks(inboundItemVO.getRemarks());
  326. inboundItemMapper.update(inboundItem,
  327. new UpdateWrapper<InboundItem>().lambda()
  328. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  329. );
  330. }
  331. }
  332. }
  333. //endregion
  334. //region 大编辑
  335. else {
  336. //region 根据id查询 此条入库单的数据还未更改前的数据
  337. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  338. BigDecimal sumQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  339. BigDecimal sumAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  340. //endregion
  341. //region 自动办理参数为true 已入库编辑
  342. //自动办理参数为true
  343. if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) {
  344. //region 退账
  345. if (inboundVO.getReceivableId() != null) {
  346. accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  347. }
  348. //endregion
  349. //region 修改明细
  350. List<InboundItemVO> itemList = inboundVO.getItemList();
  351. for (InboundItemVO inboundItemVO : itemList) {
  352. //根据id查询
  353. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  354. //region 编辑明细 赋值
  355. if (inboundItemVO.getItemId() != null) {
  356. //region 将库存需要的参数赋值
  357. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  358. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  359. //编辑之前的数
  360. inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
  361. inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
  362. //编辑之后的数
  363. inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty());
  364. inboundItemVO.setIntoAmt(inboundItemVO.getIntoingAmt());
  365. inboundItemVO.setAddOrEditFlag(false);
  366. //endregion
  367. InboundItem inboundItem = new InboundItem();
  368. inboundItem.setItemId(inboundItemVO.getItemId());
  369. inboundItem.setIntoQty(inboundItemVO.getIntoingQty());
  370. inboundItem.setIntoAmt(inboundItemVO.getIntoingAmt());
  371. inboundItem.setCostPrice(inboundItemVO.getPriceInto());
  372. inboundItem.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(6, BigDecimal.ROUND_HALF_UP));
  373. //修改
  374. inboundItemMapper.update(inboundItem,
  375. new UpdateWrapper<InboundItem>().lambda()
  376. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  377. );
  378. }
  379. //endregion
  380. //region 新建明细
  381. else {
  382. inboundItemVO
  383. .setIntoQty(inboundItemVO.getIntoingQty())
  384. .setIntoAmt(inboundItemVO.getIntoingAmt())
  385. .setIntoingQty(BigDecimal.ZERO)
  386. .setIntoingAmt(BigDecimal.ZERO)
  387. .setCostPrice(inboundItemVO.getPriceInto())
  388. .setCostAmt(inboundItemVO.getOutQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  389. ;
  390. inboundItemVO.setIntoId(inboundVO.getIntoId());
  391. //入库状态
  392. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  393. inboundItemVO.setIntoType(Constant.IntoType.SALE.getName());
  394. //实体转换
  395. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  396. inboundItemMapper.insert(inboundItem);
  397. inboundItemVO.setItemId(inboundItem.getItemId());
  398. //region 将库存需要的参数赋值
  399. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  400. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  401. inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
  402. inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
  403. inboundItemVO.setAddOrEditFlag(true);
  404. //endregion
  405. }
  406. //endregion
  407. //region 销售明细
  408. if (inboundItemVO.getFromItemId() != null) {
  409. //根据id查询
  410. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  411. PurchaseItem purchaseItem = new PurchaseItem();
  412. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  413. purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate().add(inboundItemVO.getIntoingQty()));
  414. purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate().add(inboundItemVO.getIntoingAmt()));
  415. //入库状态
  416. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
  417. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  418. purchaseItem.setIntoStatus(intoStatus);
  419. int countRow = purchaseItemMapper.updateById(purchaseItem);
  420. //数量超出
  421. if (countRow == 0) {
  422. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  423. }
  424. }
  425. //endregion
  426. }
  427. //endregion
  428. //region 删除明细
  429. BigDecimal delIntoQty = BigDecimal.ZERO;
  430. BigDecimal delIntoAmt = BigDecimal.ZERO;
  431. if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
  432. delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  433. delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  434. for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
  435. if (inboundItemVO.getItemId() != null) {
  436. //region 将库存需要的参数赋值
  437. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  438. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  439. inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
  440. inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
  441. //endregion
  442. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  443. inboundItem.setFlgValid(false);
  444. //修改
  445. inboundItemMapper.update(inboundItem,
  446. new UpdateWrapper<InboundItem>().lambda()
  447. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  448. );
  449. }
  450. //region 销售明细
  451. if (inboundItemVO.getFromItemId() != null) {
  452. //根据id查询
  453. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  454. PurchaseItem purchaseItem = new PurchaseItem();
  455. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  456. purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
  457. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
  458. purchaseItem.setIntoingQty(inboundItemVO.getIntoQty());
  459. purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt());
  460. //入库状态
  461. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  462. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  463. purchaseItem.setIntoStatus(intoStatus);
  464. int countRow = purchaseItemMapper.updateById(purchaseItem);
  465. //数量超出
  466. if (countRow == 0) {
  467. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  468. }
  469. }
  470. //endregion
  471. }
  472. }
  473. //endregion
  474. //region 修改入库总单
  475. Inbound inbound = new Inbound();
  476. inbound.setIntoId(inboundVO.getIntoId());
  477. inbound.setIntoQty(sumQty);
  478. inbound.setIntoAmt(sumAmt);
  479. //修改
  480. inboundMapper.update(inbound,
  481. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  482. );
  483. //endregion
  484. //region 修改销售总单
  485. if (inboundVO.getFromId() != null) {
  486. //根据id查询
  487. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  488. Purchase purchase = new Purchase();
  489. purchase.setPurId(inboundVO.getFromId());
  490. purchase.setIntoQty(inboundResponse.getIntoQty().negate().add(sumQty).subtract(delIntoQty));
  491. purchase.setIntoAmt(inboundResponse.getIntoAmt().negate().add(sumAmt).subtract(delIntoAmt));
  492. purchase.setIntoingQty(delIntoQty);
  493. purchase.setIntoingAmt(delIntoAmt);
  494. //入库状态
  495. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  496. purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
  497. purchase.setIntoStatus(intoStatus);
  498. //修改
  499. int countRow = purchaseMapper.updateById(purchase);
  500. //数量超出
  501. if (countRow == 0) {
  502. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  503. }
  504. //endregion
  505. }
  506. //endregion
  507. //region 入账
  508. if (inboundVO.getReceivableId() != null) {
  509. accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  510. }
  511. //endregion
  512. //region 调用库存
  513. Map<String, Object> map = new HashMap<>();
  514. map.put("intoDetail", inboundVO.getItemList());
  515. map.put("delIntoDetail", inboundVO.getDeleteItemList());
  516. inventoryService.operatingInventoryInformation(map);
  517. //endregion
  518. }
  519. else{
  520. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
  521. }
  522. //endregion
  523. //region 自动办理参数false 入库中编辑
  524. //自动办理标识为false 并且 自动办理参数为false 入库中
  525. if (!inboundVO.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(inboundVO.getFlgHandleSetting())) {
  526. //region 修改明细
  527. List<InboundItemVO> itemList = inboundVO.getItemList();
  528. for (InboundItemVO inboundItemVO : itemList) {
  529. //根据id查询 获取到还未进行修改的数据
  530. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  531. //region 编辑明细
  532. if (inboundItemVO.getItemId() != null) {
  533. InboundItem inboundItem = new InboundItem();
  534. inboundItem.setItemId(inboundItemVO.getItemId());
  535. inboundItem.setIntoingQty(inboundItemVO.getIntoingQty());
  536. inboundItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
  537. //修改
  538. inboundItemMapper.update(inboundItem,
  539. new UpdateWrapper<InboundItem>().lambda()
  540. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  541. );
  542. }
  543. //endregion
  544. //region 新建明细
  545. else {
  546. inboundItemVO
  547. .setIntoQty(BigDecimal.ZERO)
  548. .setIntoAmt(BigDecimal.ZERO)
  549. .setCostPrice(inboundItemVO.getPriceInto())
  550. .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  551. ;
  552. inboundItemVO.setIntoId(inboundVO.getIntoId());
  553. //入库状态
  554. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  555. inboundItemVO.setIntoType(Constant.IntoType.SALE.getName());
  556. //实体转换
  557. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  558. inboundItemMapper.insert(inboundItem);
  559. inboundItemVO.setItemId(inboundItem.getItemId());
  560. }
  561. //endregion
  562. //region 销售明细
  563. if (inboundItemVO.getFromItemId() != null) {
  564. //根据id查询
  565. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  566. PurchaseItem purchaseItem = new PurchaseItem();
  567. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  568. //本次修改几个传几个(负数) sql中是原数据+本次修改数据
  569. purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate().add(inboundItemVO.getIntoingQty()));
  570. purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate().add(inboundItemVO.getIntoingAmt()));
  571. //入库状态
  572. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  573. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  574. purchaseItem.setIntoStatus(intoStatus);
  575. int countRow = purchaseItemMapper.updateById(purchaseItem);
  576. //数量超出
  577. if (countRow == 0) {
  578. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  579. }
  580. }
  581. //endregion
  582. }
  583. //endregion
  584. //region 删除明细
  585. BigDecimal delIntoQty = BigDecimal.ZERO;
  586. BigDecimal delIntoAmt = BigDecimal.ZERO;
  587. if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
  588. delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  589. delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  590. for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
  591. //region 明细
  592. if (inboundItemVO.getItemId() != null) {
  593. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  594. inboundItem.setFlgValid(false);
  595. //修改
  596. inboundItemMapper.update(inboundItem,
  597. new UpdateWrapper<InboundItem>().lambda()
  598. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  599. );
  600. }
  601. //endregion
  602. //region 销售明细
  603. if (inboundItemVO.getFromItemId() != null) {
  604. //根据id查询
  605. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  606. PurchaseItem purchaseItem = new PurchaseItem();
  607. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  608. purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
  609. purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
  610. //入库状态
  611. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  612. purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
  613. purchaseItem.setIntoStatus(intoStatus);
  614. int countRow = purchaseItemMapper.updateById(purchaseItem);
  615. //数量超出
  616. if (countRow == 0) {
  617. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  618. }
  619. }
  620. //endregion
  621. }
  622. }
  623. //endregion
  624. //region 修改入库总单
  625. Inbound inbound = new Inbound();
  626. inbound.setIntoId(inboundVO.getIntoId());
  627. inbound.setIntoingQty(sumQty);
  628. inbound.setIntoingAmt(sumAmt);
  629. //修改
  630. inboundMapper.update(inbound,
  631. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  632. );
  633. //endregion
  634. //region 修改采购总单
  635. if (inboundVO.getFromId() != null) {
  636. //根据id查询
  637. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  638. Purchase purchase = new Purchase();
  639. purchase.setPurId(inboundVO.getFromId());
  640. purchase.setIntoingQty(inboundResponse.getIntoingQty().negate().add(sumQty).subtract(delIntoQty));
  641. purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate().add(sumAmt).subtract(delIntoAmt));
  642. //入库状态
  643. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  644. purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
  645. purchase.setIntoStatus(intoStatus);
  646. //修改
  647. int countRow = purchaseMapper.updateById(purchase);
  648. //数量超出
  649. if (countRow == 0) {
  650. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  651. }
  652. }
  653. //endregion
  654. }
  655. else{
  656. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
  657. }
  658. //endregion
  659. }
  660. //endregion
  661. return ResponseResultUtil.success(inboundVO);
  662. }
  663. /**
  664. * @desc : 采购入库作废
  665. * @date : 2024/3/26 9:24
  666. * @author : 寇珊珊
  667. */
  668. @Transactional(rollbackFor = {Exception.class})
  669. public ResponseResultVO<?> purchaseInboundRepeal(String intoId) {
  670. //region 查询总单 查询明细
  671. //根据id查询 此条入库单的数据还未更改前的数据
  672. InboundResponse inboundResponse = inboundMapper.selectById(intoId);
  673. //根据总单id查询
  674. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
  675. //endregion
  676. //region 已入库作废
  677. if (Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
  678. //region 退账
  679. if (inboundResponse.getReceivableId() != null) {
  680. accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  681. }
  682. //endregion
  683. //region 修改明细
  684. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  685. //region 将库存需要的参数赋值
  686. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  687. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  688. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  689. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  690. //endregion
  691. //region 编辑明细 赋值 赋值明细 防止作废的单据查不到明细 故注掉下面代码
  692. // InboundItem inboundItem = new InboundItem();
  693. // inboundItem.setItemId(inboundItemResponse.getItemId());
  694. // inboundItem.setFlgValid(false);
  695. // //修改
  696. // inboundItemMapper.update(inboundItem,
  697. // new UpdateWrapper<InboundItem>().lambda()
  698. // .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  699. // );
  700. //endregion
  701. //region 销售明细
  702. if (inboundItemResponse.getFromItemId() != null) {
  703. //根据id查询
  704. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
  705. PurchaseItem purchaseItem = new PurchaseItem();
  706. purchaseItem.setItemId(inboundItemResponse.getFromItemId());
  707. purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
  708. purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  709. //入库状态
  710. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
  711. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  712. purchaseItem.setIntoStatus(intoStatus);
  713. int countRow = purchaseItemMapper.updateById(purchaseItem);
  714. //数量超出
  715. if (countRow == 0) {
  716. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  717. }
  718. }
  719. //endregion
  720. }
  721. //endregion
  722. //region 修改入库总单
  723. Inbound inbound = new Inbound();
  724. inbound.setIntoId(inboundResponse.getIntoId());
  725. inbound.setFlgValid(false);
  726. //修改
  727. inboundMapper.update(inbound,
  728. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  729. );
  730. //endregion
  731. //region 修改销售总单
  732. if (inboundResponse.getFromId() != null) {
  733. //根据id查询
  734. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
  735. Purchase purchase = new Purchase();
  736. purchase.setPurId(inboundResponse.getFromId());
  737. purchase.setIntoQty(inboundResponse.getIntoQty().negate());
  738. purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
  739. //入库状态
  740. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty(),
  741. purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
  742. purchase.setIntoStatus(intoStatus);
  743. //修改
  744. int countRow = purchaseMapper.updateById(purchase);
  745. //数量超出
  746. if (countRow == 0) {
  747. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  748. }
  749. }
  750. //endregion
  751. //region 入账
  752. if (inboundResponse.getReceivableId() != null) {
  753. accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  754. }
  755. //endregion
  756. //region 调用库存
  757. Map<String, Object> map = new HashMap<>();
  758. map.put("delIntoDetail", inboundItemResponseList);
  759. inventoryService.operatingInventoryInformation(map);
  760. //endregion
  761. }
  762. //endregion
  763. //region 入库中、待入库作废
  764. if (Constant.IntoStatus.RUKUZHONG.getName().equals(inboundResponse.getIntoStatus()) ||
  765. Constant.IntoStatus.DAIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
  766. //region 修改明细
  767. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  768. //region 编辑明细 赋值
  769. InboundItem inboundItem = new InboundItem();
  770. inboundItem.setItemId(inboundItemResponse.getItemId());
  771. inboundItem.setIntoingQty(BigDecimal.ZERO);
  772. inboundItem.setIntoingAmt(BigDecimal.ZERO);
  773. // inboundItem.setFlgValid(false);
  774. //修改
  775. inboundItemMapper.update(inboundItem,
  776. new UpdateWrapper<InboundItem>().lambda()
  777. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  778. );
  779. //endregion
  780. //region 销售明细
  781. if (inboundItemResponse.getFromItemId() != null) {
  782. //根据id查询
  783. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
  784. PurchaseItem purchaseItem = new PurchaseItem();
  785. purchaseItem.setItemId(inboundItemResponse.getFromItemId());
  786. purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
  787. purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
  788. //入库状态
  789. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  790. purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
  791. purchaseItem.setIntoStatus(intoStatus);
  792. int countRow = purchaseItemMapper.updateById(purchaseItem);
  793. //数量超出
  794. if (countRow == 0) {
  795. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  796. }
  797. }
  798. //endregion
  799. }
  800. //endregion
  801. //region 修改入库总单
  802. Inbound inbound = new Inbound();
  803. inbound.setIntoId(inboundResponse.getIntoId());
  804. inbound.setIntoingQty(BigDecimal.ZERO);
  805. inbound.setIntoAmt(BigDecimal.ZERO);
  806. inbound.setFlgValid(false);
  807. //修改
  808. inboundMapper.update(inbound,
  809. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  810. );
  811. //endregion
  812. //region 修改销售总单
  813. if (inboundResponse.getFromId() != null) {
  814. //根据id查询
  815. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
  816. Purchase purchase = new Purchase();
  817. purchase.setPurId(inboundResponse.getFromId());
  818. purchase.setIntoingQty(inboundResponse.getIntoingQty().negate());
  819. purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate());
  820. //入库状态
  821. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  822. purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
  823. purchase.setIntoStatus(intoStatus);
  824. //修改
  825. int countRow = purchaseMapper.updateById(purchase);
  826. //数量超出
  827. if (countRow == 0) {
  828. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  829. }
  830. }
  831. //endregion
  832. }
  833. //endregion
  834. return ResponseResultUtil.success();
  835. }
  836. /**
  837. * @desc : 采购入库办理
  838. * @date : 2024/3/7 15:47
  839. * @author : 寇珊珊
  840. */
  841. @Transactional(rollbackFor = {Exception.class})
  842. public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
  843. //region 根据id查询 此条入库单的数据还未更改前的数据
  844. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  845. //endregion
  846. //region 退账
  847. if (inboundResponse.getReceivableId() != null) {
  848. accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  849. }
  850. //endregion
  851. //region 编辑明细
  852. //校验明细
  853. if (inboundVO.getItemList().size() == 0) {
  854. throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
  855. ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
  856. }
  857. for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
  858. //入库明细根据id查询
  859. InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
  860. //region 校验数量是否超出
  861. if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoingQty()) > 0) {
  862. throw new BaseBusinessException(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(),
  863. ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage());
  864. }
  865. //endregion
  866. //region 编辑明细
  867. if (inboundItemVO.getItemId() != null) {
  868. inboundItemVO
  869. .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
  870. .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
  871. .setIntoingQty(BigDecimal.ZERO)
  872. .setIntoingAmt(BigDecimal.ZERO)
  873. .setCostPrice(inboundItemVO.getPriceInto())
  874. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  875. ;
  876. //入库状态
  877. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  878. inboundItemVO.setIntoStatus(intoStatus);
  879. //实体转换
  880. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  881. //修改
  882. inboundItemMapper.update(inboundItem,
  883. new UpdateWrapper<InboundItem>().lambda()
  884. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  885. );
  886. //region 将库存需要的参数赋值
  887. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  888. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  889. //编辑之前的数
  890. if(inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO)>0) {
  891. inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
  892. inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
  893. }
  894. inboundItemVO.setAddOrEditFlag(true);
  895. //endregion
  896. }
  897. //endregion
  898. //region 新建明细
  899. else {
  900. inboundItemVO
  901. .setIntoQty(inboundItemVO.getIntoingQty())
  902. .setIntoAmt(inboundItemVO.getIntoingAmt())
  903. .setIntoId(inboundVO.getIntoId())
  904. .setCostPrice(inboundItemVO.getPriceInto())
  905. .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
  906. .setIntoType(Constant.IntoType.SALE.getName())
  907. .setIntoingQty(BigDecimal.ZERO)
  908. .setIntoingAmt(BigDecimal.ZERO)
  909. ;
  910. //入库状态
  911. String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
  912. inboundItemVO.setIntoStatus(intoStatus);
  913. //实体转换
  914. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  915. //新建
  916. inboundItemMapper.insert(inboundItem);
  917. inboundItemVO.setItemId(inboundItem.getItemId());
  918. //region 将库存需要的参数赋值
  919. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  920. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  921. inboundItemVO.setAddOrEditFlag(true);
  922. //endregion
  923. }
  924. //endregion
  925. //region 采购明细
  926. if(inboundItemVO.getFromItemId()!=null){
  927. //根据id查询
  928. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  929. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  930. PurchaseItem purchaseItem = new PurchaseItem();
  931. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  932. purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
  933. purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
  934. purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
  935. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
  936. //入库状态
  937. String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  938. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  939. purchaseItem.setIntoStatus(purItemIntoStatus);
  940. int countRow = purchaseItemMapper.updateById(purchaseItem);
  941. //数量超出
  942. if (countRow == 0) {
  943. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  944. }
  945. }
  946. //endregion
  947. }
  948. //endregion
  949. //region 删除明细
  950. BigDecimal delIntoingQty = BigDecimal.ZERO;
  951. BigDecimal delIntoingAmt = BigDecimal.ZERO;
  952. BigDecimal delIntoQty = BigDecimal.ZERO;
  953. BigDecimal delIntoAmt = BigDecimal.ZERO;
  954. if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) {
  955. delIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  956. delIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  957. delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  958. delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  959. for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
  960. if (inboundItemVO.getItemId() != null) {
  961. //region 将库存需要的参数赋值
  962. inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
  963. inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  964. //endregion
  965. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  966. inboundItem.setFlgValid(false);
  967. //修改
  968. inboundItemMapper.update(inboundItem,
  969. new UpdateWrapper<InboundItem>().lambda()
  970. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  971. );
  972. }
  973. //region 采购
  974. if (inboundItemVO.getFromItemId() != null) {
  975. //region 采购订单明细
  976. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  977. PurchaseItem purchaseItem = new PurchaseItem();
  978. purchaseItem.setItemId(inboundItemVO.getFromItemId());
  979. purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
  980. purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
  981. purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
  982. purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
  983. //根据id查询
  984. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
  985. //入库状态
  986. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  987. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  988. purchaseItem.setIntoStatus(intoStatus);
  989. int countRow = purchaseItemMapper.updateById(purchaseItem);
  990. //数量超出
  991. if (countRow == 0) {
  992. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  993. }
  994. //endregion
  995. }
  996. //endregion
  997. }
  998. }
  999. //endregion
  1000. //region 编辑总单
  1001. BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  1002. BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  1003. inboundVO.setIntoQty(sumIntoQty);
  1004. inboundVO.setIntoAmt(sumIntoAmt);
  1005. inboundVO.setIntoingQty(BigDecimal.ZERO);
  1006. inboundVO.setIntoingAmt(BigDecimal.ZERO);
  1007. //入库状态
  1008. String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
  1009. inboundVO.setIntoStatus(intoStatus);
  1010. //实体转换
  1011. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  1012. //修改
  1013. inboundMapper.update(inbound,
  1014. new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  1015. );
  1016. //endregion
  1017. //region 修改采购订单
  1018. if (inboundVO.getFromId() != null) {
  1019. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1020. Purchase purchase = new Purchase();
  1021. purchase.setPurId(inboundVO.getFromId());
  1022. purchase.setIntoQty(sumIntoQty.subtract(delIntoQty));
  1023. purchase.setIntoAmt(sumIntoAmt.subtract(delIntoAmt));
  1024. purchase.setIntoingQty((inboundResponse.getIntoingQty().add(delIntoingQty)).negate());
  1025. purchase.setIntoingAmt((inboundResponse.getIntoingAmt().add(delIntoingAmt)).negate());
  1026. //根据id查询
  1027. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  1028. //入库状态
  1029. String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  1030. purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
  1031. purchase.setIntoStatus(purIntoStatus);
  1032. //修改
  1033. int countRow = purchaseMapper.updateById(purchase);
  1034. //数量超出
  1035. if (countRow == 0) {
  1036. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  1037. }
  1038. }
  1039. //endregion
  1040. //region 入账
  1041. accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  1042. //endregion
  1043. //region 调用库存
  1044. Map<String, Object> map = new HashMap<>();
  1045. map.put("intoDetail", inboundVO.getItemList());
  1046. map.put("delIntoDetail", inboundVO.getDeleteItemList());
  1047. inventoryService.operatingInventoryInformation(map);
  1048. //endregion
  1049. return ResponseResultUtil.success(inboundVO);
  1050. }
  1051. /**
  1052. * @desc : 采购入库撤销
  1053. * @date : 2024/3/7 17:06
  1054. * @author : 寇珊珊
  1055. */
  1056. @Transactional(rollbackFor = {Exception.class})
  1057. public ResponseResultVO<?> purchaseInboundCancel(InboundVO inboundVO) {
  1058. //region 查询入库总单数据信息
  1059. InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
  1060. //endregion
  1061. //region 退账
  1062. if (inboundResponse.getReceivableId() != null) {
  1063. accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  1064. }
  1065. //endregion
  1066. //region 修改订单数据信息
  1067. if (inboundResponse.getFromId() != null) {
  1068. //根据id查询
  1069. PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
  1070. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1071. Purchase purchase = new Purchase();
  1072. purchase.setPurId(inboundResponse.getFromId());
  1073. purchase.setIntoQty(inboundResponse.getIntoQty().negate());
  1074. purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
  1075. purchase.setIntoingQty(inboundResponse.getIntoQty());
  1076. purchase.setIntoingAmt(inboundResponse.getIntoAmt());
  1077. //入库状态
  1078. String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
  1079. purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
  1080. purchase.setIntoStatus(intoStatus);
  1081. int countRow = purchaseMapper.updateById(purchase);
  1082. //数量超出
  1083. if (countRow == 0) {
  1084. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  1085. }
  1086. }
  1087. //endregion
  1088. //region 修改总单数据信息
  1089. Inbound inbound = new Inbound();
  1090. inbound.setIntoId(inboundVO.getIntoId());
  1091. inbound.setIntoDate(null);
  1092. inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
  1093. inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
  1094. inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
  1095. inbound.setIntoQty(BigDecimal.ZERO);
  1096. inbound.setIntoAmt(BigDecimal.ZERO);
  1097. //修改
  1098. inboundMapper.update(inbound,
  1099. new UpdateWrapper<Inbound>().lambda()
  1100. .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
  1101. );
  1102. //endregion
  1103. //region 明细数据
  1104. //根据总单id查明细
  1105. List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
  1106. for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
  1107. //region 修改采购明细数据信息
  1108. if (inboundItemResponse.getFromItemId() != null) {
  1109. //根据id查询
  1110. PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
  1111. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1112. PurchaseItem purchaseItem = new PurchaseItem();
  1113. purchaseItem.setItemId(inboundItemResponse.getFromItemId());
  1114. purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
  1115. purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  1116. purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
  1117. purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
  1118. //入库状态
  1119. String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
  1120. purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
  1121. purchaseItem.setIntoStatus(intoStatus);
  1122. //修改
  1123. int countRow = purchaseItemMapper.updateById(purchaseItem);
  1124. //数量超出
  1125. if (countRow == 0) {
  1126. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
  1127. }
  1128. }
  1129. //endregion
  1130. //region修改入库明细信息
  1131. InboundItem inboundItem = new InboundItem();
  1132. //region 将库存需要的参数赋值
  1133. inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
  1134. inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
  1135. inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
  1136. inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
  1137. //endregion
  1138. inboundItem
  1139. .setIntoId(inbound.getIntoId())
  1140. .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
  1141. .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
  1142. .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
  1143. .setIntoQty(BigDecimal.ZERO)
  1144. .setIntoAmt(BigDecimal.ZERO)
  1145. .setCostPrice(BigDecimal.ZERO)
  1146. .setCostAmt(BigDecimal.ZERO)
  1147. .setItemId(inboundItemResponse.getItemId());
  1148. //入库状态
  1149. String intoStatus = this.setIntoStatus(inboundItem.getIntoingQty(), inboundItem.getIntoQty());
  1150. inboundItem.setIntoStatus(intoStatus);
  1151. //修改
  1152. inboundItemMapper.update(inboundItem,
  1153. new UpdateWrapper<InboundItem>().lambda()
  1154. .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
  1155. );
  1156. //endregion
  1157. }
  1158. //endregion
  1159. //region 调用库存
  1160. Map<String, Object> map = new HashMap<>();
  1161. map.put("delIntoDetail", inboundItemResponseList);
  1162. inventoryService.operatingInventoryInformation(map);
  1163. //endregion
  1164. return ResponseResultUtil.success();
  1165. }
  1166. /**
  1167. * @desc : 入库状态通用(目前本页面)
  1168. * @date : 2024/3/9 8:59
  1169. * @author : 寇珊珊
  1170. */
  1171. @Transactional(rollbackFor = {Exception.class})
  1172. public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
  1173. //入库状态
  1174. String intoStatus = null;
  1175. //已入库数量>0 入库中数量>0
  1176. if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
  1177. //入库中
  1178. intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
  1179. }
  1180. //已入库数量=0 入库中数量=0
  1181. else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  1182. //待入库
  1183. intoStatus = Constant.IntoStatus.DAIRUKU.getName();
  1184. }
  1185. //已入库数量>0 入库中数量=0
  1186. else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  1187. //已入库
  1188. intoStatus = Constant.IntoStatus.YIRUKU.getName();
  1189. }
  1190. return intoStatus;
  1191. }
  1192. /**
  1193. * @desc : 上游单据入库状态通用(目前本页面)
  1194. * @date : 2024/4/1 17:14
  1195. * @author : 寇珊珊
  1196. */
  1197. @Transactional(rollbackFor = {Exception.class})
  1198. public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty, BigDecimal sumQty) {
  1199. //入库状态
  1200. String intoStatus = null;
  1201. //入库中+已入库 小于 总数 并且 入库中数量 等于订单总数量
  1202. if (intoingQty.compareTo(sumQty) <= 0 && intoingQty.add(intoQty).compareTo(sumQty) <= 0) {
  1203. //入库中
  1204. intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
  1205. }
  1206. //已入库数量=0 入库中数量=0
  1207. else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  1208. //待入库
  1209. intoStatus = Constant.IntoStatus.DAIRUKU.getName();
  1210. }
  1211. //入库中+已入库 等于 总数 并且 入库中数量 小于等于订单总数量
  1212. else if (intoingQty.compareTo(sumQty) < 0 && intoingQty.add(intoQty).compareTo(sumQty) == 0) {
  1213. //已入库
  1214. intoStatus = Constant.IntoStatus.YIRUKU.getName();
  1215. }
  1216. return intoStatus;
  1217. }
  1218. }