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.SparePartReceiveDeatilMapper;
|
import org.jeecg.modules.spare.service.ISparePartReceiveDeatilService;
|
import org.jeecg.modules.spare.service.ISparePartReceiveService;
|
import org.jeecg.modules.spare.service.ISparePartService;
|
import org.jeecg.modules.spare.service.ISparesPartInventoryService;
|
import org.jeecg.modules.spare.vo.SparePartReceiveVo;
|
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-26
|
* @Version: V1.0
|
*/
|
@Service
|
public class SparePartReceiveDeatilServiceImpl extends ServiceImpl<SparePartReceiveDeatilMapper, SparePartReceiveDeatil> implements ISparePartReceiveDeatilService {
|
|
@Autowired
|
private SparePartReceiveDeatilMapper sparePartReceiveDeatilMapper;
|
|
@Autowired
|
@Lazy
|
private ISparePartService sparePartService;
|
|
|
@Autowired
|
@Lazy
|
private ISparePartReceiveService sparePartReceiveService;
|
@Autowired
|
@Lazy
|
private ISparesPartInventoryService sparesPartInventoryService;
|
|
@Autowired
|
@Lazy
|
private ISparePartReceiveDeatilService sparePartReceiveDeatilService;
|
|
@Override
|
public List<SparePartReceiveDeatil> selectByMainId(String mainId) {
|
return sparePartReceiveDeatilMapper.selectByMainId(mainId);
|
}
|
|
|
@Override
|
public boolean sparePartApproval(SparePartReceive sparePartReceive) {
|
|
for (SparePartReceiveDeatil sparePartScrapReceiveDetail : sparePartReceive.getSparePartReceiveDeatilList()) {
|
|
//1.获取库存信息及库存总数量
|
String sparePartScrapId = sparePartScrapReceiveDetail.getSparePartId();
|
SparePartReceive sparePartReceive1 = sparePartReceiveService.getById(sparePartScrapId);
|
String sparesPartInventoryId = sparePartScrapReceiveDetail.getSparePartInventoryId();
|
SparesPartInventory sparesPartInventory = sparesPartInventoryService.getById(sparesPartInventoryId);
|
|
//2.获取报废主数量
|
Double scrapMainQuantity = sparePartScrapReceiveDetail.getReceiveMainQuantity();
|
BigDecimal scrapMainQuantityB = new BigDecimal(scrapMainQuantity);
|
String sparePartId = sparePartScrapReceiveDetail.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(sparePartScrapReceiveDetail);
|
//5.更新报废单状态
|
sparePartReceive1.setStatus("4");
|
sparePartReceive1.setApprovalOpinions(sparePartReceive.getApprovalOpinions());
|
sparePartReceiveService.updateById(sparePartReceive1);
|
|
}
|
|
return true;
|
}
|
}
|