yang_shj
11 months ago
12 changed files with 711 additions and 1 deletions
@ -0,0 +1,73 @@
|
||||
package com.hnac.hzims.operational.access.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.NullSerializer; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Data |
||||
@TableName("hzims_oper_construction") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ApiModel(value = "检修施工日志表") |
||||
public class OperConstructionEntity extends TenantEntity { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "施工编号") |
||||
private String code; |
||||
|
||||
@ApiModelProperty(value = "施工时间") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date constructionTime; |
||||
|
||||
@ApiModelProperty(value = "检修名称") |
||||
private String overhaulName; |
||||
|
||||
@ApiModelProperty(value = "施工地点") |
||||
private String constructionLocation; |
||||
|
||||
@ApiModelProperty(value = "检修负责人") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Long overhaulHead; |
||||
|
||||
@ApiModelProperty(value = "检修人员: 根据“,”分割") |
||||
private String overhaulPersonnel; |
||||
|
||||
@ApiModelProperty(value = "检修时间") |
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private Date overhaulTime; |
||||
|
||||
@ApiModelProperty(value = "今日工作完成情况描述") |
||||
private String completeWorkDesc; |
||||
|
||||
@ApiModelProperty(value = "明日工作计划描述") |
||||
private String planWorkDesc; |
||||
|
||||
@ApiModelProperty(value = "施工图片: 根据“,”分割") |
||||
private String constructionImg; |
||||
|
||||
@ApiModelProperty(value = "施工附件") |
||||
private String constructionAttachment; |
||||
|
||||
@ApiModelProperty(value = "记录人") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Long recorder; |
||||
|
||||
@ApiModelProperty(value = "审核人") |
||||
@JsonSerialize(nullsUsing = NullSerializer.class) |
||||
private Long reviewer; |
||||
|
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.hnac.hzims.operational.access.vo; |
||||
|
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Data |
||||
public class ConstructionVo extends OperConstructionEntity { |
||||
|
||||
@ApiModelProperty(value = "开始时间") |
||||
private String startTime; |
||||
|
||||
@ApiModelProperty(value = "结束时间") |
||||
private String endTime; |
||||
|
||||
@ApiModelProperty(value = "创建人名称") |
||||
private String createUserName; |
||||
|
||||
@ApiModelProperty(value = "修改人名称") |
||||
private String updateUserName; |
||||
|
||||
@ApiModelProperty(value = "检修负责人名称") |
||||
private String overhaulHeadName; |
||||
|
||||
@ApiModelProperty(value = "记录人名称") |
||||
private String recorderName; |
||||
|
||||
@ApiModelProperty(value = "审核人名称") |
||||
private String reviewerName; |
||||
|
||||
@ApiModelProperty(value = "检修人员名称Name") |
||||
private String overhaulPersonnelName; |
||||
} |
@ -0,0 +1,84 @@
|
||||
package com.hnac.hzims.operational.access.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.common.logs.annotation.OperationAnnotation; |
||||
import com.hnac.hzims.common.logs.enums.BusinessType; |
||||
import com.hnac.hzims.common.logs.enums.OperatorType; |
||||
import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO; |
||||
import com.hnac.hzims.operational.access.dto.OperAccessPlanDTO; |
||||
import com.hnac.hzims.operational.access.dto.OperAccessPlanFlowDTO; |
||||
import com.hnac.hzims.operational.access.dto.OperAccessPlanListDTO; |
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import com.hnac.hzims.operational.access.service.AccessPlanV4Service; |
||||
import com.hnac.hzims.operational.access.service.ConstructionService; |
||||
import com.hnac.hzims.operational.access.vo.ConstructionVo; |
||||
import com.hnac.hzims.operational.access.vo.OperAccessPlanVO; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.log.annotation.ApiLog; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.validation.Valid; |
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/construction") |
||||
@Api(tags = "施工日志") |
||||
public class ConstructionController extends BladeController { |
||||
|
||||
|
||||
private final ConstructionService service; |
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperationSupport(order = 1) |
||||
@ApiOperation(value = "新增") |
||||
public R save(@RequestBody OperConstructionEntity entity) { |
||||
return R.status(service.save(entity)); |
||||
} |
||||
|
||||
@PostMapping("/remove") |
||||
@ApiOperationSupport(order = 2) |
||||
@ApiOperation(value = "逻辑删除") |
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { |
||||
return R.status(service.deleteLogic(Func.toLongList(ids))); |
||||
} |
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperationSupport(order = 3) |
||||
@ApiOperation(value = "修改") |
||||
public R update(@Valid @RequestBody OperConstructionEntity entity) { |
||||
return R.status(service.updateById(entity)); |
||||
} |
||||
|
||||
@GetMapping("/list") |
||||
@ApiOperationSupport(order = 4) |
||||
@OperationAnnotation(moduleName = "检修管理",title = "检修计划",operatorType = OperatorType.MOBILE,businessType = |
||||
BusinessType.GENCODE, |
||||
action = "分页查询检修计划列表") |
||||
@ApiOperation(value = "分页 查询参数:code,name,gradeCode,manager,techLead,handleStatus,status") |
||||
public R<IPage<ConstructionVo>> list(ConstructionVo construction, Query query) { |
||||
return R.data(service.pageCondition(Condition.getPage(query), construction)); |
||||
} |
||||
|
||||
@GetMapping("/preview") |
||||
@ApiOperationSupport(order = 5) |
||||
@ApiOperation(value = "检修施工日志预览", notes = "检修施工日志预览") |
||||
public void preview(@RequestParam @ApiParam("检修施工记录Id") @NotNull @Valid Long id) { |
||||
service.preview(id); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.hnac.hzims.operational.access.mapper; |
||||
|
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ConstructionMapper extends UserDataScopeBaseMapper<OperConstructionEntity> { |
||||
|
||||
} |
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.hnac.hzims.operational.access.mapper.ConstructionMapper"> |
||||
</mapper> |
@ -0,0 +1,19 @@
|
||||
package com.hnac.hzims.operational.access.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import com.hnac.hzims.operational.access.vo.ConstructionVo; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ConstructionService extends BaseService<OperConstructionEntity> { |
||||
|
||||
|
||||
IPage<ConstructionVo> pageCondition(IPage<OperConstructionEntity> page, ConstructionVo construction); |
||||
|
||||
void preview(Long id); |
||||
} |
@ -0,0 +1,117 @@
|
||||
package com.hnac.hzims.operational.access.service.impl; |
||||
|
||||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import com.hnac.hzims.operational.access.mapper.ConstructionMapper; |
||||
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; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
public class ConstructionServiceImpl extends BaseServiceImpl<ConstructionMapper, OperConstructionEntity> implements ConstructionService { |
||||
|
||||
|
||||
@Value("${hzims.operational.construction.save.xlsx}") |
||||
private String constructionSaveXlsxPath; |
||||
|
||||
@Value("${hzims.operational.construction.save.pdf}") |
||||
private String constructionSavePdfPath; |
||||
|
||||
/** |
||||
* 施工日志记录分页查询 |
||||
* @param page |
||||
* @param construction |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public IPage<ConstructionVo> pageCondition(IPage<OperConstructionEntity> page, ConstructionVo construction) { |
||||
QueryWrapper wrapper = Condition.getQueryWrapper(construction); |
||||
if(StringUtil.isNotBlank(construction.getStartTime())){ |
||||
wrapper.ge("CREATE_TIME",construction.getStartTime()); |
||||
} |
||||
if(StringUtil.isNotBlank(construction.getEndTime())){ |
||||
wrapper.le("CREATE_TIME",construction.getEndTime()); |
||||
} |
||||
IPage pages = super.page(page, wrapper); |
||||
pages.setRecords(ConstructionWrapper.build().listVO(pages.getRecords())); |
||||
return pages; |
||||
} |
||||
|
||||
/** |
||||
* 施工日志记录预览 |
||||
* @param id |
||||
*/ |
||||
@Override |
||||
public void preview(Long id) { |
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||
HttpServletResponse response = servletRequestAttributes.getResponse(); |
||||
//准备数据
|
||||
ConstructionVo construction = this.record(id); |
||||
Map<String,Object> params = new HashMap<>(); |
||||
try { |
||||
params = PdfUtils.objectToMap(construction); |
||||
}catch (Exception e) { |
||||
log.error("转换对象失败!"); |
||||
} |
||||
TemplateExportParams templateExportParams = new TemplateExportParams("template/constructio_template.xlsx", true); |
||||
Workbook workbook = null; |
||||
try { |
||||
workbook = ExcelUtil.getWorkbook(templateExportParams,params); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
//上传xlsx至服务器
|
||||
String fileName = DateUtil.format(construction.getConstructionTime(),DateUtil.PATTERN_DATETIME) + "_" + construction.getOverhaulName() + "_施工日志" + PdfUtils.XLSX_SUFFIX; |
||||
try { |
||||
ExcelUtil.upload(workbook,constructionSaveXlsxPath,fileName); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
//将docx文件转换为pdf并保存
|
||||
String pdfFileName = DateUtil.format(construction.getConstructionTime(),DateUtil.PATTERN_DATETIME) + "_" + construction.getOverhaulName() + "_施工日志" + PdfUtils.PDF_SUFFIX; |
||||
String xlsxFileName = DateUtil.format(construction.getConstructionTime(),DateUtil.PATTERN_DATETIME) + "_" + construction.getOverhaulName() + "_施工日志" + PdfUtils.XLSX_SUFFIX; |
||||
PdfUtils.convertPdf(constructionSaveXlsxPath, xlsxFileName, constructionSavePdfPath, pdfFileName); |
||||
String savePath = constructionSavePdfPath + pdfFileName; |
||||
// 设置response参数,可以打开下载页面
|
||||
PdfUtils.readPdf(response,savePath); |
||||
} |
||||
|
||||
/** |
||||
* 查询施工日志记录 |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
private ConstructionVo record(Long id) { |
||||
OperConstructionEntity entity = this.getById(id); |
||||
if(ObjectUtil.isEmpty(entity)){ |
||||
throw new ServiceException("施工日志记录不存在!"); |
||||
} |
||||
return ConstructionWrapper.build().entityVO(entity); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.hnac.hzims.operational.access.wrapper; |
||||
|
||||
import com.hnac.hzims.operational.access.constants.DictConstant; |
||||
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; |
||||
import com.hnac.hzims.operational.access.entity.OperConstructionEntity; |
||||
import com.hnac.hzims.operational.access.vo.ConstructionVo; |
||||
import com.hnac.hzims.operational.access.vo.OperAccessPlanVO; |
||||
import org.springblade.core.mp.support.BaseEntityWrapper; |
||||
import org.springblade.core.tool.utils.BeanUtil; |
||||
import org.springblade.system.cache.DictCache; |
||||
import org.springblade.system.user.cache.UserCache; |
||||
import org.springblade.system.user.entity.User; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public class ConstructionWrapper extends BaseEntityWrapper<OperConstructionEntity, ConstructionVo> { |
||||
|
||||
public static ConstructionWrapper build() { |
||||
return new ConstructionWrapper(); |
||||
} |
||||
|
||||
@Override |
||||
public ConstructionVo entityVO(OperConstructionEntity entity) { |
||||
ConstructionVo vo = BeanUtil.copy(entity, ConstructionVo.class); |
||||
User create = UserCache.getUser(entity.getCreateUser()); |
||||
User update = UserCache.getUser(entity.getUpdateUser()); |
||||
User head = UserCache.getUser(entity.getOverhaulHead()); |
||||
User recorder = UserCache.getUser(entity.getRecorder()); |
||||
User reviewer = UserCache.getUser(entity.getReviewer()); |
||||
vo.setCreateUserName(Optional.ofNullable(create).map(User :: getName).orElse(null)); |
||||
vo.setUpdateUserName(Optional.ofNullable(update).map(User :: getName).orElse(null)); |
||||
vo.setOverhaulHeadName(Optional.ofNullable(head).map(User :: getName).orElse(null)); |
||||
vo.setRecorderName(Optional.ofNullable(recorder).map(User :: getName).orElse(null)); |
||||
vo.setReviewerName(Optional.ofNullable(reviewer).map(User :: getName).orElse(null)); |
||||
return vo; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,322 @@
|
||||
package com.hnac.hzims.operational.util; |
||||
|
||||
import com.documents4j.api.DocumentType; |
||||
import com.documents4j.api.IConverter; |
||||
import com.documents4j.job.LocalConverter; |
||||
import com.hnac.hzims.ticket.annotation.DefaultValue; |
||||
import com.hnac.hzims.ticket.constants.TicketConstants; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.io.IOUtils; |
||||
import org.apache.poi.ss.usermodel.Workbook; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.*; |
||||
import java.lang.reflect.Field; |
||||
import java.net.URLEncoder; |
||||
import java.time.LocalDateTime; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @author hx |
||||
*/ |
||||
@Slf4j |
||||
public class PdfUtils { |
||||
|
||||
/** 文件后缀名 **/ |
||||
public static String DOC_SUFFIX = ".doc"; |
||||
public static String DOCX_SUFFIX = ".docx"; |
||||
public static String XLS_SUFFIX = ".xls"; |
||||
public static String XLSX_SUFFIX = ".xlsx"; |
||||
public static String PDF_SUFFIX = ".pdf"; |
||||
|
||||
/*** |
||||
* 各文件转换为pdf |
||||
* @param templatePath 待转换的文件路径 |
||||
* @param templateFileName 待转换的文件名 |
||||
* @param savePath 转换为pdf后的文件路径 |
||||
* @param saveFileName 转换为pdf后的文件名称 |
||||
* @return |
||||
*/ |
||||
public static void convertPdf(String templatePath, String templateFileName, String savePath, String saveFileName) { |
||||
String templateFilePath = templatePath + templateFileName; |
||||
String saveFilePath = savePath + saveFileName; |
||||
log.info("转换前的文件为:{};转换后的路径为:{}", templateFilePath, saveFilePath); |
||||
File templateFile = new File(templateFilePath); |
||||
File saveFile = new File(saveFilePath); |
||||
//获取文件类型
|
||||
String fileType = templateFileName.substring(templateFileName.lastIndexOf("."), templateFileName.length()); |
||||
InputStream inputStream = null; |
||||
OutputStream outputStream = null; |
||||
try { |
||||
try { |
||||
inputStream = new FileInputStream(templateFile); |
||||
outputStream = new FileOutputStream(saveFile); |
||||
//document4j 转换 pdf linux环境下不支持
|
||||
if (DOCX_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (DOC_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (XLS_SUFFIX.equals(fileType)) { |
||||
IConverter converter = LocalConverter.builder().build(); |
||||
converter.convert(inputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute(); |
||||
converter.shutDown(); |
||||
} else if (XLSX_SUFFIX.equals(fileType)) { |
||||
//此方式行不通
|
||||
//converter.convert(inputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute();
|
||||
Workbook wb = new Workbook(); |
||||
wb.loadFromFile(templateFilePath); |
||||
wb.saveToFile(saveFilePath, FileFormat.PDF); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("转换失败,错误信息为:{}", e.getMessage()); |
||||
throw new ServiceException(e.getMessage()); |
||||
} finally { |
||||
inputStream.close(); |
||||
outputStream.close(); |
||||
} |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 对象转化为Map 并设置默认值 |
||||
* |
||||
* @param obj |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Map<String, Object> objectToMap(Object obj) { |
||||
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); |
||||
} |
||||
|
||||
//如果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<String, Object> objectToMap(Object obj, boolean isWordFlag) { |
||||
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); |
||||
} |
||||
|
||||
//如果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<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 { |
||||
//如果导出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(); |
||||
} |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue