fix
This commit is contained in:
parent
2fd591162a
commit
3096d7f37b
@ -1,12 +1,13 @@
|
||||
package com.lz.modules.app.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.common.utils.R;
|
||||
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.StaffEntity;
|
||||
import com.lz.modules.app.enums.ResultRecordStatusEnum;
|
||||
import com.lz.modules.app.enums.ResultRecordTypeEnum;
|
||||
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.StaffService;
|
||||
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.ResultRecordService;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
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
|
||||
@ -49,36 +54,31 @@ public class ReportResultController extends AbstractController{
|
||||
|
||||
|
||||
@RequestMapping("chart")
|
||||
public R reportChart(String monthTime){
|
||||
public R reportChart(String monthTime,String departmentId){
|
||||
if(StringUtil.isBlank(monthTime)){
|
||||
String time = LocalDate.now().toString();
|
||||
monthTime = time.substring(0,time.length()-3);
|
||||
}
|
||||
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> sortStaffLevels = new ArrayList<>();
|
||||
// 0人是否需要展示
|
||||
Map<String,Integer> map = Maps.newHashMap();
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> datas = new ArrayList<>();
|
||||
int konwn = 0;
|
||||
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);
|
||||
names.add(staffLevel.getCategory());
|
||||
datas.add(BigDecimalUtil.div(Double.valueOf(staffLevel.getNumber()),Double.valueOf(total),2));
|
||||
konwn = konwn + staffLevel.getNumber();
|
||||
logger.info("等级:" + staffLevel.getCategory() + " 人数:" + staffLevel.getNumber());
|
||||
}
|
||||
names.add("未知");
|
||||
datas.add(BigDecimalUtil.div(Double.valueOf((total - konwn)),Double.valueOf(total),2));
|
||||
//部门等级占比
|
||||
GraphicsDto dto = new GraphicsDto();
|
||||
dto.setRows(start);
|
||||
@ -86,9 +86,12 @@ public class ReportResultController extends AbstractController{
|
||||
dto = new GraphicsDto();
|
||||
dto.setRows(end);
|
||||
data.setResultDistribution(dto);
|
||||
dto = new GraphicsDto();
|
||||
dto.setRows(sortStaffLevels);
|
||||
data.setStaffDistribution(dto);
|
||||
CharBarDto barDto= new CharBarDto();
|
||||
barDto.setNames(names);
|
||||
barDto.setDatas(datas);
|
||||
barDto.setTotal(total);
|
||||
data.setStaffDistribution(barDto);
|
||||
data.setMonthTime(YearMonth.now().toString());
|
||||
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);
|
||||
}*/
|
||||
20
src/main/java/com/lz/modules/app/dto/CharBarDto.java
Normal file
20
src/main/java/com/lz/modules/app/dto/CharBarDto.java
Normal 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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -1,12 +1,9 @@
|
||||
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.GraphicsStatisticalDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: djc
|
||||
* @Desc:
|
||||
@ -19,8 +16,8 @@ public class ReportChartResp {
|
||||
//月末结果
|
||||
private GraphicsDto resultDistribution;
|
||||
//个人等级占比
|
||||
private GraphicsDto staffDistribution;
|
||||
//部门等级占比
|
||||
private GraphicsDto departmentDistribution;
|
||||
private CharBarDto staffDistribution;
|
||||
//当前月份
|
||||
private String monthTime;
|
||||
|
||||
}
|
||||
|
||||
@ -75,7 +75,11 @@ public interface StaffService extends IService<StaffEntity> {
|
||||
|
||||
SysUserEntity getUser(String userName);
|
||||
|
||||
//查询部门下的所有人员 包括子部门下人员
|
||||
List<Long> selectAllStaffByDepartmentId(String departmentId);
|
||||
//查询部门下的所有子部门
|
||||
List<String> selectAllDeparmentIdsByDepartmentParentId(String departmentId);
|
||||
//统计部门下的人数
|
||||
int countStaffByAllDeparmentIds(List<String> deparmentIds);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -6,10 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.lz.common.utils.DateUtils;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.Query;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.common.utils.*;
|
||||
import com.lz.modules.app.dao.DepartmentsDao;
|
||||
import com.lz.modules.app.dto.*;
|
||||
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.job.model.responseBo.DepartmentStaffBo;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -26,6 +24,8 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service("staffService")
|
||||
@ -49,6 +49,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
|
||||
DepartmentsStaffRelateService departmentsStaffRelateService;
|
||||
@Autowired
|
||||
private DepartmentsDao departmentsDao;
|
||||
@Autowired
|
||||
private StaffService staffService;
|
||||
|
||||
|
||||
|
||||
@ -378,11 +380,42 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> selectAllStaffByDepartmentId(String departmentId) {
|
||||
//154344269,154322459,154274609,154254673
|
||||
List<String> parentsIds = Lists.newArrayList("154344269","154322459","154274609","154254673");
|
||||
public List<String> selectAllDeparmentIdsByDepartmentParentId(String departmentId) {
|
||||
//默认所有
|
||||
if(StringUtil.isBlank(departmentId)){
|
||||
departmentId = "1";
|
||||
}
|
||||
List<String> parentsIds = Lists.newArrayList(departmentId);
|
||||
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){
|
||||
List<String> childs = departmentsDao.selectDepartmentIdsByparentIds(parentIds);
|
||||
/* while (childs!=null){
|
||||
|
||||
}*/
|
||||
return null;
|
||||
|
||||
|
||||
if(CollectionUtils.isEmpty(childs)){
|
||||
return departmentsList;
|
||||
}
|
||||
departmentsList.addAll(childs);
|
||||
return getAllChilds(departmentsList,childs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ package com.lz.modules.sys.dao.app;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
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.req.ResultRecordReq;
|
||||
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<ChartDto> departmentDistribution(@Param("monthTime") String monthTime);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package com.lz.modules.sys.service.app;
|
||||
|
||||
import com.lz.modules.app.dto.ChartDto;
|
||||
import com.lz.modules.app.dto.GraphicsStatisticalDto;
|
||||
|
||||
import java.util.List;
|
||||
@ -18,7 +17,7 @@ public interface ChartService {
|
||||
* @param monthTime
|
||||
* @return
|
||||
*/
|
||||
List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime);
|
||||
List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
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.entity.StaffEntity;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
@ -79,11 +78,4 @@ public interface ResultRecordService extends IService<ResultRecord> {
|
||||
*/
|
||||
List<GraphicsStatisticalDto> staffDistribution(String monthTime);
|
||||
|
||||
/**
|
||||
* 部门等级占比
|
||||
* @param monthTime
|
||||
* @return
|
||||
*/
|
||||
List<ChartDto> departmentDistribution(String monthTime);
|
||||
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
package com.lz.modules.sys.service.app.impl;
|
||||
|
||||
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.entity.StaffEntity;
|
||||
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.service.app.ChartService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -29,15 +26,18 @@ public class ChartServiceImpl implements ChartService {
|
||||
@Autowired
|
||||
private StaffService staffService;
|
||||
@Override
|
||||
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime) {
|
||||
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) {
|
||||
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>()
|
||||
.eq("is_delete", 0)
|
||||
.eq("type", type)
|
||||
.like("month_time",monthTime)
|
||||
.ne("status", ResultRecordStatusEnum.CREATE.getStatus()));
|
||||
//已完成
|
||||
int finished = resultRecordService.count(new QueryWrapper<ResultRecord>()
|
||||
.eq("is_delete", 0)
|
||||
.eq("type", type)
|
||||
@ -45,17 +45,23 @@ public class ChartServiceImpl implements ChartService {
|
||||
.in("status", ResultRecordStatusEnum.REFUSE.getStatus(),ResultRecordStatusEnum.AGREE.getStatus()));
|
||||
|
||||
GraphicsStatisticalDto dto = new GraphicsStatisticalDto();
|
||||
dto.setCategory("未提交");
|
||||
dto.setNumber(total-commit);
|
||||
dtos.add(dto);
|
||||
dto = new GraphicsStatisticalDto();
|
||||
dto.setCategory("已完成");
|
||||
dto.setNumber(finished);
|
||||
dtos.add(dto);
|
||||
dto = new GraphicsStatisticalDto();
|
||||
dto.setCategory("审核中");
|
||||
dto.setNumber(commit-finished);
|
||||
dtos.add(dto);
|
||||
if(total-commit>0){
|
||||
dto.setCategory("未提交");
|
||||
dto.setNumber(total-commit);
|
||||
dtos.add(dto);
|
||||
}
|
||||
if(finished>0){
|
||||
dto = new GraphicsStatisticalDto();
|
||||
dto.setCategory("已完成");
|
||||
dto.setNumber(finished);
|
||||
dtos.add(dto);
|
||||
}
|
||||
if(commit-finished>0){
|
||||
dto = new GraphicsStatisticalDto();
|
||||
dto.setCategory("审核中");
|
||||
dto.setNumber(commit-finished);
|
||||
dtos.add(dto);
|
||||
}
|
||||
return dtos;
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.*;
|
||||
import com.lz.modules.app.dao.DepartmentsDao;
|
||||
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.GraphicsStatisticalDto;
|
||||
import com.lz.modules.app.entity.DepartmentsEntity;
|
||||
@ -622,9 +621,4 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
public List<GraphicsStatisticalDto> staffDistribution(String monthTime) {
|
||||
return resultRecordMapper.staffDistribution(monthTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChartDto> departmentDistribution(String monthTime) {
|
||||
return resultRecordMapper.departmentDistribution(monthTime);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,12 +259,7 @@
|
||||
</select>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
<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 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>
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user