|
@@ -12,8 +12,10 @@ import com.github.zuihou.business.barrel.service.EquBarrelService;
|
|
|
import com.github.zuihou.business.formula.entity.Formula;
|
|
|
import com.github.zuihou.business.formula.service.FormulaService;
|
|
|
import com.github.zuihou.business.productConfig.service.ProductConfigService;
|
|
|
+import com.github.zuihou.business.productionresource.dto.EquGoodsDto;
|
|
|
import com.github.zuihou.business.productionresource.entity.EquAndGoods;
|
|
|
import com.github.zuihou.business.productionresource.service.EquAndGoodsService;
|
|
|
+import com.github.zuihou.business.productionresource.service.ProductionTenantResourceService;
|
|
|
import com.github.zuihou.business.spe.entity.Spe;
|
|
|
import com.github.zuihou.business.spe.service.SpeService;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
|
|
@@ -24,6 +26,8 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 业务实现类
|
|
@@ -45,57 +49,131 @@ public class EquBarrelServiceImpl extends SuperServiceImpl<EquBarrelMapper, EquB
|
|
|
private SpeService speService;
|
|
|
@Autowired
|
|
|
private EquAndGoodsService equAndGoodsService;
|
|
|
+ @Autowired
|
|
|
+ private ProductionTenantResourceService productionTenantResourceService;
|
|
|
|
|
|
@Override
|
|
|
public void updateBarrel(Long speId, Long equId) {
|
|
|
- System.out.println("查询条件:equId="+equId+"--specId="+speId);
|
|
|
+ System.out.println("查询条件:equId=" + equId + "--specId=" + speId);
|
|
|
+
|
|
|
+ // 查询料筒信息
|
|
|
+
|
|
|
+ QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
|
|
|
+ equBarrelQueryWrap.eq("equ_id", equId);
|
|
|
+ List<EquBarrel> barrelList = this.list(equBarrelQueryWrap);
|
|
|
+ System.out.println("查询到的料筒" + JSON.toJSONString(barrelList));
|
|
|
+
|
|
|
+// 查询该设备上的所有商品
|
|
|
+ List<EquGoodsDto> equGoodsDtoList = productionTenantResourceService.getEquGoods(equId);
|
|
|
+
|
|
|
+ if (equGoodsDtoList != null) {
|
|
|
+ equGoodsDtoList.forEach(equGoodsDto -> {
|
|
|
+ List<Spe> speList = equGoodsDto.getSpeList();
|
|
|
+ if (null != speList) {
|
|
|
+ speList.forEach(spe -> {
|
|
|
+ QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
|
|
|
+ formulaQueryWrap.eq("formula_spe_id", spe.getId());
|
|
|
+ List<Formula> formulaList = formulaService.list(formulaQueryWrap);
|
|
|
+ if (formulaList != null) {
|
|
|
+
|
|
|
+ if (barrelList != null) {
|
|
|
+ List<Long> mtList = barrelList.stream().map(EquBarrel::getMtrId).collect(toList());
|
|
|
+ formulaList.forEach(formula -> {
|
|
|
+ if (mtList.contains(formula.getFormulaMtId())) {
|
|
|
+ System.out.println("料筒里有原料" + formula.getFormulaMtId());
|
|
|
+ } else {
|
|
|
+ equGoodsDto.setIsStarving("0");
|
|
|
+ System.out.println("料筒里没有原料" + formula.getFormulaMtId() + ",商品" + equGoodsDto.getGoodsName() + "缺料");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ barrelList.forEach(equBarrel -> {
|
|
|
+ if (formula.getFormulaMtId().equals(equBarrel.getMtrId())) {
|
|
|
+ System.out.println("小程序换料接口-->配方中的原料" + formula.getFormulaMtId() + "和料筒中的原料" + equBarrel.getMtrId() + "相同");
|
|
|
+ UpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new UpdateWrapper<>();
|
|
|
+
|
|
|
+ if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
|
|
|
+ equGoodsDtoUpdateWrapper.set("is_starving", "1").eq("goods_id", equGoodsDto.getGoodsId()).eq("equ_id", equId);
|
|
|
+ equGoodsDto.setIsStarving("1");
|
|
|
+ } else {
|
|
|
+ equGoodsDtoUpdateWrapper.set("is_starving", "0");
|
|
|
+ equGoodsDto.setIsStarving("0");
|
|
|
+ }
|
|
|
+ equAndGoodsService.update(equGoodsDtoUpdateWrapper);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 查询出配方
|
|
|
QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
|
|
|
formulaQueryWrap.eq("formula_spe_id", speId);
|
|
|
List<Formula> formulaList = formulaService.list(formulaQueryWrap);
|
|
|
System.out.println("查询到的配方" + JSON.toJSONString(formulaList));
|
|
|
-// 查询料筒信息
|
|
|
|
|
|
- QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
|
|
|
- equBarrelQueryWrap.eq("equ_id", equId);
|
|
|
- List<EquBarrel> barrelList = this.list(equBarrelQueryWrap);
|
|
|
- System.out.println("查询到的料筒" + JSON.toJSONString(barrelList));
|
|
|
|
|
|
// 遍历配方,扣减每种原料的余量
|
|
|
+ if (barrelList != null && formulaList != null) {
|
|
|
+
|
|
|
|
|
|
- for (Formula f : formulaList
|
|
|
- ) {
|
|
|
- Long formulaMtId = f.getFormulaMtId();
|
|
|
- BigDecimal formulaMtQuantity = f.getFormulaMtQuantity();
|
|
|
- for (EquBarrel barrel : barrelList
|
|
|
+ for (Formula f : formulaList
|
|
|
) {
|
|
|
+ Long formulaMtId = f.getFormulaMtId();
|
|
|
+
|
|
|
+ BigDecimal formulaMtQuantity = f.getFormulaMtQuantity();
|
|
|
+
|
|
|
+
|
|
|
+ for (EquBarrel barrel : barrelList
|
|
|
+ ) {
|
|
|
// 查询料筒余料
|
|
|
- BigDecimal mtrResidue = barrel.getMtrResidue();
|
|
|
- if (barrel.getMtrId().equals(formulaMtId)) {
|
|
|
- System.out.println("比对出料筒里的原料" + barrel.getMtrId() + "等于配方里的原料" + formulaMtId);
|
|
|
- BigDecimal subtract = mtrResidue.subtract(formulaMtQuantity);
|
|
|
- System.out.println("料筒原先的余料" + mtrResidue);
|
|
|
- System.out.println("料筒生产后的余料" + subtract);
|
|
|
- UpdateWrapper<EquBarrel> equBarrelUpdateWrapper = new UpdateWrapper<>();
|
|
|
- equBarrelUpdateWrapper.set("mtr_residue", subtract).eq("id", barrel.getId());
|
|
|
+ BigDecimal mtrResidue = barrel.getMtrResidue();
|
|
|
+ if (barrel.getMtrId().equals(formulaMtId)) {
|
|
|
+ System.out.println("比对出料筒里的原料" + barrel.getMtrId() + "等于配方里的原料" + formulaMtId);
|
|
|
+ BigDecimal subtract = mtrResidue.subtract(formulaMtQuantity);
|
|
|
+ System.out.println("料筒原先的余料" + mtrResidue);
|
|
|
+ System.out.println("料筒生产后的余料" + subtract);
|
|
|
+ UpdateWrapper<EquBarrel> equBarrelUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ equBarrelUpdateWrapper.set("mtr_residue", subtract).eq("id", barrel.getId());
|
|
|
// 扣减后,余料达到余料预警,更新料筒余料
|
|
|
- this.update(equBarrelUpdateWrapper);
|
|
|
- if (subtract.compareTo(barrel.getResidueWarn()) != 1) {
|
|
|
+ this.update(equBarrelUpdateWrapper);
|
|
|
+ if (subtract.compareTo(barrel.getResidueWarn()) != 1) {
|
|
|
// 扣减后,余料小于余料预警,更新商品缺料
|
|
|
- Spe spe = speService.getById(speId);
|
|
|
- Long goodsId = spe.getGoodsId();
|
|
|
- System.out.println("商品id" + goodsId + "规格" + speId + "原料不足了");
|
|
|
- UpdateWrapper<EquAndGoods> equAndGoodsUpdateWrapper = new UpdateWrapper<>();
|
|
|
- equAndGoodsUpdateWrapper.eq("equ_id", equId).eq("goods_id", goodsId).set("is_starving", "0");
|
|
|
- equAndGoodsService.update(equAndGoodsUpdateWrapper);
|
|
|
+ Spe spe = speService.getById(speId);
|
|
|
+ Long goodsId = spe.getGoodsId();
|
|
|
+ System.out.println("商品id" + goodsId + "规格" + speId + "原料不足了");
|
|
|
+ UpdateWrapper<EquAndGoods> equAndGoodsUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ equAndGoodsUpdateWrapper.eq("equ_id", equId).eq("goods_id", goodsId).set("is_starving", "0");
|
|
|
+ equAndGoodsService.update(equAndGoodsUpdateWrapper);
|
|
|
// 更新料筒缺料
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|