Переглянути джерело

1.导入生产计划年数据时自动生成月和天数据

zhangym 1 рік тому
батько
коміт
dff934fe26

+ 111 - 6
src/main/java/com/steerinfo/ems/emsprodplanyear/service/impl/EmsProdplanYearServiceImpl.java

@@ -1,7 +1,11 @@
 package com.steerinfo.ems.emsprodplanyear.service.impl;
 
+import com.steerinfo.auth.utils.JwtUtil;
 import com.steerinfo.ems.Utils.ExcelToolUtils;
 import com.steerinfo.ems.Utils.MarketSlmException;
+import com.steerinfo.ems.emsprodplanmonth.mapper.EmsProdplanMonthMapper;
+import com.steerinfo.ems.emsprodplanmonth.model.EmsProdplanMonth;
+import com.steerinfo.ems.emsprodplanmonth.service.IEmsProdplanMonthService;
 import com.steerinfo.ems.emsprodplanyear.mapper.EmsProdplanYearMapper;
 import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
 import com.steerinfo.ems.emsprodplanyear.service.IEmsProdplanYearService;
@@ -40,6 +44,13 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
     @Autowired
     private EmsProdplanYearMapper emsProdplanYearMapper;
 
+    @Autowired
+    private IEmsProdplanMonthService emsProdplanMonthService;
+
+
+    @Autowired
+    private EmsProdplanMonthMapper emsProdplanMonthMapper;
+
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
 
     @Override
@@ -109,6 +120,8 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
                         continue;
                     } else {
                         this.add(model);
+                        this.createMounth(lsp);
+
                     }
                 }
             } else
@@ -125,6 +138,66 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
         }
         return rs;
     }
