Browse Source

# 风险点列表导出接口

zhongwei
haungxing 10 months ago
parent
commit
4f36b1a680
  1. 5
      hzims-biz-common/src/main/java/com/hnac/hzims/common/support/constants/Order.java
  2. 49
      hzims-biz-common/src/main/java/com/hnac/hzims/common/support/utils/Condition.java
  3. 2
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java
  4. 11
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/IDangerSourceService.java
  5. 28
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java

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

49
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<Field> getFieldList(Object object) {
Class<?> clazz = object.getClass();
List<Field> fields = Lists.newArrayList();
while (null != clazz){
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
return fields;
}
public static <T> LambdaQueryWrapper<T> getQueryWrapper(Object query, Class<T> clazz, Map<String,? extends Enum<Order>> orderFields) {
QueryWrapper<T> queryWrapper = getQueryWrapper(BeanUtil.copy(query,clazz));
List<Field> fields = getFieldList(query);
// 填充排序字段
orderFields.forEach((fieldName,order) -> {
Optional<Field> 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;
}
}

2
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DangerSourceEntity.java

@ -49,6 +49,7 @@ public class DangerSourceEntity extends TenantEntity {
*/ */
@ApiModelProperty(value = "设备ID") @ApiModelProperty(value = "设备ID")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
@QueryField(condition = SqlCondition.EQUAL)
private Long eqId; private Long eqId;
@ApiModelProperty("设备编号") @ApiModelProperty("设备编号")
@ -74,6 +75,7 @@ public class DangerSourceEntity extends TenantEntity {
* 应用类型 * 应用类型
*/ */
@ApiModelProperty(value = "应用类型") @ApiModelProperty(value = "应用类型")
@QueryField(condition = SqlCondition.EQUAL)
private String applyType; private String applyType;
/** /**
* 可能导致的事故 * 可能导致的事故

11
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; package com.hnac.hzims.safeproduct.hazard.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; 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.hazard.dto.DangerSourceDTO;
import com.hnac.hzims.safeproduct.entity.DangerSourceEntity; import com.hnac.hzims.safeproduct.entity.DangerSourceEntity;
import com.hnac.hzims.safeproduct.hazard.dto.HazardInstanceDTO; import com.hnac.hzims.safeproduct.hazard.dto.HazardInstanceDTO;
@ -14,7 +17,9 @@ import org.springblade.system.vo.CreateTableVO;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author xiashandong * @author xiashandong
@ -52,4 +57,10 @@ public interface IDangerSourceService extends BaseService<DangerSourceEntity> {
* @param response 请求响应 * @param response 请求响应
*/ */
void exportDangerSource(DangerSourceEntity req, HttpServletResponse response); void exportDangerSource(DangerSourceEntity req, HttpServletResponse response);
default LambdaQueryWrapper<DangerSourceEntity> getQueryWrapper(Object req) {
Map<String, Order> param = new HashMap<>();
param.put("create_time",Order.DESC);
return Condition.getQueryWrapper(req,DangerSourceEntity.class,param);
}
} }

28
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/hazard/service/impl/DangerSourceServiceImpl.java

@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; 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.entity.EmInfoEntity;
import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO;
@ -183,28 +184,7 @@ public class DangerSourceServiceImpl extends BaseServiceImpl<DangerSourceMapper,
@Override @Override
public R<IPage<DangerSourceVO>> pageCondition(DangerSourceEntity req, Query query) { public R<IPage<DangerSourceVO>> pageCondition(DangerSourceEntity req, Query query) {
Wrapper<DangerSourceEntity> queryWrapper = new LambdaQueryWrapper<DangerSourceEntity>() {{ IPage page = super.page(Condition.getPage(query), getQueryWrapper(req));
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);
page.setRecords(DangerSourceWrapper.build().listVO(page.getRecords())); page.setRecords(DangerSourceWrapper.build().listVO(page.getRecords()));
return R.data(page); return R.data(page);
} }
@ -336,6 +316,8 @@ public class DangerSourceServiceImpl extends BaseServiceImpl<DangerSourceMapper,
List<DangerSourceEntity> sourceList = req.getHazardList().stream().map(h -> { List<DangerSourceEntity> sourceList = req.getHazardList().stream().map(h -> {
DangerSourceEntity result = JSONObject.parseObject(JSON.toJSONString(h), DangerSourceEntity.class); DangerSourceEntity result = JSONObject.parseObject(JSON.toJSONString(h), DangerSourceEntity.class);
result.setId(null); result.setId(null);
result.setEmCode(req.getEmCode());
result.setEmName(req.getEmName());
result.setLibraryId(h.getId()); result.setLibraryId(h.getId());
result.setRefDept(req.getDeptId()); result.setRefDept(req.getDeptId());
result.setRefDeptName(req.getDeptName()); result.setRefDeptName(req.getDeptName());
@ -352,7 +334,7 @@ public class DangerSourceServiceImpl extends BaseServiceImpl<DangerSourceMapper,
@Override @Override
public void exportDangerSource(DangerSourceEntity req, HttpServletResponse response) { public void exportDangerSource(DangerSourceEntity req, HttpServletResponse response) {
List<DangerSourceEntity> dangerSourceList = this.list(Condition.getQueryWrapper(req)); List<DangerSourceEntity> dangerSourceList = this.list(getQueryWrapper(req));
List<DangerSourceVO> voList = DangerSourceWrapper.build().listVO(dangerSourceList); List<DangerSourceVO> voList = DangerSourceWrapper.build().listVO(dangerSourceList);
List<DangerSourceExportVO> exportVOList = BeanUtil.copy(voList, DangerSourceExportVO.class); List<DangerSourceExportVO> exportVOList = BeanUtil.copy(voList, DangerSourceExportVO.class);
// 设置响应头 // 设置响应头

Loading…
Cancel
Save