Commit 62e6978e authored by nie'hong's avatar nie'hong

完善项目统计报表

parent 635761ec
......@@ -2,7 +2,6 @@ package cn.wisenergy.mapper;
import cn.wisenergy.model.dto.ProjectStatisticsByMonth;
import cn.wisenergy.model.dto.WorkTimeAndCostCollect;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
......@@ -27,21 +26,16 @@ public interface WorkProjectTimeCostMapper {
/**
* 部门编号不为空,查询部门下所有项目统计。部门主键为空时,查询项目主键参数为主键的项目信息
* @param year
* @param deptId
* @param projectId
* @return
*/
List<ProjectStatisticsByMonth> selectListByMonth(@Param("year") Integer year,@Param("deptId") Integer deptId,@Param("projectId") Integer projectId);
List<ProjectStatisticsByMonth> selectListByMonth(Map<String,Object> map);
/**
* 部门编号不为空,查询部门下所有项目所有人员统计。部门主键为空时,查询项目下的所有人员的统计
* @param year
* @param deptId
* @param projectId
* @param map
* @return
*/
List<ProjectStatisticsByMonth> selectListStatistics(@Param("year") Integer year,@Param("deptId") Integer deptId,@Param("projectId") Integer projectId);
List<ProjectStatisticsByMonth> selectListStatistics(Map<String,Object> map);
/**
......
......@@ -94,9 +94,8 @@
</foreach>
</if>
<if test="deptId != null">
AND ptc.dept_id = #{deptId}
AND p.dept_id = #{deptId}
</if>
<if test="centreId != null">
AND centre_id = #{centreId}
</if>
......@@ -110,15 +109,21 @@
<select id="selectListByMonth" resultMap="projectStatisticsByMonth">
select <if test="deptId != null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date, sum(total_time) AS total_time, sum(cost) AS cost
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date, 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="deptId != null">
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
</if>
<if test="deptId != null and managerId == null">
AND (p.dept_id = #{deptId} OR p.manager_id= #{managerId}) AND year(statistics_start) = #{year}
</if>
<if test="deptId == null and managerId != null">
AND p.manager_id = #{managerId} AND year(statistics_start) = #{year}
</if>
</where>
group by <if test="projectId != null"> project_name,</if> year(statistics_start),MONTH(statistics_start)
</select>
......@@ -129,12 +134,18 @@
sum(total_time) AS total_time, sum(cost) AS cost <if test="projectId != null "> ,d.dept_name AS dept_name</if>
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="deptId != null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
</if>
<if test="projectId != null ">
ptc.project_id = #{projectId}
</if>
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
</if>
<if test="deptId != null and managerId == null">
AND (p.dept_id = #{deptId} OR p.manager_id= #{managerId}) AND year(statistics_start) = #{year}
</if>
<if test="deptId == null and managerId != null">
AND p.manager_id = #{managerId} AND year(statistics_start) = #{year}
</if>
</where>
group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null "> ,d.dept_name</if>
</select>
......
......@@ -312,7 +312,8 @@
<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, 0, sum(t.work_time)) AS over_time, if(t.is_overtime=1, 0, 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.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
where
t.status in (2,5) AND
......@@ -323,11 +324,13 @@
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<if test="deptId != null">
<if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId}
</if>
<if test="managerId != null">
<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>
......
......@@ -42,11 +42,17 @@
select distinct user_id
from work_user_project up join work_project p on up.project_id = p.id
<where>
<if test="deptId != null">
p.dept_id = #{deptId}
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<if test="managerId != null">
p.manager_id = #{managerId}
<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>
</where>
</select>
......
......@@ -559,6 +559,7 @@ public class StatisticsServiceImpl implements StatisticsService {
} else if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) {
// 查询部门下所有项目,部门主键是用户的部门主键,当前权限最高级别为部门级别
map.put("deptId", user.getDeptId());
map.put("managerId", user.getId());
} else {
// 项目/商机级别,以项目管理查询
map.put("managerId", user.getId());
......@@ -572,7 +573,6 @@ public class StatisticsServiceImpl implements StatisticsService {
map.replace("isAll", true);
userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map);
// 查询结果为空,新建一个“合计”对象添加到集合
if (CollectionUtils.isEmpty(userProjectWorkTimeStatistics)) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject = new UserWorkTimeStatisticsByProject();
......@@ -635,7 +635,6 @@ public class StatisticsServiceImpl implements StatisticsService {
}
userProjectWorkTimeStatistics.addAll(0, userProjectWorkTimeStatistics1);
// 取出单人的项目工时统计
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) {
int totalTime = 0;
......@@ -650,10 +649,24 @@ public class StatisticsServiceImpl implements StatisticsService {
projectWorkTimeAndType1.get(i - 1).setOvertime(projectWorkTimeAndType2.getOvertime());
projectWorkTimeAndType1.remove(i);
}
// 获取前一个对象
ProjectWorkTimeAndType projectWorkTimeAndTypes = projectWorkTimeAndType1.get(i-1);
totalTime += projectWorkTimeAndTypes.getNormalTime() + projectWorkTimeAndTypes.getOvertime();
if (projectWorkTimeAndTypes.getNormalTime() != null) {
totalTime += projectWorkTimeAndTypes.getNormalTime();
}
if (projectWorkTimeAndTypes.getOvertime()!=null) {
totalTime += projectWorkTimeAndTypes.getOvertime();
}
}
// 最后一个对象
ProjectWorkTimeAndType projectWorkTimeAndTypes = projectWorkTimeAndType1.get(projectWorkTimeAndType1.size()-1);
if (projectWorkTimeAndTypes.getOvertime()!=null) {
totalTime += projectWorkTimeAndTypes.getOvertime();
}
totalTime += projectWorkTimeAndType1.get(projectWorkTimeAndType1.size() - 1).getOvertime() + projectWorkTimeAndType1.get(projectWorkTimeAndType1.size() - 1).getNormalTime();
if (projectWorkTimeAndTypes.getNormalTime() != null) {
totalTime += projectWorkTimeAndTypes.getNormalTime();
}
userProjectWorkTimeStatistic.setTotalTime(totalTime);
}
......@@ -667,6 +680,11 @@ public class StatisticsServiceImpl implements StatisticsService {
if (!UserRoleLevelUtils.isManagerLevel(userId, LevelEnum.PROJECT_STATISTICS.getLevelName())) {
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 (year == null) {
......@@ -677,12 +695,29 @@ public class StatisticsServiceImpl implements StatisticsService {
deptId = DEFAULT_DEPT_ID;
}
// 部门为空,查询某个项目的全周期统计,不为空,查询部门在某年的全部项目按月总计信息
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(year, deptId, projectId);
Map<String, Object> map = new HashMap<>();
map.put("year", year);
if (projectId == null) {
if (rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// 查询部门下所有项目,部门主键为空时是默认部门
map.put("deptId", deptId);
} else if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) {
// 查询部门下所有项目,部门主键是用户的部门主键,当前权限最高级别为部门级别
map.put("deptId", deptId);
map.put("managerId", userId);
} else {
// 项目/商机级别,以项目管理查询
map.put("managerId", userId);
}
}else {
map.put("projectId", projectId);
}
// 查询所管理项目的项目统计
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map);
if (CollectionUtil.isEmpty(projectStatisticsByMonths)) {
return null;
}
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(year, deptId, projectId);
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map);
if (projectId != null) {
// 项目的全周期统计
......@@ -725,8 +760,8 @@ public class StatisticsServiceImpl implements StatisticsService {
// 项目合计对象
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime1 = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime1.setDate("项目合计");
BigDecimal totalTime = new BigDecimal("0.0000");
BigDecimal cost = new BigDecimal("0.0000");
BigDecimal totalTime = new BigDecimal("0.000");
BigDecimal cost = new BigDecimal("0.000");
// 统计项目工时和成本
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
totalTime = totalTime.add(statisticsDateAndWorkTime.getTotalTime());
......
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