Commit dee443dd authored by nie'hong's avatar nie'hong

完善工时统计

parent e31e92a8
package cn.wisenergy.mapper;
import cn.wisenergy.model.dto.WorkTimeAndCostCollect;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author: nh
* @create: 2021-02-07 11:09
**/
public interface WorkProjectTimeCostMapper {
/**
* 根据添加查询项目统计信息
*/
void statisticsTimeOrderByMonth();
/**
* 统计项目总工时和成本,按月统计
* @param map
*/
List<WorkTimeAndCostCollect> selectList(Map<String, Object> map);
}
...@@ -72,11 +72,10 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> { ...@@ -72,11 +72,10 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
/** /**
* 获取项目或商机的成本 * 获取项目或商机的成本
* *
* @param projectIds * @param map
* @param firstDayOfMonth
* @return * @return
*/ */
List<WorkTimeAndCostCollect> getWorkTimeAndCostCollect(@Param("projectIds") List<Integer> projectIds, @Param("firstDayOfMonth") String firstDayOfMonth); List<WorkTimeAndCostCollect> getWorkTimeAndCostCollect(Map<String, Object> map);
/** /**
* 获取上班日期集合 * 获取上班日期集合
...@@ -95,4 +94,5 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> { ...@@ -95,4 +94,5 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
* 获取人员项目工时 * 获取人员项目工时
*/ */
List<UserWorkTimeStatisticsByProject> getUserProjectWorkTimeStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("status") Integer status, @Param("projectIds") List<Integer> projectIds); List<UserWorkTimeStatisticsByProject> getUserProjectWorkTimeStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("status") Integer status, @Param("projectIds") List<Integer> projectIds);
} }
...@@ -47,15 +47,13 @@ ...@@ -47,15 +47,13 @@
<select id="getProjectsByCriteria" resultMap="BaseResultMap" parameterType="map"> <select id="getProjectsByCriteria" resultMap="BaseResultMap" parameterType="map">
select <include refid="Base_Column_List"/> select <include refid="Base_Column_List"/>
from <include refid="table"/> from <include refid="table"/>
<where> where manager_id = #{managerId} OR dept_id = #{deptId}
<include refid="criteria"/>
<if test="deptIds != null"> <if test="deptIds != null">
AND dept_id IN OR dept_id IN
<foreach collection="deptIds" item="deptId" separator="," open="(" close=")"> <foreach collection="deptIds" item="deptId" separator="," open="(" close=")">
#{deptId} #{deptId}
</foreach> </foreach>
</if> </if>
</where>
</select> </select>
<select id="getProjectsByIds" resultType="cn.wisenergy.model.app.WorkProject"> <select id="getProjectsByIds" resultType="cn.wisenergy.model.app.WorkProject">
select <include refid="Base_Column_List"/> select <include refid="Base_Column_List"/>
......
<?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="cn.wisenergy.mapper.WorkProjectTimeCostMapper">
<resultMap id="workProjectTimeCost" type="cn.wisenergy.model.app.WorkProjectTimeCost">
<id column="id" property="id"/>
<result property="projectId" column="project_id"/>
<result property="statisticsStart" column="statistics_start"/>
<result property="statisticsEnd" column="statistics_end"/>
<result property="totalTime" column="total_time"/>
<result property="cost" column="cost"/>
</resultMap>
<resultMap id="workTimeAndCostCollect" type="cn.wisenergy.model.dto.WorkTimeAndCostCollect">
<result property="type" column="type"/>
<collection property="deptProjectWorkTimeAndCosts" resultMap="deptProjectWorkTimeAndCost"/>
</resultMap>
<resultMap id="deptProjectWorkTimeAndCost" type="cn.wisenergy.model.dto.DeptProjectWorkTimeAndCost">
<result property="deptId" column="dept_id"/>
<result property="deptName" column="dept_name"/>
<collection property="projectWorkTimeAndCostStatistics"
ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndCostStatistics">
<result property="projectId" column="project_id"/>
<result property="projectName" column="project_name"/>
<result property="firstTime" column="statistics_start"/>
<result property="lastTime" column="statistics_end"/>
<result property="totalTime" column="total_time"/>
<result property="cost" column="cost"/>
</collection>
</resultMap>
<insert id="statisticsTimeOrderByMonth">
INSERT into work_project_time_cost(project_id,statistics_start,statistics_end,total_time,cost)
SELECT
project_id,
min(work_day) AS statistics_start,
max(work_day),
sum(work_time/8),
-- 加班和不加班成本结算不同
sum(if(is_overtime=0,work_time/8*s.day_salary,work_time/8*s.day_salary*1.5)) AS cost
FROM
work_time_order t join work_user_salary s on t.user_id = s.user_id
WHERE status in (2,5) AND s.create_time &lt; work_day AND s.end_time>work_day AND
GROUP BY
project_id,
YEAR (work_day),
MONTH (work_day)
ON DUPLICATE key UPDATE statistics_end = VALUES(statistics_end),total_time = VALUES(total_time),cost= VALUES(cost)
</insert>
<select id="selectList" resultMap="workTimeAndCostCollect">
SELECT case `type` when 1 then "项目" else "商机" end AS type ,dept_name,dept_id,ptc.project_id AS
project_id,project_name,min(statistics_start) AS statistics_start,max(statistics_end) AS
statistics_end,sum(total_time) AS total_time,sum(cost) AS cost
from work_project_time_cost ptc join work_project p on ptc.project_id=p.id join work_dept d on p.dept_id=d.id
where project_id in
<foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
#{projectId}
</foreach>
<if test="deptId != null">
AND dept_id = #{deptId}
</if>
AND type in
<foreach collection="types" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="firstDayOfMonth != null">
AND statistics_start >= #{firstDayOfMonth}
</if>
GROUP BY type,dept_name,dept_id,ptc.project_id,project_name
</select>
</mapper>
\ No newline at end of file
...@@ -33,6 +33,25 @@ ...@@ -33,6 +33,25 @@
</collection> </collection>
</resultMap> </resultMap>
<resultMap id="workTimeAndCostCollect" type="cn.wisenergy.model.dto.WorkTimeAndCostCollect" >
<result property="type" column="type"/>
<collection property="deptProjectWorkTimeAndCosts" resultMap="deptProjectWorkTimeAndCosts" >
</collection>
</resultMap>
<resultMap id="deptProjectWorkTimeAndCosts" type="cn.wisenergy.model.dto.DeptProjectWorkTimeAndCost">
<result property="deptId" column="dept_id"/>
<result property="deptName" column="dept_name"/>
<collection property="projectWorkTimeAndCostStatistics" ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndCostStatistics">
<result property="projectId" column="project_id"/>
<result property="projectName" column="project_name"/>
<result property="firstTime" column="first_time"/>
<result property="lastTime" column="last_time"/>
<result property="totalTime" column="total_time"/>
<result property="cost" column="cost"/>
</collection>
</resultMap>
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="vals"> <sql id="vals">
...@@ -209,21 +228,31 @@ ...@@ -209,21 +228,31 @@
</where> </where>
</select> </select>
<select id="getWorkTimeAndCostCollect" resultType="cn.wisenergy.model.dto.WorkTimeAndCostCollect" <select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" >
parameterType="integer"> SELECT CASE t.type WHEN 1 THEN "项目" WHEN 2 THEN "商机" WHEN 5 THEN "外部商务" WHEN 6 THEN "内部培训、技术准备、管理" WHEN 7 THEN "其他非项目/商机工作" END AS type,p.dept_id AS dept_id,
select CASE WHEN t.type= 1 THEN "项目" WHEN t.type= 2 THEN "商机" END AS type,t.dept_id, t.project_id AS project_id,MIN(t.work_day) AS first_time,MAX(t.work_day) AS last_time,ROUND(SUM(t.work_time)/8,2) AS
t.project_id,MIN(t.work_day) AS firstTime,MAX(t.work_day) AS lastTime,SUM(t.work_time)/8 AS total_time,ROUND((SUM(t.work_time))/8*10,2) AS cost,dept_name AS dept_name,project_name
totalTime,(SUM(t.work_time))/8*10 AS cost,dept_name AS deptName,project_name AS projectName FROM work_time_order t LEFT JOIN work_project p ON t.project_id=p.id LEFT JOIN work_dept d ON p.dept_id=d.id
from work_time_order t JOIN work_dept d ON t.dept_id=d.id WHERE status IN (2,5)
JOIN work_project p ON t.project_id=p.id <if test="projectIds != null">
where status IN (2,5) AND t.type IN (1,2) AND project_id IN AND (t.project_id IN
<foreach collection="projectIds" item="projectId" open="(" close=")" separator=","> <foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
#{projectId} #{projectId}
</foreach> </foreach>
<if test="firstDayOfMonth != null"> OR t.project_id IS null)
AND work_day >= #{firstDayOfMonth} </if>
<if test="startTime != null">
AND work_day >= #{startTime}
</if> </if>
group by t.type,dept_id, project_id,dept_name,project_name <if test="deptId != null">
AND t.dept_id = #{deptId}
</if>
AND t.type in
<foreach collection="types" item="type" open="(" close=")" separator=",">
#{type}
</foreach>
group by t.type,t.dept_id, t.project_id,dept_name,p.project_name
order by t.dept_id
</select> </select>
<select id="getDaysByDateAndStatus" resultType="date"> <select id="getDaysByDateAndStatus" resultType="date">
......
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* @description:
* @author: nh
* @create: 2021-02-07 11:02
**/
@ApiModel
@Data
public class WorkProjectTimeCost implements Serializable {
private static final long serialVersionUID = -1233065911955324813L;
@ApiModelProperty(name = "id", value = "主键")
private Integer id;
@ApiModelProperty(name = "projectId", value = "项目主键")
private Integer projectId;
@ApiModelProperty(name = "statisticsStart", value = "当月第一次统计的时间")
private Date statisticsStart;
@ApiModelProperty(name = "statisticsEnd", value = "当月最后一次统计的时间")
private Date statisticsEnd;
@ApiModelProperty(name = "totalTime", value = "当月统计总工时,单位:人/天")
private Integer totalTime;
@ApiModelProperty(name = "cost", value = "成本")
private BigDecimal cost;
}
package cn.wisenergy.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @description:
* @author: nh
* @create: 2021-02-05 11:54
**/
@Data
@ApiModel(value = "DeptProjectWorkTimeAndCost", description = "部门项目工时及成本")
public class DeptProjectWorkTimeAndCost implements Serializable {
private static final long serialVersionUID = -4607187953621906522L;
/**
* 部门名称
*/
@ApiModelProperty(name = "deptName", value = "部门名称")
private String deptName;
/**
* 部门主键
*/
@ApiModelProperty(name = "deptId", value = "部门主键")
private Integer deptId;
List<ProjectWorkTimeAndCostStatistics> projectWorkTimeAndCostStatistics;
}
package cn.wisenergy.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @description:
* @author: nh
* @create: 2021-02-05 11:47
**/
@Data
@ApiModel(value = "ProjectWorkTimeAndCostStatistics", description = "项目的工时及成本统计")
public class ProjectWorkTimeAndCostStatistics implements Serializable {
private static final long serialVersionUID = -4314814033869080027L;
/**
* 项目主键
*/
@ApiModelProperty(name = "projectId", value = "项目主键")
private Integer projectId;
/**
* 项目名称
*/
@ApiModelProperty(name = "projectName", value = "项目名称")
private String projectName;
/**
* 开始统计日期
*/
@ApiModelProperty(name = "firstTime", value = "开始统计的日期")
private String firstTime;
/**
*最后统计日期
*/
@ApiModelProperty(name = "lastTime", value = "最后统计的日期")
private String lastTime;
/**
* 工时总计:人/天
*/
@ApiModelProperty(name = "totalTime", value = "工时总计")
private BigDecimal totalTime;
/**
* 工时成本
*/
@ApiModelProperty(name = "cost", value = "工时成本")
private BigDecimal cost;
}
...@@ -6,6 +6,7 @@ import lombok.Data; ...@@ -6,6 +6,7 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
/** /**
* @description: 项目的工时和工时成本统计 * @description: 项目的工时和工时成本统计
...@@ -18,57 +19,21 @@ public class WorkTimeAndCostCollect implements Serializable { ...@@ -18,57 +19,21 @@ public class WorkTimeAndCostCollect implements Serializable {
private static final long serialVersionUID = 7207732278277982917L; private static final long serialVersionUID = 7207732278277982917L;
/** /**
* 类型:项目/商机 * 工时类型
*/ */
@ApiModelProperty(name = "type", value = "类型:商机/项目") @ApiModelProperty(name = "type", value = "工时类型")
private String type; private String type;
/** /**
* 部门名称 * 部门工时统计
*/ */
@ApiModelProperty(name = "deptName", value = "部门名称") @ApiModelProperty(name = "deptProjectWorkTimeAndCosts", value = "部门工时统计")
private String deptName; private List<DeptProjectWorkTimeAndCost> deptProjectWorkTimeAndCosts;
/** /**
* 部门主键 * 工时总计
*/ */
@ApiModelProperty(name = "deptId", value = "部门主键") @ApiModelProperty(name = "workTime", value = "工时总计")
private Integer deptId; private BigDecimal workTime;
/**
* 项目主键
*/
@ApiModelProperty(name = "projectId", value = "项目主键")
private Integer projectId;
/**
* 项目名称
*/
@ApiModelProperty(name = "projectName", value = "项目名称")
private String projectName;
/**
* 开始统计日期
*/
@ApiModelProperty(name = "firstTime", value = "开始统计的日期")
private String firstTime;
/**
*最后统计日期
*/
@ApiModelProperty(name = "lastTime", value = "最后统计的日期")
private String lastTime;
/**
* 工时总计:人/天
*/
@ApiModelProperty(name = "totalTime", value = "工时总计")
private BigDecimal totalTime;
/**
* 工时成本
*/
@ApiModelProperty(name = "cost", value = "工时成本")
private Integer cost;
} }
...@@ -5,17 +5,13 @@ import cn.wisenergy.common.utils.DateUtil; ...@@ -5,17 +5,13 @@ import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.ExcelUtils; import cn.wisenergy.common.utils.ExcelUtils;
import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM; import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException; import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.WorkHolidayMapper; import cn.wisenergy.mapper.*;
import cn.wisenergy.mapper.WorkTimeOrderMapper;
import cn.wisenergy.mapper.WorkUserDeptMapper;
import cn.wisenergy.mapper.WorkUserMapper;
import cn.wisenergy.model.app.WorkHoliday; import cn.wisenergy.model.app.WorkHoliday;
import cn.wisenergy.model.app.WorkProject; import cn.wisenergy.model.app.WorkProject;
import cn.wisenergy.model.app.WorkUser; import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.model.dto.*; import cn.wisenergy.model.dto.*;
import cn.wisenergy.model.enums.*; import cn.wisenergy.model.enums.*;
import cn.wisenergy.service.StatisticsService; import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.service.WorkProjectService; import cn.wisenergy.service.WorkProjectService;
import cn.wisenergy.service.WorkUserService; import cn.wisenergy.service.WorkUserService;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
...@@ -24,12 +20,15 @@ import com.github.pagehelper.PageInfo; ...@@ -24,12 +20,15 @@ import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil; import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -45,9 +44,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -45,9 +44,6 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired @Autowired
private WorkUserService workUserService; private WorkUserService workUserService;
@Autowired
private WorkDeptService workDeptService;
@Autowired @Autowired
private WorkTimeOrderMapper workTimeOrderMapper; private WorkTimeOrderMapper workTimeOrderMapper;
...@@ -63,6 +59,9 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -63,6 +59,9 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired @Autowired
private WorkUserMapper workUserMapper; private WorkUserMapper workUserMapper;
@Autowired
WorkProjectTimeCostMapper workProjectTimeCostMapper;
private final static Integer EXCEL_WIDTH = 1000 * 6; private final static Integer EXCEL_WIDTH = 1000 * 6;
private final static Integer DEFAULT_DEPT_ID = 1; private final static Integer DEFAULT_DEPT_ID = 1;
...@@ -139,8 +138,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -139,8 +138,7 @@ public class StatisticsServiceImpl implements StatisticsService {
//存放查询条件 //存放查询条件
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
//用户是项目或部门级别,查询审批统计 //用户是项目或部门级别,查询审批统计
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode()) || if (user.getLevel() != ManagerEnum.NOT_MANAGER.getCode()) {
user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
//以审批人、审核状态、开始时间查询本月审批数量 //以审批人、审核状态、开始时间查询本月审批数量
map.put("reviewerId", userId); map.put("reviewerId", userId);
map.put("startDay", firstDayOfMonth); map.put("startDay", firstDayOfMonth);
...@@ -181,11 +179,10 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -181,11 +179,10 @@ public class StatisticsServiceImpl implements StatisticsService {
approvalStatistics.setNotApprovalCount(notCompletedCount); approvalStatistics.setNotApprovalCount(notCompletedCount);
objects.add(approvalStatistics); objects.add(approvalStatistics);
} }
//用户是普通用户或项目级别用户,查询填报统计
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode()) || // 填报情况
user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
// 本月应填报日期 // 本月应填报日期
List<Date> currentMonthWorkDays = this.currentMonthWorkDays(); List<Date> currentMonthWorkDays = this.currentMonthWorkDays(firstDayOfMonth);
// 本月已填报日期 // 本月已填报日期
List<Date> currentMonthFilledDays = currentMonthFilledDays(userId); List<Date> currentMonthFilledDays = currentMonthFilledDays(userId);
// 本月未填报日期 // 本月未填报日期
...@@ -199,17 +196,31 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -199,17 +196,31 @@ public class StatisticsServiceImpl implements StatisticsService {
Integer countByCondition = workTimeOrderMapper.getCountByCondition(map); Integer countByCondition = workTimeOrderMapper.getCountByCondition(map);
List<MonthlyWorkingHoursStatistics> monthlyWorkingHoursStatistics = workTimeOrderMapper.statisticsByProjectType(userId, firstDayOfMonth); List<MonthlyWorkingHoursStatistics> monthlyWorkingHoursStatistics = workTimeOrderMapper.statisticsByProjectType(userId, firstDayOfMonth);
// 如果不存在商机或项目其中某项,造对象传前端 // 如果没填写填报类型其中某项,造对象传前端
while (monthlyWorkingHoursStatistics.size() < 2) { while (monthlyWorkingHoursStatistics.size() < 5) {
// 获取工时类型(项目或商机) // 获取工时类型(项目或商机)
List<String> projectTypes = monthlyWorkingHoursStatistics.stream().map(MonthlyWorkingHoursStatistics::getProjectType).collect(Collectors.toList()); List<String> projectTypes = monthlyWorkingHoursStatistics.stream().map(MonthlyWorkingHoursStatistics::getProjectType).collect(Collectors.toList());
MonthlyWorkingHoursStatistics workingHoursStatistics = new MonthlyWorkingHoursStatistics(); MonthlyWorkingHoursStatistics workingHoursStatistics = new MonthlyWorkingHoursStatistics();
// 如果不存在项目或商机工时 // 如果没填写项目
if (!projectTypes.contains(ProjectTypeEnum.PROJECT.getTypeName())) { if (!projectTypes.contains(ProjectTypeEnum.PROJECT.getTypeName())) {
workingHoursStatistics.setProjectType(ProjectTypeEnum.PROJECT.getTypeName()); workingHoursStatistics.setProjectType(ProjectTypeEnum.PROJECT.getTypeName());
} else if (!projectTypes.contains(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName())){ }
// 没填写商机
if (!projectTypes.contains(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName())) {
workingHoursStatistics.setProjectType(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName()); workingHoursStatistics.setProjectType(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName());
} }
// 没填写外部商务
if (!projectTypes.contains(ProjectTypeEnum.EXTERNAL_BUSINESS.getTypeName())) {
workingHoursStatistics.setProjectType(ProjectTypeEnum.EXTERNAL_BUSINESS.getTypeName());
}
// 没填写内部培训、技术准备、管理
if (!projectTypes.contains(ProjectTypeEnum.INTERNAL_TRAINING.getTypeName())) {
workingHoursStatistics.setProjectType(ProjectTypeEnum.INTERNAL_TRAINING.getTypeName());
}
// 没填写其他非项目/商机工作
if (!projectTypes.contains(ProjectTypeEnum.OTHER_NON_PROJECTS.getTypeName())) {
workingHoursStatistics.setProjectType(ProjectTypeEnum.OTHER_NON_PROJECTS.getTypeName());
}
workingHoursStatistics.setCount(0); workingHoursStatistics.setCount(0);
workingHoursStatistics.setWorkTime(0); workingHoursStatistics.setWorkTime(0);
monthlyWorkingHoursStatistics.add(workingHoursStatistics); monthlyWorkingHoursStatistics.add(workingHoursStatistics);
...@@ -221,7 +232,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -221,7 +232,6 @@ public class StatisticsServiceImpl implements StatisticsService {
monthlyWorkingHoursStatistic.setRejectCount(countByCondition); monthlyWorkingHoursStatistic.setRejectCount(countByCondition);
} }
objects.add(monthlyWorkingHoursStatistics); objects.add(monthlyWorkingHoursStatistics);
}
return objects; return objects;
} }
...@@ -237,18 +247,77 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -237,18 +247,77 @@ public class StatisticsServiceImpl implements StatisticsService {
startTime = DateUtil.convertDateToYMDStr(currentFirstDayOfMonth); startTime = DateUtil.convertDateToYMDStr(currentFirstDayOfMonth);
} }
WorkUser user = workUserService.getById(userId); WorkUser user = workUserService.getById(userId);
// 普通用户
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode())) { if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode())) {
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);
} }
//查询用户管理的项目 // 查询用户管理的项目
List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId); List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId);
if (CollectionUtil.isEmpty(userManageProjects)) { if (CollectionUtil.isEmpty(userManageProjects)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.MANAGER_NOT_PROJECT); throw new BaseCustomException(BASE_RESP_CODE_ENUM.MANAGER_NOT_PROJECT);
} }
//获取项目集合中所有项目的项目主键 // 获取项目集合中所有项目的项目主键
List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList()); List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList());
// 查询条件
Map<String, Object> map = new HashMap<>();
map.put("projectIds", projectIds);
// 起始时间为空时不以时间作为查询条件
if (StringUtil.isNotEmpty(startTime)) {
map.put("firstDayOfMonth", startTime);
}
// 工时类型包含:项目,商机
List<Integer> types = new ArrayList<>();
types.add(ProjectTypeEnum.PROJECT.getType());
types.add(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getType());
map.put("types", types);
// 查询项目和商机的工时统计
List<WorkTimeAndCostCollect> collect = workProjectTimeCostMapper.selectList(map);
// 部门和中心级别
if (!user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
// 请假、调休、外部商务、技术交流,内部培训、技术准备、管理,其他非项目/商机工作
types.clear();
map.clear();
for (ProjectTypeEnum value : ProjectTypeEnum.values()) {
// 查询条件排除项目和商机
if (!value.getTypeName().equals(ProjectTypeEnum.PROJECT.getTypeName()) && !value.getTypeName().equals(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName())) {
types.add(value.getType());
}
}
List<WorkTimeAndCostCollect> collect = workTimeOrderMapper.getWorkTimeAndCostCollect(projectIds, startTime); if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
map.put("deptId", user.getDeptId());
}
map.put("types", types);
List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
List<String> typeList = workTimeAndCostCollect.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,并且不为项目或商机类型,造对象传前端
for (ProjectTypeEnum value : ProjectTypeEnum.values()) {
if (!typeList.contains(value.getTypeName()) && !value.getTypeName().equals(ProjectTypeEnum.PROJECT.getTypeName()) && !value.getTypeName().equals(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName())){
WorkTimeAndCostCollect workTimeAndCostCollect1 = new WorkTimeAndCostCollect();
workTimeAndCostCollect1.setType(value.getTypeName());
workTimeAndCostCollect.add(workTimeAndCostCollect1);
}
}
collect.addAll(workTimeAndCostCollect);
}
for (WorkTimeAndCostCollect workTimeAndCostCollect : collect) {
// 类型的总工时
BigDecimal typeTotalTime = new BigDecimal("0.00");
List<DeptProjectWorkTimeAndCost> deptProjectWorkTimeAndCosts = workTimeAndCostCollect.getDeptProjectWorkTimeAndCosts();
if (CollectionUtil.isNotEmpty(deptProjectWorkTimeAndCosts)) {
for (DeptProjectWorkTimeAndCost deptProjectWorkTimeAndCost : deptProjectWorkTimeAndCosts) {
List<ProjectWorkTimeAndCostStatistics> projectWorkTimeAndCostStatistics = deptProjectWorkTimeAndCost.getProjectWorkTimeAndCostStatistics();
for (ProjectWorkTimeAndCostStatistics projectWorkTimeAndCostStatistic : projectWorkTimeAndCostStatistics) {
typeTotalTime.add(projectWorkTimeAndCostStatistic.getTotalTime());
}
}
}
workTimeAndCostCollect.setWorkTime(typeTotalTime);
}
return collect; return collect;
} }
...@@ -265,15 +334,30 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -265,15 +334,30 @@ public class StatisticsServiceImpl implements StatisticsService {
HSSFWorkbook sheets = new HSSFWorkbook(); HSSFWorkbook sheets = new HSSFWorkbook();
// 创建表 // 创建表
HSSFSheet sheet = sheets.createSheet("Sheet1"); HSSFSheet sheet = sheets.createSheet("Sheet1");
// 样式对象 // 节假日样式,底色为红色,其余样式与普通项目
HSSFCellStyle cellStyle1 = sheets.createCellStyle();
// cellStyle1.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
cellStyle1.setFillForegroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
// 设置全填充
cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 普通样式对象
HSSFCellStyle cellStyle = sheets.createCellStyle(); HSSFCellStyle cellStyle = sheets.createCellStyle();
// 垂直、水平中心对齐 // 垂直、水平中心对齐
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.CENTER); cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle1.setAlignment(HorizontalAlignment.CENTER);
// 自动换行 // 自动换行
cellStyle.setWrapText(true); cellStyle.setWrapText(true);
cellStyle1.setWrapText(true);
// 第一列列宽 // 第一列列宽
sheet.setColumnWidth(1, EXCEL_WIDTH); sheet.setColumnWidth(1, EXCEL_WIDTH);
// 获取本月应上班日期集合
List<Date> dates = this.currentMonthWorkDays(date);
List<Integer> days = new ArrayList<>();
for (Date date1 : dates) {
days.add(DateUtil.getDay(date1));
}
// 创建一行 // 创建一行
HSSFRow row1 = sheet.createRow(0); HSSFRow row1 = sheet.createRow(0);
// 给第一行赋值 // 给第一行赋值
...@@ -283,8 +367,13 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -283,8 +367,13 @@ public class StatisticsServiceImpl implements StatisticsService {
for (int i = 1; i <= dayCount; i++) { for (int i = 1; i <= dayCount; i++) {
HSSFCell cell = row1.createCell(2 + i); HSSFCell cell = row1.createCell(2 + i);
cell.setCellValue(i + "日"); cell.setCellValue(i + "日");
// 如果为节假日
if (!days.contains(i)) {
cell.setCellStyle(cellStyle1);
} else {
cell.setCellStyle(cellStyle); cell.setCellStyle(cellStyle);
} }
}
Iterator<StatisticsTableDto> iterator = list.iterator(); Iterator<StatisticsTableDto> iterator = list.iterator();
int i = 1; int i = 1;
while (iterator.hasNext()) { while (iterator.hasNext()) {
...@@ -341,25 +430,34 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -341,25 +430,34 @@ public class StatisticsServiceImpl implements StatisticsService {
return userProjectWorkTimeStatistics; return userProjectWorkTimeStatistics;
} }
//获取本月应上班日期 //获取一个月应上班日期,如果是当月,时间截至到当天
public List<Date> currentMonthWorkDays() { public List<Date> currentMonthWorkDays(Date date) {
log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method"); log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method");
//当前时间 // 时间为本月,起始时间为参数时间当月第一天,截至时间为当天。否则,截至时间为当月最后一天
Date startDate = DateUtil.getFirstDayOfMonth(date);
Date endDate = null;
// 当前时间
Date now = new Date(); Date now = new Date();
//本月第一天 if (DateUtil.getYear(date) == DateUtil.getYear(now) && DateUtil.getMonth(date) == DateUtil.getMonth(now)) {
Date firstDayOfMonth = DateUtil.getFirstDayOfMonth(now); endDate = now;
//本月第一天到当日的日期集合 } else {
List<Date> workDays = DateUtil.getDatesBetweenTwoDate(firstDayOfMonth, now); endDate = DateUtil.getLastDayOfMonth(date);
}
// 当月月第一天到截止时间的日期集合
List<Date> workDays = DateUtil.getDatesBetweenTwoDate(startDate, endDate);
//除去周末 //除去周末
Iterator<Date> iterator = workDays.iterator(); Iterator<Date> iterator = workDays.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
int week = DateUtil.getWeek(iterator.next()); Date next = iterator.next();
if (week == 6 || week == 7) { int week = DateUtil.getWeek(next);
// week为7是星期六,1是星期天
if (week == 7 || week == 1) {
iterator.remove(); iterator.remove();
} }
} }
//获取当月的节日和周末上班日期 //获取当月的节日和周末上班日期
List<WorkHoliday> specialDates = workHolidayMapper.getByDate(firstDayOfMonth, now); List<WorkHoliday> specialDates = workHolidayMapper.getByDate(startDate, endDate);
if (CollectionUtil.isEmpty(specialDates)) { if (CollectionUtil.isEmpty(specialDates)) {
return workDays; return workDays;
} }
......
...@@ -128,17 +128,16 @@ public class WorkProjectServiceImpl implements WorkProjectService { ...@@ -128,17 +128,16 @@ public class WorkProjectServiceImpl implements WorkProjectService {
} }
WorkUser user = workUserService.getById(userId); WorkUser user = workUserService.getById(userId);
//普通用户 //普通用户
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode())) { if (user.getLevel().equals(ManagerEnum.NOT_MANAGER)) {
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);
} }
//存放项目列表 //存放项目列表
List<WorkProject> workProjects; List<WorkProject> workProjects;
//存放查询条件 //存放查询条件
HashMap<String, Object> map = new HashMap<>(10); HashMap<String, Object> map = new HashMap<>();
//项目级别查询项目管理员为用户的项目
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) { // 查询项目表中管理为用户的项目集合,用户为项目经理,但level可能不为1
map.put("managerId", userId); map.put("managerId", userId);
}
//用户是部门级别,查询该部门下的所有项目 //用户是部门级别,查询该部门下的所有项目
if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) { if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
map.put("deptId", user.getDeptId()); map.put("deptId", user.getDeptId());
...@@ -150,7 +149,7 @@ public class WorkProjectServiceImpl implements WorkProjectService { ...@@ -150,7 +149,7 @@ public class WorkProjectServiceImpl implements WorkProjectService {
if (workCentre == null) { if (workCentre == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTRE_NOT_FOUND); throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTRE_NOT_FOUND);
} }
map.put("centreId", workCentre.getId()); map.put("centreId",workCentre.getId());
//获取中心下的部门信息 //获取中心下的部门信息
List<WorkDept> workDepts = workDeptMapper.getDeptByCondition(map); List<WorkDept> workDepts = workDeptMapper.getDeptByCondition(map);
if (CollectionUtils.isEmpty(workDepts)) { if (CollectionUtils.isEmpty(workDepts)) {
......
...@@ -42,6 +42,8 @@ public class StatisticsController extends BaseController { ...@@ -42,6 +42,8 @@ public class StatisticsController extends BaseController {
@Autowired @Autowired
WorkDeptService workDeptService; WorkDeptService workDeptService;
@ApiOperation(value = "获取部门员工一个月每天的工时", notes = "获取部门员工一个月每天的工时") @ApiOperation(value = "获取部门员工一个月每天的工时", notes = "获取部门员工一个月每天的工时")
@GetMapping("/getMonthlyCollect") @GetMapping("/getMonthlyCollect")
public PageInfo getMonthlyCollect(GetMonthlyCollectParam param) { public PageInfo getMonthlyCollect(GetMonthlyCollectParam param) {
...@@ -119,5 +121,4 @@ public class StatisticsController extends BaseController { ...@@ -119,5 +121,4 @@ public class StatisticsController extends BaseController {
return getResult(userWorkTimeStatisticsByProjects); return getResult(userWorkTimeStatisticsByProjects);
} }
} }
\ No newline at end of file
...@@ -30,7 +30,6 @@ public class Trigger implements SchedulingConfigurer { ...@@ -30,7 +30,6 @@ public class Trigger implements SchedulingConfigurer {
@Autowired @Autowired
private WorkTimeOrderMapper workTimeOrderMapper; private WorkTimeOrderMapper workTimeOrderMapper;
@Autowired @Autowired
private WorkCollectService workCollectService; private WorkCollectService workCollectService;
......
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