格式化代码

This commit is contained in:
liuchengqian 2022-03-12 15:07:20 +08:00
parent 7690f14c0d
commit a995d08f6f
7 changed files with 52 additions and 61 deletions

View File

@ -4,8 +4,9 @@ import java.io.Serializable;
/** /**
* 输出信息对象 * 输出信息对象
* @author tajochen *
* @param <T> * @param <T>
* @author tajochen
*/ */
public class EncapsulationObejct<T> implements Serializable { public class EncapsulationObejct<T> implements Serializable {
@ -50,10 +51,6 @@ public class EncapsulationObejct<T> implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "EncapsulationObejct{" + return "EncapsulationObejct{" + "status=" + status + ", msg='" + msg + '\'' + ", data=" + data + '}';
"status=" + status +
", msg='" + msg + '\'' +
", data=" + data +
'}';
} }
} }

View File

@ -21,6 +21,7 @@ import java.util.Properties;
/** /**
* 输出信息封装 * 输出信息封装
*
* @author tajochen * @author tajochen
*/ */
@Component @Component
@ -30,6 +31,7 @@ public class OutputEncapsulation {
/** /**
* 读取多国语言文件 * 读取多国语言文件
*
* @return * @return
*/ */
public static MessageSource messageSource() { public static MessageSource messageSource() {
@ -50,6 +52,7 @@ public class OutputEncapsulation {
/** /**
* 封装输出数据 * 封装输出数据
*
* @param promptMessageEnum * @param promptMessageEnum
* @param obj * @param obj
* @return * @return
@ -58,12 +61,12 @@ public class OutputEncapsulation {
EncapsulationObejct encapsulationObejct = new EncapsulationObejct(); EncapsulationObejct encapsulationObejct = new EncapsulationObejct();
encapsulationObejct.setStatus(promptMessageEnum.getCode()); encapsulationObejct.setStatus(promptMessageEnum.getCode());
encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(),null,locale)); encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(), null, locale));
encapsulationObejct.setData(obj); encapsulationObejct.setData(obj);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
// 忽略无法转换的对象 // 忽略无法转换的对象
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// 忽略json字符串中不识别的属性 // 忽略json字符串中不识别的属性
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准 // 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
@ -82,15 +85,16 @@ public class OutputEncapsulation {
/** /**
* 输出请求值检验错误信息 * 输出请求值检验错误信息
*
* @param fieldErrors * @param fieldErrors
* @return * @return
*/ */
public static String outputEncapsulationErrorList(List<FieldError> fieldErrors, Locale locale){ public static String outputEncapsulationErrorList(List<FieldError> fieldErrors, Locale locale) {
List<String> errorMsg = new ArrayList<>(); List<String> errorMsg = new ArrayList<>();
for (FieldError fieldError : fieldErrors) { for (FieldError fieldError : fieldErrors) {
String errMessage = fieldError.getDefaultMessage().subSequence(1,fieldError.getDefaultMessage().length()-1).toString(); String errMessage = fieldError.getDefaultMessage().subSequence(1, fieldError.getDefaultMessage().length() - 1).toString();
errorMsg.add(messageSource().getMessage(errMessage,null,locale)); errorMsg.add(messageSource().getMessage(errMessage, null, locale));
} }
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,errorMsg,locale); return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, errorMsg, locale);
} }
} }

View File

@ -143,16 +143,6 @@ public class FileEntity {
@Override @Override
public String toString() { public String toString() {
return "FileEntity{" + return "FileEntity{" + "id=" + id + ", lotNo='" + lotNo + '\'' + ", machineNo='" + machineNo + '\'' + ", materialNo='" + materialNo + '\'' + ", modelNo='" + modelNo + '\'' + ", machineTypeNo='" + machineTypeNo + '\'' + ", craftItemName='" + craftItemName + '\'' + ", fileUploadPath='" + fileUploadPath + '\'' + ", fileDownloadPath='" + fileDownloadPath + '\'' + '}';
"id=" + id +
", lotNo='" + lotNo + '\'' +
", machineNo='" + machineNo + '\'' +
", materialNo='" + materialNo + '\'' +
", modelNo='" + modelNo + '\'' +
", machineTypeNo='" + machineTypeNo + '\'' +
", craftItemName='" + craftItemName + '\'' +
", fileUploadPath='" + fileUploadPath + '\'' +
", fileDownloadPath='" + fileDownloadPath + '\'' +
'}';
} }
} }

View File

