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

完善工时统计

parent 22767fad
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
where (year(day_start) = year(#{startDay}) AND month(day_start) = month(#{startDay})) OR where (year(day_start) = year(#{startDay}) AND month(day_start) = month(#{startDay})) OR
(year(day_end) = year(#{endDay}) AND month(day_end) = month(#{endDay})) (year(day_end) = year(#{endDay}) AND month(day_end) = month(#{endDay}))
</select> </select>
<select id="getByTypeAndStartDate" resultType="cn.wisenergy.model.app.WorkHoliday"> <select id="getByTypeAndStartDate" resultType="cn.wisenergy.model.app.WorkHoliday">
SELECT <include refid="Base_Column_List"/> SELECT <include refid="Base_Column_List"/>
FROM <include refid="table"/> FROM <include refid="table"/>
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<result property="projectId" column="project_id"/> <result property="projectId" column="project_id"/>
<result property="projectName" column="project_name"/> <result property="projectName" column="project_name"/>
<result property="deptName" column="dept_name"/> <result property="deptName" column="dept_name"/>
<result property="userName" column="user_name"/>
<collection property="statisticsDateAndWorkTimes" ofType="cn.wisenergy.model.dto.ProjectStatisticsByMonth$StatisticsDateAndWorkTime"> <collection property="statisticsDateAndWorkTimes" ofType="cn.wisenergy.model.dto.ProjectStatisticsByMonth$StatisticsDateAndWorkTime">
<result property="date" column="date"/> <result property="date" column="date"/>
<result property="year" column="year"/> <result property="year" column="year"/>
...@@ -88,14 +89,11 @@ ...@@ -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 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 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> <where>
<if test="projectIds != null"> <if test="managerId != null and deptId == null">
project_id in AND p.manager_id = #{managerId}
<foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
#{projectId}
</foreach>
</if> </if>
<if test="deptId != null"> <if test="deptId != null and managerId != null">
AND p.dept_id = #{deptId} AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if> </if>
<if test="centreId != null"> <if test="centreId != null">
AND centre_id = #{centreId} AND centre_id = #{centreId}
...@@ -110,12 +108,19 @@ ...@@ -110,12 +108,19 @@
<select id="selectListByMonth" resultMap="projectStatisticsByMonth"> <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 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> <where>
<if test="projectId != null "> <if test="projectId != null ">
ptc.project_id = #{projectId} ptc.project_id = #{projectId}
</if> </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"> <if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year} AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
</if> </if>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<result property="userName" column="user_name"/> <result property="userName" column="user_name"/>
<collection property="projectWorkTimeAndType" ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndType"> <collection property="projectWorkTimeAndType" ofType="cn.wisenergy.model.dto.ProjectWorkTimeAndType">
<result property="projectId" column="project_id"/> <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="projectName" column="project_name"/>
<result property="overTime" column="over_time"/> <result property="overTime" column="over_time"/>
<result property="normalTime" column="normal_time"/> <result property="normalTime" column="normal_time"/>
...@@ -256,25 +256,16 @@ ...@@ -256,25 +256,16 @@
</where> </where>
</select> </select>
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect"> <select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" >
SELECT t.type AS type, t.dept_id AS dept_id,dept_name, SELECT t.type AS type, d.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),'月') 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
, 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
total_time, SUM(t.work_time * s.day_salary)/8 AS cost ,project_name 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
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 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"> <if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth} AND work_day >= #{firstDayOfMonth}
</if> </if>
<if test="deptId != null"> <if test="deptId != null">
AND t.dept_id = #{deptId} AND t.dept_id = #{deptId}
</if> </if>
AND t.type in AND t.type in
...@@ -284,9 +275,8 @@ ...@@ -284,9 +275,8 @@
<if test="centreId != null"> <if test="centreId != null">
AND centre_id = #{centreId} AND centre_id = #{centreId}
</if> </if>
group by t.type,t.dept_id, dept_name, t.project_id,p.project_name, if(YEAR (work_day) = group by t.type,d.id, dept_name, if(YEAR (work_day) = YEAR(NOW()),',month(work_day)','')
YEAR(NOW()),',month(work_day)','') order by d.id,work_day
order by t.dept_id,work_day
</select> </select>
<select id="getDaysByDateAndStatus" resultType="date"> <select id="getDaysByDateAndStatus" resultType="date">
...@@ -331,37 +321,18 @@ ...@@ -331,37 +321,18 @@
<select id="getUserProjectWorkTimeStatistics" resultMap="userWorkTimeStatisticsByProject"> <select id="getUserProjectWorkTimeStatistics" resultMap="userWorkTimeStatisticsByProject">
SELECT 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 test="isAll">u.id AS user_id, u.`name` AS user_name,</if> 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
<if test="!isAll">'合计' AS user_name ,</if> 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
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 where
t.status in (2,5) AND t.status in (2,5) AND
t.work_day &lt;= #{endDate} t.work_day &lt;= #{endDate}
AND t.dept_id = #{deptId}
<if test="startDate != null"> <if test="startDate != null">
AND t.work_day >= #{startDate} AND t.work_day >= #{startDate}
</if>
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if> </if>
<if test="deptId != null and managerId == null"> GROUP BY <if test="isAll"> u.id,u.`name`,</if> t.project_id,t.type,p.project_name, t.is_overtime
AND p.dept_id = #{deptId} 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
</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
</select> </select>
<select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics"> <select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
...@@ -376,15 +347,8 @@ ...@@ -376,15 +347,8 @@
</select> </select>
<select id="selectListByType" resultMap="userWorkTimeStatisticsByProject"> <select id="selectListByType" resultMap="userWorkTimeStatisticsByProject">
SELECT 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 test="isAll">u.id AS user_id, u.`name` AS user_name,</if> 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
<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
from work_time_order t JOIN work_user u ON t.user_id = u.id from work_time_order t JOIN work_user u ON t.user_id = u.id
where where
t.work_day &lt;= #{endDate} AND t.status IN (2, 5) t.work_day &lt;= #{endDate} AND t.status IN (2, 5)
...@@ -396,22 +360,21 @@ ...@@ -396,22 +360,21 @@
AND t.work_day >= #{startDate} AND t.work_day >= #{startDate}
</if> </if>
AND user_id in ( AND user_id in (
select user_id select user_id
from work_project p JOIN work_user_project up ON p.id = up.project_id from work_project p JOIN work_user_project up ON p.id = up.project_id
<if test="isConclusion != null"> <if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion} AND p.is_conclusion = #{isConclusion}
</if> </if>
<if test="deptId != null and managerId == null"> <if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND p.dept_id = #{deptId}
</if> </if>
<if test="deptId != null and managerId != null"> <if test="deptId != null and managerId != null">
AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId}) AND (p.dept_id = #{deptId} OR p.manager_id = #{managerId})
</if> </if>
<if test="managerId != null and deptId == null"> <if test="managerId != null and deptId == null">
AND p.manager_id = #{managerId} AND p.manager_id = #{managerId}
</if> </if>
) )
GROUP BY <if test="isAll">u.id,u.`name`,</if> t.type, t.is_overtime GROUP BY <if test="isAll">u.id,u.`name`,</if> t.type, t.is_overtime
</select> </select>
</mapper> </mapper>
...@@ -27,6 +27,9 @@ public class ProjectStatisticsByMonth implements Serializable { ...@@ -27,6 +27,9 @@ public class ProjectStatisticsByMonth implements Serializable {
@ApiModelProperty(name = "deptName", value = "部门名称") @ApiModelProperty(name = "deptName", value = "部门名称")
private String deptName; private String deptName;
@ApiModelProperty(name = "userName", value = "用户姓名")
private String userName;
@ApiModelProperty(name = "statisticsDateAndWorkTime", value = "项目统计的时间段、工时和成本") @ApiModelProperty(name = "statisticsDateAndWorkTime", value = "项目统计的时间段、工时和成本")
List<StatisticsDateAndWorkTime> statisticsDateAndWorkTimes; List<StatisticsDateAndWorkTime> statisticsDateAndWorkTimes;
......
...@@ -22,8 +22,8 @@ public class ProjectWorkTimeAndType{ ...@@ -22,8 +22,8 @@ public class ProjectWorkTimeAndType{
/** /**
* 项目类型 * 项目类型
*/ */
@ApiModelProperty(name = "projectType", value = "项目类型") @ApiModelProperty(name = "workTimeType", value = "项目类型")
private Integer projectType; private Integer workTimeType;
...@@ -39,4 +39,10 @@ public class ProjectWorkTimeAndType{ ...@@ -39,4 +39,10 @@ public class ProjectWorkTimeAndType{
@ApiModelProperty(name = "normalTime", value = "正常工时") @ApiModelProperty(name = "normalTime", value = "正常工时")
private Integer normalTime; private Integer normalTime;
/**
* 总工时:加班工时+正常工时
*/
@ApiModelProperty(name = "totalTime", value = "总工时")
private Integer totalTime;
} }
\ No newline at end of file
...@@ -9,9 +9,6 @@ public enum LevelRankEnum { ...@@ -9,9 +9,6 @@ public enum LevelRankEnum {
PROJECT_LEVEL(1,"项目级"), PROJECT_LEVEL(1,"项目级"),
DEPARTMENT_LEVEL(2,"部门级"), DEPARTMENT_LEVEL(2,"部门级"),
CENTRAL_LEVEL(3, "中心级"), CENTRAL_LEVEL(3, "中心级"),
; ;
private Integer rank; private Integer rank;
......
...@@ -53,7 +53,7 @@ public interface StatisticsService { ...@@ -53,7 +53,7 @@ public interface StatisticsService {
* @param isConclusion * @param isConclusion
* @return * @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 { ...@@ -66,6 +66,25 @@ public interface StatisticsService {
*/ */
List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId); 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 * @param date
......
...@@ -12,9 +12,7 @@ import cn.wisenergy.service.StatisticsService; ...@@ -12,9 +12,7 @@ import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkDeptService; import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.web.admin.controller.common.BaseController; import cn.wisenergy.web.admin.controller.common.BaseController;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -87,7 +85,7 @@ public class StatisticsController extends BaseController { ...@@ -87,7 +85,7 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "导出部门员工一个月每天的工时", notes = "导出部门员工一个月每天的工时") @ApiOperation(value = "导出部门员工一个月每天的工时", notes = "导出部门员工一个月每天的工时")
@GetMapping("/exportWorkTime") @GetMapping("/exportWorkTime")
public void export(GetMonthlyCollectParam param, HttpServletResponse response) { public void export(GetMonthlyCollectParam param, HttpServletResponse response) {
log.info("StatisticsController[]getDeptInfo[]input.param" + param); log.info("StatisticsController[]export[]input.param" + param);
// 获取excel // 获取excel
HSSFWorkbook sheets = statisticsService.exportWorkTimeExcel(param); HSSFWorkbook sheets = statisticsService.exportWorkTimeExcel(param);
...@@ -115,9 +113,9 @@ public class StatisticsController extends BaseController { ...@@ -115,9 +113,9 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表") @ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表")
@GetMapping("/getUserWorkTimeStatisticsReport") @GetMapping("/getUserWorkTimeStatisticsReport")
public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate, Integer isConclusion) { public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate, isConclusion); log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId,deptId, startDate, endDate, isConclusion); List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
return getResult(userWorkTimeStatisticsByProjects); return getResult(userWorkTimeStatisticsByProjects);
} }
...@@ -129,4 +127,63 @@ public class StatisticsController extends BaseController { ...@@ -129,4 +127,63 @@ public class StatisticsController extends BaseController {
return getResult(projectStatisticsByMonths); return getResult(projectStatisticsByMonths);
} }
} @ApiOperation(value = "导出人员工时统计", notes = "导出人员工时统计")
\ No newline at end of file @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