|
@@ -1,5 +1,6 @@
|
|
package com.iamberry.rst.controllers.pts;
|
|
package com.iamberry.rst.controllers.pts;
|
|
|
|
|
|
|
|
+import com.alibaba.dubbo.common.json.JSONObject;
|
|
import com.iamberry.rst.core.page.PagedResult;
|
|
import com.iamberry.rst.core.page.PagedResult;
|
|
import com.iamberry.rst.core.pts.Produce;
|
|
import com.iamberry.rst.core.pts.Produce;
|
|
import com.iamberry.rst.core.pts.PtsBom;
|
|
import com.iamberry.rst.core.pts.PtsBom;
|
|
@@ -9,9 +10,16 @@ import com.iamberry.rst.faces.pts.MachinePartsService;
|
|
import com.iamberry.rst.faces.pts.MachineSupplierService;
|
|
import com.iamberry.rst.faces.pts.MachineSupplierService;
|
|
import com.iamberry.rst.faces.pts.ProduceService;
|
|
import com.iamberry.rst.faces.pts.ProduceService;
|
|
import com.iamberry.rst.faces.pts.PtsBomService;
|
|
import com.iamberry.rst.faces.pts.PtsBomService;
|
|
|
|
+import com.iamberry.rst.utils.ExcelUtil;
|
|
import com.iamberry.rst.utils.StitchAttrUtil;
|
|
import com.iamberry.rst.utils.StitchAttrUtil;
|
|
import com.iamberry.wechat.tools.ResponseJson;
|
|
import com.iamberry.wechat.tools.ResponseJson;
|
|
import com.iamberry.wechat.tools.ResultInfo;
|
|
import com.iamberry.wechat.tools.ResultInfo;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -20,15 +28,22 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.context.ContextLoader;
|
|
import org.springframework.web.context.ContextLoader;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
import javax.servlet.ServletContext;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
+import java.text.MessageFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import static com.iamberry.rst.util.SmsConfig.SEND_NOTICE;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Created by LJK on 2017/8/29.
|
|
* Created by LJK on 2017/8/29.
|
|
*/
|
|
*/
|
|
@@ -46,6 +61,7 @@ public class AdminMachinePartsController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private PtsBomService ptsBomService;
|
|
private PtsBomService ptsBomService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 进入添加机器零件页面
|
|
* 进入添加机器零件页面
|
|
* **/
|
|
* **/
|
|
@@ -88,6 +104,55 @@ public class AdminMachinePartsController {
|
|
return responseJson;
|
|
return responseJson;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/excelAdd")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public boolean excelAdd(@RequestParam("sourceFile") MultipartFile sourceFile, HttpServletRequest request, HttpServletResponse response)throws IOException {
|
|
|
|
+ //判断文件是否为空
|
|
|
|
+ if (sourceFile==null) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //获取文件名
|
|
|
|
+ String name=sourceFile.getOriginalFilename();
|
|
|
|
+ long size =sourceFile.getSize();
|
|
|
|
+ if (name==null ||("").equals(name) && size==0) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //把spring文件上传的MultipartFile转换成CommonsMultipartFile类型
|
|
|
|
+ CommonsMultipartFile cf= (CommonsMultipartFile)sourceFile; //获取本地存储路径
|
|
|
|
+ File file = new File(ResultInfo.PARTS_EXCEL);
|
|
|
|
+ //创建一个目录 (它的路径名由当前 File 对象指定,包括任一必须的父路径。)
|
|
|
|
+ if (!file.exists()) file.mkdirs();
|
|
|
|
+ //新建一个文件
|
|
|
|
+ File file1 = new File(ResultInfo.PARTS_EXCEL + new Date().getTime() + ".xls");
|
|
|
|
+ //将上传的文件写入新建的文件中
|
|
|
|
+ try {
|
|
|
|
+ cf.getFileItem().write(file1);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取Workbook
|
|
|
|
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file1));
|
|
|
|
+ Workbook wb = null;
|
|
|
|
+
|
|
|
|
+ if (name.endsWith("xls")) {
|
|
|
|
+ wb = new HSSFWorkbook(inputStream);
|
|
|
|
+ } else {
|
|
|
|
+ wb = new XSSFWorkbook(inputStream);
|
|
|
|
+ }
|
|
|
|
+ inputStream.close();
|
|
|
|
+ // 获取Sheet
|
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
|
+ Integer msg = machinePartsService.excelAddMachineParts(sheet);
|
|
|
|
+ if(msg > 0){
|
|
|
|
+ return true;
|
|
|
|
+ }else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取机器零件列表
|
|
* 获取机器零件列表
|
|
*
|
|
*
|