@ -4,7 +4,6 @@ import com.xkrs.model.qo.FileQo;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
@ -15,13 +14,15 @@ public interface FileService {
/** /**
* 添加模板信息 * 添加模板信息
*
* @param fileQo * @param fileQo
* @return * @return
*/ */
String insertFileExcel(FileQo fileQo,MultipartFile fileExcel) throws IOException; String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException;
/** /**
* 导出excel * 导出excel
*
* @param fileQo * @param fileQo
* @return * @return
*/ */

View File

@ -1,6 +1,7 @@
package com.xkrs.service.impl; package com.xkrs.service.impl;
import com.xkrs.dao.FileDao; import com.xkrs.dao.FileDao;
import com.xkrs.dao.QcSourceDao;
import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.FileEntity; import com.xkrs.model.entity.FileEntity;
import com.xkrs.model.qo.FileQo; import com.xkrs.model.qo.FileQo;
@ -29,8 +30,8 @@ public class FileServiceImpl implements FileService {
@Resource @Resource
private FileDao fileDao; private FileDao fileDao;
// @Resource @Resource
// private DataSourceQuery dataSourceQuery; private QcSourceDao qcSourceDao;
/** /**
* 添加模板信息 * 添加模板信息
@ -75,29 +76,28 @@ public class FileServiceImpl implements FileService {
@Transactional(rollbackOn = Exception.class) @Transactional(rollbackOn = Exception.class)
@Override @Override
public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException { public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException {
return null; String lotNo = fileQo.getLotNo();
// String lotNo = fileQo.getLotNo(); String machineNo = fileQo.getMachineNo();
// String machineNo = fileQo.getMachineNo(); String materialNo = fileQo.getMaterialNo();
// String materialNo = fileQo.getMaterialNo(); String modelNo = fileQo.getModelNo();
// String modelNo = fileQo.getModelNo(); String machineTypeNo = fileQo.getMachineTypeNo();
// String machineTypeNo = fileQo.getMachineTypeNo(); String craftItemName = fileQo.getCraftItemName();
// String craftItemName = fileQo.getCraftItemName(); Locale locale = LocaleContextHolder.getLocale();
// Locale locale = LocaleContextHolder.getLocale(); Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
// Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); if (fileEntity.isEmpty()) {
// if (fileEntity.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); }
// } String fileUploadPath = fileEntity.get().getFileUploadPath();
// String fileUploadPath = fileEntity.get().getFileUploadPath(); List<Map<String, Object>> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo);
// List<DataSource> dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); if (resultList == null || resultList.size() == 0) {
// if (dataSources == null || dataSources.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale);
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); }
// } Map<String, String> map = new HashMap<>();
// Map<String, String> map = new HashMap<>(); for (Map<String, Object> result : resultList) {
// for (DataSource dataSource : dataSources) { map.put((String) result.get("qcItemNo"), (String) result.get("qcValue"));
// map.put(dataSource.getInspectionItemCode(), dataSource.getInspectValue()); }
// } String fill = ExportExcel.exportToProveExcel(map, fileUploadPath);
// String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill);
// fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale);
// return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale);
} }
} }

View File

@ -39,17 +39,17 @@ public class ExcelUploadUtil {
String suffix = originalFilename.substring(index); String suffix = originalFilename.substring(index);
//uuid生成新的文件名 //uuid生成新的文件名
String newName = UUID.randomUUID().toString() + suffix; String newName = UUID.randomUUID().toString() + suffix;
File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); // File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir);
// File file = new File("/home/sxy/server/industrial_measurement/" + subDir); File file = new File("/home/sxy/server/industrial_measurement/" + subDir);
if (!file.exists()) { if (!file.exists()) {
file.mkdirs(); file.mkdirs();
} }
String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; // String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName;
// String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; String path = "/home/sxy/server/industrial_measurement/" + subDir + newName;
//实现上传 //实现上传
fileInput.transferTo(new File(path)); fileInput.transferTo(new File(path));
return path; // return path;
// return subDir + newName; return subDir + newName;
} }
return null; return null;
} }

View File

@ -2,7 +2,8 @@ package com.xkrs.util;
import net.sf.jxls.transformer.XLSTransformer; import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import java.io.*;
import java.io.IOException;
import java.util.Map; import java.util.Map;
/** /**
@ -39,8 +40,6 @@ public class ExportExcel {
return "http://118.24.27.47:2088/excel/"+s; return "http://118.24.27.47:2088/excel/"+s;
//return "http://192.168.2.139/"+s; //return "http://192.168.2.139/"+s;
}*/ }*/
public static String exportToProveExcel(Map<String, String> dataMap, String srcFilePath) throws IOException, InvalidFormatException { public static String exportToProveExcel(Map<String, String> dataMap, String srcFilePath) throws IOException, InvalidFormatException {
String s = System.currentTimeMillis() + ".xlsx"; String s = System.currentTimeMillis() + ".xlsx";
//String path = "E:/shop/"+s; //String path = "E:/shop/"+s;
@ -51,7 +50,7 @@ public class ExportExcel {
// 参数srcFilePath模板源文件 cMap需要导出的数据 destFile.getAbsolutePath()下载的目标文件 // 参数srcFilePath模板源文件 cMap需要导出的数据 destFile.getAbsolutePath()下载的目标文件
transformer.transformXLS(srcFilePath, dataMap, path); transformer.transformXLS(srcFilePath, dataMap, path);
//return "http://192.168.2.139/"+s; //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 { /*public static void main(String[] args) throws IOException, InvalidFormatException {