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

完善工时统计

parent 80826eaf
......@@ -82,7 +82,7 @@ public enum BASE_RESP_CODE_ENUM {
ROLE_CANNOTBE_EMPTY("662", "设置的角色不能为空"),
NOADMIN_ISTRATIVE_RIGHTS("663", "设置的负责人没有管理权限"),
CHOOSEATLEASTONEROLE("667", "至少保留一个角色"),
DOWNLOAD_ERROR("668","下载出错")
;
......
......@@ -198,10 +198,11 @@
</sql>
<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
select ty.id AS id , ty.name AS name ,count(1),sum(work_time)
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
group by type
order by filed(ty.id, 1, 2, 5, 6, 7, 3, 4)
</select>
<select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
......@@ -256,16 +257,17 @@
</where>
</select>
<select id="getWorkTimeAndCostCollect" resultMap="workTimeAndCostCollect" >
<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), '年')) AS statistics_time ,SUM(t.work_time)/8 AS
total_time, SUM(t.work_time * s.day_salary)/8 AS cost
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
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
WHERE status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day
<if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth}
</if>
<if test="deptId != null">
<if test="deptId != null">
AND t.dept_id = #{deptId}
</if>
AND t.type in
......@@ -321,18 +323,23 @@
<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,
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
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(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
t.work_day &lt;= #{endDate}
AND t.dept_id = #{deptId}
<if test="startDate != null">
AND t.work_day >= #{startDate}
AND t.work_day >= #{startDate}
</if>
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
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
</select>
<select id="selectCountByTypeAndStatus" resultType="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
......@@ -347,8 +354,11 @@
</select>
<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,
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
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(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
where
t.work_day &lt;= #{endDate} AND t.status IN (2, 5)
......@@ -360,20 +370,20 @@
AND t.work_day >= #{startDate}
</if>
AND user_id in (
select user_id
from work_project p JOIN work_user_project up ON p.id = up.project_id
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<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>
select user_id
from work_project p JOIN work_user_project up ON p.id = up.project_id
<if test="isConclusion != null">
AND p.is_conclusion = #{isConclusion}
</if>
<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>
)
GROUP BY <if test="isAll">u.id,u.`name`,</if> t.type, t.is_overtime
</select>
......
......@@ -13,7 +13,7 @@ import java.io.Serializable;
**/
@Data
@ApiModel(value = "MonthlyWorkingHoursStatistics", description = "统计本月的填报信息")
public class MonthlyWorkingHoursStatistics implements Serializable ,Comparable{
public class MonthlyWorkingHoursStatistics implements Serializable {
private static final long serialVersionUID = -8216457470821285624L;
// 工单类型展示顺序,存储为类型id
......@@ -49,19 +49,4 @@ public class MonthlyWorkingHoursStatistics implements Serializable ,Comparable{
@ApiModelProperty(name = "workTime", value = "合计填报工时")
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 {
* @param projectIds
* @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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -245,8 +246,6 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
}
// 调整类型顺序
Collections.sort(monthlyWorkingHoursStatistics);
// 赋值未填报天数、被驳回未重报天
for (MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistic : monthlyWorkingHoursStatistics) {
......@@ -487,6 +486,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
}
this.closeSheets(sheets);
return sheets;
}
......@@ -519,7 +519,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 获取用户的权限名
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);
}
......@@ -914,15 +914,19 @@ public class StatisticsServiceImpl implements StatisticsService {
}
sheet1.getRow(0).getCell(0).setCellStyle(ordinaryCellStyle1);
this.closeSheets(sheets);
return sheets;
}
@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);
// 将项目主键解析出来
List<Integer> projectIdList = Arrays.asList(projectIds.split(",")).stream().map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
// 查询条件
Map<String, Object> map = new HashMap<>();
map.put("year", year);
map.put("projectIds", projectIds);
map.put("projectIds", projectIdList);
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map);
map.put("isAll", false);
List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map);
......@@ -1023,8 +1027,8 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
// 释放资源
this.closeSheets(sheets);
return sheets;
}
......@@ -1166,7 +1170,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 获取用户权限
public List<String> getUserAuthority(List<UserRoleLevelDto> 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());
......@@ -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;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
......@@ -61,6 +62,10 @@ public class StatisticsController extends BaseController {
}
@ApiOperation(value = "获取负责项目工时汇总", notes = "获取负责项目工时汇总")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户主键"),
@ApiImplicitParam(name = "startTime", value = "开始时间")
})
@GetMapping("/getCurrentMonthWorkTimeCollect")
public Result<List<WorkTimeAndCostCollect>> getWorkTimeCollect(Integer userId, String startTime) {
log.info("WorkUserController[]getCurrentMonthWorkTimeCollect[]input.param" + userId, startTime);
......@@ -101,6 +106,12 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "获取人员工时统计报表", notes = "获取人员工时统计报表")
@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) {
log.info("StatisticsController[]getUserWorkTimeStatisticsReport[]input.param{}" + userId, deptId, startDate, endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = statisticsService.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
......@@ -108,6 +119,12 @@ public class StatisticsController extends BaseController {
}
@ApiOperation(value = "获取项目统计报表", notes = "获取项目统计报表")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "deptId", value = "部门主键"),
@ApiImplicitParam(name = "year", value = "统计年"),
@ApiImplicitParam(name = "projectId", value = "项目主键")
})
@GetMapping("/getProjectStatistics")
public Result<List<ProjectStatisticsByMonth>> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) {
log.info("StatisticsController[]getProjectStatistics[]input.param" + userId + deptId + year, projectId);
......@@ -116,6 +133,12 @@ public class StatisticsController extends BaseController {
}
@ApiOperation(value = "导出人员工时统计", notes = "导出人员工时统计")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "deptId", value = "部门主键"),
@ApiImplicitParam(name = "startDate", value = "开始统计时间"),
@ApiImplicitParam(name = "endDate", value = "结束统计时间")
})
@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);
......@@ -128,8 +151,13 @@ public class StatisticsController extends BaseController {
@ApiOperation(value = "导出项目统计明细", notes = "导出项目明细表")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId",value = "用户主键"),
@ApiImplicitParam(name = "year", value = "统计年"),
@ApiImplicitParam(name = "projectIds", value = "项目主键,以逗号隔开")
})
@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);
// 获取excel
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