This commit is contained in:
杜建超 2020-09-27 17:53:58 +08:00
parent 2b09014842
commit bd2de3c75c
6 changed files with 232 additions and 101 deletions

View File

@ -0,0 +1,48 @@
package com.lz.common.utils;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
import java.util.Objects;
/**
* @Author: djc
* @Desc:
* @Date: 2020/9/27 14:48
*/
public class ListUtils { //list 分页
public static List startPage(List list, Integer pageNum,
Integer pageSize) {
if (CollectionUtils.isEmpty(list)) {
return Lists.newArrayList();
}
pageNum = pageNum<1?1:pageNum;
Integer count = list.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
if(pageNum>pageCount){
return Lists.newArrayList();
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (!Objects.equals(pageNum, pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}

View File

@ -53,14 +53,11 @@ public class ReportResultController extends AbstractController{
@RequestMapping("chart") @RequestMapping("chart")
public R reportChart(String selectMonthTime,String departmentId){ public R reportChart(String selectMonthTime,String departmentId){
/* if(!chartService.hrOrBoss(getUserId())){
return R.ok();
}*/
if(StringUtil.isBlank(selectMonthTime)){ if(StringUtil.isBlank(selectMonthTime)){
selectMonthTime = YearMonth.now().toString(); selectMonthTime = YearMonth.now().toString();
}
Long userId = getUserId();
//是自己部门得领导
DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(userId);
if("1".equals(departmentsStaffRelateEntity.getIsLeader())){
} }
ReportChartResp reportChartResp = chartService.reportChart(selectMonthTime, departmentId); ReportChartResp reportChartResp = chartService.reportChart(selectMonthTime, departmentId);
return R.ok().put("data",reportChartResp); return R.ok().put("data",reportChartResp);
@ -71,29 +68,42 @@ public class ReportResultController extends AbstractController{
@RequestMapping("/report") @RequestMapping("/report")
public R list(ReportListReq req){ public R list(ReportListReq req){
//获取部门下所有人员 /* if(!chartService.leader(getUserId())){
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId()); return R.ok();
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds); }*/
PageUtils pageUtils = chartService.resultReportList(req, staffIds); PageUtils pageUtils = chartService.resultReportList(req);
return R.ok().put("page",pageUtils); return R.ok().put("page",pageUtils);
} }
// 未解决问题 部门负责人游离在外 无法统计
@RequestMapping("/distribution") @RequestMapping("/distribution")
public R distribution(ResultDistributionReq req){ public R distribution(ResultDistributionReq req){
req.setDepartmentId("1"); /* if(!chartService.hrOrBoss(getUserId())){
return R.ok();
}*/
PageUtils pageUtils = chartService.reportDistribution(req); PageUtils pageUtils = chartService.reportDistribution(req);
return R.ok().put("page",pageUtils); return R.ok().put("page",pageUtils);
}
}
@RequestMapping("/departmentTreeByStaffId") @RequestMapping("/departmentTreeByStaffId")
public R departmentTreeByStaffId(ResultDistributionReq req){ public R departmentTreeByStaffId(){
//Long userId = getUserId(); /*Long userId = getUserId();
List<DepartmentsDto> data = departmentsService.getDepartmentTreeByStaffId("303",true); if(chartService.hrOrBoss(userId)){
List<DepartmentsDto> data = departmentsService.getDepartmentTree();
return R.ok().put("data",data);
}
if(chartService.leader(getUserId())){
List<DepartmentsDto> data = departmentsService.getDepartmentTreeByStaffId(String.valueOf(userId),true);
return R.ok().put("data",data);
}
return R.ok();*/
List<DepartmentsDto> data = departmentsService.getDepartmentTree();
return R.ok().put("data",data); return R.ok().put("data",data);
} }
@RequestMapping("/own/result") @RequestMapping("/own/result")

View File

@ -26,7 +26,7 @@ public interface ChartService {
*/ */
List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId); List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId);
PageUtils resultReportList(ReportListReq req, List<String> staffIds); PageUtils resultReportList(ReportListReq req);
ReportChartResp reportChart(String selectMonthTime, String departmentId); ReportChartResp reportChart(String selectMonthTime, String departmentId);
@ -35,6 +35,11 @@ public interface ChartService {
String businessLineByStaffId(String staffId); String businessLineByStaffId(String staffId);
boolean hrOrBoss(Long staffId);
boolean leader(Long staffId);
} }

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.lz.common.utils.BigDecimalUtil; import com.lz.common.utils.BigDecimalUtil;
import com.lz.common.utils.ListUtils;
import com.lz.common.utils.PageUtils; import com.lz.common.utils.PageUtils;
import com.lz.common.utils.StringUtil; import com.lz.common.utils.StringUtil;
import com.lz.modules.app.dao.DepartmentsDao; import com.lz.modules.app.dao.DepartmentsDao;
@ -21,6 +22,8 @@ import com.lz.modules.app.req.ReportListReq;
import com.lz.modules.app.req.ResultDistributionReq; import com.lz.modules.app.req.ResultDistributionReq;
import com.lz.modules.app.resp.ReportChartResp; import com.lz.modules.app.resp.ReportChartResp;
import com.lz.modules.app.service.StaffService; import com.lz.modules.app.service.StaffService;
import com.lz.modules.flow.dao.StaffRoleMapper;
import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.sys.dao.app.ResultRecordMapper; import com.lz.modules.sys.dao.app.ResultRecordMapper;
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;
@ -60,10 +63,13 @@ public class ChartServiceImpl implements ChartService {
private StaffDao staffDao; private StaffDao staffDao;
@Autowired @Autowired
private DepartmentsDao departmentsDao; private DepartmentsDao departmentsDao;
@Autowired
private StaffRoleMapper staffRoleMapper;
static final String[] levels = new String[]{"3.25","3.5-","3.5","3.5+","3.75-","3.75","3.75+","4"}; static final String[] levels = new String[]{"3.25","3.5-","3.5","3.5+","3.75-","3.75","3.75+","4"};
//如果多次提交会统计有问题
@Override @Override
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) { public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) {
List<GraphicsStatisticalDto> dtos = new ArrayList<>(); List<GraphicsStatisticalDto> dtos = new ArrayList<>();
@ -75,13 +81,17 @@ public class ChartServiceImpl implements ChartService {
.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())
.in("department_id",allDeparmentIds)
.select("DISTINCT staff_id"));
//已完成 //已完成
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)
.like("month_time",monthTime) .like("month_time",monthTime)
.in("status", ResultRecordStatusEnum.REFUSE.getStatus(),ResultRecordStatusEnum.AGREE.getStatus(),ResultRecordStatusEnum.SUSPEND.getStatus())); .in("status", ResultRecordStatusEnum.REFUSE.getStatus(),ResultRecordStatusEnum.AGREE.getStatus(),ResultRecordStatusEnum.SUSPEND.getStatus())
.in("department_id",allDeparmentIds)
.select("DISTINCT staff_id"));
GraphicsStatisticalDto dto = new GraphicsStatisticalDto(); GraphicsStatisticalDto dto = new GraphicsStatisticalDto();
if(total-commit>0){ if(total-commit>0){
@ -144,47 +154,111 @@ public class ChartServiceImpl implements ChartService {
} }
@Override @Override
public PageUtils resultReportList(ReportListReq req, List<String> staffIds) { public PageUtils resultReportList(ReportListReq req) {
// 状态为0的数据存在两张表单独处理 List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId());
if(!"0".equals(req.getStatus())){ //获取部门下所有人员
//获取真实状态 List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
List<Integer> groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus()); List<String> copyStaffIds = Lists.newArrayList();
req.setRealStatus(groupStatus); ReportListReq copyReq = new ReportListReq();
//获取处理过业绩目标的人员 copyStaffIds.addAll(staffIds);
if(req.getStatus()!=null){
if(req.getStatus() == ResultRecordStatusEnum.CREATE.getStatus()){ // 状态为0的数据存在两张表单独处理
//获取已提交人员
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())
.in("department_id",allDeparmentIds)
.in("staff_id",staffIds)
.select(" DISTINCT staff_id"));
if(CollectionUtils.isNotEmpty(collect)){
commitStaffIds = collect.stream().map(o -> o.toString()).collect(Collectors.toList());
}
//去除已经提交的
staffIds.removeAll(commitStaffIds);
return buildPageByStaffIds(req,staffIds);
}else {
//获取真实状态
List<Integer> groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus());
req.setRealStatus(groupStatus);
//获取处理过业绩目标的人员
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page -> resultRecordMapper.targetReportList(req, staffIds, page)
);
return pageUtils;
}
}else{ // 查询所有需要拼装数据 ,先查询已提交得剩余得 用未提交缺多少补多少
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect( PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page -> resultRecordMapper.targetReportList(req, staffIds, page) page -> resultRecordMapper.targetReportList(req, staffIds, page)
); );
return pageUtils; List<ReportProgressListDto> list = pageUtils.getList();
int totalPage = pageUtils.getTotalPage();
/*************************************数据拼接逻辑****************************************/
if(list.size()<req.getPageSize()){
List<String> commitStaffIds = new ArrayList<>();
//已提交
List<Object> objects = resultRecordService.listObjs(new QueryWrapper<ResultRecord>()
.eq("is_delete", 0)
.eq("type", req.getType())
.like("month_time", req.getSelectMonthTime())
.in("department_id", allDeparmentIds)
.select("DISTINCT staff_id"));
if(CollectionUtils.isNotEmpty(objects)){
commitStaffIds = objects.stream().map(o -> o.toString()).collect(Collectors.toList());
}
staffIds.removeAll(commitStaffIds);
if(CollectionUtils.isEmpty(staffIds)){
return pageUtils;
}
int addSize = req.getPageSize()-list.size();
int addStart = req.getCurrPage() -totalPage;
//如果相差大于0 则需找到最后一页得个数 补齐得时候减去这些个数
if(addStart>0){
copyReq.setCurrPage(pageUtils.getTotalPage());
copyReq.setPageSize(req.getPageSize());
PageUtils ps = PageUtils.startPage(copyReq.getCurrPage(),copyReq.getPageSize()).doSelect(
page -> resultRecordMapper.targetReportList(copyReq, copyStaffIds, page)
);
int sub = ps.getList().size();
addStart = (addStart-1) * req.getPageSize() + (copyReq.getPageSize()-sub);
}
int addEnd = addSize + addStart;
addEnd = addEnd>staffIds.size()?staffIds.size():addEnd;
List<String> addList = staffIds.subList(addStart,addEnd);
copyReq.setCurrPage(0);
copyReq.setPageSize(addSize);
PageUtils addResult = buildPageByStaffIds(copyReq, addList);
staffIds.addAll(commitStaffIds);
PageUtils data = new PageUtils();
list.addAll(addResult.getList());
data.setList(list);
data.setPageSize(req.getPageSize());
data.setCurrPage(req.getCurrPage());
data.setTotalCount(copyStaffIds.size());
data.setTotalPage(PageUtil.totalPage(copyStaffIds.size(),req.getPageSize()));
return data;
}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(o -> o.toString()).collect(Collectors.toList());
} }
//去除已经提交的
staffIds.removeAll(commitStaffIds); PageUtils data = new PageUtils();
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page ->staffDao.getPositionByStaffIds(staffIds,page) data.setList(list);
); data.setPageSize(req.getPageSize());
//本次分页数据 data.setCurrPage(req.getCurrPage());
List<ReportProgressListDto> dataList = pageUtils.getList(); data.setTotalCount(copyStaffIds.size());
if(dataList.size()<1){ data.setTotalPage(PageUtil.totalPage(copyStaffIds.size(),req.getPageSize()));
return pageUtils;
} return data;
//拿到用户数据查询部门信息封装
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;
} }
} }
@ -202,7 +276,7 @@ public class ChartServiceImpl implements ChartService {
}); });
// 由于deparmentIds 递归所得无法分页 则list分页 // 由于deparmentIds 递归所得无法分页 则list分页
List<String> list = startPage(allDeparmentIds, req.getCurrPage(), req.getPageSize()); List<String> list = ListUtils.startPage(allDeparmentIds, req.getCurrPage(), req.getPageSize());
return buildPages(list,req,allDeparmentIds.size()); return buildPages(list,req,allDeparmentIds.size());
} }
@ -214,6 +288,25 @@ public class ChartServiceImpl implements ChartService {
return getBussinessLine(departmentId); return getBussinessLine(departmentId);
} }
@Override
public boolean hrOrBoss(Long staffId) {
StaffRole staffRole = staffRoleMapper.selectByStaffId(staffId);
if(staffRole!=null){
return true;
}
return false;
}
@Override
public boolean leader(Long staffId) {
DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateDao.selectByStaffId(staffId);
if(departmentsStaffRelateEntity!=null && "1".equals(departmentsStaffRelateEntity.getIsLeader())){
return true;
}
return false;
}
private String getBussinessLine(String departmentId){ private String getBussinessLine(String departmentId){
DepartmentsEntity departmentsEntity = departmentsDao.selectByDepartmentId(departmentId); DepartmentsEntity departmentsEntity = departmentsDao.selectByDepartmentId(departmentId);
if("1".equals(departmentsEntity.getDepartmentParentId())){ if("1".equals(departmentsEntity.getDepartmentParentId())){
@ -264,42 +357,22 @@ public class ChartServiceImpl implements ChartService {
} }
//根据用户组拼接未提交分页数据
public static List startPage(List list, Integer pageNum, private PageUtils buildPageByStaffIds(ReportListReq req,List<String> staffIds){
Integer pageSize) { PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
if (list == null) { page ->staffDao.getPositionByStaffIds(staffIds,page)
return null; );
//本次分页数据
List<ReportProgressListDto> dataList = pageUtils.getList();
if(dataList.size()<1){
return pageUtils;
} }
if (list.size() == 0) { //拿到用户数据查询部门信息封装
return null; List<String> selectStaffIds = dataList.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList());
} List<ReportProgressListDto> departmentNameByStaffIds = departmentsStaffRelateDao.getDepartmentNameByStaffIds(selectStaffIds);
Map<String,String> map = Maps.newHashMap();
Integer count = list.size(); // 记录总数 departmentNameByStaffIds.forEach(reportProgressListDto -> map.put(reportProgressListDto.getStaffId(),reportProgressListDto.getDepartmentName()));
Integer pageCount = 0; // 页数 dataList.forEach(reportProgressListDto -> reportProgressListDto.setDepartmentName(map.get(reportProgressListDto.getStaffId())));
if (count % pageSize == 0) { return pageUtils;
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (!Objects.equals(pageNum, pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
private boolean hasPermissions(Long staffId){
return true;
} }
} }

View File

@ -301,22 +301,17 @@
<if test="req.level !=null and req.level != ''"> <if test="req.level !=null and req.level != ''">
and r.score_level = #{req.level} and r.score_level = #{req.level}
</if> </if>
<if test="req.selectMonthTime !=null and req.selectMonthTime !=''">
and month_time like CONCAT('', #{req.selectMonthTime}, '%')
</if>
<if test="req.realStatus !=null and req.realStatus.size() !=0"> <if test="req.realStatus !=null and req.realStatus.size() !=0">
and r.status in and r.status in
<foreach collection="req.realStatus" item="item" index="index" separator="," open="(" close=")"> <foreach collection="req.realStatus" item="item" index="index" separator="," open="(" close=")">
#{item} #{item}
</foreach> </foreach>
</if>
<if test="req.selectMonthTime !=null">
</if> </if>
GROUP BY r.staff_id GROUP BY r.staff_id
</select>
<select id="resultReportList" resultType="com.lz.modules.app.dto.ReportProgressListDto">
</select> </select>

View File

@ -63,7 +63,7 @@ public class MysqlMain {
} }
List<TablesBean> list = new ArrayList<TablesBean>(); List<TablesBean> list = new ArrayList<TablesBean>();
list.add(new TablesBean("t_count")); list.add(new TablesBean("lz_staff_role"));
List<TablesBean> list2 = new ArrayList<TablesBean>(); List<TablesBean> list2 = new ArrayList<TablesBean>();
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments(); Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();