Browse Source

解决后台加料和操作完成功能bug

oyq28 2 years ago
parent
commit
db9319f9fc

+ 6 - 2
imcs-bt-be/imcs-authority-server/src/main/java/com/github/zuihou/api/AndroidApi.java

@@ -3,6 +3,8 @@ package com.github.zuihou.api;
 import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.zuihou.base.R;
 import com.github.zuihou.business.barrel.entity.EquBarrel;
 import com.github.zuihou.business.barrel.service.EquBarrelService;
@@ -319,8 +321,10 @@ public class AndroidApi {
 
         QueryWrap<EquBarrel> queryWrap = new QueryWrap<>();
         queryWrap.eq("equ_id", equId);
-        List<EquBarrel> list = barrelService.list(queryWrap);
-        return R.success(list);
+        //List<EquBarrel> list = barrelService.list(queryWrap);
+        Page<EquBarrel> page = new Page<>(1L, 10);
+        IPage<EquBarrel> list = barrelService.pageList(page, queryWrap);
+        return R.success(list.getRecords());
 
     }
 

+ 53 - 69
imcs-bt-be/imcs-authority-server/src/main/java/com/github/zuihou/api/OpsAppApi.java

@@ -303,7 +303,6 @@ public class OpsAppApi {
     @PostMapping("/recordSave")
     public R<Boolean> recordSave(@RequestBody EquRecord equRecord) {
         BaseContextHandler.setTenant("0000");
-        System.out.println("小程序换料接口");
         LambdaUpdateWrapper<EquBarrel> updateWrapper = new LambdaUpdateWrapper();
         updateWrapper.set(EquBarrel::getMtrId, equRecord.getReplaceMaterial()).set(EquBarrel::getMtrName, equRecord.getMtName()).set(EquBarrel::getMtrResidue, equRecord.getSpecs())
                 .set(StringUtil.isNotEmpty(equRecord.getDate()), EquBarrel::getExprTime, equRecord.getDate()).eq(EquBarrel::getId, equRecord.getMaterialId());
@@ -312,67 +311,34 @@ public class OpsAppApi {
             bool = equRecordService.save(equRecord);
         }
 
-
-        //        根据设备id查询商品
+        // 根据设备id查询商品
         List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equRecord.getEquId());
         QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
-        equBarrelQueryWrap.eq("equ_id", equRecord.getEquId());
-
-        Page<EquBarrel> page = new Page<>(1L, 20);
-        IPage<EquBarrel> equBarrelIPage = equBarrelService.pageList(page, equBarrelQueryWrap);
-        List<EquBarrel> barrelList = equBarrelIPage.getRecords();
-        List<Long> mtList = new ArrayList<>();
-        if (null != barrelList && barrelList.size()>0) {
-            mtList = barrelList.stream().map(EquBarrel::getMtrId).collect(toList());
-        }
-
-//        遍历商品,查询配方列表
-        if (equGoods != null && equGoods.size() > 0) {
-            List<Long> finalMtList = mtList;
-            equGoods.forEach(equGoodsDto -> {
-                QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
-                speQueryWrap.eq("goods_id", equGoodsDto.getGoodsId());
-                List<Spe> speList = speService.list(speQueryWrap);
-                equGoodsDto.setSpeList(speList);
-//            查询每一个规格的配方列表
-                if (speList != null && speList.size() > 0) {
-                    speList.forEach(spe -> {
-                        QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
-                        formulaQueryWrap.eq("formula_spe_id", spe.getId());
-                        List<Formula> formulaList = formulaService.list(formulaQueryWrap);
-                        if (formulaList != null && barrelList != null) {
-                            formulaList.forEach(formula -> {
-                                if (finalMtList.contains(formula.getFormulaMtId())) {
-                                    System.out.println("料筒里有原料" + formula.getFormulaMtId());
-                                } else {
-                                    System.out.println("料筒里没有原料" + formula.getFormulaMtId() + ",商品" + equGoodsDto.getGoodsName() + "缺料");
-                                    equGoodsDto.setIsStarving("0");
-                                }
-                                barrelList.forEach(equBarrel -> {
-                                    if (formula.getFormulaMtId().equals(equBarrel.getMtrId())) {
-                                        System.out.println("小程序换料接口-->配方中的原料" + formula.getFormulaMtId() + "和料筒中的原料" + equBarrel.getMtrId() + "相同");
-                                        LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
-
-                                        if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
-                                            equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getGoodsId, equGoodsDto.getGoodsId()).eq(EquAndGoods::getEquId, equRecord.getEquId());
-                                            equGoodsDto.setIsStarving("1");
-                                        } else {
-                                            equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0");
-                                            equGoodsDto.setIsStarving("0");
-                                        }
-                                        equAndGoodsService.update(equGoodsDtoUpdateWrapper);
-                                    }
-                                });
-                            });
-                        }
-                        ;
-                    });
+        equBarrelQueryWrap.eq("id", equRecord.getMaterialId());
+        Page<EquBarrel> page = new Page<>(1L, 1);
+        EquBarrel equBarrel = equBarrelService.pageList(page, equBarrelQueryWrap).getRecords().get(0);
+        QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
+        formulaQueryWrap.eq("formula_mt_id", equBarrel.getMtrId());
+        //获取关联配方数据
+        List<Formula> formulaList = formulaService.list(formulaQueryWrap);
+        //获取商品对应规格数据
+        List<Long> speIds = formulaList.stream().map(Formula::getFormulaSpeId).collect(toList());
+        //商品规格获取对应商品数据
+        QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
+        speQueryWrap.in("id", speIds);
+        List<Long> goodsIds = speService.list(speQueryWrap).stream().map(Spe::getGoodsId).collect(toList());
+
+        equGoods.forEach(equGoodsDto -> {
+            if(CollectionUtil.contains(goodsIds, equGoodsDto.getGoodsId())){
+                LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
+                if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
+                    equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getId, equGoodsDto.getId());
+                } else {
+                    equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0").eq(EquAndGoods::getId, equGoodsDto.getId());
                 }
-                ;
-            });
-        }
-
-
+                equAndGoodsService.update(null, equGoodsDtoUpdateWrapper);
+            }
+        });
         return R.success(bool);
     }
 