+
+    //导入模板后自动生成月数据
+    public void createMounth(List<EmsProdplanYear> lists) throws ParseException {
+        Calendar c = Calendar.getInstance();
+        String unit = "008";
+        String productid = "";
+        String workProcid = "";
+        for (int i = 0; i <= lists.size(); i++) {
+            EmsProdplanMonth maxSqno =  emsProdplanMonthMapper.getMaxSqno();
+            int dayMax = this.getDaysOfMonth(lists.get(i).getYearmonth());
+            Double days = Double.valueOf(dayMax);
+            int[] avgWeight = this.avgWeight(lists.get(i).getWeight().intValue(),dayMax, days);
+            for (int k = 0;k < dayMax;k++) {
+                EmsProdplanMonth monModel = new EmsProdplanMonth();
+                c.setTime(lists.get(i).getYearmonth());
+                c.add(Calendar.DATE, k);
+                monModel.setMay(c.getTime());
+                monModel.setUnit(unit);
+                monModel.setProductid(lists.get(i).getProductid());
+                monModel.setWeightMonth(lists.get(i).getWeight());
+                if (workProcid.equals("")) {
+                    monModel.setWorkprocid(lists.get(i).getLine());
+                } else {
+                    monModel.setWorkprocid(workProcid);
+                    monModel.setWeightMonth(BigDecimal.valueOf(lists.get(i).getWeight().intValue()));
+                }
+                monModel.setWeightOrigin(BigDecimal.valueOf(avgWeight[k]));
+                monModel.setWeightDay(BigDecimal.valueOf(avgWeight[k]));
+                monModel.setKxf_weight(BigDecimal.valueOf(avgWeight[k]));
+                monModel.setYxf_weight(BigDecimal.valueOf(0));
+                monModel.setJxdays("0");
+                monModel.setMemo("根据年计划,系统自动生成。");
+                monModel.setCreateman("系统");
+                monModel.setCreatetime(new Date());
+                monModel.setSqno(maxSqno.getSqno()+k);
+                Map monMap = new HashMap();
+                monMap.put("may",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
+                monMap.put("workprocid","'"+monModel.getWorkprocid()+"'");
+                monMap.put("productid",monModel.getProductid());
+                monMap.put("startTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
+                monMap.put("endTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
+                List<EmsProdplanMonth> monList = emsProdplanMonthMapper.selectByParameters(monMap);
+                if(monList.size()<=0){
+                    EmsProdplanMonth emsProdplanMonth = emsProdplanMonthService.add(monModel);
+                } else {
+                    if((lists.get(i).getParentid().equals("LG") && monModel.getProductid().equals("方坯")) || lists.get(i).getParentid().equals("JJZ")) {
+                        //|| model.getParentid().equals("FDC")
+                        monModel.setKxf_weight(monList.get(0).getKxf_weight().add(monModel.getKxf_weight()));
+                        monModel.setWeightMonth(monList.get(0).getWeightMonth().add(monModel.getWeightMonth()));
+                        monModel.setWeightDay(monList.get(0).getWeightDay().add(monModel.getWeightDay()));
+                        monModel.setWeightOrigin(monList.get(0).getWeightOrigin().add(monModel.getWeightOrigin()));
+                        monModel.setId(monList.get(0).getId());
+                        emsProdplanMonthService.modify(monModel);
+                    }
+                }
+            }
+
+
+        }
+    }
     public  List<EmsProdplanYear> createCheckCar(File file ) throws Exception, IOException {
         UserPayload payload = UserPayload.getCurrUser();
         FileInputStream is = null;
@@ -184,17 +257,20 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
                         // 烧结else
                         if (arr1[k].trim().indexOf("1#烧结") != -1) {
                             spp.setParentid("SJ");
+                            spp.setProductid("烧结矿");
                             spp.setLine("AT3013");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("2#烧结") != -1) {
                             spp.setParentid("SJ");
                             spp.setLine("AT3014");
+                            spp.setProductid("烧结矿");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("3#烧结") != -1) {
                             spp.setParentid("SJ");
                             spp.setLine("AT3015");
+                            spp.setProductid("烧结矿");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         }
@@ -202,59 +278,75 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
                         else if (arr1[k].trim().indexOf("1#高炉") != -1) {
                             spp.setParentid("LT");
                             spp.setLine("AT3001");
+                            spp.setProductid("生铁");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("2#高炉") != -1) {
                             spp.setParentid("LT");
                             spp.setLine("AT3002");
+                            spp.setProductid("生铁");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("3#高炉") != -1) {
                             spp.setParentid("LT");
                             spp.setLine("AT3003");
+                            spp.setProductid("生铁");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("4#高炉") != -1) {
                             spp.setParentid("LT");
                             spp.setLine("AT3004");
+                            spp.setProductid("生铁");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         }
                         // 钢坯
                         else if ("供高线一车间方坯".equals(arr1[k].trim())) {
                             spp.setParentid("LG");
-                            spp.setLine("AT2005-1");
+                            //spp.setLine("AT2005-1");
+                            spp.setLine("AT2004");
+                            spp.setProductid("供高线一车间");
+                            spp.setProductid("方坯");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("供高线二车间方坯".equals(arr1[k].trim())) {
                             spp.setParentid("LG");
-                            spp.setLine("AT2006-1");
+                            //spp.setLine("AT2006-1");
+                            spp.setLine("AT2004");
+                            spp.setProductid("方坯");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("异形坯".equals(arr1[k].trim())) {
                             spp.setParentid("LG");
-                            spp.setLine("AT2007-1");
+                            //spp.setLine("AT2007-1");
+                            spp.setLine("AT2004");
+                            spp.setProductid("异形坯");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("外销方坯".equals(arr1[k].trim())) {
                             spp.setParentid("LG");
-                            spp.setLine("AT3008-1");
+                            //spp.setLine("AT3008-1");
+                            spp.setLine("AT3008");
                             spp.setUnit("吨");
+                            spp.setProductid("外销方坯");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         }
                         // 钢轧厂
                         else if ("高线一车间".equals(arr1[k].trim())) {
                             spp.setParentid("ZG");
                             spp.setLine("AT2005");
+                            spp.setProductid("线材");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("高线二车间".equals(arr1[k].trim())) {
                             spp.setParentid("ZG");
                             spp.setLine("AT2006");
+                            spp.setProductid("线材");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("H型钢".equals(arr1[k].trim())) {
                             spp.setParentid("ZG");
+                            spp.setProductid("H型钢");
                             spp.setLine("AT2007");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
@@ -366,74 +458,87 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
                             spp.setParentid("FDC");
                             spp.setLine("AT4002");
                             spp.setUnit("Kwh");
+                            spp.setProductid("发电量");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("45MW") != -1) {
                             spp.setParentid("FDC");
                             spp.setLine("AT4003");
+                            spp.setProductid("发电量");
                             spp.setUnit("Kwh");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("25MW煤气") != -1) {
                             spp.setParentid("FDC");
                             spp.setLine("AT4001");
+                            spp.setProductid("发电量");
                             spp.setUnit("Kwh");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("15MW") != -1) {
                             spp.setParentid("FDC");
                             spp.setLine("AT4004");
+                            spp.setProductid("发电量");
                             spp.setUnit("Kwh");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("25MW干熄焦") != -1) {
                             spp.setParentid("FDC");
                             spp.setLine("AT4009");
+                            spp.setProductid("发电量");
                             spp.setUnit("Kwh");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("TRT") != -1) {
                             spp.setParentid("FDC");
                             spp.setLine("AT3022");
+                            spp.setProductid("发电量");
                             spp.setUnit("Kwh");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         }
                         // 机焦副产品
                         else if ("焦油".equals(arr1[k].trim())) {
+                            spp.setProductid("焦油");
                             spp.setParentid("JJF");
                             spp.setLine("AT3024");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("粗笨".equals(arr1[k].trim())) {
                             spp.setParentid("JJF");
+                            spp.setProductid("粗笨");
                             spp.setLine("AT3009");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("硫铵".equals(arr1[k].trim())) {
                             spp.setParentid("JJF");
+                            spp.setProductid("硫铵");
                             spp.setLine("AT3010");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("硫酸".equals(arr1[k].trim())) {
                             spp.setParentid("JJF");
+                            spp.setProductid("硫酸");
                             spp.setLine("AT3025");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("洗煤".equals(arr1[k].trim())) {
                             spp.setParentid("JJH");
-                            spp.setProductid("AT2012");
+                            spp.setLine("AT2012");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         }
                         // 建材
                         else if (arr1[k].trim().indexOf("1#回转窑") != -1) {
                             spp.setParentid("JCS");
+                            spp.setProductid("白灰粉");
                             spp.setLine("AT3011");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if (arr1[k].trim().indexOf("2#回转窑") != -1) {
                             spp.setParentid("JCS");
+                            spp.setProductid("白灰粉");
                             spp.setLine("AT3012");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else if ("矿渣粉".equals(arr1[k].trim())) {
                             spp.setParentid("JCW");
-                            spp.setProductid("AT2014");
+                            spp.setProductid("矿渣粉");
+                            spp.setLine("AT2014");
                             spp.setUnit("吨");
                             spp.setWeight(new BigDecimal(arr[k].trim()).setScale(0, BigDecimal.ROUND_HALF_UP));
                         } else {