package org.jeecg.modules.spare.service.impl; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.spare.entity.*; import org.jeecg.modules.spare.mapper.SparesScrapDetailMapper; import org.jeecg.modules.spare.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; /** * @Description: 备件报废明细表 * @Author: jeecg-boot * @Date: 2023-06-21 * @Version: V1.0 */ @Service public class SparesScrapDetailServiceImpl extends ServiceImpl implements ISparesScrapDetailService { @Autowired private SparesScrapDetailMapper sparesScrapDetailMapper; @Autowired @Lazy private ISparePartScrapService sparePartScrapService; @Autowired @Lazy private ISparesPartInventoryService sparesPartInventoryService; @Autowired @Lazy private ISparePartService sparePartService; @Override public List getSparesScrapDetailList(String sparePartScrapId) { return super.getBaseMapper().getSparesScrapDetailList(sparePartScrapId); } @Override public List selectByMainId(String mainId) { return sparesScrapDetailMapper.selectByMainId(mainId); } @Override public boolean sparePartApproval(SparePartScrap sparesScrapDetails) { for (SparesScrapDetail sparePartScrapDetail : sparesScrapDetails.getSparesScrapDetailList()) { //1.获取库存信息及库存总数量 String sparePartScrapId = sparePartScrapDetail.getSparePartScrapId(); SparePartScrap sparePartScrap = sparePartScrapService.getById(sparePartScrapId); String sparesPartInventoryId = sparePartScrapDetail.getSparePartInventoryId(); SparesPartInventory sparesPartInventory = sparesPartInventoryService.getById(sparesPartInventoryId); //2.获取报废主数量 Double scrapMainQuantity = sparePartScrapDetail.getScrapMainQuantity(); BigDecimal scrapMainQuantityB = new BigDecimal(scrapMainQuantity); String sparePartId = sparePartScrapDetail.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.subtract(scrapMainQuantityB);//报废后库存主数量 BigDecimal scrapAuxiliaryQuantity = mainQuantitySubtract.multiply(conversionRatioB);//报废后库存辅数量 sparesPartInventory.setMainQuantity(mainQuantitySubtract.doubleValue()); sparesPartInventory.setAuxiliaryQuantity(scrapAuxiliaryQuantity.doubleValue()); boolean b = sparesPartInventoryService.updateById(sparesPartInventory); if (!b) { return b; } super.updateById(sparePartScrapDetail); //5.更新报废单状态 sparePartScrap.setAuditStatus("Approved"); sparePartScrap.setApprovalOpinions(sparesScrapDetails.getApprovalOpinions()); sparePartScrapService.updateById(sparePartScrap); } return true; } }