Commit 6e2eefc9 authored by nie'hong's avatar nie'hong

完善工时统计

parent b398984b
......@@ -19,10 +19,19 @@ public interface WorkProjectTimeCostMapper {
int statisticsTimeOrderByMonth(String date);
/**
* 统计项目总工时和成本,按月统计
* 统计项目和商机总工时和成本,按月统计
* @param map
*/
List<WorkTimeAndCostCollect> selectList(Map<String, Object> map);
List<WorkTimeAndCostCollect> selectListByProjectAndBusiness(Map<String, Object> map);
/**
* 统计其他类型的总工时,按月统计
* @param map
* @return
*/
List<WorkTimeAndCostCollect> selectListByOtherType(Map<String, Object> map);
/**
* 部门编号不为空,查询部门下所有项目统计。部门主键为空时,查询项目主键参数为主键的项目信息
......
......@@ -50,6 +50,7 @@
<insert id="statisticsTimeOrderByMonth" useGeneratedKeys="true">
INSERT INTO work_project_time_cost (
`type`,
project_id,
user_id,
dept_id,
......@@ -60,6 +61,7 @@
create_time
)
SELECT
t.type,
project_id,
t.user_id,
t.dept_id,
......@@ -73,8 +75,9 @@
LEFT JOIN work_user_salary s ON t.user_id = s.user_id
WHERE
t.work_day >= #{date} AND s.create_time &lt;work_day AND s.end_time > work_day
AND t.`status` IN (2, 5) AND project_id is not null
AND t.`status` IN (2, 5)
GROUP BY
`type`,
project_id,
t.dept_id,
t.user_id,
......@@ -84,8 +87,8 @@
</insert>
<select id="selectList" resultMap="workTimeAndCostCollect">
SELECT p.type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id AS
<select id="selectListByProjectAndBusiness" resultMap="workTimeAndCostCollect">
SELECT ptc.type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id AS
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>
......@@ -105,8 +108,8 @@
AND statistics_start >= #{firstDayOfMonth}
</if>
</where>
GROUP BY p.type, <if test="centreId == null"> dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id,project_name
ORDER BY p.type<if test="centreId != null">, d.sort</if>
GROUP BY ptc.type, <if test="centreId == null"> dept_name,</if> <if test="centreId != null"> dept_name,p.dept_id,</if>p.id,project_name
ORDER BY ptc.type<if test="centreId != null">, d.sort</if>
</select>
......@@ -167,4 +170,46 @@
</select>
<select id="selectListByOtherType" resultMap="workTimeAndCostCollect">
SELECT ptc.type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,u.dept_id,</if>
concat(YEAR(statistics_start),'年') AS statistics_time ,sum(total_time) AS total_time,sum(cost) AS cost,d.sort AS d_sort
from work_project_time_cost ptc join work_user u on u.id=ptc.user_id join work_dept d on ptc.dept_id = d.id
<where>
ptc.type not in(1,2)AND YEAR (statistics_start) &lt; YEAR (NOW())
<if test="deptId != null ">
AND ptc.dept_id = #{deptId}
</if>
<if test="centreId != null">
AND d.centre_id = #{centreId}
</if>
<if test="firstDayOfMonth != null">
AND statistics_start >= #{firstDayOfMonth}
</if>
</where>
GROUP BY ptc.type, dept_name,year(statistics_start) <if test="centreId != null"> ,u.dept_id</if>
union
SELECT ptc.type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,u.dept_id,</if>
concat(YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS statistics_time ,sum(total_time) AS total_time,sum(cost) AS cost,d.sort AS d_sort
from work_project_time_cost ptc join work_user u on u.id=ptc.user_id join work_dept d on ptc.dept_id = d.id
<where>
ptc.type not in(1,2) AND YEAR(statistics_start) = YEAR (NOW())
<if test="deptId != null ">
AND ptc.dept_id = #{deptId}
</if>
<if test="centreId != null">
AND d.centre_id = #{centreId}
</if>
<if test="firstDayOfMonth != null">
AND statistics_start >= #{firstDayOfMonth}
</if>
</where>
GROUP BY ptc.type, dept_name,month(statistics_start) <if test="centreId != null"> ,u.dept_id</if>
ORDER BY <if test="centreId != null">d_sort,</if>statistics_time
</select>
</mapper>
\ No newline at end of file
......@@ -256,7 +256,7 @@
<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),
IF (YEAR (work_day) &lt; 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,ty.sort AS ty_sort, d.sort AS d_sort
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 join work_type ty on t.type = ty.id
......
......@@ -18,8 +18,6 @@ import java.util.List;
public class WorkTimeAndCostCollect implements Serializable {
private static final long serialVersionUID = 7207732278277982917L;
// 工单类型展示顺序,存储为类型id
private final static Integer[] TYPE_ORDER = {1, 2, 5, 6, 7, 3, 4};
@ApiModelProperty(name = "type", value = "工时类型主键")
private Integer type;
......
......@@ -28,6 +28,7 @@ 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;
import java.io.IOException;
import java.math.BigDecimal;
......@@ -295,14 +296,15 @@ public class StatisticsServiceImpl implements StatisticsService {
// 获取所有的类型
List<WorkType> workTypes = workTypeService.getAll(1);
// 存储查询的类型
List<Integer> types = new ArrayList<>();
// 只存储项目和商机之外的类型
for (WorkType workType : workTypes) {
if (workType.getId() != 1 && workType.getId() != 2) {
types.add(workType.getId());
}
}
// // 存储查询的类型
// List<Integer> types = new ArrayList<>();
// // 只存储项目和商机之外的类型
// for (WorkType workType : workTypes) {
// if (workType.getId() != 1 && workType.getId() != 2) {
// types.add(workType.getId());
// }
// }
List<WorkTimeAndCostCollect> workTimeAndCostCollects = null;
Map<String, Object> map = new HashMap<>();
......@@ -314,13 +316,18 @@ public class StatisticsServiceImpl implements StatisticsService {
WorkDept userDept = workDeptMapper.getById(user.getDeptId());
// 获取中心下的所有项目和商机工单统计
map.put("centreId", userDept.getCentreId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
workTimeAndCostCollects = workProjectTimeCostMapper.selectListByProjectAndBusiness(map);
// 除项目和项目的类型
map.put("types", types);
// 获取这些类型的所有工单
List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
workTimeAndCostCollects.addAll(workTimeAndCostCollect);
// 中心下其他类型的同时统计
List<WorkTimeAndCostCollect> workTimeAndCostCollects1 = workProjectTimeCostMapper.selectListByOtherType(map);
workTimeAndCostCollects.addAll(workTimeAndCostCollects1);
// // 除项目和项目的类型
// map.put("types", types);
// // 获取这些类型的所有工单
// List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
// workTimeAndCostCollects.addAll(workTimeAndCostCollect);
} else if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank())) { // 如果用户的审批权限的级别最高为部门级别
// 如果用户同时为项目级别和部门级别
......@@ -329,21 +336,27 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取部门下的所有项目和商机的工时统计
map.put("deptId", user.getDeptId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
workTimeAndCostCollects = workProjectTimeCostMapper.selectListByProjectAndBusiness(map);
// 部门下其他类型的同时统计
List<WorkTimeAndCostCollect> workTimeAndCostCollects1 = workProjectTimeCostMapper.selectListByOtherType(map);
// 除项目和项目的类型
map.put("types", types);
// 获取这些类型的所有工单
List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
workTimeAndCostCollects.addAll(workTimeAndCostCollect);
workTimeAndCostCollects.addAll(workTimeAndCostCollects1);
// // 除项目和项目的类型
// map.put("types", types);
// // 获取这些类型的所有工单
// List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
// workTimeAndCostCollects.addAll(workTimeAndCostCollect);
} else if (rank.contains(LevelRankEnum.PROJECT_LEVEL.getRank())) { // 如果用户的审批权限的级别最高为项目/商机级别,与其他两种级别不同的是只汇总项目和商机类型的工单
map.put("managerId", user.getId());
workTimeAndCostCollects = workProjectTimeCostMapper.selectList(map);
workTimeAndCostCollects = workProjectTimeCostMapper.selectListByProjectAndBusiness(map);
}
// 获取查询结果中的类型
assert workTimeAndCostCollects != null;
List<Integer> typeList = workTimeAndCostCollects.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
List<Integer> typeList = new ArrayList<>(workTypes.size());
if (!CollectionUtils.isEmpty(workTimeAndCostCollects)) {
typeList = workTimeAndCostCollects.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
}
if (typeList.size() < workTypes.size()) {
int j;
// 用户仅为项目商机级别用户,仅展示项目和商机类型
......@@ -363,6 +376,19 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
}
// 按照类型排序
for (int i = 0; i < workTypes.size(); i++) {
WorkType workType = workTypes.get(i);
for (int i1 = 0; i1 < workTimeAndCostCollects.size(); i1++) {
if (workTimeAndCostCollects.get(i1).getType().equals(workType.getId())) {
WorkTimeAndCostCollect workTimeAndCostCollect ;
workTimeAndCostCollect = workTimeAndCostCollects.get(i1);
workTimeAndCostCollects.remove(i1);
workTimeAndCostCollects.add(i, workTimeAndCostCollect);
}
}
}
// 给类型赋值类型名称
for (WorkTimeAndCostCollect timeAndCostCollect : workTimeAndCostCollects) {
......
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