|
@@ -6,6 +6,7 @@ import com.jeesite.common.collect.ListUtils;
|
|
|
import com.jeesite.common.config.Global;
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.entity.Page;
|
|
import com.jeesite.common.entity.Page;
|
|
|
import com.jeesite.common.lang.DateUtils;
|
|
import com.jeesite.common.lang.DateUtils;
|
|
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
import com.jeesite.common.service.ServiceException;
|
|
import com.jeesite.common.service.ServiceException;
|
|
|
import com.jeesite.common.utils.excel.ExcelExport;
|
|
import com.jeesite.common.utils.excel.ExcelExport;
|
|
|
import com.jeesite.common.utils.excel.ExcelImport;
|
|
import com.jeesite.common.utils.excel.ExcelImport;
|
|
@@ -14,6 +15,7 @@ import com.jeesite.common.validator.ValidatorUtils;
|
|
|
import com.jeesite.common.web.BaseController;
|
|
import com.jeesite.common.web.BaseController;
|
|
|
import com.jeesite.modules.mes.entity.MesDevicePrevent;
|
|
import com.jeesite.modules.mes.entity.MesDevicePrevent;
|
|
|
import com.jeesite.modules.mes.entity.MesDevicePreventForm;
|
|
import com.jeesite.modules.mes.entity.MesDevicePreventForm;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.excel.ExcelMesDevicePrevent;
|
|
|
import com.jeesite.modules.mes.service.MesDevicePreventService;
|
|
import com.jeesite.modules.mes.service.MesDevicePreventService;
|
|
|
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;
|
|
@@ -31,7 +33,10 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.ConstraintViolation;
|
|
import javax.validation.ConstraintViolation;
|
|
|
import javax.validation.ConstraintViolationException;
|
|
import javax.validation.ConstraintViolationException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 预防性维修任务清单Controller
|
|
* 预防性维修任务清单Controller
|
|
@@ -160,8 +165,8 @@ public class MesDevicePreventController extends BaseController {
|
|
|
public void exportData(MesDevicePrevent mesDevicePrevent, HttpServletResponse response) {
|
|
public void exportData(MesDevicePrevent mesDevicePrevent, HttpServletResponse response) {
|
|
|
List<MesDevicePrevent> list = mesDevicePreventService.findList(mesDevicePrevent);
|
|
List<MesDevicePrevent> list = mesDevicePreventService.findList(mesDevicePrevent);
|
|
|
String fileName = "预防性维修任务清单" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
String fileName = "预防性维修任务清单" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
- try(ExcelExport ee = new ExcelExport("预防性维修任务清单", MesDevicePrevent.class)){
|
|
|
|
|
- ee.setDataList(list).write(response, fileName);
|
|
|
|
|
|
|
+ try(ExcelExport ee = new ExcelExport("预防性维修任务清单", ExcelMesDevicePrevent.class)){
|
|
|
|
|
+ ee.setDataList(buildExportRows(list)).write(response, fileName);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
@@ -169,10 +174,10 @@ public class MesDevicePreventController extends BaseController {
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping(value = "importTemplate")
|
|
@RequestMapping(value = "importTemplate")
|
|
|
public void importTemplate(HttpServletResponse response) {
|
|
public void importTemplate(HttpServletResponse response) {
|
|
|
- MesDevicePrevent mesDeviceCate = new MesDevicePrevent();
|
|
|
|
|
- List<MesDevicePrevent> list = ListUtils.newArrayList(mesDeviceCate);
|
|
|
|
|
|
|
+ ExcelMesDevicePrevent mesDeviceCate = new ExcelMesDevicePrevent();
|
|
|
|
|
+ List<ExcelMesDevicePrevent> list = ListUtils.newArrayList(mesDeviceCate);
|
|
|
String fileName = "预防性维修任务清单.xlsx";
|
|
String fileName = "预防性维修任务清单.xlsx";
|
|
|
- try(ExcelExport ee = new ExcelExport("预防性维修任务清单", MesDevicePrevent.class, ExcelField.Type.IMPORT)){
|
|
|
|
|
|
|
+ try(ExcelExport ee = new ExcelExport("预防性维修任务清单", ExcelMesDevicePrevent.class, ExcelField.Type.IMPORT)){
|
|
|
ee.setDataList(list).write(response, fileName);
|
|
ee.setDataList(list).write(response, fileName);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -199,7 +204,7 @@ public class MesDevicePreventController extends BaseController {
|
|
|
StringBuilder successMsg = new StringBuilder();
|
|
StringBuilder successMsg = new StringBuilder();
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
|
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
|
|
- List<MesDevicePrevent> list = ei.getDataList(MesDevicePrevent.class);
|
|
|
|
|
|
|
+ List<MesDevicePrevent> list = buildImportList(ei.getDataList(ExcelMesDevicePrevent.class));
|
|
|
for (MesDevicePrevent mesDeviceCheck : list) {
|
|
for (MesDevicePrevent mesDeviceCheck : list) {
|
|
|
try{
|
|
try{
|
|
|
ValidatorUtils.validateWithException(mesDeviceCheck);
|
|
ValidatorUtils.validateWithException(mesDeviceCheck);
|
|
@@ -234,4 +239,81 @@ public class MesDevicePreventController extends BaseController {
|
|
|
}
|
|
}
|
|
|
return successMsg.toString();
|
|
return successMsg.toString();
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private List<ExcelMesDevicePrevent> buildExportRows(List<MesDevicePrevent> list) {
|
|
|
|
|
+ List<ExcelMesDevicePrevent> rows = new ArrayList<>();
|
|
|
|
|
+ for (MesDevicePrevent item : list) {
|
|
|
|
|
+ MesDevicePrevent full = mesDevicePreventService.get(item);
|
|
|
|
|
+ if (full == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<MesDevicePreventForm> formList = full.getMesDevicePreventFormList();
|
|
|
|
|
+ if (ListUtils.isEmpty(formList)) {
|
|
|
|
|
+ rows.add(copyPreventToExcelRow(full, null));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (MesDevicePreventForm form : formList) {
|
|
|
|
|
+ rows.add(copyPreventToExcelRow(full, form));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rows;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ExcelMesDevicePrevent copyPreventToExcelRow(MesDevicePrevent prevent, MesDevicePreventForm form) {
|
|
|
|
|
+ ExcelMesDevicePrevent row = new ExcelMesDevicePrevent();
|
|
|
|
|
+ row.setTitle(prevent.getTitle());
|
|
|
|
|
+ row.setCate(prevent.getCate());
|
|
|
|
|
+ row.setCycle(prevent.getCycle());
|
|
|
|
|
+ row.setLaborHour(prevent.getLaborHour());
|
|
|
|
|
+ row.setStatus(prevent.getStatus());
|
|
|
|
|
+ if (form != null) {
|
|
|
|
|
+ row.setFormTitle(form.getTitle());
|
|
|
|
|
+ row.setFormLaborHour(form.getLaborHour());
|
|
|
|
|
+ }
|
|
|
|
|
+ return row;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<MesDevicePrevent> buildImportList(List<ExcelMesDevicePrevent> rows) {
|
|
|
|
|
+ Map<String, MesDevicePrevent> preventMap = new LinkedHashMap<>();
|
|
|
|
|
+ for (ExcelMesDevicePrevent row : rows) {
|
|
|
|
|
+ if (row == null || isBlankRow(row)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String key = buildImportKey(row);
|
|
|
|
|
+ MesDevicePrevent prevent = preventMap.get(key);
|
|
|
|
|
+ if (prevent == null) {
|
|
|
|
|
+ prevent = new MesDevicePrevent();
|
|
|
|
|
+ prevent.setTitle(row.getTitle());
|
|
|
|
|
+ prevent.setCate(row.getCate());
|
|
|
|
|
+ prevent.setCycle(row.getCycle());
|
|
|
|
|
+ prevent.setLaborHour(row.getLaborHour());
|
|
|
|
|
+ prevent.setStatus(StringUtils.isBlank(row.getStatus()) ? MesDevicePrevent.STATUS_NORMAL : row.getStatus());
|
|
|
|
|
+ preventMap.put(key, prevent);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(row.getFormTitle()) || StringUtils.isNotBlank(row.getFormLaborHour())) {
|
|
|
|
|
+ MesDevicePreventForm form = new MesDevicePreventForm();
|
|
|
|
|
+ form.setTitle(row.getFormTitle());
|
|
|
|
|
+ form.setLaborHour(row.getFormLaborHour());
|
|
|
|
|
+ form.setStatus(MesDevicePreventForm.STATUS_NORMAL);
|
|
|
|
|
+ prevent.getMesDevicePreventFormList().add(form);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new ArrayList<>(preventMap.values());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isBlankRow(ExcelMesDevicePrevent row) {
|
|
|
|
|
+ return StringUtils.isBlank(row.getTitle())
|
|
|
|
|
+ && StringUtils.isBlank(row.getCate())
|
|
|
|
|
+ && StringUtils.isBlank(row.getCycle())
|
|
|
|
|
+ && StringUtils.isBlank(row.getLaborHour())
|
|
|
|
|
+ && StringUtils.isBlank(row.getFormTitle())
|
|
|
|
|
+ && StringUtils.isBlank(row.getFormLaborHour());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String buildImportKey(ExcelMesDevicePrevent row) {
|
|
|
|
|
+ return StringUtils.trimToEmpty(row.getTitle()) + "|"
|
|
|
|
|
+ + StringUtils.trimToEmpty(row.getCate()) + "|"
|
|
|
|
|
+ + StringUtils.trimToEmpty(row.getCycle()) + "|"
|
|
|
|
|
+ + StringUtils.trimToEmpty(row.getLaborHour());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|