diff --git a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/enums/OrderStatusEnum.java b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/enums/OrderStatusEnum.java index 9579d7ef7..219b46a9d 100644 --- a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/enums/OrderStatusEnum.java +++ b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/enums/OrderStatusEnum.java @@ -8,7 +8,7 @@ import lombok.Getter; @Getter public enum OrderStatusEnum { - EMPTY(0, "默认"), + EMPTY(0, "空单"), NEW_ORDER(1, "新单"), NO_SORT(2, "未排单"), IN_PRODUCTION(3, "生产中"), diff --git a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/validation/Mobile.java b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/validation/Mobile.java index 3bfa34000..7d089476d 100644 --- a/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/validation/Mobile.java +++ b/cf-framework/cf-common/src/main/java/com/cf/imes/framework/common/validation/Mobile.java @@ -19,7 +19,7 @@ import java.lang.annotation.*; ) public @interface Mobile { - String message() default "手机号格式不正确"; + String message() default "手机号格式不正确,请重新确认"; Class[] groups() default {}; diff --git a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/security/OrganSecurityWebFilter.java b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/security/OrganSecurityWebFilter.java index 64fd51034..00b9d1fd7 100644 --- a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/security/OrganSecurityWebFilter.java +++ b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/security/OrganSecurityWebFilter.java @@ -1,6 +1,7 @@ package com.cf.imes.framework.organ.core.security; import cn.hutool.core.collection.CollUtil; +import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants; import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.framework.common.util.servlet.ServletUtils; @@ -13,6 +14,7 @@ import com.cf.imes.framework.web.config.WebProperties; import com.cf.imes.framework.web.core.filter.ApiRequestFilter; import com.cf.imes.framework.web.core.handler.GlobalExceptionHandler; import com.cf.imes.framework.web.core.util.WebFrameworkUtils; +import com.cf.imes.module.system.enums.ErrorCodeConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.util.AntPathMatcher; @@ -90,6 +92,10 @@ public class OrganSecurityWebFilter extends ApiRequestFilter { organFrameworkService.validOrgan(organId); } catch (Throwable ex) { CommonResult result = globalExceptionHandler.allExceptionHandler(request, ex); + // 组织失效返回401踢出系统 + if (needUnauthorizedWhenOrgExpired(ex)) { + result.setCode(GlobalErrorCodeConstants.UNAUTHORIZED.getCode()); + } ServletUtils.writeJSON(response, result); return; } @@ -117,4 +123,21 @@ public class OrganSecurityWebFilter extends ApiRequestFilter { return false; } + /** + * 是否组织失效设置未登录回调 + * + * @param ex + * @return + */ + private boolean needUnauthorizedWhenOrgExpired(Throwable ex) { + if (ex instanceof ServiceException) { + ServiceException serviceException = (ServiceException) ex; + if (Objects.equals(serviceException.getCode(), ErrorCodeConstants.ORGAN_EXPIRE.getCode()) + || Objects.equals(serviceException.getCode(), ErrorCodeConstants.ORGAN_DISABLE.getCode()) + || Objects.equals(serviceException.getCode(), ErrorCodeConstants.ORGAN_NOT_EXISTS.getCode())) { + return true; + } + } + return false; + } } diff --git a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/service/OrganFrameworkServiceImpl.java b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/service/OrganFrameworkServiceImpl.java index 134767c92..a065cdddc 100644 --- a/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/service/OrganFrameworkServiceImpl.java +++ b/cf-framework/cf-spring-boot-starter-biz-organ/src/main/java/com/cf/imes/framework/organ/core/service/OrganFrameworkServiceImpl.java @@ -1,6 +1,5 @@ package com.cf.imes.framework.organ.core.service; -import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.framework.common.util.cache.CacheUtils; import com.cf.imes.module.system.api.organ.OrganApi; import com.google.common.cache.CacheLoader; @@ -26,7 +25,7 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService { */ private final LoadingCache> getOrganIdsCache = CacheUtils.buildAsyncReloadingCache( Duration.ofMinutes(1L), // 过期时间 1 分钟 - new CacheLoader>() { + new CacheLoader<>() { @Override public List load(Object key) { @@ -35,20 +34,6 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService { }); - /** - * 针对 {@link #validOrgan(Long)} 的缓存 - */ - private final LoadingCache> validOrganCache = CacheUtils.buildAsyncReloadingCache( - Duration.ofMinutes(1L), // 过期时间 1 分钟 - new CacheLoader>() { - - @Override - public CommonResult load(Long id) { - return organApi.validOrgan(id); - } - - }); - @Override @SneakyThrows public List getOrganIds() { @@ -58,7 +43,7 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService { @Override @SneakyThrows public void validOrgan(Long id) { - validOrganCache.get(id).checkError(); + organApi.validOrgan(id).checkError(); } } diff --git a/cf-framework/cf-spring-boot-starter-security/src/main/java/com/cf/imes/framework/security/core/util/SecurityFrameworkUtils.java b/cf-framework/cf-spring-boot-starter-security/src/main/java/com/cf/imes/framework/security/core/util/SecurityFrameworkUtils.java index 625cab2e9..48cfd8025 100644 --- a/cf-framework/cf-spring-boot-starter-security/src/main/java/com/cf/imes/framework/security/core/util/SecurityFrameworkUtils.java +++ b/cf-framework/cf-spring-boot-starter-security/src/main/java/com/cf/imes/framework/security/core/util/SecurityFrameworkUtils.java @@ -1,6 +1,8 @@ package com.cf.imes.framework.security.core.util; import cn.hutool.core.util.StrUtil; +import com.cf.imes.framework.common.exception.ServiceException; +import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants; import com.cf.imes.framework.security.core.LoginUser; import com.cf.imes.framework.web.core.util.WebFrameworkUtils; import org.springframework.lang.Nullable; @@ -88,7 +90,10 @@ public class SecurityFrameworkUtils { @Nullable public static Long getLoginUserId() { LoginUser loginUser = getLoginUser(); - return loginUser != null ? loginUser.getId() : null; + if (loginUser == null) { + throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED); + } + return loginUser.getId(); } /** @@ -123,9 +128,12 @@ public class SecurityFrameworkUtils { * 获取当前用户的组织ID * */ - public static Long getUserOrganId(){ - - return SecurityFrameworkUtils.getLoginUser().getOrganId(); + public static Long getUserOrganId() { + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + if (loginUser == null) { + throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED); + } + return loginUser.getOrganId(); } } diff --git a/cf-framework/cf-spring-boot-starter-web/src/main/java/com/cf/imes/framework/web/core/handler/GlobalExceptionHandler.java b/cf-framework/cf-spring-boot-starter-web/src/main/java/com/cf/imes/framework/web/core/handler/GlobalExceptionHandler.java index 5b734fe73..91cb6e04d 100644 --- a/cf-framework/cf-spring-boot-starter-web/src/main/java/com/cf/imes/framework/web/core/handler/GlobalExceptionHandler.java +++ b/cf-framework/cf-spring-boot-starter-web/src/main/java/com/cf/imes/framework/web/core/handler/GlobalExceptionHandler.java @@ -124,7 +124,7 @@ public class GlobalExceptionHandler { log.warn("[methodArgumentNotValidExceptionExceptionHandler]", ex); FieldError fieldError = ex.getBindingResult().getFieldError(); assert fieldError != null; // 断言,避免告警 - return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", fieldError.getDefaultMessage())); + return CommonResult.error(BAD_REQUEST.getCode(), fieldError.getDefaultMessage()); } /** diff --git a/cf-module-prod-executor/cf-module-prod-executor-api/src/main/java/com/cf/imes/module/executor/enums/OrderStatisticsUnit.java b/cf-module-prod-executor/cf-module-prod-executor-api/src/main/java/com/cf/imes/module/executor/enums/OrderStatisticsUnit.java new file mode 100644 index 000000000..f02c40c1d --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-api/src/main/java/com/cf/imes/module/executor/enums/OrderStatisticsUnit.java @@ -0,0 +1,34 @@ +package com.cf.imes.module.executor.enums; + +/** + * 生产单统计维度单位 + * @author Gqr + * @since 2024/8/6 10:04 + */ +public enum OrderStatisticsUnit { + //季度、月、周、日 + QUARTER(0), + MONTH(1), + WEEK(2), + DAY(3); + + OrderStatisticsUnit(Integer value) { + this.value = value; + } + + private Integer value; + + public Integer getValue() { + return value; + } + + // from value + public static OrderStatisticsUnit fromValue(Integer value) { + for (OrderStatisticsUnit unit : OrderStatisticsUnit.values()) { + if (unit.getValue().equals(value)) { + return unit; + } + } + return null; + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java index 8dcfe37f7..7fd8f4963 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java @@ -455,59 +455,6 @@ public class OrderController { return success(orderService.getOrderWarn()); } - // 生产单总数 - @GetMapping("/orderCount") - @Operation(summary = "生产单总数") - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult getOrderCount() { - return success(orderService.orderCount()); - } - - // 今日新增生产单总数 - @GetMapping("/orderCountToday") - @Operation(summary = "今日新增生产单总数") - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult getOrderCountToday() { - return success(orderService.orderCountToday()); - } - - // 今日生产单完成总数 - @GetMapping("/orderCountTodayFinish") - @Operation(summary = "今日生产单完成总数") - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult getOrderCountTodayFinish() { - return success(orderService.orderCountTodayFinish()); - } - - // 生产中生产单总数 - @GetMapping("/orderCountProduce") - @Operation(summary = "生产中生产单总数") - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult getOrderCountProduce() { - return success(orderService.orderCountProduce()); - } - - // 生产中生产平方数 - @GetMapping("/orderSquareProduce") - @Operation(summary = "生产中生产平方数") - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult getOrderSquareProduce() { - return success(orderService.orderSquareProduce()); - } - - // 生产单状态分组统计返回 - @GetMapping("/getOrderStatusCount") - @Operation(summary = "生产单状态分组统计返回") - @Parameters({ - @Parameter(name = "startTime", description = "开始时间", example = "2024-07-15"), - @Parameter(name = "endTime", description = "结束时间", example = "2024-07-16") - }) - @PreAuthorize("@ss.hasPermission('productManager:List')") - public CommonResult> getOrderStatusCount(@RequestParam(value = "startTime") String startTime, - @RequestParam(value = "endTime") String endTime) { - return success(orderService.getOrderStatusCount(startTime + " 00:00:00", endTime + " 23:59:59")); - } - // 小板数量 <集合> @GetMapping("/getPlateCount") @Operation(summary = "小板数量") diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java new file mode 100644 index 000000000..c8c09f68a --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderStatisticsController.java @@ -0,0 +1,79 @@ +package com.cf.imes.module.executor.controller.admin.order; + +import com.cf.imes.framework.common.pojo.CommonResult; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; +import com.cf.imes.module.executor.service.order.OrderStatisticsService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import java.util.Map; + +import static com.cf.imes.framework.common.pojo.CommonResult.success; + +/** + * @author Gqr + * @since 2024/8/5 17:00 + */ +@Tag(name = "管理后台 - 生产单统计管理") +@RestController +@RequestMapping("/executor/order/statistics") +@Validated +public class OrderStatisticsController { + @Resource + private OrderStatisticsService orderStatisticsService; + + @GetMapping("/total") + @Operation(summary = "生产单总数") + public CommonResult getOrderCount(OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.orderCount(reqVO)); + } + + @GetMapping("/today/increase") + @Operation(summary = "今日新增生产单总数") + public CommonResult getOrderCountToday(OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.orderCountToday(reqVO)); + } + + @GetMapping("/today/finish") + @Operation(summary = "今日生产单完成总数") + public CommonResult getOrderCountTodayFinish(OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.orderCountTodayFinish(reqVO)); + } + + @GetMapping("/producing/total") + @Operation(summary = "生产中生产单总数") + public CommonResult getOrderCountProduce(OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.orderCountProduce(reqVO)); + } + + @GetMapping("/producing/square") + @Operation(summary = "生产中生产平方数") + public CommonResult getOrderSquareProduce(OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.orderSquareProduce(reqVO)); + } + + @GetMapping("/orderStatus/group") + @Operation(summary = "生产单状态分组统计") + public CommonResult> getOrderStatusCount(@Valid OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.getOrderStatusCount(reqVO)); + } + + @GetMapping("/orderAndPlanCount/group") + @Operation(summary = "生产单、排单单量分组统计") + public CommonResult> getOrderAndPlanCountGroup(@Valid OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.getOrderAndPlanCountGroup(reqVO)); + } + + @GetMapping("/orderAndPlanArea/group") + @Operation(summary = "生产单、排单平方数分组统计") + public CommonResult> getOrderAndPlanAreaGroup(@Valid OrderStatisticsReqVO reqVO) { + return success(orderStatisticsService.getOrderAndPlanAreaSumGroup(reqVO)); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsAreaRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsAreaRespVO.java new file mode 100644 index 000000000..127e3b727 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsAreaRespVO.java @@ -0,0 +1,57 @@ +package com.cf.imes.module.executor.controller.admin.order.vo.order; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.jetbrains.annotations.NotNull; + +import java.math.BigDecimal; + +@Schema(description = "管理后台 - 生产单平方数统计") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString(callSuper = true) +public class OrderStatisticsAreaRespVO implements Comparable { + @Schema(description = "订单平方数") + private BigDecimal areaSum; + + @Schema(description = "生产单时间") + private String date; + + @Override + public int compareTo(@NotNull OrderStatisticsAreaRespVO other) { + // 解析 orderDate 字符串为年、月、周 + String[] partsThis = date.split("-"); + String[] partsOther = other.date.split("-"); + + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; + } + + // 比较月份 + if (partsThis.length > 1 && partsOther.length > 1) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } + } + + // 比较周数 + if (partsThis.length > 2 && partsOther.length > 2) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } + + // 如果所有部分都相同,则按状态排序 + return this.areaSum.compareTo(other.areaSum); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsReqVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsReqVO.java new file mode 100644 index 000000000..dbf1d18ec --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsReqVO.java @@ -0,0 +1,30 @@ +package com.cf.imes.module.executor.controller.admin.order.vo.order; + +import com.cf.imes.module.executor.validation.order.OrderStatisticsUnitInEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; + +/** + * @author Gqr + * @since 2024/8/5 17:10 + */ +@Schema(description = "管理后台 - 生产单统计 Request VO") +@Data +public class OrderStatisticsReqVO { + @Schema(description = "组织id") + private Long organId; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate[] createTime; + + /** + * 统计维度单位 + */ + @Schema(description = "统计维度单位", example = "0", allowableValues = {"0", "1", "2", "3"}, type = "integer") + @OrderStatisticsUnitInEnum + private Integer unit; +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsStatusRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsStatusRespVO.java new file mode 100644 index 000000000..173951d3c --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatisticsStatusRespVO.java @@ -0,0 +1,54 @@ +package com.cf.imes.module.executor.controller.admin.order.vo.order; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import org.jetbrains.annotations.NotNull; + +@Schema(description = "管理后台 - 生产单状态统计") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString(callSuper = true) +public class OrderStatisticsStatusRespVO implements Comparable { + @Schema(description = "订单状态") + private Integer orderStatus; + + @Schema(description = "订单数量") + private Integer orderCount; + + @Schema(description = "生产单时间") + private String date; + + @Override + public int compareTo(@NotNull OrderStatisticsStatusRespVO other) { + // 解析 orderDate 字符串为年、月、周 + String[] partsThis = date.split("-"); + String[] partsOther = other.date.split("-"); + + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; + } + + // 比较月份 + if (partsThis.length > 1 && partsOther.length > 1) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } + } + + // 比较周数 + if (partsThis.length > 2 && partsOther.length > 2) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } + + // 如果所有部分都相同,则按状态排序 + return this.orderStatus.compareTo(other.orderStatus); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatusRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatusRespVO.java deleted file mode 100644 index 547dc76ca..000000000 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/vo/order/OrderStatusRespVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.cf.imes.module.executor.controller.admin.order.vo.order; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 生产单状态统计") -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@ToString(callSuper = true) -public class OrderStatusRespVO { - @Schema(description = "订单状态") - private Integer orderState; - - @Schema(description = "订单数量") - private Integer orderCount; - - @Schema(description = "生产单时间") - private LocalDateTime orderDate; -} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsAreaRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsAreaRespVO.java new file mode 100644 index 000000000..b3fc1647c --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsAreaRespVO.java @@ -0,0 +1,62 @@ +package com.cf.imes.module.executor.controller.admin.plan.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.jetbrains.annotations.NotNull; + +import java.math.BigDecimal; + +/** + * @author Gqr + * @since 2024/8/7 15:12 + */ + +@Schema(description = "管理后台 - 排单统计RespVO") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString(callSuper = true) +public class OrderPlanStatisticsAreaRespVO implements Comparable { + @Schema(description = "统计时间") + private String date; + + @Schema(description = "面积总和") + private BigDecimal areaSum; + + @Override + public int compareTo(@NotNull OrderPlanStatisticsAreaRespVO other) { + // 解析 date 字符串为年、月、周 + String[] partsThis = date.split("-"); + String[] partsOther = other.date.split("-"); + + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; + } + + // 比较月份 + if (partsThis.length > 1 && partsOther.length > 1) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } + } + + // 比较周数 + if (partsThis.length > 2 && partsOther.length > 2) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } + + // 如果所有部分都相同,则按面积排序 + return this.areaSum.compareTo(other.areaSum); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsCountRespVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsCountRespVO.java new file mode 100644 index 000000000..179a555b0 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/OrderPlanStatisticsCountRespVO.java @@ -0,0 +1,61 @@ +package com.cf.imes.module.executor.controller.admin.plan.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.jetbrains.annotations.NotNull; + +/** + * @author Gqr + * @since 2024/8/7 15:12 + */ + +@Schema(description = "管理后台 - 排单统计RespVO") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString(callSuper = true) +public class OrderPlanStatisticsCountRespVO implements Comparable { + + @Schema(description = "数量") + private Integer count; + + @Schema(description = "统计时间") + private String date; + + @Override + public int compareTo(@NotNull OrderPlanStatisticsCountRespVO other) { + // 解析 date 字符串为年、月、周 + String[] partsThis = date.split("-"); + String[] partsOther = other.date.split("-"); + + // 比较年份 + int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0])); + if (yearComparison != 0) { + return yearComparison; + } + + // 比较月份 + if (partsThis.length > 1 && partsOther.length > 1) { + int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1])); + if (monthComparison != 0) { + return monthComparison; + } + } + + // 比较周数 + if (partsThis.length > 2 && partsOther.length > 2) { + int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2])); + if (weekComparison != 0) { + return weekComparison; + } + } + + // 如果所有部分都相同,则按面积排序 + return this.count.compareTo(other.count); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderMapper.java index 55cb6bac2..886037f39 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderMapper.java @@ -8,19 +8,14 @@ import com.baomidou.mybatisplus.core.toolkit.Constants; import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.cf.imes.framework.mybatis.core.query.QueryWrapperX; -import com.cf.imes.framework.organ.core.aop.OrganIgnore; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderOverdueRespVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderPageReqVO; -import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatusRespVO; import com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds; import com.cf.imes.module.executor.controller.admin.plan.vo.OrderRespVOCopy; import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; -import com.cf.imes.module.executor.enums.OrderStatusEnum; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -139,70 +134,9 @@ public interface OrderMapper extends BaseMapperX { List selectOrderIds(@Param(Constants.WRAPPER) Wrapper wrapper); -// 生产单状态统计 - List selectOrderStatusCount(@Param("organId")Long organId, @Param("startTime")String startTime, @Param("endTime")String endTime); - // 生产单预警统计 List selectOrderNear(@Param("today") LocalDateTime today, @Param("orderDate") LocalDateTime orderDate, @Param("organId") Long organId); // 生产单逾期统计 List selectOrderOverdue(@Param("today") LocalDateTime today, @Param("organId") Long organId); - -// 生产单数量统计 - default Integer selectOrderCount(Long organId){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getOrganId, organId) - .eq(OrderDO::getDeleted, 0))); - } - @OrganIgnore - default Integer selectOrderCount(){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getDeleted, 0))); - } - -// 今日新增生产单总数统计 - default Integer selectOrderCountToday(Long organId){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getOrganId, organId) - .eq(OrderDO::getDeleted, 0) - .between(OrderDO::getCreateTime, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)))); - } - @OrganIgnore - default Integer selectOrderCountToday(){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getDeleted, 0) - .between(OrderDO::getCreateTime, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)))); - } - -// 今日新增生产单总数统计 - default Integer selectOrderCountTodayFinish(Long organId){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getOrganId, organId) - .eq(OrderDO::getDeleted, 0) - .between(OrderDO::getFinishTime, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)))); - } - @OrganIgnore - default Integer selectOrderCountTodayFinish(){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getDeleted, 0) - .between(OrderDO::getFinishTime, LocalDateTime.now().withHour(0).withMinute(0).withSecond(0), LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)))); - } - -// 今日新增生产单总数统计 - default Integer selectOrderCountProduce(Long organId){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getOrganId, organId) - .eq(OrderDO::getDeleted, 0) - .eq(OrderDO::getStatus, OrderStatusEnum.IN_PRODUCTION.getStatus()))); - } - @OrganIgnore - default Integer selectOrderCountProduce(){ - return Math.toIntExact(selectCount(new LambdaQueryWrapper() - .eq(OrderDO::getDeleted, 0) - .eq(OrderDO::getStatus, OrderStatusEnum.IN_PRODUCTION.getStatus()))); - } - -// 生产中生产平方数 - @OrganIgnore - Integer selectOrderSquareProduce(@Param("organId") Long organId); } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderStatisticsMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderStatisticsMapper.java new file mode 100644 index 000000000..b17eb8a17 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/order/OrderStatisticsMapper.java @@ -0,0 +1,96 @@ +package com.cf.imes.module.executor.dal.mysql.order; + +import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; +import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO; +import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; +import com.cf.imes.module.executor.enums.OrderStatusEnum; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + +/** + * @author Gqr + * @since 2024/8/7 9:35 + */ +@Mapper +public interface OrderStatisticsMapper extends BaseMapperX { + + /** + * 生产单数量统计 + */ + default Integer selectOrderCount(Long organId) { + return Math.toIntExact(selectCount(new LambdaQueryWrapperX() + .eqIfPresent(OrderDO::getOrganId, organId) + .eq(OrderDO::getDeleted, 0))); + } + + /** + * 今日新增生产单总数统计 + * + */ + default Integer selectOrderCountToday(Long organId) { + return Math.toIntExact(selectCount(new LambdaQueryWrapperX() + .eqIfPresent(OrderDO::getOrganId, organId) + .eq(OrderDO::getOrderDate, LocalDate.now()))); + + } + + /** + * 今日完成生产单总数统计 + * + */ + default Integer selectOrderCountTodayFinish(Long organId) { + return Math.toIntExact(selectCount(new LambdaQueryWrapperX() + .eqIfPresent(OrderDO::getOrganId, organId) + .between(OrderDO::getFinishTime, LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX)))); + } + + /** + * 生产中生产单总数 + * + */ + default Integer selectOrderCountProduce(Long organId) { + return Math.toIntExact(selectCount(new LambdaQueryWrapperX() + .eqIfPresent(OrderDO::getOrganId, organId) + .eq(OrderDO::getStatus, OrderStatusEnum.IN_PRODUCTION.getStatus()))); + } + + /** + * 生产中生产平方数 + * + * @param organId + * @return + */ + Integer selectOrderSquareProduce(@Param("organId") Long organId); + + /** + * 生产单状态按时间分组统计数量 + * + * @param reqVO + * @return + */ + List selectOrderStatusCountGroupBy(@Param("req") OrderStatisticsReqVO reqVO); + + /** + * 生产单按时间分组统计数量 + * + * @param reqVO + * @return + */ + List selectOrderCountGroupByOrderDate(@Param("req") OrderStatisticsReqVO reqVO); + + /** + * 生产单按时间分组统计面积 + * + * @param reqVO + * @return + */ + List selectOrderAreaGroupByOrderDate(@Param("req") OrderStatisticsReqVO reqVO); +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java index 4f1fa4c8e..33ef05b45 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java @@ -2,15 +2,16 @@ package com.cf.imes.module.executor.dal.mysql.plan; import java.util.*; -import cn.hutool.core.util.StrUtil; import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO; import com.cf.imes.module.executor.dal.dataobject.plan.PlanDO; import com.cf.imes.module.executor.dal.dataobject.planitem.PlanItemDO; +import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Mapper; import com.cf.imes.module.executor.controller.admin.plan.vo.*; import org.apache.ibatis.annotations.Param; @@ -26,7 +27,7 @@ import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.ge public interface PlanMapper extends BaseMapperX { default PageResult selectPage(PlanPageReqVO reqVO) { - if(StrUtil.isNotBlank(reqVO.getCustomer())) { + if(StringUtils.isNotBlank(reqVO.getCustomer())) { return selectJoinPage(reqVO, PlanDO.class, new MPJLambdaWrapperX() .eq(PlanDO::getDeleted,false) .eq(PlanDO::getOrganId,getUserOrganId()) @@ -85,10 +86,18 @@ public interface PlanMapper extends BaseMapperX { .eq(PlanDO::getMachineId,machineId)); } -// -// default PlanDO selectByOrderId(Long orderId) { -// return selectOne(new MPJLambdaWrapperX() -// .like(PlanDO::getOrderNos, orderId)); -// -// } + /** + * 排单按时间分组统计数量 + * + * @param reqVO + * @return + */ + List selectPlanCountGroupByCreateTime(@Param("req") OrderStatisticsReqVO reqVO); + + /** + * 排单按时间分组统计面积 + * @param reqVO + * @return + */ + List selectPlanAreaGroupByCreateTime(@Param("req") OrderStatisticsReqVO reqVO); } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java index bc1f41dac..a71bfb299 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderService.java @@ -173,41 +173,12 @@ public interface OrderService { */ List getApiOrderList(JSONObject orderList); - /** - * 生产单状态统计 - */ - List getOrderStatusCount(String startTime, String endTime); /** * 生产单超期告警分析统计 */ Map> getOrderWarn(); - /** - * 生产单总数统计 - */ - Integer orderCount(); - - /** - * 今日新增生产单总数统计 - */ - Integer orderCountToday(); - - /** - * 今日生产单完成总数 - */ - Integer orderCountTodayFinish(); - - /** - * 今日生产单完成总数 - */ - Integer orderCountProduce(); - - /** - * 今日生产单完成总数 - */ - Integer orderSquareProduce(); - /** * 小板数量 */ diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java index 35b10ccbb..e56b0c7ac 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java @@ -1,7 +1,6 @@ package com.cf.imes.module.executor.service.order; import cn.smallbun.screw.core.util.CollectionUtils; -import co.elastic.clients.elasticsearch.nodes.Ingest; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -71,7 +70,6 @@ import java.nio.file.Paths; import java.time.*; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -296,61 +294,6 @@ public class OrderServiceImpl implements OrderService { return JsonUtils.zipString(orderBodyToString); } - @Override - public Integer orderCount() { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - if (loginUser.getIsSupAdmin()){ - return orderMapper.selectOrderCount(); - } - return orderMapper.selectOrderCount(getUserOrganId()); - } - - @Override - public Integer orderCountToday() { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - if (loginUser.getIsSupAdmin()){ - return orderMapper.selectOrderCountToday(); - } - return orderMapper.selectOrderCountToday(getUserOrganId()); - } - - @Override - public Integer orderCountTodayFinish() { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - if (loginUser.getIsSupAdmin()){ - return orderMapper.selectOrderCountTodayFinish(); - } - return orderMapper.selectOrderCountTodayFinish(getUserOrganId()); - } - - @Override - public Integer orderCountProduce() { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - if (loginUser.getIsSupAdmin()){ - return orderMapper.selectOrderCountProduce(); - } - return orderMapper.selectOrderCountProduce(getUserOrganId()); - } - - @Override - public Integer orderSquareProduce() { -// 角色判断 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); -// 数据查询 - if (loginUser.getIsSupAdmin()){ - return orderMapper.selectOrderSquareProduce(null); - } - return orderMapper.selectOrderSquareProduce(getUserOrganId()); - } - @Override public PageResult plateCount(String startTime, String endTime, Integer pageNo, Integer pageSize) { // 角色判断 @@ -677,13 +620,6 @@ public class OrderServiceImpl implements OrderService { return apiOrderRespVOS; } - @Override - public List getOrderStatusCount(String startTime, String endTime) { - List orderStatusRespVOS = orderMapper.selectOrderStatusCount(OrganContextHolder.getOrganId(), startTime, endTime); - orderStatusRespVOS.removeIf(obj -> obj.getOrderState() == OrderStatusEnum.EMPTY.getStatus()); - return orderStatusRespVOS; - } - @Override public Map> getOrderWarn() { Map> map = new HashMap<>(); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java new file mode 100644 index 000000000..a125192da --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsService.java @@ -0,0 +1,59 @@ +package com.cf.imes.module.executor.service.order; + +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; + +import java.util.Map; + +/** + * 生产单统计 order_{N} Service 接口 + * + * @author Gqr + * @since 2024/8/5 16:57 + */ +public interface OrderStatisticsService { + /** + * 生产单总数统计 + */ + Integer orderCount(OrderStatisticsReqVO reqVO); + + /** + * 今日新增生产单总数统计 + */ + Integer orderCountToday(OrderStatisticsReqVO reqVO); + + /** + * 今日生产单完成总数 + */ + Integer orderCountTodayFinish(OrderStatisticsReqVO reqVO); + + /** + * 今日生产单完成总数 + */ + Integer orderCountProduce(OrderStatisticsReqVO reqVO); + + /** + * 今日生产单完成总数 + */ + Integer orderSquareProduce(OrderStatisticsReqVO reqVO); + + /** + * 生产单状态分组统计 + */ + Map getOrderStatusCount(OrderStatisticsReqVO reqVO); + + /** + * 生产单、排单单量分组统计 + * + * @param reqVO + * @return + */ + Map getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO); + + /** + * 生产单、排单平方数统计 + * + * @param reqVO + * @return + */ + Map getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO); +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java new file mode 100644 index 000000000..235c6c028 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderStatisticsServiceImpl.java @@ -0,0 +1,318 @@ +package com.cf.imes.module.executor.service.order; + +import cn.hutool.core.util.ObjectUtil; +import com.cf.imes.framework.common.enums.OrderStatusEnum; +import com.cf.imes.framework.organ.core.aop.OrganIgnore; +import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO; +import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO; +import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsAreaRespVO; +import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO; +import com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper; +import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper; +import com.cf.imes.module.executor.enums.OrderStatisticsUnit; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAdjusters; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @author Gqr + * @since 2024/8/5 16:58 + */ +@Service +@Validated +public class OrderStatisticsServiceImpl implements OrderStatisticsService { + @Resource + private OrderStatisticsMapper orderStatisticsMapper; + + @Resource + private PlanMapper planMapper; + + @Override + @OrganIgnore + public Integer orderCount(OrderStatisticsReqVO reqVO) { + return orderStatisticsMapper.selectOrderCount(getOrganIdParam(reqVO)); + } + + @Override + @OrganIgnore + public Integer orderCountToday(OrderStatisticsReqVO reqVO) { + return orderStatisticsMapper.selectOrderCountToday(getOrganIdParam(reqVO)); + } + + @Override + @OrganIgnore + public Integer orderCountTodayFinish(OrderStatisticsReqVO reqVO) { + return orderStatisticsMapper.selectOrderCountTodayFinish(getOrganIdParam(reqVO)); + } + + @Override + @OrganIgnore + public Integer orderCountProduce(OrderStatisticsReqVO reqVO) { + return orderStatisticsMapper.selectOrderCountProduce(getOrganIdParam(reqVO)); + } + + @Override + @OrganIgnore + public Integer orderSquareProduce(OrderStatisticsReqVO reqVO) { + return orderStatisticsMapper.selectOrderSquareProduce(getOrganIdParam(reqVO)); + } + + @Override + @OrganIgnore + public Map getOrderStatusCount(OrderStatisticsReqVO reqVO) { + Map resultMap = new HashMap<>(); + + // 获取机构id + reqVO.setOrganId(getOrganIdParam(reqVO)); + + // 计算时间跨度 + getTimeSpan(reqVO); + + // 查询订单状态统计数据 + List orderStatusRespVOS = orderStatisticsMapper.selectOrderStatusCountGroupBy(reqVO); + + // 基于相同的orderDate分组 + Map> orderDateMap = orderStatusRespVOS.stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + + // 所有的日期集合 + List dateList = generateDateRange(reqVO); + resultMap.put("dateList", dateList); + + // 遍历订单状态所有枚举值 + List> series = new ArrayList<>(); + for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) { + Map seriesItem = new HashMap<>(); + int[] sumArr = new int[dateList.size()]; + + // 遍历完整的日期范围 + int index = 0; + for (String dateStr : dateList) { + // 查找匹配的订单状态 + List listForDate = orderDateMap.get(dateStr); + int count = 0; + if (listForDate != null) { + count = listForDate.stream() + .filter(respVO -> Objects.equals(orderStatusEnum.getStatus(), respVO.getOrderStatus())) + .mapToInt(OrderStatisticsStatusRespVO::getOrderCount) + .sum(); + } + + sumArr[index++] = count; + } + + seriesItem.put("data", sumArr); + seriesItem.put("name", orderStatusEnum.getDescription()); + series.add(seriesItem); + } + + resultMap.put("series", series); + + return resultMap; + } + + @Override + @OrganIgnore + public Map getOrderAndPlanCountGroup(OrderStatisticsReqVO reqVO) { + Map resultMap = new LinkedHashMap<>(); + + // 获取机构id + reqVO.setOrganId(getOrganIdParam(reqVO)); + + // 计算时间跨度 + getTimeSpan(reqVO); + + // 所有的日期集合 + List dateList = generateDateRange(reqVO); + + Map> orderRespMap = orderStatisticsMapper.selectOrderCountGroupByOrderDate(reqVO).stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrderStatisticsStatusRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + Map> planRespMap = planMapper.selectPlanCountGroupByCreateTime(reqVO).stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrderPlanStatisticsCountRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + + // 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组 + for (int i = 0; i < dateList.size(); i++) { + String dateStr = dateList.get(i); + int[] countArr = new int[2]; + // 存入生产单数量 + Integer orderCount = Optional.ofNullable(orderRespMap.get(dateStr)) + .map(list -> list.stream().findFirst().orElse(new OrderStatisticsStatusRespVO())) + .map(OrderStatisticsStatusRespVO::getOrderCount) + .orElse(0); + countArr[0] = orderCount; + + // 存入排单数量 + Integer planCount = Optional.ofNullable(planRespMap.get(dateStr)) + .map(list -> list.stream().findFirst().orElse(new OrderPlanStatisticsCountRespVO())) + .map(OrderPlanStatisticsCountRespVO::getCount) + .orElse(0); + countArr[1] = planCount; + + resultMap.put(dateStr, countArr); + } + + return resultMap; + } + + @Override + @OrganIgnore + public Map getOrderAndPlanAreaSumGroup(OrderStatisticsReqVO reqVO) { + Map resultMap = new LinkedHashMap<>(); + + // 获取机构id + reqVO.setOrganId(getOrganIdParam(reqVO)); + + // 计算时间跨度 + getTimeSpan(reqVO); + + // 所有的日期集合 + List dateList = generateDateRange(reqVO); + + Map> orderRespMap = orderStatisticsMapper.selectOrderAreaGroupByOrderDate(reqVO).stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrderStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + Map> planRespMap = planMapper.selectPlanAreaGroupByCreateTime(reqVO).stream() + .sorted(Comparator.naturalOrder()) + .collect(Collectors.groupingBy(OrderPlanStatisticsAreaRespVO::getDate, LinkedHashMap::new, Collectors.toList())); + + // 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组 + for (String dateStr : dateList) { + BigDecimal[] areaArr = new BigDecimal[2]; + + // 存生产单面积 + List orderCountRespVOS = orderRespMap.get(dateStr); + areaArr[0] = orderCountRespVOS != null && !orderCountRespVOS.isEmpty() ? orderCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO; + + // 存排单面积 + List planCountRespVOS = planRespMap.get(dateStr); + areaArr[1] = planCountRespVOS != null && !planCountRespVOS.isEmpty() ? planCountRespVOS.get(0).getAreaSum() : BigDecimal.ZERO; + + resultMap.put(dateStr, areaArr); + } + + return resultMap; + } + + /** + * 获取统计的时间跨度 + * 计算起止时间:前端不传入时间就根据维度单位从当前日期计算 + * + * @param reqVO + */ + private void getTimeSpan(OrderStatisticsReqVO 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])) { + endTime = now; + switch (OrderStatisticsUnit.fromValue(reqVO.getUnit())) { + case QUARTER: + // 从now往前的2年 + startTime = now.minusYears(2); + break; + case MONTH: + // 从now往前的12个月 + startTime = now.minusMonths(12); + break; + case WEEK: + // 从now往前的12周 + startTime = now.minusWeeks(12); + break; + case DAY: + // 从now往前的15天 + startTime = now.minusDays(15); + break; + default: + break; + } + // 声明一个LocalDateTime的数组,把startTime和endTime放进去 + reqVO.setCreateTime(new LocalDate[]{startTime, endTime}); + } + } + + /** + * 获取日期范围内的所有格式字符串 + * + * @param reqVO + * @return + */ + private List generateDateRange(OrderStatisticsReqVO reqVO) { + Integer unit = reqVO.getUnit(); + // 计算时间跨度 + getTimeSpan(reqVO); + // 计算后的开始和结束时间 + LocalDate startDate = ObjectUtil.clone(reqVO.getCreateTime()[0]); + LocalDate endDate = ObjectUtil.clone(reqVO.getCreateTime()[1]); + + List dates = new ArrayList<>(); + while (!startDate.isAfter(endDate)) { + String dateStr; + switch (OrderStatisticsUnit.fromValue(unit)) { + case QUARTER: + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-Q")); + // 加一季度(3个月) + startDate = startDate.plusMonths(3); + break; + case MONTH: + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M")); + // 加一月 + startDate = startDate.plusMonths(1); + break; + case WEEK: + // 使用自定义格式表示月份 + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M")); + // 计算从月份第一天到当前日期经过了多少周 + LocalDate monthStart = startDate.with(TemporalAdjusters.firstDayOfMonth()); + long weeksInMonth = ChronoUnit.WEEKS.between(monthStart, startDate) + 1; + dateStr = dateStr + "-" + weeksInMonth; + // 加一周 + startDate = startDate.plusWeeks(1); + break; + case DAY: + dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M-d")); + // 加一天 + startDate = startDate.plusDays(1); + break; + default: + throw new IllegalArgumentException("Unsupported unit: " + unit); + } + dates.add(dateStr); + } + return dates; + } + + /** + * 前端传组织否则查当前用户所在的组织 + * + * @param reqVO + * @return + */ + private Long getOrganIdParam(OrderStatisticsReqVO reqVO) { + if (reqVO != null && reqVO.getOrganId() != null) { + return reqVO.getOrganId(); + } else { + return SecurityFrameworkUtils.getUserOrganId(); + } + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnum.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnum.java new file mode 100644 index 000000000..b151c2a1a --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnum.java @@ -0,0 +1,36 @@ +package com.cf.imes.module.executor.validation.order; + +import javax.validation.Constraint; +import javax.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 = {OrderStatisticsUnitInEnumValidator.class} +) +public @interface OrderStatisticsUnitInEnum { + String message() default "生产单统计维度单位[unit]错误,请检查"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnumValidator.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnumValidator.java new file mode 100644 index 000000000..6fe1288dc --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/validation/order/OrderStatisticsUnitInEnumValidator.java @@ -0,0 +1,36 @@ +package com.cf.imes.module.executor.validation.order; + +import cn.hutool.core.util.ObjectUtil; +import com.cf.imes.module.executor.enums.OrderStatisticsUnit; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +/** + * 生产单统计维度单位入参校验器 + * + * @author Gqr + * @since 2024/7/17 9:33 + */ +public class OrderStatisticsUnitInEnumValidator implements ConstraintValidator { + + @Override + public void initialize(OrderStatisticsUnitInEnum constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + if (ObjectUtil.isNull(value)) { + return true; + } + OrderStatisticsUnit unit = OrderStatisticsUnit.fromValue(value); + if (ObjectUtil.isNotNull(unit)) { + return true; + } else { + return false; + } + } + +} + diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderMapper.xml index 873649a30..cc8db0aec 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderMapper.xml @@ -79,18 +79,6 @@ - - - - - - \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderStatisticsMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderStatisticsMapper.xml new file mode 100644 index 000000000..3a4df3814 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/order/OrderStatisticsMapper.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml index a8131c5be..1b442cca4 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml @@ -123,4 +123,52 @@ + + + \ No newline at end of file diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/user/UserController.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/user/UserController.java index 7113f5c2b..9c2c98474 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/user/UserController.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/controller/admin/user/UserController.java @@ -115,7 +115,6 @@ public class UserController { @GetMapping("/page") @Operation(summary = "获得用户分页列表") -// @PreAuthorize("@ss.hasPermission('system:user:list')") @PreAuthorize("@ss.hasAnyPermissions('system:user:list','base:user:query')") public CommonResult> getUserPage(@Valid UserPageReqVO pageReqVO) { // 获得用户分页列表 @@ -123,6 +122,11 @@ public class UserController { if (CollUtil.isEmpty(pageResult.getList())) { return success(new PageResult<>(pageResult.getTotal())); } + // 用户列表不展示当前登录人 + boolean removeCurrentUser = pageResult.getList().removeIf(user -> Objects.equals(user.getId(), SecurityFrameworkUtils.getLoginUserId())); + if (removeCurrentUser) { + pageResult.setTotal(pageResult.getTotal() - 1); + } // 拼接数据 Map deptMap = deptService.getDeptMap( convertList(pageResult.getList(), AdminUserDO::getDeptId)); diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/auth/AdminAuthServiceImpl.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/auth/AdminAuthServiceImpl.java index fbc9d39c4..328c51fc5 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/auth/AdminAuthServiceImpl.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/auth/AdminAuthServiceImpl.java @@ -1,15 +1,12 @@ package com.cf.imes.module.system.service.auth; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import com.cf.imes.framework.common.enums.CommonStatusEnum; import com.cf.imes.framework.common.enums.UserTypeEnum; -import com.cf.imes.framework.common.exception.ServerException; import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil; import com.cf.imes.framework.common.util.monitor.TracerUtils; import com.cf.imes.framework.common.util.servlet.ServletUtils; import com.cf.imes.framework.common.util.validation.ValidationUtils; -import com.cf.imes.framework.organ.core.context.OrganContextHolder; import com.cf.imes.module.system.api.logger.dto.LoginLogCreateReqDTO; import com.cf.imes.module.system.api.sms.SmsCodeApi; import com.cf.imes.module.system.api.social.dto.SocialUserBindReqDTO; @@ -39,6 +36,7 @@ import com.xingyuv.captcha.model.common.ResponseModel; import com.xingyuv.captcha.model.vo.CaptchaVO; import com.xingyuv.captcha.service.CaptchaService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -124,9 +122,12 @@ public class AdminAuthServiceImpl implements AdminAuthService { reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())); } Long organId = user.getOrganId(); + // 校验机构有效性 + organService.validOrgan(organId); OrganizationDO organ = organService.getOrgan(organId); String dataSourceCode = organ.getDataSourceCode(); - if(StrUtil.isBlank(dataSourceCode)) { + // 校验机构数据源 + if (StringUtils.isBlank(dataSourceCode)) { throw exception(ORGAN_DATA_CODE_NOT_EXISTS); } // 创建 Token 令牌,记录登录日志 @@ -156,7 +157,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { Long organId = user.getOrganId(); OrganizationDO organ = organService.getOrgan(organId); String dataSourceCode = organ.getDataSourceCode(); - if(StrUtil.isBlank(dataSourceCode)) { + if(StringUtils.isBlank(dataSourceCode)) { throw exception(ORGAN_DATA_CODE_NOT_EXISTS); } @@ -201,7 +202,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { Long organId = user.getOrganId(); OrganizationDO organ = organService.getOrgan(organId); String dataSourceCode = organ.getDataSourceCode(); - if(StrUtil.isBlank(dataSourceCode)) { + if(StringUtils.isBlank(dataSourceCode)) { throw exception(ORGAN_DATA_CODE_NOT_EXISTS); } @@ -231,11 +232,6 @@ public class AdminAuthServiceImpl implements AdminAuthService { private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType, Boolean large, String dataCode, Long organId, String nickname) { // 插入登陆日志 createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS); - /*Long organId = OrganContextHolder.getOrganId(); - OrganizationDO organ = organService.getOrgan(organId); - if(Objects.isNull(organ)) { - throw new ServerException(10023,"组织不存在"); - }*/ // 创建访问令牌 OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(), OAuth2ClientConstants.CLIENT_ID_DEFAULT, null, large, null, null, dataCode, organId, nickname); diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/oauth2/OAuth2TokenServiceImpl.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/oauth2/OAuth2TokenServiceImpl.java index eadc6b03f..6cd7e85b7 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/oauth2/OAuth2TokenServiceImpl.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/oauth2/OAuth2TokenServiceImpl.java @@ -15,6 +15,7 @@ import com.cf.imes.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO; import com.cf.imes.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper; import com.cf.imes.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper; import com.cf.imes.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO; +import com.cf.imes.module.system.service.organ.OrganService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,6 +37,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { @Resource private OAuth2AccessTokenMapper oauth2AccessTokenMapper; + @Resource private OAuth2RefreshTokenMapper oauth2RefreshTokenMapper; @@ -48,6 +50,9 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { @Resource private SecurityFrameworkService securityFrameworkService; + @Resource + private OrganService organService; + @Override @Transactional public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List scopes,Boolean large, Integer dbNo, Integer tableNo, String dataCode, Long organId, String nickname) { @@ -68,7 +73,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { } // 校验 Client 匹配 - OAuth2ClientDO clientDO = oauth2ClientService.validOAuthClientFromCache(clientId); if (ObjectUtil.notEqual(clientId, refreshTokenDO.getClientId())) { throw exception0(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), "刷新令牌的客户端编号不正确"); } @@ -86,31 +90,19 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { throw exception0(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), "刷新令牌已过期"); } -// // 创建访问令牌 -// return createOAuth2AccessToken(refreshTokenDO, clientDO); return null; } @Override public OAuth2AccessTokenDO getAccessToken(String accessToken) { -// // 优先从 Redis 中获取 -// OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenRedisDAO.get(accessToken); -// if (accessTokenDO != null) { -// return accessTokenDO; -// } -// -// // 获取不到,从 MySQL 中获取 -// accessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessToken); -// // 如果在 MySQL 存在,则往 Redis 中写入 -// if (accessTokenDO != null && !DateUtils.isExpired(accessTokenDO.getExpiresTime())) { -// oauth2AccessTokenRedisDAO.set(accessTokenDO); -// } // 因数据库不在存入缓存数据,所以直接从缓存中获取 // 数据库移除令牌存入,所以直接从缓存中获取 OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenRedisDAO.get(accessToken); if(accessTokenDO != null){ + // 校验组织的有效性 + organService.validOrgan(accessTokenDO.getOrganId()); // 有令牌的校验,代表有接口访问,延长令牌的过期时间(30分钟) oauth2AccessTokenRedisDAO.expire(accessToken, 1800, TimeUnit.SECONDS); } @@ -123,9 +115,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { if (accessTokenDO == null) { throw exception0(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), "访问令牌不存在"); } -// if (DateUtils.isExpired(accessTokenDO.getExpiresTime())) { -// throw exception0(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), "访问令牌已过期"); - return accessTokenDO; } @@ -162,7 +151,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { } boolean b = securityFrameworkService.hasAnyRoles(userId,"super_admin"); refreshToken.setIsSupAdmin(b); -// oauth2RefreshTokenMapper.insert(refreshToken); return refreshToken; } @@ -177,8 +165,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { .setDataCode(refreshTokenDO.getDataCode()).setOrganId(refreshTokenDO.getOrganId()) .setNickname(refreshTokenDO.getNickname()).setIsSupAdmin(refreshTokenDO.getIsSupAdmin()) ; - //accessTokenDO.setOrganId(OrganContextHolder.getOrganId()); // 手动设置组织编号,避免缓存到 Redis 的时候,无对应的组织编号 -// oauth2AccessTokenMapper.insert(accessTokenDO); // 记录到 Redis 中 oauth2AccessTokenRedisDAO.set(accessTokenDO); return accessTokenDO; diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/organ/OrganServiceImpl.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/organ/OrganServiceImpl.java index 0857310fc..e2c08f560 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/organ/OrganServiceImpl.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/organ/OrganServiceImpl.java @@ -128,7 +128,6 @@ public class OrganServiceImpl implements OrganService { pinyinFull = pinyinFull.replaceAll(" ", ""); } tenant.setPinyinFull(pinyinFull); - tenant.setCode(StrUtil.isBlank(createReqVO.getCode())? pinyinFull : createReqVO.getCode()); tenant.setLarge(createReqVO.getLarge() == null ? Boolean.FALSE : createReqVO.getLarge()); tenant.setPinyinInitial(PinYinUtils.convertFirstChar(tenant.getName())); //todo 未来还需要判断是否大客户,大客户有自己dataCode