package com.chinaztt.mes.production.util;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import com.chinaztt.mes.production.entity.Feeding;
|
import com.chinaztt.mes.production.entity.ProductInput;
|
import com.chinaztt.mes.production.mapper.FeedingMapper;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
|
/**
|
* @Author: cxf
|
* @Date: 2020/11/16 11:20
|
*/
|
@Service
|
@AllArgsConstructor
|
public class FeedingUtils {
|
|
private FeedingMapper feedingMapper;
|
|
/**
|
* 投料数量修改统一接口
|
*
|
* @param id 需要修改的投料id
|
* @param suppliedQuantityIncrement 投料增量
|
* @param residualQuantityIncrement 剩余增量
|
* @return
|
*/
|
public boolean updateById(Long id, BigDecimal suppliedQuantityIncrement, BigDecimal residualQuantityIncrement) {
|
synchronized (String.valueOf(id).intern()) {
|
Feeding feeding = feedingMapper.selectById(id);
|
// 1.更新投料数量
|
if (suppliedQuantityIncrement != null && suppliedQuantityIncrement.compareTo(BigDecimal.ZERO) != 0) {
|
feeding.setSuppliedQuantity(feeding.getSuppliedQuantity().add(suppliedQuantityIncrement));
|
}
|
// 2.更新剩余数量
|
if (residualQuantityIncrement != null && residualQuantityIncrement.compareTo(BigDecimal.ZERO) != 0) {
|
feeding.setResidualQuantity(feeding.getResidualQuantity().add(residualQuantityIncrement));
|
}
|
// 判断数值大于等于0
|
if (feeding.getResidualQuantity().compareTo(BigDecimal.ZERO) == -1) {
|
throw new RuntimeException("投料剩余数量不足");
|
}
|
return SqlHelper.retBool(feedingMapper.updateById(feeding));
|
}
|
}
|
|
/**
|
* 根据投入信息+工作站id查询投料id
|
*
|
* @param workstationId
|
* @param productInput
|
* @param suppliedQuantityIncrement
|
* @param residualQuantityIncrement
|
* @return
|
*/
|
public boolean update(Long workstationId, ProductInput productInput, BigDecimal suppliedQuantityIncrement, BigDecimal residualQuantityIncrement) {
|
Feeding feeding = feedingMapper.selectOne(Wrappers.<Feeding>lambdaQuery()
|
.eq(Feeding::getWorkstationId, workstationId).eq(Feeding::getPartId, productInput.getPartId())
|
.eq(Feeding::getPartBatchNo, productInput.getPartBatchNo()).eq(Feeding::getSystemNo, productInput.getSystemNo())
|
.eq(Feeding::getStockId, productInput.getStockId()));
|
return updateById(feeding.getId(), suppliedQuantityIncrement, residualQuantityIncrement);
|
}
|
|
}
|