| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288 |
- package com.dk.mdm.service.ivt.outbound;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.dk.common.exception.BaseBusinessException;
- import com.dk.common.infrastructure.annotaiton.Pagination;
- import com.dk.common.infrastructure.constant.Constant;
- import com.dk.common.infrastructure.enums.ErrorCodeEnum;
- import com.dk.common.mapper.BaseMapper;
- import com.dk.common.model.pojo.PageList;
- import com.dk.common.response.ResponseCodeEnum;
- import com.dk.common.response.ResponseResultUtil;
- import com.dk.common.response.ResponseResultVO;
- import com.dk.common.service.BaseService;
- import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
- import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
- import com.dk.mdm.infrastructure.convert.ivt.OutboundConvert;
- import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
- import com.dk.mdm.mapper.common.CommonMapper;
- import com.dk.mdm.mapper.ivt.*;
- import com.dk.mdm.mapper.sale.OrderItemMapper;
- import com.dk.mdm.mapper.sale.OrderMapper;
- import com.dk.mdm.model.pojo.ivt.Inbound;
- import com.dk.mdm.model.pojo.ivt.InboundItem;
- import com.dk.mdm.model.pojo.ivt.Outbound;
- import com.dk.mdm.model.pojo.ivt.OutboundItem;
- import com.dk.mdm.model.pojo.sale.Order;
- import com.dk.mdm.model.pojo.sale.OrderItem;
- import com.dk.mdm.model.query.ivt.InboundItemQuery;
- import com.dk.mdm.model.query.ivt.InventoryQuery;
- import com.dk.mdm.model.query.ivt.OutboundItemQuery;
- import com.dk.mdm.model.query.ivt.OutboundQuery;
- import com.dk.mdm.model.response.ivt.InboundResponse;
- import com.dk.mdm.model.response.ivt.InventoryResponse;
- import com.dk.mdm.model.response.ivt.OutboundItemResponse;
- import com.dk.mdm.model.response.ivt.OutboundResponse;
- import com.dk.mdm.model.response.sale.OrderItemResponse;
- import com.dk.mdm.model.response.sale.OrderResponse;
- import com.dk.mdm.model.vo.ivt.InboundItemVO;
- import com.dk.mdm.model.vo.ivt.InboundVO;
- import com.dk.mdm.model.vo.ivt.OutboundItemVO;
- import com.dk.mdm.model.vo.ivt.OutboundVO;
- import com.dk.mdm.service.common.CommonService;
- import com.dk.mdm.service.ivt.inventory.InventoryService;
- import com.dk.mdm.service.mac.AccountService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.time.LocalDate;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.stream.Collectors;
- /**
- * @author : 寇珊珊
- * @desc : 销售出库业务层
- * @date : 2024/3/18 15:33
- */
- @Service
- public class OutboundSaleOrderService extends BaseService<Outbound> {
- @Override
- public BaseMapper<Outbound> getRepository() {
- return outboundMapper;
- }
- @Autowired
- private CommonService commonService;
- @Autowired
- private OutboundMapper outboundMapper;
- @Autowired
- private OutboundConvert outboundConvert;
- @Autowired
- private OutboundItemMapper outboundItemMapper;
- @Autowired
- private OutboundItemConvert outboundItemConvert;
- @Autowired
- private OrderMapper orderMapper;
- @Autowired
- private OrderItemMapper orderItemMapper;
- @Autowired
- private CommonMapper commonMapper;
- @Autowired
- private InventoryService inventoryService;
- @Autowired
- private AccountService accountService;
- @Autowired
- private OutCommon outCommon;
- @Autowired
- private InboundMapper inboundMapper;
- @Autowired
- private InboundConvert inboundConvert;
- @Autowired
- private InboundItemMapper inboundItemMapper;
- @Autowired
- private InboundItemConvert inboundItemConvert;
- @Autowired
- private InventoryMapper inventoryMapper;
- /*****************************************先判断库存*****************************************/
- /**
- * @desc : 校验库存是否存在
- * @date : 2024/6/11 10:55
- * @author : 寇珊珊
- */
- @Transactional(
- rollbackFor = {Exception.class}
- )
- public InventoryResponse checkInventoryExist(OutboundItemVO outboundItemVO) {
- //存在标识
- //根据sku,仓库,非标号查询
- InventoryResponse inventoryResponse = null;
- if (outboundItemVO.getSkuId() != null) {
- inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
- .setSkuId(outboundItemVO.getSkuId())
- .setWhId(outboundItemVO.getWhId())
- .setNonStdCode(outboundItemVO.getNonStdCode()));
- }
- //库存不存在
- if(inventoryResponse == null){
- //当前出库商品中在库存中不存在
- throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
- ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
- }
- return inventoryResponse;
- }
- /**
- * @desc : 先查库存后出库
- * @date : 2024/6/11 9:30
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void inventoryOUtBond(OutboundVO outboundVO) {
- //region 校验明细
- if (outboundVO.getItemList().size() == 0) {
- throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
- ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
- }
- //endregion
- //可以负库存 不用交验库存直接走负库存逻辑
- if (outboundVO.getFlgHandleSetting()) {
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- //可以输入负数出库标识
- outboundItemVO.setCanNegativeFlag(true);
- //业务部门Id
- outboundItemVO.setOrgId(outboundVO.getOrgId());
- //业务员Id
- outboundItemVO.setStaffId(outboundVO.getStaffId());
- //制单员Id
- outboundItemVO.setMakeStaff(outboundVO.getMakeStaff());
- }
- //销售出库新建
- this.saleOrderOutboundInsert(outboundVO, true);
- }
- //先查库存锁表看能出库的数量有多少 可出库数量建一张已出库的单子并扣减库存,剩下的数量建一张出库中的单子
- else {
- //过滤外协品
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- //商品id不为空才校验库存 因为为空是外协品
- if (outboundItemVO.getSkuId() != null) {
- //查询库存是否存在
- InventoryResponse inventoryResponse = this.checkInventoryExist(outboundItemVO);
- if (inventoryResponse != null) {
- //库存量小于本次出库数量
- if(inventoryResponse.getInvQty().compareTo(outboundItemVO.getOutingQty())<0){
- throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
- ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
- }
- //region todo 2024年7月10日14:36:47 严格按照库存数量足够额为准
- BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
- // (库存量 大于等于 本次出库数量不用做任何处理)
- //库存量 小于 本次出库数量
- if (invQty.compareTo(BigDecimal.ZERO) < 0) {
- outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
- //不够库存数量----新建出库中数量
- outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
- }
- //endregion
- } else {
- //todo 2024年7月2日09:23:38 修改成无库存不允许出库
- // //不够库存数量----新建出库中数量
- // outboundItemVO.setNotEnoughInventoryQty(outboundItemVO.getOutingQty());
- //当前出库商品中在库存中不存在
- throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
- ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
- }
- }
- }
- //过滤出库存量足够的数据
- List<OutboundItemVO> itemList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty() == null).collect(Collectors.toList());
- //region 过滤出不够出库的每条明细数量 ------新建出库中数据
- List<OutboundItemVO> outboundIngList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty() != null && it.getNotEnoughInventoryQty().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
- if (outboundIngList != null && outboundIngList.size() > 0) {
- //赋值箱片
- for (OutboundItemVO outboundItemVO : outboundIngList) {
- //箱
- outboundItemVO.setOutingBox(Integer.valueOf(outboundItemVO.getOutingQty().divide(outboundItemVO.getPackBox(), 0, RoundingMode.DOWN).toString()));
- //片
- outboundItemVO.setOutingPiece(outboundItemVO.getOutingQty().remainder(outboundItemVO.getPackBox()));
- }
- outboundVO.setFlgAutoHandle(false);
- outboundVO.setItemList(outboundIngList);
- //销售出库新建
- this.saleOrderOutboundInsert(outboundVO, true);
- }
- //endregion
- //region 库存够扣减的明细 -----------新建已出库数据并扣减库存
- //销售出库新建
- if (itemList != null && itemList.size() > 0) {
- for (OutboundItemVO outboundItemVO : itemList) {
- //过滤外协品 外协品没有箱片
- if (outboundItemVO.getSkuId() != null) {
- //箱
- outboundItemVO.setOutBox(Integer.valueOf(outboundItemVO.getOutingQty().divide(outboundItemVO.getPackBox(), 0, RoundingMode.DOWN).toString()));
- //片
- outboundItemVO.setOutPiece(outboundItemVO.getOutingQty().remainder(outboundItemVO.getPackBox()));
- }
- }
- outboundVO.setFlgAutoHandle(true);
- outboundVO.setItemList(itemList);
- this.saleOrderOutboundInsert(outboundVO, true);
- }
- //endregion
- }
- }
- /*****************************************先判断库存*****************************************/
- /**
- * @desc : 删除外协品生产外协入库单
- * @date : 2024/5/10 10:31
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void deleteOutsideGoodsInto(OutboundVO outboundVO, List<OutboundItemVO> outboundItemVOList) {
- if (outboundItemVOList != null && outboundItemVOList.size() > 0) {
- //根据出库单id分组
- Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- for (String str : outboundItemVOMap.keySet()) {
- InboundResponse inboundResponse = inboundMapper.selectByFromId(str);
- // 退账
- if (inboundResponse != null && inboundResponse.getReceivableId() != null) {
- accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- }
- }
- //删除外协入库单
- //外协入库总单
- inboundMapper.deleteByFromId(outboundItemVOList.get(0).getFromId());
- //外协入库明细
- inboundItemMapper.deleteItemByFromId(outboundItemVOList.get(0).getFromId());
- }
- }
- /**
- * @desc : 新建外协品生产外协入库单
- * @date : 2024/5/10 10:31
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void insertOutsideGoodsInto(OutboundVO outboundVO, List<OutboundItemVO> outboundItemVOList) {
- if (outboundItemVOList != null && outboundItemVOList.size() > 0) {
- Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getOutId));
- for (String str : outboundItemVOMap.keySet()) {
- //提取分组后的明细
- List<OutboundItemVO> outboundItemVOListGroup = outboundItemVOMap.get(str);
- //region 新建总单
- //已入库金额
- BigDecimal sumIntoAmt = outboundItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //已入库数量
- BigDecimal sumIntoQty = outboundItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //总单实体
- InboundVO inboundVO = new InboundVO();
- //获取 id/单号
- Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OUTSOURCED.getName(), false);
- inboundVO.setIntoId(codeMap.get("outId").toString()).
- setIntoNo(codeMap.get("outNote").toString());
- //入库类型
- inboundVO.setIntoType(Constant.IntoType.OUTSOURCED.getName());
- //已入库
- inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
- //供应商
- inboundVO.setSupId(outboundItemVOListGroup.get(0).getSupId());
- //入库状态等于已入库
- inboundVO.setIntoQty(sumIntoQty)
- .setIntoAmt(sumIntoAmt)
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO);
- //来源id
- inboundVO.setFromId(outboundItemVOListGroup.get(0).getFromId());
- //来源单号
- inboundVO.setFromNo(outboundVO.getOutNo());
- //部门
- inboundVO.setOrgId(outboundVO.getOrgId());
- //员工
- inboundVO.setStaffId(outboundVO.getStaffId());
- //入库日期
- inboundVO.setIntoDate(LocalDate.now());
- //制单人
- inboundVO.setMakeStaff(outboundVO.getMakeStaff());
- //公司
- inboundVO.setCpId(outboundVO.getCpId());
- // 来源Id
- inboundVO.setFromId(outboundVO.getFromId());
- inboundVO.setFromNo(outboundVO.getFromNo());
- //实体转换
- Inbound inbound = inboundConvert.convertToPo(inboundVO);
- inboundMapper.insert(inbound);
- //endregion
- //region 明细
- Integer count = 0;
- for (OutboundItemVO outboundItemVO : outboundItemVOListGroup) {
- InboundItemVO inboundItemVO = new InboundItemVO();
- //总单id
- inboundItemVO.setIntoId(inboundVO.getIntoId());
- //入库类型
- inboundItemVO.setIntoType(inboundVO.getIntoType());
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
- BigDecimal costAmount = outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP);
- //todo 2024年6月28日11:13:18 wyj 实际金额和单价前台传
- inboundItemVO
- .setFromId(outboundItemVO.getFromId())
- .setFromItemId(outboundItemVO.getFromItemId())
- .setPriceInto(outboundItemVO.getPriceOut())
- .setIntoQty(outboundItemVO.getOutQty())
- .setIntoAmt(outboundItemVO.getOutAmt())
- .setIntoAmt(costAmount)
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- .setCostPrice(outboundItemVO.getCostPrice())
- .setCostAmt(outboundItemVO.getCostAmt())
- ;
- //入库状态
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
- //商品顺序
- inboundItemVO.setItemIndex(count);
- //箱(入库中)
- inboundItemVO.setIntoingBox(outboundItemVO.getOutingBox());
- //片(入库中)
- inboundItemVO.setIntoingPiece(outboundItemVO.getOutingPiece());
- //箱(已入库)
- inboundItemVO.setIntoBox(outboundItemVO.getOutBox());
- //片(已入库)
- inboundItemVO.setIntoPiece(outboundItemVO.getOutPiece());
- //入库仓库
- inboundItemVO.setWhId(outboundItemVO.getWhId());
- //企业ID
- inboundItemVO.setCpId(outboundItemVO.getCpId());
- // 商品
- inboundItemVO.setSkuModel(outboundItemVO.getSkuModel());
- inboundItemVO.setSkuName(outboundItemVO.getSkuName());
- // 来源Id
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItemMapper.insert(inboundItem);
- //用来填写商品顺序
- count++;
- inboundItemVO.setItemId(inboundItem.getItemId());
- }
- //endregion
- //region 入账
- accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
- //endregion
- }
- }
- }
- /**
- * @desc : 销售出库新建
- * orderTransmitFlag :订单传递过来的
- * @date : 2024/3/7 14:13
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOrderOutboundInsert(OutboundVO outboundVO, Boolean orderTransmitFlag) {
- //region 如果没有客户id,要新建
- // outboundVO = outCommon.insertCustomer(outboundVO);
- //endregion
- //region 查询当前公司的系统参数 自动办理信息 并赋值
- if (!orderTransmitFlag) {
- Map<String, Object> map = new HashMap<>();
- map.put("cpId", outboundVO.getCpId());
- map.put("code", Constant.SystemConstant.IVT_001.getValue());
- //自动办理标识
- String flgHandleSetting = commonMapper.getSettingValue(map);
- //自动办理标识为1 自动办理入库
- if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) {
- outboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
- outboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue());
- }
- }
- //endregion
- //region 总单
- //出库数量
- BigDecimal sumIntoQty = BigDecimal.ZERO;
- //出库金额
- BigDecimal sumIntoPriceAmt = BigDecimal.ZERO;
- if (orderTransmitFlag) {
- sumIntoQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- sumIntoPriceAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getFactAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //获取 id/单号
- Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
- outboundVO.setOutId(codeMap.get("outId").toString()).
- setOutNo(codeMap.get("outNote").toString());
- //出库类型
- outboundVO.setOutType(Constant.OutType.SALE.getName()).setOutDate(LocalDate.now());
- //自动入库标识
- if (outboundVO.getFlgAutoHandle()) {
- //已出库
- outboundVO.setOutStatus(Constant.OutStatus.YICHUKU.getName());
- } else {
- //出库中
- outboundVO.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
- }
- //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- outboundVO
- .setOutQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
- .setOutAmt(orderTransmitFlag ? sumIntoPriceAmt : outboundVO.getOutingAmt())
- .setOutingQty(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- ;
- } else {
- outboundVO
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO)
- //用于销售订单自动创建出库单
- .setOutingQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
- .setOutingAmt(orderTransmitFlag ? sumIntoPriceAmt : outboundVO.getOutingAmt())
- ;
- }
- //实体转换
- Outbound outbound = outboundConvert.convertToPo(outboundVO);
- outboundMapper.insert(outbound);
- //endregion
- //region 新建多业务归属
- // outCommon.insertMultiOwner(outboundVO);
- //endregion
- //region 销售订单
- //新建销售出库修改销售订单信息
- this.insertOrderMessageByEdit(outboundVO,outboundVO.getItemList());
- //endregion
- BigDecimal factAmt = BigDecimal.ZERO; //总单的实际金额
- //region 明细
- //校验明细
- if (outboundVO.getItemList().size() == 0) {
- throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
- ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
- }
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- outboundItemVO.setItemId(null);
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemVO.setAddOrEditFlag(true);
- if(outboundItemVO.getFromItemId() != null){
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- //总单id
- outboundItemVO.setOutId(outboundVO.getOutId());
- //出库类型
- outboundItemVO.setOutType(outboundVO.getOutType());
- //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- outboundItemVO
- .setOutQty(outboundItemVO.getOutingQty())
- .setOutAmt(outboundItemVO.getOutingAmt())
- .setOutingQty(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- ;
- //todo 2024年6月28日11:15:03 外协品的实际金额和单价 前台传 wyj
- if (outboundItemVO.getSkuId() != null) {
- outboundItemVO.setCostPrice(outboundItemVO.getPriceOut());
- outboundItemVO.setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP));
- }
- } else {
- outboundItemVO
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO);
- }
- factAmt = factAmt.add(outboundItemVO.getFactAmt()); //把明细的 实际金额相加就是总单的
- //出库状态
- outboundItemVO.setOutStatus(outboundVO.getOutStatus());
- //实体转换
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- outboundItemMapper.insert(outboundItem);
- //明细id
- outboundItemVO.setItemId(outboundItem.getItemId());
- //endregion
- //region 销售明细
- if (outboundItemVO.getFromItemId() != null) {
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库原数量+本次数量)
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- orderItem.setOutingQty(BigDecimal.ZERO);
- orderItem.setOutingAmt(BigDecimal.ZERO);
- orderItem.setOutQty(outboundItemVO.getOutQty());
- orderItem.setOutAmt(outboundItemVO.getOutAmt());
- }
- //出库中
- else {
- orderItem.setOutingQty(outboundItemVO.getOutingQty());
- orderItem.setOutingAmt(outboundItemVO.getOutingAmt());
- orderItem.setOutQty(BigDecimal.ZERO);
- orderItem.setOutAmt(BigDecimal.ZERO);
- }
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- //修改
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- Outbound outboundup = new Outbound();
- outboundup.setOutId(outbound.getOutId()).setFactAmt(factAmt);
- //反写总单实际金额
- outboundMapper.update(outboundup,
- new UpdateWrapper<Outbound>().lambda()
- .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //region 已出库 应收记账
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- accountService.accReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 外协品+库存
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- //region 外协品新建外协入库单
- //筛选出skuId为空的 走外协品逻辑
- List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- for (int i = 0; i < outsideGoods.size(); i++) {
- outsideGoods.get(i).setPriceOut(outsideGoods.get(i).getCostPrice() == null ? BigDecimal.ZERO : outsideGoods.get(i).getCostPrice());
- }
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, outsideGoods);
- //新建外协品生产外协入库单
- this.insertOutsideGoodsInto(outboundVO, outsideGoods);
- //endregion
- //region 库存
- //筛选出skuId不为空的 走库存
- List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- if (invList != null && invList.size() > 0) {
- Map<String, Object> invMap = new HashMap<>();
- invMap.put("outDetail", invList);
- inventoryService.operatingInventoryInformation(invMap);
- }
- //endregion
- }
- //endregion
- return ResponseResultUtil.success(outboundVO);
- }
- /**
- * @desc : 新建销售出库修改销售订单信息
- * @date : 2024/6/27 9:27
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void insertOrderMessageByEdit(OutboundVO outboundVO, List<OutboundItemVO> itemList) {
- //出库明细汇总
- Map<String, List<OutboundItemVO>> orderOutItemVOListMap = itemList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- //出库明细汇总循环
- for (String fromId : orderOutItemVOListMap.keySet()) {
- //region 提取新建分组后的明细
- List<OutboundItemVO> orderOutItemVOListGroup = orderOutItemVOListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQty = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- Order order = new Order();
- order.setOrderId(fromId);
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- order.setOutingQty(BigDecimal.ZERO);
- order.setOutingAmt(BigDecimal.ZERO);
- order.setOutQty(orderSumQty);
- order.setOutAmt(orderSumAmt);
- }
- //出库中
- else {
- order.setOutingQty(orderSumQty);
- order.setOutingAmt(orderSumQty);
- order.setOutQty(BigDecimal.ZERO);
- order.setOutAmt(BigDecimal.ZERO);
- }
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- /**
- * @desc : 销售出库编辑
- * @date : 2024/3/25 16:25
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOutboundUpdate(OutboundVO outboundVO) {
- //region 小编辑
- if (!outboundVO.getLimitEdit()) {
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundVO.getOutId());
- outbound.setRemarks(outboundVO.getRemarks());
- outbound.setAnnexPaths(outboundVO.getAnnexPaths());
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda()
- .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemVO.getItemId());
- if (outboundItemVO.getRemarks() != null || outboundItemVO.getRemarks() != " ") {
- outboundItem.setRemarks(outboundItemVO.getRemarks());
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- }
- }
- //endregion
- //region 大编辑
- else {
- // region 更新客户信息
- // outboundVO = outCommon.insertCustomer(outboundVO);
- // endregion
- //region 根据id查询 并且明细数量金额 求和
- OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
- //根据总单id查询
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- //编辑的数据金额汇总 todo 2024年7月11日13:16:38 以前台传过来的数据为主 因为原来明细数据是全给,现在只给改过的数据
- BigDecimal sumQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal sumAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 已出库编辑
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- //region 应收反记账
- if (outboundVO.getReceivableId() != null) {
- accountService.reverseReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- //根据id查询先赋值
- OutboundItemResponse outboundItemResponse = null;
- //region 编辑明细
- if (outboundItemVO.getItemId() != null) {
- //根据id查询 获取到还未进行修改的数据
- outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
- //region 反写订单总单 数据需要 把查出来的已出库数量用别的变量存起来
- outboundItemVO.setUpdateOrderOutQty(outboundItemResponse.getOutQty());
- outboundItemVO.setUpdateOrderOutAmt(outboundItemResponse.getOutAmt());
- //endregion
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- //编辑之前的数
- outboundItemVO.setQtyBeforeUpdate(outboundItemResponse.getOutQty());
- outboundItemVO.setAmtBeforeUpdate(outboundItemResponse.getOutAmt());
- //编辑之后的数
- outboundItemVO.setOutQty(outboundItemVO.getOutingQty());
- outboundItemVO.setOutAmt(outboundItemVO.getOutingAmt());
- outboundItemVO.setAddOrEditFlag(false);
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemVO.getItemId());
- outboundItem.setOutQty(outboundItemVO.getOutingQty());
- outboundItem.setOutAmt(outboundItemVO.getOutingAmt());
- outboundItem.setFactAmt(outboundItemVO.getFactAmt());
- outboundItem.setFactPrice(outboundItemVO.getFactPrice());
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- //endregion
- //region 新建明细
- else {
- outboundItemVO
- .setOutId(outboundItemVO.getOutId())
- .setOutQty(outboundItemVO.getOutingQty())
- .setOutAmt(outboundItemVO.getOutingAmt())
- .setOutingQty(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- .setOutType(Constant.OutType.SALE.getName())
- ;
- //出库状态
- String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
- outboundItemVO.setOutStatus(outStatus);
- //实体转换
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- //新建
- outboundItemMapper.insert(outboundItem);
- outboundItemVO.setItemId(outboundItem.getItemId());
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemVO.setAddOrEditFlag(true);
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- }
- //endregion
- //region 销售明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutQty((outboundItemResponse != null ? outboundItemResponse.getOutQty().negate() : BigDecimal.ZERO).add(outboundItemVO.getOutQty()));
- orderItem.setOutAmt((outboundItemResponse != null ? outboundItemResponse.getOutAmt().negate() : BigDecimal.ZERO).add(outboundItemVO.getOutAmt()));
- orderItem.setOutingQty((outboundItemResponse != null && outboundItemResponse.getOutingQty().compareTo(BigDecimal.ZERO) > 0) ? outboundItemVO.getOutQty().negate() : BigDecimal.ZERO);
- orderItem.setOutingAmt((outboundItemResponse != null && outboundItemResponse.getOutingAmt().compareTo(BigDecimal.ZERO) > 0) ? outboundItemVO.getOutAmt().negate() : BigDecimal.ZERO);
- orderItem.setUpdateOutMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
- if (outboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- outboundItem.setFlgValid(false);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- //region 销售明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutQty(outboundItemVO.getOutQty().negate());
- orderItem.setOutAmt(outboundItemVO.getOutAmt().negate());
- orderItem.setOutingQty(outboundItemVO.getOutQty());
- orderItem.setOutingAmt(outboundItemVO.getOutQty());
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundVO.getOutId());
- outbound.setOutQty(outboundVO.getOutingQty());
- outbound.setOutAmt(outboundVO.getOutingAmt());
- outbound.setAnnexPaths(outboundVO.getAnnexPaths());
- outbound.setFactAmt(outboundVO.getFactAmt());
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售总单
- this.updateOrderMessageByEdit(outboundResponse, outboundVO.getItemList(), outboundVO.getDeleteItemList());
- //endregion
- //region 应收记账
- if (outboundVO.getReceivableId() != null) {
- accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 外协品新建外协入库单
- //筛选出skuId为空的 走外协品逻辑
- List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, outsideGoods);
- //新建外协品生产外协入库单
- this.insertOutsideGoodsInto(outboundVO, outsideGoods);
- if (outboundVO.getDeleteItemList() != null) {
- List<OutboundItemVO> delOutsideGoods = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, delOutsideGoods);
- }
- //endregion
- //region 修改库存
- //筛选出skuId不为空的 走库存
- List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- List<OutboundItemVO> invDelList = null;
- if (outboundVO.getDeleteItemList() != null) {
- invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- }
- if ((invList != null && invList.size() > 0) || (invDelList != null && invDelList.size() > 0)) {
- Map<String, Object> invMap = new HashMap<>();
- invMap.put("outDetail", invList);
- invMap.put("delOutDetail", invDelList);
- inventoryService.operatingInventoryInformation(invMap);
- }
- //endregion
- }
- //endregion
- //region 出库中编辑
- if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundVO.getOutStatus()) ||
- Constant.OutStatus.DAICHUKU.getName().equals(outboundVO.getOutStatus())) {
- //region 修改明细
- List<OutboundItemVO> itemList = outboundVO.getItemList();
- for (OutboundItemVO outboundItemVO : itemList) {
- //根据id查询先赋值 获取到还未进行修改的数据
- OutboundItemResponse outboundItemResponse = null;
- //region 编辑明细
- if (outboundItemVO.getItemId() != null) {
- //根据id查询 获取到还未进行修改的数据
- outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
- //region 反写订单总单 数据需要 把查出来的出库中数量用别的变量存起来
- outboundItemVO.setUpdateOrderOutingQty(outboundItemResponse.getOutingQty());
- outboundItemVO.setUpdateOrderOutingAmt(outboundItemResponse.getOutingAmt());
- //endregion
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemResponse.getItemId());
- outboundItem.setOutingQty(outboundItemVO.getOutingQty());
- outboundItem.setOutingAmt(outboundItemVO.getOutingAmt());
- outboundItem.setWhId(outboundItemVO.getWhId());
- outboundItem.setFactAmt(outboundItemVO.getFactAmt());
- outboundItem.setFactPrice(outboundItemVO.getFactPrice());
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- //endregion
- //region 新建明细
- else {
- outboundItemVO
- .setOutId(outboundItemVO.getOutId())
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO)
- .setOutType(Constant.OutType.SALE.getName())
- ;
- //出库状态
- String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
- outboundItemVO.setOutStatus(outStatus);
- //实体转换
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- //新建
- outboundItemMapper.insert(outboundItem);
- outboundItemVO.setItemId(outboundItem.getItemId());
- }
- //endregion
- //region 销售明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutingQty((outboundItemResponse != null ? outboundItemResponse.getOutingQty().negate() : BigDecimal.ZERO).add(outboundItemVO.getOutingQty()));
- orderItem.setOutingAmt((outboundItemResponse != null ? outboundItemResponse.getOutingAmt().negate() : BigDecimal.ZERO).add(outboundItemVO.getOutingAmt()));
- orderItem.setUpdateOutingMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
- if (outboundItemVO.getItemId() != null) {
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- outboundItem.setFlgValid(false);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- //region 销售明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutingQty(outboundItemVO.getOutQty().negate());
- orderItem.setOutingAmt(outboundItemVO.getOutQty().negate());
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改入库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundVO.getOutId());
- outbound.setOutingQty(outboundVO.getOutingQty());
- outbound.setOutingAmt(outboundVO.getOutingAmt());
- outbound.setAnnexPaths(outboundVO.getAnnexPaths());
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售总单
- this.updateOrderMessageByEdit(outboundResponse, outboundVO.getItemList(), outboundVO.getDeleteItemList());
- //endregion
- }
- //endregion
- }
- //endregion
- return ResponseResultUtil.success(outboundVO);
- }
- /**
- * @desc : 编辑销售出库修改销售订单信息
- * @date : 2024/6/21 10:34
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void updateOrderMessageByEdit(OutboundResponse outboundResponse, List<OutboundItemVO> itemList, List<OutboundItemVO> deleteItemList) {
- //出库明细汇总
- Map<String, List<OutboundItemVO>> orderOutItemVOListMap = itemList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- //出库明细删除汇总
- Map<String, List<OutboundItemVO>> delOrderOutItemVOListMap = deleteItemList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- //出库明细汇总循环
- for (String fromId : orderOutItemVOListMap.keySet()) {
- //有需要删除的修改数据
- if (delOrderOutItemVOListMap != null && delOrderOutItemVOListMap.keySet().size() > 0) {
- //出库明细删除汇总循环
- for (String delFromId : delOrderOutItemVOListMap.keySet()) {
- //新建出库明细来源Id = 删除出库明细来源Id
- if (fromId.equals(delFromId)) {
- //region 提取新建分组后的明细
- List<OutboundItemVO> orderOutItemVOListGroup = orderOutItemVOListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQtying = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmting = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumQty = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //分组后的明细 原出库数量和金额总和
- BigDecimal updateOrderOutQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutAmt = BigDecimal.ZERO;
- BigDecimal updateOrderOutingQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutingAmt = BigDecimal.ZERO;
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- updateOrderOutQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutQty() != null).map(OutboundItemVO::getUpdateOrderOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutAmt() != null).map(OutboundItemVO::getUpdateOrderOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //出库中
- else {
- updateOrderOutingQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingQty() != null).map(OutboundItemVO::getUpdateOrderOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutingAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingAmt() != null).map(OutboundItemVO::getUpdateOrderOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //endregion
- //region 提取删除分组后的明细
- List<OutboundItemVO> delOrderOutItemVOListGroup = delOrderOutItemVOListMap.get(delFromId);
- BigDecimal orderDelOutQty = BigDecimal.ZERO;
- BigDecimal orderDelOutAmt = BigDecimal.ZERO;
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- orderDelOutQty = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- orderDelOutAmt = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //出库中
- else if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus())) {
- orderDelOutQty = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- orderDelOutAmt = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- Order order = new Order();
- order.setOrderId(fromId);
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutQty(orderSumQty.subtract(updateOrderOutQty).subtract(orderDelOutQty));
- order.setOutAmt(orderSumAmt.subtract(updateOrderOutAmt).subtract(orderDelOutAmt));
- // order.setOutingQty(orderDelOutQty);
- // order.setOutingAmt(orderDelOutAmt);
- order.setUpdateOutMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty(),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- }
- //出库中
- else if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutingQty(orderSumQtying.subtract(updateOrderOutingQty).subtract(orderDelOutQty));
- order.setOutingAmt(orderSumAmting.subtract(updateOrderOutingAmt).subtract(orderDelOutAmt));
- order.setUpdateOutingMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
- orderResponse.getOutQty(), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- }
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- }
- //没有需要删除的修改数据
- else {
- //region 提取新建分组后的明细
- List<OutboundItemVO> orderOutItemVOListGroup = orderOutItemVOListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQty = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //分组后的明细 原出库数量和金额总和
- BigDecimal updateOrderOutQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutAmt = BigDecimal.ZERO;
- BigDecimal updateOrderOutingQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutingAmt = BigDecimal.ZERO;
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- updateOrderOutQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutQty() != null).map(OutboundItemVO::getUpdateOrderOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutAmt() != null).map(OutboundItemVO::getUpdateOrderOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //出库中
- else {
- updateOrderOutingQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingQty() != null).map(OutboundItemVO::getUpdateOrderOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutingAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingAmt() != null).map(OutboundItemVO::getUpdateOrderOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- Order order = new Order();
- order.setOrderId(fromId);
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutQty(orderSumQty.subtract(updateOrderOutQty));
- order.setOutAmt(orderSumAmt.subtract(updateOrderOutAmt));
- order.setUpdateOutMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty(),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- }
- //出库中
- else if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutingQty(updateOrderOutingQty.negate());
- order.setOutingAmt(updateOrderOutingAmt.negate());
- order.setUpdateOutingMessageFlag(true);
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
- orderResponse.getOutQty(), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- }
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- }
- /**
- * @desc : 销售出库作废
- * @date : 2024/3/26 9:24
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOutboundRepeal(String outId) {
- //region 查询总单 查询明细
- //根据id查询 此条出库单的数据还未更改前的数据
- OutboundResponse outboundResponse = outboundMapper.selectById(outId);
- //根据总单id查询
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- //endregion
- //region 已出库状态作废
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- //region 应收反记账
- if (outboundResponse.getReceivableId() != null) {
- accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
- //region 将库存需要的参数赋值
- outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
- outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt());
- if (outboundItemResponse.getFromItemId() != null) {
- outboundItemResponse.setInvOrderItemId(outboundItemResponse.getFromItemId());
- }
- //endregion
- //赋值 防止作废的单据查不到明细 故注掉下面代码
- // OutboundItem outboundItem = new OutboundItem();
- // outboundItem.setItemId(outboundItemResponse.getItemId());
- // outboundItem.setFlgValid(false);
- // //修改
- // outboundItemMapper.update(outboundItem,
- // new UpdateWrapper<OutboundItem>().lambda()
- // .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- // );
- //region 销售明细
- if (outboundItemResponse.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemResponse.getFromItemId());
- orderItem.setOutQty(outboundItemResponse.getOutQty().negate());
- orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty(),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(orderOutStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundResponse.getOutId());
- outbound.setFlgValid(false);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售总单
- this.updateOrderMessageByRepeal(outboundResponse, outboundItemResponseList);
- //endregion
- //region 外协品新建外协入库单
- //筛选出skuId为空的 走外协品逻辑
- OutboundVO outboundVO = outboundConvert.convertResToVO(outboundResponse);
- List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, outsideGoodsVOList);
- //endregion
- //region 修改库存
- //筛选出skuId不为空的 走库存
- List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- if (invList != null && invList.size() > 0) {
- Map<String, Object> map = new HashMap<>();
- map.put("delOutDetail", invList);
- inventoryService.operatingInventoryInformation(map);
- }
- //endregion
- }
- //endregion
- //region 出库中、待出库状态作废
- if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus()) ||
- Constant.OutStatus.DAICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- //region 修改明细
- for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
- //region 修改明细
- //赋值
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemResponse.getItemId());
- outboundItem.setOutingQty(BigDecimal.ZERO);
- outboundItem.setOutingAmt(BigDecimal.ZERO);
- // outboundItem.setFlgValid(false);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- //endregion
- //region 销售明细
- if (outboundItemResponse.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemResponse.getFromItemId());
- orderItem.setOutingQty(outboundItemResponse.getOutingQty().negate());
- orderItem.setOutingAmt(outboundItemResponse.getOutingAmt().negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty(), orderItemResponse.getItemQty());
- orderItem.setOutStatus(orderOutStatus);
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundResponse.getOutId());
- outbound.setOutingQty(BigDecimal.ZERO);
- outbound.setOutingAmt(BigDecimal.ZERO);
- outbound.setFlgValid(false);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售总单
- this.updateOrderMessageByRepeal(outboundResponse, outboundItemResponseList);
- //endregion
- }
- //endregion
- return ResponseResultUtil.success();
- }
- /**
- * @desc : 作废销售出库修改销售订单信息
- * @date : 2024/6/21 10:34
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void updateOrderMessageByRepeal(OutboundResponse outboundResponse, List<OutboundItemResponse> itemList) {
- //出库明细汇总
- Map<String, List<OutboundItemResponse>> orderOutItemListMap = itemList.stream().collect(Collectors.groupingBy(OutboundItemResponse::getFromId));
- //出库明细汇总循环
- for (String fromId : orderOutItemListMap.keySet()) {
- //region 提取新建分组后的明细
- //分组后的明细 原出库数量和金额总和
- List<OutboundItemResponse> orderOutItemListGroup = orderOutItemListMap.get(fromId);
- BigDecimal updateOrderOutQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutAmt = BigDecimal.ZERO;
- BigDecimal updateOrderOutingQty = BigDecimal.ZERO;
- BigDecimal updateOrderOutingAmt = BigDecimal.ZERO;
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- updateOrderOutQty = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutAmt = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //出库中
- else {
- updateOrderOutingQty = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- updateOrderOutingAmt = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- }
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- Order order = new Order();
- order.setOrderId(fromId);
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutQty(updateOrderOutQty.negate());
- order.setOutAmt(updateOrderOutAmt.negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty(),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(orderOutStatus);
- }
- //出库中
- else if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus())) {
- order.setOutingQty(updateOrderOutingQty.negate());
- order.setOutingAmt(updateOrderOutingAmt.negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
- orderResponse.getOutQty(), orderResponse.getSumQuantity());
- order.setOutStatus(orderOutStatus);
- }
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- /**
- * @desc : 销售出库办理
- * @date : 2024/3/7 15:47
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOrderHandleOutbound(OutboundVO outboundVO) {
- //region 根据id查询 此条入库单的数据还未更改前的数据
- OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
- //endregion
- //region 应收反记账
- if (outboundResponse.getReceivableId() != null) {
- accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 编辑明细
- //校验明细
- if (outboundVO.getItemList().size() == 0) {
- throw new BaseBusinessException(ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getCode(),
- ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
- }
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
- //明细根据id查询
- OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
- //region 校验数量是否超出
- if (outboundItemVO.getOutingQty().compareTo(outboundItemResponse.getOutingQty()) > 0) {
- throw new BaseBusinessException(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getCode(),
- ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITYIN_THE_WAREHOUSE.getMessage());
- }
- //endregion
- //region 反写订单总单 数据需要 把查出来的出库中数量用别的变量存起来
- outboundItemVO.setUpdateOrderOutingQty(outboundItemResponse.getOutingQty());
- outboundItemVO.setUpdateOrderOutingAmt(outboundItemResponse.getOutingAmt());
- //endregion
- //region 编辑明细
- if (outboundItemVO.getItemId() != null) {
- outboundItemVO
- .setOutQty(outboundItemVO.getOutingQty())
- .setOutBox(outboundItemVO.getOutingBox()).setOutPiece(outboundItemVO.getOutingPiece())
- .setOutAmt(outboundItemVO.getOutingAmt())
- .setOutingQty(BigDecimal.ZERO).setOutingBox(0).setOutingPiece(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- ;
- //出库状态
- String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
- outboundItemVO.setOutStatus(outStatus);
- //实体转换
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- //编辑之前的数
- if (outboundItemResponse.getOutQty().compareTo(BigDecimal.ZERO) > 0) {
- outboundItemVO.setQtyBeforeUpdate(outboundItemResponse.getOutQty());
- outboundItemVO.setAmtBeforeUpdate(outboundItemResponse.getOutAmt());
- }
- outboundItemVO.setAddOrEditFlag(true);
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- }
- //endregion
- //region 新建明细
- else {
- outboundItemVO
- .setOutId(outboundItemVO.getOutId())
- .setOutQty(outboundItemVO.getOutingQty())
- .setOutBox(outboundItemVO.getOutingBox()).setOutPiece(outboundItemVO.getOutingPiece())
- .setOutAmt(outboundItemVO.getOutingAmt())
- .setOutType(Constant.OutType.SALE.getName())
- .setOutingQty(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- ;
- //出库状态
- String outStatus = this.setOutStatus(outboundItemVO.getOutingQty(), outboundItemVO.getOutQty());
- outboundItemVO.setOutStatus(outStatus);
- //实体转换
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- //新建
- outboundItemMapper.insert(outboundItem);
- outboundItemVO.setItemId(outboundItem.getItemId());
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemVO.setAddOrEditFlag(true);
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- }
- //endregion
- //region 销售订单明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutingQty(outboundItemVO.getOutQty().negate());
- orderItem.setOutingAmt(outboundItemVO.getOutAmt().negate());
- orderItem.setOutQty(outboundItemVO.getOutQty());
- orderItem.setOutAmt(outboundItemVO.getOutAmt());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderItemResponse.getOutingQty().subtract(outboundItemVO.getOutQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(orderOutStatus);
- //修改
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
- if (outboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- if (outboundItemVO.getFromItemId() != null) {
- outboundItemVO.setInvOrderItemId(outboundItemVO.getFromItemId());
- }
- //endregion
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
- outboundItem.setFlgValid(false);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- }
- //region 销售订单明细
- if (outboundItemVO.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemVO.getFromItemId());
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemVO.getFromItemId());
- orderItem.setOutingQty(outboundItemVO.getOutingQty().negate());
- orderItem.setOutingAmt(outboundItemVO.getOutingAmt().negate());
- orderItem.setOutQty(outboundItemVO.getOutQty().negate());
- orderItem.setOutAmt(outboundItemVO.getOutAmt().negate());
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().subtract(orderItem.getOutingQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- //修改
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 编辑总单
- BigDecimal sumOutQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal sumOutAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- outboundVO.setOutQty(sumOutQty);
- outboundVO.setOutAmt(sumOutAmt);
- outboundVO.setOutingQty(BigDecimal.ZERO);
- outboundVO.setOutingAmt(BigDecimal.ZERO);
- //出库状态
- String outStatus = this.setOutStatus(outboundVO.getOutingQty(), outboundVO.getOutQty());
- outboundVO.setOutStatus(outStatus);
- //实体转换
- Outbound outbound = outboundConvert.convertToPo(outboundVO);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda()
- .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售订单订单
- this.updateOrderMessageByHandle(outboundVO.getItemList(), outboundVO.getDeleteItemList());
- //endregion
- //region 应收记账
- accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- //endregion
- //region 库存明细处理
- if (outboundVO.getItemList() != null && outboundVO.getItemList().size() > 0) {
- Map<String, Object> map = new HashMap<>(); // 定义map值 修改库存用
- // 获取外协数据
- List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- //新建外协品生产外协入库单
- this.insertOutsideGoodsInto(outboundVO, outsideGoods);
- // 获取商品明细数据
- List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- // 赋值修改明细
- map.put("outDetail", invList);
- // 删除的商品
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- // 获取外协删除数据
- List<OutboundItemVO> invsideDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, invsideDelList);
- // 获取删除商品数据
- List<OutboundItemVO> invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- // 赋值删除明细
- map.put("delOutDetail", invDelList);
- }
- // 调用修改库存信息方法
- inventoryService.operatingInventoryInformation(map);
- }
- //endregion
- return ResponseResultUtil.success(outboundVO);
- }
- /**
- * @desc : 办理销售出库修改销售订单信息
- * @date : 2024/6/21 15:13
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void updateOrderMessageByHandle(List<OutboundItemVO> itemList, List<OutboundItemVO> deleteItemList) {
- //出库明细汇总
- Map<String, List<OutboundItemVO>> orderOutItemVOListMap = itemList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- //出库明细删除汇总
- Map<String, List<OutboundItemVO>> delOrderOutItemVOListMap = deleteItemList.stream().collect(Collectors.groupingBy(OutboundItemVO::getFromId));
- //出库明细汇总循环
- for (String fromId : orderOutItemVOListMap.keySet()) {
- //有需要删除的办理数据
- if (delOrderOutItemVOListMap != null && delOrderOutItemVOListMap.keySet().size() > 0) {
- //出库明细删除汇总循环
- for (String delFromId : delOrderOutItemVOListMap.keySet()) {
- //新建出库明细来源Id = 删除出库明细来源Id
- if (fromId.equals(delFromId)) {
- //region 提取新建分组后的明细
- List<OutboundItemVO> orderOutItemVOListGroup = orderOutItemVOListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQty = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //分组后的明细 原出库数量和金额总和
- BigDecimal updateOrderOutingQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingQty() != null).map(OutboundItemVO::getUpdateOrderOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal updateOrderOutingAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingAmt() != null).map(OutboundItemVO::getUpdateOrderOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 提取删除分组后的明细
- List<OutboundItemVO> delOrderOutItemVOListGroup = delOrderOutItemVOListMap.get(delFromId);
- BigDecimal orderDelOutingQty = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderDelOutingAmt = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderDelOutQty = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderDelOutAmt = delOrderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Order order = new Order();
- order.setOrderId(fromId);
- order.setOutQty(orderSumQty.subtract(orderDelOutQty));
- order.setOutAmt(orderSumAmt.subtract(orderDelOutAmt));
- order.setOutingQty((updateOrderOutingQty.add(orderDelOutingQty)).negate());
- order.setOutingAmt((updateOrderOutingAmt.add(orderDelOutingAmt)).negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().subtract(orderSumQty).add(orderDelOutQty),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(orderOutStatus);
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- }
- //没有需要删除的办理数据
- else {
- //region 提取新建分组后的明细
- List<OutboundItemVO> orderOutItemVOListGroup = orderOutItemVOListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQty = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //分组后的明细 原出库数量和金额总和
- BigDecimal updateOrderOutingQty = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingQty() != null).map(OutboundItemVO::getUpdateOrderOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal updateOrderOutingAmt = orderOutItemVOListGroup.stream().filter(it -> it.getUpdateOrderOutingAmt() != null).map(OutboundItemVO::getUpdateOrderOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Order order = new Order();
- order.setOrderId(fromId);
- order.setOutQty(orderSumQty);
- order.setOutAmt(orderSumAmt);
- order.setOutingQty(updateOrderOutingQty.negate());
- order.setOutingAmt(updateOrderOutingAmt.negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().subtract(orderSumQty),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(orderOutStatus);
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- }
- /**
- * @desc : 销售出库撤销
- * @date : 2024/3/7 17:06
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOrderOutboundCancel(OutboundVO outboundVO) {
- //region 查询出库总单数据信息
- OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
- //endregion
- //region根据总单id查明细
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- //endregion
- //region 应收反记账
- if (outboundResponse.getReceivableId() != null) {
- accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改订单数据信息
- this.updateOrderMessageByCancel(outboundItemResponseList);
- //endregion
- //region 修改总单数据信息
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundResponse.getOutId());
- outbound.setOutDate(null);
- outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
- outbound.setOutQty(BigDecimal.ZERO);
- outbound.setOutAmt(BigDecimal.ZERO);
- outbound.setOutingQty(outboundResponse.getOutingQty().add(outboundResponse.getOutQty()));
- outbound.setOutingAmt(outboundResponse.getOutingAmt().add(outboundResponse.getOutAmt()));
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda()
- .eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 明细数据
- for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
- //region 修改销售订单明细数据信息
- if (outboundItemResponse.getFromItemId() != null) {
- //根据id查询
- OrderItemResponse orderItemResponse = orderItemMapper.selectById(outboundItemResponse.getFromItemId());
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- OrderItem orderItem = new OrderItem();
- orderItem.setItemId(outboundItemResponse.getFromItemId());
- orderItem.setOutQty(outboundItemResponse.getOutQty().negate());
- orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate());
- orderItem.setOutingQty(outboundItemResponse.getOutQty());
- orderItem.setOutingAmt(outboundItemResponse.getOutAmt());
- //出库状态
- String outStatus = this.setOutStatus(orderItemResponse.getOutingQty().add(orderItem.getOutingQty()),
- orderItemResponse.getOutQty().add(orderItem.getOutQty()), orderItemResponse.getItemQty());
- orderItem.setOutStatus(outStatus);
- //修改
- int countRow = orderItemMapper.updateById(orderItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.UPDATE_ORDER_ERROR.getMessage());
- }
- }
- //endregion
- //region修改出库明细信息
- OutboundItem outboundItem = new OutboundItem();
- //region 将库存需要的参数赋值
- outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
- outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
- if (outboundItemResponse.getFromItemId() != null) {
- outboundItemResponse.setInvOrderItemId(outboundItemResponse.getFromItemId());
- }
- //endregion
- outboundItem
- .setOutId(outboundResponse.getOutId())
- .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
- .setOutingQty(outboundItemResponse.getOutingQty().add(outboundItemResponse.getOutQty()))
- .setOutAmt(outboundItemResponse.getOutingAmt().add(outboundItemResponse.getOutAmt()))
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO)
- .setCostPrice(BigDecimal.ZERO)
- .setCostAmt(BigDecimal.ZERO)
- .setItemId(outboundItemResponse.getItemId());
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- //endregion
- }
- //endregion
- //region 外协品新建外协入库单
- //筛选出skuId为空的 走外协品逻辑
- OutboundVO outsideGoodVO = outboundConvert.convertResToVO(outboundResponse);
- List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outsideGoodVO, outsideGoodsVOList);
- //endregion
- //region 调用库存
- //筛选出skuId不为空的 走库存
- List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- if (invList != null && invList.size() > 0) {
- Map<String, Object> map = new HashMap<>();
- map.put("delOutDetail", invList);
- inventoryService.operatingInventoryInformation(map);
- }
- //endregion
- return ResponseResultUtil.success();
- }
- /**
- * @desc : 撤销销售出库修改销售订单信息
- * @date : 2024/6/21 16:00
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public void updateOrderMessageByCancel(List<OutboundItemResponse> itemList) {
- //出库明细汇总
- Map<String, List<OutboundItemResponse>> orderOutItemListMap = itemList.stream().collect(Collectors.groupingBy(OutboundItemResponse::getFromId));
- //出库明细汇总循环
- for (String fromId : orderOutItemListMap.keySet()) {
- //region 提取新建分组后的明细
- List<OutboundItemResponse> orderOutItemListGroup = orderOutItemListMap.get(fromId);
- //分组后的明细 出库数量和金额总和
- BigDecimal orderSumQty = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal orderSumAmt = orderOutItemListGroup.stream().map(OutboundItemResponse::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- //endregion
- //region 反写订单数据
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(fromId);
- Order order = new Order();
- order.setOrderId(fromId);
- order.setOutingQty(orderSumQty);
- order.setOutingAmt(orderSumAmt);
- order.setOutQty(orderSumQty.negate());
- order.setOutAmt(orderSumAmt.negate());
- //出库状态
- String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
- orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
- order.setOutStatus(outStatus);
- //修改
- int countRow = orderMapper.updateById(order);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- //endregion
- }
- }
- /**
- * @desc : 销售出库一键作废
- * @date : 2024/7/1 13:29
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> oneKeySaleOutboundRepeal(String orderId) {
- List<OutboundItemResponse> outboundItemResponses = outboundItemMapper.selectByCond(new OutboundItemQuery().setFromId(orderId));
- if (outboundItemResponses != null && outboundItemResponses.size() > 0) {
- Map<String, List<OutboundItemResponse>> outboundItemVOMap = outboundItemResponses.stream().collect(Collectors.groupingBy(OutboundItemResponse::getOutId));
- for (String str : outboundItemVOMap.keySet()) {
- //region 查询总单 查询明细
- //根据id查询 此条出库单的数据还未更改前的数据
- OutboundResponse outboundResponse = outboundMapper.selectById(str);
- //根据总单id查询
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- //endregion
- //region 已出库状态作废
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- //region 应收反记账
- if (outboundResponse.getReceivableId() != null) {
- accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
- //region 将库存需要的参数赋值
- outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
- outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt());
- if (outboundItemResponse.getFromItemId() != null) {
- outboundItemResponse.setInvOrderItemId(outboundItemResponse.getFromItemId());
- }
- //endregion
- //赋值 防止作废的单据查不到明细 故注掉下面代码
- // OutboundItem outboundItem = new OutboundItem();
- // outboundItem.setItemId(outboundItemResponse.getItemId());
- // outboundItem.setFlgValid(false);
- // //修改
- // outboundItemMapper.update(outboundItem,
- // new UpdateWrapper<OutboundItem>().lambda()
- // .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- // );
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundResponse.getOutId());
- outbound.setFlgValid(false);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 外协品新建外协入库单
- //筛选出skuId为空的 走外协品逻辑
- OutboundVO outboundVO = outboundConvert.convertResToVO(outboundResponse);
- List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
- List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
- //删除外协品生产外协入库单
- this.deleteOutsideGoodsInto(outboundVO, outsideGoodsVOList);
- //endregion
- //region 修改库存
- //筛选出skuId不为空的 走库存
- List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
- if (invList != null && invList.size() > 0) {
- Map<String, Object> map = new HashMap<>();
- map.put("delOutDetail", invList);
- inventoryService.operatingInventoryInformation(map);
- }
- //endregion
- }
- //endregion
- //region 出库中、待出库状态作废
- if (Constant.OutStatus.CHUKUZHONG.getName().equals(outboundResponse.getOutStatus()) ||
- Constant.OutStatus.DAICHUKU.getName().equals(outboundResponse.getOutStatus())) {
- //region 修改明细
- for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
- //region 修改明细
- //赋值
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemResponse.getItemId());
- outboundItem.setOutingQty(BigDecimal.ZERO);
- outboundItem.setOutingAmt(BigDecimal.ZERO);
- // outboundItem.setFlgValid(false);
- //修改
- outboundItemMapper.update(outboundItem,
- new UpdateWrapper<OutboundItem>().lambda()
- .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
- );
- //endregion
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundResponse.getOutId());
- outbound.setOutingQty(BigDecimal.ZERO);
- outbound.setOutingAmt(BigDecimal.ZERO);
- outbound.setFlgValid(false);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- }
- //endregion
- }
- }
- return ResponseResultUtil.success();
- }
- /**
- * @desc : 出库状态通用(目前本页面)
- * @date : 2024/3/9 8:59
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public String setOutStatus(BigDecimal outingQty, BigDecimal outQty) {
- //出库状态
- String outStatus = null;
- //已出库数量>0 出库中数量>0
- if (outQty.compareTo(BigDecimal.ZERO) >= 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
- //出库中
- outStatus = Constant.OutStatus.CHUKUZHONG.getName();
- }
- //出入库数量=0 出库中数量=0
- else if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
- //待出库
- outStatus = Constant.OutStatus.DAICHUKU.getName();
- }
- //已出库数量>0 出库中数量=0
- else if (outQty.compareTo(BigDecimal.ZERO) > 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
- //已出库
- outStatus = Constant.OutStatus.YICHUKU.getName();
- }
- return outStatus;
- }
- /**
- * @desc : 上游单据入库状态通用(目前本页面)
- * @date : 2024/4/1 17:14
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public String setOutStatus(BigDecimal intoingQty, BigDecimal intoQty, BigDecimal sumQty) {
- //出库状态
- String outStatus = null;
- //出库中小于等于总数,已出库小于总数,并且出库中+已出库大于0
- if (intoingQty.compareTo(sumQty) <= 0 && intoQty.compareTo(sumQty) < 0 && intoingQty.add(intoQty).compareTo(BigDecimal.ZERO) > 0) {
- //出库中
- outStatus = Constant.OutStatus.CHUKUZHONG.getName();
- }
- //已出库数量=0 出库中数量=0
- else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
- //待出库
- outStatus = Constant.OutStatus.DAICHUKU.getName();
- }
- //出库中+已出库 等于 总数 并且 出库中数量小于等于订单总数量
- else if (intoingQty.compareTo(sumQty) < 0 && intoingQty.add(intoQty).compareTo(sumQty) == 0) {
- //已出库
- outStatus = Constant.OutStatus.YICHUKU.getName();
- }
- return outStatus;
- }
- /**
- * @desc : 获取单据信息(编辑用)
- * @date : 2024/3/16 16:28
- * @author : 寇珊珊
- */
- public ResponseResultVO<?> selectByUpdate(String id) {
- Map<String, Object> dataInfo = new HashMap<>();
- //总单
- OutboundResponse outboundResponse = outboundMapper.selectMessageByOtherQuery(new OutboundQuery().setOutId(id).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName()));
- //单据不存在
- if (outboundResponse == null) {
- throw new BaseBusinessException(ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getCode(),
- ErrorCodeEnum.THERE_ORDER_IS_NOT_CAN_OUTBOUND_QUANTITY.getMessage());
- }
- dataInfo.put("data", outboundResponse);
- // 明细
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- dataInfo.put("dataItem", outboundItemResponseList);
- return ResponseResultUtil.success(dataInfo);
- }
- /********************************************** 销售出库查询相关方法begin *************************************/
- /**
- * @desc : 一览页销售出库
- * @author : 付斌
- * @date : 2023/1/9 10:40
- */
- @Pagination
- public ResponseResultVO<PageList<OutboundResponse>> selectByCond(OutboundQuery outboundQuery) {
- outboundQuery.setOutType(Constant.OutType.SALE.getName());
- return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
- outboundMapper.countByCond(outboundQuery));
- }
- /**
- * @desc : 一览页销售出库明细(货物、附件)
- * @author : 付斌
- * @date : 2024-02-28 13:25
- */
- @Pagination
- public ResponseResultVO<Map<String, Object>> selectOutboundInfoById(String id) {
- Map<String, Object> result = new HashMap<>();
- // 商品明细
- List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
- result.put("outboundItem", outboundItem);
- // 附件
- return ResponseResultUtil.success(result);
- }
- /**
- * @desc : 获取销售出库信息(编辑用)
- * @author : 付斌
- * @date : 2024-03-02 17:27
- */
- public ResponseResultVO<?> getOutboundForUpdate(String id) {
- Map<String, Object> dataInfo = new HashMap<>();
- OutboundResponse outboundResponse = outboundMapper.selectById(id);
- dataInfo.put("data", outboundResponse);
- // 商品明细
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEdit(id);
- dataInfo.put("dataItem", outboundItemResponseList);
- return ResponseResultUtil.success(dataInfo);
- }
- /**
- * @desc : 获取销售出库信息(编辑用,适用于直接新建的出库单)
- * @author : 付斌
- * @date : 2024-03-02 17:27
- */
- public ResponseResultVO<?> getOutboundTogetherForUpdate(String id) {
- Map<String, Object> dataInfo = new HashMap<>();
- OutboundResponse outboundResponse = outboundMapper.selectById(id);
- dataInfo.put("data", outboundResponse);
- // 商品明细
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEditTogether(id);
- dataInfo.put("dataItem", outboundItemResponseList);
- return ResponseResultUtil.success(dataInfo);
- }
- /**
- * @desc : 获取出库信息(新建退货用)
- * @author : 付斌
- * @date : 2024-03-02 17:27
- */
- public ResponseResultVO<?> getOutForReturn(String id) {
- OutboundResponse outboundResponse = outboundMapper.selectByIdForReturn(id);
- List<OutboundItemResponse> outboundItemList = outboundItemMapper.selectByCondForReturn(new OutboundItemQuery().setOutId(id));
- if (outboundItemList != null && outboundItemList.size() > 0) {
- // 求和
- OutboundItemResponse sumEntity = outboundItemList.stream().reduce((x, y) -> {
- OutboundItemResponse item = new OutboundItemResponse();
- item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
- item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
- return item;
- }).get();
- outboundResponse.setOutingQty(sumEntity.getOutingQty()).setOutingAmt(sumEntity.getOutingAmt());
- }
- Map<String, Object> dataInfo = new HashMap<>();
- dataInfo.put("data", outboundResponse);
- dataInfo.put("dataItem", outboundItemList);
- return ResponseResultUtil.success(dataInfo);
- }
- /**
- * @desc : 查询出库明细(货物、附件)
- * @author : 付斌
- * @date : 2024-02-28 13:25
- */
- @Pagination
- public ResponseResultVO selectById(String id) {
- OutboundResponse outboundResponse = outboundMapper.selectById(id);
- // 商品明细
- List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
- outboundResponse.setGoodsList(outboundItem);
- // 附件
- return ResponseResultUtil.success(outboundResponse);
- }
- /********************************************** 销售出库查询相关方法end *************************************/
- // /**
- // * @desc : 条件查询
- // * @date : 2024/3/18 11:20
- // * @author : 寇珊珊
- // */
- // @Pagination
- // public ResponseResultVO<PageList<InboundResponse>> selectByCond(OutboundQuery outboundQuery) {
- // return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
- // outboundMapper.countByCond(outboundQuery));
- // }
- //
- // /**
- // * @desc : 查询明细
- // * @date : 2024/3/15 16:43
- // * @author : 寇珊珊
- // */
- // @Pagination
- // public ResponseResultVO<Map<String, Object>> selectOutBoundSaleOrderItemInfoById(String id) {
- // Map<String, Object> result = new HashMap<>();
- // // 商品明细
- // List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
- // result.put("itemList", outboundItemResponseList);
- // // 收款
- //
- // // 附件
- // return ResponseResultUtil.success(result);
- // }
- /**
- * @desc : 条件查询(总单带明细)
- * @author : 于继渤
- * @date : 2023/1/9 10:36
- */
- @Pagination
- public ResponseResultVO<PageList<OutboundResponse>> selectByCondDetail(OutboundQuery outboundQuery) {
- return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCondDetail(outboundQuery),
- outboundMapper.countByCondDetail(outboundQuery));
- }
- }
|