@@ -394,16 +360,34 @@ public class OpsAppApi {
             bool = equRecordService.save(equRecord);
         }
 
-
-        ;
-
-
-//        遍历配方
-
-
-//        根据配方中原料用量和料筒余量对比  修改商品是否缺料状态
-
-
+        // 根据设备id查询商品
+        List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equRecord.getEquId());
+        QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
+        equBarrelQueryWrap.eq("id", equRecord.getMaterialId());
+        Page<EquBarrel> page = new Page<>(1L, 1);
+        EquBarrel equBarrel = equBarrelService.pageList(page, equBarrelQueryWrap).getRecords().get(0);
+        QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
+        formulaQueryWrap.eq("formula_mt_id", equBarrel.getMtrId());
+        //获取关联配方数据
+        List<Formula> formulaList = formulaService.list(formulaQueryWrap);
+        //获取商品对应规格数据
+        List<Long> speIds = formulaList.stream().map(Formula::getFormulaSpeId).collect(toList());
+        //商品规格获取对应商品数据
+        QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
+        speQueryWrap.in("id", speIds);
+        List<Long> goodsIds = speService.list(speQueryWrap).stream().map(Spe::getGoodsId).collect(toList());
+
+        equGoods.forEach(equGoodsDto -> {
+            if(CollectionUtil.contains(goodsIds, equGoodsDto.getGoodsId())){
+                LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
+                if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
+                    equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getId, equGoodsDto.getId());
+                } else {
+                    equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0").eq(EquAndGoods::getId, equGoodsDto.getId());
+                }
+                equAndGoodsService.update(null, equGoodsDtoUpdateWrapper);
+            }
+        });
         return R.success(bool);
     }
 

