Browse Source

# 风险点列表导出接口

zhongwei
haungxing 12 months ago
parent
commit
8507fa7e42
  1. 2
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java
  2. 21
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/DictConstants.java
  3. 11
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java
  4. 5
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/hazard/vo/DangerSourceVO.java
  5. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/controller/DangerSourceController.java
  6. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java
  7. 41
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java
  8. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java
  9. 43
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/vo/DangerSourceExportVO.java

2
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";
/**
* 安全生产标准化评审标准

21
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<DangerSourceTypeEnum> first = Arrays.stream(DangerSourceTypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst();
return first.map(DangerSourceTypeEnum::getTypeName).orElse(null);
}
}
}

11
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;
}

5
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;

8
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);
}
}

8
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<DangerSourceEntity> {
List<DangerSourceEntity> safes(String safeInfos);
Boolean importDangerSource(HazardInstanceDTO req);
/**
* 导出危险源
* @param req 筛选条件
* @param response 请求响应
*/
void exportDangerSource(DangerSourceEntity req, HttpServletResponse response);
}

41
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<DangerSourceMapper,
}
@Override
public void exportDangerSource(DangerSourceEntity req, HttpServletResponse response) {
List<DangerSourceEntity> dangerSourceList = this.list(Condition.getQueryWrapper(req));
List<DangerSourceVO> voList = DangerSourceWrapper.build().listVO(dangerSourceList);
List<DangerSourceExportVO> 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<SourceVO> listByTenantId(String tenantId) {
return this.baseMapper.listByTenantId(tenantId);
}

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/wrapper/DangerSourceWrapper.java

@ -29,6 +29,8 @@ public class DangerSourceWrapper extends BaseEntityWrapper<DangerSourceEntity, D
vo.setCreateUserName(Optional.ofNullable(createUser).map(User::getName).orElse(null));
vo.setUpdateUserName(Optional.ofNullable(updateUser).map(User::getName).orElse(null));
vo.setApplyTypeName(DictCache.getValue(DictConstants.SAFE_DANGER_SOURCE_APPLY_TYPE, entity.getApplyType()));
vo.setLevelName(DictCache.getValue(DictConstants.RISK_LEVEL, entity.getLevel()));
vo.setTypeName(DictConstants.DangerSourceTypeEnum.getTypeNameByType(entity.getType()));
return vo;
}

43
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;
}
Loading…
Cancel
Save