yang_shj
10 months ago
35 changed files with 609 additions and 148 deletions
@ -0,0 +1,5 @@
|
||||
package com.hnac.hzims.common.support.constants; |
||||
|
||||
public enum Order { |
||||
ASC,DESC; |
||||
} |
@ -0,0 +1,112 @@
|
||||
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.log.exception.ServiceException; |
||||
import org.springblade.core.mp.support.QueryField; |
||||
import org.springblade.core.mp.support.SqlCondition; |
||||
import org.springblade.core.tool.utils.BeanUtil; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springframework.util.Assert; |
||||
|
||||
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(query,clazz); |
||||
List<Field> fields = getFieldList(query); |
||||
// 填充排序字段
|
||||
orderFields.forEach((fieldNames,order) -> { |
||||
Func.toStrList(",",fieldNames).stream().forEach(fieldName -> { |
||||
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; |
||||
} |
||||
|
||||
private static <T> QueryWrapper<T> getQueryWrapper(Object query, Class<T> clazz) { |
||||
QueryWrapper qw = new QueryWrapper(); |
||||
qw.setEntityClass(clazz); |
||||
List<Field> fieldList = getFieldList(query); |
||||
for(Field field:fieldList){ |
||||
field.setAccessible(true); |
||||
QueryField queryField = field.getAnnotation(QueryField.class); |
||||
if(queryField==null) { |
||||
continue; |
||||
} |
||||
Object value; |
||||
try { |
||||
value = field.get(query); |
||||
} catch (Exception e) { |
||||
throw new ServiceException("获取属性性出错"); |
||||
} |
||||
if(value == null) { |
||||
continue; |
||||
} |
||||
List list = null; |
||||
if(value instanceof List){ |
||||
list = (List)value; |
||||
if(list.size() == 0) { |
||||
continue; |
||||
} |
||||
} |
||||
String condition = queryField.condition(); |
||||
if(Func.isBlank(condition)) { |
||||
continue; |
||||
} |
||||
String fileName = camel2under(field.getName()); |
||||
if(SqlCondition.EQUAL.equals(condition)) { |
||||
qw.eq(fileName, value); |
||||
}else if(SqlCondition.LIKE.equals(condition)){ |
||||
qw.like(fileName,value); |
||||
}else if(SqlCondition.LIKE_LEFT.equals(condition)){ |
||||
qw.likeLeft(fileName,value); |
||||
}else if(SqlCondition.LIKE_RIGHT.equals(condition)){ |
||||
qw.likeRight(fileName,value); |
||||
}else if(SqlCondition.NOT_IN.equals(condition)){ |
||||
String columnName = queryField.columnName(); |
||||
Assert.isTrue(Func.isBlank(columnName),() -> { |
||||
throw new ServiceException("查询不包含条件时需要指定列名"); |
||||
}); |
||||
qw.notIn(camel2under(columnName),list); |
||||
}else if(SqlCondition.IN.equals(condition)){ |
||||
String columnName = queryField.columnName(); |
||||
Assert.isTrue(Func.isBlank(columnName), () -> { |
||||
throw new ServiceException("查询包含条件时需要指定列名"); |
||||
}); |
||||
qw.in(camel2under(columnName),list); |
||||
} |
||||
} |
||||
return qw; |
||||
} |
||||
} |
@ -0,0 +1,3 @@
|
||||
-- 参数分组还原添加字段 |
||||
alter table `HZIMS_PARAM_BACKUPS_DETAIL` add column `model_classify_id` BIGINT(20) COMMENT '参数分组'; |
||||
alter table `HZIMS_PARAM_BACKUPS_DETAIL` add column `model_classify_name` BIGINT(20) COMMENT '参数分组名称'; |
@ -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; |
||||
|
||||
} |
Binary file not shown.
Loading…
Reference in new issue