diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperConstructionEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperConstructionEntity.java new file mode 100644 index 0000000..1467abe --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperConstructionEntity.java @@ -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; + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/vo/ConstructionVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/vo/ConstructionVo.java new file mode 100644 index 0000000..aeaf0aa --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/vo/ConstructionVo.java @@ -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; +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java index e1346c1..6239612 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java @@ -66,6 +66,7 @@ public class EmInfoController extends BladeController { /** * 元件列表 分页 */ + @GetMapping("/partList") @ApiOperationSupport(order = 2) @ApiOperation(value = "元件分页", notes = "传入em_info,必须传gpid(上级设备ID)") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/ConstructionController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/ConstructionController.java new file mode 100644 index 0000000..aa03b00 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/ConstructionController.java @@ -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> 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); + } + + +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.java new file mode 100644 index 0000000..e5dd121 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.java @@ -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 { + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.xml new file mode 100644 index 0000000..b1358be --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/ConstructionMapper.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/ConstructionService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/ConstructionService.java new file mode 100644 index 0000000..a70cedc --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/ConstructionService.java @@ -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 { + + + IPage pageCondition(IPage page, ConstructionVo construction); + + void preview(Long id); +} \ No newline at end of file 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 new file mode 100644 index 0000000..e291ccb --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/ConstructionServiceImpl.java @@ -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 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 pageCondition(IPage 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 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); + } +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/wrapper/ConstructionWrapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/wrapper/ConstructionWrapper.java new file mode 100644 index 0000000..93d1aba --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/wrapper/ConstructionWrapper.java @@ -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 { + + 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; + } + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/PdfUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/PdfUtils.java new file mode 100644 index 0000000..89ce2ac --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/PdfUtils.java @@ -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 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(); + } + } + } +} diff --git a/hzims-service/operational/src/main/resources/template/excel/constructio_template.xlsx b/hzims-service/operational/src/main/resources/template/excel/constructio_template.xlsx new file mode 100644 index 0000000..201df42 Binary files /dev/null and b/hzims-service/operational/src/main/resources/template/excel/constructio_template.xlsx differ diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/mapper/xml/WorkTicketInfoMapper.xml b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/mapper/xml/WorkTicketInfoMapper.xml index 9c57323..2dc2cc3 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/mapper/xml/WorkTicketInfoMapper.xml +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/mapper/xml/WorkTicketInfoMapper.xml @@ -91,7 +91,7 @@ (select count(*) from hzims_work_ticket_info i where flow_description = '作废' and i.id = info.id) as invalid, (select count(*) from hzims_ticket_info_evaluate e where evaluate = '合格!' and e.id = eval.id) as qualified from hzims_work_ticket_info info - LEFT JOIN hzims_ticket_info_evaluate eval ON info.id = eval.ticket_i + LEFT JOIN hzims_ticket_info_evaluate eval ON info.id = eval.ticket_id and info.em_code in