feat(employee-big-brother): 新增建联率统计与柱状图接口
- Controller 增加 /self_complete、/employeeCompleteBarChart 两个端点 - Mapper 新增 selectEmployeeBrotherCompleteBarChart、selectEmployeeBrotherWithOperationStatus 查询 - Service 层实现个人及多用户建联率统计逻辑 - XML 补充对应 SQL,支持按天数与用户列表过滤
This commit is contained in:
@@ -6,9 +6,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherRespVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherRespVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO;
|
||||||
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.EmployeeCompleteBarChartReqVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
||||||
import cn.iocoder.yudao.module.tkdata.service.employeebigbrother.EmployeeBigBrotherService;
|
import cn.iocoder.yudao.module.tkdata.service.employeebigbrother.EmployeeBigBrotherService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -125,4 +128,20 @@ public class EmployeeBigBrotherController {
|
|||||||
employeeBigBrotherService.batchUpdateEmployeeBigBrother(updateReqVO);
|
employeeBigBrotherService.batchUpdateEmployeeBigBrother(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/self_complete")
|
||||||
|
@Operation(summary = "获得自己的建联率")
|
||||||
|
@PreAuthorize("@ss.hasPermission('server:employee-hosts:selfquery')")
|
||||||
|
public CommonResult<CompletedRateVO> getEmployeeHostsCompleteWithSelf() {
|
||||||
|
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||||
|
return success(employeeBigBrotherService.getEmployeeHostsCompleteWithSelf(loginUserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/employeeCompleteBarChart")
|
||||||
|
@Operation(summary = "获得员工的建联柱状图数据")
|
||||||
|
@PreAuthorize("@ss.hasPermission('server:employee-big-brother:selfquery')")
|
||||||
|
public CommonResult<List<CompletedRateVO>> getEmployeeCompleteBarChart(@RequestBody EmployeeCompleteBarChartReqVO reqVO) {
|
||||||
|
return success(employeeBigBrotherService.getEmployeeBrotherCompleteBarChart(reqVO.getUserId(),reqVO.getDays()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,14 @@ package cn.iocoder.yudao.module.tkdata.dal.mysql.employeebigbrother;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 大哥数据员工业务 Mapper
|
* 大哥数据员工业务 Mapper
|
||||||
*
|
*
|
||||||
@@ -20,4 +23,9 @@ public interface EmployeeBigBrotherMapper extends BaseMapperX<EmployeeBigBrother
|
|||||||
|
|
||||||
|
|
||||||
IPage<EmployeeBigBrotherDO> selectPagewithSelf(@Param("page") IPage<EmployeeBigBrotherDO> iPage,@Param("dto") EmployeeBigBrotherPageReqVO pageReqVO);
|
IPage<EmployeeBigBrotherDO> selectPagewithSelf(@Param("page") IPage<EmployeeBigBrotherDO> iPage,@Param("dto") EmployeeBigBrotherPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
List<CompletedRateVO> selectEmployeeBrotherCompleteBarChart(@Param("list") List<Long> list, @Param("days") Integer days);
|
||||||
|
|
||||||
|
CompletedRateVO selectEmployeeBrotherWithOperationStatus(@Param("userId") Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,9 @@ import javax.validation.*;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,4 +67,8 @@ public interface EmployeeBigBrotherService {
|
|||||||
PageResult<EmployeeBigBrotherDO> getEmployeeBigBrotherPageWithSelf(@Valid EmployeeBigBrotherPageReqVO pageReqVO);
|
PageResult<EmployeeBigBrotherDO> getEmployeeBigBrotherPageWithSelf(@Valid EmployeeBigBrotherPageReqVO pageReqVO);
|
||||||
|
|
||||||
void batchUpdateEmployeeBigBrother(@Valid List<EmployeeBigBrotherSaveReqVO> updateReqVO);
|
void batchUpdateEmployeeBigBrother(@Valid List<EmployeeBigBrotherSaveReqVO> updateReqVO);
|
||||||
|
|
||||||
|
List<CompletedRateVO> getEmployeeBrotherCompleteBarChart(@Param("list") List<Long> list, @Param("days") Integer days);
|
||||||
|
|
||||||
|
CompletedRateVO getEmployeeHostsCompleteWithSelf(Long loginUserId);
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|||||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherPageReqVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeebigbrother.vo.EmployeeBigBrotherSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.bigbrother.BigBrotherDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.bigbrother.BigBrotherDO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeebigbrother.EmployeeBigBrotherDO;
|
||||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeehosts.EmployeeHostsDO;
|
import cn.iocoder.yudao.module.tkdata.dal.dataobject.employeehosts.EmployeeHostsDO;
|
||||||
@@ -21,6 +22,8 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
@@ -157,4 +160,36 @@ public class EmployeeBigBrotherServiceImpl implements EmployeeBigBrotherService
|
|||||||
employeeBigBrotherMapper.updateBatch(employeeBigBrotherDOS);
|
employeeBigBrotherMapper.updateBatch(employeeBigBrotherDOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CompletedRateVO> getEmployeeBrotherCompleteBarChart(List<Long> userIdList, Integer days) {
|
||||||
|
|
||||||
|
List<CompletedRateVO> dbList = employeeBigBrotherMapper.selectEmployeeBrotherCompleteBarChart(userIdList,days);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 2. 转 Map,key 是 userId
|
||||||
|
Map<Long, CompletedRateVO> dbMap = dbList.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
CompletedRateVO::getUserId,
|
||||||
|
Function.identity(),
|
||||||
|
(oldVal, newVal) -> newVal)); // 重复时保留新的
|
||||||
|
// 3. 组装结果
|
||||||
|
return userIdList.stream()
|
||||||
|
.map(userId -> dbMap.getOrDefault(userId, new CompletedRateVO(userId, 0))) // 缺数据补0
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
ArrayList<CompletedRateVO> nullData = new ArrayList<>();
|
||||||
|
for (Long userId : userIdList) {
|
||||||
|
nullData.add(new CompletedRateVO(userId, 0));
|
||||||
|
}
|
||||||
|
return nullData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletedRateVO getEmployeeHostsCompleteWithSelf(Long loginUserId) {
|
||||||
|
return employeeBigBrotherMapper.selectEmployeeBrotherWithOperationStatus(loginUserId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -228,4 +228,39 @@
|
|||||||
</when>
|
</when>
|
||||||
</choose>
|
</choose>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectEmployeeBrotherCompleteBarChart"
|
||||||
|
resultType="cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO">
|
||||||
|
SELECT
|
||||||
|
user_id AS userId,
|
||||||
|
COUNT(DISTINCT
|
||||||
|
CASE WHEN operation_status = 1 THEN display_id END) AS finishedNum
|
||||||
|
FROM server_employee_big_brother
|
||||||
|
WHERE deleted = 0
|
||||||
|
AND operation_status = 1
|
||||||
|
<!-- 日期范围:今天或过去 7 天(含今天) -->
|
||||||
|
AND update_time >= DATE_SUB(CURDATE(), INTERVAL #{days,jdbcType=INTEGER} - 1 DAY)
|
||||||
|
<if test="list != null and list.size() > 0">
|
||||||
|
AND user_id IN
|
||||||
|
<foreach collection="list" item="user_id" open="(" separator="," close=")">
|
||||||
|
#{user_id}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
GROUP BY user_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectEmployeeBrotherWithOperationStatus"
|
||||||
|
resultType="cn.iocoder.yudao.module.tkdata.controller.admin.employeehosts.vo.CompletedRateVO">
|
||||||
|
SELECT
|
||||||
|
user_id AS userId,
|
||||||
|
SUM(CASE WHEN operation_status = 1 THEN 1 ELSE 0 END) AS finishedNum,
|
||||||
|
SUM(CASE WHEN operation_status = 0 THEN 1 ELSE 0 END) AS unfinishedNum,
|
||||||
|
COUNT(*) AS totalNum
|
||||||
|
FROM server_employee_big_brother
|
||||||
|
WHERE deleted = 0
|
||||||
|
<if test="userId != null">
|
||||||
|
AND user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
GROUP BY user_id
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user