OutboundSaleOrderService.java 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. package com.dk.mdm.service.ivt.outbound;
  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.infrastructure.convert.ivt.OutboundConvert;
  16. import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
  17. import com.dk.mdm.mapper.common.CommonMapper;
  18. import com.dk.mdm.mapper.ivt.*;
  19. import com.dk.mdm.mapper.mst.CustomerMapper;
  20. import com.dk.mdm.mapper.sale.MultiOwnerMapper;
  21. import com.dk.mdm.mapper.sale.OrderItemMapper;
  22. import com.dk.mdm.mapper.sale.OrderMapper;
  23. import com.dk.mdm.model.pojo.ivt.Inbound;
  24. import com.dk.mdm.model.pojo.ivt.InboundItem;
  25. import com.dk.mdm.model.pojo.ivt.Outbound;
  26. import com.dk.mdm.model.pojo.ivt.OutboundItem;
  27. import com.dk.mdm.model.pojo.mst.Customer;
  28. import com.dk.mdm.model.pojo.pur.Purchase;
  29. import com.dk.mdm.model.pojo.pur.PurchaseItem;
  30. import com.dk.mdm.model.pojo.sale.MultiOwner;
  31. import com.dk.mdm.model.pojo.sale.Order;
  32. import com.dk.mdm.model.pojo.sale.OrderItem;
  33. import com.dk.mdm.model.query.ivt.InventoryQuery;
  34. import com.dk.mdm.model.query.ivt.OutboundItemQuery;
  35. import com.dk.mdm.model.query.ivt.OutboundQuery;
  36. import com.dk.mdm.model.query.sale.OrderQuery;
  37. import com.dk.mdm.model.response.ivt.InboundResponse;
  38. import com.dk.mdm.model.response.ivt.InventoryResponse;
  39. import com.dk.mdm.model.response.ivt.OutboundItemResponse;
  40. import com.dk.mdm.model.response.ivt.OutboundResponse;
  41. import com.dk.mdm.model.response.pur.PurchaseItemResponse;
  42. import com.dk.mdm.model.response.pur.PurchaseResponse;
  43. import com.dk.mdm.model.response.sale.OrderItemResponse;
  44. import com.dk.mdm.model.response.sale.OrderResponse;
  45. import com.dk.mdm.model.vo.ivt.*;
  46. import com.dk.mdm.model.vo.mac.RecPayVO;
  47. import com.dk.mdm.service.common.CommonService;
  48. import com.dk.mdm.service.ivt.inventory.InventoryService;
  49. import com.dk.mdm.service.mac.AccountService;
  50. import com.dk.mdm.service.mac.ReceiptService;
  51. import org.springframework.beans.factory.annotation.Autowired;
  52. import org.springframework.stereotype.Service;
  53. import org.springframework.transaction.annotation.Transactional;
  54. import java.math.BigDecimal;
  55. import java.time.LocalDate;
  56. import java.util.HashMap;
  57. import java.util.List;
  58. import java.util.Map;
  59. import java.util.UUID;
  60. import java.util.stream.Collectors;
  61. /**
  62. * @author : 寇珊珊
  63. * @desc : 销售出库业务层
  64. * @date : 2024/3/18 15:33
  65. */
  66. @Service
  67. public class OutboundSaleOrderService extends BaseService<Outbound> {
  68. @Override
  69. public BaseMapper<Outbound> getRepository() {
  70. return outboundMapper;
  71. }
  72. @Autowired
  73. private CommonService commonService;
  74. @Autowired
  75. private OutboundMapper outboundMapper;
  76. @Autowired
  77. private OutboundConvert outboundConvert;
  78. @Autowired
  79. private OutboundItemMapper outboundItemMapper;
  80. @Autowired
  81. private OutboundItemConvert outboundItemConvert;
  82. @Autowired
  83. private OrderMapper orderMapper;
  84. @Autowired
  85. private OrderItemMapper orderItemMapper;
  86. @Autowired
  87. private CommonMapper commonMapper;
  88. @Autowired
  89. private InventoryService inventoryService;
  90. @Autowired
  91. private AccountService accountService;
  92. @Autowired
  93. private OutCommon outCommon;
  94. @Autowired
  95. private InboundMapper inboundMapper;
  96. @Autowired
  97. private InboundConvert inboundConvert;
  98. @Autowired
  99. private InboundItemMapper inboundItemMapper;
  100. @Autowired
  101. private InboundItemConvert inboundItemConvert;
  102. @Autowired
  103. private ReceiptService receiptService;
  104. @Autowired
  105. private InventoryMapper inventoryMapper;
  106. /*****************************************先判断库存*****************************************/
  107. /**
  108. * @desc : 校验库存是否存在
  109. * @date : 2024/6/11 10:55
  110. * @author : 寇珊珊
  111. */
  112. @Transactional(
  113. rollbackFor = {Exception.class}
  114. )
  115. public InventoryResponse checkInventoryExist(OutboundItemVO outboundItemVO) {
  116. //存在标识
  117. //根据sku,仓库,非标号查询
  118. InventoryResponse inventoryResponse = null;
  119. if (outboundItemVO.getSkuId() != null) {
  120. inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
  121. .setSkuId(outboundItemVO.getSkuId())
  122. .setWhId(outboundItemVO.getWhId())
  123. .setNonStdCode(outboundItemVO.getNonStdCode()));
  124. }
  125. return inventoryResponse;
  126. }
  127. /**
  128. * @desc : 先查库存后出库
  129. * @date : 2024/6/11 9:30
  130. * @author : 寇珊珊
  131. */
  132. @Transactional(rollbackFor = {Exception.class})
  133. public void inventoryOUtBond(OutboundVO outboundVO) {
  134. //region 校验明细
  135. if (outboundVO.getItemList().size() == 0) {
  136. throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
  137. ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
  138. }
  139. //endregion
  140. //可以负库存 不用交验库存直接走负库存逻辑
  141. if (outboundVO.getFlgHandleSetting()) {
  142. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  143. //可以输入负数出库标识
  144. outboundItemVO.setCanNegativeFlag(true);
  145. //业务部门Id
  146. outboundItemVO.setOrgId(outboundVO.getOrgId());
  147. //业务员Id
  148. outboundItemVO.setStaffId(outboundVO.getStaffId());
  149. //制单员Id
  150. outboundItemVO.setMakeStaff(outboundVO.getMakeStaff());
  151. }
  152. //销售出库新建
  153. this.saleOrderOutboundInsert(outboundVO,true);
  154. }
  155. //先查库存锁表看能出库的数量有多少 可出库数量建一张已出库的单子并扣减库存,剩下的数量建一张出库中的单子
  156. else {
  157. //过滤外协品
  158. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  159. //商品id不为空才校验库存 因为为空是外协品
  160. if(outboundItemVO.getSkuId()!=null){
  161. //查询库存是否存在
  162. InventoryResponse inventoryResponse = this.checkInventoryExist(outboundItemVO);
  163. if (inventoryResponse != null) {
  164. BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
  165. // (库存量 大于等于 本次出库数量不用做任何处理)
  166. //库存量 小于 本次出库数量
  167. if (invQty.compareTo(BigDecimal.ZERO) < 0) {
  168. outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
  169. //不够库存数量----新建出库中数量
  170. outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
  171. }
  172. } else {
  173. //不够库存数量----新建出库中数量
  174. outboundItemVO.setNotEnoughInventoryQty(outboundItemVO.getOutingQty());
  175. }
  176. }
  177. }
  178. //过滤出库存量足够的数据
  179. List<OutboundItemVO> itemList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()==null ).collect(Collectors.toList());
  180. //region 过滤出不够出库的每条明细数量 ------新建出库中数据
  181. List<OutboundItemVO> outboundIngList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()!=null && it.getNotEnoughInventoryQty().compareTo(BigDecimal.ZERO)>0).collect(Collectors.toList());
  182. if(outboundIngList != null && outboundIngList.size()>0){
  183. outboundVO.setFlgAutoHandle(false);
  184. outboundVO.setItemList(outboundIngList);
  185. //销售出库新建
  186. this.saleOrderOutboundInsert(outboundVO,true);
  187. }
  188. //endregion
  189. //region 库存够扣减的明细 -----------新建已出库数据并扣减库存
  190. //销售出库新建
  191. outboundVO.setFlgAutoHandle(true);
  192. outboundVO.setItemList(itemList);
  193. this.saleOrderOutboundInsert(outboundVO,true);
  194. //endregion
  195. }
  196. }
  197. /*****************************************先判断库存*****************************************/
  198. /**
  199. * @desc : 删除外协品生产外协入库单
  200. * @date : 2024/5/10 10:31
  201. * @author : 寇珊珊
  202. */
  203. @Transactional(rollbackFor = {Exception.class})
  204. public void deleteOutsideGoodsInto(OutboundVO outboundVO, List<OutboundItemVO> outboundItemVOList) {
  205. if (outboundItemVOList != null && outboundItemVOList.size() > 0) {
  206. //根据出库单id分组
  207. Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getOutId));
  208. for (String str : outboundItemVOMap.keySet()) {
  209. InboundResponse inboundResponse = inboundMapper.selectByFromId(str);
  210. // 退账
  211. if (inboundResponse != null && inboundResponse.getReceivableId() != null) {
  212. accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  213. }
  214. }
  215. //删除外协入库单
  216. //外协入库总单
  217. inboundMapper.deleteByFromId(outboundItemVOList.get(0).getOutId());
  218. //外协入库明细
  219. inboundItemMapper.deleteItemByFromId(outboundItemVOList.get(0).getOutId());
  220. }
  221. }
  222. /**
  223. * @desc : 新建外协品生产外协入库单
  224. * @date : 2024/5/10 10:31
  225. * @author : 寇珊珊
  226. */
  227. @Transactional(rollbackFor = {Exception.class})
  228. public void insertOutsideGoodsInto(OutboundVO outboundVO, List<OutboundItemVO> outboundItemVOList) {
  229. if (outboundItemVOList != null && outboundItemVOList.size() > 0) {
  230. Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getOutId));
  231. for (String str : outboundItemVOMap.keySet()) {
  232. //提取分组后的明细
  233. List<OutboundItemVO> outboundItemVOListGroup = outboundItemVOMap.get(str);
  234. //region 新建总单
  235. //已入库金额
  236. BigDecimal sumIntoAmt = outboundItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  237. //已入库数量
  238. BigDecimal sumIntoQty = outboundItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  239. //总单实体
  240. InboundVO inboundVO = new InboundVO();
  241. //获取 id/单号
  242. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OUTSOURCED.getName(), false);
  243. inboundVO.setIntoId(codeMap.get("outId").toString()).
  244. setIntoNo(codeMap.get("outNote").toString());
  245. //入库类型
  246. inboundVO.setIntoType(Constant.IntoType.OUTSOURCED.getName());
  247. //已入库
  248. inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
  249. //供应商
  250. inboundVO.setSupId(outboundItemVOListGroup.get(0).getSupId());
  251. //入库状态等于已入库
  252. inboundVO.setIntoQty(sumIntoQty)
  253. .setIntoAmt(sumIntoAmt)
  254. .setIntoingQty(BigDecimal.ZERO)
  255. .setIntoingAmt(BigDecimal.ZERO);
  256. //来源id
  257. inboundVO.setFromId(outboundItemVOListGroup.get(0).getFromId());
  258. //来源单号
  259. inboundVO.setFromNo(outboundVO.getOutNo());
  260. //部门
  261. inboundVO.setOrgId(outboundVO.getOrgId());
  262. //员工
  263. inboundVO.setStaffId(outboundVO.getStaffId());
  264. //入库日期
  265. inboundVO.setIntoDate(LocalDate.now());
  266. //制单人
  267. inboundVO.setMakeStaff(outboundVO.getMakeStaff());
  268. //公司
  269. inboundVO.setCpId(outboundVO.getCpId());
  270. // 来源Id
  271. inboundVO.setFromId(outboundVO.getFromId());
  272. inboundVO.setFromNo(outboundVO.getFromNo());
  273. //实体转换
  274. Inbound inbound = inboundConvert.convertToPo(inboundVO);
  275. inboundMapper.insert(inbound);
  276. //endregion
  277. //region 明细
  278. Integer count = 0;
  279. for (OutboundItemVO outboundItemVO : outboundItemVOListGroup) {
  280. InboundItemVO inboundItemVO = new InboundItemVO();
  281. //总单id
  282. inboundItemVO.setIntoId(inboundVO.getIntoId());
  283. //入库类型
  284. inboundItemVO.setIntoType(inboundVO.getIntoType());
  285. //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
  286. BigDecimal costAmount = outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP);
  287. inboundItemVO
  288. .setFromId(outboundItemVO.getFromId())
  289. .setFromItemId(outboundItemVO.getFromItemId())
  290. .setPriceInto(outboundItemVO.getPriceOut())
  291. .setIntoQty(outboundItemVO.getOutQty())
  292. .setIntoAmt(outboundItemVO.getOutAmt())
  293. .setIntoAmt(costAmount)
  294. .setIntoingQty(BigDecimal.ZERO)
  295. .setIntoingAmt(BigDecimal.ZERO)
  296. .setCostPrice(outboundItemVO.getPriceOut())
  297. .setCostAmt(costAmount)
  298. ;
  299. //入库状态
  300. inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
  301. //商品顺序
  302. inboundItemVO.setItemIndex(count);
  303. //箱(入库中)
  304. inboundItemVO.setIntoingBox(outboundItemVO.getOutingBox());
  305. //片(入库中)
  306. inboundItemVO.setIntoingPiece(outboundItemVO.getOutingPiece());
  307. //箱(已入库)
  308. inboundItemVO.setIntoBox(outboundItemVO.getOutBox());
  309. //片(已入库)
  310. inboundItemVO.setIntoPiece(outboundItemVO.getOutPiece());
  311. //入库仓库
  312. inboundItemVO.setWhId(outboundItemVO.getWhId());
  313. //企业ID
  314. inboundItemVO.setCpId(outboundItemVO.getCpId());
  315. // 商品
  316. inboundItemVO.setSkuModel(outboundItemVO.getSkuModel());
  317. inboundItemVO.setSkuName(outboundItemVO.getSkuName());
  318. // 来源Id
  319. //实体转换
  320. InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
  321. inboundItemMapper.insert(inboundItem);
  322. //用来填写商品顺序
  323. count++;
  324. inboundItemVO.setItemId(inboundItem.getItemId());
  325. }
  326. //endregion
  327. //region 入账
  328. accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
  329. //endregion
  330. }
  331. }
  332. }
  333. /**
  334. * @desc : 销售出库新建
  335. * orderTransmitFlag :订单传递过来的
  336. * @date : 2024/3/7 14:13
  337. * @author : 寇珊珊
  338. */
  339. @Transactional(rollbackFor = {Exception.class})
  340. public ResponseResultVO<?> saleOrderOutboundInsert(OutboundVO outboundVO,Boolean orderTransmitFlag) {
  341. //region 如果没有客户id,要新建
  342. // outboundVO = outCommon.insertCustomer(outboundVO);
  343. //endregion
  344. //region 查询当前公司的系统参数 自动办理信息 并赋值
  345. if(!orderTransmitFlag){
  346. Map<String, Object> map = new HashMap<>();
  347. map.put("cpId", outboundVO.getCpId());
  348. map.put("code", Constant.SystemConstant.IVT_001.getValue());
  349. //自动办理标识
  350. String flgHandleSetting = commonMapper.getSettingValue(map);
  351. //自动办理标识为1 自动办理入库
  352. if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
  353. outboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
  354. outboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
  355. }
  356. }
  357. //endregion
  358. //region 总单
  359. //出库数量
  360. BigDecimal sumIntoQty = BigDecimal.ZERO;
  361. //出库金额
  362. BigDecimal sumIntoPriceAmt = BigDecimal.ZERO;
  363. if(orderTransmitFlag){
  364. sumIntoQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  365. sumIntoPriceAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getPriceOut).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  366. }
  367. //获取 id/单号
  368. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
  369. outboundVO.setOutId(codeMap.get("outId").toString()).
  370. setOutNo(codeMap.get("outNote").toString());
  371. //出库类型
  372. outboundVO.setOutType(Constant.OutType.SALE.getName()).setOutDate(LocalDate.now());
  373. //自动入库标识
  374. if (outboundVO.getFlgAutoHandle()) {
  375. //已出库
  376. outboundVO.setOutStatus(Constant.OutStatus.YICHUKU.getName());
  377. } else {
  378. //出库中
  379. outboundVO.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
  380. }
  381. //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
  382. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  383. outboundVO
  384. .setOutQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
  385. .setOutAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
  386. .setOutingQty(BigDecimal.ZERO)
  387. .setOutingAmt(BigDecimal.ZERO)
  388. ;
  389. } else {
  390. outboundVO
  391. .setOutQty(BigDecimal.ZERO)
  392. .setOutAmt(BigDecimal.ZERO)
  393. //用于销售订单自动创建出库单
  394. .setOutingQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
  395. .setOutingAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
  396. ;
  397. }
  398. //实体转换
  399. Outbound outbound = outboundConvert.convertToPo(outboundVO);
  400. outboundMapper.insert(outbound);
  401. //endregion
  402. //region 新建多业务归属
  403. // outCommon.insertMultiOwner(outboundVO);
  404. //endregion
  405. //region 销售订单
  406. if (outboundVO.getFromId() != null) {
  407. //赋值 (这里重写了更新方法,数量在更新方法中有数据库原始数量+本次数量)
  408. Order order = new Order();
  409. order.setOrderId(outboundVO.getFromId());
  410. //根据id查询
  411. OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
  412. //已出库
  413. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  414. order.setOutingQty(BigDecimal.ZERO);
  415. order.setOutingAmt(BigDecimal.ZERO);
  416. order.setOutQty(outboundVO.getOutQty());
  417. order.setOutAmt(outboundVO.getOutAmt());
  418. }
  419. //出库中
  420. else {
  421. order.setOutingQty(outboundVO.getOutingQty());
  422. order.setOutingAmt(outboundVO.getOutingAmt());
  423. order.setOutQty(BigDecimal.ZERO);
  424. order.setOutAmt(BigDecimal.ZERO);
  425. }
  426. //入库状态
  427. String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
  428. orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
  429. order.setOutStatus(outStatus);
  430. //修改
  431. int countRow = orderMapper.updateById(order);
  432. //数量超出
  433. if (countRow == 0) {
  434. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  435. }
  436. }
  437. //endregion
  438. //region 明细
  439. //校验明细
  440. if (outboundVO.getItemList().size() == 0) {
  441. throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
  442. ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
  443. }
  444. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  445. outboundItemVO.setItemId(null );
  446. //region 将库存需要的参数赋值
  447. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  448. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  449. outboundItemVO.setAddOrEditFlag(true);
  450. //endregion
  451. //总单id
  452. outboundItemVO.setOutId(outboundVO.getOutId());
  453. //出库类型
  454. outboundItemVO.setOutType(outboundVO.getOutType());
  455. //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
  456. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  457. outboundItemVO
  458. .setOutQty(outboundItemVO.getOutingQty())
  459. .setOutAmt(outboundItemVO.getOutingAmt())
  460. .setOutingQty(BigDecimal.ZERO)
  461. .setOutingAmt(BigDecimal.ZERO)
  462. .setCostPrice(outboundItemVO.getPriceOut())
  463. .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  464. ;
  465. } else {
  466. outboundItemVO
  467. .setOutQty(BigDecimal.ZERO)
  468. .setOutAmt(BigDecimal.ZERO);
  469. }
  470. //出库状态
  471. outboundItemVO.setOutStatus(outboundVO.getOutStatus());
  472. //实体转换
  473. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  474. outboundItemMapper.insert(outboundItem);
  475. //明细id
  476. outboundItemVO.setItemId(outboundItem.getItemId());
  477. //endregion
  478. //region 销售明细
  479. if (outboundItemVO.getFromItemId() != null) {
  480. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  481. OrderItem orderItem = new OrderItem();
  482. orderItem.setItemId(outboundItemVO.getFromItemId());
  483. //根据id查询
  484. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  485. //已出库
  486. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  487. orderItem.setOutingQty(BigDecimal.ZERO);
  488. orderItem.setOutingAmt(BigDecimal.ZERO);
  489. orderItem.setOutQty(outboundItemVO.getOutQty());
  490. orderItem.setOutAmt(outboundItemVO.getOutAmt());
  491. }
  492. //出库中
  493. else {
  494. orderItem.setOutingQty(outboundItemVO.getOutingQty());
  495. orderItem.setOutingAmt(outboundItemVO.getOutingAmt());
  496. orderItem.setOutQty(BigDecimal.ZERO);
  497. orderItem.setOutAmt(BigDecimal.ZERO);
  498. }
  499. //出库状态
  500. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  501. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  502. orderItem.setOutStatus(outStatus);
  503. //修改
  504. int countRow = orderItemMapper.updateById(orderItem);
  505. //数量超出
  506. if (countRow == 0) {
  507. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  508. }
  509. }
  510. //endregion
  511. }
  512. //endregion
  513. //region 已出库 应收记账
  514. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  515. accountService.accReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  516. }
  517. //endregion
  518. //region 外协品+库存
  519. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  520. //region 外协品新建外协入库单
  521. //筛选出skuId为空的 走外协品逻辑
  522. List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  523. for(int i=0;i<outsideGoods.size();i++){
  524. outsideGoods.get(i).setPriceOut( outsideGoods.get(i).getCostPrice()==null?BigDecimal.ZERO:outsideGoods.get(i).getCostPrice());
  525. }
  526. //删除外协品生产外协入库单
  527. this.deleteOutsideGoodsInto(outboundVO, outsideGoods);
  528. //新建外协品生产外协入库单
  529. this.insertOutsideGoodsInto(outboundVO, outsideGoods);
  530. //endregion
  531. //region 库存
  532. //筛选出skuId不为空的 走库存
  533. List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  534. if(invList!=null && invList.size() > 0){
  535. Map<String, Object> invMap = new HashMap<>();
  536. invMap.put("outDetail", invList);
  537. inventoryService.operatingInventoryInformation(invMap);
  538. }
  539. //endregion
  540. }
  541. //endregion
  542. return ResponseResultUtil.success(outboundVO);
  543. }
  544. /**
  545. * @desc : 销售出库编辑
  546. * @date : 2024/3/25 16:25
  547. * @author : 寇珊珊
  548. */
  549. @Transactional(rollbackFor = {Exception.class})
  550. public ResponseResultVO<?> saleOutboundUpdate(OutboundVO outboundVO) {
  551. //region 小编辑
  552. if (!outboundVO.getLimitEdit()) {
  553. Outbound outbound = new Outbound();
  554. outbound.setOutId(outboundVO.getOutId());
  555. outbound.setRemarks(outboundVO.getRemarks());
  556. outbound.setAnnexPaths(outboundVO.getAnnexPaths());
  557. outboundMapper.update(outbound,
  558. new UpdateWrapper<Outbound>().lambda()
  559. .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  560. );
  561. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  562. OutboundItem outboundItem = new OutboundItem();
  563. outboundItem.setItemId(outboundItemVO.getItemId());
  564. if (outboundItemVO.getRemarks() != null || outboundItemVO.getRemarks() != " ") {
  565. outboundItem.setRemarks(outboundItemVO.getRemarks());
  566. outboundItemMapper.update(outboundItem,
  567. new UpdateWrapper<OutboundItem>().lambda()
  568. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  569. );
  570. }
  571. }
  572. }
  573. //endregion
  574. //region 大编辑
  575. else {
  576. // region 更新客户信息
  577. outboundVO = outCommon.insertCustomer(outboundVO);
  578. // endregion
  579. //region 根据id查询 并且明细数量金额 求和
  580. OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
  581. BigDecimal sumQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  582. BigDecimal sumAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  583. //endregion
  584. //region 已入库编辑
  585. if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
  586. //region 应收反记账
  587. if (outboundVO.getReceivableId() != null) {
  588. accountService.reverseReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  589. }
  590. //endregion
  591. //region 修改明细
  592. List<OutboundItemVO> itemList = outboundVO.getItemList();
  593. for (OutboundItemVO outboundItemVO : itemList) {
  594. //根据id查询
  595. OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
  596. //region 编辑明细
  597. if (outboundItemVO.getItemId() != null) {
  598. //region 将库存需要的参数赋值
  599. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  600. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  601. //编辑之前的数
  602. outboundItemVO.setQtyBeforeUpdate(outboundItemResponse.getOutQty());
  603. outboundItemVO.setAmtBeforeUpdate(outboundItemResponse.getOutAmt());
  604. //编辑之后的数
  605. outboundItemVO.setOutQty(outboundItemVO.getOutingQty());
  606. outboundItemVO.setOutAmt(outboundItemVO.getOutingAmt());
  607. outboundItemVO.setAddOrEditFlag(false);
  608. //endregion
  609. OutboundItem outboundItem = new OutboundItem();
  610. outboundItem.setItemId(outboundItemVO.getItemId());
  611. outboundItem.setOutQty(outboundItemVO.getOutingQty());
  612. outboundItem.setOutAmt(outboundItemVO.getOutingAmt());
  613. outboundItem.setCostPrice(outboundItemVO.getPriceOut());
  614. outboundItem.setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(6, BigDecimal.ROUND_HALF_UP));
  615. //修改
  616. outboundItemMapper.update(outboundItem,
  617. new UpdateWrapper<OutboundItem>().lambda()
  618. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  619. );
  620. }
  621. //endregion
  622. //region 新建明细
  623. else {
  624. outboundItemVO
  625. .setOutId(outboundItemVO.getOutId())
  626. .setOutQty(outboundItemVO.getOutingQty())
  627. .setOutAmt(outboundItemVO.getOutingAmt())
  628. .setOutingQty(BigDecimal.ZERO)
  629. .setOutingAmt(BigDecimal.ZERO)
  630. .setCostPrice(outboundItemVO.getPriceOut())
  631. .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  632. .setOutType(Constant.OutType.SALE.getName())
  633. ;
  634. //出库状态
  635. String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
  636. outboundItemVO.setOutStatus(outStatus);
  637. //实体转换
  638. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  639. //新建
  640. outboundItemMapper.insert(outboundItem);
  641. outboundItemVO.setItemId(outboundItem.getItemId());
  642. //region 将库存需要的参数赋值
  643. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  644. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  645. outboundItemVO.setAddOrEditFlag(true);
  646. //endregion
  647. }
  648. //endregion
  649. //region 销售明细
  650. if (outboundItemVO.getFromItemId() != null) {
  651. //根据id查询
  652. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  653. OrderItem orderItem = new OrderItem();
  654. orderItem.setItemId(outboundItemVO.getFromItemId());
  655. orderItem.setOutQty(outboundItemResponse.getOutQty().negate().add(outboundItemVO.getOutingQty()));
  656. orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate().add(outboundItemVO.getOutingAmt()));
  657. orderItem.setOutingQty(outboundItemVO.getOutQty());
  658. orderItem.setOutingAmt(outboundItemVO.getOutAmt());
  659. //出库状态
  660. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  661. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  662. orderItem.setOutStatus(outStatus);
  663. int countRow = orderItemMapper.updateById(orderItem);
  664. //数量超出
  665. if (countRow == 0) {
  666. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  667. }
  668. }
  669. //endregion
  670. }
  671. //endregion
  672. //region 删除明细
  673. BigDecimal delOutQty = BigDecimal.ZERO;
  674. BigDecimal delOutAmt = BigDecimal.ZERO;
  675. if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
  676. delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  677. delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  678. for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
  679. if (outboundItemVO.getItemId() != null) {
  680. //region 将库存需要的参数赋值
  681. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  682. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  683. //endregion
  684. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  685. outboundItem.setFlgValid(false);
  686. //修改
  687. outboundItemMapper.update(outboundItem,
  688. new UpdateWrapper<OutboundItem>().lambda()
  689. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  690. );
  691. }
  692. //region 销售明细
  693. if (outboundItemVO.getFromItemId() != null) {
  694. //根据id查询
  695. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  696. OrderItem orderItem = new OrderItem();
  697. orderItem.setItemId(outboundItemVO.getFromItemId());
  698. orderItem.setOutQty(outboundItemVO.getOutQty().negate());
  699. orderItem.setOutAmt(outboundItemVO.getOutAmt().negate());
  700. orderItem.setOutingQty(outboundItemVO.getOutQty());
  701. orderItem.setOutingAmt(outboundItemVO.getOutQty());
  702. //出库状态
  703. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  704. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  705. orderItem.setOutStatus(outStatus);
  706. int countRow = orderItemMapper.updateById(orderItem);
  707. //数量超出
  708. if (countRow == 0) {
  709. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  710. }
  711. }
  712. //endregion
  713. }
  714. }
  715. //endregion
  716. //region 修改出库总单
  717. Outbound outbound = new Outbound();
  718. outbound.setOutId(outboundVO.getOutId());
  719. outbound.setOutQty(sumQty);
  720. outbound.setOutAmt(sumAmt);
  721. //修改
  722. outboundMapper.update(outbound,
  723. new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  724. );
  725. //endregion
  726. //region 修改销售总单
  727. if (outboundVO.getFromId() != null) {
  728. //根据id查询
  729. OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
  730. Order order = new Order();
  731. order.setOrderId(outboundVO.getFromId());
  732. order.setOutQty(outboundResponse.getOutQty().negate().add(sumQty).subtract(delOutQty));
  733. order.setOutAmt(outboundResponse.getOutAmt().negate().add(sumAmt).subtract(delOutAmt));
  734. order.setOutingQty(delOutQty);
  735. order.setOutingAmt(delOutAmt);
  736. //出库状态
  737. String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
  738. orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
  739. order.setOutStatus(outStatus);
  740. //修改
  741. int countRow = orderMapper.updateById(order);
  742. //数量超出
  743. if (countRow == 0) {
  744. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  745. }
  746. }
  747. //endregion
  748. //region 应收记账
  749. if (outboundVO.getReceivableId() != null) {
  750. accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  751. }
  752. //endregion
  753. //region 外协品新建外协入库单
  754. //筛选出skuId为空的 走外协品逻辑
  755. List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  756. //删除外协品生产外协入库单
  757. this.deleteOutsideGoodsInto(outboundVO, outsideGoods);
  758. //新建外协品生产外协入库单
  759. this.insertOutsideGoodsInto(outboundVO, outsideGoods);
  760. if(outboundVO.getDeleteItemList() != null){
  761. List<OutboundItemVO> delOutsideGoods = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  762. //删除外协品生产外协入库单
  763. this.deleteOutsideGoodsInto(outboundVO, delOutsideGoods);
  764. }
  765. //endregion
  766. //region 修改库存
  767. //筛选出skuId不为空的 走库存
  768. List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  769. List<OutboundItemVO> invDelList = null;
  770. if(outboundVO.getDeleteItemList() != null){
  771. invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  772. }
  773. if ((invList != null && invList.size() > 0) || (invDelList != null && invDelList.size() > 0)) {
  774. Map<String, Object> invMap = new HashMap<>();
  775. invMap.put("outDetail", invList);
  776. invMap.put("delOutDetail", invDelList);
  777. inventoryService.operatingInventoryInformation(invMap);
  778. }
  779. //endregion
  780. }
  781. //endregion
  782. //region 入库中编辑
  783. if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundVO.getOutStatus()) ||
  784. Constant.OutStatus.DAICHUKU.getName().equals(outboundVO.getOutStatus())) {
  785. //region 修改明细
  786. List<OutboundItemVO> itemList = outboundVO.getItemList();
  787. for (OutboundItemVO outboundItemVO : itemList) {
  788. //根据id查询 获取到还未进行修改的数据
  789. OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
  790. //region 编辑明细
  791. if (outboundItemVO.getItemId() != null) {
  792. OutboundItem outboundItem = new OutboundItem();
  793. outboundItem.setItemId(outboundItemResponse.getItemId());
  794. outboundItem.setOutingQty(outboundItemResponse.getOutingQty());
  795. outboundItem.setOutingAmt(outboundItemResponse.getOutingAmt());
  796. //修改
  797. outboundItemMapper.update(outboundItem,
  798. new UpdateWrapper<OutboundItem>().lambda()
  799. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  800. );
  801. }
  802. //endregion
  803. //region 新建明细
  804. else {
  805. outboundItemVO
  806. .setOutId(outboundItemVO.getOutId())
  807. .setOutQty(BigDecimal.ZERO)
  808. .setOutAmt(BigDecimal.ZERO)
  809. .setCostPrice(outboundItemVO.getPriceOut())
  810. .setCostAmt(outboundItemVO.getOutingQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  811. .setOutType(Constant.OutType.SALE.getName())
  812. ;
  813. //出库状态
  814. String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
  815. outboundItemVO.setOutStatus(outStatus);
  816. //实体转换
  817. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  818. //新建
  819. outboundItemMapper.insert(outboundItem);
  820. outboundItemVO.setItemId(outboundItem.getItemId());
  821. }
  822. //endregion
  823. //region 销售明细
  824. if (outboundItemVO.getFromItemId() != null) {
  825. //根据id查询
  826. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  827. OrderItem orderItem = new OrderItem();
  828. orderItem.setItemId(outboundItemVO.getFromItemId());
  829. orderItem.setOutingQty(outboundItemResponse.getOutingQty().negate().add(outboundItemVO.getOutingQty()));
  830. orderItem.setOutingAmt(outboundItemResponse.getOutingAmt().negate().add(outboundItemVO.getOutingAmt()));
  831. //出库状态
  832. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  833. orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
  834. orderItem.setOutStatus(outStatus);
  835. int countRow = orderItemMapper.updateById(orderItem);
  836. //数量超出
  837. if (countRow == 0) {
  838. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  839. }
  840. }
  841. //endregion
  842. }
  843. //endregion
  844. //region 删除明细
  845. BigDecimal delOutQty = BigDecimal.ZERO;
  846. BigDecimal delOutAmt = BigDecimal.ZERO;
  847. if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
  848. delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  849. delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  850. for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
  851. if (outboundItemVO.getItemId() != null) {
  852. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  853. outboundItem.setFlgValid(false);
  854. //修改
  855. outboundItemMapper.update(outboundItem,
  856. new UpdateWrapper<OutboundItem>().lambda()
  857. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  858. );
  859. }
  860. //region 销售明细
  861. if (outboundItemVO.getFromItemId() != null) {
  862. //根据id查询
  863. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  864. OrderItem orderItem = new OrderItem();
  865. orderItem.setItemId(outboundItemVO.getFromItemId());
  866. orderItem.setOutingQty(outboundItemVO.getOutQty().negate());
  867. orderItem.setOutingAmt(outboundItemVO.getOutQty().negate());
  868. //出库状态
  869. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  870. orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
  871. orderItem.setOutStatus(outStatus);
  872. int countRow = orderItemMapper.updateById(orderItem);
  873. //数量超出
  874. if (countRow == 0) {
  875. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  876. }
  877. }
  878. //endregion
  879. }
  880. }
  881. //endregion
  882. //region 修改入库总单
  883. Outbound outbound = new Outbound();
  884. outbound.setOutId(outboundVO.getOutId());
  885. outbound.setOutingQty(sumQty);
  886. outbound.setOutingAmt(sumAmt);
  887. //修改
  888. outboundMapper.update(outbound,
  889. new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  890. );
  891. //endregion
  892. //region 修改采购总单
  893. if (outboundVO.getFromId() != null) {
  894. //根据id查询
  895. OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
  896. Order order = new Order();
  897. order.setOrderId(outboundVO.getFromId());
  898. order.setOutingQty(outboundResponse.getOutingQty().negate().add(sumQty).subtract(delOutQty));
  899. order.setOutingAmt(outboundResponse.getOutingAmt().negate().add(sumAmt).subtract(delOutAmt));
  900. //出库状态
  901. String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
  902. orderResponse.getOutQty(), orderResponse.getSumQuantity());
  903. order.setOutStatus(outStatus);
  904. //修改
  905. int countRow = orderMapper.updateById(order);
  906. //数量超出
  907. if (countRow == 0) {
  908. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  909. }
  910. }
  911. //endregion
  912. }
  913. //endregion
  914. }
  915. //endregion
  916. return ResponseResultUtil.success(outboundVO);
  917. }
  918. /**
  919. * @desc : 销售出库作废
  920. * @date : 2024/3/26 9:24
  921. * @author : 寇珊珊
  922. */
  923. @Transactional(rollbackFor = {Exception.class})
  924. public ResponseResultVO<?> saleOutboundRepeal(String outId) {
  925. //region 查询总单 查询明细
  926. //根据id查询 此条出库单的数据还未更改前的数据
  927. OutboundResponse outboundResponse = outboundMapper.selectById(outId);
  928. //根据总单id查询
  929. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
  930. //endregion
  931. //region 已出库状态作废
  932. if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
  933. //region 应收反记账
  934. if (outboundResponse.getReceivableId() != null) {
  935. accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  936. }
  937. //endregion
  938. //region 修改明细
  939. for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
  940. //region 将库存需要的参数赋值
  941. outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  942. outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  943. outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
  944. outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt());
  945. //endregion
  946. //赋值 防止作废的单据查不到明细 故注掉下面代码
  947. // OutboundItem outboundItem = new OutboundItem();
  948. // outboundItem.setItemId(outboundItemResponse.getItemId());
  949. // outboundItem.setFlgValid(false);
  950. // //修改
  951. // outboundItemMapper.update(outboundItem,
  952. // new UpdateWrapper<OutboundItem>().lambda()
  953. // .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  954. // );
  955. //region 销售明细
  956. if (outboundItemResponse.getFromItemId() != null) {
  957. //根据id查询
  958. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
  959. OrderItem orderItem = new OrderItem();
  960. orderItem.setItemId(outboundItemResponse.getFromItemId());
  961. orderItem.setOutQty(outboundItemResponse.getOutQty().negate());
  962. orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate());
  963. //出库状态
  964. String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty(),
  965. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  966. orderItem.setOutStatus(orderOutStatus);
  967. int countRow = orderItemMapper.updateById(orderItem);
  968. //数量超出
  969. if (countRow == 0) {
  970. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  971. }
  972. }
  973. //endregion
  974. }
  975. //endregion
  976. //region 修改入库总单
  977. Outbound outbound = new Outbound();
  978. outbound.setOutId(outboundResponse.getOutId());
  979. outbound.setFlgValid(false);
  980. //修改
  981. outboundMapper.update(outbound,
  982. new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  983. );
  984. //endregion
  985. //region 修改销售总单
  986. if (outboundResponse.getFromId() != null) {
  987. //根据id查询
  988. OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
  989. Order order = new Order();
  990. order.setOrderId(outboundResponse.getFromId());
  991. order.setOutQty(outboundResponse.getOutQty().negate());
  992. order.setOutAmt(outboundResponse.getOutAmt().negate());
  993. //出库状态
  994. String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty(),
  995. orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
  996. order.setOutStatus(orderOutStatus);
  997. //修改
  998. int countRow = orderMapper.updateById(order);
  999. //数量超出
  1000. if (countRow == 0) {
  1001. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1002. }
  1003. }
  1004. //endregion
  1005. //region 外协品新建外协入库单
  1006. //筛选出skuId为空的 走外协品逻辑
  1007. OutboundVO outboundVO = outboundConvert.convertResToVO(outboundResponse);
  1008. List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  1009. List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
  1010. //删除外协品生产外协入库单
  1011. this.deleteOutsideGoodsInto(outboundVO, outsideGoodsVOList);
  1012. //endregion
  1013. //region 修改库存
  1014. //筛选出skuId不为空的 走库存
  1015. List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  1016. if(invList!=null && invList.size()>0) {
  1017. Map<String, Object> map = new HashMap<>();
  1018. map.put("delOutDetail", invList);
  1019. inventoryService.operatingInventoryInformation(map);
  1020. }
  1021. //endregion
  1022. }
  1023. //endregion
  1024. //region 出库中、待出库状态作废
  1025. if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus()) ||
  1026. Constant.OutStatus.DAICHUKU.getName().equals(outboundResponse.getOutStatus())) {
  1027. //region 修改明细
  1028. for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
  1029. //region 修改明细
  1030. //赋值
  1031. OutboundItem outboundItem = new OutboundItem();
  1032. outboundItem.setItemId(outboundItemResponse.getItemId());
  1033. outboundItem.setOutingQty(BigDecimal.ZERO);
  1034. outboundItem.setOutingAmt(BigDecimal.ZERO);
  1035. // outboundItem.setFlgValid(false);
  1036. //修改
  1037. outboundItemMapper.update(outboundItem,
  1038. new UpdateWrapper<OutboundItem>().lambda()
  1039. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  1040. );
  1041. //endregion
  1042. //region 销售明细
  1043. if (outboundItemResponse.getFromItemId() != null) {
  1044. //根据id查询
  1045. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
  1046. OrderItem orderItem = new OrderItem();
  1047. orderItem.setItemId(outboundItemResponse.getFromItemId());
  1048. orderItem.setOutingQty(outboundItemResponse.getOutingQty().negate());
  1049. orderItem.setOutingAmt(outboundItemResponse.getOutingAmt().negate());
  1050. //出库状态
  1051. String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  1052. orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
  1053. orderItem.setOutStatus(orderOutStatus);
  1054. int countRow = orderItemMapper.updateById(orderItem);
  1055. //数量超出
  1056. if (countRow == 0) {
  1057. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1058. }
  1059. }
  1060. //endregion
  1061. }
  1062. //endregion
  1063. //region 修改出库总单
  1064. Outbound outbound = new Outbound();
  1065. outbound.setOutId(outboundResponse.getOutId());
  1066. outbound.setOutingQty(BigDecimal.ZERO);
  1067. outbound.setOutingAmt(BigDecimal.ZERO);
  1068. outbound.setFlgValid(false);
  1069. //修改
  1070. outboundMapper.update(outbound,
  1071. new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  1072. );
  1073. //endregion
  1074. //region 修改销售总单
  1075. if (outboundResponse.getFromId() != null) {
  1076. //根据id查询
  1077. OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
  1078. Order order = new Order();
  1079. order.setOrderId(outboundResponse.getFromId());
  1080. order.setOutingQty(outboundResponse.getOutingQty().negate());
  1081. order.setOutingAmt(outboundResponse.getOutingAmt().negate());
  1082. //出库状态
  1083. String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
  1084. orderResponse.getOutQty(), orderResponse.getSumQuantity());
  1085. order.setOutStatus(orderOutStatus);
  1086. //修改
  1087. int countRow = orderMapper.updateById(order);
  1088. //数量超出
  1089. if (countRow == 0) {
  1090. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1091. }
  1092. }
  1093. //endregion
  1094. }
  1095. //endregion
  1096. return ResponseResultUtil.success();
  1097. }
  1098. /**
  1099. * @desc : 销售出库办理
  1100. * @date : 2024/3/7 15:47
  1101. * @author : 寇珊珊
  1102. */
  1103. @Transactional(rollbackFor = {Exception.class})
  1104. public ResponseResultVO<?> saleOrderHandleOutbound(OutboundVO outboundVO) {
  1105. //region 根据id查询 此条入库单的数据还未更改前的数据
  1106. OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
  1107. //endregion
  1108. //region 应收反记账
  1109. if (outboundResponse.getReceivableId() != null) {
  1110. accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  1111. }
  1112. //endregion
  1113. //region 编辑明细
  1114. //校验明细
  1115. if (outboundVO.getItemList().size() == 0) {
  1116. throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
  1117. ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
  1118. }
  1119. for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
  1120. //明细根据id查询
  1121. OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
  1122. //region 校验数量是否超出
  1123. if (outboundItemVO.getOutingQty().compareTo(outboundItemResponse.getOutingQty()) > 0) {
  1124. throw new BaseBusinessException(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getCode(),
  1125. ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getMessage());
  1126. }
  1127. //endregion
  1128. //region 编辑明细
  1129. if (outboundItemVO.getItemId() != null) {
  1130. outboundItemVO
  1131. .setOutQty(outboundItemVO.getOutingQty())
  1132. .setOutBox(outboundItemVO.getOutingBox()).setOutPiece(outboundItemVO.getOutingPiece())
  1133. .setOutAmt(outboundItemVO.getOutingAmt())
  1134. .setOutingQty(BigDecimal.ZERO).setOutingBox(0).setOutingPiece(BigDecimal.ZERO)
  1135. .setOutingAmt(BigDecimal.ZERO)
  1136. .setCostPrice(outboundItemVO.getPriceOut())
  1137. .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  1138. ;
  1139. //出库状态
  1140. String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
  1141. outboundItemVO.setOutStatus(outStatus);
  1142. //实体转换
  1143. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  1144. //修改
  1145. outboundItemMapper.update(outboundItem,
  1146. new UpdateWrapper<OutboundItem>().lambda()
  1147. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  1148. );
  1149. //region 将库存需要的参数赋值
  1150. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  1151. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  1152. //编辑之前的数
  1153. if (outboundItemResponse.getOutQty().compareTo(BigDecimal.ZERO) > 0) {
  1154. outboundItemVO.setQtyBeforeUpdate(outboundItemResponse.getOutQty());
  1155. outboundItemVO.setAmtBeforeUpdate(outboundItemResponse.getOutAmt());
  1156. }
  1157. outboundItemVO.setAddOrEditFlag(true);
  1158. //endregion
  1159. }
  1160. //endregion
  1161. //region 新建明细
  1162. else {
  1163. outboundItemVO
  1164. .setOutId(outboundItemVO.getOutId())
  1165. .setOutQty(outboundItemVO.getOutingQty())
  1166. .setOutBox(outboundItemVO.getOutingBox()).setOutPiece(outboundItemVO.getOutingPiece())
  1167. .setOutAmt(outboundItemVO.getOutingAmt())
  1168. .setCostPrice(outboundItemVO.getPriceOut())
  1169. .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
  1170. .setOutType(Constant.OutType.SALE.getName())
  1171. .setOutingQty(BigDecimal.ZERO)
  1172. .setOutingAmt(BigDecimal.ZERO)
  1173. ;
  1174. //出库状态
  1175. String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
  1176. outboundItemVO.setOutStatus(outStatus);
  1177. //实体转换
  1178. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  1179. //新建
  1180. outboundItemMapper.insert(outboundItem);
  1181. outboundItemVO.setItemId(outboundItem.getItemId());
  1182. //region 将库存需要的参数赋值
  1183. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  1184. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  1185. outboundItemVO.setAddOrEditFlag(true);
  1186. //endregion
  1187. }
  1188. //endregion
  1189. //region 销售订单明细
  1190. if (outboundItemVO.getFromItemId() != null) {
  1191. //根据id查询
  1192. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  1193. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1194. OrderItem orderItem = new OrderItem();
  1195. orderItem.setItemId(outboundItemVO.getFromItemId());
  1196. orderItem.setOutingQty(outboundItemVO.getOutQty().negate());
  1197. orderItem.setOutingAmt(outboundItemVO.getOutAmt().negate());
  1198. orderItem.setOutQty(outboundItemVO.getOutQty());
  1199. orderItem.setOutAmt(outboundItemVO.getOutAmt());
  1200. //出库状态
  1201. String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().subtract(outboundItemVO.getOutQty()),
  1202. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  1203. orderItem.setOutStatus(orderOutStatus);
  1204. //修改
  1205. int countRow = orderItemMapper.updateById(orderItem);
  1206. //数量超出
  1207. if (countRow == 0) {
  1208. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1209. }
  1210. }
  1211. //endregion
  1212. }
  1213. //endregion
  1214. //region 删除明细
  1215. BigDecimal delOutingQty = BigDecimal.ZERO;
  1216. BigDecimal delOutingAmt = BigDecimal.ZERO;
  1217. BigDecimal delOutQty = BigDecimal.ZERO;
  1218. BigDecimal delOutAmt = BigDecimal.ZERO;
  1219. if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
  1220. delOutingQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  1221. delOutingAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  1222. delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  1223. delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  1224. for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
  1225. if (outboundItemVO.getItemId() != null) {
  1226. //region 将库存需要的参数赋值
  1227. outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  1228. outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  1229. //endregion
  1230. OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
  1231. outboundItem.setFlgValid(false);
  1232. //修改
  1233. outboundItemMapper.update(outboundItem,
  1234. new UpdateWrapper<OutboundItem>().lambda()
  1235. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  1236. );
  1237. }
  1238. //region 销售订单明细
  1239. if (outboundItemVO.getFromItemId() != null) {
  1240. //根据id查询
  1241. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
  1242. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1243. OrderItem orderItem = new OrderItem();
  1244. orderItem.setItemId(outboundItemVO.getFromItemId());
  1245. orderItem.setOutingQty(outboundItemVO.getOutingQty().negate());
  1246. orderItem.setOutingAmt(outboundItemVO.getOutingAmt().negate());
  1247. orderItem.setOutQty(outboundItemVO.getOutQty().negate());
  1248. orderItem.setOutAmt(outboundItemVO.getOutAmt().negate());
  1249. //出库状态
  1250. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().subtract(orderItem.getOutingQty()),
  1251. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  1252. orderItem.setOutStatus(outStatus);
  1253. //修改
  1254. int countRow = orderItemMapper.updateById(orderItem);
  1255. //数量超出
  1256. if (countRow == 0) {
  1257. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1258. }
  1259. }
  1260. //endregion
  1261. }
  1262. }
  1263. //endregion
  1264. //region 编辑总单
  1265. BigDecimal sumOutQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
  1266. BigDecimal sumOutAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
  1267. outboundVO.setOutQty(sumOutQty);
  1268. outboundVO.setOutAmt(sumOutAmt);
  1269. outboundVO.setOutingQty(BigDecimal.ZERO);
  1270. outboundVO.setOutingAmt(BigDecimal.ZERO);
  1271. //出库状态
  1272. String outStatus = this.setOutStatus(outboundVO.getOutingQty(), outboundVO.getOutQty());
  1273. outboundVO.setOutStatus(outStatus);
  1274. //实体转换
  1275. Outbound outbound = outboundConvert.convertToPo(outboundVO);
  1276. //修改
  1277. outboundMapper.update(outbound,
  1278. new UpdateWrapper<Outbound>().lambda()
  1279. .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  1280. );
  1281. //endregion
  1282. //region 修改销售订单订单
  1283. if (outboundVO.getFromId() != null) {
  1284. //根据id查询
  1285. OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
  1286. //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1287. Order order = new Order();
  1288. order.setOrderId(outboundVO.getFromId());
  1289. order.setOutQty(sumOutQty.subtract(delOutQty));
  1290. order.setOutAmt(sumOutAmt.subtract(delOutAmt));
  1291. order.setOutingQty((outboundResponse.getOutingQty().add(delOutingQty)).negate());
  1292. order.setOutingAmt((outboundResponse.getOutingAmt().add(delOutingAmt)).negate());
  1293. //出库状态
  1294. String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().subtract(sumOutQty).add(delOutQty),
  1295. orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
  1296. order.setOutStatus(orderOutStatus);
  1297. //修改
  1298. int countRow = orderMapper.updateById(order);
  1299. //数量超出
  1300. if (countRow == 0) {
  1301. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1302. }
  1303. }
  1304. //endregion
  1305. //region 应收记账
  1306. accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  1307. //endregion
  1308. //region 库存明细处理
  1309. if(outboundVO.getItemList()!=null && outboundVO.getItemList().size()>0){
  1310. Map<String, Object> map = new HashMap<>(); // 定义map值 修改库存用
  1311. // 获取外协数据
  1312. List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  1313. //新建外协品生产外协入库单
  1314. this.insertOutsideGoodsInto(outboundVO, outsideGoods);
  1315. // 获取商品明细数据
  1316. List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  1317. // 赋值修改明细
  1318. map.put("outDetail", invList);
  1319. // 删除的商品
  1320. if(outboundVO.getDeleteItemList()!=null && outboundVO.getDeleteItemList().size()>0){
  1321. // 获取外协删除数据
  1322. List<OutboundItemVO> invsideDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  1323. //删除外协品生产外协入库单
  1324. this.deleteOutsideGoodsInto(outboundVO, invsideDelList);
  1325. // 获取删除商品数据
  1326. List<OutboundItemVO> invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  1327. // 赋值删除明细
  1328. map.put("delOutDetail", invDelList);
  1329. }
  1330. // 调用修改库存信息方法
  1331. inventoryService.operatingInventoryInformation(map);
  1332. }
  1333. //endregion
  1334. return ResponseResultUtil.success(outboundVO);
  1335. }
  1336. /**
  1337. * @desc : 销售出库撤销
  1338. * @date : 2024/3/7 17:06
  1339. * @author : 寇珊珊
  1340. */
  1341. @Transactional(rollbackFor = {Exception.class})
  1342. public ResponseResultVO<?> saleOrderOutboundCancel(OutboundVO outboundVO) {
  1343. //region 查询出库总单数据信息
  1344. OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
  1345. //endregion
  1346. //region 应收反记账
  1347. if (outboundResponse.getReceivableId() != null) {
  1348. accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
  1349. }
  1350. //endregion
  1351. //region 修改订单数据信息
  1352. if (outboundResponse.getFromId() != null) {
  1353. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1354. Order order = new Order();
  1355. order.setOrderId(outboundResponse.getFromId());
  1356. order.setOutingQty(outboundResponse.getOutQty());
  1357. order.setOutingAmt(outboundResponse.getOutAmt());
  1358. order.setOutQty(outboundResponse.getOutQty().negate());
  1359. order.setOutAmt(outboundResponse.getOutAmt().negate());
  1360. //根据id查询
  1361. OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
  1362. //出库状态
  1363. String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
  1364. orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
  1365. order.setOutStatus(outStatus);
  1366. //修改
  1367. int countRow = orderMapper.updateById(order);
  1368. //数量超出
  1369. if (countRow == 0) {
  1370. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1371. }
  1372. }
  1373. //endregion
  1374. //region 修改总单数据信息
  1375. Outbound outbound = new Outbound();
  1376. outbound.setOutId(outboundResponse.getOutId());
  1377. outbound.setOutDate(null);
  1378. outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
  1379. outbound.setOutQty(BigDecimal.ZERO);
  1380. outbound.setOutAmt(BigDecimal.ZERO);
  1381. outbound.setOutingQty(outboundResponse.getOutingQty().add(outboundResponse.getOutQty()));
  1382. outbound.setOutingAmt(outboundResponse.getOutingAmt().add(outboundResponse.getOutAmt()));
  1383. //修改
  1384. outboundMapper.update(outbound,
  1385. new UpdateWrapper<Outbound>().lambda()
  1386. .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
  1387. );
  1388. //endregion
  1389. //region 明细数据
  1390. //根据总单id查明细
  1391. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
  1392. for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
  1393. //region 修改销售订单明细数据信息
  1394. if (outboundItemResponse.getFromItemId() != null) {
  1395. //根据id查询
  1396. OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
  1397. //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
  1398. OrderItem orderItem = new OrderItem();
  1399. orderItem.setItemId(outboundItemResponse.getFromItemId());
  1400. orderItem.setOutQty(outboundItemResponse.getOutQty().negate());
  1401. orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate());
  1402. orderItem.setOutingQty(outboundItemResponse.getOutQty());
  1403. orderItem.setOutingAmt(outboundItemResponse.getOutAmt());
  1404. //出库状态
  1405. String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
  1406. orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
  1407. orderItem.setOutStatus(outStatus);
  1408. //修改
  1409. int countRow = orderItemMapper.updateById(orderItem);
  1410. //数量超出
  1411. if (countRow == 0) {
  1412. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
  1413. }
  1414. }
  1415. //endregion
  1416. //region修改出库明细信息
  1417. OutboundItem outboundItem = new OutboundItem();
  1418. //region 将库存需要的参数赋值
  1419. outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
  1420. outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
  1421. outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
  1422. outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
  1423. //endregion
  1424. outboundItem
  1425. .setOutId(outboundResponse.getOutId())
  1426. .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
  1427. .setOutingQty(outboundItemResponse.getOutingQty().add(outboundItemResponse.getOutQty()))
  1428. .setOutAmt(outboundItemResponse.getOutingAmt().add(outboundItemResponse.getOutAmt()))
  1429. .setOutQty(BigDecimal.ZERO)
  1430. .setOutAmt(BigDecimal.ZERO)
  1431. .setCostPrice(BigDecimal.ZERO)
  1432. .setCostAmt(BigDecimal.ZERO)
  1433. .setItemId(outboundItemResponse.getItemId());
  1434. //修改
  1435. outboundItemMapper.update(outboundItem,
  1436. new UpdateWrapper<OutboundItem>().lambda()
  1437. .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
  1438. );
  1439. //endregion
  1440. }
  1441. //endregion
  1442. //region 外协品新建外协入库单
  1443. //筛选出skuId为空的 走外协品逻辑
  1444. OutboundVO outsideGoodVO = outboundConvert.convertResToVO(outboundResponse);
  1445. List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
  1446. List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
  1447. //删除外协品生产外协入库单
  1448. this.deleteOutsideGoodsInto(outsideGoodVO, outsideGoodsVOList);
  1449. //endregion
  1450. //region 调用库存
  1451. //筛选出skuId不为空的 走库存
  1452. List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
  1453. if(invList!=null && invList.size()>0) {
  1454. Map<String, Object> map = new HashMap<>();
  1455. map.put("delOutDetail", invList);
  1456. inventoryService.operatingInventoryInformation(map);
  1457. }
  1458. //endregion
  1459. return ResponseResultUtil.success();
  1460. }
  1461. /**
  1462. * @desc : 出库状态通用(目前本页面)
  1463. * @date : 2024/3/9 8:59
  1464. * @author : 寇珊珊
  1465. */
  1466. @Transactional(rollbackFor = {Exception.class})
  1467. public String setOutStatus(BigDecimal outingQty, BigDecimal outQty) {
  1468. //出库状态
  1469. String outStatus = null;
  1470. //已出库数量>0 出库中数量>0
  1471. if (outQty.compareTo(BigDecimal.ZERO) >= 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
  1472. //出库中
  1473. outStatus = Constant.OutStatus.CHUKUZHONG.getName();
  1474. }
  1475. //出入库数量=0 出库中数量=0
  1476. else if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
  1477. //待出库
  1478. outStatus = Constant.OutStatus.DAICHUKU.getName();
  1479. }
  1480. //已出库数量>0 出库中数量=0
  1481. else if (outQty.compareTo(BigDecimal.ZERO) > 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
  1482. //已出库
  1483. outStatus = Constant.OutStatus.YICHUKU.getName();
  1484. }
  1485. return outStatus;
  1486. }
  1487. /**
  1488. * @desc : 上游单据入库状态通用(目前本页面)
  1489. * @date : 2024/4/1 17:14
  1490. * @author : 寇珊珊
  1491. */
  1492. @Transactional(rollbackFor = {Exception.class})
  1493. public String setOutStatus(BigDecimal intoingQty, BigDecimal intoQty, BigDecimal sumQty) {
  1494. //入库状态
  1495. String outStatus = null;
  1496. //入库中+已入库 小于 总数
  1497. if (intoingQty.add(intoQty).compareTo(sumQty) < 0) {
  1498. //入库中
  1499. outStatus = Constant.OutStatus.CHUKUZHONG.getName();
  1500. }
  1501. //已入库数量=0 入库中数量=0
  1502. else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
  1503. //待入库
  1504. outStatus = Constant.OutStatus.DAICHUKU.getName();
  1505. }
  1506. //入库中+已入库 等于 总数
  1507. else if (intoingQty.add(intoQty).compareTo(sumQty) == 0) {
  1508. //已入库
  1509. outStatus = Constant.OutStatus.YICHUKU.getName();
  1510. }
  1511. return outStatus;
  1512. }
  1513. /**
  1514. * @desc : 获取单据信息(编辑用)
  1515. * @date : 2024/3/16 16:28
  1516. * @author : 寇珊珊
  1517. */
  1518. public ResponseResultVO<?> selectByUpdate(String id) {
  1519. Map<String, Object> dataInfo = new HashMap<>();
  1520. //总单
  1521. OutboundResponse outboundResponse = outboundMapper.selectMessageByOtherQuery(new OutboundQuery().setOutId(id).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName()));
  1522. //单据不存在
  1523. if (outboundResponse == null) {
  1524. throw new BaseBusinessException(ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getCode(),
  1525. ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getMessage());
  1526. }
  1527. dataInfo.put("data", outboundResponse);
  1528. // 明细
  1529. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
  1530. dataInfo.put("dataItem", outboundItemResponseList);
  1531. return ResponseResultUtil.success(dataInfo);
  1532. }
  1533. /********************************************** 销售出库查询相关方法begin *************************************/
  1534. /**
  1535. * @desc : 一览页销售出库
  1536. * @author : 付斌
  1537. * @date : 2023/1/9 10:40
  1538. */
  1539. @Pagination
  1540. public ResponseResultVO<PageList<OutboundResponse>> selectByCond(OutboundQuery outboundQuery) {
  1541. outboundQuery.setOutType(Constant.OutType.SALE.getName());
  1542. return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
  1543. outboundMapper.countByCond(outboundQuery));
  1544. }
  1545. /**
  1546. * @desc : 一览页销售出库明细(货物、附件)
  1547. * @author : 付斌
  1548. * @date : 2024-02-28 13:25
  1549. */
  1550. @Pagination
  1551. public ResponseResultVO<Map<String, Object>> selectOutboundInfoById(String id) {
  1552. Map<String, Object> result = new HashMap<>();
  1553. // 商品明细
  1554. List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
  1555. result.put("outboundItem", outboundItem);
  1556. // 附件
  1557. return ResponseResultUtil.success(result);
  1558. }
  1559. /**
  1560. * @desc : 获取销售出库信息(编辑用)
  1561. * @author : 付斌
  1562. * @date : 2024-03-02 17:27
  1563. */
  1564. public ResponseResultVO<?> getOutboundForUpdate(String id) {
  1565. Map<String, Object> dataInfo = new HashMap<>();
  1566. OutboundResponse outboundResponse = outboundMapper.selectById(id);
  1567. dataInfo.put("data", outboundResponse);
  1568. // 商品明细
  1569. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEdit(id);
  1570. dataInfo.put("dataItem", outboundItemResponseList);
  1571. return ResponseResultUtil.success(dataInfo);
  1572. }
  1573. /**
  1574. * @desc : 获取销售出库信息(编辑用,适用于直接新建的出库单)
  1575. * @author : 付斌
  1576. * @date : 2024-03-02 17:27
  1577. */
  1578. public ResponseResultVO<?> getOutboundTogetherForUpdate(String id) {
  1579. Map<String, Object> dataInfo = new HashMap<>();
  1580. OutboundResponse outboundResponse = outboundMapper.selectById(id);
  1581. dataInfo.put("data", outboundResponse);
  1582. // 商品明细
  1583. List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEditTogether(id);
  1584. dataInfo.put("dataItem", outboundItemResponseList);
  1585. return ResponseResultUtil.success(dataInfo);
  1586. }
  1587. /**
  1588. * @desc : 获取出库信息(新建退货用)
  1589. * @author : 付斌
  1590. * @date : 2024-03-02 17:27
  1591. */
  1592. public ResponseResultVO<?> getOutForReturn(String id) {
  1593. OutboundResponse outboundResponse = outboundMapper.selectByIdForReturn(id);
  1594. List<OutboundItemResponse> outboundItemList = outboundItemMapper.selectByCondForReturn(new OutboundItemQuery().setOutId(id));
  1595. if (outboundItemList != null && outboundItemList.size() > 0) {
  1596. // 求和
  1597. OutboundItemResponse sumEntity = outboundItemList.stream().reduce((x, y) -> {
  1598. OutboundItemResponse item = new OutboundItemResponse();
  1599. item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
  1600. item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
  1601. return item;
  1602. }).get();
  1603. outboundResponse.setOutingQty(sumEntity.getOutingQty()).setOutingAmt(sumEntity.getOutingAmt());
  1604. }
  1605. Map<String, Object> dataInfo = new HashMap<>();
  1606. dataInfo.put("data", outboundResponse);
  1607. dataInfo.put("dataItem", outboundItemList);
  1608. return ResponseResultUtil.success(dataInfo);
  1609. }
  1610. /**
  1611. * @desc : 查询出库明细(货物、附件)
  1612. * @author : 付斌
  1613. * @date : 2024-02-28 13:25
  1614. */
  1615. @Pagination
  1616. public ResponseResultVO selectById(String id) {
  1617. OutboundResponse outboundResponse = outboundMapper.selectById(id);
  1618. // 商品明细
  1619. List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
  1620. outboundResponse.setGoodsList(outboundItem);
  1621. // 附件
  1622. return ResponseResultUtil.success(outboundResponse);
  1623. }
  1624. /********************************************** 销售出库查询相关方法end *************************************/
  1625. // /**
  1626. // * @desc : 条件查询
  1627. // * @date : 2024/3/18 11:20
  1628. // * @author : 寇珊珊
  1629. // */
  1630. // @Pagination
  1631. // public ResponseResultVO<PageList<InboundResponse>> selectByCond(OutboundQuery outboundQuery) {
  1632. // return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
  1633. // outboundMapper.countByCond(outboundQuery));
  1634. // }
  1635. //
  1636. // /**
  1637. // * @desc : 查询明细
  1638. // * @date : 2024/3/15 16:43
  1639. // * @author : 寇珊珊
  1640. // */
  1641. // @Pagination
  1642. // public ResponseResultVO<Map<String, Object>> selectOutBoundSaleOrderItemInfoById(String id) {
  1643. // Map<String, Object> result = new HashMap<>();
  1644. // // 商品明细
  1645. // List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
  1646. // result.put("itemList", outboundItemResponseList);
  1647. // // 收款
  1648. //
  1649. // // 附件
  1650. // return ResponseResultUtil.success(result);
  1651. // }
  1652. /**
  1653. * @desc : 条件查询(总单带明细)
  1654. * @author : 于继渤
  1655. * @date : 2023/1/9 10:36
  1656. */
  1657. @Pagination
  1658. public ResponseResultVO<PageList<OutboundResponse>> selectByCondDetail(OutboundQuery outboundQuery) {
  1659. return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCondDetail(outboundQuery),
  1660. outboundMapper.countByCondDetail(outboundQuery));
  1661. }
  1662. }