package org.jeecg.modules.spare.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.spare.entity.*; import org.jeecg.modules.spare.mapper.SparePartCancellingStocksDetailMapper; import org.jeecg.modules.spare.service.ISparePartCancellingStocksDetailService; import org.jeecg.modules.spare.service.ISparePartCancellingStocksService; import org.jeecg.modules.spare.service.ISparePartService; import org.jeecg.modules.spare.service.ISparesPartInventoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.List; import java.util.Map; /** * @Description: 备件退库详情 * @Author: jeecg-boot * @Date: 2023-07-04 * @Version: V1.0 */ @Service public class SparePartCancellingStocksDetailServiceImpl extends ServiceImpl implements ISparePartCancellingStocksDetailService { @Autowired private SparePartCancellingStocksDetailMapper sparePartCancellingStocksDetailMapper; @Autowired private ISparePartCancellingStocksService sparePartCancellingStocksService; @Autowired private ISparesPartInventoryService sparesPartInventoryService; @Autowired private ISparePartService sparePartService; @Override public List> getSparePartCancellingStocksDeatilList(String sparePartCancellingId) { return super.getBaseMapper().getSparePartCancellingStocksDeatilList(sparePartCancellingId); } @Override public IPage> getSparePartList(Integer pageNo, Integer pageSize, Map params) { IPage pageData = new Page(pageNo, pageSize); return super.getBaseMapper().getSparePartList(pageData, params); } @Override public IPage> getSparePartCanxellingStoksDetailsById(Integer pageNo, Integer pageSize, Map params) { IPage pageData = new Page(pageNo, pageSize); return super.getBaseMapper().getSparePartCanxellingStoksDetailsById(pageData, params); } @Override @Transactional(rollbackFor = {Exception.class}) public boolean sparePartGround(SparePartCancellingStocksDetail stocksDetail) { //1.获取库存信息及库存总数量 String sparePartCancellingId = stocksDetail.getSparePartCancellingId(); SparePartCancellingStocks sparePartCancellingStocks = sparePartCancellingStocksService.getById(sparePartCancellingId); String sparesPartInventoryId = stocksDetail.getSparePartInventoryId(); SparesPartInventory sparesPartInventory = sparesPartInventoryService.getById(sparesPartInventoryId); //2.获取出库数量 Double outboundMainQuantity = stocksDetail.getOutboundMainQuantity(); BigDecimal outboundMainQuantityB = new BigDecimal(outboundMainQuantity); String sparePartId = stocksDetail.getSparePartId(); //3.获取主 辅单位转换比例 SparePart sparePart = sparePartService.getById(sparePartId); String conversionRatio = sparePart.getConversionRatio(); double conversionRatioD = 0; if (StringUtils.isBlank(conversionRatio)) { conversionRatioD = Double.parseDouble("0"); } else { conversionRatioD = Double.parseDouble(conversionRatio); } BigDecimal conversionRatioB = new BigDecimal(conversionRatioD); //4.计算出库数量更新库存数量(库存) Double mainQuantity = sparesPartInventory.getMainQuantity(); BigDecimal mainQuantityB = new BigDecimal(mainQuantity); /*仓库辅数量*/ Double auxiliaryQuantity = sparesPartInventory.getAuxiliaryQuantity(); BigDecimal auxiliaryQuantityB = new BigDecimal(auxiliaryQuantity); BigDecimal mainQuantitySubtract = mainQuantityB.add(outboundMainQuantityB);//加后的库存主数量 BigDecimal outboundAuxiliaryQuantity = outboundMainQuantityB.multiply(conversionRatioB);//出库辅数量 /*辅数量=仓库辅数量+出库的辅数量(出库数量*计算比例)*/ BigDecimal auxiliaryQuantitySubtract = auxiliaryQuantityB.add(outboundAuxiliaryQuantity);//加后的库存辅数量 sparesPartInventory.setMainQuantity(mainQuantitySubtract.doubleValue()); sparesPartInventory.setAuxiliaryQuantity(auxiliaryQuantitySubtract.doubleValue()); boolean b = sparesPartInventoryService.updateById(sparesPartInventory); if (!b) { return b; } stocksDetail.setStatus("1"); super.updateById(stocksDetail); //5.更新出库单状态 List sparePartCancellingStocksDetails = super.lambdaQuery() .eq(SparePartCancellingStocksDetail::getSparePartCancellingId, sparePartCancellingId) .eq(SparePartCancellingStocksDetail::getStatus, "0") .eq(SparePartCancellingStocksDetail::getDelFlag, "0").list(); if (sparePartCancellingStocksDetails.size() == 0) { sparePartCancellingStocks.setStatus("4"); sparePartCancellingStocksService.updateById(sparePartCancellingStocks); } return true; } @Override public List selectByMainId(String mainId) { return sparePartCancellingStocksDetailMapper.selectByMainId(mainId); } }