| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674 |
- 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.InboundItemMapper;
- import com.dk.mdm.mapper.ivt.InboundMapper;
- import com.dk.mdm.mapper.ivt.OutboundItemMapper;
- import com.dk.mdm.mapper.ivt.OutboundMapper;
- import com.dk.mdm.mapper.mst.CustomerMapper;
- import com.dk.mdm.mapper.sale.MultiOwnerMapper;
- 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.mst.Customer;
- import com.dk.mdm.model.pojo.pur.Purchase;
- import com.dk.mdm.model.pojo.pur.PurchaseItem;
- import com.dk.mdm.model.pojo.sale.MultiOwner;
- import com.dk.mdm.model.pojo.sale.Order;
- import com.dk.mdm.model.pojo.sale.OrderItem;
- import com.dk.mdm.model.query.ivt.OutboundItemQuery;
- import com.dk.mdm.model.query.ivt.OutboundQuery;
- import com.dk.mdm.model.query.sale.OrderQuery;
- import com.dk.mdm.model.response.ivt.InboundResponse;
- import com.dk.mdm.model.response.ivt.OutboundItemResponse;
- import com.dk.mdm.model.response.ivt.OutboundResponse;
- import com.dk.mdm.model.response.pur.PurchaseItemResponse;
- import com.dk.mdm.model.response.pur.PurchaseResponse;
- 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.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;
- /**
- * @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::getOutId));
- 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).getOutId());
- //外协入库明细
- inboundItemMapper.deleteItemByFromId(outboundItemVOList.get(0).getOutId());
- }
- }
- /**
- * @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(sumIntoAmt)
- .setIntoAmt(sumIntoQty)
- .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());
- //实体转换
- 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());
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
- inboundItemVO
- .setPriceInto(outboundItemVO.getPriceOut())
- .setIntoQty(outboundItemVO.getOutQty())
- .setIntoAmt(outboundItemVO.getOutQty())
- .setIntoingQty(BigDecimal.ZERO)
- .setIntoingAmt(BigDecimal.ZERO)
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- //入库状态
- 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());
- //实体转换
- 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 : 销售出库新建
- * @date : 2024/3/7 14:13
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> saleOrderOutboundInsert(OutboundVO outboundVO) {
- //region 如果没有客户id,要新建
- // if (outboundVO.getCusId() == null) {
- //
- // }
- outboundVO = outCommon.insertCustomer(outboundVO);
- //endregion
- //region 查询当前公司的系统参数 自动办理信息 并赋值
- 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 总单
- //获取 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());
- //自动入库标识
- 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(outboundVO.getOutingQty())
- .setOutAmt(outboundVO.getOutingAmt())
- .setOutingQty(BigDecimal.ZERO)
- .setOutingAmt(BigDecimal.ZERO)
- ;
- } else {
- outboundVO
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO)
- ;
- }
- //实体转换
- Outbound outbound = outboundConvert.convertToPo(outboundVO);
- outboundMapper.insert(outbound);
- //endregion
- //region 新建多业务归属
- outCommon.insertMultiOwner(outboundVO);
- //endregion
- //region 销售订单
- if (outboundVO.getFromId() != null) {
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Order order = new Order();
- order.setOrderId(outboundVO.getFromId());
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
- //已出库
- if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
- order.setOutingQty(BigDecimal.ZERO);
- order.setOutingAmt(BigDecimal.ZERO);
- order.setOutQty(outboundVO.getOutQty());
- order.setOutAmt(outboundVO.getOutAmt());
- }
- //出库中
- else {
- order.setOutingQty(outboundVO.getOutingQty());
- order.setOutingAmt(outboundVO.getOutingAmt());
- 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
- //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()) {
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- outboundItemVO.setAddOrEditFlag(true);
- //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)
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- } else {
- outboundItemVO
- .setOutQty(BigDecimal.ZERO)
- .setOutAmt(BigDecimal.ZERO);
- }
- //入库状态
- 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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //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());
- //删除外协品生产外协入库单
- 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/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 根据id查询 并且明细数量金额 求和
- OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
- 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 自动办理参数为true 已入库编辑
- //自动办理参数为true
- if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundVO.getFlgHandleSetting())) {
- //region 应收反记账
- if (outboundVO.getReceivableId() != null) {
- accountService.reverseReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改明细
- List<OutboundItemVO> itemList = outboundVO.getItemList();
- for (OutboundItemVO outboundItemVO : itemList) {
- //根据id查询
- OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
- //region 编辑明细
- if (outboundItemVO.getItemId() != null) {
- //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);
- //endregion
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemVO.getItemId());
- outboundItem.setOutQty(outboundItemVO.getOutingQty());
- outboundItem.setOutAmt(outboundItemVO.getOutingAmt());
- outboundItem.setCostPrice(outboundItemVO.getPriceOut());
- outboundItem.setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(6, BigDecimal.ROUND_HALF_UP));
- //修改
- 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)
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- .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);
- //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.getOutQty().negate().add(outboundItemVO.getOutingQty()));
- orderItem.setOutAmt(outboundItemResponse.getOutAmt().negate().add(outboundItemVO.getOutingAmt()));
- orderItem.setOutingQty(outboundItemVO.getOutQty());
- orderItem.setOutingAmt(outboundItemVO.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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delOutQty = BigDecimal.ZERO;
- BigDecimal delOutAmt = BigDecimal.ZERO;
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
- if (outboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- //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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改出库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundVO.getOutId());
- outbound.setOutQty(sumQty);
- outbound.setOutAmt(sumAmt);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改销售总单
- if (outboundVO.getFromId() != null) {
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
- Order order = new Order();
- order.setOrderId(outboundVO.getFromId());
- order.setOutQty(outboundResponse.getOutQty().negate().add(sumQty).subtract(delOutQty));
- order.setOutAmt(outboundResponse.getOutAmt().negate().add(sumAmt).subtract(delOutAmt));
- order.setOutingQty(delOutQty);
- order.setOutingAmt(delOutAmt);
- //出库状态
- 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
- //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);
- 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 = 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
- } else {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_OUT.getMessage());
- }
- //endregion
- //region 自动办理参数false 入库中编辑
- //自动办理标识为false 并且 自动办理参数为false 入库中
- if (!outboundVO.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(outboundVO.getFlgHandleSetting())) {
- //region 修改明细
- List<OutboundItemVO> itemList = outboundVO.getItemList();
- for (OutboundItemVO outboundItemVO : itemList) {
- //根据id查询 获取到还未进行修改的数据
- OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVO.getItemId());
- //region 编辑明细
- if (outboundItemVO.getItemId() != null) {
- OutboundItem outboundItem = new OutboundItem();
- outboundItem.setItemId(outboundItemResponse.getItemId());
- outboundItem.setOutingQty(outboundItemResponse.getOutingQty());
- outboundItem.setOutingAmt(outboundItemResponse.getOutingAmt());
- //修改
- 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)
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutingQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- .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.getOutingQty().negate().add(outboundItemVO.getOutingQty()));
- orderItem.setOutingAmt(outboundItemResponse.getOutingAmt().negate().add(outboundItemVO.getOutingAmt()));
- //出库状态
- 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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delOutQty = BigDecimal.ZERO;
- BigDecimal delOutAmt = BigDecimal.ZERO;
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- 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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- }
- //endregion
- //region 修改入库总单
- Outbound outbound = new Outbound();
- outbound.setOutId(outboundVO.getOutId());
- outbound.setOutingQty(sumQty);
- outbound.setOutingAmt(sumAmt);
- //修改
- outboundMapper.update(outbound,
- new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
- );
- //endregion
- //region 修改采购总单
- if (outboundVO.getFromId() != null) {
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
- Order order = new Order();
- order.setOrderId(outboundVO.getFromId());
- order.setOutingQty(outboundResponse.getOutingQty().negate().add(sumQty).subtract(delOutQty));
- order.setOutingAmt(outboundResponse.getOutingAmt().negate().add(sumAmt).subtract(delOutAmt));
- //出库状态
- 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 {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_OUT.getMessage());
- }
- //endregion
- }
- //endregion
- return ResponseResultUtil.success(outboundVO);
- }
- /**
- * @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().negate());
- outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt().negate());
- //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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.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 修改销售总单
- if (outboundResponse.getFromId() != null) {
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
- Order order = new Order();
- order.setOrderId(outboundResponse.getFromId());
- order.setOutQty(outboundResponse.getOutQty().negate());
- order.setOutAmt(outboundResponse.getOutAmt().negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty(),
- 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
- //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
- } else {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_OUT.getMessage());
- }
- //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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.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 修改销售总单
- if (outboundResponse.getFromId() != null) {
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
- Order order = new Order();
- order.setOrderId(outboundResponse.getFromId());
- order.setOutingQty(outboundResponse.getOutingQty().negate());
- order.setOutingAmt(outboundResponse.getOutingAmt().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
- } else {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_OUT.getMessage());
- }
- //endregion
- return ResponseResultUtil.success();
- }
- /**
- * @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 编辑明细
- if (outboundItemVO.getItemId() != null) {
- outboundItemVO
- .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
- .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
- .setOutingQty(outboundItemResponse.getOutingQty().subtract(outboundItemVO.getOutingQty()))
- .setOutingAmt(outboundItemResponse.getOutingAmt().subtract(outboundItemVO.getOutingAmt()))
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- ;
- //出库状态
- 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);
- //endregion
- }
- //endregion
- //region 新建明细
- else {
- outboundItemVO
- .setOutId(outboundItemVO.getOutId())
- .setOutQty(outboundItemVO.getOutingQty())
- .setOutAmt(outboundItemVO.getOutingAmt())
- .setCostPrice(outboundItemVO.getPriceOut())
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
- .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);
- //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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal delOutingQty = BigDecimal.ZERO;
- BigDecimal delOutingAmt = BigDecimal.ZERO;
- BigDecimal delOutQty = BigDecimal.ZERO;
- BigDecimal delOutAmt = BigDecimal.ZERO;
- if (outboundVO.getDeleteItemList() != null && outboundVO.getDeleteItemList().size() > 0) {
- delOutingQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delOutingAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- delOutQty = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- delOutAmt = outboundVO.getDeleteItemList().stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- for (OutboundItemVO outboundItemVO : outboundVO.getDeleteItemList()) {
- if (outboundItemVO.getItemId() != null) {
- //region 将库存需要的参数赋值
- outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
- outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
- //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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.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 修改销售订单订单
- if (outboundVO.getFromId() != null) {
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
- //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Order order = new Order();
- order.setOrderId(outboundVO.getFromId());
- order.setOutQty(sumOutQty.subtract(delOutQty));
- order.setOutAmt(sumOutAmt.subtract(delOutAmt));
- order.setOutingQty((outboundResponse.getOutingQty().add(delOutingQty)).negate());
- order.setOutingAmt((outboundResponse.getOutingAmt().add(delOutingAmt)).negate());
- //出库状态
- String orderOutStatus = this.setOutStatus(orderResponse.getOutingQty().subtract(sumOutQty).add(delOutQty),
- 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
- //region 应收记账
- 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);
- 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 = 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> map = new HashMap<>();
- map.put("outDetail", invList);
- map.put("delOutDetail", invDelList);
- inventoryService.operatingInventoryInformation(map);
- }
- //endregion
- return ResponseResultUtil.success(outboundVO);
- }
- /**
- * @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 应收反记账
- if (outboundResponse.getReceivableId() != null) {
- accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
- }
- //endregion
- //region 修改订单数据信息
- if (outboundResponse.getFromId() != null) {
- //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
- Order order = new Order();
- order.setOrderId(outboundResponse.getFromId());
- order.setOutingQty(outboundResponse.getOutQty());
- order.setOutingAmt(outboundResponse.getOutAmt());
- order.setOutQty(outboundResponse.getOutQty().negate());
- order.setOutAmt(outboundResponse.getOutAmt().negate());
- //根据id查询
- OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
- //出库状态
- 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
- //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 明细数据
- //根据总单id查明细
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
- 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.INVENTORY_QUANTITY_EXCEEDED_OUTBOUND.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().negate());
- outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
- //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/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;
- //入库中+已入库 小于 总数
- if (intoingQty.add(intoQty).compareTo(sumQty) < 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.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));
- }
- }
|