diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/ConstructionServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/ConstructionServiceImpl.java index e291ccb..91e4ca1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/ConstructionServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/ConstructionServiceImpl.java @@ -9,7 +9,6 @@ import com.hnac.hzims.operational.access.service.ConstructionService; import com.hnac.hzims.operational.access.vo.ConstructionVo; import com.hnac.hzims.operational.access.wrapper.ConstructionWrapper; import com.hnac.hzims.operational.util.ExcelUtil; -import com.hnac.hzims.operational.util.PdfUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.usermodel.Workbook; @@ -74,11 +73,11 @@ public class ConstructionServiceImpl extends BaseServiceImpl params = new HashMap<>(); - try { + /*try { params = PdfUtils.objectToMap(construction); }catch (Exception e) { log.error("转换对象失败!"); - } + }*/ TemplateExportParams templateExportParams = new TemplateExportParams("template/constructio_template.xlsx", true); Workbook workbook = null; try { @@ -87,19 +86,19 @@ public class ConstructionServiceImpl extends BaseServiceImpl objectToMap(Object obj) { - Map result = new HashMap<>(); - if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { - Class clazz = obj.getClass(); - List fieldList = new ArrayList<>(); - while (clazz != null) { - fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); - clazz = clazz.getSuperclass(); - } - fieldList.forEach(field -> { - field.setAccessible(true); - DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); - Object value; - try { - value = field.get(obj); - } catch (IllegalAccessException e) { - throw new ServiceException("获取属性性出错"); - } - //若为list则不处理 - if (value instanceof List) { - return; - } - //若为时间格式则进行格式化 - if (value instanceof LocalDateTime) { - value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); - } - if (value instanceof Date) { - value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); - } - - //如果value为空直接跳出 - // if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ - // return; - // } - - //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 - if (ObjectUtil.isNotEmpty(defaultValue)) { - result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), - ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); - } else { - result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); - - } - }); - } - return result; - } - - - /** - * 对象转化为Map 并设置默认值 - * - * @param obj - * @return - * @throws Exception - */ - public static Map objectToMap(Object obj, boolean isWordFlag) { - Map result = new HashMap<>(); - if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { - Class clazz = obj.getClass(); - List fieldList = new ArrayList<>(); - while (clazz != null) { - fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); - clazz = clazz.getSuperclass(); - } - fieldList.forEach(field -> { - field.setAccessible(true); - DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); - Object value; - try { - value = field.get(obj); - } catch (IllegalAccessException e) { - throw new ServiceException("获取属性性出错"); - } - //若为list则不处理 - if (value instanceof List) { - return; - } - //若为时间格式则进行格式化 - if (value instanceof LocalDateTime) { - value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); - } - if (value instanceof Date) { - value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); - } - - //如果value为空直接跳出 - // if ((ObjectUtils.isEmpty(value) || value == "") && StringUtil.isNoneBlank(field.getName())){ - // return; - // } - - //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 - if (ObjectUtil.isNotEmpty(defaultValue)) { - result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), - ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); - } else { - if (isWordFlag) { - //如果导出word为null会出现{{ ,value设置"\u00A0" - result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0")); - } else { - result.put(field.getName(), Optional.ofNullable(value).orElse(" ")); - } - } - }); - } - return result; - } - - - /** - * 对象转化为Map 并设置默认值 - * - * @param obj - * @return - * @throws Exception - */ - public static Map objectToMapResult(Object obj, Map map) { - Map result = new HashMap<>(); - if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { - Class clazz = obj.getClass(); - List fieldList = new ArrayList<>(); - while (clazz != null) { - fieldList.addAll(Arrays.asList(clazz.getDeclaredFields())); - clazz = clazz.getSuperclass(); - } - fieldList.forEach(field -> { - field.setAccessible(true); - DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); - Object value; - try { - value = field.get(obj); - } catch (IllegalAccessException e) { - throw new ServiceException("获取属性性出错"); - } - //若为list则不处理 - if (value instanceof List) { - return; - } - //若为时间格式则进行格式化 - if (value instanceof LocalDateTime) { - value = DateUtil.format((LocalDateTime) value, TicketConstants.TICKET_DATE_PATTERN); - } - if (value instanceof Date) { - value = DateUtil.format((Date) value, TicketConstants.TICKET_DATE_PATTERN); - } - - if (map.containsKey(field.getName())) { - return; - } - - //属性上是否加入DefaultValue注解 若加入 则判断是否定义属性名以及值 若未定义则取原属性名及值 - if (ObjectUtil.isNotEmpty(defaultValue)) { - result.put(StringUtil.isNoneBlank(defaultValue.name()) ? defaultValue.name() : field.getName(), - ObjectUtil.isNotEmpty(defaultValue.value()) ? defaultValue.value() : value); - } else { - //如果导出word为null会出现{{ ,value设置"\u00A0" - result.put(field.getName(), Optional.ofNullable(value).orElse("")); - } - }); - } - return result; - } - - - /** - * 读取本地pdf,这里设置的是预览 - */ - public static void readPdf(HttpServletResponse response, String filePath) { - response.reset(); - response.setContentType("application/pdf"); - FileInputStream fileInputStream = null; - OutputStream outputStream = null; - try { - File file = new File(filePath); - fileInputStream = new FileInputStream(file); - outputStream = response.getOutputStream(); - IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); - response.setHeader("Content-Disposition", - "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); - outputStream.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - fileInputStream.close(); - outputStream.close(); - - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * 读取本地pdf,这里设置的是导出 - */ - public static void exportPdf(HttpServletResponse response, String filePath) { - response.reset(); - response.setContentType("application/pdf"); - FileInputStream fileInputStream = null; - OutputStream outputStream = null; - try { - File file = new File(filePath); - fileInputStream = new FileInputStream(file); - outputStream = response.getOutputStream(); - IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); - response.setHeader("Content-Disposition", "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); - outputStream.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - fileInputStream.close(); - outputStream.close(); - - } catch (IOException e) { - e.printStackTrace(); - } - } - } -}