Commit e289fd64 authored by nie'hong's avatar nie'hong

人员工时统计报表,项目统计报表

parent 02912147
......@@ -76,6 +76,7 @@ public enum BASE_RESP_CODE_ENUM {
REPEAT_WITH_OLDTIME("654", "日期与旧时间冲突"),
BUDGET_CANNOT_BELESSTHAN_ZERO("655", "预算不能小于0"),
ITEMOADUPLICATE("656", "项目OA重复"),
NO_AUTHORITY("657","暂无该权限")
;
......
......@@ -81,10 +81,10 @@
select <include refid="Base_Column_List"/>
from <include refid="table"/>
<where>
<if test="manager_id != null">
<if test="managerId != null">
manager_id = #{managerId}
</if>
<if test="dept_id != null">
<if test="deptId != null">
OR dept_id = #{deptId}
</if>
<if test="deptIds != null">
......@@ -95,6 +95,7 @@
</if>
</where>
</select>
<select id="getProjectsByIds" resultType="cn.wisenergy.model.app.WorkProject">
select <include refid="Base_Column_List"/>
from <include refid="table"/>
......
......@@ -50,20 +50,20 @@
INSERT INTO work_project_time_cost (
project_id,
user_id,
is_overtime,
statistics_start,
statistics_end,
total_time,
cost
cost,
create_time
)
SELECT
project_id,
t.user_id,
is_overtime,
min(work_day),
max(work_day),
sum(work_time / 8),
sum(work_time / 8 * s.day_salary)
sum(work_time / 8 * s.day_salary),
now() AS create_time
FROM
work_time_order t
JOIN work_user_salary s ON t.user_id = s.user_id
......@@ -76,8 +76,8 @@
is_overtime,
YEAR (work_day),
MONTH (work_day)
ON DUPLICATE KEY UPDATE is_overtime =
VALUES(is_overtime),
ON DUPLICATE KEY UPDATE create_time =
VALUES(create_time),
statistics_end =
VALUES(statistics_end),
total_time =
......
......@@ -23,6 +23,7 @@
FROM work_user_role
WHERE user_id = #{userId}
</select>
<select id="getRoleUserLevel" resultType="cn.wisenergy.model.dto.UserRoleLevelDto">
select ur.user_id as 'user_id',r.id as 'role_id',l.name as 'level_name',l.rank as 'rank'
from work_user_role ur join work_role r on ur.role_id = r.id
......
......@@ -28,7 +28,7 @@ public interface StatisticsService {
List<Object> getMonthlyStatistics(Integer userId);
/**
* 获取负责项目在本月的工时汇总:花费工时,工时成本
* 获取负责项目的工时汇总:花费工时,工时成本
*
* @param userId
*/
......@@ -44,7 +44,7 @@ public interface StatisticsService {
HSSFWorkbook exportWorkTimeExcel(GetMonthlyCollectParam param);
/**
* 获取用户所在未结项目的工时统计
* 获取用户管理项目人员工时统计
*
* @param startDate
* @param endDate
......@@ -58,7 +58,8 @@ public interface StatisticsService {
*
* @param userId
* @param deptId
* @param date
* @param year
* @param projectId
* @return
*/
List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId);
......
......@@ -14,6 +14,7 @@ import cn.wisenergy.model.enums.*;
import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkProjectService;
import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.service.utils.UserRoleLevelUtils;
import com.alibaba.excel.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -21,10 +22,7 @@ import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -60,7 +58,7 @@ public class StatisticsServiceImpl implements StatisticsService {
private WorkUserMapper workUserMapper;
@Autowired
private WorkProjectMapper workProjectMapper;
private UserRoleLevelUtils userRoleLevelUtils;
@Autowired
WorkProjectTimeCostMapper workProjectTimeCostMapper;
......@@ -76,8 +74,8 @@ public class StatisticsServiceImpl implements StatisticsService {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
//管理员用户
WorkUser user = workUserService.getById(param.getUserId());
if (!user.getLevel().equals(ManagerEnum.IS_SYSTEM_MANAGER.getCode())) {
List<Integer> role = userRoleLevelUtils.getRole(param.getUserId());
if (!role.contains(ManagerEnum.IS_SYSTEM_MANAGER.getCode())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
}
//默认时间为当月
......@@ -134,6 +132,7 @@ public class StatisticsServiceImpl implements StatisticsService {
public List<Object> getMonthlyStatistics(Integer userId) {
log.info("WorkTimeOrderServiceImpl[]getMonthlyStatistics[]input.param" + userId);
WorkUser user = workUserService.getById(userId);
List<Integer> role = userRoleLevelUtils.getRole(user.getId());
//本月第一天
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
//返回数据对象
......@@ -141,7 +140,7 @@ public class StatisticsServiceImpl implements StatisticsService {
//存放查询条件
Map<String, Object> map = new HashMap<>();
//用户是项目或部门级别,查询审批统计
if (user.getLevel() != ManagerEnum.NOT_MANAGER.getCode()) {
if (role.contains(ManagerEnum.IS_PROJECT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
//以审批人、审核状态、开始时间查询本月审批数量
map.put("reviewerId", userId);
map.put("startDay", firstDayOfMonth);
......@@ -152,7 +151,7 @@ public class StatisticsServiceImpl implements StatisticsService {
Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map);
// 项目级别,获取所管理项目,
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
List<WorkProject> projects = workProjectService.getUserManageProjects(userId);
if (CollectionUtil.isNotEmpty(projects)) {
List<Integer> projectIds = projects.stream().map(WorkProject::getId).collect(Collectors.toList());
......@@ -160,7 +159,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
// 部门级别
if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
map.put("deptId", user.getDeptId());
//填报项目类型编码
int[] workOrderTypeArray = {WorkOrderType.EXTERNAL_WORK.getCode(), WorkOrderType.INTERNAL_WORK.getCode(), WorkOrderType.OTHER_NOT_PROJECT_BUSINESS.getCode()};
......@@ -244,16 +243,21 @@ public class StatisticsServiceImpl implements StatisticsService {
if (userId == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
WorkUser user = workUserService.getById(userId);
// 时间不为空,赋值当月第一天
if (StringUtil.isNotEmpty(startTime)) {
Date currentFirstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
startTime = DateUtil.convertDateToYMDStr(currentFirstDayOfMonth);
}
WorkUser user = workUserService.getById(userId);
// 用户角色
List<Integer> role = userRoleLevelUtils.getRole(user.getId());
// 普通用户
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode())) {
if (role.contains(ManagerEnum.NOT_MANAGER.getCode())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
}
// 查询用户管理的项目
List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId);
if (CollectionUtil.isEmpty(userManageProjects)) {
......@@ -280,7 +284,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<WorkTimeAndCostCollect> collect = workProjectTimeCostMapper.selectList(map);
// 部门和中心级别
if (!user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode()) || role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
// 请假、调休、外部商务、技术交流,内部培训、技术准备、管理,其他非项目/商机工作
types.clear();
map.clear();
......@@ -290,22 +294,23 @@ public class StatisticsServiceImpl implements StatisticsService {
types.add(value.getType());
}
}
if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
map.put("deptId", user.getDeptId());
}
map.put("types", types);
List<WorkTimeAndCostCollect> workTimeAndCostCollect = workTimeOrderMapper.getWorkTimeAndCostCollect(map);
List<String> typeList = workTimeAndCostCollect.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,并且不为项目或商机类型,造对象传前端
// 将查询结果封装在一起
collect.addAll(workTimeAndCostCollect);
// 获取查询结果中的类型
List<String> typeList = collect.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,造对象传前端
for (ProjectTypeEnum value : ProjectTypeEnum.values()) {
if (!typeList.contains(value.getTypeName()) && !value.getTypeName().equals(ProjectTypeEnum.PROJECT.getTypeName()) && !value.getTypeName().equals(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName())) {
if (!typeList.contains(value.getTypeName())) {
WorkTimeAndCostCollect workTimeAndCostCollect1 = new WorkTimeAndCostCollect();
workTimeAndCostCollect1.setType(value.getTypeName());
workTimeAndCostCollect.add(workTimeAndCostCollect1);
collect.add(workTimeAndCostCollect1);
}
}
collect.addAll(workTimeAndCostCollect);
}
for (WorkTimeAndCostCollect workTimeAndCostCollect : collect) {
// 类型的总工时
......@@ -337,22 +342,17 @@ public class StatisticsServiceImpl implements StatisticsService {
HSSFWorkbook sheets = new HSSFWorkbook();
// 创建表
HSSFSheet sheet = sheets.createSheet("Sheet1");
// 节假日样式,底色为红色,其余样式与普通项目
HSSFCellStyle cellStyle1 = sheets.createCellStyle();
// cellStyle1.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
cellStyle1.setFillForegroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
// 设置全填充
cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 普通样式对象
HSSFCellStyle cellStyle = sheets.createCellStyle();
// 垂直、水平中心对齐
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle1.setAlignment(HorizontalAlignment.CENTER);
// 自动换行
cellStyle.setWrapText(true);
cellStyle1.setWrapText(true);
HSSFCellStyle cellStyle = this.createOrdinaryCellStyle(sheets);
// 节假日样式,底色为绿色,其余样式与普通相同
HSSFCellStyle cellStyle1 = this.createOrdinaryCellStyle(sheets);
cellStyle1.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIGHT_GREEN.getIndex());
// 当日工时小于8,底色为红色,其余样式与普通相同
HSSFCellStyle cellStyle2 = this.createOrdinaryCellStyle(sheets);
cellStyle2.setFillForegroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
// 第一列列宽
sheet.setColumnWidth(1, EXCEL_WIDTH);
// 获取本月应上班日期集合
......@@ -403,16 +403,51 @@ public class StatisticsServiceImpl implements StatisticsService {
emptyCell.setCellValue(timeAndType.getType() + timeAndType.getWorkTime().toString());
}
}
// 给该行每个单元格设置单元格样式
for (Cell cell : row_i) {
cell.setCellStyle(cellStyle);
}
// 换行
i++;
}
// 给节假日单元格设置单元格格式
for (int j = 0; j < list.size(); j++) {
HSSFRow row = sheet.getRow(j + 1);
for (int r = 0; r < dayCount; r++) {
HSSFCell cell = null;
if (row.getCell(r + 3) == null) {
cell = row.createCell(r + 3);
} else {
cell = row.getCell(r + 3);
}
// 节假日单元格标绿色
if (!days.contains(r + 1)) {
cell.setCellStyle(cellStyle1);
}
// 获取单元格中的工时,当日总工时小于8,则单元格底色为红色
String cellValue = ExcelUtils.getCellValue(cell, true);
if (StringUtil.isNotEmpty(cellValue)) {
Integer numberOfString = this.getNumberOfString(cellValue);
if (numberOfString != null && numberOfString < 8) {
cell.setCellStyle(cellStyle2);
}
}
}
}
return sheets;
}
// 将字符串中的1到9的数字相加
private Integer getNumberOfString(String value) {
value = value.trim();
if (StringUtil.isEmpty(value)) {
return null;
}
Integer sum = 0;
for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) >= 48 && value.charAt(i) <= 57) {
sum += value.charAt(i) - 48;
}
}
return sum;
}
@Override
public List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, String startDate, String endDate, Integer status) {
log.info("StatisticsServiceImpl[]getUserWorkTimeStatisticsReport[]");
......@@ -422,9 +457,11 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取用户负责项目主键集合
List<WorkProject> userManageProjects = workProjectService.getUserManageProjects(userId);
// 为空则提前结束
if (CollectionUtil.isEmpty(userManageProjects)) {
// throw new BaseCustomException(BASE_RESP_CODE_ENUM.MANAGER_NOT_PROJECT);
return null;
}
// 提取项目主键
List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList());
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = new ArrayList<>();
......@@ -435,21 +472,34 @@ public class StatisticsServiceImpl implements StatisticsService {
ProjectWorkTimeAndType projectWorkTimeAndType = new ProjectWorkTimeAndType();
projectWorkTimeAndType.setProjectId(userManageProject.getId());
projectWorkTimeAndType.setProjectName(userManageProject.getProjectName());
projectWorkTimeAndType.setWorkTime(0);
projectWorkTimeAndType.setIsOvertime("正常");
projectWorkTimeAndTypes.add(projectWorkTimeAndType);
projectWorkTimeAndType.setIsOvertime("加班");
projectWorkTimeAndTypes.add(projectWorkTimeAndType);
}
userWorkTimeStatisticsByProject.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
userWorkTimeStatisticsByProjects.add(userWorkTimeStatisticsByProject);
// 查询人员项目工时统计
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(startDate, endDate, status, projectIds);
// 取出单人的项目工时统计
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) {
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userWorkTimeStatisticsByProjects) {
int totalTime = 0;
// 遍历一个人所有项目统计,计算所有项目所有工时总和
for (ProjectWorkTimeAndType projectWorkTimeAndType : userProjectWorkTimeStatistic.getProjectWorkTimeAndType()) {
totalTime += projectWorkTimeAndType.getWorkTime();
// 计算项目的所有人员工时总和
for (ProjectWorkTimeAndType workTimeAndType : projectWorkTimeAndTypes) {
if (workTimeAndType.getProjectName().equals(projectWorkTimeAndType.getProjectName()) && workTimeAndType.getIsOvertime().equals(projectWorkTimeAndType.getIsOvertime())) {
workTimeAndType.setWorkTime(workTimeAndType.getWorkTime()+projectWorkTimeAndType.getWorkTime());
}
}
}
userProjectWorkTimeStatistic.setTotalTime(totalTime);
}
// 返回结果第一条数据是所有项目的名称和工时总计
userWorkTimeStatisticsByProject.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
userWorkTimeStatisticsByProjects.add(userWorkTimeStatisticsByProject);
// 将项目名称集合与人员工时统计封装在一起
userWorkTimeStatisticsByProjects.addAll(userProjectWorkTimeStatistics);
return userWorkTimeStatisticsByProjects;
......@@ -459,7 +509,10 @@ public class StatisticsServiceImpl implements StatisticsService {
public List<ProjectStatisticsByMonth> getProjectStatistics(Integer userId, Integer deptId, Integer year, Integer projectId) {
log.info("StatisticsServiceImpl[]getProjectStatistics[]input.param" + userId + deptId + year + projectId);
// 权限判断
List<Integer> role = userRoleLevelUtils.getRole(userId);
if (!role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
// 默认查询时间为当前
if (year == null) {
year = DateUtil.getYear(new Date());
......@@ -574,4 +627,30 @@ public class StatisticsServiceImpl implements StatisticsService {
return currentMonthFilledDays;
}
// 设置单元格基本样式
HSSFCellStyle createOrdinaryCellStyle(HSSFWorkbook sheets) {
HSSFCellStyle cellStyle = sheets.createCellStyle();
// 设置全填充
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 垂直、水平中心对齐
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setBorderBottom(BorderStyle.THIN);
//设置下边框的边框线颜色(颜色和上述的颜色对照表是一样的)
cellStyle.setBottomBorderColor(IndexedColors.SKY_BLUE.getIndex());
cellStyle.setBorderLeft(BorderStyle.THIN);
//左边框
cellStyle.setLeftBorderColor(IndexedColors.SKY_BLUE.getIndex());
cellStyle.setBorderTop(BorderStyle.THIN);
//上边框
cellStyle.setRightBorderColor(IndexedColors.SKY_BLUE.getIndex());
cellStyle.setBorderRight(BorderStyle.THIN);
//右边框
cellStyle.setTopBorderColor(IndexedColors.SKY_BLUE.getIndex());
// 自动换行
cellStyle.setWrapText(true);
return cellStyle;
}
}
......@@ -66,7 +66,7 @@ public class WorkProjectServiceImpl implements WorkProjectService {
private WorkProjectChangeService workProjectChangeService;
@Autowired
private WorkUserDeptService workUserDeptService;
private UserRoleLevelUtils userRoleLevelUtils;
/**
* 功能:根据项目id获取项目
......@@ -145,8 +145,9 @@ public class WorkProjectServiceImpl implements WorkProjectService {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
WorkUser user = workUserService.getById(userId);
List<Integer> role = userRoleLevelUtils.getRole(user.getId());
//普通用户
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER)) {
if (role.contains(ManagerEnum.NOT_MANAGER.getCode())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.THE_USER_NOT_MANAGER_PLASE_MANAGER_LOGIN);
}
//存放项目列表
......@@ -154,14 +155,15 @@ public class WorkProjectServiceImpl implements WorkProjectService {
//存放查询条件
HashMap<String, Object> map = new HashMap<>();
// 查询项目表中管理为用户的项目集合,用户为项目经理,但level可能不为1
// 查询项目表中管理为用户的项目集合,
map.put("managerId", userId);
//用户是部门级别,查询该部门下的所有项目
if (user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
map.remove("managerId");
map.put("deptId", user.getDeptId());
}
//中心级别的用户查看中心下所有部门的所有项目
if (user.getLevel().equals(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
if (role.contains(ManagerEnum.IS_CENTRE_DIRECTOR.getCode())) {
//获取中心信息
WorkCentre workCentre = workCentreMapper.getByManagerId(user.getId());
if (workCentre == null) {
......
......@@ -128,5 +128,4 @@ public class StatisticsController extends BaseController {
return getResult(projectStatisticsByMonths);
}
}
\ 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