完成责任量化功能
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.njcn.common.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月25日 09:40
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SelectOption implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -82,6 +82,10 @@ public enum CommonResponseEnum {
|
||||
|
||||
FILE_EXIST("A0096", "文件已存在"),
|
||||
|
||||
FILE_SIZE_ERROR("A0096", "文件过大"),
|
||||
|
||||
FILE_XLSX_ERROR("A0096", "请上传excel文件"),
|
||||
|
||||
DEPT_EXIST("A0097", "部门id已存在"),
|
||||
|
||||
DEPT_NOT_EXIST("A0098", "部门id不存在"),
|
||||
@@ -95,6 +99,8 @@ public enum CommonResponseEnum {
|
||||
MATH_ERROR("A0103","比例总和大于100%"),
|
||||
CS_DEVICE_RESPONSE_ENUM("A0104", "治理终端响应枚举类型"),
|
||||
|
||||
ADVANCE_RESPONSE_ENUM("A00105", "终端响应枚举类型"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -15,15 +15,18 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -307,6 +310,78 @@ public class PubUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前时间的秒数置为0
|
||||
*
|
||||
* @param date 时间
|
||||
*/
|
||||
public static Date getSecondsAsZero(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据起始时间和截止时间返回yyyy-MM-dd的日期,
|
||||
*
|
||||
* @param startTime 起始时间
|
||||
* @param endTime 截止时间
|
||||
*/
|
||||
public static List<String> getTimes(Date startTime, Date endTime) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
List<String> result = new ArrayList<>();
|
||||
Calendar start = Calendar.getInstance();
|
||||
start.setTime(startTime);
|
||||
Calendar end = Calendar.getInstance();
|
||||
end.setTime(endTime);
|
||||
end.set(end.get(Calendar.YEAR), end.get(Calendar.MONTH), end.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
||||
long interval = end.getTimeInMillis() - start.getTimeInMillis();
|
||||
result.add(sdf.format(start.getTime()));
|
||||
if (interval > 0) {
|
||||
int days = (int) (interval / 86400000);
|
||||
for (int i = 0; i < days; i++) {
|
||||
start.add(Calendar.DAY_OF_MONTH, 1);
|
||||
result.add(sdf.format(start.getTime()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/***
|
||||
* 将instant转为date 处理8小时误差
|
||||
* @author hongawen
|
||||
* @date 2023/7/20 15:58
|
||||
* @param instant 日期
|
||||
* @return Instant
|
||||
*/
|
||||
public static Date instantToDate(Instant instant){
|
||||
return Date.from(instant.minusMillis(TimeUnit.HOURS.toMillis(8)));
|
||||
}
|
||||
|
||||
/***
|
||||
* 将date转为instant 处理8小时误差
|
||||
* @author hongawen
|
||||
* @date 2023/7/20 15:58
|
||||
* @param date 日期
|
||||
* @return Instant
|
||||
*/
|
||||
public static Instant dateToInstant(Date date){
|
||||
return date.toInstant().plusMillis(TimeUnit.HOURS.toMillis(8));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据参数返回float的四舍五入值
|
||||
*
|
||||
* @param i 保留的位数
|
||||
* @param value float原值
|
||||
*/
|
||||
public static Float floatRound(int i, float value) {
|
||||
BigDecimal bp = new BigDecimal(value);
|
||||
return bp.setScale(i, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
}
|
||||
|
||||
//*****************************************xuyang添加,用于App********************************************************
|
||||
/**
|
||||
* 正则表达式字符串
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.common.utils.serializer;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月24日 13:33
|
||||
*/
|
||||
@Component
|
||||
public class InstantDateDeserializer extends StdDeserializer<Instant> {
|
||||
|
||||
|
||||
public InstantDateDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
|
||||
protected InstantDateDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
String text = p.getValueAsString();
|
||||
return PubUtils.dateToInstant(DateUtil.parse(text,DatePattern.NORM_DATETIME_PATTERN));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class InstantDateSerializer extends StdSerializer<Instant> {
|
||||
if (instant == null) {
|
||||
return;
|
||||
}
|
||||
String jsonValue = format.format(instant.atZone(ZoneId.systemDefault()));
|
||||
String jsonValue = format.format(instant.atZone(ZoneId.of("+00:00")));
|
||||
jsonGenerator.writeString(jsonValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user