Commit 147cadae authored by nie'hong's avatar nie'hong

完善工时统计

parent 80826eaf
...@@ -82,7 +82,7 @@ public enum BASE_RESP_CODE_ENUM { ...@@ -82,7 +82,7 @@ public enum BASE_RESP_CODE_ENUM {
ROLE_CANNOTBE_EMPTY("662", "设置的角色不能为空"), ROLE_CANNOTBE_EMPTY("662", "设置的角色不能为空"),
NOADMIN_ISTRATIVE_RIGHTS("663", "设置的负责人没有管理权限"), NOADMIN_ISTRATIVE_RIGHTS("663", "设置的负责人没有管理权限"),
CHOOSEATLEASTONEROLE("667", "至少保留一个角色"), CHOOSEATLEASTONEROLE("667", "至少保留一个角色"),
DOWNLOAD_ERROR("668","下载出错")
; ;
......
...@@ -198,10 +198,11 @@ ...@@ -198,10 +198,11 @@
</sql> </sql>
<select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics"> <select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics">
select t2.id AS id , t2.name AS name ,count(1),sum(work_time) select ty.id AS id , ty.name AS name ,count(1),sum(work_time)
from work_time_order t join work_type t2 on t.type = t2.id from work_time_order t join work_type ty on t.type = ty.id
where user_id = #{userId} AND work_day >= #{currentMonthFirstDay} AND t.status != 3 where user_id = #{userId} AND work_day >= #{currentMonthFirstDay} AND t.status != 3
group by type group by type
order by filed(ty.id, 1, 2, 5, 6, 7, 3, 4)
</select> </select>
<select id="listByDateAndUserId" resultMap="dayWorkTimeAndType"> <select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
...@@ -256,16 +257,17 @@ ...@@ -256,16 +257,17 @@
</where> </where>
</select> </select>
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" > <select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect">
SELECT t.type AS type, d.id AS dept_id,dept_name, 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 IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day),
total_time, SUM(t.work_time * s.day_salary)/8 AS cost '年')) 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 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 WHERE status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day
<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
...@@ -321,18 +323,23 @@ ...@@ -321,18 +323,23 @@
<select id="getUserProjectWorkTimeStatistics" resultMap="userWorkTimeStatisticsByProject"> <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 work_time_type, p.project_name AS project_name, SELECT <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.project_id AS project_id, t.type AS work_time_type, p.project_name
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 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} 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>
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 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>
<select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics"> <select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
...@@ -347,8 +354,11 @@ ...@@ -347,8 +354,11 @@
</select> </select>
<select id="selectListByType" resultMap="userWorkTimeStatisticsByProject"> <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 work_time_type, SELECT <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 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 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)
...@@ -360,20 +370,20 @@ ...@@ -360,20 +370,20 @@
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>
......
...@@ -13,7 +13,7 @@ import java.io.Serializable; ...@@ -13,7 +13,7 @@ import java.io.Serializable;
**/ **/
@Data @Data
@ApiModel(value = "MonthlyWorkingHoursStatistics", description = "统计本月的填报信息") @ApiModel(value = "MonthlyWorkingHoursStatistics", description = "统计本月的填报信息")
public class MonthlyWorkingHoursStatistics implements Serializable ,Comparable{ public class MonthlyWorkingHoursStatistics implements Serializable {
private static final long serialVersionUID = -8216457470821285624L; private static final long serialVersionUID = -8216457470821285624L;
// 工单类型展示顺序,存储为类型id // 工单类型展示顺序,存储为类型id
...@@ -49,19 +49,4 @@ public class MonthlyWorkingHoursStatistics implements Serializable ,Comparable{ ...@@ -49,19 +49,4 @@ public class MonthlyWorkingHoursStatistics implements Serializable ,Comparable{
@ApiModelProperty(name = "workTime", value = "合计填报工时") @ApiModelProperty(name = "workTime", value = "合计填报工时")
private Integer workTime; private Integer workTime;
@Override
public int compareTo(Object o) {
MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistics = (MonthlyWorkingHoursStatistics) o;
int thisI = 0;
int oI = 0;
for (int i = 0; i < TYPE_ORDER.length; i++) {
if (projectType == TYPE_ORDER[i]) {
thisI = i;
}
if (monthlyWorkingHoursStatistics.getProjectType() == TYPE_ORDER[i]) {
oI = i;
}
}
return thisI - oI;
}
} }
...@@ -84,7 +84,7 @@ public interface StatisticsService { ...@@ -84,7 +84,7 @@ public interface StatisticsService {
* @param projectIds * @param projectIds
* @return * @return
*/ */
HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, List<Integer> projectIds); HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, String projectIds);
/** /**
* 获取某月需要填报的日期 * 获取某月需要填报的日期
......
...@@ -28,6 +28,7 @@ import org.apache.poi.ss.util.RegionUtil; ...@@ -28,6 +28,7 @@ import org.apache.poi.ss.util.RegionUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -245,8 +246,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -245,8 +246,6 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
} }
} }
// 调整类型顺序
Collections.sort(monthlyWorkingHoursStatistics);
// 赋值未填报天数、被驳回未重报天 // 赋值未填报天数、被驳回未重报天
for (MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistic : monthlyWorkingHoursStatistics) { for (MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistic : monthlyWorkingHoursStatistics) {
...@@ -487,6 +486,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -487,6 +486,7 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
} }
} }
this.closeSheets(sheets);
return sheets; return sheets;
} }
...@@ -519,7 +519,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -519,7 +519,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 获取用户的权限名 // 获取用户的权限名
List<String> userAuthority = this.getUserAuthority(workLevels); List<String> userAuthority = this.getUserAuthority(workLevels);
// 判断是否有该权限 // 判断是否有该权限
if (!userAuthority.contains(LevelEnum.USER_STATISTICS.getLevelName())) { if (CollectionUtil.isEmpty(userAuthority) || !userAuthority.contains(LevelEnum.USER_STATISTICS.getLevelName())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY); throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
} }
...@@ -914,15 +914,19 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -914,15 +914,19 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
sheet1.getRow(0).getCell(0).setCellStyle(ordinaryCellStyle1); sheet1.getRow(0).getCell(0).setCellStyle(ordinaryCellStyle1);
this.closeSheets(sheets);
return sheets; return sheets;
} }
@Override @Override
public HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, List<Integer> projectIds) { public HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, String projectIds) {
log.info("StatisticsServiceImpl[]exportProjectStatistics[]param{}" + userId + year + projectIds); log.info("StatisticsServiceImpl[]exportProjectStatistics[]param{}" + userId + year + projectIds);
// 将项目主键解析出来
List<Integer> projectIdList = Arrays.asList(projectIds.split(",")).stream().map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
// 查询条件
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("year", year); map.put("year", year);
map.put("projectIds", projectIds); map.put("projectIds", projectIdList);
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map); List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map);
map.put("isAll", false); map.put("isAll", false);
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map); List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map);
...@@ -1023,8 +1027,8 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1023,8 +1027,8 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
} }
// 释放资源
this.closeSheets(sheets);
return sheets; return sheets;
} }
...@@ -1166,7 +1170,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1166,7 +1170,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 获取用户权限 // 获取用户权限
public List<String> getUserAuthority(List<UserRoleLevelDto> roleUserLevel) { public List<String> getUserAuthority(List<UserRoleLevelDto> roleUserLevel) {
if (CollectionUtil.isEmpty(roleUserLevel)) { if (CollectionUtil.isEmpty(roleUserLevel)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY); return null;
} }
// 获取权限名 // 获取权限名
List<String> collect = roleUserLevel.stream().map(UserRoleLevelDto::getLevelName).collect(Collectors.toList()); List<String> collect = roleUserLevel.stream().map(UserRoleLevelDto::getLevelName).collect(Collectors.toList());
...@@ -1259,5 +1263,12 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1259,5 +1263,12 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
} }
} }
public void closeSheets(HSSFWorkbook sheets ){
try {
sheets.close();
} catch (IOException e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.DOWNLOAD_ERROR);
}
}
} }
...@@ -14,6 +14,7 @@ import cn.wisenergy.web.admin.controller.common.BaseController; ...@@ -14,6 +14,7 @@ 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.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; 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;
...@@ -61,6 +62,10 @@ public class StatisticsController extends BaseController { ...@@ -61,6 +62,10 @@ public class StatisticsController extends BaseController {
} }
@ApiOperation(value = "获取负责项目工时汇总", notes = "获取负责项目工时汇总") @ApiOperation(value = "获取负责项目工时汇总", notes = "获取负责项目工时汇总")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户主键"),
@ApiImplicitParam(name = "startTime", value = "开始时间")
})
@GetMapping("/getCurrentMonthWorkTimeCollect") @GetMapping("/getCurrentMonthWorkTimeCollect")
public Result<List<WorkTimeAndCostCollect>> getWorkTimeCollect(Integer userId, String startTime) { public Result<List<WorkTimeAndCostCollect>> getWorkTimeCollect(Integer userId, String startTime) {
log.info("WorkUserController[]getCurrentMonthWorkTimeCollect[]input.param" + userId, startTime); log.info("WorkUserController[]getCurrentMonthWorkTimeCollect[]input.param" + userId, startTime);
...@@ -101,6 +106,12 @@ public class StatisticsController extends BaseController { ...@@ -101,6 +106,12 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表") @ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表")
@GetMapping("/getUserWorkTimeStatisticsReport") @GetMapping("/getUserWorkTimeStatisticsReport")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "deptId", value = "部门主键"),
@ApiImplicitParam(name = "startDate", value = "开始统计时间"),
@ApiImplicitParam(name = "endDate", value = "结束统计时间")
})
public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) { public Result<List<UserWorkTimeStatisticsByProject>> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate); log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate); List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
...@@ -108,6 +119,12 @@ public class StatisticsController extends BaseController { ...@@ -108,6 +119,12 @@ public class StatisticsController extends BaseController {
} }
@ApiOperation(value = "获取项目统计报表", notes = "获取项目统计报表") @ApiOperation(value = "获取项目统计报表", notes = "获取项目统计报表")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "deptId", value = "部门主键"),
@ApiImplicitParam(name = "year", value = "统计年"),
@ApiImplicitParam(name = "projectId", value = "项目主键")
})
@GetMapping("/getProjectStatistics") @GetMapping("/getProjectStatistics")
public Result<List<ProjectStatisticsByMonth>> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) { public Result<List<ProjectStatisticsByMonth>> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) {
log.info("StatisticsController[]getProjectStatistics[]input.param" + userId + deptId + year, projectId); log.info("StatisticsController[]getProjectStatistics[]input.param" + userId + deptId + year, projectId);
...@@ -116,6 +133,12 @@ public class StatisticsController extends BaseController { ...@@ -116,6 +133,12 @@ public class StatisticsController extends BaseController {
} }
@ApiOperation(value = "导出人员工时统计", notes = "导出人员工时统计") @ApiOperation(value = "导出人员工时统计", notes = "导出人员工时统计")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "deptId", value = "部门主键"),
@ApiImplicitParam(name = "startDate", value = "开始统计时间"),
@ApiImplicitParam(name = "endDate", value = "结束统计时间")
})
@GetMapping("/exportUserStatistics") @GetMapping("/exportUserStatistics")
public void exportUserStatistics(Integer userId, Integer deptId, String startDate, String endDate,HttpServletResponse response) { public void exportUserStatistics(Integer userId, Integer deptId, String startDate, String endDate,HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + deptId + startDate + endDate); log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + deptId + startDate + endDate);
...@@ -128,8 +151,13 @@ public class StatisticsController extends BaseController { ...@@ -128,8 +151,13 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "导出项目统计明细", notes = "导出项目明细表") @ApiOperation(value = "导出项目统计明细", notes = "导出项目明细表")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "year", value = "统计年"),
@ApiImplicitParam(name = "projectIds", value = "项目主键,以逗号隔开")
})
@GetMapping("/exportProjectStatistics") @GetMapping("/exportProjectStatistics")
public void exportProjectStatistics(Integer userId, Integer year, @RequestParam("projectIds") List<Integer> projectIds, HttpServletResponse response) { public void exportProjectStatistics(Integer userId, Integer year, String projectIds, HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds); log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds);
// 获取excel // 获取excel
HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds); HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds);
......
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