|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.hnac.hzims.ticket.utils; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
|
import com.documents4j.api.DocumentType; |
|
|
|
|
import com.documents4j.api.IConverter; |
|
|
|
|
import com.documents4j.job.LocalConverter; |
|
|
|
@ -209,6 +210,89 @@ public class PdfUtils {
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 对象转化为Map 并设置默认值 |
|
|
|
|
* |
|
|
|
|
* @param obj |
|
|
|
|
* @return |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public static Map<String, Object> objectToMapResult(Object obj, Map<String, Object> map) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { |
|
|
|
|
Class clazz = obj.getClass(); |
|
|
|
|
List<Field> 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 { |
|
|
|
|
if ("initialPrincipalName".equals(field.getName()) |
|
|
|
|
|| "principalChangeTime".equals(field.getName()) |
|
|
|
|
|| "principalName".equals(field.getName()) |
|
|
|
|
|| "jobReceiver".equals(field.getName()) |
|
|
|
|
|| "jobReceiverDateTime".equals(field.getName()) |
|
|
|
|
|| "watchPrincipalEndTime".equals(field.getName()) |
|
|
|
|
|| "licenseTime".equals(field.getName()) |
|
|
|
|
|| "licensorName".equals(field.getName()) |
|
|
|
|
|| "signerDateTime".equals(field.getName()) |
|
|
|
|
|| "classGroupName".equals(field.getName()) |
|
|
|
|
|| "code".equals(field.getName()) |
|
|
|
|
|| "signerName".equals(field.getName()) |
|
|
|
|
|| "watchPrincipalName".equals(field.getName())) |
|
|
|
|
{ |
|
|
|
|
result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); |
|
|
|
|
|
|
|
|
|
} else if ( |
|
|
|
|
"groundNum".equals(field.getName()) || |
|
|
|
|
"dismantleNum".equals(field.getName()) || |
|
|
|
|
"retainNum".equals(field.getName()) |
|
|
|
|
|
|
|
|
|
) { |
|
|
|
|
result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0 ")); |
|
|
|
|
} else { |
|
|
|
|
//如果导出word为null会出现{{ ,value设置"\u00A0"
|
|
|
|
|
result.put(field.getName(), Optional.ofNullable(value).orElse("\u00A0")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 读取本地pdf,这里设置的是预览 |
|
|
|
|
*/ |
|
|
|
|