mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、新增组织编辑修改首购价格能力;2、账单分页支持非管理端只允许查看本组织下;3、统计公共入参和方法抽象、过期组织接口分离移到system、新增销售额统计接口;
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
package com.cf.imes.framework.common.enums;
|
||||
|
||||
/**
|
||||
* 统计维度单位
|
||||
* @author Gqr
|
||||
* @since 2024/8/6 10:04
|
||||
*/
|
||||
public enum StatisticsUnit {
|
||||
//季度、月、周、日
|
||||
QUARTER(0),
|
||||
MONTH(1),
|
||||
WEEK(2),
|
||||
DAY(3);
|
||||
|
||||
StatisticsUnit(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private Integer value;
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
// from value
|
||||
public static StatisticsUnit fromValue(Integer value) {
|
||||
for (StatisticsUnit unit : StatisticsUnit.values()) {
|
||||
if (unit.getValue().equals(value)) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.cf.imes.framework.common.pojo;
|
||||
|
||||
import com.cf.imes.framework.common.util.validation.statistics.StatisticsUnitInEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 通用统计 ReqVO
|
||||
* @author Gqr
|
||||
* @since 2025/9/29 16:50
|
||||
*/
|
||||
@Data
|
||||
public class CommonStatisticsReqVO {
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate[] createTime;
|
||||
|
||||
/**
|
||||
* 统计维度单位
|
||||
*/
|
||||
@Schema(description = "统计维度单位", example = "0", allowableValues = {"0", "1", "2", "3"}, type = "integer")
|
||||
@NotNull(message = "统计维度单位不能为空")
|
||||
@StatisticsUnitInEnum
|
||||
private Integer unit;
|
||||
}
|
||||
+83
-14
@@ -1,7 +1,10 @@
|
||||
package com.cf.imes.framework.common.util.time;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.OrderStatisticsUnit;
|
||||
import com.cf.imes.framework.common.enums.StatisticsUnit;
|
||||
import com.cf.imes.framework.common.pojo.CommonStatisticsReqVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -22,12 +25,15 @@ public class StatisticsChangeUtils {
|
||||
* 3、返回所有日期的集合
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getDateList(LocalDate[] createTime, Integer unit) {
|
||||
public static List<String> getDateList(CommonStatisticsReqVO reqVO) {
|
||||
// 计算时间跨度
|
||||
getTimeSpan(createTime, unit);
|
||||
getTimeSpan(reqVO);
|
||||
|
||||
// 重新计算开始时间和结束时间
|
||||
computeTimeSpan(reqVO);
|
||||
|
||||
// 所有的日期集合
|
||||
return generateDateRange(createTime, unit);
|
||||
return generateDateRange(reqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,13 +41,14 @@ public class StatisticsChangeUtils {
|
||||
* 计算起止时间:前端不传入时间就根据维度单位从当前日期计算
|
||||
*
|
||||
*/
|
||||
public static LocalDate[] getTimeSpan(LocalDate[] createTime, Integer unit) {
|
||||
public static void getTimeSpan(CommonStatisticsReqVO reqVO) {
|
||||
LocalDate[] createTime = reqVO.getCreateTime();
|
||||
LocalDate startTime = null;
|
||||
LocalDate endTime;
|
||||
LocalDate now = LocalDate.now();
|
||||
if (ObjectUtil.isNull(createTime) || ObjectUtil.isNull(createTime[0]) || ObjectUtil.isNull(createTime[1])) {
|
||||
if (ArrayUtil.isEmpty(createTime) || ObjectUtil.isNull(createTime[0]) || ObjectUtil.isNull(createTime[1])) {
|
||||
endTime = now;
|
||||
switch (OrderStatisticsUnit.fromValue(unit)) {
|
||||
switch (StatisticsUnit.fromValue(reqVO.getUnit())) {
|
||||
case QUARTER:
|
||||
// 从now往前的2年
|
||||
startTime = now.minusYears(2);
|
||||
@@ -62,10 +69,45 @@ public class StatisticsChangeUtils {
|
||||
break;
|
||||
}
|
||||
// 声明一个LocalDateTime的数组,把startTime和endTime放进去
|
||||
createTime[0] = startTime;
|
||||
createTime[1] = endTime;
|
||||
reqVO.setCreateTime(new LocalDate[]{startTime, endTime});
|
||||
}
|
||||
return createTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入信息重新计算时间范围
|
||||
*
|
||||
* @param reqVO
|
||||
*/
|
||||
public static void computeTimeSpan(CommonStatisticsReqVO reqVO) {
|
||||
Integer unit = reqVO.getUnit();
|
||||
// 计算后的开始和结束时间
|
||||
LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]);
|
||||
LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]);
|
||||
|
||||
if (startDate.isAfter(endDate)) {
|
||||
startDate = ObjectUtil.clone(reqVO.getCreateTime()[1]);
|
||||
endDate = ObjectUtil.clone(reqVO.getCreateTime()[0]);
|
||||
}
|
||||
LocalDate first = startDate;
|
||||
LocalDate end = endDate;
|
||||
switch (OrderStatisticsUnit.fromValue(unit)) {
|
||||
case QUARTER -> {
|
||||
first = firstDayOfQuarter(startDate);
|
||||
end = lastDayOfQuarter(endDate);
|
||||
}
|
||||
case MONTH -> {
|
||||
first = startDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
end = endDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||
}
|
||||
case WEEK -> {
|
||||
first = startDate.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));
|
||||
end = endDate.with(TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY));
|
||||
}
|
||||
default -> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
reqVO.setCreateTime(new LocalDate[]{first, end});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,12 +115,13 @@ public class StatisticsChangeUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<String> generateDateRange(LocalDate[] createTime, Integer unit) {
|
||||
public static List<String> generateDateRange(CommonStatisticsReqVO reqVO) {
|
||||
Integer unit = reqVO.getUnit();
|
||||
// 计算时间跨度
|
||||
getTimeSpan(createTime, unit);
|
||||
// 计算后的开始和结束时间
|
||||
LocalDate startDate = ObjectUtil.clone(createTime[0]);
|
||||
LocalDate endDate = ObjectUtil.clone(createTime[1]);
|
||||
getTimeSpan(reqVO);
|
||||
// 计算后的开始和结束时间
|
||||
LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]);
|
||||
LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]);
|
||||
|
||||
List<String> dates = new ArrayList<>();
|
||||
while (!startDate.isAfter(endDate)) {
|
||||
@@ -146,4 +189,30 @@ public class StatisticsChangeUtils {
|
||||
}
|
||||
return newDateStrBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在季度的开始日期
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
private static LocalDate firstDayOfQuarter(LocalDate date) {
|
||||
int month = date.getMonthValue();
|
||||
int quarter = (month - 1) / 3 + 1;
|
||||
int startMonth = (quarter - 1) * 3 + 1;
|
||||
return LocalDate.of(date.getYear(), startMonth, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在季度的结束日期
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
private static LocalDate lastDayOfQuarter(LocalDate date) {
|
||||
int month = date.getMonthValue();
|
||||
int quarter = (month - 1) / 3 + 1;
|
||||
int endMonth = (quarter - 1) * 3 + 3;
|
||||
return LocalDate.of(date.getYear(), endMonth, 1).with(TemporalAdjusters.lastDayOfMonth());
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.cf.imes.framework.common.util.validation.statistics;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 统计维度单位入参校验注解
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/17 9:33
|
||||
*/
|
||||
@Target({
|
||||
ElementType.METHOD,
|
||||
ElementType.FIELD,
|
||||
ElementType.ANNOTATION_TYPE,
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.TYPE_USE
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = {StatisticsUnitInEnumValidator.class}
|
||||
)
|
||||
public @interface StatisticsUnitInEnum {
|
||||
String message() default "统计维度单位[unit]错误,请检查";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.cf.imes.framework.common.util.validation.statistics;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.StatisticsUnit;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* 统计维度单位入参校验器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/17 9:33
|
||||
*/
|
||||
public class StatisticsUnitInEnumValidator implements ConstraintValidator<StatisticsUnitInEnum, Integer> {
|
||||
|
||||
@Override
|
||||
public void initialize(StatisticsUnitInEnum constraintAnnotation) {
|
||||
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
StatisticsUnit unit = StatisticsUnit.fromValue(value);
|
||||
if (ObjectUtil.isNotNull(unit)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user