mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
接口对接修改,超管分时间统计生产单
This commit is contained in:
+81
-4
@@ -1,16 +1,24 @@
|
||||
package com.cf.imes.module.system.api.organ;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.OrderStatisticsUnit;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsReqDTO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganRespVO;
|
||||
import com.cf.imes.module.system.service.organ.OrganService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.generateDateRangeAxis;
|
||||
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.getDateList;
|
||||
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
@@ -36,8 +44,77 @@ public class OrganApiImpl implements OrganApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Map<String, Object>> getOrgSeparate(LocalDate[] createTime, Integer unit) {
|
||||
return null;
|
||||
public CommonResult<Map<String, Object>> getOrgSeparate(OrgStatisticsReqDTO reqVO) {
|
||||
setOrgStatisticsReqVO(reqVO);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
|
||||
// 所有的日期集合
|
||||
List<String> dateList = getDateList(reqVO.getCreateTime(),reqVO.getUnit());
|
||||
|
||||
|
||||
// 生产单有效数量
|
||||
Map<String, List<OrgStatisticsIsLapseRespDTO>> orderLapseRespMap = organService.orgCountAddByOrderDateAdd(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrgStatisticsIsLapseRespDTO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
// 组织无效数量
|
||||
Map<String, List<OrgStatisticsIsLapseRespDTO>> orderNotLapseRespMap = organService.orgCountLapseByOrderDate(reqVO).stream()
|
||||
.sorted(Comparator.naturalOrder())
|
||||
.collect(Collectors.groupingBy(OrgStatisticsIsLapseRespDTO::getDate, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
// 遍历时间跨度列表,匹配数量存入数组,没有补0存入数组
|
||||
for (String dateStr : dateList) {
|
||||
int[] countArr = new int[2];
|
||||
// 组织有效数量
|
||||
Integer orderNotLapseCount = Optional.ofNullable(orderNotLapseRespMap.get(dateStr))
|
||||
.map(list -> list.stream().findFirst().orElse(new OrgStatisticsIsLapseRespDTO()))
|
||||
.map(OrgStatisticsIsLapseRespDTO::getOrgCount)
|
||||
.orElse(0);
|
||||
countArr[0] = orderNotLapseCount;
|
||||
|
||||
|
||||
// 组织无效数量
|
||||
Integer orderLapseCount = Optional.ofNullable(orderLapseRespMap.get(dateStr))
|
||||
.map(list -> list.stream().findFirst().orElse(new OrgStatisticsIsLapseRespDTO()))
|
||||
.map(OrgStatisticsIsLapseRespDTO::getOrgCount)
|
||||
.orElse(0);
|
||||
countArr[1] = orderLapseCount;
|
||||
|
||||
resultMap.put(generateDateRangeAxis(dateStr, reqVO.getUnit()), countArr);
|
||||
}
|
||||
|
||||
return success(resultMap);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Map<String, List<Object>>> getWarnToOrg() {
|
||||
Map<String, List<Object>> map = new HashMap<>();
|
||||
|
||||
LocalDateTime today = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
||||
LocalDateTime afterDay = today.plusDays(15).withHour(23).withMinute(59).withSecond(59);
|
||||
LocalDateTime alertDay = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
|
||||
|
||||
// 即将过期组织
|
||||
List<OrganRespVO> expireOrg = organService.orgCountExpire(today, afterDay);
|
||||
map.put("expireOrg", Collections.singletonList(expireOrg));
|
||||
|
||||
// 已过期组织
|
||||
List<OrganRespVO> lapseOrg = organService.orgCountExpired(alertDay);
|
||||
map.put("expiredOrg", Collections.singletonList(lapseOrg));
|
||||
|
||||
return success(map);
|
||||
}
|
||||
|
||||
private void setOrgStatisticsReqVO(OrgStatisticsReqDTO reqVO){
|
||||
if (ObjectUtil.isNull(reqVO.getUnit())){
|
||||
reqVO.setUnit(OrderStatisticsUnit.DAY.getValue());
|
||||
}
|
||||
if (ObjectUtil.isNull(reqVO.getCreateTime())){
|
||||
reqVO.setCreateTime(new LocalDate[2]);
|
||||
}
|
||||
LocalDate[] time = reqVO.getCreateTime();
|
||||
reqVO.setCreateTime(new LocalDate[]{time[0], time[1]});
|
||||
}
|
||||
}
|
||||
|
||||
+22
-1
@@ -5,6 +5,8 @@ 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.module.executor.enums.OrderDeletedEnum;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsReqDTO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganPageReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -61,7 +63,7 @@ public interface OrganMapper extends BaseMapperX<OrganizationDO> {
|
||||
|
||||
default Integer selectOrgCount() {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OrganizationDO>()
|
||||
.eq(OrganizationDO::getUpdateTime, OrderDeletedEnum.NOT_DELETED.getStatus())));
|
||||
.eq(OrganizationDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())));
|
||||
}
|
||||
|
||||
default Integer selectOrgCountAdd() {
|
||||
@@ -91,6 +93,25 @@ public interface OrganMapper extends BaseMapperX<OrganizationDO> {
|
||||
List<OrganizationDO> selectTestSQL(@Param("sql") String sql);
|
||||
|
||||
|
||||
/**
|
||||
* 组织按时间统计新增数量
|
||||
*/
|
||||
List<OrgStatisticsIsLapseRespDTO> selectOrgCountAddByOrderDate(@Param("req") OrgStatisticsReqDTO reqVO);
|
||||
|
||||
/**
|
||||
* 组织按时间分组统计注销数量
|
||||
*/
|
||||
List<OrgStatisticsIsLapseRespDTO> selectOrgCountLapseByOrderDate(@Param("req") OrgStatisticsReqDTO reqVO);
|
||||
|
||||
default List<OrganizationDO> selectOrgCountExpire(LocalDateTime today, LocalDateTime afterDay){
|
||||
return selectList(new LambdaQueryWrapperX<OrganizationDO>()
|
||||
.eq(OrganizationDO::getDeleted,false)
|
||||
.between(OrganizationDO::getExpireTime,today,afterDay));
|
||||
}
|
||||
|
||||
default List<OrganizationDO> selectOrgCountExpired(LocalDateTime alertDay){
|
||||
return selectList(new LambdaQueryWrapperX<OrganizationDO>()
|
||||
.eq(OrganizationDO::getDeleted,false)
|
||||
.lt(OrganizationDO::getExpireTime,alertDay));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -129,12 +129,16 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
LocalDateTime.of(LocalDate.now(), LocalTime.of(23, 59, 59)))));
|
||||
}
|
||||
|
||||
Integer selectUserSilentCount(@Param("dateTime")LocalDateTime dateTime);
|
||||
default Integer selectUserCountSilent(LocalDateTime dateTime) {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.eq(AdminUserDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())
|
||||
.lt(AdminUserDO::getLoginDate, dateTime)));
|
||||
}
|
||||
|
||||
default Integer selectUserActCountTime(LocalDateTime startTime, LocalDateTime endTIme) {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.eq(AdminUserDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())
|
||||
.eq(AdminUserDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||
.between(AdminUserDO::getCreateTime, startTime, endTIme)));
|
||||
.between(AdminUserDO::getLoginDate, startTime, endTIme)));
|
||||
}
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.cf.imes.module.system.order;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 生产单统计维度单位入参校验注解
|
||||
*
|
||||
* @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<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.cf.imes.module.system.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<OrderStatisticsUnitInEnum, Integer> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-1
@@ -2,15 +2,18 @@ package com.cf.imes.module.system.service.organ;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsReqDTO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganSaveReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganSimpleRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.user.vo.user.UserSimpleRespVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
||||
import com.cf.imes.module.system.service.organ.handler.OrganInfoHandler;
|
||||
import com.cf.imes.module.system.service.organ.handler.OrganMenuHandler;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -136,4 +139,24 @@ public interface OrganService {
|
||||
* 组织总数统计
|
||||
*/
|
||||
Map<String, Integer> orgTotal();
|
||||
|
||||
/**
|
||||
* 组织新增统计
|
||||
*/
|
||||
List<OrgStatisticsIsLapseRespDTO> orgCountAddByOrderDateAdd(OrgStatisticsReqDTO reqVO);
|
||||
|
||||
/**
|
||||
* 组织注销统计
|
||||
*/
|
||||
List<OrgStatisticsIsLapseRespDTO> orgCountLapseByOrderDate(OrgStatisticsReqDTO reqVO);
|
||||
|
||||
/**
|
||||
* 即将过期组织统计
|
||||
*/
|
||||
List<OrganRespVO> orgCountExpire(LocalDateTime today, LocalDateTime afterDay);
|
||||
|
||||
/**
|
||||
* 已过期组织统计
|
||||
*/
|
||||
List<OrganRespVO> orgCountExpired(LocalDateTime alertDay);
|
||||
}
|
||||
|
||||
+24
@@ -15,7 +15,10 @@ import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.config.OrganProperties;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.organ.core.util.OrganUtils;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO;
|
||||
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsReqDTO;
|
||||
import com.cf.imes.module.system.constants.permission.InternalRoleConstants;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganSimpleRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.role.RoleSaveReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganPageReqVO;
|
||||
@@ -44,6 +47,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -372,4 +376,24 @@ public class OrganServiceImpl implements OrganService {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrgStatisticsIsLapseRespDTO> orgCountAddByOrderDateAdd(OrgStatisticsReqDTO reqVO) {
|
||||
return organMapper.selectOrgCountAddByOrderDate(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrgStatisticsIsLapseRespDTO> orgCountLapseByOrderDate(OrgStatisticsReqDTO reqVO) {
|
||||
return organMapper.selectOrgCountLapseByOrderDate(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrganRespVO> orgCountExpire(LocalDateTime today, LocalDateTime afterDay) {
|
||||
return BeanUtils.toBean(organMapper.selectOrgCountExpire(today, afterDay), OrganRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrganRespVO> orgCountExpired(LocalDateTime alertDay) {
|
||||
return BeanUtils.toBean(organMapper.selectOrgCountExpired(alertDay), OrganRespVO.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -597,7 +597,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
map.put("userTodayDel", userTodayDel);
|
||||
// 当日沉寂数 (30天未登录)
|
||||
Date date = DateUtil.offsetDay(new Date(), -30);
|
||||
Integer userTodaySilent = userMapper.selectUserSilentCount(DateUtil.beginOfDay(date).toLocalDateTime());
|
||||
Integer userTodaySilent = userMapper.selectUserCountSilent(DateUtil.beginOfDay(date).toLocalDateTime());
|
||||
map.put("userTodaySilent", userTodaySilent);
|
||||
|
||||
return map;
|
||||
|
||||
+32
-1
@@ -28,8 +28,39 @@
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="dateFormat">
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.framework.common.enums.OrderStatisticsUnit@QUARTER.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', QUARTER(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.framework.common.enums.OrderStatisticsUnit@MONTH.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date)) as date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.framework.common.enums.OrderStatisticsUnit@WEEK.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', FLOOR((DayOfMonth(o.order_date)-1)/7)+1) AS date
|
||||
</if>
|
||||
<if test="req.unit != null and req.unit == @com.cf.imes.framework.common.enums.OrderStatisticsUnit@DAY.getValue()">
|
||||
,CONCAT(YEAR(o.order_date), '-', MONTH(o.order_date), '-', DAY(o.order_date)) as date
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="selectOrgCountLapseByOrderDate"
|
||||
resultType="com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO">
|
||||
select count(o.id) as orgCount
|
||||
<include refid="dateFormat"/>
|
||||
from system_organization o
|
||||
where o.update_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and o.deleted = 1
|
||||
group by date;
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectOrgCountAddByOrderDate"
|
||||
resultType="com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO">
|
||||
select count(o.id) as orgCount
|
||||
<include refid="dateFormat"/>
|
||||
from system_organization o
|
||||
where o.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and o.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.cf.imes.module.system.dal.mysql.organ.OrganMapper">
|
||||
<mapper namespace="com.cf.imes.module.system.dal.mysql.user.AdminUserMapper">
|
||||
|
||||
<select id="selectUserSilentCount" resultType="java.lang.Integer">
|
||||
SELECT DISTINCT COUNT(*) AS count
|
||||
|
||||
Reference in New Issue
Block a user