+ 37 - 8
imcs-bt-be/imcs-business-biz/src/main/java/com/github/zuihou/business/barrel/service/impl/EquBarrelServiceImpl.java

@@ -2,6 +2,7 @@ package com.github.zuihou.business.barrel.service.impl;
 
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import static java.util.stream.Collectors.toList;
@@ -59,13 +61,46 @@ public class EquBarrelServiceImpl extends SuperServiceImpl<EquBarrelMapper, EquB
 
         QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
         equBarrelQueryWrap.eq("equ_id", equId);
-        List<EquBarrel> barrelList = this.list(equBarrelQueryWrap);
+        Page<EquBarrel> page = new Page<>(1L, 10);
+        IPage<EquBarrel> list = this.pageList(page, equBarrelQueryWrap);
+        List<EquBarrel> barrelList = list.getRecords();
         System.out.println("查询到的料筒" + JSON.toJSONString(barrelList));
 
 //        查询该设备上的所有商品
         List<EquGoodsDto> equGoodsDtoList = productionTenantResourceService.getEquGoods(equId);
         System.out.println("查询到的设备上的商品" + JSON.toJSONString(equGoodsDtoList));
 
+        //        查询出配方
+        QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
+        formulaQueryWrap.eq("formula_spe_id", speId);
+        List<Formula> formulaList = formulaService.list(formulaQueryWrap);
+        System.out.println("查询到的配方" + JSON.toJSONString(formulaList));
+
+        if (barrelList != null && formulaList != null){
+            formulaList.forEach(formula -> {
+                Long formulaMtId = formula.getFormulaMtId();
+                BigDecimal formulaMtQuantity = formula.getFormulaMtQuantity();
+                barrelList.forEach(equBarrel -> {
+                    BigDecimal mtrResidue = equBarrel.getMtrResidue();
+                    if (equBarrel.getMtrId().equals(formulaMtId)) {
+                        BigDecimal subtract = mtrResidue.subtract(formulaMtQuantity);
+                        LambdaUpdateWrapper<EquBarrel> equBarrelUpdateWrapper = new LambdaUpdateWrapper<>();
+                        equBarrelUpdateWrapper.set(EquBarrel::getMtrResidue, subtract).eq(EquBarrel::getId, equBarrel.getId());
+                        this.update(null, equBarrelUpdateWrapper);
+                        if (subtract.compareTo(equBarrel.getResidueWarn()) != 1) {
+                            Spe spe = speService.getById(speId);
+                            Long goodsId = spe.getGoodsId();
+                            LambdaUpdateWrapper<EquAndGoods> equAndGoodsUpdateWrapper = new LambdaUpdateWrapper<>();
+                            equAndGoodsUpdateWrapper.eq(EquAndGoods::getEquId, equId).eq(EquAndGoods::getGoodsId, goodsId).set(EquAndGoods::getIsStarving, "0");
+                            equAndGoodsService.update(null, equAndGoodsUpdateWrapper);
+                        }
+                    }
+                });
+            });
+        }
+
+
+        /*
         if (equGoodsDtoList != null && equGoodsDtoList.size() > 0) {
 
             equGoodsDtoList.forEach(equGoodsDto -> {
@@ -122,13 +157,7 @@ public class EquBarrelServiceImpl extends SuperServiceImpl<EquBarrelMapper, EquB
 
 
         }
-
-
-//        查询出配方
-//        QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
-//        formulaQueryWrap.eq("formula_spe_id", speId);
-//        List<Formula> formulaList = formulaService.list(formulaQueryWrap);
-//        System.out.println("查询到的配方" + JSON.toJSONString(formulaList));
+         */
 
 
         //        遍历配方,扣减每种原料的余量