diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/constants/Order.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/constants/Order.java new file mode 100644 index 0000000..67e68c4 --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/constants/Order.java @@ -0,0 +1,5 @@ +package com.hnac.hzims.common.support.constants; + +public enum Order { + ASC,DESC; +} diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/utils/Condition.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/utils/Condition.java new file mode 100644 index 0000000..c593bb0 --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/support/utils/Condition.java @@ -0,0 +1,49 @@ +package com.hnac.hzims.common.support.utils; + + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import com.hnac.hzims.common.support.constants.Order; +import org.springblade.core.tool.utils.BeanUtil; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.function.Function; + +public class Condition extends org.springblade.core.mp.support.Condition { + + public static List getFieldList(Object object) { + Class clazz = object.getClass(); + List fields = Lists.newArrayList(); + while (null != clazz){ + fields.addAll(Arrays.asList(clazz.getDeclaredFields())); + clazz = clazz.getSuperclass(); + } + return fields; + } + + public static LambdaQueryWrapper getQueryWrapper(Object query, Class clazz, Map> orderFields) { + QueryWrapper queryWrapper = getQueryWrapper(BeanUtil.copy(query,clazz)); + List fields = getFieldList(query); + // 填充排序字段 + orderFields.forEach((fieldName,order) -> { + Optional existField = fields.stream().filter(field -> camel2under(fieldName).equals(camel2under(field.getName()))).findAny(); + if(existField.isPresent()) { + if(Order.ASC.equals(order)) { + queryWrapper.orderByAsc(fieldName); + } + else if(Order.DESC.equals(order)) { + queryWrapper.orderByDesc(fieldName); + } + } + }); + return queryWrapper.lambda(); + } + + private static String camel2under(String c) { + String separator = "_"; + c = c.replaceAll("([a-z])([A-Z])", "$1" + separator + "$2").toUpperCase(); + return c; + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/DictConstants.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/DictConstants.java index e829c5b..a01b53e 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/DictConstants.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/DictConstants.java @@ -1,5 +1,11 @@ package com.hnac.hzims.safeproduct.constants; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + /** * @author xiashandong * @created 2021/5/27 10:09 @@ -11,4 +17,19 @@ public interface DictConstants { String DANGER_TYPE = "dangerType"; /**危险等级**/ String RISK_LEVEL = "riskLevel"; + + @AllArgsConstructor + enum DangerSourceTypeEnum { + OPERATION(1,"作业活动"), + EQUIPMENT(2,"设备"), + ; + @Getter + private Integer type; + @Getter + private String typeName; + public static String getTypeNameByType(Integer type) { + Optional first = Arrays.stream(DangerSourceTypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst(); + return first.map(DangerSourceTypeEnum::getTypeName).orElse(null); + } + } } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java index ebca8f7..f40f1a0 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java @@ -1,5 +1,7 @@ package com.hnac.hzims.safeproduct.entity; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; @@ -7,6 +9,8 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; import org.springblade.core.tenant.mp.TenantEntity; @@ -23,12 +27,14 @@ public class DangerSourceEntity extends TenantEntity { private static final long serialVersionUID = 1L; @ApiModelProperty("所属机构") + @QueryField(condition = SqlCondition.EQUAL) private Long refDept; @ApiModelProperty("所属机构名称") private String refDeptName; @ApiModelProperty(value = "危险源库ID") + @QueryField(condition = SqlCondition.EQUAL) private Long libraryId; /** @@ -36,15 +42,18 @@ public class DangerSourceEntity extends TenantEntity { */ @ApiModelProperty(value = "危险源类型 1=作业活动 2=设备") @JsonSerialize(nullsUsing = NullSerializer.class) + @QueryField(condition = SqlCondition.EQUAL) private Integer type; /** * 设备ID */ @ApiModelProperty(value = "设备ID") @JsonSerialize(nullsUsing = NullSerializer.class) + @QueryField(condition = SqlCondition.EQUAL) private Long eqId; @ApiModelProperty("设备编号") + @QueryField(condition = SqlCondition.LIKE) private String emCode; @ApiModelProperty("设备名称") @@ -53,17 +62,20 @@ public class DangerSourceEntity extends TenantEntity { * 危险源名称 */ @ApiModelProperty(value = "危险源名称") + @QueryField(condition = SqlCondition.LIKE) private String name; /** * 危险因素 */ @ApiModelProperty(value = "危险因素") + @QueryField(condition = SqlCondition.LIKE) private String dangerEle; /** * 应用类型 */ @ApiModelProperty(value = "应用类型") + @QueryField(condition = SqlCondition.EQUAL) private String applyType; /** * 可能导致的事故 @@ -80,6 +92,7 @@ public class DangerSourceEntity extends TenantEntity { */ @ApiModelProperty(value = "风险等级 10=稍有危险 20=一般危险 30=显著危险 40=高度危险") @JsonSerialize(nullsUsing = NullSerializer.class) + @QueryField(condition = SqlCondition.EQUAL) private Integer level; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/hazard/vo/DangerSourceVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/hazard/vo/DangerSourceVO.java index edab947..a212b4b 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/hazard/vo/DangerSourceVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/hazard/vo/DangerSourceVO.java @@ -1,5 +1,7 @@ package com.hnac.hzims.safeproduct.hazard.vo; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.hnac.hzims.safeproduct.entity.DangerSourceEntity; import com.hnac.hzims.safeproduct.hazard.enums.DangerSourceLevelEnum; import com.hnac.hzims.safeproduct.hazard.vo.DangerSourcePositionVO; @@ -23,6 +25,9 @@ public class DangerSourceVO extends DangerSourceEntity { @ApiModelProperty(value = "危险等级Name") private String applyTypeName; + @ApiModelProperty(value = "危险源类型名称") + private String typeName; + @ApiModelProperty("创建人名称") private String createUserName; diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java index 1aeae76..52bee71 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java @@ -47,4 +47,10 @@ public class HygieneRecordDetailVO { @ApiModelProperty("检查信息列表") private List checkList; + + @ApiModelProperty("年份") + private String year; + + @ApiModelProperty("月份") + private String month; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java index 72f5a91..4182137 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java @@ -2,7 +2,6 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.service.IRehearsalPlanService; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java index 8bbf0ea..f65f90d 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java @@ -2,7 +2,6 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.safeproduct.dto.TestDTO; import com.hnac.hzims.safeproduct.dto.TestScoreDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/controller/DangerSourceController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/controller/DangerSourceController.java index 268a02b..39e784f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/controller/DangerSourceController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/controller/DangerSourceController.java @@ -22,6 +22,7 @@ import org.springblade.core.tool.utils.Func; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -119,4 +120,11 @@ public class DangerSourceController extends BladeController { public R importDangerSource(@RequestBody HazardInstanceDTO req) { return R.status(dangerSourceService.importDangerSource(req)); } + + @GetMapping("/exportDangerSource") + @ApiOperation("导出危险源") + @ApiOperationSupport(order = 90) + public void exportDangerSource(DangerSourceEntity req, HttpServletResponse response) { + dangerSourceService.exportDangerSource(req,response); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java index 44d2889..53b565a 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java @@ -1,6 +1,9 @@ package com.hnac.hzims.safeproduct.hazard.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.common.support.constants.Order; +import com.hnac.hzims.common.support.utils.Condition; import com.hnac.hzims.safeproduct.hazard.dto.DangerSourceDTO; import com.hnac.hzims.safeproduct.entity.DangerSourceEntity; import com.hnac.hzims.safeproduct.hazard.dto.HazardInstanceDTO; @@ -13,7 +16,10 @@ import org.springblade.core.tool.api.R; import org.springblade.system.vo.CreateTableVO; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author xiashandong @@ -44,4 +50,17 @@ public interface IDangerSourceService extends BaseService { List safes(String safeInfos); Boolean importDangerSource(HazardInstanceDTO req); + + /** + * 导出危险源 + * @param req 筛选条件 + * @param response 请求响应 + */ + void exportDangerSource(DangerSourceEntity req, HttpServletResponse response); + + default LambdaQueryWrapper getQueryWrapper(Object req) { + Map param = new HashMap<>(); + param.put("create_time",Order.DESC); + return Condition.getQueryWrapper(req,DangerSourceEntity.class,param); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java index d4a369c..8e0418a 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java @@ -1,5 +1,8 @@ package com.hnac.hzims.safeproduct.hazard.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -7,8 +10,10 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.common.support.constants.Order; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; import com.hnac.hzims.safeproduct.constants.DictConstants; import com.hnac.hzims.safeproduct.hazard.dto.DangerSourceDTO; import com.hnac.hzims.safeproduct.hazard.dto.DangerSourcePositionDTO; @@ -25,6 +30,7 @@ import com.hnac.hzims.safeproduct.hazard.service.IDangerSourceService; import com.hnac.hzims.safeproduct.utils.ExcelToolListener; import com.hnac.hzims.safeproduct.utils.TableJsonUtils; import com.hnac.hzims.safeproduct.hazard.vo.DangerSourcePositionVO; +import com.hnac.hzims.safeproduct.vo.DangerSourceExportVO; import com.hnac.hzims.safeproduct.vo.DangerSourceReportVO; import com.hnac.hzims.safeproduct.hazard.vo.DangerSourceVO; import com.hnac.hzims.safeproduct.vo.SourceVO; @@ -33,6 +39,7 @@ import com.hnac.hzims.safeproduct.hazard.wrapper.DangerSourceWrapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; +import org.apache.poi.ss.usermodel.BorderStyle; import org.springblade.core.excel.support.ExcelException; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; @@ -52,9 +59,12 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -174,28 +184,7 @@ public class DangerSourceServiceImpl extends BaseServiceImpl> pageCondition(DangerSourceEntity req, Query query) { - Wrapper queryWrapper = new LambdaQueryWrapper() {{ - orderByDesc(DangerSourceEntity::getCreateTime); - if (req.getType() != null) { - eq(DangerSourceEntity::getType, req.getType()); - } - if (null != req.getEqId()) { - eq(DangerSourceEntity::getEqId, req.getEqId()); - } - if (null != req.getLevel()) { - eq(DangerSourceEntity::getLevel, req.getLevel()); - } - if (StringUtil.isNotBlank(req.getName())) { - like(DangerSourceEntity::getName, req.getName()); - } - if (StringUtil.isNotBlank(req.getDangerEle())) { - like(DangerSourceEntity::getDangerEle, req.getDangerEle()); - } - if (StringUtil.isNotBlank(req.getApplyType())) { - eq(DangerSourceEntity::getApplyType, req.getApplyType()); - } - }}; - IPage page = super.page(Condition.getPage(query), queryWrapper); + IPage page = super.page(Condition.getPage(query), getQueryWrapper(req)); page.setRecords(DangerSourceWrapper.build().listVO(page.getRecords())); return R.data(page); } @@ -327,6 +316,8 @@ public class DangerSourceServiceImpl extends BaseServiceImpl sourceList = req.getHazardList().stream().map(h -> { DangerSourceEntity result = JSONObject.parseObject(JSON.toJSONString(h), DangerSourceEntity.class); result.setId(null); + result.setEmCode(req.getEmCode()); + result.setEmName(req.getEmName()); result.setLibraryId(h.getId()); result.setRefDept(req.getDeptId()); result.setRefDeptName(req.getDeptName()); @@ -342,6 +333,38 @@ public class DangerSourceServiceImpl extends BaseServiceImpl dangerSourceList = this.list(getQueryWrapper(req)); + List voList = DangerSourceWrapper.build().listVO(dangerSourceList); + List exportVOList = BeanUtil.copy(voList, DangerSourceExportVO.class); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName; + try { + fileName = URLEncoder.encode("危险点列表", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); + contentWriteCellStyle.setBorderTop(BorderStyle.THIN); + contentWriteCellStyle.setBorderRight(BorderStyle.THIN); + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); + contentWriteCellStyle.setWrapped(true); + try { + EasyExcel.write(response.getOutputStream(), DangerSourceExportVO.class) + .registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle)) + .autoCloseStream(Boolean.FALSE).sheet("危险点列表") + .doWrite(exportVOList); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override public List listByTenantId(String tenantId) { return this.baseMapper.listByTenantId(tenantId); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java index e71adde..658b5f6 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java @@ -29,6 +29,8 @@ public class DangerSourceWrapper extends BaseEntityWrapper hygienePlanEntity.getStandardScore()) { @@ -122,7 +122,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl hygienePlanEntity.getStandardScore()) { @@ -138,11 +138,11 @@ public class HygieneRecordServiceImpl extends ServiceImpl checkDetailVOList = new ArrayList<>(); - for (int i = 0; i < zoneIds.length ; i++) { + for (int i = 0; i < zoneIds.length; i++) { HygieneZoneDetailVO zoneDetailVO = new HygieneZoneDetailVO(); HygieneZoneEntity hygieneZoneEntity = hygieneZoneService.getById(zoneIds[i]); BeanUtils.copyProperties(hygieneZoneEntity, zoneDetailVO); @@ -169,6 +169,29 @@ public class HygieneRecordServiceImpl extends ServiceImpl checkList = hygieneRecordDetailVO.getCheckList(); + List res = new ArrayList<>(); + checkList.forEach(item -> { + String[] checkItem = item.getCheckItem().split(","); + String[] checkItemScore = item.getCheckItemScore().split(","); + for (int i = 0; i < checkItem.length; i++) { + HygieneZoneDetailVO hygieneZoneDetailVO = new HygieneZoneDetailVO(); + hygieneZoneDetailVO.setZone(item.getZone()); + hygieneZoneDetailVO.setPrincipal(item.getPrincipal()); + hygieneZoneDetailVO.setResult(item.getResult()); + hygieneZoneDetailVO.setScore(item.getScore()); + hygieneZoneDetailVO.setCheckItem(checkItem[i]); + hygieneZoneDetailVO.setCheckItemScore(checkItemScore[i]); + res.add(hygieneZoneDetailVO); + } + }); + // 表头 + String code = hygieneRecordDetailVO.getCode(); + hygieneRecordDetailVO.setYear(code.substring(4, 8)); + hygieneRecordDetailVO.setMonth(code.substring(8, 10)); + hygieneRecordDetailVO.setCheckList(res); Map params = BaseUtil.obj2Map(hygieneRecordDetailVO); String templateFile = "template/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; String wordPath = savePath + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java index c40c905..09cc4df 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java @@ -70,7 +70,7 @@ public class TestServiceImpl extends ServiceImpl impleme TestEntity test = getTestByCode(testEntity.getCode()); // 获取姓名数组 String people = test.getPeopleName(); - String[] person = people.split(",|,"); + String[] person = people.split(","); // 新增参考人员成绩数据 List scoreList = getReferenceTestScore(test, person); return R.status(testScoreService.saveBatch(scoreList)); @@ -169,7 +169,7 @@ public class TestServiceImpl extends ServiceImpl impleme boolean removeByIds = testScoreService.removeByIds(scoreIds); // 若删除成功,新增新的考试成绩数据 if (removeByIds) { - String[] person = testEntity.getPeopleName().split(",|,"); + String[] person = testEntity.getPeopleName().split(","); // 新增参考人员成绩数据 List scoreList = getReferenceTestScore(testEntity, person); return testScoreService.saveBatch(scoreList); diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java index 3118280..20028cd 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java @@ -6,6 +6,10 @@ import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.apache.poi.xwpf.usermodel.XWPFTableRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -106,11 +110,15 @@ public class BaseUtil { * 数据写入 * @param templatePath 模板文件路径 * @param params 数据参数 + * @return 文件 */ public static XWPFDocument fillDocument(String templatePath, Map params) { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); + if (templatePath.equals("template/卫生自查表.docx")) { + formatHygieneRecordTable(xwpfDocument); + } } catch (Exception e) { log.error("数据写入异常: {}", e.getMessage()); e.printStackTrace(); @@ -119,6 +127,60 @@ public class BaseUtil { } /** + * 卫生自查表格式处理 + * @param xwpfDocument word文件类 + */ + private static void formatHygieneRecordTable(XWPFDocument xwpfDocument) { + // 获取文档中所有的表格 + List tableList = xwpfDocument.getTables(); + if (tableList.size() > 0) { + // 循环表格 + for (XWPFTable table : tableList) { + // 获取表格所有行数 + List rows = table.getRows(); + // 第三行到倒数第二行为需合并区域 + for (int row = 3; row < rows.size() - 1;) { + XWPFTableCell startCell = rows.get(row).getCell(0); + String startText = startCell.getText(); + int index = row + 1; + for (; index < rows.size(); index++) { + XWPFTableCell endCell = rows.get(index).getCell(0); + String endText = endCell.getText(); + if (!startText.equals(endText)) { + break; + } + } + mergeCellsVertically(table, 0, row, index - 1); + mergeCellsVertically(table, 1, row, index - 1); + mergeCellsVertically(table, 4, row, index - 1); + mergeCellsVertically(table, 5, row, index - 1); + row = index; + } + } + } + } + + /** + * word单元格行合并 + * @param table 表格 + * @param col 合并行所在列 + * @param startRow 开始行 + * @param endRow 结束行 + */ + public static void mergeCellsVertically(XWPFTable table, int col, int startRow, int endRow) { + for (int i = startRow; i <= endRow; i++) { + XWPFTableCell cell = table.getRow(i).getCell(col); + if (i == startRow) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + } + } + } + + /** * 读取本地pdf,这里设置的是预览 * @param response 响应类 * @param filePath 文件路径 diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/vo/DangerSourceExportVO.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/vo/DangerSourceExportVO.java new file mode 100644 index 0000000..8c69bd3 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/vo/DangerSourceExportVO.java @@ -0,0 +1,43 @@ +package com.hnac.hzims.safeproduct.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode +public class DangerSourceExportVO implements Serializable { + + @ExcelProperty(value = "所属站点",index = 0) + @ColumnWidth(value = 25) + private String refDeptName; + + @ExcelProperty(value = "危险源类型",index = 1) + @ColumnWidth(value = 15) + private String typeName; + + @ExcelProperty(value = "风险等级",index = 2) + @ColumnWidth(value = 20) + private String levelName; + + @ExcelProperty(value = "设备",index = 3) + @ColumnWidth(value = 15) + private String emName; + + @ExcelProperty(value = "危险源名称",index = 4) + @ColumnWidth(value = 30) + private String name; + + @ExcelProperty(value = "危险因素",index = 5) + @ColumnWidth(value = 30) + private String dangerEle; + + @ExcelProperty(value = "措施",index = 6) + @ColumnWidth(value = 40) + private String measures; + +} diff --git a/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx b/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx index 06133d5..141b2ae 100644 Binary files a/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx and b/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx differ