diff --git a/src/main/java/com/lz/common/utils/ListUtils.java b/src/main/java/com/lz/common/utils/ListUtils.java new file mode 100644 index 00000000..5d211e7e --- /dev/null +++ b/src/main/java/com/lz/common/utils/ListUtils.java @@ -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; + } + +} diff --git a/src/main/java/com/lz/modules/app/controller/ReportResultController.java b/src/main/java/com/lz/modules/app/controller/ReportResultController.java index aa8cca21..c9e0d6df 100644 --- a/src/main/java/com/lz/modules/app/controller/ReportResultController.java +++ b/src/main/java/com/lz/modules/app/controller/ReportResultController.java @@ -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 allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId()); - List 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 data = departmentsService.getDepartmentTreeByStaffId("303",true); + public R departmentTreeByStaffId(){ + /*Long userId = getUserId(); + if(chartService.hrOrBoss(userId)){ + List data = departmentsService.getDepartmentTree(); + return R.ok().put("data",data); + } + if(chartService.leader(getUserId())){ + List data = departmentsService.getDepartmentTreeByStaffId(String.valueOf(userId),true); + return R.ok().put("data",data); + } + return R.ok();*/ + List data = departmentsService.getDepartmentTree(); return R.ok().put("data",data); + + + } @RequestMapping("/own/result") diff --git a/src/main/java/com/lz/modules/sys/service/app/ChartService.java b/src/main/java/com/lz/modules/sys/service/app/ChartService.java index 85c13cb0..24d821ac 100644 --- a/src/main/java/com/lz/modules/sys/service/app/ChartService.java +++ b/src/main/java/com/lz/modules/sys/service/app/ChartService.java @@ -26,7 +26,7 @@ public interface ChartService { */ List resultProgressDistribution(int type, String monthTime,String departmentId); - PageUtils resultReportList(ReportListReq req, List 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); + + } diff --git a/src/main/java/com/lz/modules/sys/service/app/impl/ChartServiceImpl.java b/src/main/java/com/lz/modules/sys/service/app/impl/ChartServiceImpl.java index 03d72967..a4ec665b 100644 --- a/src/main/java/com/lz/modules/sys/service/app/impl/ChartServiceImpl.java +++ b/src/main/java/com/lz/modules/sys/service/app/impl/ChartServiceImpl.java @@ -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 resultProgressDistribution(int type, String monthTime,String departmentId) { List 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() .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 staffIds) { - // 状态为0的数据存在两张表,单独处理 - if(!"0".equals(req.getStatus())){ - //获取真实状态 - List groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus()); - req.setRealStatus(groupStatus); - //获取处理过业绩目标的人员 + public PageUtils resultReportList(ReportListReq req) { + List allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId()); + //获取部门下所有人员 + List staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds); + List copyStaffIds = Lists.newArrayList(); + ReportListReq copyReq = new ReportListReq(); + copyStaffIds.addAll(staffIds); + + if(req.getStatus()!=null){ + if(req.getStatus() == ResultRecordStatusEnum.CREATE.getStatus()){ // 状态为0的数据存在两张表,单独处理 + //获取已提交人员 + List commitStaffIds = new ArrayList<>(); + List collect=resultRecordService.listObjs(new QueryWrapper() + .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 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 list = pageUtils.getList(); + int totalPage = pageUtils.getTotalPage(); + + /*************************************数据拼接逻辑****************************************/ + if(list.size() commitStaffIds = new ArrayList<>(); + //已提交 + List objects = resultRecordService.listObjs(new QueryWrapper() + .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 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 commitStaffIds = new ArrayList<>(); - List collect=resultRecordService.listObjs(new QueryWrapper() - .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 dataList = pageUtils.getList(); - if(dataList.size()<1){ - return pageUtils; - } - //拿到用户数据查询部门信息封装 - List selectStaffIds = dataList.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList()); - List departmentNameByStaffIds = departmentsStaffRelateDao.getDepartmentNameByStaffIds(selectStaffIds); - Map 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 list = startPage(allDeparmentIds, req.getCurrPage(), req.getPageSize()); + List 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 staffIds){ + PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect( + page ->staffDao.getPositionByStaffIds(staffIds,page) + ); + //本次分页数据 + List 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 selectStaffIds = dataList.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList()); + List departmentNameByStaffIds = departmentsStaffRelateDao.getDepartmentNameByStaffIds(selectStaffIds); + Map map = Maps.newHashMap(); + departmentNameByStaffIds.forEach(reportProgressListDto -> map.put(reportProgressListDto.getStaffId(),reportProgressListDto.getDepartmentName())); + dataList.forEach(reportProgressListDto -> reportProgressListDto.setDepartmentName(map.get(reportProgressListDto.getStaffId()))); + return pageUtils; } } diff --git a/src/main/resources/mapper/app/ResultRecordMapper.xml b/src/main/resources/mapper/app/ResultRecordMapper.xml index 4103e760..92dfb66d 100644 --- a/src/main/resources/mapper/app/ResultRecordMapper.xml +++ b/src/main/resources/mapper/app/ResultRecordMapper.xml @@ -301,22 +301,17 @@ and r.score_level = #{req.level} + + and month_time like CONCAT('', #{req.selectMonthTime}, '%') + and r.status in #{item} - - - GROUP BY r.staff_id - - - - - diff --git a/src/test/java/com/lz/mysql/MysqlMain.java b/src/test/java/com/lz/mysql/MysqlMain.java index 828987c7..8b0e88fd 100644 --- a/src/test/java/com/lz/mysql/MysqlMain.java +++ b/src/test/java/com/lz/mysql/MysqlMain.java @@ -63,7 +63,7 @@ public class MysqlMain { } List list = new ArrayList(); - list.add(new TablesBean("t_count")); + list.add(new TablesBean("lz_staff_role")); List list2 = new ArrayList(); Map map = MysqlUtil2ShowCreateTable.getComments();