This commit is contained in:
杜建超 2020-09-23 18:05:10 +08:00
parent d516af8bc3
commit 00a30281e1
12 changed files with 259 additions and 52 deletions

View File

@ -1,15 +1,14 @@
package com.lz.modules.app.controller;
import com.lz.common.utils.BigDecimalUtil;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
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.dto.*;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.enums.ResultRecordStatusEnum;
import com.lz.modules.app.enums.ResultRecordTypeEnum;
import com.lz.modules.app.req.ReportListReq;
import com.lz.modules.app.resp.OwnResultResp;
import com.lz.modules.app.resp.ReportChartResp;
import com.lz.modules.app.service.DepartmentsService;
@ -37,7 +36,7 @@ import java.util.List;
* @Date: 2020/9/11 10:22
*/
@RestController
@RequestMapping("/report")
@RequestMapping("/result")
public class ReportResultController extends AbstractController{
@Autowired
private ResultRecordService resultRecordService;
@ -58,40 +57,20 @@ public class ReportResultController extends AbstractController{
if(StringUtil.isBlank(selectMonthTime)){
selectMonthTime = YearMonth.now().toString();
}
ReportChartResp data = new ReportChartResp();
//月初目标
List<GraphicsStatisticalDto> start = chartService.resultProgressDistribution(ResultRecordTypeEnum.TARGET.getType(),selectMonthTime,departmentId);
//月末结果
List<GraphicsStatisticalDto> end = chartService.resultProgressDistribution(ResultRecordTypeEnum.RESULT.getType(),selectMonthTime,departmentId);
//人员等级分布
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(departmentId);
List<String> strings = staffService.staffsByAllDeparmentIds(allDeparmentIds);
int total = strings.size();
List<GraphicsStatisticalDto> staffLevels = resultRecordService.staffDistribution(selectMonthTime,strings);
List<String> names = new ArrayList<>();
List<Double> datas = new ArrayList<>();
int konwn = 0;
for (GraphicsStatisticalDto staffLevel : staffLevels) {
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);
data.setTargetDistribution(dto);
dto = new GraphicsDto();
dto.setRows(end);
data.setResultDistribution(dto);
CharBarDto barDto= new CharBarDto();
barDto.setNames(names);
barDto.setDatas(datas);
barDto.setTotal(total);
data.setStaffDistribution(barDto);
return R.ok().put("data",data);
ReportChartResp reportChartResp = chartService.reportChart(selectMonthTime, departmentId);
return R.ok().put("data",reportChartResp);
}
@RequestMapping("/report")
public R list(ReportListReq req){
//获取部门下所有人员
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId());
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
PageUtils pageUtils = chartService.resultReportList(req, staffIds);
return R.ok().put("page",pageUtils);
}
@ -106,16 +85,12 @@ public class ReportResultController extends AbstractController{
return R.ok().put("data",ownResultResp);
}
}
@RequestMapping("/team/result")
public R teamResult(){
return R.ok();
}
//是在这个地方查询出所有的部门选择 还是 通过关键字搜索
@RequestMapping("underDepartment")
/* @RequestMapping("underDepartment")
public R underDepartment(){
DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(null);
if(departmentsStaffRelateEntity == null){
@ -128,12 +103,12 @@ public class ReportResultController extends AbstractController{
}
return R.ok();
}
}*/
//获取日期之内的月份
private static List<String> getMonthBetween(String minDate, String maxDate){
/* private static List<String> getMonthBetween(String minDate, String maxDate){
ArrayList<String> result = new ArrayList<String>();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
@ -157,8 +132,8 @@ public class ReportResultController extends AbstractController{
return result;
}
*/
}

View File

@ -1,5 +1,7 @@
package com.lz.modules.app.dao;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lz.modules.app.dto.ReportProgressListDto;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.app.entity.StaffEntity;
@ -58,4 +60,8 @@ public interface DepartmentsStaffRelateDao extends BaseMapper<DepartmentsStaffRe
DepartmentsStaffRelateEntity selectDepartmentByDepartmentId(@Param("departmentId") String departmentId);
DepartmentsStaffRelateEntity selectByStaffId(@Param("staffId") Long staffId);
List<ReportProgressListDto> getDepartmentNameByStaffIds(@Param("staffIds") List<String> staffIds);
}

View File

