diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/order/service/impl/MoldDemandServiceImpl.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/order/service/impl/MoldDemandServiceImpl.java index 9b6db346..aba7c038 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/order/service/impl/MoldDemandServiceImpl.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/order/service/impl/MoldDemandServiceImpl.java @@ -35,7 +35,7 @@ public class MoldDemandServiceImpl extends BaseServiceImpl implements IStGoodsService { - @Resource - private StHttpRequestService stHttpRequestService; - @Resource - private IStGoodsExtService stGoodsExtService; - - @Override - public IPage selectStGoodsPage(IPage page, StGoodsVO stGoods) { - return page.setRecords(baseMapper.selectStGoodsPage(page, stGoods)); - } - - @Override - public IPage selectFindAllGoodsPage(IPage page, StGoodsVO stGoods) { - return page.setRecords(baseMapper.selectFindAllGoodsPage(page, stGoods)); - } - - @Override - public void saveGoods(String goodsCode) throws Exception { - StGoods stGoods = baseMapper.queryByCode(goodsCode); - if (stGoods != null) { - throw new Exception("该物料已存在!"); - } else { - List prtnoList = new ArrayList<>(); - prtnoList.add(goodsCode); -// saveGoodsInfo(prtnoList); - - } - } - - /*public void saveGoodsInfo(List prtnoList) throws Exception { - StGoods goods = null; - //查询物料信息 - List pdmPartInfo = stHttpRequestService.getPdmPartInfo(prtnoList); - log.debug("pdmPartInfo:{}", pdmPartInfo); - - if (pdmPartInfo != null) { - for (StPdmPartDTO dto : pdmPartInfo) { - //保存物料信息 - goods = this.queryByCodeAndVersion(dto.getPrtno(), dto.getReleaseNo()); - if (goods == null) { - goods = new StGoods(); - // goods.setDept(); - goods.setDrawingNo(dto.getDrwpartno()); - goods.setGoodsCode(dto.getPrtno()); - goods.setGoodsName(dto.getPrtdesc()); - goods.setDensity(dto.getDensity()); - goods.setPrtType(dto.getPrtType()); - goods.setSourceByStr(dto.getSource()); - goods.setSpecifications(dto.getMtlspcf()); - goods.setUnitName(dto.getPrtum()); - goods.setCavityNo(dto.getCavityNo()); - goods.setProductCategory(dto.getProductCategory()); - goods.setEcnNo(dto.getEcnNo()); - goods.setEndItem(dto.getEndItem()); - goods.setMaterialModel(dto.getMaterialModel()); - goods.setPartLink(dto.getPartLink()); - goods.setPriority(dto.getPriority()); - goods.setPartRevisionStatus(dto.getPartRevisionStatus()); - goods.setProductTechSpec(dto.getProductTechSpec()); - goods.setWeight(dto.getWeight()); - goods.setReleaseNo(dto.getReleaseNo()); - goods.setRemark(dto.getRemark()); - goods.setTradeMark(dto.getTradeMark()); - goods.setUsed(Boolean.TRUE); - goods.setIsDeleted(0); - goods.setCreateTime(new Date()); - goods.setReleaseNoTime(dto.getRcdchgdatd()); - this.save(goods); - } - } - } - }*/ - - @Override - public StGoods queryByCodeAndVersion(String prtno, String releaseNo) { - return baseMapper.queryByCodeAndVersion(prtno, releaseNo); - } - - @Override - public void changeUsed(Long id, Boolean used) throws Exception { - StGoods stGoods = this.getById(id); - if (stGoods == null) { - return; - } - stGoods.setUsed(used); - this.updateById(stGoods); - - } - - @Override - public StGoods queryByCode(String goodsCode) { - return baseMapper.queryByCode(goodsCode); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void addOnthewayQuantity(Long goodsId, Double num) { - StGoods coGoods = baseMapper.selectById(goodsId); - if (coGoods == null) { - throw new ServiceException("物料不存在或已停用:ID=" + goodsId); - } - - // 累加在途数量(负值自动归零) - double ontheway = NumberUtil.add( - BigDecimal.valueOf(coGoods.getOnthewayQuantity()), - BigDecimal.valueOf(num) - ).doubleValue(); - if (ontheway < 0) { - ontheway = 0D; - } - coGoods.setOnthewayQuantity(ontheway); - baseMapper.updateById(coGoods); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void addCurQuantity(Long goodsId, Double num) { - StGoods stGoods = baseMapper.selectById(goodsId); - if (stGoods == null) { - throw new ServiceException("物料不存在:ID=" + goodsId); - } - - // 累加当前库存(负值自动归零) - double curQuantity = NumberUtil.add( - BigDecimal.valueOf(stGoods.getCurrentQuantity()), - BigDecimal.valueOf(num) - ).doubleValue(); - if (curQuantity < 0) { - curQuantity = 0D; - } - stGoods.setCurrentQuantity(curQuantity); - baseMapper.updateById(stGoods); - - // 同步更新物料扩展表二级库存 - StGoodsExt stGoodsExt = stGoodsExtService.getById(stGoods.getId()); - if (stGoodsExt != null) { - stGoodsExt.setLastStore(curQuantity); - stGoodsExtService.updateById(stGoodsExt); - } - } - - @Override - public void addLockQuantity(Long goodsId, double num) { - StGoods stGoods = this.getById(goodsId); - Double lockQuantity = - BigDecimal.valueOf(stGoods.getLockQuantity()).add(BigDecimal.valueOf(num)).doubleValue(); - if (lockQuantity < 0) { - lockQuantity = 0d; - } - stGoods.setLockQuantity(lockQuantity); - } - - @Override - public List exportStGoods(Wrapper queryWrapper) { - List stGoodsList = baseMapper.exportStGoods(queryWrapper); - //stGoodsList.forEach(stGoods -> { - // stGoods.setTypeName(DictCache.getValue(DictEnum.YES_NO, StGoods.getType())); - //}); - return stGoodsList; - } - -} - +//package org.springblade.wms.service.impl; +// +//import cn.hutool.core.util.NumberUtil; +//import com.baomidou.mybatisplus.core.conditions.Wrapper; +//import com.baomidou.mybatisplus.core.metadata.IPage; +//import jakarta.annotation.Resource; +//import lombok.extern.slf4j.Slf4j; +//import org.springblade.core.log.exception.ServiceException; +//import org.springblade.core.mp.base.BaseServiceImpl; +//import org.springblade.wms.excel.StGoodsExcel; +//import org.springblade.wms.mapper.StGoodsClassMapper; +//import org.springblade.wms.mapper.StGoodsMapper; +//import org.springblade.wms.pojo.dto.StPdmPartDTO; +//import org.springblade.wms.pojo.entity.StGoods; +//import org.springblade.wms.pojo.entity.StGoodsExt; +//import org.springblade.wms.pojo.vo.StGoodsVO; +//import org.springblade.wms.service.IStGoodsExtService; +//import org.springblade.wms.service.IStGoodsService; +//import org.springframework.stereotype.Service; +//import org.springframework.transaction.annotation.Transactional; +// +//import java.math.BigDecimal; +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.List; +// +///** +// * @version 1.0 +// * @program: jonhon-mes-svr +// * @ClassName StGoodsServiceImpl +// * @description: +// * @autor: WuSiYu +// * @create 2025-12-12 14:21 +// **/ +// +//@Service +//@Slf4j +//public class StGoodsServiceImpl extends BaseServiceImpl implements IStGoodsService { +// @Resource +// private StHttpRequestService stHttpRequestService; +// @Resource +// private IStGoodsExtService stGoodsExtService; +// +// @Override +// public IPage selectStGoodsPage(IPage page, StGoodsVO stGoods) { +// return page.setRecords(baseMapper.selectStGoodsPage(page, stGoods)); +// } +// +// @Override +// public IPage selectFindAllGoodsPage(IPage page, StGoodsVO stGoods) { +// return page.setRecords(baseMapper.selectFindAllGoodsPage(page, stGoods)); +// } +// +// @Override +// public void saveGoods(String goodsCode) throws Exception { +// StGoods stGoods = baseMapper.queryByCode(goodsCode); +// if (stGoods != null) { +// throw new Exception("该物料已存在!"); +// } else { +// List prtnoList = new ArrayList<>(); +// prtnoList.add(goodsCode); +//// saveGoodsInfo(prtnoList); +// +// } +// } +// +// /*public void saveGoodsInfo(List prtnoList) throws Exception { +// StGoods goods = null; +// //查询物料信息 +// List pdmPartInfo = stHttpRequestService.getPdmPartInfo(prtnoList); +// log.debug("pdmPartInfo:{}", pdmPartInfo); +// +// if (pdmPartInfo != null) { +// for (StPdmPartDTO dto : pdmPartInfo) { +// //保存物料信息 +// goods = this.queryByCodeAndVersion(dto.getPrtno(), dto.getReleaseNo()); +// if (goods == null) { +// goods = new StGoods(); +// // goods.setDept(); +// goods.setDrawingNo(dto.getDrwpartno()); +// goods.setGoodsCode(dto.getPrtno()); +// goods.setGoodsName(dto.getPrtdesc()); +// goods.setDensity(dto.getDensity()); +// goods.setPrtType(dto.getPrtType()); +// goods.setSourceByStr(dto.getSource()); +// goods.setSpecifications(dto.getMtlspcf()); +// goods.setUnitName(dto.getPrtum()); +// goods.setCavityNo(dto.getCavityNo()); +// goods.setProductCategory(dto.getProductCategory()); +// goods.setEcnNo(dto.getEcnNo()); +// goods.setEndItem(dto.getEndItem()); +// goods.setMaterialModel(dto.getMaterialModel()); +// goods.setPartLink(dto.getPartLink()); +// goods.setPriority(dto.getPriority()); +// goods.setPartRevisionStatus(dto.getPartRevisionStatus()); +// goods.setProductTechSpec(dto.getProductTechSpec()); +// goods.setWeight(dto.getWeight()); +// goods.setReleaseNo(dto.getReleaseNo()); +// goods.setRemark(dto.getRemark()); +// goods.setTradeMark(dto.getTradeMark()); +// goods.setUsed(Boolean.TRUE); +// goods.setIsDeleted(0); +// goods.setCreateTime(new Date()); +// goods.setReleaseNoTime(dto.getRcdchgdatd()); +// this.save(goods); +// } +// } +// } +// }*/ +// +// @Override +// public StGoods queryByCodeAndVersion(String prtno, String releaseNo) { +// return baseMapper.queryByCodeAndVersion(prtno, releaseNo); +// } +// +// @Override +// public void changeUsed(Long id, Boolean used) throws Exception { +// StGoods stGoods = this.getById(id); +// if (stGoods == null) { +// return; +// } +// stGoods.setUsed(used); +// this.updateById(stGoods); +// +// } +// +// @Override +// public StGoods queryByCode(String goodsCode) { +// return baseMapper.queryByCode(goodsCode); +// } +// +// @Override +// @Transactional(rollbackFor = Exception.class) +// public void addOnthewayQuantity(Long goodsId, Double num) { +// StGoods coGoods = baseMapper.selectById(goodsId); +// if (coGoods == null) { +// throw new ServiceException("物料不存在或已停用:ID=" + goodsId); +// } +// +// // 累加在途数量(负值自动归零) +// double ontheway = NumberUtil.add( +// BigDecimal.valueOf(coGoods.getOnthewayQuantity()), +// BigDecimal.valueOf(num) +// ).doubleValue(); +// if (ontheway < 0) { +// ontheway = 0D; +// } +// coGoods.setOnthewayQuantity(ontheway); +// baseMapper.updateById(coGoods); +// } +// +// @Override +// @Transactional(rollbackFor = Exception.class) +// public void addCurQuantity(Long goodsId, Double num) { +// StGoods stGoods = baseMapper.selectById(goodsId); +// if (stGoods == null) { +// throw new ServiceException("物料不存在:ID=" + goodsId); +// } +// +// // 累加当前库存(负值自动归零) +// double curQuantity = NumberUtil.add( +// BigDecimal.valueOf(stGoods.getCurrentQuantity()), +// BigDecimal.valueOf(num) +// ).doubleValue(); +// if (curQuantity < 0) { +// curQuantity = 0D; +// } +// stGoods.setCurrentQuantity(curQuantity); +// baseMapper.updateById(stGoods); +// +// // 同步更新物料扩展表二级库存 +// StGoodsExt stGoodsExt = stGoodsExtService.getById(stGoods.getId()); +// if (stGoodsExt != null) { +// stGoodsExt.setLastStore(curQuantity); +// stGoodsExtService.updateById(stGoodsExt); +// } +// } +// +// @Override +// public void addLockQuantity(Long goodsId, double num) { +// StGoods stGoods = this.getById(goodsId); +// Double lockQuantity = +// BigDecimal.valueOf(stGoods.getLockQuantity()).add(BigDecimal.valueOf(num)).doubleValue(); +// if (lockQuantity < 0) { +// lockQuantity = 0d; +// } +// stGoods.setLockQuantity(lockQuantity); +// } +// +// @Override +// public List exportStGoods(Wrapper queryWrapper) { +// List stGoodsList = baseMapper.exportStGoods(queryWrapper); +// //stGoodsList.forEach(stGoods -> { +// // stGoods.setTypeName(DictCache.getValue(DictEnum.YES_NO, StGoods.getType())); +// //}); +// return stGoodsList; +// } +// +//} +// diff --git a/blade-service/blade-wms/src/main/java/org/springblade/wms/service/impl/StRealtimeStockServiceImpl.java b/blade-service/blade-wms/src/main/java/org/springblade/wms/service/impl/StRealtimeStockServiceImpl.java index 1c1904c6..2a6850b1 100644 --- a/blade-service/blade-wms/src/main/java/org/springblade/wms/service/impl/StRealtimeStockServiceImpl.java +++ b/blade-service/blade-wms/src/main/java/org/springblade/wms/service/impl/StRealtimeStockServiceImpl.java @@ -1,546 +1,546 @@ -package org.springblade.wms.service.impl; - -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.annotation.Resource; -import org.apache.commons.lang3.StringUtils; -import org.springblade.common.exception.BusinessException; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.secure.BladeUser; -import org.springblade.wms.excel.StRealtimeStockExcel; -import org.springblade.wms.mapper.StGoodsMapper; -import org.springblade.wms.mapper.StRealtimeStockMapper; -import org.springblade.wms.mapper.StStorageLocationMapper; -import org.springblade.wms.pojo.entity.*; -import org.springblade.wms.pojo.vo.*; -import org.springblade.wms.service.*; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @version 1.0 - * @program: jonhon-mes-svr - * @ClassName StRealtimeStockServiceImpl - * @description: 仓库实时结余表 服务实现类 - * @autor: WuSiYu - * @create 2025-12-15 14:58 - **/ - -@Service -public class StRealtimeStockServiceImpl extends BaseServiceImpl implements IStRealtimeStockService { - - @Resource - private StRealtimeStockMapper stRealtimeStockMapper; - @Resource - private StGoodsMapper stGoodsMapper; - @Resource - private StStorageLocationMapper stStorageLocationMapper; - @Resource - private IStGoodsService stGoodsService; - @Resource - private IStStoreBillService stStoreBillService; - @Resource - private IStLockGoodsService stLockGoodsService; - @Resource - private IStOtherOutRecordService stOtherOutRecordService; - - - @Override - public IPage selectStRealtimeStockPage(IPage page, StRealtimeStockVO stRealtimeStock) { - return page.setRecords(baseMapper.selectStRealtimeStockPage(page, stRealtimeStock)); - } - - @Override - public IPage selectStockGoodsPage(IPage page, StRealtimeStockVO stRealtimeStock) { - return page.setRecords(baseMapper.selectStockGoodsPage(page, stRealtimeStock)); - } - - @Override - public IPage selectToolsStockPage(IPage page, StRealtimeStockVO stRealtimeStock) { - return page.setRecords(baseMapper.selectToolsStockPage(page, stRealtimeStock)); - } - - @Override - public List getGoodsByPartCode(String partCode) { - return baseMapper.getGoodsByPartCode(partCode); - } - - @Override - public StGoodStatisVO getGoodsByCode(String partCode) { - return baseMapper.getGoodsByCode(partCode); - } - - @Override - public List printPrintWoLabel(List rlsIdList, Short quantity) { - if (rlsIdList == null || rlsIdList.size() == 0) { - return null; - } - List rlsIdListAll = new ArrayList<>(); - for (int i = 0; i < quantity; i++) { - rlsIdListAll.addAll(rlsIdList); - } - rlsIdListAll = rlsIdListAll.stream().sorted(Long::compareTo).collect(Collectors.toList()); - Map> map = new HashMap<>(1); - List list = null; - Integer num = 0; - int i = 1; - PrintWoLabel printWoLabel; - PrintParentWoLabel printParentWoLabel = null; - StRealtimeStock stRealtimeStock; - List plList = new ArrayList<>(); - for (Long id : rlsIdListAll) { - if (!map.containsKey(num)) { - list = new ArrayList<>(); - map.put(num, list); - printParentWoLabel = new PrintParentWoLabel(); - } - list.add(id); - printWoLabel = new PrintWoLabel(); - stRealtimeStock = stRealtimeStockMapper.selectById(id); - printWoLabel.setRsId(String.valueOf(id)); - StGoods goods = stGoodsMapper.selectById(stRealtimeStock.getGoodsId()); - printWoLabel.setCode(goods.getGoodsCode()); - printWoLabel.setName(goods.getGoodsName()); - printWoLabel.setCheckCode(stRealtimeStock.getCheckCode()); - Date scrapCycle = stRealtimeStock.getScrapCycle(); - if (scrapCycle != null) { - printWoLabel.setDate(scrapCycle.toString()); - } else { - printWoLabel.setDate(""); - } - if (list.size() == 1) { - printParentWoLabel.setPlOne(printWoLabel); - } - if (list.size() == 2) { - printParentWoLabel.setPlTwo(printWoLabel); - } - if (list.size() == 3) { - printParentWoLabel.setPlThree(printWoLabel); - } - if (list.size() == 4) { - printParentWoLabel.setPlFour(printWoLabel); - plList.add(printParentWoLabel); - num++; - } else if (i == rlsIdListAll.size()) { - plList.add(printParentWoLabel); - } - i++; - } - return plList; - } - - @Override - public List printStRealtimeStockList(List idArr) { - List pcdLst = new ArrayList<>(); - for (Long rlsId : idArr) { - PrintStoresList psl = new PrintStoresList(); - // 组装头 - this.makeHead(psl, rlsId); - pcdLst.add(psl); - } - return pcdLst; - } - - private void makeHead(PrintStoresList psl, Long rlsId) { - StRealtimeStock sts = this.getById(rlsId); - StGoods goods = stGoodsMapper.selectById(sts.getGoodsId()); - psl.setMaterialMess(goods.getGoodsCode() + goods.getGoodsName()); - psl.setMaterialCode(goods.getGoodsCode()); - psl.setInStore(sts.getCreateTime().toString()); - StStorageLocation stStorageLocation = stStorageLocationMapper.selectById(sts.getSlId()); - psl.setLocator(stStorageLocation.getLocation()); - psl.setUnit(goods.getUnitName()); - psl.setTestCode(sts.getCheckCode() != null ? sts.getCheckCode() : ""); - psl.setMatureDate(sts.getScrapCycle() != null ? sts.getScrapCycle().toString() : ""); - psl.setBatchNo(sts.getPiNo()); - psl.setIdentification(goods.getMaterialModel()); - psl.setSupplier(""); - psl.setHeatNo(sts.getStovePiNo() != null ? sts.getStovePiNo() : ""); - psl.setDate(sts.getCreateTime().toString()); - psl.setMemo(""); - psl.setIncome(goods.getPurchaseQuantity() != null ? goods.getPurchaseQuantity().toString() : ""); - DecimalFormat df = new DecimalFormat("#"); - psl.setBalance(df.format(sts.getQuantity())); -// psl.setHandledBy(sts.getKeeper()); - } - - @Override - public Double getByShId(Long shId) { - return stRealtimeStockMapper.getByShId(shId); - } - - @Override - public Double getQuantityBySlId(Long slId) { - return stRealtimeStockMapper.getQuantityBySlId(slId); - } - - @Override - public StRealtimeStock getBySlId(Long slId) { - return stRealtimeStockMapper.getBySlId(slId); - } - - @Override - public boolean findBySlId(Long slId) { - return stRealtimeStockMapper.findBySlId(slId); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateLocation(Long id, StStorageLocation newStorageLocation) { - StRealtimeStock stock = stRealtimeStockMapper.selectById(id); - if (stock == null) { - throw new ServiceException("实时库存不存在,rlsId=" + id); - } - if (newStorageLocation == null || newStorageLocation.getShId() == null) { - throw new ServiceException("目标库位信息不完整"); - } - stock.setShId(newStorageLocation.getShId()); - stock.setSlId(newStorageLocation.getId()); - stRealtimeStockMapper.updateById(stock); - } - - @Override - public List reviseRealTimeStock(List inoutList, List stockList, List splyCodeList) { - // 前置校验:避免空列表和索引越界 - if (inoutList == null || inoutList.isEmpty()) { - throw new IllegalArgumentException("StStockInoutRecord出入库记录列表不能为空!"); - } - // 校验前两个List长度一致性(保证明细与库存对象一一对应) - if (stockList != null && stockList.size() != inoutList.size()) { - throw new IllegalArgumentException("StStockInoutRecord与StRealtimeStock两个列表长度不一致,无法批量处理!"); - } - - // 初始化返回集合,收集批量处理的rlsId - List rlsIdList = new ArrayList<>(); - - // 遍历出入库记录列表,批量执行核心业务逻辑 - for (int i = 0; i < inoutList.size(); i++) { - // 3.1 获取当前索引对应的单个对象 - StStockInoutRecord inout = inoutList.get(i); - // 兼容stockList为null的情况,避免空指针 - StRealtimeStock stock = (stockList != null && stockList.size() > i) ? stockList.get(i) : null; - - // 核心业务逻辑 - Double quantity = inout.getQuantity(); - Double balanceMoney = inout.getSirMoney() == null ? 0.0 : inout.getSirMoney(); // 字段名若变更需同步调整 - - - if (inout.getInOutSource() < StStockInoutRecord.INOUT_SOURCE_QUOTA_OUT) { - //入库逻辑 - if (StStockInoutRecord.INOUT_SOURCE_PURCHASE_RECEIPT.equals(inout.getInOutSource())) { - // 1.减在途 - if (!inout.getMoldBaseMaterial()) { - stGoodsService.addOnthewayQuantity(inout.getGoodsId(), - BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); - } - // 2.增当前库存 - stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); - -// } else if (StStockInoutRecord.INOUT_SOURCE_PRODUCE_PURCHASE_RECEIPT.equals(inout.getBillFlag())) { -// //生产入库:增库存 -// stGoodsService.addCurQuantity(inout.getGoods().getGoodsId(), quantity); - } else if (StStockInoutRecord.INOUT_SOURCE_OTHER_PURCHASE_RECEIPT.equals(inout.getInOutSource()) - || StStockInoutRecord.INOUT_SOURCE_PRODUCTION_MATERIAL_RETURN.equals(inout.getInOutSource())) { - //其他入库/生产退料:增库存 - stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); - } else if (StStockInoutRecord.INOUT_SOURCE_TRANSFER_RECEIPT.equals(inout.getInOutSource())) { - //调拨入库 - // 1.减在途 - stGoodsService.addOnthewayQuantity(inout.getGoodsId(), - BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); - // 2.增当前库存 - stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); - } else if (StStockInoutRecord.INOUT_SOURCE_WAREHOUSE_TRANSFER.equals(inout.getInOutSource())) { - //库转移入库 - // 1.减在途 - if (!inout.getMoldBaseMaterial()) { - stGoodsService.addOnthewayQuantity(inout.getGoodsId(), - BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); - } - // 2.增当前库存 - stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); - } +//package org.springblade.wms.service.impl; +// +//import cn.hutool.core.util.NumberUtil; +//import cn.hutool.core.util.StrUtil; +//import com.baomidou.mybatisplus.core.conditions.Wrapper; +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import com.baomidou.mybatisplus.core.metadata.IPage; +//import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +//import jakarta.annotation.Resource; +//import org.apache.commons.lang3.StringUtils; +//import org.springblade.common.exception.BusinessException; +//import org.springblade.core.log.exception.ServiceException; +//import org.springblade.core.mp.base.BaseServiceImpl; +//import org.springblade.core.mp.support.Condition; +//import org.springblade.core.secure.BladeUser; +//import org.springblade.wms.excel.StRealtimeStockExcel; +//import org.springblade.wms.mapper.StGoodsMapper; +//import org.springblade.wms.mapper.StRealtimeStockMapper; +//import org.springblade.wms.mapper.StStorageLocationMapper; +//import org.springblade.wms.pojo.entity.*; +//import org.springblade.wms.pojo.vo.*; +//import org.springblade.wms.service.*; +//import org.springframework.stereotype.Service; +//import org.springframework.transaction.annotation.Transactional; +// +//import java.math.BigDecimal; +//import java.text.DecimalFormat; +//import java.time.LocalDateTime; +//import java.util.*; +//import java.util.stream.Collectors; +// +///** +// * @version 1.0 +// * @program: jonhon-mes-svr +// * @ClassName StRealtimeStockServiceImpl +// * @description: 仓库实时结余表 服务实现类 +// * @autor: WuSiYu +// * @create 2025-12-15 14:58 +// **/ +// +//@Service +//public class StRealtimeStockServiceImpl extends BaseServiceImpl implements IStRealtimeStockService { +// +// @Resource +// private StRealtimeStockMapper stRealtimeStockMapper; +// @Resource +// private StGoodsMapper stGoodsMapper; +// @Resource +// private StStorageLocationMapper stStorageLocationMapper; +// @Resource +// private IStGoodsService stGoodsService; +// @Resource +// private IStStoreBillService stStoreBillService; +// @Resource +// private IStLockGoodsService stLockGoodsService; +// @Resource +// private IStOtherOutRecordService stOtherOutRecordService; +// +// +// @Override +// public IPage selectStRealtimeStockPage(IPage page, StRealtimeStockVO stRealtimeStock) { +// return page.setRecords(baseMapper.selectStRealtimeStockPage(page, stRealtimeStock)); +// } +// +// @Override +// public IPage selectStockGoodsPage(IPage page, StRealtimeStockVO stRealtimeStock) { +// return page.setRecords(baseMapper.selectStockGoodsPage(page, stRealtimeStock)); +// } +// +// @Override +// public IPage selectToolsStockPage(IPage page, StRealtimeStockVO stRealtimeStock) { +// return page.setRecords(baseMapper.selectToolsStockPage(page, stRealtimeStock)); +// } +// +// @Override +// public List getGoodsByPartCode(String partCode) { +// return baseMapper.getGoodsByPartCode(partCode); +// } +// +// @Override +// public StGoodStatisVO getGoodsByCode(String partCode) { +// return baseMapper.getGoodsByCode(partCode); +// } +// +// @Override +// public List printPrintWoLabel(List rlsIdList, Short quantity) { +// if (rlsIdList == null || rlsIdList.size() == 0) { +// return null; +// } +// List rlsIdListAll = new ArrayList<>(); +// for (int i = 0; i < quantity; i++) { +// rlsIdListAll.addAll(rlsIdList); +// } +// rlsIdListAll = rlsIdListAll.stream().sorted(Long::compareTo).collect(Collectors.toList()); +// Map> map = new HashMap<>(1); +// List list = null; +// Integer num = 0; +// int i = 1; +// PrintWoLabel printWoLabel; +// PrintParentWoLabel printParentWoLabel = null; +// StRealtimeStock stRealtimeStock; +// List plList = new ArrayList<>(); +// for (Long id : rlsIdListAll) { +// if (!map.containsKey(num)) { +// list = new ArrayList<>(); +// map.put(num, list); +// printParentWoLabel = new PrintParentWoLabel(); +// } +// list.add(id); +// printWoLabel = new PrintWoLabel(); +// stRealtimeStock = stRealtimeStockMapper.selectById(id); +// printWoLabel.setRsId(String.valueOf(id)); +// StGoods goods = stGoodsMapper.selectById(stRealtimeStock.getGoodsId()); +// printWoLabel.setCode(goods.getGoodsCode()); +// printWoLabel.setName(goods.getGoodsName()); +// printWoLabel.setCheckCode(stRealtimeStock.getCheckCode()); +// Date scrapCycle = stRealtimeStock.getScrapCycle(); +// if (scrapCycle != null) { +// printWoLabel.setDate(scrapCycle.toString()); // } else { -// //出库逻辑 -// if (stock == null) { -// throw new RuntimeException("第" + (i+1) + "条出入库记录对应的出库物料为空,请选择出库物料!"); -// } -// stock = stRealtimeStockMapper.getSynchById(stock.getId()); -// //当前库位库存小于出库数量 -// if (stock.getQuantity() < quantity) { -// throw new RuntimeException("第" + (i+1) + "条出入库记录当前库位库存不足,出库失败!"); -// } -// // 获取物料信息 -// StGoods stGoods = stGoodsService.getById(inout.getGoodsId()); -// -// if (StStockInoutRecord.INOUT_SOURCE_QUOTA_OUT.equals(inout.getInOutSource())) { -// //配额出库 -// //1.减锁料 -// PvBomRequest pvBomRequest = inout.getBrId(); -// if (pvBomRequest != null) { -// -// StLockGoods lockGoods = stLockGoodsService.getByBrId(pvBomRequest.getId()); -// //锁料中数量 -// Double lockingQuantity = null; -// if (lockGoods != null) { -// lockingQuantity = -// BigDecimal.valueOf(lockGoods.getLockQuantity()).subtract(BigDecimal.valueOf(lockGoods.getOutQuantity())).doubleValue(); -// } else { -// lockingQuantity = 0.0; -// } -// if (lockingQuantity < 0) { -// lockingQuantity = 0.0; -// } -// // 判断可用库存是否充足 -// Double surplusQuantity = -// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); -// if (surplusQuantity < quantity - lockingQuantity) { -// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); -// } -// if (lockGoods != null) { -// stLockGoodsService.addOutQuantity(quantity, lockGoods.getId()); -// } -// if (quantity < lockingQuantity) { -// stGoodsService.addLockQuantity(inout.getGoodsId(), -// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); -// } else { -// stGoodsService.addLockQuantity(inout.getGoodsId(), -// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(lockingQuantity)).doubleValue()); -// } -// -// //2 减库存 -// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); -// } +// printWoLabel.setDate(""); +// } +// if (list.size() == 1) { +// printParentWoLabel.setPlOne(printWoLabel); +// } +// if (list.size() == 2) { +// printParentWoLabel.setPlTwo(printWoLabel); +// } +// if (list.size() == 3) { +// printParentWoLabel.setPlThree(printWoLabel); +// } +// if (list.size() == 4) { +// printParentWoLabel.setPlFour(printWoLabel); +// plList.add(printParentWoLabel); +// num++; +// } else if (i == rlsIdListAll.size()) { +// plList.add(printParentWoLabel); +// } +// i++; +// } +// return plList; +// } // -// } else if (StStockInoutRecord.INOUT_SOURCE_OTHER_OUT.equals(inout.getInOutSource()) -// || StStockInoutRecord.INOUT_SOURCE_TOOl_OUT.equals(inout.getInOutSource())) { -// if (StringUtils.isNotBlank(inout.getWoCode()) && stock.getId() != null) { -//// if (!this.checkRealTimeLock(inout.getWoCode(),stock.getId().toString()) && !(inout.getMemo().indexOf("补")!=-1)) { -//// throw new RuntimeException("第" + (i+1) + "条出入库记录热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); -//// } -// if (!this.checkRealTimeLock(inout.getWoCode(), stock.getId().toString())) { -// StOtherOutRecord stOtherOutRecord = stOtherOutRecordService.getBySirId(inout.getId()); -// if (StringUtils.isNotBlank(stOtherOutRecord.getMemo())) { -// if (!(stOtherOutRecord.getMemo().indexOf("补") != -1)) { -// throw new ServiceException("热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); -// } -// } else { -// throw new ServiceException("热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); -// } -// } +// @Override +// public List printStRealtimeStockList(List idArr) { +// List pcdLst = new ArrayList<>(); +// for (Long rlsId : idArr) { +// PrintStoresList psl = new PrintStoresList(); +// // 组装头 +// this.makeHead(psl, rlsId); +// pcdLst.add(psl); +// } +// return pcdLst; +// } +// +// private void makeHead(PrintStoresList psl, Long rlsId) { +// StRealtimeStock sts = this.getById(rlsId); +// StGoods goods = stGoodsMapper.selectById(sts.getGoodsId()); +// psl.setMaterialMess(goods.getGoodsCode() + goods.getGoodsName()); +// psl.setMaterialCode(goods.getGoodsCode()); +// psl.setInStore(sts.getCreateTime().toString()); +// StStorageLocation stStorageLocation = stStorageLocationMapper.selectById(sts.getSlId()); +// psl.setLocator(stStorageLocation.getLocation()); +// psl.setUnit(goods.getUnitName()); +// psl.setTestCode(sts.getCheckCode() != null ? sts.getCheckCode() : ""); +// psl.setMatureDate(sts.getScrapCycle() != null ? sts.getScrapCycle().toString() : ""); +// psl.setBatchNo(sts.getPiNo()); +// psl.setIdentification(goods.getMaterialModel()); +// psl.setSupplier(""); +// psl.setHeatNo(sts.getStovePiNo() != null ? sts.getStovePiNo() : ""); +// psl.setDate(sts.getCreateTime().toString()); +// psl.setMemo(""); +// psl.setIncome(goods.getPurchaseQuantity() != null ? goods.getPurchaseQuantity().toString() : ""); +// DecimalFormat df = new DecimalFormat("#"); +// psl.setBalance(df.format(sts.getQuantity())); +//// psl.setHandledBy(sts.getKeeper()); +// } +// +// @Override +// public Double getByShId(Long shId) { +// return stRealtimeStockMapper.getByShId(shId); +// } +// +// @Override +// public Double getQuantityBySlId(Long slId) { +// return stRealtimeStockMapper.getQuantityBySlId(slId); +// } +// +// @Override +// public StRealtimeStock getBySlId(Long slId) { +// return stRealtimeStockMapper.getBySlId(slId); +// } +// +// @Override +// public boolean findBySlId(Long slId) { +// return stRealtimeStockMapper.findBySlId(slId); +// } +// +// @Override +// @Transactional(rollbackFor = Exception.class) +// public void updateLocation(Long id, StStorageLocation newStorageLocation) { +// StRealtimeStock stock = stRealtimeStockMapper.selectById(id); +// if (stock == null) { +// throw new ServiceException("实时库存不存在,rlsId=" + id); +// } +// if (newStorageLocation == null || newStorageLocation.getShId() == null) { +// throw new ServiceException("目标库位信息不完整"); +// } +// stock.setShId(newStorageLocation.getShId()); +// stock.setSlId(newStorageLocation.getId()); +// stRealtimeStockMapper.updateById(stock); +// } +// +// @Override +// public List reviseRealTimeStock(List inoutList, List stockList, List splyCodeList) { +// // 前置校验:避免空列表和索引越界 +// if (inoutList == null || inoutList.isEmpty()) { +// throw new IllegalArgumentException("StStockInoutRecord出入库记录列表不能为空!"); +// } +// // 校验前两个List长度一致性(保证明细与库存对象一一对应) +// if (stockList != null && stockList.size() != inoutList.size()) { +// throw new IllegalArgumentException("StStockInoutRecord与StRealtimeStock两个列表长度不一致,无法批量处理!"); +// } +// +// // 初始化返回集合,收集批量处理的rlsId +// List rlsIdList = new ArrayList<>(); +// +// // 遍历出入库记录列表,批量执行核心业务逻辑 +// for (int i = 0; i < inoutList.size(); i++) { +// // 3.1 获取当前索引对应的单个对象 +// StStockInoutRecord inout = inoutList.get(i); +// // 兼容stockList为null的情况,避免空指针 +// StRealtimeStock stock = (stockList != null && stockList.size() > i) ? stockList.get(i) : null; +// +// // 核心业务逻辑 +// Double quantity = inout.getQuantity(); +// Double balanceMoney = inout.getSirMoney() == null ? 0.0 : inout.getSirMoney(); // 字段名若变更需同步调整 +// +// +// if (inout.getInOutSource() < StStockInoutRecord.INOUT_SOURCE_QUOTA_OUT) { +// //入库逻辑 +// if (StStockInoutRecord.INOUT_SOURCE_PURCHASE_RECEIPT.equals(inout.getInOutSource())) { +// // 1.减在途 +// if (!inout.getMoldBaseMaterial()) { +// stGoodsService.addOnthewayQuantity(inout.getGoodsId(), +// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); // } -// //其他出库/刀具出库:校验可用库存并减库存 -// Double surplusQuantity = -// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); -// if (surplusQuantity < quantity) { -// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); +// // 2.增当前库存 +// stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); +// +//// } else if (StStockInoutRecord.INOUT_SOURCE_PRODUCE_PURCHASE_RECEIPT.equals(inout.getBillFlag())) { +//// //生产入库:增库存 +//// stGoodsService.addCurQuantity(inout.getGoods().getGoodsId(), quantity); +// } else if (StStockInoutRecord.INOUT_SOURCE_OTHER_PURCHASE_RECEIPT.equals(inout.getInOutSource()) +// || StStockInoutRecord.INOUT_SOURCE_PRODUCTION_MATERIAL_RETURN.equals(inout.getInOutSource())) { +// //其他入库/生产退料:增库存 +// stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); +// } else if (StStockInoutRecord.INOUT_SOURCE_TRANSFER_RECEIPT.equals(inout.getInOutSource())) { +// //调拨入库 +// // 1.减在途 +// stGoodsService.addOnthewayQuantity(inout.getGoodsId(), +// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +// // 2.增当前库存 +// stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); +// } else if (StStockInoutRecord.INOUT_SOURCE_WAREHOUSE_TRANSFER.equals(inout.getInOutSource())) { +// //库转移入库 +// // 1.减在途 +// if (!inout.getMoldBaseMaterial()) { +// stGoodsService.addOnthewayQuantity(inout.getGoodsId(), +// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); // } -// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); -// } else if (StStockInoutRecord.INOUT_SOURCE_ASSIGN_OUT.equals(inout.getInOutSource())) { -// if (!stock.getMoldBaseMaterial()) { -// //生产领料出库 -//// StUseGoodsDetail detail = stUseGoodsDetailService.queryByAbdId(inout.getAbdId()); // 字段名若变更需调整 -//// PvBomRequest pvBomRequest = null; -//// if (detail != null) { -//// pvBomRequest = detail.getPrWorkpiece().getDsSelfParts().getPvBomRequest(); +// // 2.增当前库存 +// stGoodsService.addCurQuantity(inout.getGoodsId(), quantity); +// } +//// } else { +//// //出库逻辑 +//// if (stock == null) { +//// throw new RuntimeException("第" + (i+1) + "条出入库记录对应的出库物料为空,请选择出库物料!"); +//// } +//// stock = stRealtimeStockMapper.getSynchById(stock.getId()); +//// //当前库位库存小于出库数量 +//// if (stock.getQuantity() < quantity) { +//// throw new RuntimeException("第" + (i+1) + "条出入库记录当前库位库存不足,出库失败!"); +//// } +//// // 获取物料信息 +//// StGoods stGoods = stGoodsService.getById(inout.getGoodsId()); +//// +//// if (StStockInoutRecord.INOUT_SOURCE_QUOTA_OUT.equals(inout.getInOutSource())) { +//// //配额出库 +//// //1.减锁料 +//// PvBomRequest pvBomRequest = inout.getBrId(); +//// if (pvBomRequest != null) { +//// +//// StLockGoods lockGoods = stLockGoodsService.getByBrId(pvBomRequest.getId()); +//// //锁料中数量 +//// Double lockingQuantity = null; +//// if (lockGoods != null) { +//// lockingQuantity = +//// BigDecimal.valueOf(lockGoods.getLockQuantity()).subtract(BigDecimal.valueOf(lockGoods.getOutQuantity())).doubleValue(); +//// } else { +//// lockingQuantity = 0.0; +//// } +//// if (lockingQuantity < 0) { +//// lockingQuantity = 0.0; //// } +//// // 判断可用库存是否充足 +//// Double surplusQuantity = +//// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); +//// if (surplusQuantity < quantity - lockingQuantity) { +//// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); +//// } +//// if (lockGoods != null) { +//// stLockGoodsService.addOutQuantity(quantity, lockGoods.getId()); +//// } +//// if (quantity < lockingQuantity) { +//// stGoodsService.addLockQuantity(inout.getGoodsId(), +//// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +//// } else { +//// stGoodsService.addLockQuantity(inout.getGoodsId(), +//// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(lockingQuantity)).doubleValue()); +//// } +//// +//// //2 减库存 +//// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +//// } +//// +//// } else if (StStockInoutRecord.INOUT_SOURCE_OTHER_OUT.equals(inout.getInOutSource()) +//// || StStockInoutRecord.INOUT_SOURCE_TOOl_OUT.equals(inout.getInOutSource())) { +//// if (StringUtils.isNotBlank(inout.getWoCode()) && stock.getId() != null) { +////// if (!this.checkRealTimeLock(inout.getWoCode(),stock.getId().toString()) && !(inout.getMemo().indexOf("补")!=-1)) { +////// throw new RuntimeException("第" + (i+1) + "条出入库记录热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); +////// } +//// if (!this.checkRealTimeLock(inout.getWoCode(), stock.getId().toString())) { +//// StOtherOutRecord stOtherOutRecord = stOtherOutRecordService.getBySirId(inout.getId()); +//// if (StringUtils.isNotBlank(stOtherOutRecord.getMemo())) { +//// if (!(stOtherOutRecord.getMemo().indexOf("补") != -1)) { +//// throw new ServiceException("热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); +//// } +//// } else { +//// throw new ServiceException("热表玻璃饼出库需匹配预占用,此工作订单无预占用!"); +//// } +//// } +//// } +//// //其他出库/刀具出库:校验可用库存并减库存 +//// Double surplusQuantity = +//// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); +//// if (surplusQuantity < quantity) { +//// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); +//// } +//// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +//// } else if (StStockInoutRecord.INOUT_SOURCE_ASSIGN_OUT.equals(inout.getInOutSource())) { +//// if (!stock.getMoldBaseMaterial()) { +//// //生产领料出库 +////// StUseGoodsDetail detail = stUseGoodsDetailService.queryByAbdId(inout.getAbdId()); // 字段名若变更需调整 +////// PvBomRequest pvBomRequest = null; +////// if (detail != null) { +////// pvBomRequest = detail.getPrWorkpiece().getDsSelfParts().getPvBomRequest(); +////// } +//// +//// //1.减锁料 +////// if (pvBomRequest != null) { +////// StLockGoods lockGoods = stLockGoodsService.getByBrId(pvBomRequest.getId()); +//// Double lockingQuantity = null; +//// if (lockGoods != null) { +//// lockingQuantity = +//// BigDecimal.valueOf(lockGoods.getLockQuantity()).subtract(BigDecimal.valueOf(lockGoods.getOutQuantity())).doubleValue(); +//// } else { +//// lockingQuantity = 0.0; +//// } +//// if (lockingQuantity < 0) { +//// lockingQuantity = 0.0; +//// } +//// // 校验可用库存 +//// Double surplusQuantity = +//// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); +//// if (surplusQuantity < quantity - lockingQuantity) { +//// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); +//// } +//// if (lockGoods != null) { +//// stLockGoodsService.addOutQuantity(quantity, lockGoods.getId()); +//// } +//// if (quantity < lockingQuantity) { +//// stGoodsService.addLockQuantity(inout.getGoodsId(), +//// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +//// } else { +//// stGoodsService.addLockQuantity(inout.getGoodsId(), +//// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(lockingQuantity)).doubleValue()); +//// } +//// //2.减库存 +//// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); +//// } +//// } +//// } +//// +//// quantity = BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue(); +// } // -// //1.减锁料 -//// if (pvBomRequest != null) { -//// StLockGoods lockGoods = stLockGoodsService.getByBrId(pvBomRequest.getId()); -// Double lockingQuantity = null; -// if (lockGoods != null) { -// lockingQuantity = -// BigDecimal.valueOf(lockGoods.getLockQuantity()).subtract(BigDecimal.valueOf(lockGoods.getOutQuantity())).doubleValue(); -// } else { -// lockingQuantity = 0.0; -// } -// if (lockingQuantity < 0) { -// lockingQuantity = 0.0; -// } -// // 校验可用库存 -// Double surplusQuantity = -// stGoods.getCurrentQuantity() + stGoods.getOnthewayQuantity() - stGoods.getLockQuantity(); -// if (surplusQuantity < quantity - lockingQuantity) { -// throw new ServiceException(stGoods.getGoodsCode() + "可用库存不足,出库失败"); -// } -// if (lockGoods != null) { -// stLockGoodsService.addOutQuantity(quantity, lockGoods.getId()); -// } -// if (quantity < lockingQuantity) { -// stGoodsService.addLockQuantity(inout.getGoodsId(), -// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); -// } else { -// stGoodsService.addLockQuantity(inout.getGoodsId(), -// BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(lockingQuantity)).doubleValue()); -// } -// //2.减库存 -// stGoodsService.addCurQuantity(inout.getGoodsId(), BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue()); -// } -// } +// // 调用底层方法,获取单个rlsId并添加到返回集合 +//// Long rlsId = this.reviseRealTimeStock(stock, inout, quantity, balanceMoney, splyCode); +//// rlsIdList.add(rlsId); +// } +//// +//// // 返回批量处理后的rlsId列表 +// return rlsIdList; +// } +// +// @Transactional(rollbackFor = Exception.class) +// public Long reviseRealTimeStock(StRealtimeStock stock, +// StStockInoutRecord inout, +// Double quantity, +// Double balanceMoney, +// String splyCode) { +// +// /* 1. 无记录 → 新增 */ +// if (stock == null) { +// StRealtimeStock entity = new StRealtimeStock(); +// entity.setGoodsId(inout.getGoodsId()); +// entity.setShId(inout.getShId()); +// entity.setSlId(inout.getSlId()); +// entity.setPiNo(inout.getPiNo()); +// entity.setStovePiNo(inout.getStovePiNo()); +// entity.setThickness(inout.getThickness()); +// entity.setQuantity(quantity); +// entity.setOccupyQuantity(0D); +// entity.setBalanceMoney(balanceMoney); +// entity.setCreateTime(Optional.ofNullable(inout.getInOutDate()).orElse(new Date())); +// entity.setQuantityLevel(inout.getQuantityLevel()); +// entity.setScrapCycle(inout.getScrapCycle()); +// entity.setCheckCode(inout.getCheckNo()); +// entity.setMoldBaseMaterial(inout.getMoldBaseMaterial()); +// entity.setBarCode(inout.getBarCode()); +// entity.setSplyCode(splyCode); +// entity.setDeptId(inout.getDeptId()); +// this.save(entity); +// return entity.getId(); +// } +// +// /* 2. 有记录 → 累加数量 & 更新 */ +// StRealtimeStock db = baseMapper.getSynchById(stock.getId()); +// double newQty = NumberUtil.add(BigDecimal.valueOf(db.getQuantity()), +// BigDecimal.valueOf(quantity)) +// .doubleValue(); +// db.setQuantity(newQty); +// db.setBalanceMoney(balanceMoney); +// db.setSplyCode(splyCode); +// +// /* 车间订单锁料 */ +// double newOccupy = NumberUtil +// .add(BigDecimal.valueOf(db.getOccupyQuantity()), +// BigDecimal.valueOf(quantity)) +// .doubleValue(); +// +// if (StrUtil.isNotBlank(inout.getWoCode()) && newOccupy >= 0) { +// db.setOccupyQuantity(newOccupy); +// this.updateRealTimeLock(inout.getWoCode(), db.getId(), newOccupy); +// } +// this.updateById(db); +// return db.getId(); +// } +// +// private void updateRealTimeLock(String woCode, Long id, double doubleValue) { +// baseMapper.updateRealTimeLock(woCode, id.toString(), doubleValue); +// } +// +// private boolean checkRealTimeLock(String woCode, String rlsId) { +// return baseMapper.checkRealTimeLock(woCode, rlsId); +// } +// +// @Override +// public Double findPriceByParams(Long goodsId, String checkNo) { +// return baseMapper.findPriceByParams(goodsId, checkNo); +// } +// +// @Override +// public IPage selectByGoodsIdShId(Long goodsId, Long shId, String deptId) { +// return baseMapper.selectByGoodsIdShId(goodsId, shId, deptId); +// } +// +//// @Override +//// public IPage selectGoodsOut(String filterValue, Long shId, Long goodsId, String deptId, Integer current, Integer size) { +//// int curr = current == null || current < 1 ? 1 : current; +//// int sz = size == null || size < 1 ? 10 : size; +//// IPage page = new Page<>(curr, sz); +//// return baseMapper.selectGoodsOut(page, filterValue, shId, goodsId, deptId); +//// } +// +// +// @Override +// public void stockProcessing(List sbList, Short status, BladeUser curUserInfo) throws Exception { +// StRealtimeStock rs = null; +// for (StStoreBill sb : sbList) { +// rs = this.getById(sb.getGoodsId()); +// if(rs == null){ +// throw new BusinessException("当前物料无可用库存,无法借出!"); +// } +// if (status.equals(StStoreBill.BILLSOURCE_BORROW)) { +// Double surplusQuantity = rs.getQuantity() - rs.getOccupyQuantity(); +// if (sb.getQuantity() > surplusQuantity) { +// throw new BusinessException("库存剩余数量不足!"); +// } +// rs.setOccupyQuantity(rs.getOccupyQuantity() + sb.getQuantity()); +// this.updateById(rs); +// } else if (status.equals(StStoreBill.BILLSOURCE_RETURN)) { +// if (sb.getBillSource().equals(StStoreBill.BILLSOURCE_RETURN)) { +// rs.setSumNum(rs.getSumNum() + sb.getUseNum()); +// this.updateById(rs); // } +// } +// sb = stStoreBillService.getById(sb.getId()); +// sb.setCurStatus(StStoreBill.CURSTATUS_COMPLETE); +// stStoreBillService.updateById(sb); +// } +// } +// +// @Override +// public IPage selectGoodsOut(String filterValue, Long shId, Long goodsId, IPage page) { +// return this.baseMapper.selectGoodsOut(page, filterValue, shId, goodsId); +// } // -// quantity = BigDecimal.valueOf(0).subtract(BigDecimal.valueOf(quantity)).doubleValue(); - } - - // 调用底层方法,获取单个rlsId并添加到返回集合 -// Long rlsId = this.reviseRealTimeStock(stock, inout, quantity, balanceMoney, splyCode); -// rlsIdList.add(rlsId); - } -// -// // 返回批量处理后的rlsId列表 - return rlsIdList; - } - - @Transactional(rollbackFor = Exception.class) - public Long reviseRealTimeStock(StRealtimeStock stock, - StStockInoutRecord inout, - Double quantity, - Double balanceMoney, - String splyCode) { - - /* 1. 无记录 → 新增 */ - if (stock == null) { - StRealtimeStock entity = new StRealtimeStock(); - entity.setGoodsId(inout.getGoodsId()); - entity.setShId(inout.getShId()); - entity.setSlId(inout.getSlId()); - entity.setPiNo(inout.getPiNo()); - entity.setStovePiNo(inout.getStovePiNo()); - entity.setThickness(inout.getThickness()); - entity.setQuantity(quantity); - entity.setOccupyQuantity(0D); - entity.setBalanceMoney(balanceMoney); - entity.setCreateTime(Optional.ofNullable(inout.getInOutDate()).orElse(new Date())); - entity.setQuantityLevel(inout.getQuantityLevel()); - entity.setScrapCycle(inout.getScrapCycle()); - entity.setCheckCode(inout.getCheckNo()); - entity.setMoldBaseMaterial(inout.getMoldBaseMaterial()); - entity.setBarCode(inout.getBarCode()); - entity.setSplyCode(splyCode); - entity.setDeptId(inout.getDeptId()); - this.save(entity); - return entity.getId(); - } - - /* 2. 有记录 → 累加数量 & 更新 */ - StRealtimeStock db = baseMapper.getSynchById(stock.getId()); - double newQty = NumberUtil.add(BigDecimal.valueOf(db.getQuantity()), - BigDecimal.valueOf(quantity)) - .doubleValue(); - db.setQuantity(newQty); - db.setBalanceMoney(balanceMoney); - db.setSplyCode(splyCode); - - /* 车间订单锁料 */ - double newOccupy = NumberUtil - .add(BigDecimal.valueOf(db.getOccupyQuantity()), - BigDecimal.valueOf(quantity)) - .doubleValue(); - - if (StrUtil.isNotBlank(inout.getWoCode()) && newOccupy >= 0) { - db.setOccupyQuantity(newOccupy); - this.updateRealTimeLock(inout.getWoCode(), db.getId(), newOccupy); - } - this.updateById(db); - return db.getId(); - } - - private void updateRealTimeLock(String woCode, Long id, double doubleValue) { - baseMapper.updateRealTimeLock(woCode, id.toString(), doubleValue); - } - - private boolean checkRealTimeLock(String woCode, String rlsId) { - return baseMapper.checkRealTimeLock(woCode, rlsId); - } - - @Override - public Double findPriceByParams(Long goodsId, String checkNo) { - return baseMapper.findPriceByParams(goodsId, checkNo); - } - - @Override - public IPage selectByGoodsIdShId(Long goodsId, Long shId, String deptId) { - return baseMapper.selectByGoodsIdShId(goodsId, shId, deptId); - } - // @Override -// public IPage selectGoodsOut(String filterValue, Long shId, Long goodsId, String deptId, Integer current, Integer size) { -// int curr = current == null || current < 1 ? 1 : current; -// int sz = size == null || size < 1 ? 10 : size; -// IPage page = new Page<>(curr, sz); -// return baseMapper.selectGoodsOut(page, filterValue, shId, goodsId, deptId); +// public StRealtimeStock getFirstByGoodsCodeAndDeptId(String goodsCode, String deptId) { +// return baseMapper.getFirstByGoodsCodeAndDeptId(goodsCode, deptId); // } - - - @Override - public void stockProcessing(List sbList, Short status, BladeUser curUserInfo) throws Exception { - StRealtimeStock rs = null; - for (StStoreBill sb : sbList) { - rs = this.getById(sb.getGoodsId()); - if(rs == null){ - throw new BusinessException("当前物料无可用库存,无法借出!"); - } - if (status.equals(StStoreBill.BILLSOURCE_BORROW)) { - Double surplusQuantity = rs.getQuantity() - rs.getOccupyQuantity(); - if (sb.getQuantity() > surplusQuantity) { - throw new BusinessException("库存剩余数量不足!"); - } - rs.setOccupyQuantity(rs.getOccupyQuantity() + sb.getQuantity()); - this.updateById(rs); - } else if (status.equals(StStoreBill.BILLSOURCE_RETURN)) { - if (sb.getBillSource().equals(StStoreBill.BILLSOURCE_RETURN)) { - rs.setSumNum(rs.getSumNum() + sb.getUseNum()); - this.updateById(rs); - } - } - sb = stStoreBillService.getById(sb.getId()); - sb.setCurStatus(StStoreBill.CURSTATUS_COMPLETE); - stStoreBillService.updateById(sb); - } - } - - @Override - public IPage selectGoodsOut(String filterValue, Long shId, Long goodsId, IPage page) { - return this.baseMapper.selectGoodsOut(page, filterValue, shId, goodsId); - } - - @Override - public StRealtimeStock getFirstByGoodsCodeAndDeptId(String goodsCode, String deptId) { - return baseMapper.getFirstByGoodsCodeAndDeptId(goodsCode, deptId); - } - - @Override - public StRealtimeStock getByBarCode(String barCode) { - return baseMapper.getByBarCode(barCode); - } - - @Override - public StRealtimeStock getByGoodsCode(String barCode) { - return baseMapper.getByGoodsCode(barCode); - } - - @Override - public List exportStRealtimeStock (Wrapper < StRealtimeStock > queryWrapper) { - List stRealtimeStockList = baseMapper.exportStRealtimeStock(queryWrapper); - //stRealtimeStockList.forEach(stRealtimeStock -> { - // stRealtimeStock.setTypeName(DictCache.getValue(DictEnum.YES_NO, StRealtimeStock.getType())); - //}); - return stRealtimeStockList; - } - - -} - +// +// @Override +// public StRealtimeStock getByBarCode(String barCode) { +// return baseMapper.getByBarCode(barCode); +// } +// +// @Override +// public StRealtimeStock getByGoodsCode(String barCode) { +// return baseMapper.getByGoodsCode(barCode); +// } +// +// @Override +// public List exportStRealtimeStock (Wrapper < StRealtimeStock > queryWrapper) { +// List stRealtimeStockList = baseMapper.exportStRealtimeStock(queryWrapper); +// //stRealtimeStockList.forEach(stRealtimeStock -> { +// // stRealtimeStock.setTypeName(DictCache.getValue(DictEnum.YES_NO, StRealtimeStock.getType())); +// //}); +// return stRealtimeStockList; +// } +// +// +//} +//