From a995d08f6f19f11415d683eda19a5db036fdb571 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 12 Mar 2022 15:07:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../encapsulation/EncapsulationObejct.java | 9 ++-- .../encapsulation/OutputEncapsulation.java | 16 +++--- .../com/xkrs/model/entity/FileEntity.java | 12 +---- .../java/com/xkrs/service/FileService.java | 5 +- .../xkrs/service/impl/FileServiceImpl.java | 52 +++++++++---------- .../java/com/xkrs/util/ExcelUploadUtil.java | 12 ++--- src/main/java/com/xkrs/util/ExportExcel.java | 7 ++- 7 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/xkrs/encapsulation/EncapsulationObejct.java b/src/main/java/com/xkrs/encapsulation/EncapsulationObejct.java index 3822e1a..adaf854 100644 --- a/src/main/java/com/xkrs/encapsulation/EncapsulationObejct.java +++ b/src/main/java/com/xkrs/encapsulation/EncapsulationObejct.java @@ -4,8 +4,9 @@ import java.io.Serializable; /** * 输出信息对象 - * @author tajochen + * * @param + * @author tajochen */ public class EncapsulationObejct implements Serializable { @@ -50,10 +51,6 @@ public class EncapsulationObejct implements Serializable { @Override public String toString() { - return "EncapsulationObejct{" + - "status=" + status + - ", msg='" + msg + '\'' + - ", data=" + data + - '}'; + return "EncapsulationObejct{" + "status=" + status + ", msg='" + msg + '\'' + ", data=" + data + '}'; } } diff --git a/src/main/java/com/xkrs/encapsulation/OutputEncapsulation.java b/src/main/java/com/xkrs/encapsulation/OutputEncapsulation.java index 641e53f..3fcea45 100644 --- a/src/main/java/com/xkrs/encapsulation/OutputEncapsulation.java +++ b/src/main/java/com/xkrs/encapsulation/OutputEncapsulation.java @@ -21,6 +21,7 @@ import java.util.Properties; /** * 输出信息封装 + * * @author tajochen */ @Component @@ -30,6 +31,7 @@ public class OutputEncapsulation { /** * 读取多国语言文件 + * * @return */ public static MessageSource messageSource() { @@ -50,6 +52,7 @@ public class OutputEncapsulation { /** * 封装输出数据 + * * @param promptMessageEnum * @param obj * @return @@ -58,12 +61,12 @@ public class OutputEncapsulation { EncapsulationObejct encapsulationObejct = new EncapsulationObejct(); encapsulationObejct.setStatus(promptMessageEnum.getCode()); - encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(),null,locale)); + encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(), null, locale)); encapsulationObejct.setData(obj); ObjectMapper objectMapper = new ObjectMapper(); // 忽略无法转换的对象 - objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false); + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); // 忽略json字符串中不识别的属性 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准 @@ -82,15 +85,16 @@ public class OutputEncapsulation { /** * 输出请求值检验错误信息 + * * @param fieldErrors * @return */ - public static String outputEncapsulationErrorList(List fieldErrors, Locale locale){ + public static String outputEncapsulationErrorList(List fieldErrors, Locale locale) { List errorMsg = new ArrayList<>(); for (FieldError fieldError : fieldErrors) { - String errMessage = fieldError.getDefaultMessage().subSequence(1,fieldError.getDefaultMessage().length()-1).toString(); - errorMsg.add(messageSource().getMessage(errMessage,null,locale)); + String errMessage = fieldError.getDefaultMessage().subSequence(1, fieldError.getDefaultMessage().length() - 1).toString(); + errorMsg.add(messageSource().getMessage(errMessage, null, locale)); } - return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,errorMsg,locale); + return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, errorMsg, locale); } } diff --git a/src/main/java/com/xkrs/model/entity/FileEntity.java b/src/main/java/com/xkrs/model/entity/FileEntity.java index d2965f3..7d2054b 100644 --- a/src/main/java/com/xkrs/model/entity/FileEntity.java +++ b/src/main/java/com/xkrs/model/entity/FileEntity.java @@ -143,16 +143,6 @@ public class FileEntity { @Override public String toString() { - return "FileEntity{" + - "id=" + id + - ", lotNo='" + lotNo + '\'' + - ", machineNo='" + machineNo + '\'' + - ", materialNo='" + materialNo + '\'' + - ", modelNo='" + modelNo + '\'' + - ", machineTypeNo='" + machineTypeNo + '\'' + - ", craftItemName='" + craftItemName + '\'' + - ", fileUploadPath='" + fileUploadPath + '\'' + - ", fileDownloadPath='" + fileDownloadPath + '\'' + - '}'; + return "FileEntity{" + "id=" + id + ", lotNo='" + lotNo + '\'' + ", machineNo='" + machineNo + '\'' + ", materialNo='" + materialNo + '\'' + ", modelNo='" + modelNo + '\'' + ", machineTypeNo='" + machineTypeNo + '\'' + ", craftItemName='" + craftItemName + '\'' + ", fileUploadPath='" + fileUploadPath + '\'' + ", fileDownloadPath='" + fileDownloadPath + '\'' + '}'; } } diff --git a/src/main/java/com/xkrs/service/FileService.java b/src/main/java/com/xkrs/service/FileService.java index 367f056..995f5a4 100644 --- a/src/main/java/com/xkrs/service/FileService.java +++ b/src/main/java/com/xkrs/service/FileService.java @@ -4,7 +4,6 @@ import com.xkrs.model.qo.FileQo; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** @@ -15,13 +14,15 @@ public interface FileService { /** * 添加模板信息 + * * @param fileQo * @return */ - String insertFileExcel(FileQo fileQo,MultipartFile fileExcel) throws IOException; + String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException; /** * 导出excel + * * @param fileQo * @return */ diff --git a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java index 6964f84..22970f4 100644 --- a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java @@ -1,6 +1,7 @@ package com.xkrs.service.impl; import com.xkrs.dao.FileDao; +import com.xkrs.dao.QcSourceDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.FileEntity; import com.xkrs.model.qo.FileQo; @@ -29,8 +30,8 @@ public class FileServiceImpl implements FileService { @Resource private FileDao fileDao; -// @Resource -// private DataSourceQuery dataSourceQuery; + @Resource + private QcSourceDao qcSourceDao; /** * 添加模板信息 @@ -75,29 +76,28 @@ public class FileServiceImpl implements FileService { @Transactional(rollbackOn = Exception.class) @Override public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException { - return null; -// String lotNo = fileQo.getLotNo(); -// String machineNo = fileQo.getMachineNo(); -// String materialNo = fileQo.getMaterialNo(); -// String modelNo = fileQo.getModelNo(); -// String machineTypeNo = fileQo.getMachineTypeNo(); -// String craftItemName = fileQo.getCraftItemName(); -// Locale locale = LocaleContextHolder.getLocale(); -// Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); -// if (fileEntity.isEmpty()) { -// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); -// } -// String fileUploadPath = fileEntity.get().getFileUploadPath(); -// List dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); -// if (dataSources == null || dataSources.size() == 0) { -// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); -// } -// Map map = new HashMap<>(); -// for (DataSource dataSource : dataSources) { -// map.put(dataSource.getInspectionItemCode(), dataSource.getInspectValue()); -// } -// String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); -// fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill); -// return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale); + String lotNo = fileQo.getLotNo(); + String machineNo = fileQo.getMachineNo(); + String materialNo = fileQo.getMaterialNo(); + String modelNo = fileQo.getModelNo(); + String machineTypeNo = fileQo.getMachineTypeNo(); + String craftItemName = fileQo.getCraftItemName(); + Locale locale = LocaleContextHolder.getLocale(); + Optional fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); + if (fileEntity.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); + } + String fileUploadPath = fileEntity.get().getFileUploadPath(); + List> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo); + if (resultList == null || resultList.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); + } + Map map = new HashMap<>(); + for (Map result : resultList) { + map.put((String) result.get("qcItemNo"), (String) result.get("qcValue")); + } + String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); + fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale); } } diff --git a/src/main/java/com/xkrs/util/ExcelUploadUtil.java b/src/main/java/com/xkrs/util/ExcelUploadUtil.java index bb4e494..90ef579 100644 --- a/src/main/java/com/xkrs/util/ExcelUploadUtil.java +++ b/src/main/java/com/xkrs/util/ExcelUploadUtil.java @@ -39,17 +39,17 @@ public class ExcelUploadUtil { String suffix = originalFilename.substring(index); //uuid生成新的文件名 String newName = UUID.randomUUID().toString() + suffix; - File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); -// File file = new File("/home/sxy/server/industrial_measurement/" + subDir); +// File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); + File file = new File("/home/sxy/server/industrial_measurement/" + subDir); if (!file.exists()) { file.mkdirs(); } - String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; -// String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; +// String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; + String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; //实现上传 fileInput.transferTo(new File(path)); - return path; -// return subDir + newName; +// return path; + return subDir + newName; } return null; } diff --git a/src/main/java/com/xkrs/util/ExportExcel.java b/src/main/java/com/xkrs/util/ExportExcel.java index 0fbf2a7..6a16795 100644 --- a/src/main/java/com/xkrs/util/ExportExcel.java +++ b/src/main/java/com/xkrs/util/ExportExcel.java @@ -2,7 +2,8 @@ package com.xkrs.util; import net.sf.jxls.transformer.XLSTransformer; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import java.io.*; + +import java.io.IOException; import java.util.Map; /** @@ -39,8 +40,6 @@ public class ExportExcel { return "http://118.24.27.47:2088/excel/"+s; //return "http://192.168.2.139/"+s; }*/ - - public static String exportToProveExcel(Map dataMap, String srcFilePath) throws IOException, InvalidFormatException { String s = System.currentTimeMillis() + ".xlsx"; //String path = "E:/shop/"+s; @@ -51,7 +50,7 @@ public class ExportExcel { // 参数:srcFilePath:模板源文件 cMap:需要导出的数据 destFile.getAbsolutePath():下载的目标文件 transformer.transformXLS(srcFilePath, dataMap, path); //return "http://192.168.2.139/"+s; - return "http://118.24.27.47:2088/excel/"+s; + return "http://118.24.27.47:2088/excel/" + s; } /*public static void main(String[] args) throws IOException, InvalidFormatException {