Commit 3f97e249 authored by nie'hong's avatar nie'hong

完善工时统计

parent 7c183d72
...@@ -51,4 +51,6 @@ public interface WorkProjectMapper extends BaseMapper<WorkProject> { ...@@ -51,4 +51,6 @@ public interface WorkProjectMapper extends BaseMapper<WorkProject> {
int updateProject(ModifyProjectVo modifyProjectVo); int updateProject(ModifyProjectVo modifyProjectVo);
List<WorkProject> getListByDeptAndIsConclusion(@Param("deptId") Integer deptId,@Param("isConclusion") Integer isConclusion); List<WorkProject> getListByDeptAndIsConclusion(@Param("deptId") Integer deptId,@Param("isConclusion") Integer isConclusion);
List<Integer> getProjectIdByManager(Integer userId);
} }
...@@ -168,5 +168,11 @@ ORDER BY p.is_conclusion DESC ...@@ -168,5 +168,11 @@ ORDER BY p.is_conclusion DESC
<if test="isConclusion !=null ">AND is_conclusion=#{isConclusion}</if> <if test="isConclusion !=null ">AND is_conclusion=#{isConclusion}</if>
</select> </select>
<select id="getProjectIdByManager" resultType="java.lang.Integer">
select id
from <include refid="table"/>
where manager_id = #{userId}
</select>
</mapper> </mapper>
...@@ -210,15 +210,16 @@ ...@@ -210,15 +210,16 @@
<if test="startDay != null"> <if test="startDay != null">
AND work_day>=#{startDay} AND work_day>=#{startDay}
</if> </if>
<if test="projectIds != null"> <if test="projectIdList != null">
AND project_id IN AND project_id IN
<foreach collection="projectIds" item="projectId" open="(" close=")" separator=","> <foreach collection="projectIdList" item="projectId" open="(" close=")" separator=",">
#{projectId} #{projectId}
</foreach> </foreach>
</if> </if>
<if test="statusArray != null"> <if test="statusArray != null">
AND `status` IN AND `status` IN
<foreach collection="statusArray" item="workStatus" open="(" close=")" separator=",">#{workStatus} <foreach collection="statusArray" item="workStatus" open="(" close=")" separator=",">
#{workStatus}
</foreach> </foreach>
</if> </if>
<if test="typeList != null"> <if test="typeList != null">
......
...@@ -6,7 +6,8 @@ package cn.wisenergy.model.enums; ...@@ -6,7 +6,8 @@ package cn.wisenergy.model.enums;
*/ */
public enum LevelEnum { public enum LevelEnum {
EXAMINE("工时审批"), EXAMINE("工时审批"),
STATISTICS("统计"), USER_STATISTICS("人员统计报表"),
PROJECT_STATITSTICS("项目统计报表"),
PROJECT_MANAGER( "项目/商机管理"), PROJECT_MANAGER( "项目/商机管理"),
TIMEEXPORT("工时导出"), TIMEEXPORT("工时导出"),
SYSTEMSETTINGS("系统设置"), SYSTEMSETTINGS("系统设置"),
......
...@@ -148,13 +148,13 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -148,13 +148,13 @@ public class StatisticsServiceImpl implements StatisticsService {
log.info("WorkTimeOrderServiceImpl[]getMonthlyStatistics[]input.param" + userId); log.info("WorkTimeOrderServiceImpl[]getMonthlyStatistics[]input.param" + userId);
WorkUser user = workUserService.getById(userId); WorkUser user = workUserService.getById(userId);
List<String> userAuthority = this.getUserAuthority(userId); List<String> userAuthority = this.getUserAuthority(userId);
//本月第一天 // 本月第一天
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth(); Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
// 返回数据对象 // 返回数据对象
Map<String, Object> objects = new HashMap<>(); Map<String, Object> objects = new HashMap<>();
//存放查询条件 // 存放查询条件
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
//用户是项目或部门级别,查询审批统计 // 用户有审批权限
if (userAuthority.contains(LevelEnum.EXAMINE.getLevelName())) { if (userAuthority.contains(LevelEnum.EXAMINE.getLevelName())) {
//以审批人、审核状态、开始时间查询本月审批数量 //以审批人、审核状态、开始时间查询本月审批数量
map.put("reviewerId", userId); map.put("reviewerId", userId);
...@@ -165,39 +165,45 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -165,39 +165,45 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("status", WorkOrderStatus.TURN_DOWN.getCode()); map.put("status", WorkOrderStatus.TURN_DOWN.getCode());
Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map); Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map);
// 查询用户负责项目 // 移除查询审批人和状态条件
List<WorkProject> projects = workProjectService.getUserManageProjects(userId); map.remove("reviewerId");
if (CollectionUtil.isNotEmpty(projects)) { map.remove("status");
List<Integer> projectIds = projects.stream().map(WorkProject::getId).collect(Collectors.toList()); //待审核包括:新提交和重新提交的
map.put("projectIds", projectIds); List<Integer> statusArray = new ArrayList<>();
statusArray.add(WorkOrderStatus.WAIT_AUDIT.getCode());
statusArray.add(WorkOrderStatus.RE_SUBMIT.getCode());
//本月未审批数量查询
map.put("statusArray", statusArray);
// 查询用户负责的项目和商机id
List<Integer> projectIdList = workProjectMapper.getProjectIdByManager(userId);
if (CollectionUtil.isNotEmpty(projectIdList)) {
map.put("projectIdList", projectIdList);
} }
// 项目和商机的未审批的条数
Integer notCompletedCount1 = workTimeOrderMapper.getCountByCondition(map);
// 查询用户负责审批的除项目合商机的其余类型
List<WorkTypeManager> workTypeManagers = workTypeManagerMapper.getListByManagerId(userId); List<WorkTypeManager> workTypeManagers = workTypeManagerMapper.getListByManagerId(userId);
if (CollectionUtil.isNotEmpty(workTypeManagers)) { if (CollectionUtil.isNotEmpty(workTypeManagers)) {
map.remove("projectIdList");
List<Integer> type = workTypeManagers.stream().map(WorkTypeManager::getType).collect(Collectors.toList()); List<Integer> type = workTypeManagers.stream().map(WorkTypeManager::getType).collect(Collectors.toList());
map.put("typeList", type); map.put("typeList", type);
map.put("deptId", user.getDeptId()); map.put("deptId", user.getDeptId());
} }
// 其余类型为审批的条数
Integer notCompletedCount2 = workTimeOrderMapper.getCountByCondition(map);
//待审核包括:新提交和重新提交的
List<Integer> statusArray = new ArrayList<>();
statusArray.add(WorkOrderStatus.WAIT_AUDIT.getCode());
statusArray.add(WorkOrderStatus.RE_SUBMIT.getCode());
map.remove("reviewerId");
map.remove("status");
//本月未审批数量查询
map.put("statusArray", statusArray);
Integer notCompletedCount = workTimeOrderMapper.getCountByCondition(map);
//所有查询结果封装进对象 //所有查询结果封装进对象
ApprovalStatistics approvalStatistics = new ApprovalStatistics(); ApprovalStatistics approvalStatistics = new ApprovalStatistics();
approvalStatistics.setApprovalCount(completedCount); approvalStatistics.setApprovalCount(completedCount);
approvalStatistics.setRejectNotSubmit(rejectAndNotResubmit); approvalStatistics.setRejectNotSubmit(rejectAndNotResubmit);
approvalStatistics.setNotApprovalCount(notCompletedCount); approvalStatistics.setNotApprovalCount(notCompletedCount1 + notCompletedCount2);
objects.put("manager", approvalStatistics); objects.put("manager", approvalStatistics);
} }
// 填报情况 // 填报情况
// 本月应填报日期 // 本月应填报日期
List<Date> currentMonthWorkDays = this.currentMonthWorkDays(firstDayOfMonth,true); List<Date> currentMonthWorkDays = this.currentMonthWorkDays(firstDayOfMonth, true);
// 本月已填报日期 // 本月已填报日期
List<Date> currentMonthFilledDays = this.currentMonthFilledDays(userId, firstDayOfMonth); List<Date> currentMonthFilledDays = this.currentMonthFilledDays(userId, firstDayOfMonth);
// 本月未填报日期 // 本月未填报日期
...@@ -258,14 +264,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -258,14 +264,6 @@ public class StatisticsServiceImpl implements StatisticsService {
if (userId == null) { if (userId == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
} }
WorkUser user = workUserService.getById(userId);
// 时间不为空,赋值当月第一天
if (StringUtil.isNotEmpty(startTime)) {
Date currentFirstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
startTime = DateUtil.convertDateToYMDStr(currentFirstDayOfMonth);
}
// 用户角色 // 用户角色
List<Integer> role = UserRoleLevelUtils.getRole(userId); List<Integer> role = UserRoleLevelUtils.getRole(userId);
// 用户权限 // 用户权限
...@@ -274,6 +272,13 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -274,6 +272,13 @@ public class StatisticsServiceImpl implements StatisticsService {
if (!userAuthority.contains(LevelEnum.EXAMINE.getLevelName())) { if (!userAuthority.contains(LevelEnum.EXAMINE.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN); throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
} }
WorkUser user = workUserService.getById(userId);
// 时间不为空,赋值当月第一天
if (StringUtil.isNotEmpty(startTime)) {
Date currentFirstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
startTime = DateUtil.convertDateToYMDStr(currentFirstDayOfMonth);
}
// 查询用户管理的项目 // 查询用户管理的项目
List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId); List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId);
...@@ -295,7 +300,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -295,7 +300,7 @@ public class StatisticsServiceImpl implements StatisticsService {
if (role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) { if (role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
WorkDept workDept = workDeptMapper.getById(user.getDeptId()); WorkDept workDept = workDeptMapper.getById(user.getDeptId());
map.put("centreId",workDept.getCentreId() ); map.put("centreId", workDept.getCentreId());
} }
// 查询项目和商机的工时统计 // 查询项目和商机的工时统计
List<WorkTimeAndCostCollect> collect = workProjectTimeCostMapper.selectList(map); List<WorkTimeAndCostCollect> collect = workProjectTimeCostMapper.selectList(map);
...@@ -411,7 +416,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -411,7 +416,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 第一列列宽 // 第一列列宽
sheet.setColumnWidth(1, EXCEL_WIDTH); sheet.setColumnWidth(1, EXCEL_WIDTH);
// 获取本月应上班日期集合 // 获取本月应上班日期集合
List<Date> dates = this.currentMonthWorkDays(date,false); List<Date> dates = this.currentMonthWorkDays(date, false);
List<Integer> days = new ArrayList<>(); List<Integer> days = new ArrayList<>();
for (Date date1 : dates) { for (Date date1 : dates) {
days.add(DateUtil.getDay(date1)); days.add(DateUtil.getDay(date1));
...@@ -529,7 +534,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -529,7 +534,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<WorkProject> userManageProjects; List<WorkProject> userManageProjects;
if (deptId != null) { if (deptId != null) {
userManageProjects = workProjectMapper.getListByDeptAndIsConclusion(deptId, isConclusion); userManageProjects = workProjectMapper.getListByDeptAndIsConclusion(deptId, isConclusion);
}else { } else {
userManageProjects = workProjectService.getUserManageProjects(userId); userManageProjects = workProjectService.getUserManageProjects(userId);
} }
// 管理项目为空则提前结束 // 管理项目为空则提前结束
...@@ -553,7 +558,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -553,7 +558,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单 // 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单
List<Integer> userIds = workUserProjectMapper.selectUserIdByProjectIds(projectIds); List<Integer> userIds = workUserProjectMapper.selectUserIdByProjectIds(projectIds);
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) { if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(startDate, endDate, queryType, userIds,false); List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(startDate, endDate, queryType, userIds, false);
if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) { if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) {
userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType()); userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType());
} }
...@@ -577,7 +582,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -577,7 +582,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userProjectWorkTimeStatistic.getProjectWorkTimeAndType(); List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userProjectWorkTimeStatistic.getProjectWorkTimeAndType();
// 遍历一个人所有项目统计,计算所有项目所有工时总和 // 遍历一个人所有项目统计,计算所有项目所有工时总和
for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) { for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
projectWorkTimeAndType.setProjectTypeName(types.get(projectWorkTimeAndType.getProjectType()-1).getName()); projectWorkTimeAndType.setProjectTypeName(types.get(projectWorkTimeAndType.getProjectType() - 1).getName());
totalTime += projectWorkTimeAndType.getWorkTime(); totalTime += projectWorkTimeAndType.getWorkTime();
} }
userProjectWorkTimeStatistic.setTotalTime(totalTime); userProjectWorkTimeStatistic.setTotalTime(totalTime);
...@@ -589,11 +594,9 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -589,11 +594,9 @@ public class StatisticsServiceImpl implements StatisticsService {
@Override @Override
public List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) { public List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) {
log.info("StatisticsServiceImpl[]getProjectStatistics[]input.param" + userId + deptId + year + projectId); log.info("StatisticsServiceImpl[]getProjectStatistics[]input.param" + userId + deptId + year + projectId);
// 获取角色
List<Integer> role = userRoleLevelUtils.getRole(userId);
// 获取权限 // 获取权限
List<String> userAuthority = this.getUserAuthority(userId); List<String> userAuthority = this.getUserAuthority(userId);
if (!role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) { if (!userAuthority.contains(LevelEnum.PROJECT_STATITSTICS.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY); throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
} }
// 默认查询时间为当前 // 默认查询时间为当前
...@@ -618,7 +621,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -618,7 +621,7 @@ public class StatisticsServiceImpl implements StatisticsService {
if (deptId == null) { if (deptId == null) {
projectStatistics.addAll(projectStatisticsByMonths); projectStatistics.addAll(projectStatisticsByMonths);
projectStatistics.addAll(projectStatisticsByMonths1); projectStatistics.addAll(projectStatisticsByMonths1);
}else { } else {
projectStatistics.addAll(projectStatisticsByMonths1); projectStatistics.addAll(projectStatisticsByMonths1);
projectStatistics.addAll(projectStatisticsByMonths); projectStatistics.addAll(projectStatisticsByMonths);
} }
...@@ -694,7 +697,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -694,7 +697,7 @@ public class StatisticsServiceImpl implements StatisticsService {
//获取用户某月已填报的日期,如果一天中只有被驳回则不为已填报 //获取用户某月已填报的日期,如果一天中只有被驳回则不为已填报
public List<Date> currentMonthFilledDays(Integer userId, Date date) { public List<Date> currentMonthFilledDays(Integer userId, Date date) {
log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method"); log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method");
List<Date> currentMonthFilledDays = workTimeOrderMapper.getDaysByDateAndStatus( userId, date); List<Date> currentMonthFilledDays = workTimeOrderMapper.getDaysByDateAndStatus(userId, date);
return currentMonthFilledDays; return currentMonthFilledDays;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment