Procházet zdrojové kódy

炼钢计划bug修改。

zhangym před 9 měsíci
rodič
revize
e0e668e250

+ 3 - 3
src/main/java/com/steerinfo/ems/emsprodplanroundweight/controller/EmsProdplanRoundWeightController.java

@@ -104,9 +104,9 @@ public class EmsProdplanRoundWeightController extends BaseRESTfulController {
     	}
       return success();
     }
-    @GetMapping("/restartData")
-    public RESTfulResult aaa() throws ParseException {
-        emsProdplanRoundWeightService.getWeightForLg半年();
+    @GetMapping("/restartData/{day}")
+    public RESTfulResult aaa(@PathVariable String day) throws ParseException {
+        emsProdplanRoundWeightService.getWeightForLg半年( day);
         return success();
     }
 

+ 1 - 1
src/main/java/com/steerinfo/ems/emsprodplanroundweight/service/IEmsProdplanRoundWeightService.java

@@ -20,7 +20,7 @@ import java.text.ParseException;
  */
 public interface IEmsProdplanRoundWeightService extends IBaseService<EmsProdplanRoundWeight, String>{
     public void getWeightForLg() throws ParseException;
-    public void getWeightForLg半年() throws ParseException;
+    public void getWeightForLg半年(String day) throws ParseException;
     public void getWeightForGx() throws ParseException;
 
 }

+ 77 - 39
src/main/java/com/steerinfo/ems/emsprodplanroundweight/service/impl/EmsProdplanRoundWeightServiceImpl.java

@@ -1,5 +1,6 @@
 package com.steerinfo.ems.emsprodplanroundweight.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.steerinfo.ems.Utils.DateUtils;
 import com.steerinfo.feigen.model.GxWeight;
 import com.steerinfo.feigen.model.LgWeight;
@@ -10,6 +11,8 @@ import com.steerinfo.framework.service.impl.BaseServiceImpl;
 import com.steerinfo.ems.emsprodplanroundweight.model.EmsProdplanRoundWeight;
 import com.steerinfo.ems.emsprodplanroundweight.mapper.EmsProdplanRoundWeightMapper;
 import com.steerinfo.ems.emsprodplanroundweight.service.IEmsProdplanRoundWeightService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -39,6 +42,8 @@ public class EmsProdplanRoundWeightServiceImpl extends BaseServiceImpl<EmsProdpl
     private LgWeightFeigenService lgWeightFeigenService;
     @Autowired
     private GxWeightFeigenService gxWeightFeigenService;
+    private static final Logger logger = LoggerFactory.getLogger(EmsProdplanRoundWeightServiceImpl.class);
+
     @Override
     protected IBaseMapper<EmsProdplanRoundWeight, String> getMapper() {
         return emsProdplanRoundWeightMapper;
@@ -54,30 +59,38 @@ public class EmsProdplanRoundWeightServiceImpl extends BaseServiceImpl<EmsProdpl
         Date dt1 = rightNow.getTime();
         String reStr = sdf.format(dt1);
         List<LgWeight> lgWeights = lgWeightFeigenService.QueryWeightforRound(reStr, DateUtils.dateStr(new Date(), "yyyy-MM-dd"));
+        logger.info("获取炼钢计划条数" + lgWeights.size());
         lgWeights.forEach(item -> {
-            EmsProdplanRoundWeight model = new EmsProdplanRoundWeight();
-            model.setFid(item.getFid());
-            model.setLcId(item.getRoundid());
-            model.setQty(item.getWeight());
-            model.setMaterialcode(item.getMaterialcode());
-            model.setMaterialname(item.getMaterialname());
-            model.setProdate(item.getProdate());
-            model.setUnit(item.getUnit());
-            //fid有重复
-//            EmsProdplanRoundWeight emsProdplanRoundWeight = emsProdplanRoundWeightMapper.selectByPrimaryKey(model.getFid());
-            Map<String,Object> map =  new HashMap();
-            map.put("fid",model.getFid());
-            map.put("lcId",model.getLcId());
-            List<EmsProdplanRoundWeight> emsProdplanRoundWeights = emsProdplanRoundWeightMapper.selectByParameters(map);
-            for(EmsProdplanRoundWeight emsProdplanRoundWeight:emsProdplanRoundWeights){
+            try{
+                EmsProdplanRoundWeight model = new EmsProdplanRoundWeight();
+                model.setFid(item.getFid());
+                model.setLcId(item.getRoundid());
+                model.setQty(item.getWeight());
+                model.setMaterialcode(item.getMaterialcode());
+                model.setMaterialname(item.getMaterialname());
+                model.setProdate(item.getProdate());
+                model.setUnit(item.getUnit());
+                model.setRemark("");
+                //fid有重复
+                //            EmsProdplanRoundWeight emsProdplanRoundWeight = emsProdplanRoundWeightMapper.selectByPrimaryKey(model.getFid());
+                Map<String,Object> map =  new HashMap();
+                map.put("fid",model.getFid());
+                map.put("lcId",model.getLcId());
+                List<EmsProdplanRoundWeight> emsProdplanRoundWeights = emsProdplanRoundWeightMapper.selectByParameters(map);
+                EmsProdplanRoundWeight emsProdplanRoundWeight =null;
+                if(emsProdplanRoundWeights.size()>0) {
+                    emsProdplanRoundWeight = emsProdplanRoundWeights.get(0);
+                }
                 if(emsProdplanRoundWeight !=  null){
+                    emsProdplanRoundWeight.setQty(item.getWeight());
                     emsProdplanRoundWeightMapper.updateByPrimaryKeySelective(emsProdplanRoundWeight);
-                }
-                else {
+                }else {
                     emsProdplanRoundWeightMapper.insert(model);
                 }
+            }catch (Exception e) {
+                logger.info("本次获取炼钢计划出错" + JSONObject.toJSONString(item));
+                e.printStackTrace();
             }
-
         });
 
     }
@@ -111,41 +124,66 @@ public class EmsProdplanRoundWeightServiceImpl extends BaseServiceImpl<EmsProdpl
             }
         });
     }
