Explorar el Código

Merge branch 'master' of https://git.steerinfo.com/XTEMS/xt-ems-api

lirl hace 3 años
padre
commit
1679a57a27

+ 31 - 0
src/main/java/com/steerinfo/ems/Utils/DateUtils.java

@@ -130,6 +130,13 @@ public class DateUtils {
         return list;
     }
 
+    /**
+     * 自动补全日期并返回新日期 偏移量自定义
+     *
+     * @param time 时间
+     * @param interval 偏移量
+     * @return
+     */
     public static String changeTime(String time,int interval){
         Calendar dd = Calendar.getInstance();
         try{
@@ -229,4 +236,28 @@ public class DateUtils {
         }
         return reStr ;
     }
+
+    /**
+     * 根据月份得到当月天数
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int getDaysOfMonth(String date) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(sdf.parse(date));
+        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+    }
+    /**
+     * 根据月份得到当月天数
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int getDaysOfMonth(Date date) throws ParseException {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+    }
 }

+ 11 - 12
src/main/java/com/steerinfo/ems/emsprodplanmonth/controller/EmsProdplanMonthController.java

@@ -1,24 +1,20 @@
 package com.steerinfo.ems.emsprodplanmonth.controller;
 
 import com.steerinfo.auth.utils.JwtUtil;
+import com.steerinfo.ems.Utils.DateUtils;
 import com.steerinfo.ems.emsprodplanmonth.mapper.EmsProdplanMonthMapper;
-import com.steerinfo.ems.emsprodplanround.model.EmsProdplanRound;
+import com.steerinfo.ems.emsprodplanmonth.model.EmsProdplanMonth;
+import com.steerinfo.ems.emsprodplanmonth.service.IEmsProdplanMonthService;
 import com.steerinfo.ems.emsprodplanround.service.IEmsProdplanRoundService;
-import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
 import com.steerinfo.ems.trmworkproc.mapper.TRmWorkprocMapper;
 import com.steerinfo.ems.trmworkproc.model.TRmWorkproc;
-import com.steerinfo.ems.trmworkproc.service.ITRmWorkprocService;
 import com.steerinfo.framework.controller.BaseRESTfulController;
 import com.steerinfo.framework.controller.RESTfulResult;
 import com.steerinfo.framework.service.pagehelper.PageList;
 import com.steerinfo.framework.utils.collection.ListUtils;
-import com.steerinfo.ems.emsprodplanmonth.model.EmsProdplanMonth;
-import com.steerinfo.ems.emsprodplanmonth.service.IEmsProdplanMonthService;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -26,7 +22,6 @@ import org.springframework.web.bind.annotation.*;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
-import java.math.BigDecimal;
 
 /**
  * EmsProdplanMonth RESTful接口:
@@ -64,7 +59,7 @@ public class EmsProdplanMonthController extends BaseRESTfulController {
     })
     //@RequiresPermissions("emsprodplanmonth:view")
     @GetMapping(value = "/")
-    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
+    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize) throws ParseException {
         if(parmas.containsKey("workprocid") && parmas.get("workprocid") != null && !"".equals(parmas.get("workprocid").toString())){
         String  workprocid =  parmas.get("workprocid").toString();
         if(!workprocid.startsWith(",")){
@@ -72,6 +67,8 @@ public class EmsProdplanMonthController extends BaseRESTfulController {
         }
             parmas.put("workprocid",workprocid);
         }
+        parmas.put("startTime",parmas.get("startTime")+"-01");
+        parmas.put("endTime",parmas.get("endTime").toString()+DateUtils.getDaysOfMonth(parmas.get("endTime").toString()));
         PageList<EmsProdplanMonth> list = emsProdplanMonthService.queryForPage(parmas, pageNum, pageSize);
         return success(list);
     }
@@ -100,12 +97,14 @@ public class EmsProdplanMonthController extends BaseRESTfulController {
             model.setCreateman(userId);
             model.setCreatetime(new Date());
             Map map = new HashMap();
-            map.put("may",new SimpleDateFormat("yyyy-MM").format(model.getMay()));
-            map.put("workprocid",model.getWorkprocid());
+            map.put("may",new SimpleDateFormat("yyyy-MM-dd").format(model.getMay()));
+            map.put("workprocid","'"+model.getWorkprocid()+"'");
             map.put("productid",model.getProductid());
+            map.put("startTime",new SimpleDateFormat("yyyy-MM-dd").format(model.getMay()));
+            map.put("endTime",new SimpleDateFormat("yyyy-MM-dd").format(model.getMay()));
             List list = emsProdplanMonthMapper.selectByParameters(map);
             if(list.size()>0){
-                return failed(null,"该月时间段数据已生成,无法再次生成");
+                return failed(null,"该数据已生成,无法再次生成");
             }
             EmsProdplanMonth maxSqno = emsProdplanMonthService.getMaxSqno();
             model.setSqno(maxSqno.getSqno());

+ 2 - 2
src/main/java/com/steerinfo/ems/emsprodplanmonth/mapper/EmsProdplanMonthMapper.xml

@@ -5,7 +5,7 @@
     <id column="ID" jdbcType="VARCHAR" property="id" />
     <result column="PRODUCTID" jdbcType="VARCHAR" property="productid" />
     <result column="WORKPROCID" jdbcType="VARCHAR" property="workprocid" />
-    <result column="MAY" jdbcType="DATE" property="may" />
+    <result column="MAY" jdbcType="TIMESTAMP" property="may" />
     <result column="WEIGHT_MONTH" jdbcType="DECIMAL" property="weightMonth" />
     <result column="WEIGHT_DAY" jdbcType="DECIMAL" property="weightDay" />
     <result column="UNIT" jdbcType="VARCHAR" property="unit" />
@@ -74,7 +74,7 @@
         and STATE = #{state}
       </if>
       <if test="startTime != null and startTime != '' and endTime != null and endTime != '' ">
-       and  MAY  between  to_date(#{startTime},'yyyy-mm') and to_date(#{endTime},'yyyy-mm')
+       and  MAY  between  to_date(#{startTime},'yyyy-mm-dd') and to_date(#{endTime},'yyyy-mm-dd')
       </if>
     </where>
     ORDER  BY SQNO

+ 1 - 3
src/main/java/com/steerinfo/ems/emsprodplanmonth/model/EmsProdplanMonth.java

@@ -1,8 +1,6 @@
 package com.steerinfo.ems.emsprodplanmonth.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.steerinfo.framework.model.IBasePO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -33,7 +31,7 @@ public class EmsProdplanMonth implements IBasePO<String> {
     /**
      * 月份(MAY,TIMESTAMP,7)
      */
-    @JSONField(format = "yyyy-MM")
+    @JSONField(format = "yyyy-MM-dd")
     @ApiModelProperty(value="月份",required=false)
     private Date may;
 

+ 122 - 3
src/main/java/com/steerinfo/ems/emsprodplanyear/controller/EmsProdplanYearController.java

@@ -1,6 +1,9 @@
 package com.steerinfo.ems.emsprodplanyear.controller;
 
 import com.steerinfo.auth.utils.JwtUtil;
+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;
@@ -13,6 +16,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -40,6 +45,11 @@ public class EmsProdplanYearController extends BaseRESTfulController {
     @Autowired
    private  EmsProdplanYearMapper emsProdplanYearMapper;
 
+    @Autowired
+    private EmsProdplanMonthMapper emsProdplanMonthMapper;
+
+    @Autowired
+    private IEmsProdplanMonthService emsProdplanMonthService;
 
     @ApiOperation(value="获取列表", notes="分页查询")
     @ApiImplicitParams({
@@ -101,8 +111,9 @@ public class EmsProdplanYearController extends BaseRESTfulController {
     @ApiOperation(value="创建", notes="根据EmsProdplanYear对象创建")
     @ApiImplicitParam(name = "emsProdplanYear", value = "详细实体emsProdplanYear", required = true, dataType = "EmsProdplanYear")
     @PostMapping(value = "/", produces  = "application/json;charset=UTF-8")
-    public RESTfulResult add(@RequestBody EmsProdplanYear[] models){
+    public RESTfulResult add(@RequestBody EmsProdplanYear[] models) throws ParseException {
         String userId = JwtUtil.getUseridByToken();
+        Calendar c = Calendar.getInstance();
         for (int i = 0; i < models.length; i++) {
             EmsProdplanYear model = models[i];
             Boolean lineBool = (model.getLine() == null || model.getLine().equals(""))
@@ -124,10 +135,118 @@ public class EmsProdplanYearController extends BaseRESTfulController {
             if (list.size()>0){
                 return  failed(null,"该月时间段数据已生成,无法再次生成");
             }
-
             model.setCjr(userId);
             model.setCjsj(new Date());
-            EmsProdplanYear emsProdplanYear = emsProdplanYearService.add(model);
+            emsProdplanYearService.add(model);
+            int dayMax = emsProdplanYearService.getDaysOfMonth(model.getYearmonth());
+            Integer sumWeight = 0;
+            EmsProdplanMonth maxSqno =  emsProdplanMonthService.getMaxSqno();
+            String unit = "008";
+            String productid = "";
+            String workProcid = "";
+            switch (model.getParentid()) {
+                case "LG":
+                    sumWeight = model.getWeight().intValue();
+                    productid="钢坯";
+                    unit="008";
+                    workProcid = "AT2004";
+                    break;
+                case "LT":
+                    sumWeight = model.getWeight().intValue();
+                    productid="生铁";
+                    unit="008";
+                    break;
+                case "SJ":
+                    sumWeight = model.getWeight().intValue();
+                    productid="烧结矿";
+                    unit="008";
+                    break;
+                case "ZG" :
+                    sumWeight = model.getWeight().intValue();
+                    productid="线材";
+                    if(model.getLine().equals("AT2007")) {
+                        productid="H型钢";
+                    }
+                    unit="008";
+                    break;
+                case "FDC" :
+                    sumWeight = model.getWeight().intValue();
+                    productid="发电量";
+                    unit="006";
+                    break;
+                case "JCS" :
+                    sumWeight = model.getWeight().intValue();
+                    productid="白灰";
+                    unit="008";
+                    break;
+                case "JCW" :
+                    sumWeight = model.getWeight().intValue();
+                    productid="矿渣粉";
+                    unit="008";
+                    workProcid = model.getProductid();
+                    break;
+                case "JJZ" :
+                    sumWeight = model.getWeight1().intValue() + model.getWeight2().intValue();
+                    productid="焦炭";
+                    unit="008";
+                    workProcid = "AT1007";
+                    break;
+                case "JJF" :
+                    sumWeight = model.getWeight().intValue();
+                    productid="焦油";
+                    if(model.getLine().equals("AT3009")){
+                        productid="粗苯";
+                    }
+                    if(model.getLine().equals("AT3010")){
+                        productid="硫铵";
+                    }
+                    unit="008";
+                    //workProcid = "AT1007";
+                    break;
+                default: break;
+            }
+            int[] avgWeight = emsProdplanYearService.avgWeight(sumWeight,dayMax);
+            for (int k = 0;k < dayMax;k++) {
+                EmsProdplanMonth monModel = new EmsProdplanMonth();
+                c.setTime(model.getYearmonth());
+                c.add(Calendar.DATE, k);
+                monModel.setMay(c.getTime());
+                monModel.setUnit(unit);
+                monModel.setProductid(productid);
+                monModel.setWeightMonth(model.getWeight());
+                if (workProcid.equals("")) {
+                    monModel.setWorkprocid(model.getLine());
+                } else {
+                    monModel.setWorkprocid(workProcid);
+                    monModel.setWeightMonth(BigDecimal.valueOf(sumWeight));
+                }
+                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(model.getParentid().equals("LG") || model.getParentid().equals("JJZ")) {
+                        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.setId(monList.get(0).getId());
+                        emsProdplanMonthService.modify(monModel);
+                    }
+                }
+            }
         }
         return success();
     }

+ 22 - 3
src/main/java/com/steerinfo/ems/emsprodplanyear/service/IEmsProdplanYearService.java

@@ -1,11 +1,10 @@
 package com.steerinfo.ems.emsprodplanyear.service;
 
-import com.steerinfo.framework.service.IBaseService;
 import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
-import com.steerinfo.framework.service.pagehelper.PageList;
+import com.steerinfo.framework.service.IBaseService;
 
+import java.text.ParseException;
 import java.util.Date;
-import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,4 +39,24 @@ public interface IEmsProdplanYearService extends IBaseService<EmsProdplanYear, S
      */
     List<Map<String, Object>> getDateForProduct(HashMap<String, Object> parmas);
 
+    /**
+     * 获取指定月天数
+     * @param date
+     * @return 天数
+     */
+    int getDaysOfMonth(String date) throws ParseException;
+    /**
+     * 获取指定月天数
+     * @param date
+     * @return 天数
+     */
+    int getDaysOfMonth(Date date) throws ParseException;
+
+    /**
+     * 获取每日平均重量
+     * @param sumWeight 总重量
+     * @param day 天数
+     * @return 每天的数量
+     */
+    public int[] avgWeight(Integer sumWeight,Integer day);
 }

+ 33 - 10
src/main/java/com/steerinfo/ems/emsprodplanyear/service/impl/EmsProdplanYearServiceImpl.java

@@ -1,19 +1,16 @@
 package com.steerinfo.ems.emsprodplanyear.service.impl;
 
-import com.steerinfo.framework.mapper.IBaseMapper;
-import com.steerinfo.framework.service.impl.BaseServiceImpl;
-import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
 import com.steerinfo.ems.emsprodplanyear.mapper.EmsProdplanYearMapper;
+import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
 import com.steerinfo.ems.emsprodplanyear.service.IEmsProdplanYearService;
-import com.steerinfo.framework.service.pagehelper.PageHelper;
-import com.steerinfo.framework.service.pagehelper.PageList;
+import com.steerinfo.framework.mapper.IBaseMapper;
+import com.steerinfo.framework.service.impl.BaseServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import java.util.Date;
-import java.math.BigDecimal;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * EmsProdplanYear服务实现:
@@ -34,6 +31,8 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
     @Autowired
     private EmsProdplanYearMapper emsProdplanYearMapper;
 
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+
     @Override
     protected IBaseMapper<EmsProdplanYear, String> getMapper() {
         return emsProdplanYearMapper;
@@ -58,4 +57,28 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
         return emsProdplanYearMapper.getDateForProduct(parmas);
     }
 
+    @Override
+    public int getDaysOfMonth(String date) throws ParseException {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(sdf.parse(date));
+        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+    }
+
+    @Override
+    public int getDaysOfMonth(Date date) throws ParseException {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+    }
+
+    @Override
+    public int[] avgWeight(Integer sumWeight, Integer day){
+        int[] weightArr = new int[day];
+       Integer avgWeight = sumWeight / day;
+        for(int i = 0;i<day-1;i++){
+            weightArr[i] = avgWeight;
+        }
+        weightArr[day-1] =sumWeight - (avgWeight * ( day - 1));
+        return weightArr;
+    }
 }