Commit 9c8edbed authored by nie'hong's avatar nie'hong

完善工时统计

parent 22767fad
......@@ -26,6 +26,7 @@
where (year(day_start) = year(#{startDay}) AND month(day_start) = month(#{startDay})) OR
(year(day_end) = year(#{endDay}) AND month(day_end) = month(#{endDay}))
</select>
<select id="getByTypeAndStartDate" resultType="cn.wisenergy.model.app.WorkHoliday">
SELECT <include refid="Base_Column_List"/>
FROM <include refid="table"/>
......
......@@ -32,6 +32,7 @@
<result property="projectId" column="project_id"/>
<result property="projectName" column="project_name"/>
<result property="deptName" column="dept_name"/>
<result property="userName" column="user_name"/>
<collection property="statisticsDateAndWorkTimes" ofType="cn.wisenergy.model.dto.ProjectStatisticsByMonth$StatisticsDateAndWorkTime">
<result property="date" column="date"/>
<result property="year" column="year"/>
......@@ -88,14 +89,11 @@
project_id,project_name,concat(min(statistics_start),'~' ,max(statistics_end)) AS statistics_time ,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>
<if test="projectIds != null">
project_id in
<foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
#{projectId}
</foreach>
<if test="managerId != null and deptId == null">
AND p.manager_id = #{managerId}
</if>
<if test="deptId != null">
AND p.dept_id = #{deptId}
<if test="deptId != null and managerId != null">
AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if>
<if test="centreId != null">
AND centre_id = #{centreId}
......@@ -110,12 +108,19 @@
<select id="selectListByMonth" resultMap="projectStatisticsByMonth">
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,'合计' AS dept_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year, sum(total_time) AS total_time, sum(cost) AS cost
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null || projectIds != null"> project_name,'合计' AS dept_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year, 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 ptc.dept_id = d.id
<where>
<if test="projectId != null ">
ptc.project_id = #{projectId}
</if>
<if test="projectIds != null ">
ptc.project_id in
<foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
#{projectId}
</foreach>
AND year(statistics_start) = #{year}
</if>
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
</if>
......
......@@ -26,7 +26,7 @@
<result property="userName" column="user_name"/>
<collection property="projectWorkTimeAndType" ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndType">
<result property="projectId" column="project_id"/>
<result property="projectType" column="project_type"/>
<result property="workTimeType" column="work_time_type"/>
<result property="projectName" column="project_name"/>
<result property="overTime" column="over_time"/>
<result property="normalTime" column="normal_time"/>
......@@ -256,25 +256,16 @@
</where>
</select>
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect">
SELECT t.type AS type, t.dept_id AS dept_id,dept_name,
t.project_id AS project_id ,IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月')
, concat(YEAR(work_day), '年')) AS statistics_time ,SUM(t.work_time)/8 AS
total_time, SUM(t.work_time * s.day_salary)/8 AS cost ,project_name
FROM work_time_order t LEFT JOIN work_project p ON t.project_id=p.id LEFT JOIN work_dept d ON t.dept_id=d.id
LEFT JOIN work_user_salary s ON s.user_id = t.user_id
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" >
SELECT t.type AS type, d.id AS dept_id,dept_name,
IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day), '年')) AS statistics_time ,SUM(t.work_time)/8 AS
total_time, SUM(t.work_time * s.day_salary)/8 AS cost
FROM work_time_order t join work_dept d on d.id = t.dept_id join work_user_salary s on s.user_id = t.user_id
WHERE status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day
<if test="projectIds != null">
AND (t.project_id IN
<foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
#{projectId}
</foreach>
OR t.project_id IS null)
</if>
<if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth}
</if>
<if test="deptId != null">
<if test="deptId != null">
AND t.dept_id = #{deptId}
</if>
AND t.type in
......@@ -284,9 +275,8 @@
<if test="centreId != null">
AND centre_id = #{centreId}
</if>
group by t.type,t.dept_id, dept_name, t.project_id,p.project_name, if(YEAR (work_day) =
YEAR(NOW()),',month(work_day)','')
order by t.dept_id,work_day
group by t.type,d.id, dept_name, if(YEAR (work_day) = YEAR(NOW()),',month(work_day)','')
order by d.id,work_day
</select>
<select id="getDaysByDateAndStatus" resultType="date">
......@@ -331,37 +321,18 @@
<select id="getUserProjectWorkTimeStatistics" resultMap="userWorkTimeStatisticsByProject">
SELECT
<if test="isAll">u.id AS user_id, u.`name` AS user_name,</if>
<if test="!isAll">'合计' AS user_name ,</if>
t.project_id AS project_id, t.type AS project_type, p.project_name AS
project_name,
IF(t.is_overtime = 0,
<if test="!isAll">0</if>
<if test="isAll">null</if>, sum(t.work_time)) AS over_time, IF(t.is_overtime=1,
<if test="!isAll">0</if>
<if test="isAll">null</if>, sum(t.work_time)) AS normal_time
from work_time_order t left join work_project p on t.project_id = p.id join work_user u on t.user_id = u.id
SELECT <if test="isAll"> u.id AS user_id, u.`name` AS user_name,</if> <if test="!isAll">'合计' AS user_name ,</if> t.project_id AS project_id, t.type AS work_time_type, p.project_name AS project_name,
IF(t.is_overtime = 0, <if test="!isAll">0</if> <if test="isAll">null</if>, sum(t.work_time)) AS over_time, IF(t.is_overtime=1, <if test="!isAll">0</if> <if test="isAll">null</if>, sum(t.work_time)) AS normal_time
from work_time_order t left join work_project p on t.project_id = p.id join work_user u on t.user_id = u.id
where
t.status in (2,5) AND
t.work_day &lt;= #{endDate}
AND t.dept_id = #{deptId}
<if test="startDate != null">
AND t.work_day >= #{startDate}
</if>
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
AND t.work_day >= #{startDate}
</if>
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId}
</if>
<if test="deptId != null and managerId != null">
AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if>
<if test="managerId != null and deptId == null">
AND p.manager_id = #{managerId}
</if>
GROUP BY <if test="isAll">u.id,u.`name`,</if>t.project_id,t.type,p.project_name, t.is_overtime
GROUP BY <if test="isAll"> u.id,u.`name`,</if> t.project_id,t.type,p.project_name, t.is_overtime
ORDER BY <if test="isAll">convert(u.`name` using gbk) asc</if> <if test="!isAll">field(t.type,1,2,5,6,7,3,4)</if> ,t.project_id
</select>
<select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
......@@ -376,15 +347,8 @@
</select>
<select id="selectListByType" resultMap="userWorkTimeStatisticsByProject">
SELECT
<if test="isAll">u.id AS user_id, u.`name` AS user_name,</if>
<if test="!isAll">'合计' AS user_name,</if>
t.type AS project_type,
IF(t.is_overtime = 0,
<if test="!isAll">0</if>
<if test="isAll">null</if>, sum(t.work_time)) AS over_time, IF(t.is_overtime=1,
<if test="!isAll">0</if>
<if test="isAll">null</if>, sum(t.work_time)) AS normal_time
SELECT <if test="isAll"> u.id AS user_id, u.`name` AS user_name,</if> <if test="!isAll"> '合计' AS user_name,</if> t.type AS work_time_type,
IF(t.is_overtime = 0, <if test="!isAll">0</if> <if test="isAll">null</if>, sum(t.work_time)) AS over_time, IF(t.is_overtime=1, <if test="!isAll">0</if> <if test="isAll">null</if>, sum(t.work_time)) AS normal_time
from work_time_order t JOIN work_user u ON t.user_id = u.id
where
t.work_day &lt;= #{endDate} AND t.status IN (2, 5)
......@@ -396,22 +360,21 @@
AND t.work_day >= #{startDate}
</if>
AND user_id in (
select user_id
from work_project p JOIN work_user_project up ON p.id = up.project_id
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId}
</if>
<if test="deptId != null and managerId != null">
AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if>
<if test="managerId != null and deptId == null">
AND p.manager_id = #{managerId}
</if>
select user_id
from work_project p JOIN work_user_project up ON p.id = up.project_id
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId}
</if>
<if test="deptId != null and managerId != null">
AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if>
<if test="managerId != null and deptId == null">
AND p.manager_id = #{managerId}
</if>
)
GROUP BY <if test="isAll">u.id,u.`name`,</if> t.type, t.is_overtime
</select>
</mapper>
......@@ -27,6 +27,9 @@ public class ProjectStatisticsByMonth implements Serializable {
@ApiModelProperty(name = "deptName", value = "部门名称")
private String deptName;
@ApiModelProperty(name = "userName", value = "用户姓名")
private String userName;
@ApiModelProperty(name = "statisticsDateAndWorkTime", value = "项目统计的时间段、工时和成本")
List<StatisticsDateAndWorkTime> statisticsDateAndWorkTimes;
......
......@@ -22,8 +22,8 @@ public class ProjectWorkTimeAndType{
/**
* 项目类型
*/
@ApiModelProperty(name = "projectType", value = "项目类型")
private Integer projectType;
@ApiModelProperty(name = "workTimeType", value = "项目类型")
private Integer workTimeType;
......@@ -39,4 +39,10 @@ public class ProjectWorkTimeAndType{
@ApiModelProperty(name = "normalTime", value = "正常工时")
private Integer normalTime;
/**
* 总工时:加班工时+正常工时
*/
@ApiModelProperty(name = "totalTime", value = "总工时")
private Integer totalTime;
}
\ No newline at end of file
......@@ -9,9 +9,6 @@ public enum LevelRankEnum {
PROJECT_LEVEL(1,"项目级"),
DEPARTMENT_LEVEL(2,"部门级"),
CENTRAL_LEVEL(3, "中心级"),
;
private Integer rank;
......
......@@ -53,7 +53,7 @@ public interface StatisticsService {
* @param isConclusion
* @return
*/
List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate, Integer isConclusion);
List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate);
/**
* 获取项目统计
......@@ -66,6 +66,25 @@ public interface StatisticsService {
*/
List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId);
/**
* 导出人员工时统计
* @param userId
* @param deptId
* @param startDate
* @param endDate
* @return
*/
HSSFWorkbook exportUserStatistics(Integer userId, Integer deptId, String startDate, String endDate);
/**
* 导出项目工时统计
* @param userId
* @param year
* @param projectIds
* @return
*/
HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, List<Integer> projectIds);
/**
* 获取某月需要填报的日期
* @param date
......
......@@ -11,7 +11,6 @@ import cn.wisenergy.model.app.*;
import cn.wisenergy.model.dto.*;
import cn.wisenergy.model.enums.*;
import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkProjectService;
import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.service.utils.UserRoleLevelUtils;
import com.alibaba.excel.util.StringUtils;
......@@ -22,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -50,9 +51,6 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private WorkUserDeptMapper workUserDeptMapper;
@Autowired
private WorkProjectService workProjectService;
@Autowired
private WorkHolidayMapper workHolidayMapper;
......@@ -71,13 +69,8 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private WorkDeptMapper workDeptMapper;
@Autowired
private WorkUserProjectMapper workUserProjectMapper;
private final static Integer EXCEL_WIDTH = 1000 * 6;
private final static Integer DEFAULT_DEPT_ID = 1;
@Override
public PageInfo getDayWorkTimeOfMonth(GetMonthlyCollectParam param) {
......@@ -85,9 +78,10 @@ public class StatisticsServiceImpl implements StatisticsService {
if (param == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
// 用户权限和对应级别
List<UserRoleLevelDto> roleUserLevel = UserRoleLevelUtils.getRoleUserLevel(param.getUserId());
// 用户权限名
List<String> userAuthority = this.getUserAuthority(param.getUserId());
List<String> userAuthority = this.getUserAuthority(roleUserLevel);
if (CollectionUtil.isEmpty(userAuthority) || !userAuthority.contains(LevelEnum.TIMEEXPORT.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
}
......@@ -99,10 +93,9 @@ public class StatisticsServiceImpl implements StatisticsService {
year = DateUtil.getYear(now);
month = DateUtil.getMonth(now) + 1;
}
//默认部门主键为1
Integer deptId = param.getDeptId();
if (param.getDeptId() == null) {
deptId = DEFAULT_DEPT_ID;
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
//默认当前页码为1,每页数量为10
if (param.getCurrentPage() == null) {
......@@ -145,13 +138,9 @@ public class StatisticsServiceImpl implements StatisticsService {
public Map<String, Object> getMonthlyStatistics(Integer userId) {
log.info("WorkTimeOrderServiceImpl[]getMonthlyStatistics[]input.param" + userId);
WorkUser user = workUserService.getById(userId);
// 用户权限
List<String> userAuthority = this.getUserAuthority(userId);
// 用户权限与权限对应级别
List<Integer> role = UserRoleLevelUtils.getRole(userId);
List<Integer> list = UserRoleLevelUtils.getlevelIds(role);
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(list);
List<UserRoleLevelDto> roleUserLevel = UserRoleLevelUtils.getRoleUserLevel(user.getId());
List<String> userAuthority = this.getUserAuthority(roleUserLevel);
// 本月第一天
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
// 返回数据对象
......@@ -189,9 +178,8 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("projectIdList", projectIdList);
notCompletedCount1 = workTimeOrderMapper.getCountByCondition(map);
}
// 用户在该权限对应的级别
List<Integer> rank = this.getUserRank(workLevels, LevelEnum.EXAMINE.getLevelName());
List<Integer> rank = this.getUserRank(roleUserLevel, LevelEnum.EXAMINE.getLevelName());
// 查询用户负责审批的除项目合商机的其余类型
Integer notCompletedCount2 = 0;
if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) {
......@@ -277,27 +265,25 @@ public class StatisticsServiceImpl implements StatisticsService {
if (userId == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
// 用户角色
List<Integer> role = UserRoleLevelUtils.getRole(userId);
// 用户权限
List<String> userAuthority = this.getUserAuthority(userId);
// 没有审批权限
if (CollectionUtil.isEmpty(userAuthority) || !userAuthority.contains(LevelEnum.EXAMINE.getLevelName())) {
// 用户对象
WorkUser user = workUserService.getById(userId);
// 用户权限和对应级别
List<UserRoleLevelDto> roleUserLevel = UserRoleLevelUtils.getRoleUserLevel(user.getId());
// 用户权限名
List<String> userAuthority = this.getUserAuthority(roleUserLevel);
// 按照人员统计报表权限验证
if (CollectionUtil.isEmpty(userAuthority) || !userAuthority.contains(LevelEnum.PROJECT_STATISTICS.getLevelName())) {
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<Integer> list = UserRoleLevelUtils.getlevelIds(role);
// 获取角色对应的权限
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(list);
// 用户该权限的级别
List<Integer> rank = this.getUserRank(workLevels, LevelEnum.EXAMINE.getLevelName());
List<Integer> rank = this.getUserRank(roleUserLevel, LevelEnum.PROJECT_STATISTICS.getLevelName());
// 获取所有的类型
List<WorkType> workTypes = workTypeMapper.getAll();
......@@ -311,13 +297,14 @@ public class StatisticsServiceImpl implements StatisticsService {
}
List<WorkTimeAndCostCollect> workTimeAndCostCollects = null;
// 中心级审批权限
Map<String, Object> map = new HashMap<>();
map.put("firstDayOfMonth", startTime);
// 中心级用户,
if (rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// 获取用户所在中心
WorkDept userDept = workDeptMapper.getById(user.getDeptId());
// 获取中心下的所有项目和商机工单统计
Map<String, Object> map = new HashMap<>();
map.put("firstDayOfMonth", startTime);
map.put("centreId", userDept.getCentreId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
......@@ -329,9 +316,8 @@ public class StatisticsServiceImpl implements StatisticsService {
} else if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) { // 如果用户的审批权限的级别最高为部门级别
// 获取部门下的所有项目和商机的工时统计
Map<String, Object> map = new HashMap<>();
map.put("deptId", user.getDeptId());
map.put("firstDayOfMonth", startTime);
map.put("managerId", user.getId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
// 除项目和项目的类型
......@@ -340,12 +326,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
workTimeAndCostCollects.addAll(workTimeAndCostCollect);
} else if (rank.contains(LevelRankEnum.PROJECT_LEVEL.getRank())) { // 如果用户的审批权限的级别最高为项目/商机级别,与其他两种级别不同的是只汇总项目和商机类型的工单
// 获取部门下的所有项目和商机的工时统计
Map<String, Object> map = new HashMap<>();
// 获取用户负责项目和商机id
List<Integer> projectIdByManager = workProjectMapper.getProjectIdByManager(userId);
map.put("projectIds", projectIdByManager);
map.put("firstDayOfMonth", startTime);
map.put("managerId", user.getId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
}
......@@ -524,28 +505,26 @@ public class StatisticsServiceImpl implements StatisticsService {
}
@Override
public List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate, Integer isConclusion) {
log.info("StatisticsServiceImpl[]getUserWorkTimeStatisticsReport[]" + userId + deptId + startDate + endDate + isConclusion);
List<Integer> role = UserRoleLevelUtils.getRole(userId);
// 判断是否有该权限
if (!UserRoleLevelUtils.isManagerLevel(userId, LevelEnum.USER_STATISTICS.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
public List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsServiceImpl[]getUserWorkTimeStatisticsReport[]" + userId + deptId + startDate + endDate);
// 获取用户信息
WorkUser user = workUserService.getById(userId);
// 获取用户权限级别
List<Integer> list = UserRoleLevelUtils.getlevelIds(role);
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(list);
// 获取用户权限级别
List<UserRoleLevelDto> workLevels = UserRoleLevelUtils.getRoleUserLevel(user.getId());
// 用户在该权限下的级别
List<Integer> rank = this.getUserRank(workLevels, LevelEnum.USER_STATISTICS.getLevelName());
// 获取用户的权限名
List<String> userAuthority = this.getUserAuthority(workLevels);
// 判断是否有该权限
if (!userAuthority.contains(LevelEnum.USER_STATISTICS.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
// 不是中心级不能选择部门
if (!rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank()) && deptId != null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
// 中心级权限默认查询部门
if (rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank()) && deptId == null) {
deptId = DEFAULT_DEPT_ID;
}
// 默认统计截至时间为当天
if (StringUtil.isEmpty(endDate)) {
......@@ -555,63 +534,40 @@ public class StatisticsServiceImpl implements StatisticsService {
// 查询条件
Map<String, Object> map = new HashMap<>();
map.put("isConclusion", isConclusion);
map.put("startDate", startDate);
map.put("endDate", endDate);
map.put("deptId", deptId);
// 存所有项目的加班工时和正常工时
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics;
// 存各个项目下所有人的加班工时和平常工时
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics1;
// 当前权限最高为中心级别权限
if (rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// 查询部门下所有项目,部门主键为空时是默认部门
map.put("deptId", deptId);
} else if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) {
// 查询部门下所有项目,部门主键是用户的部门主键,当前权限最高级别为部门级别
map.put("deptId", user.getDeptId());
map.put("managerId", user.getId());
} else {
// 项目/商机级别,以项目管理查询
map.put("managerId", user.getId());
}
// 查询项目
List<WorkProject> projects = workProjectMapper.getListByCriteria(map);
// 所有项目的统计
map.put("isAll", false);
userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map);
// 给返回前端的数据补全所有项目
if (CollectionUtil.isNotEmpty(projects)) {
// 如果查询所有项目的统计为空,给集合里添加个元素
if (CollectionUtil.isEmpty(userProjectWorkTimeStatistics)) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject = new UserWorkTimeStatisticsByProject();
userWorkTimeStatisticsByProject.setUserName("合计");
List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
userWorkTimeStatisticsByProject.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
userProjectWorkTimeStatistics.add(userWorkTimeStatisticsByProject);
}
// 补全项目
List<Integer> projectIds = userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().stream().map(ProjectWorkTimeAndType::getProjectId).collect(Collectors.toList());
for (WorkProject project : projects) {
if (!projectIds.contains(project.getId())) {
ProjectWorkTimeAndType projectWorkTimeAndType = new ProjectWorkTimeAndType();
projectWorkTimeAndType.setProjectName(project.getProjectName());
projectWorkTimeAndType.setProjectId(project.getId());
projectWorkTimeAndType.setProjectType(project.getType());
projectWorkTimeAndType.setNormalTime(0);
projectWorkTimeAndType.setOverTime(0);
userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().add(projectWorkTimeAndType);
}
}
}
// 所有项目下所有人员的统计
map.replace("isAll", true);
userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map);
// 合并两个查询结果
userProjectWorkTimeStatistics.addAll(0, userProjectWorkTimeStatistics1);
// 查询所有工单类型
List<WorkType> types = workTypeMapper.getAll();
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) {
// 获取单人的统计,包括合计,为了给除了项目和商机类型的统计将项目名称赋值为类型名称
List<ProjectWorkTimeAndType> projectWorkTimeAndType = userProjectWorkTimeStatistic.getProjectWorkTimeAndType();
for (ProjectWorkTimeAndType workTimeAndType : projectWorkTimeAndType) {
if (StringUtils.isEmpty(workTimeAndType.getProjectName())) {
workTimeAndType.setProjectName(types.get(workTimeAndType.getWorkTimeType() - 1).getName());
}
}
}
// 查询结果为空,新建一个“合计”对象添加到集合
if (CollectionUtils.isEmpty(userProjectWorkTimeStatistics)) {
List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
......@@ -621,81 +577,81 @@ public class StatisticsServiceImpl implements StatisticsService {
userProjectWorkTimeStatistics.add(userWorkTimeStatisticsByProject);
}
// 查询除开项目于、商机、请假、调休这几种类型的工单
List<WorkType> types = workTypeMapper.getAll();
List<Integer> queryType = new ArrayList<>();
for (WorkType type : types) {
if (type.getId() > 4) {
queryType.add(type.getId());
}
}
// 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单
if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank()) || rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// 获取其他类型统计信息
map.replace("isAll", false);
map.put("queryType", queryType);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(map);
// 获取查询结果的类型
List<Integer> collect = new ArrayList<>();
if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsByProjectList.get(0);
List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
projectWorkTimeAndType.setProjectName(types.get(projectWorkTimeAndType.getProjectType() - 1).getName());
}
collect = projectWorkTimeAndType1.stream().map(ProjectWorkTimeAndType::getProjectType).collect(Collectors.toList());
}
// 缺少类型,造对象传前端
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = new UserWorkTimeStatisticsByProject();
List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
for (int i = 4; i < types.size(); i++) {
if (!collect.contains(types.get(i).getId())) {
ProjectWorkTimeAndType projectWorkTimeAndType = new ProjectWorkTimeAndType();
projectWorkTimeAndType.setNormalTime(0);
projectWorkTimeAndType.setOverTime(0);
projectWorkTimeAndType.setProjectType(types.get(i).getId());
projectWorkTimeAndType.setProjectName(types.get(i).getName());
projectWorkTimeAndTypes.add(projectWorkTimeAndType);
}
}
userWorkTimeStatisticsByProject1.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
userWorkTimeStatisticsByProjectList.add(userWorkTimeStatisticsByProject1);
// 将项目和商机统计信息和除开项目、商机、请假、调休类型的其他类型统计信息合并
userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType());
// 查询各个项目下所有人的其他除了项目、商机、请假、调休类型的加班工时和平常工时
map.replace("isAll", true);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = workTimeOrderMapper.selectListByType(map);
for (UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject : userWorkTimeStatisticsByProjects) {
if (!userProjectWorkTimeStatistics1.contains(userWorkTimeStatisticsByProject)) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject2 = new UserWorkTimeStatisticsByProject();
userWorkTimeStatisticsByProject2.setUserName(userWorkTimeStatisticsByProject.getUserName());
userWorkTimeStatisticsByProject2.setUserId(userWorkTimeStatisticsByProject.getUserId());
List<ProjectWorkTimeAndType> projectWorkTimeAndTypes1 = new ArrayList<>();
userWorkTimeStatisticsByProject2.setProjectWorkTimeAndType(projectWorkTimeAndTypes1);
userProjectWorkTimeStatistics1.add(userWorkTimeStatisticsByProject2);
}
for (UserWorkTimeStatisticsByProject workTimeStatisticsByProject : userProjectWorkTimeStatistics1) {
if (userWorkTimeStatisticsByProject.getUserId() != null && userWorkTimeStatisticsByProject.getUserId().equals(workTimeStatisticsByProject.getUserId())) {
workTimeStatisticsByProject.getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProject.getProjectWorkTimeAndType());
}
}
}
// 赋值类型名称
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userWorkTimeStatisticsByProjects) {
List<ProjectWorkTimeAndType> projectWorkTimeAndType = userProjectWorkTimeStatistic.getProjectWorkTimeAndType();
for (ProjectWorkTimeAndType workTimeAndType : projectWorkTimeAndType) {
workTimeAndType.setProjectName(types.get(workTimeAndType.getProjectType() - 1).getName());
}
}
}
userProjectWorkTimeStatistics.addAll(0, userProjectWorkTimeStatistics1);
// // 查询除开项目于、商机、请假、调休这几种类型的工单
//
// List<Integer> queryType = new ArrayList<>();
// for (WorkType type : types) {
// if (type.getId() > 4) {
// queryType.add(type.getId());
// }
// }
//
// // 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单
// if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank()) || rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// // 获取其他类型统计信息
// map.replace("isAll", false);
// map.put("queryType", queryType);
// List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(map);
// log.info(new Date().getTime() + "");
// // 获取查询结果的类型
// List<Integer> collect = new ArrayList<>();
// if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) {
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsByProjectList.get(0);
// List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
// for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
// projectWorkTimeAndType.setProjectName(types.get(projectWorkTimeAndType.getProjectType() - 1).getName());
// }
// collect = projectWorkTimeAndType1.stream().map(ProjectWorkTimeAndType::getProjectType).collect(Collectors.toList());
// }
//
// // 缺少类型,造对象传前端
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = new UserWorkTimeStatisticsByProject();
// List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
// for (int i = 4; i < types.size(); i++) {
// if (!collect.contains(types.get(i).getId())) {
// ProjectWorkTimeAndType projectWorkTimeAndType = new ProjectWorkTimeAndType();
// projectWorkTimeAndType.setNormalTime(0);
// projectWorkTimeAndType.setOverTime(0);
// projectWorkTimeAndType.setProjectType(types.get(i).getId());
// projectWorkTimeAndType.setProjectName(types.get(i).getName());
// projectWorkTimeAndTypes.add(projectWorkTimeAndType);
// }
// }
// userWorkTimeStatisticsByProject1.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
// userWorkTimeStatisticsByProjectList.add(userWorkTimeStatisticsByProject1);
//
// // 将项目和商机统计信息和除开项目、商机、请假、调休类型的其他类型统计信息合并
// userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType());
//
// // 查询各个项目下所有人的其他除了项目、商机、请假、调休类型的加班工时和平常工时
// map.replace("isAll", true);
// List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = workTimeOrderMapper.selectListByType(map);
// log.info(new Date().getTime() + "");
// for (UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject : userWorkTimeStatisticsByProjects) {
// if (!userProjectWorkTimeStatistics1.contains(userWorkTimeStatisticsByProject)) {
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject2 = new UserWorkTimeStatisticsByProject();
// userWorkTimeStatisticsByProject2.setUserName(userWorkTimeStatisticsByProject.getUserName());
// userWorkTimeStatisticsByProject2.setUserId(userWorkTimeStatisticsByProject.getUserId());
// List<ProjectWorkTimeAndType> projectWorkTimeAndTypes1 = new ArrayList<>();
// userWorkTimeStatisticsByProject2.setProjectWorkTimeAndType(projectWorkTimeAndTypes1);
// userProjectWorkTimeStatistics1.add(userWorkTimeStatisticsByProject2);
// }
// for (UserWorkTimeStatisticsByProject workTimeStatisticsByProject : userProjectWorkTimeStatistics1) {
// if (userWorkTimeStatisticsByProject.getUserId() != null && userWorkTimeStatisticsByProject.getUserId().equals(workTimeStatisticsByProject.getUserId())) {
// workTimeStatisticsByProject.getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProject.getProjectWorkTimeAndType());
// }
// }
// }
// // 赋值类型名称
// for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userWorkTimeStatisticsByProjects) {
// List<ProjectWorkTimeAndType> projectWorkTimeAndType = userProjectWorkTimeStatistic.getProjectWorkTimeAndType();
// for (ProjectWorkTimeAndType workTimeAndType : projectWorkTimeAndType) {
// workTimeAndType.setProjectName(types.get(workTimeAndType.getProjectType() - 1).getName());
// }
// }
// }
//
// userProjectWorkTimeStatistics.addAll(0, userProjectWorkTimeStatistics1);
// 取出单人的项目工时统计
......@@ -711,10 +667,24 @@ public class StatisticsServiceImpl implements StatisticsService {
String projectName1 = projectWorkTimeAndType3.getProjectName();
if (projectName.equals(projectName1)) {
projectWorkTimeAndType1.get(i - 1).setOverTime(projectWorkTimeAndType2.getOverTime());
Integer overTime = 0;
Integer normalTime = 0;
if (projectWorkTimeAndType2.getOverTime() != null) {
overTime += projectWorkTimeAndType2.getOverTime();
}
if (projectWorkTimeAndType3.getOverTime() != null) {
overTime += projectWorkTimeAndType3.getOverTime();
}
if (projectWorkTimeAndType2.getNormalTime() != null) {
normalTime += projectWorkTimeAndType2.getNormalTime();
}
if (projectWorkTimeAndType3.getNormalTime() != null) {
normalTime += projectWorkTimeAndType3.getNormalTime();
}
projectWorkTimeAndType1.get(i - 1).setOverTime(overTime);
projectWorkTimeAndType1.get(i - 1).setNormalTime(normalTime);
projectWorkTimeAndType1.remove(i);
}
}
for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
if (projectWorkTimeAndType.getNormalTime() != null) {
......@@ -727,6 +697,11 @@ public class StatisticsServiceImpl implements StatisticsService {
userProjectWorkTimeStatistic.setTotalTime(totalTime);
}
// 计算合计中的每个项目的正常工时加上加班工时的和
List<ProjectWorkTimeAndType> userProjectWorkTimeStatisticsCollect = userProjectWorkTimeStatistics.get(userProjectWorkTimeStatistics.size() - 1).getProjectWorkTimeAndType();
for (ProjectWorkTimeAndType projectWorkTimeAndType : userProjectWorkTimeStatisticsCollect) {
projectWorkTimeAndType.setTotalTime(projectWorkTimeAndType.getNormalTime() + projectWorkTimeAndType.getOverTime());
}
return userProjectWorkTimeStatistics;
}
......@@ -739,15 +714,8 @@ public class StatisticsServiceImpl implements StatisticsService {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
// 获取在改权限下用户对应的级别
List<Integer> role = UserRoleLevelUtils.getRole(userId);
List<Integer> list = UserRoleLevelUtils.getlevelIds(role);
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(list);
List<Integer> rank = this.getUserRank(workLevels, LevelEnum.PROJECT_STATISTICS.getLevelName());
// // 非中心级不能选择部门
// if (!rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank()) && deptId != null) {
// throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
// }
List<UserRoleLevelDto> roleUserLevel = UserRoleLevelUtils.getRoleUserLevel(userId);
List<Integer> rank = this.getUserRank(roleUserLevel, LevelEnum.PROJECT_STATISTICS.getLevelName());
// 默认查询时间为当前
if (year == null) {
......@@ -755,7 +723,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 部门主键和项目主键不能同时为空
if (deptId == null && projectId == null) {
deptId = DEFAULT_DEPT_ID;
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
Map<String, Object> map = new HashMap<>();
......@@ -791,7 +759,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map);
// 将在查询时间端内未存在填报信息的项目补齐
if (projectId == null) {
if (projectId == null) {
// 查询项目
List<WorkProject> projects = workProjectMapper.getListByCriteria(map);
// 查询统计结果中的项目主键
......@@ -811,8 +779,8 @@ public class StatisticsServiceImpl implements StatisticsService {
// 将查询结果封装在一起
projectStatisticsByMonths.addAll(0, projectStatisticsByMonths1);
String startDate = new String();
String endDate = new String();
String startDate = "";
String endDate = "";
if (projectId != null) {
// 整个项目所占时间,未结项目截止时间为当月,已结项目截止时间为最后一次统计的时间
startDate = projectStatisticsByMonths.get(0).getStatisticsDateAndWorkTimes().get(0).getDate();
......@@ -821,12 +789,9 @@ public class StatisticsServiceImpl implements StatisticsService {
if (year < DateUtil.getYear(new Date())) {
startDate = year + "年1月";
endDate = year + "年12月";
}else if (year == DateUtil.getYear(new Date())){
} else if (year == DateUtil.getYear(new Date())) {
startDate = DateUtil.convertDateToStr(DateUtil.getFirstDayOfYear(new Date()), "yyyy年M月");
endDate = DateUtil.convertDateToStr(new Date(), "yyyy年M月");
}else {
startDate = "";
endDate = "";
}
}
// 项目的周期年月集合
......@@ -857,6 +822,231 @@ public class StatisticsServiceImpl implements StatisticsService {
return projectStatisticsByMonths;
}
@Override
public HSSFWorkbook exportUserStatistics(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsServiceImpl[]exportUserStatistics[]param{}" + userId + deptId + startDate + endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsReport = this.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
// 部门信息
WorkDept dept = workDeptMapper.getById(deptId);
String statisticsStart = this.simpleDateToYearMonthDay(startDate);
String statisticsEnd = this.simpleDateToYearMonthDay(endDate);
// 创建工作簿
HSSFWorkbook sheets = new HSSFWorkbook();
HSSFSheet sheet1 = sheets.createSheet("sheet1");
// 第0行,存部门名称和时间
HSSFRow row0 = sheet1.createRow(0);
HSSFCell row0Cell0 = row0.createCell(0);
row0Cell0.setCellValue("部门:" + dept.getDeptName() + " 时间:" + statisticsStart + "-" + statisticsEnd);
// 获取合计,写入项目名称和正常工时加班工时表头,除开请假和调休,这两种类型没有正常和加班之分
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject = userWorkTimeStatisticsReport.get(userWorkTimeStatisticsReport.size() - 1);
List<ProjectWorkTimeAndType> projectWorkTimeAndType = userWorkTimeStatisticsByProject.getProjectWorkTimeAndType();
// 第1行,序号和人员的表头
HSSFRow row_1 = sheet1.createRow(1);
HSSFCell row_1Cell1 = row_1.createCell(0);
row_1Cell1.setCellValue("序号");
HSSFCell row_1Cell2 = row_1.createCell(1);
row_1Cell2.setCellValue("人员");
// 合计行
HSSFRow totalRow1 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 2);
totalRow1.createCell(0).setCellValue("合计");
// 总计
HSSFRow totalRow2 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 3);
totalRow2.createCell(0).setCellValue("总计");
// 项目行
HSSFRow row_2 = sheet1.createRow(2);
for (int i = 0; i < projectWorkTimeAndType.size(); i++) {
// 项目名称
HSSFCell row_1Cell;
HSSFCell totalRow2Cell;
if (i < projectWorkTimeAndType.size() - 2) {
// 项目名称或类型名称
row_1Cell = row_1.createCell((i + 1) * 2);
totalRow2Cell = totalRow2.createCell((i + 1) * 2);
// 正常工时
HSSFCell row2Cell = row_2.createCell((i + 1) * 2);
row2Cell.setCellValue("正常工时");
HSSFCell cell1 = totalRow1.createCell((i + 1) * 2);
cell1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
// 加班工时
HSSFCell row2Cell1 = row_2.createCell((i + 1) * 2 + 1);
row2Cell1.setCellValue("加班工时");
HSSFCell cell2 = totalRow1.createCell((i + 1) * 2 + 1);
cell2.setCellValue(projectWorkTimeAndType.get(i).getOverTime());
} else {
// 调休和请假没有加班工时和正常工时之分
row_1Cell = row_1.createCell((i + 1) * 2);
row_1Cell.setCellValue(projectWorkTimeAndType.get(i).getProjectName());
// 请假合计
HSSFCell cell1 = totalRow1.createCell((i + 1) * 2);
cell1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
// 请假总计
HSSFCell cell3 = totalRow2.createCell((i + 1) * 2);
cell3.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
i++;
row_1Cell = row_1.createCell((i + 1) * 2 - 1);
row_1Cell.setCellValue(projectWorkTimeAndType.get(i).getProjectName());
// 调休合计
HSSFCell cell2 = totalRow1.createCell((i + 1) * 2 - 1);
cell2.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
// 调休总计
HSSFCell cell4 = totalRow2.createCell((i + 1) * 2 - 1);
cell4.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
// 合计行的合计
HSSFCell cell5 = totalRow1.createCell((i + 1) * 2);
cell5.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
// 总计行的合计
HSSFCell cell6 = totalRow2.createCell((i + 1) * 2);
cell6.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
break;
}
row_1Cell.setCellValue(projectWorkTimeAndType.get(i).getProjectName());
totalRow2Cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
}
// 所有项目的合计
short row1_lastCellNum = row_1.getLastCellNum();
row_1.createCell(row1_lastCellNum).setCellValue("合计");
for (int i = 0; i < userWorkTimeStatisticsReport.size() - 1; i++) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsReport.get(i);
List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
HSSFRow row_i = sheet1.createRow(i + 3);
// 第一列:序号
HSSFCell cell_0 = row_i.createCell(0);
cell_0.setCellValue(i + 1);
// 第二列:姓名
HSSFCell cell_1 = row_i.createCell(1);
cell_1.setCellValue(userWorkTimeStatisticsByProject1.getUserName());
// 项目的工时
for (int j = 0; j < projectWorkTimeAndType1.size(); j++) {
for (int k = 2; k < row1_lastCellNum; k++) {
if (row_1.getCell(k) != null && k < row1_lastCellNum - 2 && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) {
if (projectWorkTimeAndType1.get(j).getNormalTime() != null) {
HSSFCell cell_k_1 = row_i.createCell(k);
cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime());
}
if (projectWorkTimeAndType1.get(j).getOverTime() != null) {
HSSFCell cell_k_2 = row_i.createCell(k + 1);
cell_k_2.setCellValue(projectWorkTimeAndType1.get(j).getOverTime());
}
break;
}
if (row_1.getCell(k) != null && k >= row1_lastCellNum - 2 && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) {
if (projectWorkTimeAndType1.get(j).getNormalTime() != null) {
HSSFCell cell_k_1 = row_i.createCell(k);
cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime());
}
}
}
}
// 个人合计
row_i.createCell(row1_lastCellNum).setCellValue(userWorkTimeStatisticsByProject1.getTotalTime());
}
// 合计行
// int lastRowNum = sheet1.getLastRowNum();
// HSSFRow lastRow = sheet1.createRow(lastRowNum + 1);
// lastRow.createCell(0).setCellValue("合计");
// // 总计行
// HSSFRow row = sheet1.createRow(lastRowNum + 2);
// row.createCell(0).setCellValue("总计");
// for (int i = 0; i < projectWorkTimeAndType.size(); i++) {
// // 合计行的正常工时和加班工时
// if (i < projectWorkTimeAndType.size() - 2) {
// HSSFCell cell_i_2 = lastRow.createCell((i + 1) * 2 + 1);
// cell_i_2.setCellValue(projectWorkTimeAndType.get(i).getOverTime());
//
// HSSFCell cell_i_1 = lastRow.createCell((i + 1) * 2);
// cell_i_1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
//
// // 总计行一个项目的总工时
// HSSFCell cell = row.createCell((i + 1) * 2);
// cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
// } else {
// // 合计行的请假调休
// HSSFCell cell_i_1 = lastRow.createCell((i + 1) * 2 - 1);
// cell_i_1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
//
// // 总计行请假调休的总工时
// HSSFCell cell = row.createCell((i + 1) * 2 - 1);
// cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
// }
//
// }
// // 合计行的最后一列是所有项目的合计
// short lastRowLastCellNum = lastRow.getLastCellNum();
// // 合计行和总计行的最后一列
// HSSFCell lastRowLastCell = lastRow.createCell(lastRowLastCellNum);
// HSSFCell cell = row.createCell(lastRowLastCellNum);
// // 合计行和总计行的合计都是所有项目的合计工时
// lastRowLastCell.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
// cell.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
// 合并单元格,第一行
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, row1_lastCellNum + 1);
sheet1.addMergedRegion(cellRangeAddress);
setBorderStyle(BorderStyle.THIN, cellRangeAddress, sheet1);
// 序号
CellRangeAddress cellRangeAddress1 = new CellRangeAddress(1, 2, 0, 0);
sheet1.addMergedRegion(cellRangeAddress1);
setBorderStyle(BorderStyle.THIN, cellRangeAddress1, sheet1);
// 人员
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(1, 2, 1, 1);
sheet1.addMergedRegion(cellRangeAddress2);
setBorderStyle(BorderStyle.THIN, cellRangeAddress2, sheet1);
// 合计行
CellRangeAddress cellRangeAddress3 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 2, userWorkTimeStatisticsReport.size() + 2, 0, 1);
sheet1.addMergedRegion(cellRangeAddress3);
setBorderStyle(BorderStyle.THIN, cellRangeAddress3, sheet1);
// 项目行和总计行
for (int i = 0; i < row1_lastCellNum / 2 - 1; i++) {
// 总计行
CellRangeAddress cellRangeAddress4 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 3, userWorkTimeStatisticsReport.size() + 3, i * 2, i * 2 + 1);
sheet1.addMergedRegion(cellRangeAddress4);
setBorderStyle(BorderStyle.THIN, cellRangeAddress4, sheet1);
if (i > 0) {
CellRangeAddress cellRangeAddress5 = new CellRangeAddress(1, 1, i * 2, i * 2 + 1);
sheet1.addMergedRegion(cellRangeAddress5);
setBorderStyle(BorderStyle.THIN, cellRangeAddress5, sheet1);
}
}
// 样式
HSSFCellStyle ordinaryCellStyle = this.createOrdinaryCellStyle(sheets);
// 第一行的样式,水平左对齐
HSSFCellStyle ordinaryCellStyle1 = this.createOrdinaryCellStyle(sheets);
ordinaryCellStyle1.setAlignment(HorizontalAlignment.LEFT);
for (Row cells : sheet1) {
for (Cell cell : cells) {
cell.setCellStyle(ordinaryCellStyle);
}
}
sheet1.getRow(0).getCell(0).setCellStyle(ordinaryCellStyle1);
return sheets;
}
@Override
public HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, List<Integer> projectIds) {
log.info("StatisticsServiceImpl[]exportProjectStatistics[]param{}" + userId + year + projectIds);
Map<String, Object> map = new HashMap<>();
map.put("year", year);
map.put("projectIds", projectIds);
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map);
return null;
}
//获取一个月应上班日期,如果是当月,时间截至到当天
public List<Date> currentMonthWorkDays(Date date, boolean toToday) {
log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method");
......@@ -927,19 +1117,18 @@ public class StatisticsServiceImpl implements StatisticsService {
// 垂直、水平中心对齐
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//设置下边框的边框线颜色(颜色和上述的颜色对照表是一样的)
//设置下边框的边框线颜色
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBottomBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
//左边框
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setLeftBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setLeftBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
//上边框
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setRightBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setRightBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
//右边框
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setTopBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
// 自动换行
cellStyle.setWrapText(true);
return cellStyle;
......@@ -966,7 +1155,7 @@ public class StatisticsServiceImpl implements StatisticsService {
statisticsDateAndWorkTime.setDate(s);
statisticsDateAndWorkTime.setTotalTime(new BigDecimal("0"));
statisticsDateAndWorkTime.setCost(new BigDecimal("0"));
statisticsDateAndWorkTime.setYear(Integer.valueOf(s.substring(0,4)));
statisticsDateAndWorkTime.setYear(Integer.valueOf(s.substring(0, 4)));
statisticsDateAndWorkTimes.add(i, statisticsDateAndWorkTime);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy年M月");
......@@ -992,26 +1181,23 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取用户权限
public List<String> getUserAuthority(Integer userId) {
// 获取用户角色
List<Integer> role = UserRoleLevelUtils.getRole(userId);
// 获取角色对应权限id
List<Integer> list = UserRoleLevelUtils.getlevelIds(role);
// 获取权限对象
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(list);
if (CollectionUtil.isEmpty(workLevels)) {
return null;
public List<String> getUserAuthority(List<UserRoleLevelDto> roleUserLevel) {
if (CollectionUtil.isEmpty(roleUserLevel)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
// 获取权限名
List<String> collect = workLevels.stream().map(WorkLevel::getName).collect(Collectors.toList());
List<String> collect = roleUserLevel.stream().map(UserRoleLevelDto::getLevelName).collect(Collectors.toList());
return collect;
}
// 获取用户当前权限对应的级别
public List<Integer> getUserRank(List<WorkLevel> workLevels, String levelName) {
public List<Integer> getUserRank(List<UserRoleLevelDto> workLevels, String levelName) {
List<Integer> rank = new ArrayList<>();
for (WorkLevel workLevel : workLevels) {
if (workLevel.getName().equals(levelName)) {
if (CollectionUtil.isEmpty(workLevels)) {
return rank;
}
for (UserRoleLevelDto workLevel : workLevels) {
if (workLevel.getLevelName().equals(levelName)) {
rank.add(workLevel.getRank());
}
}
......@@ -1037,5 +1223,19 @@ public class StatisticsServiceImpl implements StatisticsService {
return list;
}
public String simpleDateToYearMonthDay(String simple) {
String date1 = simple.replaceFirst("-", "年");
String date2 = date1.replaceFirst("-", "月");
String date3 = date2 + "日";
return date3;
}
//合并单元格后添加边框
public static void setBorderStyle(BorderStyle borderStyle, CellRangeAddress region, HSSFSheet sheet) {
RegionUtil.setBorderBottom(borderStyle, region, sheet); //下边框
RegionUtil.setBorderLeft(borderStyle, region, sheet); //左边框
RegionUtil.setBorderRight(borderStyle, region, sheet); //右边框
RegionUtil.setBorderTop(borderStyle, region, sheet); //上边框
}
}
......@@ -12,9 +12,7 @@ import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -87,7 +85,7 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "导出部门员工一个月每天的工时", notes = "导出部门员工一个月每天的工时")
@GetMapping("/exportWorkTime")
public void export(GetMonthlyCollectParam param, HttpServletResponse response) {
log.info("StatisticsController[]getDeptInfo[]input.param" + param);
log.info("StatisticsController[]export[]input.param" + param);
// 获取excel
HSSFWorkbook sheets = statisticsService.exportWorkTimeExcel(param);
......@@ -115,9 +113,9 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表")
@GetMapping("/getUserWorkTimeStatisticsReport")
public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate, Integer isConclusion) {
log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate, isConclusion);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId,deptId, startDate, endDate, isConclusion);
public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
return getResult(userWorkTimeStatisticsByProjects);
}
......@@ -129,4 +127,63 @@ public class StatisticsController extends BaseController {
return getResult(projectStatisticsByMonths);
}
}
\ No newline at end of file
@ApiOperation(value = "导出人员工时统计", notes = "导出人员工时统计")
@GetMapping("/exportUserStatistics")
public void exportUserStatistics(Integer userId, Integer deptId, String startDate, String endDate,HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + deptId + startDate + endDate);
// 获取excel
HSSFWorkbook sheets = statisticsService.exportUserStatistics(userId, deptId, startDate, endDate);
// 获取excel中的第2行第2列中的部门名称
// String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
// String fileName = deptName + "-" + param.getYear() + "年" + param.getMonth() + "月工时汇总";
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
String fileName = "导出人员工时统计";
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
fileName + ".xls",
"utf-8"));
response.setHeader("Cache-Control", "No-cache");
response.flushBuffer();
sheets.write(response.getOutputStream());
sheets.close();
} catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
}
@ApiOperation(value = "导出项目工时统计", notes = "导出项目工时统计")
// @ApiImplicitParams({@ApiImplicitParam(name = "userId",value = "用户主键"),
// @ApiImplicitParam(name = "projectIds",value = "项目主键集合",allowMultiple = true)})
@GetMapping("/exportProjectStatistics")
public void exportProjectStatistics(Integer userId, Integer year, @ApiParam("projectIds") List<Integer> projectIds, HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds);
// 获取excel
HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds);
// 获取excel中的第2行第2列中的部门名称
// String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
// String fileName = deptName + "-" + param.getYear() + "年" + param.getMonth() + "月工时汇总";
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
String fileName = "导出人员工时统计";
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
fileName + ".xls",
"utf-8"));
response.setHeader("Cache-Control", "No-cache");
response.flushBuffer();
sheets.write(response.getOutputStream());
sheets.close();
} catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
}
}
\ No newline at end of file
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