格式化代码
This commit is contained in:
		| @@ -4,8 +4,9 @@ import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * 输出信息对象 | ||||
|  * @author tajochen | ||||
|  * | ||||
|  * @param <T> | ||||
|  * @author tajochen | ||||
|  */ | ||||
| public class EncapsulationObejct<T> implements Serializable { | ||||
|  | ||||
| @@ -50,10 +51,6 @@ public class EncapsulationObejct<T> implements Serializable { | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "EncapsulationObejct{" + | ||||
|                 "status=" + status + | ||||
|                 ", msg='" + msg + '\'' + | ||||
|                 ", data=" + data + | ||||
|                 '}'; | ||||
|         return "EncapsulationObejct{" + "status=" + status + ", msg='" + msg + '\'' + ", data=" + data + '}'; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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<FieldError> fieldErrors, Locale locale){ | ||||
|     public static String outputEncapsulationErrorList(List<FieldError> fieldErrors, Locale locale) { | ||||
|         List<String> 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 + '\'' + '}'; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|      */ | ||||
|   | ||||
| @@ -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> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); | ||||
| //        if (fileEntity.isEmpty()) { | ||||
| //            return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); | ||||
| //        } | ||||
| //        String fileUploadPath = fileEntity.get().getFileUploadPath(); | ||||
| //        List<DataSource> dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); | ||||
| //        if (dataSources == null || dataSources.size() == 0) { | ||||
| //            return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); | ||||
| //        } | ||||
| //        Map<String, String> 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> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); | ||||
|         if (fileEntity.isEmpty()) { | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); | ||||
|         } | ||||
|         String fileUploadPath = fileEntity.get().getFileUploadPath(); | ||||
|         List<Map<String, Object>> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo); | ||||
|         if (resultList == null || resultList.size() == 0) { | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); | ||||
|         } | ||||
|         Map<String, String> map = new HashMap<>(); | ||||
|         for (Map<String, Object> 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|   | ||||
| @@ -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<String, String> 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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user