From 8507fa7e425ef1dabb440036c3e109bddf08f3d8 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Sun, 4 Feb 2024 16:05:31 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E9=A3=8E=E9=99=A9=E7=82=B9=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/safeproduct/Constants.java | 2 +- .../hzims/safeproduct/constants/DictConstants.java | 21 +++++++++++ .../safeproduct/entity/DangerSourceEntity.java | 11 ++++++ .../safeproduct/hazard/vo/DangerSourceVO.java | 5 +++ .../hazard/controller/DangerSourceController.java | 8 ++++ .../hazard/service/IDangerSourceService.java | 8 ++++ .../service/impl/DangerSourceServiceImpl.java | 41 +++++++++++++++++++++ .../hazard/wrapper/DangerSourceWrapper.java | 2 + .../hzims/safeproduct/vo/DangerSourceExportVO.java | 43 ++++++++++++++++++++++ 9 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/vo/DangerSourceExportVO.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java index eceea8d..fad01b2 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; * @Author: py */ public class Constants { - public final static String APP_NAME = "hzims-safeproduct"; + public final static String APP_NAME = "hzims-safeproduct-hx"; /** * 安全生产标准化评审标准 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..7d56405 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,6 +42,7 @@ public class DangerSourceEntity extends TenantEntity { */ @ApiModelProperty(value = "危险源类型 1=作业活动 2=设备") @JsonSerialize(nullsUsing = NullSerializer.class) + @QueryField(condition = SqlCondition.EQUAL) private Integer type; /** * 设备ID @@ -45,6 +52,7 @@ public class DangerSourceEntity extends TenantEntity { private Long eqId; @ApiModelProperty("设备编号") + @QueryField(condition = SqlCondition.LIKE) private String emCode; @ApiModelProperty("设备名称") @@ -53,11 +61,13 @@ public class DangerSourceEntity extends TenantEntity { * 危险源名称 */ @ApiModelProperty(value = "危险源名称") + @QueryField(condition = SqlCondition.LIKE) private String name; /** * 危险因素 */ @ApiModelProperty(value = "危险因素") + @QueryField(condition = SqlCondition.LIKE) private String dangerEle; /** @@ -80,6 +90,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/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..eb26ebf 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 @@ -13,6 +13,7 @@ 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.List; /** @@ -44,4 +45,11 @@ public interface IDangerSourceService extends BaseService { List safes(String safeInfos); Boolean importDangerSource(HazardInstanceDTO req); + + /** + * 导出危险源 + * @param req 筛选条件 + * @param response 请求响应 + */ + void exportDangerSource(DangerSourceEntity req, HttpServletResponse response); } 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..4a8e35e 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; @@ -9,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; 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 +29,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 +38,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 +58,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; @@ -342,6 +351,38 @@ public class DangerSourceServiceImpl extends BaseServiceImpl dangerSourceList = this.list(Condition.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