|
@@ -1,16 +1,24 @@
|
|
|
package com.steerinfo.ems.emsprodplanyear.service.impl;
|
|
|
|
|
|
+import com.steerinfo.ems.Utils.ExcelToolUtils;
|
|
|
+import com.steerinfo.ems.Utils.MarketSlmException;
|
|
|
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.controller.RESTfulResult;
|
|
|
import com.steerinfo.framework.mapper.IBaseMapper;
|
|
|
import com.steerinfo.framework.service.impl.BaseServiceImpl;
|
|
|
+import com.steerinfo.framework.user.UserPayload;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* EmsProdplanYear服务实现:
|
|
@@ -81,4 +89,300 @@ public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear,
|
|
|
weightArr[day-1] =sumWeight - (avgWeight * ( day - 1));
|
|
|
return weightArr;
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public RESTfulResult insertexcel(File file) throws Exception {
|
|
|
+ RESTfulResult rs = new RESTfulResult("200", "数据导入成功,不规范数据已自动剔除");
|
|
|
+ rs.setCode("200");
|
|
|
+ List<EmsProdplanYear> lsp = null;
|
|
|
+ try {
|
|
|
+ lsp = createCheckCar(file);
|
|
|
+ if (lsp.size()>0)
|
|
|
+ {
|
|
|
+ int spm = emsProdplanYearMapper.batchInsert(lsp);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rs.setMessage("导入失败,导入数据已经存在!");
|
|
|
+ rs.setCode("500");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ rs.setCode("500");
|
|
|
+ rs.setMessage(e.getMessage());
|
|
|
+ } finally {
|
|
|
+
|
|
|
+ }
|
|
|
+ return rs;
|
|
|
+ }
|
|
|
+ public List<EmsProdplanYear> createCheckCar(File file ) throws Exception, IOException {
|
|
|
+ UserPayload payload = UserPayload.getCurrUser();
|
|
|
+ FileInputStream is = null;
|
|
|
+ String fileName = file.getName();
|
|
|
+ // 解决fileName兼容性问题
|
|
|
+ int lastindex = fileName.lastIndexOf("\\");
|
|
|
+ fileName = fileName.substring(lastindex + 1);
|
|
|
+ List<EmsProdplanYear> lists = new ArrayList<>();
|
|
|
+ if (fileName != null && fileName.length() > 0) {
|
|
|
+ is = new FileInputStream(file);
|
|
|
+ }
|
|
|
+ List<List<String[]>> list = ExcelToolUtils.parseExcels(is, fileName, 0);
|
|
|
+
|
|
|
+ // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ String name = fileName.substring(2, 4);
|
|
|
+ for (int i = 1; i < list.size(); i++) {
|
|
|
+ for(int j = 1; j < list.get(i).size(); j++) {
|
|
|
+ String[] arr = list.get(i).get(j);
|
|
|
+ String[] arr1 = list.get(i).get(0);
|
|
|
+ //String steel = emsGmPcJhMapper.selectsteelcode(arr[1], arr[0]);
|
|
|
+ //
|
|
|
+ //String heat = emsGmPcJhMapper.selectheatno(arr[0]);
|
|
|
+
|
|
|
+ EmsProdplanYear spp = new EmsProdplanYear();
|
|
|
+ ////查询是已经有数据了,有数据不执行导入功能
|
|
|
+ //String v1 = emsGmPcJhMapper.select4(arr[0]);
|
|
|
+ //if (Integer.valueOf(v1)>0) {
|
|
|
+ // continue;
|
|
|
+ //}
|
|
|
+ //AT2005 = "G-G1-";
|
|
|
+ //AT2006 = "G-G2-";
|
|
|
+ //AT2004 = "G-L1-";
|
|
|
+ //AT2007 = "G-X1-";
|
|
|
+ //Pattern pattern = Pattern.compile("^-?[0-9]+"); //这个也行
|
|
|
+ //Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");//这个也行
|
|
|
+ //正整数
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ if(arr[0].length()>8 || !pattern.matcher(arr[0]).matches()){
|
|
|
+ throw new MarketSlmException(500,"排产日期(编号)有误!");
|
|
|
+ }
|
|
|
+ StringBuffer s=new StringBuffer(arr[0]).insert(4,"-").insert(7,"-");
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ simpleDateFormat.setLenient(false);
|
|
|
+ //spp.setJhTime(simpleDateFormat.parse(s.toString()));
|
|
|
+ spp.setStartTime(arr[0]);
|
|
|
+ //switch (name) {
|
|
|
+ // case "型钢" :
|
|
|
+ // if(arr[1].contains("一")){
|
|
|
+ // spp.setType("G-X1-");
|
|
|
+ // spp.setWorkprocType("AT2007");
|
|
|
+ // } else {
|
|
|
+ // spp.setType("G-X2-");
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ // case "钢坯" :
|
|
|
+ // spp.setType("G-L1-");
|
|
|
+ // spp.setWorkprocType("AT2004");
|
|
|
+ // break;
|
|
|
+ // case "高线" :
|
|
|
+ // if(arr[1].contains("一")){
|
|
|
+ // spp.setType("G-G1-");
|
|
|
+ // spp.setWorkprocType("AT2005");
|
|
|
+ // } else {
|
|
|
+ // spp.setType("G-G2-");
|
|
|
+ // spp.setWorkprocType("AT2006");
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ // default: throw new Exception("请选择模板文件");
|
|
|
+ //}
|
|
|
+ String maxid = "";
|
|
|
+ String strh =maxid.substring(maxid.length() -2,maxid.length());
|
|
|
+ Integer seq = Integer.parseInt(strh)+(i-1);
|
|
|
+ spp.setId(maxid.replace("-"+strh,seq<10?"-0"+seq.toString():"-"+seq.toString()));
|
|
|
+ //spp.setState("0");
|
|
|
+ //spp.setCreateMan(payload.getUserName());
|
|
|
+ //spp.setCreateTime(new Date());
|
|
|
+ //spp.setUnitid("008");
|
|
|
+ //for(int j =1;j<arr1.length;j++) {
|
|
|
+ // switch (arr1[j].trim()) {
|
|
|
+ // case "规格" :
|
|
|
+ // spp.setSpecifications(arr[j]);
|
|
|
+ // break;
|
|
|
+ // case "钢种" :
|
|
|
+ // spp.setGrades(arr[j]);
|
|
|
+ // break;
|
|
|
+ // case "长度" :
|
|
|
+ // spp.setLengths(new BigDecimal(arr[j]));
|
|
|
+ // break;
|
|
|
+ // case "运输方式" :
|
|
|
+ // spp.setTransportType(arr[j]);
|
|
|
+ // break;
|
|
|
+ // case "用途" :
|
|
|
+ // spp.setPurpose(arr[j]);
|
|
|
+ // break;
|
|
|
+ // case "订单量" :
|
|
|
+ // if(!pattern.matcher(arr[j]).matches()){
|
|
|
+ // throw new MarketSlmException(500,"订单量有误,请仔细检查");
|
|
|
+ // }
|
|
|
+ // spp.setKxfWeight(new BigDecimal(arr[j]));
|
|
|
+ // spp.setYxfWeight(new BigDecimal("0"));
|
|
|
+ // spp.setPlanWeight(new BigDecimal(arr[j]));
|
|
|
+ // break;
|
|
|
+ // case "交货日期" :
|
|
|
+ // spp.setDeliveryDate(simpleDateFormat.parse(arr[j]));
|
|
|
+ // break;
|
|
|
+ // case "备注" :
|
|
|
+ // spp.setMemo(arr[j]);
|
|
|
+ // break;
|
|
|
+ // case "分厂" : continue;
|
|
|
+ // case "应急标识" :
|
|
|
+ // if(arr[j] != null && "应急".equals(arr[j].trim()) ) {
|
|
|
+ // spp.setTag("1");
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // spp.setTag("0");
|
|
|
+ // break;
|
|
|
+ // default:
|
|
|
+ // throw new MarketSlmException(500,"模板文件存在模板外的列,请仔细检查!!");
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //spp.setSteelCode(steel);
|
|
|
+ //spp.setHeatno(heat);
|
|
|
+ //for (int j=2;j<10;j++)
|
|
|
+ //{
|
|
|
+ // if (arr1[j].equals("屈服强度ReH"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("屈服强度R(eH)");
|
|
|
+ // spp.setQltyCd("qy0001");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.size()>0)
|
|
|
+ // {
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ // if (arr1[j].equals("屈服强度ReL"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("屈服强度R(eL)");
|
|
|
+ // spp.setQltyCd("qy0002");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows!=null&&!"".equals(rows.toString()))
|
|
|
+ // {
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ // if (arr1[j].equals("抗拉强度Rm"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("抗拉强度Rm");
|
|
|
+ // spp.setQltyCd("qy0003");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (arr1[j].equals("断后伸长率%"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("断后伸长率%");
|
|
|
+ // spp.setQltyCd("qy0004");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (arr1[j].equals("冲击试验温度"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("冲击试验温度");
|
|
|
+ // spp.setQltyCd("qy0005");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ // if (arr1[j].equals("冷弯"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyCfnm("冷弯");
|
|
|
+ // spp.setQltyCd("qy0009");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+ // if (arr1[j].equals("冲击吸收功J1"))
|
|
|
+ // {
|
|
|
+ // spp.setQltyVal1(arr[j]);
|
|
|
+ // spp.setQltyVal2(arr[j+1]);
|
|
|
+ // spp.setQltyVal3(arr[j+2]);
|
|
|
+ // spp.setQltyCfnm("冲击");
|
|
|
+ // spp.setQltyCd("qy0006");
|
|
|
+ // List<Map<String,Object>> rows = qcmQltyJudgeMapper.selectstd(spp.getSteelCode(), spp.getQltyCd());
|
|
|
+ // if(rows.get(0).get("QLTY_MIN")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMin(rows.get(0).get("QLTY_MIN").toString());
|
|
|
+ // }
|
|
|
+ // if(rows.get(0).get("QLTY_MAX")!=null)
|
|
|
+ // {
|
|
|
+ // spp.setQltyMax(rows.get(0).get("QLTY_MAX").toString());
|
|
|
+ // }
|
|
|
+ // EmsGmPcJh spp1 = new EmsGmPcJh();
|
|
|
+ // BeanUtils.copyProperties(spp,spp1);
|
|
|
+ // lists.add(spp1);
|
|
|
+ // }
|
|
|
+
|
|
|
+ //}
|
|
|
+ lists.add(spp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e){
|
|
|
+ throw new MarketSlmException(500,"导入失败,请检查文档中是否有错误数据。");
|
|
|
+ }
|
|
|
+ return lists;
|
|
|
+ }
|
|
|
}
|