fix
This commit is contained in:
parent
2b09014842
commit
bd2de3c75c
48
src/main/java/com/lz/common/utils/ListUtils.java
Normal file
48
src/main/java/com/lz/common/utils/ListUtils.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,14 +53,11 @@ public class ReportResultController extends AbstractController{
|
||||
|
||||
@RequestMapping("chart")
|
||||
public R reportChart(String selectMonthTime,String departmentId){
|
||||
/* if(!chartService.hrOrBoss(getUserId())){
|
||||
return R.ok();
|
||||
}*/
|
||||
if(StringUtil.isBlank(selectMonthTime)){
|
||||
selectMonthTime = YearMonth.now().toString();
|
||||
}
|
||||
Long userId = getUserId();
|
||||
//是自己部门得领导
|
||||
DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(userId);
|
||||
if("1".equals(departmentsStaffRelateEntity.getIsLeader())){
|
||||
|
||||
}
|
||||
ReportChartResp reportChartResp = chartService.reportChart(selectMonthTime, departmentId);
|
||||
return R.ok().put("data",reportChartResp);
|
||||
@ -71,29 +68,42 @@ public class ReportResultController extends AbstractController{
|
||||
|
||||
@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);
|
||||
/* if(!chartService.leader(getUserId())){
|
||||
return R.ok();
|
||||
}*/
|
||||
PageUtils pageUtils = chartService.resultReportList(req);
|
||||
return R.ok().put("page",pageUtils);
|
||||
}
|
||||
|
||||
|
||||
// 未解决问题 部门负责人游离在外 无法统计
|
||||
@RequestMapping("/distribution")
|
||||
public R distribution(ResultDistributionReq req){
|
||||
req.setDepartmentId("1");
|
||||
/* if(!chartService.hrOrBoss(getUserId())){
|
||||
return R.ok();
|
||||
}*/
|
||||
PageUtils pageUtils = chartService.reportDistribution(req);
|
||||
return R.ok().put("page",pageUtils);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/departmentTreeByStaffId")
|
||||
public R departmentTreeByStaffId(ResultDistributionReq req){
|
||||
//Long userId = getUserId();
|
||||
List<DepartmentsDto> data = departmentsService.getDepartmentTreeByStaffId("303",true);
|
||||
public R departmentTreeByStaffId(){
|
||||
/*Long userId = getUserId();
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/own/result")
|
||||
|
||||
@ -26,7 +26,7 @@ public interface ChartService {
|
||||
*/
|
||||
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);
|
||||
|
||||
@ -35,6 +35,11 @@ public interface ChartService {
|
||||
String businessLineByStaffId(String staffId);
|
||||
|
||||
|
||||
boolean hrOrBoss(Long staffId);
|
||||
|
||||
boolean leader(Long staffId);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.common.utils.ListUtils;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.StringUtil;
|
||||
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.resp.ReportChartResp;
|
||||
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.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ChartService;
|
||||
@ -60,10 +63,13 @@ public class ChartServiceImpl implements ChartService {
|
||||
private StaffDao staffDao;
|
||||
@Autowired
|
||||
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"};
|
||||
|
||||
|
||||
//如果多次提交会统计有问题
|
||||
@Override
|
||||
public List<GraphicsStatisticalDto> resultProgressDistribution(int type, String monthTime,String departmentId) {
|
||||
List<GraphicsStatisticalDto> dtos = new ArrayList<>();
|
||||
@ -75,13 +81,17 @@ public class ChartServiceImpl implements ChartService {
|
||||
.eq("is_delete", 0)
|
||||
.eq("type", type)
|
||||
.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>()
|
||||
.eq("is_delete", 0)
|
||||
.eq("type", type)
|
||||
.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();
|
||||
if(total-commit>0){
|
||||
@ -144,47 +154,111 @@ public class ChartServiceImpl implements ChartService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils resultReportList(ReportListReq req, List<String> staffIds) {
|
||||
// 状态为0的数据存在两张表,单独处理
|
||||
if(!"0".equals(req.getStatus())){
|
||||
//获取真实状态
|
||||
List<Integer> groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus());
|
||||
req.setRealStatus(groupStatus);
|
||||
//获取处理过业绩目标的人员
|
||||
public PageUtils resultReportList(ReportListReq req) {
|
||||
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId());
|
||||
//获取部门下所有人员
|
||||
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
|
||||
List<String> copyStaffIds = Lists.newArrayList();
|
||||
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(
|
||||
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 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;
|
||||
|
||||
PageUtils data = new PageUtils();
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +276,7 @@ public class ChartServiceImpl implements ChartService {
|
||||
});
|
||||
|
||||
// 由于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());
|
||||
}
|
||||
|
||||
@ -214,6 +288,25 @@ public class ChartServiceImpl implements ChartService {
|
||||
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){
|
||||
DepartmentsEntity departmentsEntity = departmentsDao.selectByDepartmentId(departmentId);
|
||||
if("1".equals(departmentsEntity.getDepartmentParentId())){
|
||||
@ -264,42 +357,22 @@ public class ChartServiceImpl implements ChartService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List startPage(List list, Integer pageNum,
|
||||
Integer pageSize) {
|
||||
if (list == null) {
|
||||
return null;
|
||||
//根据用户组拼接未提交分页数据
|
||||
private PageUtils buildPageByStaffIds(ReportListReq req,List<String> staffIds){
|
||||
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;
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Integer count = list.size(); // 记录总数
|
||||
Integer pageCount = 0; // 页数
|
||||
if (count % pageSize == 0) {
|
||||
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;
|
||||
|
||||
//拿到用户数据查询部门信息封装
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,22 +301,17 @@
|
||||
<if test="req.level !=null and req.level != ''">
|
||||
and r.score_level = #{req.level}
|
||||
</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">
|
||||
and r.status in
|
||||
<foreach collection="req.realStatus" item="item" index="index" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="req.selectMonthTime !=null">
|
||||
|
||||
</if>
|
||||
GROUP BY r.staff_id
|
||||
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<select id="resultReportList" resultType="com.lz.modules.app.dto.ReportProgressListDto">
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ public class MysqlMain {
|
||||
}
|
||||
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>();
|
||||
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user