Procházet zdrojové kódy

优化代码执行条件

wangyuanbo před 2 roky
rodič
revize
718e22cd74

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

@@ -8,8 +8,10 @@ import com.github.zuihou.business.barrel.entity.EquBarrel;
 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.goods.entity.Goods;
 import com.github.zuihou.business.goods.service.GoodsService;
 import com.github.zuihou.business.member.entity.Member;
+import com.github.zuihou.business.member.service.MemberService;
 import com.github.zuihou.business.miniApp.service.MiniAppService;
 import com.github.zuihou.business.order.entity.Order;
 import com.github.zuihou.business.order.service.OrderService;
@@ -87,6 +89,9 @@ public class AndroidApi {
     private WxPayService wxPayService;
     @Autowired
     private FormulaService formulaService;
+    @Autowired
+    private MemberService memberService;
+
 
 
     @ApiOperation("获取商品列表")
@@ -247,14 +252,26 @@ public class AndroidApi {
 
         Order localOrder = orderService.getById(orderId);
         String localStatus = localOrder.getOrderStatus();
+        Long orderSpecs = localOrder.getOrderSpecs();
+        Long orderGoodsId = localOrder.getOrderGoodsId();
+        Long orderMemberId = localOrder.getOrderMemberId();
+        Spe spe = speService.getById(orderSpecs);
+        Goods goods = goodsService.getById(orderGoodsId);
+        Member member = memberService.getById(orderMemberId);
+        localOrder.setOrderGoodsName(goods.getGoodsName());
+        localOrder.setOrderSpecsName(spe.getSpecName());
+
+
         String newStatus = "";
 
         if (wxStatus.equals("NOTPAY")) {
 //未支付
             newStatus = "0";
+            localOrder.setOrderStatus(newStatus);
         } else if (wxStatus.equals("SUCCESS")) {
 //支付成功
             newStatus = "1";
+            localOrder.setOrderStatus(newStatus);
             Long equId = localOrder.getOrderEquId();
             QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
             formulaQueryWrap.eq("formula_spe_id", localOrder.getOrderSpecs());
@@ -263,14 +280,15 @@ public class AndroidApi {
                 QueryWrap<EquBarrel> barrelQueryWrap = new QueryWrap<>();
                 barrelQueryWrap.eq("mtr_id", item.getFormulaMtId());
                 barrelQueryWrap.eq("equ_id", equId);
-
                 List<EquBarrel> list = barrelService.list(barrelQueryWrap);
                 if (null != list) {
                     item.setBarrelCode(list.get(0).getBarrelCode());
                 }
             });
-            System.out.println("支付成功,配方是"+JSON.toJSONString(formulaList));
+            System.out.println("支付成功,配方是" + JSON.toJSONString(formulaList));
             resultMap.put("productConfig", formulaList);
+            resultMap.put("order", localOrder);
+            resultMap.put("member",member.getMemberName());
         } else if (wxStatus.equals("REFUND")) {
 //转入退款
             newStatus = "5";
@@ -348,7 +366,6 @@ public class AndroidApi {
         BufferedReader reader = null;
 
 
-//        @RequestHeader("Wechatpay-Timestamp") String timestamp, @RequestHeader("Wechatpay-Nonce") String wechatpayNonce, @RequestHeader("Wechatpay-Signature") String signature, @RequestHeader("Wechatpay-Serial") String serial, @RequestBody WxResultDto resultDto
         BaseContextHandler.setTenant("0000");
         HashMap<String, Object> returnMap = new HashMap<>();
         returnMap.put("code", "ERROR");
@@ -456,7 +473,7 @@ public class AndroidApi {
         boolean update = orderService.update(updateWrapper);
 
         if (orderStatus.equals("3")) {
-            System.out.println("订单"+orderId+"生产完成,准备扣减物料");
+            System.out.println("订单" + orderId + "生产完成,准备扣减物料");
             barrelService.updateBarrel(speId, equId);
             return R.success(update);
         }

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

@@ -41,7 +41,8 @@ import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
 import java.util.*;
-import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.toList;
 
 /**
  * 运维小程序接口
@@ -91,8 +92,8 @@ public class OpsAppApi {
         if (null != list.getRecords() && list.getRecords().size() > 0) {
             list.getRecords().stream().forEach(item -> {
                 Map map = productionTenantResourceService.getEquRunInfo(item.getId());
-                item.setOnlineStatus(map.containsKey("equStatus")?map.get("equStatus").toString():"0");
-                item.setErrMsg(map.containsKey("errMsg") && map.get("errMsg")!=null ?map.get("errMsg").toString():"");
+                item.setOnlineStatus(map.containsKey("equStatus") ? map.get("equStatus").toString() : "0");
+                item.setErrMsg(map.containsKey("errMsg") && map.get("errMsg") != null ? map.get("errMsg").toString() : "");
                 Integer lackCount = productionTenantResourceService.getEquLockCount(item.getId());
                 item.setLackCount(lackCount);
             });
@@ -138,11 +139,11 @@ public class OpsAppApi {
         if (productionResourceList.getRecords().size() > 0) {
             productionResource = productionResourceList.getRecords().get(0);
             Map map = productionTenantResourceService.getEquRunInfo(productionResource.getId());
-            productionResource.setOnlineStatus(map.containsKey("equStatus")?map.get("equStatus").toString():"0");
-            productionResource.setErrMsg(map.containsKey("errMsg") && map.get("errMsg")!=null ?map.get("errMsg").toString():"");
+            productionResource.setOnlineStatus(map.containsKey("equStatus") ? map.get("equStatus").toString() : "0");
+            productionResource.setErrMsg(map.containsKey("errMsg") && map.get("errMsg") != null ? map.get("errMsg").toString() : "");
             Integer lackCount = productionTenantResourceService.getEquLockCount(productionResource.getId());
             productionResource.setLackCount(lackCount);
-        }else{
+        } else {
             productionResource = ProductionResource.builder().build();
         }
         return R.success(productionResource);
@@ -286,7 +287,7 @@ public class OpsAppApi {
         List<Long> orgArr = CommonUtil.getOrgIdsArr();
         if (ids.size() > 0 && orgArr.size() > 0) {
             ids = productionTenantResourceService.listByIds(ids).stream().filter(item -> CollectionUtil.contains(orgArr, (Long) item.getOrgId())
-            ).map(item -> item.getId().toString()).collect(Collectors.toList());
+            ).map(item -> item.getId().toString()).collect(toList());
         }
         map.put("exceptDevice", ids.size());
         return R.success(map);
@@ -337,40 +338,62 @@ public class OpsAppApi {
         QueryWrap<EquBarrel> barrelQueryWrap = new QueryWrap<>();
         barrelQueryWrap.eq("equ_id", equRecord.getEquId());
         List<EquBarrel> barrelList = equBarrelService.list(barrelQueryWrap);
+        List<Long> mtList = new ArrayList<>();
+        if (null != barrelList) {
+            mtList = barrelList.stream().map(EquBarrel::getMtrId).collect(toList());
+        }
 
 
 //        遍历商品,查询配方列表
-        equGoods.forEach(equGoodsDto -> {
-            QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
-            speQueryWrap.eq("goods_id", equGoodsDto.getGoodsId());
-            List<Spe> speList = speService.list(speQueryWrap);
-            equGoodsDto.setSpeList(speList);
+        if (equGoods != null) {
+            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);
 //            查询每一个规格的配方列表
-            speList.forEach(spe -> {
-                QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
-                formulaQueryWrap.eq("formula_spe_id", spe.getId());
-                List<Formula> formulaList = formulaService.list(formulaQueryWrap);
-                formulaList.forEach(formula -> {
-                    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", equRecord.getEquId());
-                                equGoodsDto.setIsStarving("1");
-                            } else {
-                                equGoodsDtoUpdateWrapper.set("is_starving", "0");
-                                equGoodsDto.setIsStarving("0");
-                            }
-                            equAndGoodsService.update(equGoodsDtoUpdateWrapper);
+                if (speList != null) {
+                    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() + "相同");
+                                        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", equRecord.getEquId());
+                                            equGoodsDto.setIsStarving("1");
+                                        } else {
+                                            equGoodsDtoUpdateWrapper.set("is_starving", "0");
+                                            equGoodsDto.setIsStarving("0");
+                                        }
+                                        equAndGoodsService.update(equGoodsDtoUpdateWrapper);
+                                    }
+                                });
+                            });
                         }
+                        ;
                     });
-                });
-            });
+                }
+                ;
 
 
-        });
+            });
+        }
+        ;
 
 
 //        遍历配方
@@ -404,4 +427,6 @@ public class OpsAppApi {
     }
 
 
+
+
 }

+ 2 - 1
imcs-bt-be/imcs-authority-server/src/main/resources/bootstrap.yml

@@ -7,7 +7,8 @@ spring:
     active: dev
 logging:
   file:
-    path: /data/projects/logs
+#    path: /data/projects/logs
+    path: D:/data/projects/logs
     name: ${logging.file.path}/${spring.application.name}/root.log
 
 machine:

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

@@ -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 {
+
                     }
 
                 }
+
             }
 
+
         }
 
 

+ 2 - 2
imcs-bt-fe/imcs-bt-fe/imcs-ui/src/views/zuihou/goods/goodsManage/formula.vue

@@ -292,8 +292,8 @@
                 <el-option label="无" value="0"></el-option>
                 <el-option label="注热水" value="1"></el-option>
                 <el-option label="蒸汽加热" value="2"></el-option>
-                <el-option label="搅拌" value="3"></el-option>
-                <el-option label="注冷水" value="4"></el-option>
+<!--                <el-option label="搅拌" value="3"></el-option>-->
+<!--                <el-option label="注冷水" value="4"></el-option>-->
               </el-select>
             </el-form-item>