Procházet zdrojové kódy

重新把 修改物料的逻辑换到正确的换料接口下

wangyuanbo před 2 roky
rodič
revize
f8d18181b5

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

@@ -143,7 +143,7 @@ public class AndroidApi {
         preOrder.setOrderEquId(equId);
         orderService.save(preOrder);
 //        配方信息
-        List<Formula> productConfig = formulaService.list(new QueryWrap<Formula>().eq("formula_spe_id", speId));
+//        List<Formula> productConfig = formulaService.list(new QueryWrap<Formula>().eq("formula_spe_id", speId));
 
 //        小程序码
         Object accessToken = redisTemplate.opsForValue().get("access_token");
@@ -163,7 +163,7 @@ public class AndroidApi {
 
         HashMap<String, Object> resultMap = new HashMap<>();
         resultMap.put("orderId", preOrder.getId());
-        resultMap.put("productCfg", productConfig);
+//        resultMap.put("productCfg", productConfig);
         resultMap.put("qrCode", qrCode);
         System.out.println("安卓端下单返回orderId=" + preOrder.getId());
 
@@ -281,9 +281,10 @@ public class AndroidApi {
                 barrelQueryWrap.eq("mtr_id", item.getFormulaMtId());
                 barrelQueryWrap.eq("equ_id", equId);
                 List<EquBarrel> list = barrelService.list(barrelQueryWrap);
-                if (null != list) {
+                if (null != list&&list.size()>0) {
                     item.setBarrelCode(list.get(0).getBarrelCode());
                 }
+
             });
             System.out.println("支付成功,配方是" + JSON.toJSONString(formulaList));
             resultMap.put("productConfig", formulaList);

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

@@ -303,6 +303,7 @@ 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, DateUtils.getStartTime(equRecord.getDate())).eq(EquBarrel::getId, equRecord.getMaterialId());
@@ -310,30 +311,10 @@ public class OpsAppApi {
         if (bool) {
             bool = equRecordService.save(equRecord);
         }
-        return R.success(bool);
-    }
 
 
-    /**
-     * 换料接口
-     *
-     * @return
-     */
-    @PostMapping("/cupRecordSave")
-    public R<Boolean> cupRecordSave(@RequestBody EquRecord equRecord) {
-        System.out.println("小程序换料接口");
-        BaseContextHandler.setTenant("0000");
-        LambdaUpdateWrapper<EquBarrel> updateWrapper = new LambdaUpdateWrapper();
-        updateWrapper.set(EquBarrel::getMtrResidue, equRecord.getSpecs()).set(EquBarrel::getExprTime, equRecord.getDate())
-                .eq(EquBarrel::getId, equRecord.getMaterialId());
-        Boolean bool = equBarrelService.update(null, updateWrapper);
-        if (bool) {
-            bool = equRecordService.save(equRecord);
-        }
-//        根据设备id查询商品
+        //        根据设备id查询商品
         List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equRecord.getEquId());
-
-
 //        根据设备查询料筒信息
         QueryWrap<EquBarrel> barrelQueryWrap = new QueryWrap<>();
         barrelQueryWrap.eq("equ_id", equRecord.getEquId());
@@ -345,7 +326,7 @@ public class OpsAppApi {
 
 
 //        遍历商品,查询配方列表
-        if (equGoods != null) {
+        if (equGoods != null && equGoods.size() > 0) {
             List<Long> finalMtList = mtList;
             equGoods.forEach(equGoodsDto -> {
                 QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
@@ -353,7 +334,7 @@ public class OpsAppApi {
                 List<Spe> speList = speService.list(speQueryWrap);
                 equGoodsDto.setSpeList(speList);
 //            查询每一个规格的配方列表
-                if (speList != null) {
+                if (speList != null && speList.size() > 0) {
                     speList.forEach(spe -> {
                         QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
                         formulaQueryWrap.eq("formula_spe_id", spe.getId());
@@ -366,8 +347,6 @@ public class OpsAppApi {
                                     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() + "相同");
@@ -389,10 +368,32 @@ public class OpsAppApi {
                     });
                 }
                 ;
+            });
+        }
 
 
-            });
+        return R.success(bool);
+    }
+
+
+    /**
+     * 换料接口
+     *
+     * @return
+     */
+    @PostMapping("/cupRecordSave")
+    public R<Boolean> cupRecordSave(@RequestBody EquRecord equRecord) {
+        System.out.println("小程序换杯、盖接口");
+        BaseContextHandler.setTenant("0000");
+        LambdaUpdateWrapper<EquBarrel> updateWrapper = new LambdaUpdateWrapper();
+        updateWrapper.set(EquBarrel::getMtrResidue, equRecord.getSpecs()).set(EquBarrel::getExprTime, equRecord.getDate())
+                .eq(EquBarrel::getId, equRecord.getMaterialId());
+        Boolean bool = equBarrelService.update(null, updateWrapper);
+        if (bool) {
+            bool = equRecordService.save(equRecord);
         }
+
+
         ;
 
 
@@ -427,6 +428,4 @@ public class OpsAppApi {
     }
 
 
-
-
 }

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

@@ -23,7 +23,6 @@ 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;
@@ -66,16 +65,15 @@ public class EquBarrelServiceImpl extends SuperServiceImpl<EquBarrelMapper, EquB
 //        查询该设备上的所有商品
         List<EquGoodsDto> equGoodsDtoList = productionTenantResourceService.getEquGoods(equId);
 
-        if (equGoodsDtoList != null) {
+        if (equGoodsDtoList != null&&equGoodsDtoList.size()>0) {
             equGoodsDtoList.forEach(equGoodsDto -> {
                 List<Spe> speList = equGoodsDto.getSpeList();
-                if (null != speList) {
+                if (null != speList&&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) {
-
+                        if (formulaList != null&&formulaList.size()>0) {
                             if (barrelList != null) {
                                 List<Long> mtList = barrelList.stream().map(EquBarrel::getMtrId).collect(toList());
                                 formulaList.forEach(formula -> {
@@ -122,59 +120,59 @@ 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));
+//        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) {
-
-
-            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());
-//                    扣减后,余料达到余料预警,更新料筒余料
-                        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);
-//                        更新料筒缺料
-
-
-                        }
-
-                    } else {
-
-                    }
-
-                }
-
-            }
-
-
-        }
+//        if (barrelList != null && formulaList != null) {
+//
+//
+//            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());
+////                    扣减后,余料达到余料预警,更新料筒余料
+//                        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);
+////                        更新料筒缺料
+//
+//
+//                        }
+//
+//                    } else {
+//
+//                    }
+//
+//                }
+//
+//            }
+//
+//
+//        }
 
 
     }