@ -2,10 +2,7 @@ package com.lz.modules.app.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.dto.StaffBaseInfoDto;
import com.lz.modules.app.dto.StaffDto;
import com.lz.modules.app.dto.StaffStatisticalDto;
import com.lz.modules.app.dto.*;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.equipment.entity.model.FindByNameModel;
import org.apache.ibatis.annotations.Mapper;
@ -80,4 +77,6 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
List<StaffEntity> selectBySearchName(@Param("page") IPage page, @Param("model") FindByNameModel nameModel);
List<StaffEntity> selectAll();
List<ReportProgressListDto> getPositionByStaffIds(@Param("staffIds") List<String> staffIds,@Param("page") IPage page);
}

View File

@ -0,0 +1,32 @@
package com.lz.modules.app.dto;
import lombok.Data;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/23 11:21
*/
@Data
public class ReportProgressListDto {
private Long id;
private String staffId;
private String staffName;
private String departmentName;
//职位
private String position;
//业务得分
private String businessScore;
//价值观得分
private String valueScore;
//得分
private String score;
//等级
private String scoreLevel;
private int status;
}

View File

@ -0,0 +1,26 @@
package com.lz.modules.app.req;
import com.lz.modules.equipment.entity.model.BasePage;
import lombok.Data;
import java.time.YearMonth;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/23 11:07
*/
@Data
public class ReportListReq extends BasePage {
String departmentId;
//String startMonthTime;
//String endMonthTime;
String selectMonthTime = YearMonth.now().toString();
//提交审核状态
int status =0;
//目标还是结果
int type =1;
}

View File

@ -11,6 +11,7 @@ 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.GraphicsStatisticalDto;
import com.lz.modules.app.dto.ReportProgressListDto;
import com.lz.modules.app.req.ResultRecordReq;
import com.lz.modules.app.resp.OwnResultResp;
import com.lz.modules.flow.model.ResultRecordDto;
@ -57,4 +58,6 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
List<GraphicsStatisticalDto> staffDistribution(@Param("monthTime") String monthTime,@Param("staffIds") List<String> staffIds);
ResultRecord selectResultRecordByStaffIdStatus(@Param("staffId") Long staffId, @Param("status") int status);
List<ReportProgressListDto> targetReportList(@Param("monthTime") String monthTime,@Param("staffIds") List<String> staffIds,@Param("page") IPage page);
}

View File

@ -1,6 +1,10 @@
package com.lz.modules.sys.service.app;
import com.lz.common.utils.PageUtils;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.dto.ReportProgressListDto;
import com.lz.modules.app.req.ReportListReq;
import com.lz.modules.app.resp.ReportChartResp;
import java.util.List;
@ -19,6 +23,10 @@ public interface ChartService {
*/
List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId);
PageUtils resultReportList(ReportListReq req, List<String> staffIds);
ReportChartResp reportChart(String selectMonthTime, String departmentId);
}

View File

@ -5,6 +5,7 @@ import com.lz.common.emun.WorkMsgTypeEnum;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.dto.ReportProgressListDto;
import com.lz.modules.app.entity.DepartmentsEntity;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.req.ResultRecordReq;
@ -86,4 +87,7 @@ public interface ResultRecordService extends IService<ResultRecord> {
ResultRecord selectResultRecordByStaffIdStatus(Long staffId, int status);
R reject( ResultRecord resultRecord,ResultRecordReq req, Long userId);
// ReportProgressListDto targetReportList(String monthTime);
}

View File

