|
|
@@ -1,42 +1,51 @@
|
|
|
package com.jeesite.modules.mes.web;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.jeesite.common.collect.ListUtils;
|
|
|
import com.jeesite.common.collect.MapUtils;
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
import com.jeesite.common.lang.DateUtils;
|
|
|
import com.jeesite.common.lang.ObjectUtils;
|
|
|
import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.common.service.ServiceException;
|
|
|
+import com.jeesite.common.utils.excel.ExcelExport;
|
|
|
+import com.jeesite.common.utils.excel.ExcelImport;
|
|
|
+import com.jeesite.common.utils.excel.annotation.ExcelField;
|
|
|
+import com.jeesite.common.validator.ValidatorUtils;
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
import com.jeesite.modules.file.entity.FileUpload;
|
|
|
import com.jeesite.modules.file.service.FileUploadService;
|
|
|
-import com.jeesite.modules.mes.entity.*;
|
|
|
+import com.jeesite.modules.mes.entity.MesDevice;
|
|
|
+import com.jeesite.modules.mes.entity.MesDeviceConsumableRecord;
|
|
|
+import com.jeesite.modules.mes.entity.MesDeviceState;
|
|
|
+import com.jeesite.modules.mes.entity.MesDeviceUrgency;
|
|
|
+import com.jeesite.modules.mes.entity.excel.ExcelMesDeviceUrgency;
|
|
|
import com.jeesite.modules.mes.resp.CommonResp;
|
|
|
-import com.jeesite.modules.mes.service.MesDeviceAlarmService;
|
|
|
import com.jeesite.modules.mes.service.MesDeviceService;
|
|
|
import com.jeesite.modules.mes.service.MesDeviceStateService;
|
|
|
+import com.jeesite.modules.mes.service.MesDeviceUrgencyService;
|
|
|
import com.jeesite.modules.sys.entity.User;
|
|
|
-import com.jeesite.modules.sys.utils.DictUtils;
|
|
|
import com.jeesite.modules.sys.utils.UserUtils;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import com.jeesite.common.config.Global;
|
|
|
-import com.jeesite.common.entity.Page;
|
|
|
-import com.jeesite.common.web.BaseController;
|
|
|
-import com.jeesite.modules.mes.service.MesDeviceUrgencyService;
|
|
|
-
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.ConstraintViolation;
|
|
|
+import javax.validation.ConstraintViolationException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -347,4 +356,167 @@ public class MesDeviceUrgencyController extends BaseController {
|
|
|
mesDeviceUrgencyService.pdasave(mesDeviceUrgency);
|
|
|
return renderResult(Global.TRUE, text("保存紧急性维修记录成功!"));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 导出数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "exportData")
|
|
|
+ public void exportData(MesDeviceUrgency mesDeviceCate, HttpServletResponse response) {
|
|
|
+ List<MesDeviceUrgency> list = mesDeviceUrgencyService.findList(mesDeviceCate);
|
|
|
+ String fileName = " 紧急性维修记录" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ try(ExcelExport ee = new ExcelExport(" 紧急性维修记录", MesDeviceUrgency.class)){
|
|
|
+ ee.setDataList(list).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 下载模板
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "importTemplate")
|
|
|
+ public void importTemplate(HttpServletResponse response) {
|
|
|
+ MesDeviceUrgency mesDeviceCate = new MesDeviceUrgency();
|
|
|
+ List<MesDeviceUrgency> list = ListUtils.newArrayList(mesDeviceCate);
|
|
|
+ String fileName = " 紧急性维修记录.xlsx";
|
|
|
+ try(ExcelExport ee = new ExcelExport(" 紧急性维修记录", MesDeviceUrgency.class, ExcelField.Type.IMPORT)){
|
|
|
+ ee.setDataList(list).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @PostMapping(value = "importData")
|
|
|
+ public String importData(MultipartFile file,HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ String message = importData1(file,request);
|
|
|
+ return renderResult(Global.TRUE, "posfull:"+message);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Transactional
|
|
|
+ public String importData1(MultipartFile file,HttpServletRequest request) {
|
|
|
+ if (file == null){
|
|
|
+ throw new ServiceException(text("请选择导入的数据文件!"));
|
|
|
+ }
|
|
|
+ int successNum = 0; int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
|
|
+ List<MesDeviceUrgency> list = ei.getDataList(MesDeviceUrgency.class);
|
|
|
+ for (MesDeviceUrgency mesDeviceCheck : list) {
|
|
|
+ try{
|
|
|
+ ValidatorUtils.validateWithException(mesDeviceCheck);
|
|
|
+ this.save(mesDeviceCheck,request);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、编号 " + mesDeviceCheck.getId() + " 导入成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、编号 " + mesDeviceCheck.getId() + " 导入失败:";
|
|
|
+ if (e instanceof ConstraintViolationException){
|
|
|
+ ConstraintViolationException cve = (ConstraintViolationException)e;
|
|
|
+ for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
|
|
+ msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ msg += e.getMessage();
|
|
|
+ }
|
|
|
+ failureMsg.append(msg);
|
|
|
+ logger.error(msg, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage(), e);
|
|
|
+ failureMsg.append(e.getMessage());
|
|
|
+ return failureMsg.toString();
|
|
|
+ }
|
|
|
+ if (failureNum > 0) {
|
|
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
+ }else{
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
+ }
|
|
|
+ return successMsg.toString();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 导出数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "exportData1")
|
|
|
+ public void exportData1(MesDeviceUrgency mesDeviceCate, HttpServletResponse response) {
|
|
|
+ List<MesDeviceUrgency> list = mesDeviceUrgencyService.findList(mesDeviceCate);
|
|
|
+ List<ExcelMesDeviceUrgency> list1= BeanUtil.copyToList(list, ExcelMesDeviceUrgency.class);
|
|
|
+ String fileName = "我的维修记录" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ try(ExcelExport ee = new ExcelExport(" 我的维修记录", ExcelMesDeviceUrgency.class)){
|
|
|
+ ee.setDataList(list1).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 下载模板
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "importTemplate1")
|
|
|
+ public void importTemplate1(HttpServletResponse response) {
|
|
|
+ ExcelMesDeviceUrgency mesDeviceCate = new ExcelMesDeviceUrgency();
|
|
|
+ List<ExcelMesDeviceUrgency> list = ListUtils.newArrayList(mesDeviceCate);
|
|
|
+ String fileName = " 紧急性维修记录.xlsx";
|
|
|
+ try(ExcelExport ee = new ExcelExport(" 紧急性维修记录", ExcelMesDeviceUrgency.class, ExcelField.Type.IMPORT)){
|
|
|
+ ee.setDataList(list).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @PostMapping(value = "importData2")
|
|
|
+ public String importData2(MultipartFile file,HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ String message = importData3(file,request);
|
|
|
+ return renderResult(Global.TRUE, "posfull:"+message);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Transactional
|
|
|
+ public String importData3(MultipartFile file,HttpServletRequest request) {
|
|
|
+ if (file == null){
|
|
|
+ throw new ServiceException(text("请选择导入的数据文件!"));
|
|
|
+ }
|
|
|
+ int successNum = 0; int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
|
|
+ List<MesDeviceUrgency> list = ei.getDataList(MesDeviceUrgency.class);
|
|
|
+ for (MesDeviceUrgency mesDeviceCheck : list) {
|
|
|
+ try{
|
|
|
+ ValidatorUtils.validateWithException(mesDeviceCheck);
|
|
|
+ this.save(mesDeviceCheck,request);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、编号 " + mesDeviceCheck.getId() + " 导入成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、编号 " + mesDeviceCheck.getId() + " 导入失败:";
|
|
|
+ if (e instanceof ConstraintViolationException){
|
|
|
+ ConstraintViolationException cve = (ConstraintViolationException)e;
|
|
|
+ for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
|
|
+ msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ msg += e.getMessage();
|
|
|
+ }
|
|
|
+ failureMsg.append(msg);
|
|
|
+ logger.error(msg, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage(), e);
|
|
|
+ failureMsg.append(e.getMessage());
|
|
|
+ return failureMsg.toString();
|
|
|
+ }
|
|
|
+ if (failureNum > 0) {
|
|
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
+ }else{
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
+ }
|
|
|
+ return successMsg.toString();
|
|
|
+ }
|
|
|
}
|