Commit 145e31b8 authored by nie'hong's avatar nie'hong

完善小程序工时统计

parent f8dd35c0
......@@ -20,4 +20,6 @@ public interface WorkDeptMapper extends BaseMapper<WorkDept> {
List<WorkDept> getDeptByCondition(Map<String, Object> map);
List<OrganizationStructureDto> getAllDeptByAllCentre();
WorkDept getById(Integer deptId);
}
......@@ -80,10 +80,11 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
/**
* 获取上班日期集合
*
* @param firstDayOfMonth
* @param date
* @param userId
* @return
*/
List<Date> getDaysByDateAndStatus(@Param("firstDayOfMonth") Date firstDayOfMonth, @Param("userId") Integer userId);
List<Date> getDaysByDateAndStatus(@Param("userId") Integer userId, @Param("date") Date date);
List<WorkTimeOrder> getAutoOrder(Integer autoExamine);
......@@ -93,7 +94,7 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
/**
* 获取人员项目工时
*/
List<UserWorkTimeStatisticsByProject> getUserProjectWorkTimeStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("isConclusion") Integer isConclusion, @Param("projectIds") List<Integer> projectIds, @Param("isAll") Boolean isAll);
List<UserWorkTimeStatisticsByProject> getUserProjectWorkTimeStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("projectIds") List<Integer> projectIds, @Param("isAll") Boolean isAll);
/**
* 根据工单状态获取填报条数
......@@ -106,5 +107,5 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
List<MonthlyWorkingHoursStatistics> selectCountByTypeAndStatus(@Param("userId") Integer userId, @Param("firstDayOfMonth") Date firstDayOfMonth, @Param("status") Integer[] status);
List<UserWorkTimeStatisticsByProject> selectListByType(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("isConclusion") Integer isConclusion, @Param("queryType") List<Integer> queryType, @Param("userIds") List<Integer> userIds, @Param("isAll") Boolean isAll);
List<UserWorkTimeStatisticsByProject> selectListByType(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("queryType") List<Integer> queryType, @Param("userIds") List<Integer> userIds, @Param("isAll") Boolean isAll);
}
......@@ -32,7 +32,7 @@
</sql>
<sql id="cols_exclude_id">
dept_name, create_time, modify_time
dept_name,oa_dept_id,dept_manager_id,centre_id, create_time, modify_time
</sql>
<sql id="criteria">
......@@ -64,5 +64,11 @@ from work_centre c LEFT JOIN work_dept d ON c.id = d.centre_id
ORDER BY c.id,d.id
</select>
<select id="getById" resultMap="BaseResultMap">
select <include refid="cols_all"/>
from <include refid="table"/>
where id =#{deptId}
</select>
</mapper>
......@@ -164,7 +164,8 @@ ORDER BY p.is_conclusion DESC
<select id="getListByDeptAndIsConclusion" resultType="cn.wisenergy.model.app.WorkProject">
select <include refid="Base_Column_List"/>
from <include refid="table"/>
where dept=#{deptId} AND isConclusion=#{isConclusion}
where dept_id = #{deptId}
<if test="isConclusion !=null ">AND is_conclusion=#{isConclusion}</if>
</select>
......
......@@ -84,7 +84,7 @@
<select id="selectList" resultMap="workTimeAndCostCollect">
SELECT type ,dept_name,ptc.dept_id,ptc.project_id AS
SELECT type ,<if test="centreId == null">'汇总' AS dept_name,</if> <if test="centreId != null"> dept_name,ptc.dept_id,</if>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
......@@ -95,14 +95,19 @@
<if test="deptId != null">
AND dept_id = #{deptId}
</if>
AND type in
<foreach collection="types" open="(" close=")" separator="," item="type">
#{type}
</foreach>
<if test="types != null">
AND type in
<foreach collection="types" open="(" close=")" separator="," item="type">
#{type}
</foreach>
</if>
<if test="centreId != null">
AND centre_id = #{centreId}
</if>
<if test="firstDayOfMonth != null">
AND statistics_start >= #{firstDayOfMonth}
</if>
GROUP BY type,dept_name,dept_id,ptc.project_id,project_name
GROUP BY type, <if test="centreId == null"> dept_name,</if> <if test="centreId != null"> dept_name,ptc.dept_id,</if>ptc.project_id,project_name
</select>
......
......@@ -185,7 +185,7 @@
<select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics">
select t2.id AS id , t2.name AS name ,count(1),sum(work_time)
from work_time_order t join work_type t2 on t.type = t2.id
where user_id = #{userId} AND work_day >= #{currentMonthFirstDay}
where user_id = #{userId} AND work_day >= #{currentMonthFirstDay} AND t.status != 3
group by type
</select>
......@@ -232,9 +232,9 @@
</select>
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" >
SELECT t.type AS type,t.dept_id AS dept_id,
SELECT t.type AS type, t.dept_id AS dept_id,dept_name,
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
total_time, SUM(t.work_time * s.day_salary)/8 AS cost,dept_name AS dept_name,project_name
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
WHERE status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day
<if test="projectIds != null">
......@@ -254,16 +254,17 @@
<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
group by t.type,t.dept_id, dept_name, t.project_id,p.project_name
order by t.dept_id
</select>
<select id="getDaysByDateAndStatus" resultType="date">
select distinct(work_day)
from
<include refid="table"/>
where work_day >= #{firstDayOfMonth} AND user_id = #{userId}
where year(#{date}) = year(work_day) AND month(#{date}) = month(work_day) AND user_id = #{userId} AND status != 3
</select>
<select id="geByMonth" resultType="cn.wisenergy.model.app.WorkTimeOrder">
SELECT
<include refid="Base_Column_List"/>
......@@ -303,9 +304,6 @@
where
t.status in (2,5) AND
t.work_day &lt;= #{endDate}
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<if test="startDate != null">
AND t.work_day > #{startDate}
</if>
......@@ -331,9 +329,6 @@
from work_type ty left join work_time_order t on t.type = ty.id left join work_user u on t.user_id = u.id
where
(t.work_day &lt;= #{endDate} or t.work_day is null) AND (t.status IN (2, 5) or t.status is null)
<if test="isConclusion != null">
AND (p.is_conclusion = #{isConclusion} or p.is_conclusion is null)
</if>
<if test="startDate != null">
AND (t.work_day > #{startDate} or t.work_day is null)
</if>
......
......@@ -6,10 +6,7 @@ import cn.wisenergy.common.utils.ExcelUtils;
import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.WorkHoliday;
import cn.wisenergy.model.app.WorkProject;
import cn.wisenergy.model.app.WorkType;
import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.model.app.*;
import cn.wisenergy.model.dto.*;
import cn.wisenergy.model.enums.*;
import cn.wisenergy.service.StatisticsService;
......@@ -70,6 +67,10 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private WorkProjectMapper workProjectMapper;
@Autowired
private WorkDeptMapper workDeptMapper;
@Autowired
private WorkUserProjectMapper workUserProjectMapper;
......@@ -145,7 +146,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> role = userRoleLevelUtils.getRole(user.getId());
//本月第一天
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
//返回数据对象
// 返回数据对象
Map<String, Object> objects = new HashMap<>();
//存放查询条件
Map<String, Object> map = new HashMap<>();
......@@ -196,7 +197,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 本月应填报日期
List<Date> currentMonthWorkDays = this.currentMonthWorkDays(firstDayOfMonth);
// 本月已填报日期
List<Date> currentMonthFilledDays = currentMonthFilledDays(userId);
List<Date> currentMonthFilledDays = this.currentMonthFilledDays(userId, firstDayOfMonth);
// 本月未填报日期
currentMonthWorkDays.removeAll(currentMonthFilledDays);
int notFilledCount = currentMonthWorkDays.size();
......@@ -285,29 +286,46 @@ public class StatisticsServiceImpl implements StatisticsService {
if (StringUtil.isNotEmpty(startTime)) {
map.put("firstDayOfMonth", startTime);
}
// 工时类型包含:项目,商机
List<Integer> types = new ArrayList<>();
// 查询所有类型
List<WorkType> workTypes = workTypeMapper.getAll();
types.add(workTypes.get(1).getId());
types.add(workTypes.get(2).getId());
map.put("types", types);
if (role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
WorkDept workDept = workDeptMapper.getById(user.getDeptId());
map.put("centreId",workDept.getCentreId() );
}
// 查询项目和商机的工时统计
List<WorkTimeAndCostCollect> collect = workProjectTimeCostMapper.selectList(map);
// 获取查询出的类型
List<Integer> queryType = collect.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 商机和项目
List<Integer> types = new ArrayList<>();
types.add(workTypes.get(0).getId());
types.add(workTypes.get(1).getId());
// 如果查询出的结果中不包含项目和商机中的类型,造对象传前端
types.removeAll(queryType);
if (CollectionUtil.isNotEmpty(types)) {
for (Integer type : types) {
WorkTimeAndCostCollect workTimeAndCostCollect = new WorkTimeAndCostCollect();
workTimeAndCostCollect.setType(type);
workTimeAndCostCollect.setWorkTime(new BigDecimal("0.0000"));
collect.add(workTimeAndCostCollect);
}
}
// 部门和中心级别
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
// 请假、调休、外部商务、技术交流,内部培训、技术准备、管理,其他非项目/商机工作
types.clear();
// 清除查询条件
map.clear();
// 请假、调休、外部商务、技术交流,内部培训、技术准备、管理,其他非项目/商机工作
for (WorkType workType : workTypes) {
// 查询条件排除项目和商机
if (!workType.getName().equals(workTypes.get(1).getName()) && !workType.getName().equals(workTypes.get(2).getName())) {
if (!workType.getName().equals(workTypes.get(0).getName()) && !workType.getName().equals(workTypes.get(1).getName())) {
types.add(workType.getId());
}
}
// 用户仅为部门管理
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) && role.size() == 1) {
map.put("deptId", user.getDeptId());
......@@ -317,10 +335,6 @@ public class StatisticsServiceImpl implements StatisticsService {
// 将查询结果封装在一起
collect.addAll(workTimeAndCostCollect);
for (WorkTimeAndCostCollect timeAndCostCollect : collect) {
WorkType workType = workTypes.get(timeAndCostCollect.getType() - 1);
timeAndCostCollect.setTypeName(workType.getName());
}
// 获取查询结果中的类型
List<Integer> typeList = collect.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,造对象传前端
......@@ -333,9 +347,15 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
}
// 给类型赋值类型名称
for (WorkTimeAndCostCollect timeAndCostCollect : collect) {
WorkType workType = workTypes.get(timeAndCostCollect.getType() - 1);
timeAndCostCollect.setTypeName(workType.getName());
}
for (WorkTimeAndCostCollect workTimeAndCostCollect : collect) {
// 类型的总工时
BigDecimal typeTotalTime = new BigDecimal("0.00");
BigDecimal typeTotalTime = new BigDecimal("0.0000");
List<DeptProjectWorkTimeAndCost> deptProjectWorkTimeAndCosts = workTimeAndCostCollect.getDeptProjectWorkTimeAndCosts();
if (CollectionUtil.isNotEmpty(deptProjectWorkTimeAndCosts)) {
for (DeptProjectWorkTimeAndCost deptProjectWorkTimeAndCost : deptProjectWorkTimeAndCosts) {
......@@ -478,7 +498,7 @@ public class StatisticsServiceImpl implements StatisticsService {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
}
// 不是中心级不能选择部门
if (!role.contains(ManagerEnum.IS_CENTRE_DIRECTOR) && deptId != null) {
if (!role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode()) && deptId != null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
......@@ -489,9 +509,11 @@ public class StatisticsServiceImpl implements StatisticsService {
endDate = DateUtil.convertDateToYMDStr(yesterday);
}
// 获取用户负责项目主键集合
List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId);
List<WorkProject> userManageProjects;
if (deptId != null) {
userManageProjects = workProjectMapper.getListByDeptAndIsConclusion(deptId, isConclusion);
}else {
userManageProjects = workProjectService.getUserManageProjects(userId);
}
// 管理项目为空则提前结束
if (CollectionUtil.isEmpty(userManageProjects)) {
......@@ -501,7 +523,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList());
// 查询各个项目正常工时和加班工时统计
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(startDate, endDate, isConclusion, projectIds, false);
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(startDate, endDate, projectIds, false);
// 查询除开项目于、商机、请假、调休这几种类型的工单
List<WorkType> types = workTypeMapper.getAll();
......@@ -514,15 +536,15 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单
List<Integer> userIds = workUserProjectMapper.selectUserIdByProjectIds(projectIds);
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(startDate, endDate, isConclusion, queryType, userIds,false);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(startDate, endDate, queryType, userIds,false);
if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) {
userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType());
}
}
// 查询各个项目下所有人的加班工时和平常工时
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(startDate, endDate, isConclusion, projectIds, true);
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(startDate, endDate, projectIds, true);
// 查询各个项目下所有人的其他除了项目、商机、请假、调休类型的加班工时和平常工时
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = workTimeOrderMapper.selectListByType(startDate, endDate, isConclusion, queryType, userIds, true);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = workTimeOrderMapper.selectListByType(startDate, endDate, queryType, userIds, true);
for (UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject : userWorkTimeStatisticsByProjects) {
for (UserWorkTimeStatisticsByProject workTimeStatisticsByProject : userProjectWorkTimeStatistics1) {
if (userWorkTimeStatisticsByProject.getUserId() != null && userWorkTimeStatisticsByProject.getUserId().equals(workTimeStatisticsByProject.getUserId())) {
......@@ -531,12 +553,6 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
userProjectWorkTimeStatistics.addAll(userProjectWorkTimeStatistics1);
/*
*
*
*
* */
// 取出单人的项目工时统计
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) {
......@@ -578,18 +594,25 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
this.conversionDateFormat(projectStatisticsByMonths, deptId);
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(year, deptId, projectId);
// 将查询结果封装在一起
projectStatisticsByMonths.addAll(projectStatisticsByMonths1);
// 将查询结果封装在一起,部门主键为空,项目总计在前,否则在后
List<ProjectStatisticsByMonth> projectStatistics = new ArrayList<>();
if (deptId == null) {
projectStatistics.addAll(projectStatisticsByMonths);
projectStatistics.addAll(projectStatisticsByMonths1);
}else {
projectStatistics.addAll(projectStatisticsByMonths1);
projectStatistics.addAll(projectStatisticsByMonths);
}
// 计算项目工时和成本合计
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths1) {
// 一条统计的
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
// 项目合计对象
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime1 = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime1.setDate("项目合计");
BigDecimal totalTime = new BigDecimal("0.00");
BigDecimal cost = new BigDecimal("0.00");
BigDecimal totalTime = new BigDecimal("0.0000");
BigDecimal cost = new BigDecimal("0.0000");
// 统计项目工时和成本
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
totalTime = totalTime.add(statisticsDateAndWorkTime.getTotalTime());
......@@ -600,8 +623,7 @@ public class StatisticsServiceImpl implements StatisticsService {
statisticsDateAndWorkTime1.setCost(cost);
statisticsDateAndWorkTimes.add(statisticsDateAndWorkTime1);
}
return projectStatisticsByMonths;
return projectStatisticsByMonths1;
}
//获取一个月应上班日期,如果是当月,时间截至到当天
......@@ -613,7 +635,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 当前时间
Date now = new Date();
if (DateUtil.getYear(date) == DateUtil.getYear(now) && DateUtil.getMonth(date) == DateUtil.getMonth(now)) {
endDate = now;
endDate = DateUtil.getStartOfDay(now);
} else {
endDate = DateUtil.getLastDayOfMonth(date);
}
......@@ -649,11 +671,10 @@ public class StatisticsServiceImpl implements StatisticsService {
return workDays;
}
//获取用户本月已填报的日期
public List<Date> currentMonthFilledDays(Integer userId) {
//获取用户某月已填报的日期,如果一天中只有被驳回则不为已填报
public List<Date> currentMonthFilledDays(Integer userId, Date date) {
log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method");
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
List<Date> currentMonthFilledDays = workTimeOrderMapper.getDaysByDateAndStatus(firstDayOfMonth, userId);
List<Date> currentMonthFilledDays = workTimeOrderMapper.getDaysByDateAndStatus( userId, date);
return currentMonthFilledDays;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment