This commit is contained in:
杜建超 2020-09-22 11:33:30 +08:00
parent 2fd591162a
commit 3096d7f37b
12 changed files with 154 additions and 112 deletions

View File

@ -1,12 +1,13 @@
package com.lz.modules.app.controller; package com.lz.modules.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.lz.common.utils.BigDecimalUtil;
import com.google.common.collect.Maps;
import com.lz.common.utils.R; import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil; import com.lz.common.utils.StringUtil;
import com.lz.modules.app.dto.*; import com.lz.modules.app.dto.CharBarDto;
import com.lz.modules.app.dto.DepartmentsDto;
import com.lz.modules.app.dto.GraphicsDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.enums.ResultRecordStatusEnum; import com.lz.modules.app.enums.ResultRecordStatusEnum;
import com.lz.modules.app.enums.ResultRecordTypeEnum; import com.lz.modules.app.enums.ResultRecordTypeEnum;
import com.lz.modules.app.resp.OwnResultResp; import com.lz.modules.app.resp.OwnResultResp;
@ -15,16 +16,20 @@ import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService; import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.app.service.StaffService; import com.lz.modules.app.service.StaffService;
import com.lz.modules.sys.controller.AbstractController; import com.lz.modules.sys.controller.AbstractController;
import com.lz.modules.sys.entity.app.ResultRecord;
import com.lz.modules.sys.service.app.ChartService; import com.lz.modules.sys.service.app.ChartService;
import com.lz.modules.sys.service.app.ResultRecordService; import com.lz.modules.sys.service.app.ResultRecordService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/** /**
* @Author: djc * @Author: djc
@ -49,36 +54,31 @@ public class ReportResultController extends AbstractController{
@RequestMapping("chart") @RequestMapping("chart")
public R reportChart(String monthTime){ public R reportChart(String monthTime,String departmentId){
if(StringUtil.isBlank(monthTime)){ if(StringUtil.isBlank(monthTime)){
String time = LocalDate.now().toString(); String time = LocalDate.now().toString();
monthTime = time.substring(0,time.length()-3); monthTime = time.substring(0,time.length()-3);
} }
ReportChartResp data = new ReportChartResp(); ReportChartResp data = new ReportChartResp();
//月初目标 //月初目标
List<GraphicsStatisticalDto> start = chartService.resultProgressDistribution(ResultRecordTypeEnum.TARGET.getType(),monthTime); List<GraphicsStatisticalDto> start = chartService.resultProgressDistribution(ResultRecordTypeEnum.TARGET.getType(),monthTime,"");
//月末结果 //月末结果
List<GraphicsStatisticalDto> end = chartService.resultProgressDistribution(ResultRecordTypeEnum.RESULT.getType(),monthTime); List<GraphicsStatisticalDto> end = chartService.resultProgressDistribution(ResultRecordTypeEnum.RESULT.getType(),monthTime,"");
//人员等级分布 //人员等级分布
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(departmentId);
int total = staffService.countStaffByAllDeparmentIds(allDeparmentIds);
List<GraphicsStatisticalDto> staffLevels = resultRecordService.staffDistribution(monthTime); List<GraphicsStatisticalDto> staffLevels = resultRecordService.staffDistribution(monthTime);
List<String> names = new ArrayList<>();
List<GraphicsStatisticalDto> sortStaffLevels = new ArrayList<>(); List<Double> datas = new ArrayList<>();
// 0人是否需要展示 int konwn = 0;
Map<String,Integer> map = Maps.newHashMap();
for (GraphicsStatisticalDto staffLevel : staffLevels) { for (GraphicsStatisticalDto staffLevel : staffLevels) {
map.put(staffLevel.getCategory(),staffLevel.getNumber()); names.add(staffLevel.getCategory());
} datas.add(BigDecimalUtil.div(Double.valueOf(staffLevel.getNumber()),Double.valueOf(total),2));
// 默认等级赋予默认值并排序 konwn = konwn + staffLevel.getNumber();
for (String level : levels) { logger.info("等级:" + staffLevel.getCategory() + " 人数:" + staffLevel.getNumber());
GraphicsStatisticalDto dto = new GraphicsStatisticalDto();
dto.setCategory(level);
if(!map.containsKey(level)){
dto.setNumber(0);
}else {
dto.setNumber(map.get(level));
}
sortStaffLevels.add(dto);
} }
names.add("未知");
datas.add(BigDecimalUtil.div(Double.valueOf((total - konwn)),Double.valueOf(total),2));
//部门等级占比 //部门等级占比
GraphicsDto dto = new GraphicsDto(); GraphicsDto dto = new GraphicsDto();
dto.setRows(start); dto.setRows(start);
@ -86,9 +86,12 @@ public class ReportResultController extends AbstractController{
dto = new GraphicsDto(); dto = new GraphicsDto();
dto.setRows(end); dto.setRows(end);
data.setResultDistribution(dto); data.setResultDistribution(dto);
dto = new GraphicsDto(); CharBarDto barDto= new CharBarDto();
dto.setRows(sortStaffLevels); barDto.setNames(names);
data.setStaffDistribution(dto); barDto.setDatas(datas);
barDto.setTotal(total);
data.setStaffDistribution(barDto);
data.setMonthTime(YearMonth.now().toString());
return R.ok().put("data",data); return R.ok().put("data",data);
} }
@ -157,3 +160,25 @@ public class ReportResultController extends AbstractController{
} }
} }
// 0人是否需要展示
/* List<GraphicsStatisticalDto> sortStaffLevels = new ArrayList<>();
Map<String,Integer> map = Maps.newHashMap();
for (GraphicsStatisticalDto staffLevel : staffLevels) {
map.put(staffLevel.getCategory(),staffLevel.getNumber());
}
// 默认等级赋予默认值并排序
for (String level : levels) {
GraphicsStatisticalDto dto = new GraphicsStatisticalDto();
dto.setCategory(level);
if(!map.containsKey(level)){
dto.setNumber(0);
}else {
dto.setNumber(map.get(level));
}
sortStaffLevels.add(dto);
}*/

View File

@ -0,0 +1,20 @@
package com.lz.modules.app.dto;
import lombok.Data;
import java.util.List;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/21 10:21
*/
@Data
public class CharBarDto {
private List<String> names;
private List<Double> datas;
private int total;
}

View File

@ -1,16 +0,0 @@
package com.lz.modules.app.dto;
import lombok.Data;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/16 16:39
*/
@Data
public class ChartDto {
//属性名
private String name;
//属性值
private String value;
}

View File

@ -1,12 +1,9 @@
package com.lz.modules.app.resp; package com.lz.modules.app.resp;
import com.lz.modules.app.dto.ChartDto; import com.lz.modules.app.dto.CharBarDto;
import com.lz.modules.app.dto.GraphicsDto; import com.lz.modules.app.dto.GraphicsDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* @Author: djc * @Author: djc
* @Desc: * @Desc:
@ -19,8 +16,8 @@ public class ReportChartResp {
//月末结果 //月末结果
private GraphicsDto resultDistribution; private GraphicsDto resultDistribution;
//个人等级占比 //个人等级占比
private GraphicsDto staffDistribution; private CharBarDto staffDistribution;
//部门等级占比 //当前月份
private GraphicsDto departmentDistribution; private String monthTime;
} }

View File

@ -75,7 +75,11 @@ public interface StaffService extends IService<StaffEntity> {
SysUserEntity getUser(String userName); SysUserEntity getUser(String userName);
//查询部门下的所有人员 包括子部门下人员 //查询部门下的所有子部门
List<Long> selectAllStaffByDepartmentId(String departmentId); List<String> selectAllDeparmentIdsByDepartmentParentId(String departmentId);
//统计部门下的人数
int countStaffByAllDeparmentIds(List<String> deparmentIds);
} }

View File

@ -6,10 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.lz.common.utils.DateUtils; import com.lz.common.utils.*;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.Query;
import com.lz.common.utils.R;
import com.lz.modules.app.dao.DepartmentsDao; import com.lz.modules.app.dao.DepartmentsDao;
import com.lz.modules.app.dto.*; import com.lz.modules.app.dto.*;
import com.lz.modules.app.dao.StaffDao; import com.lz.modules.app.dao.StaffDao;
@ -17,6 +14,7 @@ import com.lz.modules.app.entity.*;
import com.lz.modules.app.service.*; import com.lz.modules.app.service.*;
import com.lz.modules.job.model.responseBo.DepartmentStaffBo; import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
import com.lz.modules.sys.entity.SysUserEntity; import com.lz.modules.sys.entity.SysUserEntity;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,6 +24,8 @@ import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service("staffService") @Service("staffService")
@ -49,6 +49,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
DepartmentsStaffRelateService departmentsStaffRelateService; DepartmentsStaffRelateService departmentsStaffRelateService;
@Autowired @Autowired
private DepartmentsDao departmentsDao; private DepartmentsDao departmentsDao;
@Autowired
private StaffService staffService;
@ -378,11 +380,42 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
@Override @Override
public List<Long> selectAllStaffByDepartmentId(String departmentId) { public List<String> selectAllDeparmentIdsByDepartmentParentId(String departmentId) {
//154344269,154322459,154274609,154254673 //默认所有
List<String> parentsIds = Lists.newArrayList("154344269","154322459","154274609","154254673"); if(StringUtil.isBlank(departmentId)){
departmentId = "1";
}
List<String> parentsIds = Lists.newArrayList(departmentId);
List<String> departmentsList = new ArrayList<>(); List<String> departmentsList = new ArrayList<>();
return null; List<String> childs = departmentsDao.selectDepartmentIdsByparentIds(parentsIds);
if(CollectionUtils.isEmpty(childs)){
departmentsList.addAll(parentsIds);
return departmentsList;
}
departmentsList.addAll(childs);
List<String> allChilds = getAllChilds(departmentsList, childs);
return allChilds;
}
@Override
public int countStaffByAllDeparmentIds(List<String> deparmentIds) {
if(CollectionUtils.isEmpty(deparmentIds)){
return 0;
}
//获取所有子部门
List<DepartmentsStaffRelateEntity> list = departmentsStaffRelateService.list(new QueryWrapper<DepartmentsStaffRelateEntity>()
.select("staff_id")
.eq("is_delete", 0)
.in("department_id", deparmentIds));
if(CollectionUtils.isEmpty(list)){
return 0;
}
//获取人员个数去重
List<String> staffs = list.stream().map(e -> e.getStaffId() + "").collect(Collectors.toList());
List<String> staffdistincts = staffs.stream().distinct().collect(Collectors.toList());
return staffdistincts.size();
} }
/** /**
@ -393,12 +426,11 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
*/ */
private List<String> getAllChilds(List<String> departmentsList,List<String> parentIds){ private List<String> getAllChilds(List<String> departmentsList,List<String> parentIds){
List<String> childs = departmentsDao.selectDepartmentIdsByparentIds(parentIds); List<String> childs = departmentsDao.selectDepartmentIdsByparentIds(parentIds);
/* while (childs!=null){ if(CollectionUtils.isEmpty(childs)){
return departmentsList;
}*/ }
return null; departmentsList.addAll(childs);
return getAllChilds(departmentsList,childs);
} }

View File

@ -10,7 +10,6 @@ package com.lz.modules.sys.dao.app;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lz.modules.app.dto.ChartDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto; import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.req.ResultRecordReq; import com.lz.modules.app.req.ResultRecordReq;
import com.lz.modules.app.resp.OwnResultResp; import com.lz.modules.app.resp.OwnResultResp;
@ -57,9 +56,4 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
List<GraphicsStatisticalDto> staffDistribution(@Param("monthTime") String monthTime); List<GraphicsStatisticalDto> staffDistribution(@Param("monthTime") String monthTime);
List<ChartDto> departmentDistribution(@Param("monthTime") String monthTime);
} }

View File

@ -1,6 +1,5 @@
package com.lz.modules.sys.service.app; package com.lz.modules.sys.service.app;
import com.lz.modules.app.dto.ChartDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto; import com.lz.modules.app.dto.GraphicsStatisticalDto;
import java.util.List; import java.util.List;
@ -18,7 +17,7 @@ public interface ChartService {
* @param monthTime * @param monthTime
* @return * @return
*/ */
List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime); List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId);

View File

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.common.emun.WorkMsgTypeEnum; import com.lz.common.emun.WorkMsgTypeEnum;
import com.lz.common.utils.PageUtils; import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R; import com.lz.common.utils.R;
import com.lz.modules.app.dto.ChartDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto; import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.entity.StaffEntity; import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.req.ResultRecordReq; import com.lz.modules.app.req.ResultRecordReq;
@ -79,11 +78,4 @@ public interface ResultRecordService extends IService<ResultRecord> {
*/ */
List<GraphicsStatisticalDto> staffDistribution(String monthTime); List<GraphicsStatisticalDto> staffDistribution(String monthTime);
/**
* 部门等级占比
* @param monthTime
* @return
*/
List<ChartDto> departmentDistribution(String monthTime);
} }

View File

@ -1,8 +1,6 @@
package com.lz.modules.sys.service.app.impl; package com.lz.modules.sys.service.app.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lz.common.utils.StringUtil;
import com.lz.modules.app.dto.ChartDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto; import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.entity.StaffEntity; import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.enums.ResultRecordStatusEnum; import com.lz.modules.app.enums.ResultRecordStatusEnum;
@ -10,7 +8,6 @@ import com.lz.modules.app.service.StaffService;
import com.lz.modules.sys.entity.app.ResultRecord; import com.lz.modules.sys.entity.app.ResultRecord;
import com.lz.modules.sys.service.app.ChartService; import com.lz.modules.sys.service.app.ChartService;
import com.lz.modules.sys.service.app.ResultRecordService; import com.lz.modules.sys.service.app.ResultRecordService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,15 +26,18 @@ public class ChartServiceImpl implements ChartService {
@Autowired @Autowired
private StaffService staffService; private StaffService staffService;
@Override @Override
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime) { public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) {
List<GraphicsStatisticalDto> dtos = new ArrayList<>(); List<GraphicsStatisticalDto> dtos = new ArrayList<>();
int total = staffService.count(new QueryWrapper<StaffEntity>().eq("is_delete", 0)); //获取所有人员总数
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(departmentId);
int total = staffService.countStaffByAllDeparmentIds(allDeparmentIds);
//已提交
int commit = resultRecordService.count(new QueryWrapper<ResultRecord>() int commit = resultRecordService.count(new QueryWrapper<ResultRecord>()
.eq("is_delete", 0) .eq("is_delete", 0)
.eq("type", type) .eq("type", type)
.like("month_time",monthTime) .like("month_time",monthTime)
.ne("status", ResultRecordStatusEnum.CREATE.getStatus())); .ne("status", ResultRecordStatusEnum.CREATE.getStatus()));
//已完成
int finished = resultRecordService.count(new QueryWrapper<ResultRecord>() int finished = resultRecordService.count(new QueryWrapper<ResultRecord>()
.eq("is_delete", 0) .eq("is_delete", 0)
.eq("type", type) .eq("type", type)
@ -45,17 +45,23 @@ public class ChartServiceImpl implements ChartService {
.in("status", ResultRecordStatusEnum.REFUSE.getStatus(),ResultRecordStatusEnum.AGREE.getStatus())); .in("status", ResultRecordStatusEnum.REFUSE.getStatus(),ResultRecordStatusEnum.AGREE.getStatus()));
GraphicsStatisticalDto dto = new GraphicsStatisticalDto(); GraphicsStatisticalDto dto = new GraphicsStatisticalDto();
if(total-commit>0){
dto.setCategory("未提交"); dto.setCategory("未提交");
dto.setNumber(total-commit); dto.setNumber(total-commit);
dtos.add(dto); dtos.add(dto);
}
if(finished>0){
dto = new GraphicsStatisticalDto(); dto = new GraphicsStatisticalDto();
dto.setCategory("已完成"); dto.setCategory("已完成");
dto.setNumber(finished); dto.setNumber(finished);
dtos.add(dto); dtos.add(dto);
}
if(commit-finished>0){
dto = new GraphicsStatisticalDto(); dto = new GraphicsStatisticalDto();
dto.setCategory("审核中"); dto.setCategory("审核中");
dto.setNumber(commit-finished); dto.setNumber(commit-finished);
dtos.add(dto); dtos.add(dto);
}
return dtos; return dtos;
} }

View File

@ -7,7 +7,6 @@ import com.lz.common.emun.WorkMsgTypeEnum;
import com.lz.common.utils.*; import com.lz.common.utils.*;
import com.lz.modules.app.dao.DepartmentsDao; import com.lz.modules.app.dao.DepartmentsDao;
import com.lz.modules.app.dao.DepartmentsStaffRelateDao; import com.lz.modules.app.dao.DepartmentsStaffRelateDao;
import com.lz.modules.app.dto.ChartDto;
import com.lz.modules.app.dto.EmployeesDto; import com.lz.modules.app.dto.EmployeesDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto; import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.entity.DepartmentsEntity; import com.lz.modules.app.entity.DepartmentsEntity;
@ -622,9 +621,4 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
public List<GraphicsStatisticalDto> staffDistribution(String monthTime) { public List<GraphicsStatisticalDto> staffDistribution(String monthTime) {
return resultRecordMapper.staffDistribution(monthTime); return resultRecordMapper.staffDistribution(monthTime);
} }
@Override
public List<ChartDto> departmentDistribution(String monthTime) {
return resultRecordMapper.departmentDistribution(monthTime);
}
} }

View File

@ -259,12 +259,7 @@
</select> </select>
<select id="staffDistribution" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto"> <select id="staffDistribution" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto">
SELECT count(score_level) number ,CASE score_level when 0 THEN '未知' ELSE score_level END category from lz_result_record where is_delete = 0 and status =4 and type =2 and DATE_FORMAT(month_time,'%Y-%m') = #{monthTime} GROUP BY score_level SELECT count(score_level) number ,score_level category from lz_result_record where is_delete = 0 and status =4 and type =2 and score_level !=0 and DATE_FORMAT(month_time,'%Y-%m') = #{monthTime} GROUP BY score_level
</select>
<select id="departmentDistribution" resultType="com.lz.modules.app.dto.ChartDto">
SELECT count(score_level) value,score_level name from lz_result_record where is_delete = 0 and status =4 and type =2 and DATE_FORMAT(month_time,'%Y-%m') = #{monthTime} GROUP BY score_level
</select> </select>
</mapper> </mapper>