@ -1,30 +1,56 @@
package com.lz.modules.sys.service.app.impl;
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.PageUtils;
import com.lz.modules.app.dao.DepartmentsStaffRelateDao;
import com.lz.modules.app.dao.StaffDao;
import com.lz.modules.app.dto.CharBarDto;
import com.lz.modules.app.dto.GraphicsDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.dto.ReportProgressListDto;
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.req.ReportListReq;
import com.lz.modules.app.resp.ReportChartResp;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.sys.dao.app.ResultRecordMapper;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/14 16:54
*/
@Slf4j
@Service
public class ChartServiceImpl implements ChartService {
@Autowired
private ResultRecordService resultRecordService;
@Autowired
private StaffService staffService;
@Autowired
private ResultRecordMapper resultRecordMapper;
@Autowired
private DepartmentsStaffRelateDao departmentsStaffRelateDao;
@Autowired
private StaffDao staffDao;
@Override
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) {
List<GraphicsStatisticalDto> dtos = new ArrayList<>();
@ -65,4 +91,86 @@ public class ChartServiceImpl implements ChartService {
return dtos;
}
@Override
public ReportChartResp reportChart(String selectMonthTime, String departmentId) {
ReportChartResp data = new ReportChartResp();
//月初目标
List<GraphicsStatisticalDto> start = this.resultProgressDistribution(ResultRecordTypeEnum.TARGET.getType(),selectMonthTime,departmentId);
//月末结果
List<GraphicsStatisticalDto> end = this.resultProgressDistribution(ResultRecordTypeEnum.RESULT.getType(),selectMonthTime,departmentId);
//人员等级分布
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(departmentId);
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
int total = staffIds.size();
List<GraphicsStatisticalDto> staffLevels = resultRecordService.staffDistribution(selectMonthTime,staffIds);
List<String> names = new ArrayList<>();
List<Double> datas = new ArrayList<>();
int konwn = 0;
for (GraphicsStatisticalDto staffLevel : staffLevels) {
names.add(staffLevel.getCategory());
datas.add(BigDecimalUtil.div(Double.valueOf(staffLevel.getNumber()),Double.valueOf(total),2));
konwn = konwn + staffLevel.getNumber();
log.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);
data.setTargetDistribution(dto);
dto = new GraphicsDto();
dto.setRows(end);
data.setResultDistribution(dto);
CharBarDto barDto= new CharBarDto();
barDto.setNames(names);
barDto.setDatas(datas);
barDto.setTotal(total);
data.setStaffDistribution(barDto);
return data;
}
@Override
public PageUtils resultReportList(ReportListReq req, List<String> staffIds) {
// 状态为0的数据存在两张表单独处理
if(req.getStatus()!=0){
//获取处理过业绩目标的人员
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page -> resultRecordMapper.targetReportList(req.getSelectMonthTime(), staffIds, page)
);
List<ReportProgressListDto> list = pageUtils.getList();
return pageUtils;
}else {
//获取已提交人员
List<String> commitStaffIds = new ArrayList<>();
List<Object> collect=resultRecordService.listObjs(new QueryWrapper<ResultRecord>()
.eq("is_delete", 0)
.eq("type", req.getType())
.like("month_time",req.getSelectMonthTime())
.ne("status", ResultRecordStatusEnum.CREATE.getStatus())
.select("staff_id"));
if(CollectionUtils.isNotEmpty(collect)){
commitStaffIds = collect.stream().map((Function<Object, String>) o -> o.toString()).collect(Collectors.toList());
}
//去除已经提交的
staffIds.removeAll(commitStaffIds);
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page ->staffDao.getPositionByStaffIds(staffIds,page)
);
//本次分页数据
List<ReportProgressListDto> dataList = pageUtils.getList();
if(dataList.size()<1){
return pageUtils;
}
//拿到用户数据查询部门信息封装
List<String> selectStaffIds = dataList.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList());
List<ReportProgressListDto> departmentNameByStaffIds = departmentsStaffRelateDao.getDepartmentNameByStaffIds(selectStaffIds);
Map<String,String> map = Maps.newHashMap();
departmentNameByStaffIds.forEach(reportProgressListDto -> map.put(reportProgressListDto.getStaffId(),reportProgressListDto.getDepartmentName()));
dataList.forEach(reportProgressListDto -> reportProgressListDto.setDepartmentName(map.get(reportProgressListDto.getStaffId())));
return pageUtils;
}
}
}

View File

@ -274,5 +274,26 @@
select * from lz_result_record where is_delete = 0 and staff_id = #{staffId} and type = 1 and status = #{status} order by id desc limit 1
</select>
<select id="targetReportList" resultType="com.lz.modules.app.dto.ReportProgressListDto">
SELECT max(r.id) id,r.staff_id ,staff_name,status,position,department_name from lz_result_record r
LEFT JOIN lz_staff_occupation o
on r.staff_id = o.staff_id
where r.is_delete=0 and o.is_delete=0 and type = 1
and r.staff_id in
<foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
GROUP BY r.staff_id
</select>
<select id="resultReportList" resultType="com.lz.modules.app.dto.ReportProgressListDto">
</select>
</mapper>

View File

@ -81,4 +81,17 @@
select * from lz_departments_staff_relate where is_delete=0 and staff_id = #{staffId}
</select>
<select id="getDepartmentNameByStaffIds" resultType="com.lz.modules.app.dto.ReportProgressListDto">
SELECT department_name,staff_id from lz_departments_staff_relate r
LEFT JOIN
lz_departments d
on r.department_id = d.department_id
where r.is_delete=0 and d.is_delete=0
and r.staff_id in
<foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</select>
</mapper>

View File

@ -447,4 +447,16 @@
select * from lz_staff where is_delete = 0
</select>
<select id="getPositionByStaffIds" resultType="com.lz.modules.app.dto.ReportProgressListDto">
SELECT o.staff_id,name staffName,position from lz_staff s
LEFT JOIN
lz_staff_occupation o
on s.id = o.staff_id
where s.is_delete=0 and o.is_delete=0
and s.id in
<foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</select>
</mapper>