-    //获取炼钢计划的重量
-    public void getWeightForLg半年() throws ParseException {
+    //获取炼钢计划的重量(可以指定生成哪段时间的)
+    public void getWeightForLg半年(String day) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date dt = sdf.parse(DateUtils.dateStr(new Date(), "yyyy-MM-dd"));
         Calendar rightNow = Calendar.getInstance();
         rightNow.setTime(dt);
-        rightNow.add(Calendar.DAY_OF_MONTH, -150);
+        rightNow.add(Calendar.DAY_OF_MONTH, -(Integer.parseInt(day)));
         Date dt1 = rightNow.getTime();
         String reStr = sdf.format(dt1);
         List<LgWeight> lgWeights = lgWeightFeigenService.QueryWeightforRound(reStr, DateUtils.dateStr(new Date(), "yyyy-MM-dd"));
+        logger.info("获取炼钢计划条数" + lgWeights.size());
         lgWeights.forEach(item -> {
-            EmsProdplanRoundWeight model = new EmsProdplanRoundWeight();
-            model.setFid(item.getFid());
-            model.setLcId(item.getRoundid());
-            model.setQty(item.getWeight());
-            model.setMaterialcode(item.getMaterialcode());
-            model.setMaterialname(item.getMaterialname());
-            model.setProdate(item.getProdate());
-            model.setUnit(item.getUnit());
-            //fid有重复
-//            EmsProdplanRoundWeight emsProdplanRoundWeight = emsProdplanRoundWeightMapper.selectByPrimaryKey(model.getFid());
-            Map<String,Object> map =  new HashMap();
-            map.put("fid",model.getFid());
-            map.put("lcId",model.getLcId());
-            List<EmsProdplanRoundWeight> emsProdplanRoundWeights = emsProdplanRoundWeightMapper.selectByParameters(map);
-            for(EmsProdplanRoundWeight emsProdplanRoundWeight:emsProdplanRoundWeights){
+            try{
+                EmsProdplanRoundWeight model = new EmsProdplanRoundWeight();
+                model.setFid(item.getFid());
+                model.setLcId(item.getRoundid());
+                model.setQty(item.getWeight());
+                model.setMaterialcode(item.getMaterialcode());
+                model.setMaterialname(item.getMaterialname());
+                model.setProdate(item.getProdate());
+                model.setUnit(item.getUnit());
+                model.setRemark("");
+                //fid有重复
+    //            EmsProdplanRoundWeight emsProdplanRoundWeight = emsProdplanRoundWeightMapper.selectByPrimaryKey(model.getFid());
+                Map<String,Object> map =  new HashMap();
+                map.put("fid",model.getFid());
+                map.put("lcId",model.getLcId());
+                logger.info("查询参数" + JSONObject.toJSONString(map));
+                List<EmsProdplanRoundWeight> emsProdplanRoundWeights = emsProdplanRoundWeightMapper.selectByParameters(map);
+                logger.info("查询结果" + JSONObject.toJSONString(emsProdplanRoundWeights));
+                EmsProdplanRoundWeight emsProdplanRoundWeight =null;
+                if(emsProdplanRoundWeights.size()>0) {
+                    emsProdplanRoundWeight = emsProdplanRoundWeights.get(0);
+                }
                 if(emsProdplanRoundWeight !=  null){
+                    emsProdplanRoundWeight.setQty(item.getWeight());
                     emsProdplanRoundWeightMapper.updateByPrimaryKeySelective(emsProdplanRoundWeight);
-                }
-                else {
+                    logger.info("更新" );
+                }else {
                     emsProdplanRoundWeightMapper.insert(model);
+                    logger.info("插入" );
                 }
+            }catch (Exception e) {
+                logger.info("本次获取炼钢计划出错" + JSONObject.toJSONString(item));
+                e.printStackTrace();
             }
-
         });
 
     }
+
+    public static void main(String[] args) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date dt = sdf.parse(DateUtils.dateStr(new Date(), "yyyy-MM-dd"));
+        Calendar rightNow = Calendar.getInstance();
+        rightNow.setTime(dt);
+        rightNow.add(Calendar.DAY_OF_MONTH, -150);
+        Date dt1 = rightNow.getTime();
+        String reStr = sdf.format(dt1);
+        System.out.println(reStr);
+        System.out.println(DateUtils.dateStr(new Date(), "yyyy-MM-dd"));
+
+    }
 }