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..abc0bcf3 100644 --- a/src/main/java/com/lz/modules/app/controller/ReportResultController.java +++ b/src/main/java/com/lz/modules/app/controller/ReportResultController.java @@ -1,13 +1,9 @@ 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.*; -import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; +import com.lz.modules.app.dto.DepartmentsDto; 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.req.ResultDistributionReq; import com.lz.modules.app.resp.OwnResultResp; @@ -18,17 +14,10 @@ import com.lz.modules.app.service.StaffService; import com.lz.modules.sys.controller.AbstractController; 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.time.YearMonth; -import java.util.ArrayList; -import java.util.Calendar; import java.util.List; /** @@ -52,17 +41,11 @@ public class ReportResultController extends AbstractController{ @RequestMapping("chart") - public R reportChart(String selectMonthTime,String departmentId){ - if(StringUtil.isBlank(selectMonthTime)){ - selectMonthTime = YearMonth.now().toString(); + public R reportChart(ResultDistributionReq req){ + if(!chartService.hrOrBoss(getUserId())){ + return R.ok(); } - Long userId = getUserId(); - //是自己部门得领导 - DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(userId); - if("1".equals(departmentsStaffRelateEntity.getIsLeader())){ - - } - ReportChartResp reportChartResp = chartService.reportChart(selectMonthTime, departmentId); + ReportChartResp reportChartResp = chartService.reportChart(req.getSelectMonthTime(), req.getDepartmentId()); return R.ok().put("data",reportChartResp); } @@ -71,29 +54,40 @@ 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); - return R.ok().put("data",data); + 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(); + + + } @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..090e1755 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<>(); @@ -72,16 +78,20 @@ public class ChartServiceImpl implements ChartService { int total = staffService.staffsByAllDeparmentIds(allDeparmentIds).size(); //已提交 int commit = resultRecordService.count(new QueryWrapper() - .eq("is_delete", 0) + .eq("is_delete", type==1?2: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("is_delete", type==1?2: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,54 +154,115 @@ 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", req.getType()==1?2: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", req.getType()==1?2: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; + } } @Override public PageUtils reportDistribution(ResultDistributionReq req) { - List allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId()); + /*List allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId()); // 去除存在子部门得id allDeparmentIds.removeIf(s -> { List departmentsEntities = departmentsDao.selectEntityByParentDepartmentId(s); @@ -202,8 +273,25 @@ public class ChartServiceImpl implements ChartService { }); // 由于deparmentIds 递归所得无法分页 则list分页 - List list = startPage(allDeparmentIds, req.getCurrPage(), req.getPageSize()); - return buildPages(list,req,allDeparmentIds.size()); + List list = ListUtils.startPage(allDeparmentIds, req.getCurrPage(), req.getPageSize()); + return buildPages(list,req,allDeparmentIds.size());*/ + //获取一级目录 + List departmentsParentsList = departmentsDao.getDepartmentsByparentId("1"); + if(CollectionUtils.isEmpty(departmentsParentsList)){ + return new PageUtils(); + } + List oneDepartmentsParentsList = Lists.newArrayList(); + departmentsParentsList.forEach(departmentsDto -> { + List departmentsParentsList1 = departmentsDao.getDepartmentsByparentId(departmentsDto.getDepartmentId()); + oneDepartmentsParentsList.addAll(departmentsParentsList1); + }); + + List list = ListUtils.startPage(oneDepartmentsParentsList, req.getCurrPage(), req.getPageSize()); + if(CollectionUtils.isEmpty(list)){ + return new PageUtils(); + } + List collect = list.stream().map(DepartmentsDto::getDepartmentId).collect(Collectors.toList()); + return buildPages(collect,req,oneDepartmentsParentsList.size()); } @@ -214,6 +302,35 @@ public class ChartServiceImpl implements ChartService { return getBussinessLine(departmentId); } + + @Override + public boolean hrOrBoss(Long staffId) { + log.info("hrOrBoss判断 : " + staffId); + //超级管理员 + if(1==staffId){ + return true; + } + StaffRole staffRole = staffRoleMapper.selectByStaffId(staffId); + if(staffRole!=null){ + return true; + } + return false; + } + + @Override + public boolean leader(Long staffId) { + log.info("leader判断 : " + staffId); + //超级管理员 + if(1==staffId){ + return true; + } + 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())){ @@ -231,8 +348,8 @@ public class ChartServiceImpl implements ChartService { } departments.forEach(s -> { DepartmentsEntity departmentsEntity = departmentsDao.selectByDepartmentId(s); - List departmentsEntities = departmentsDao.selectEntityByParentDepartmentId(departmentsEntity.getDepartmentParentId()); - List staffIds = staffService.staffsByAllDeparmentIds(Lists.newArrayList(s)); + List allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(s); + List staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds); List staffLevels = resultRecordService.staffDistribution(req.getSelectMonthTime(),staffIds); Map map = Maps.newHashMap(); for (GraphicsStatisticalDto staffLevel : staffLevels) { @@ -264,42 +381,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 c6711464..ae49e988 100644 --- a/src/main/resources/mapper/app/ResultRecordMapper.xml +++ b/src/main/resources/mapper/app/ResultRecordMapper.xml @@ -294,7 +294,10 @@ 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 + where r.is_delete=0 and o.is_delete=0 + + and type = #{req.type} + and r.staff_id in @@ -307,22 +310,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/main/resources/mapper/equipment/EquipmentInfoMapper.xml b/src/main/resources/mapper/equipment/EquipmentInfoMapper.xml index 5ad34d5f..c8b8699c 100644 --- a/src/main/resources/mapper/equipment/EquipmentInfoMapper.xml +++ b/src/main/resources/mapper/equipment/EquipmentInfoMapper.xml @@ -293,16 +293,16 @@ select ifnull(count(*),0) from equipment_info where is_delete = 0 and count =#{num} and depart_id is not null and depart_id > 0 - - update equipment_info set type = #{type} where type_id=#{id} + + update equipment_info set type = #{type} where type_id=#{id} and is_delete=0 - - update equipment_info set brand_name = #{brand} where type_id=#{id} + + update equipment_info set brand_name = #{brand} where brand_id=#{id} and is_delete=0 - - update equipment_info set spec_type = #{specs} where type_id=#{id} + + update equipment_info set spec_type = #{specs} where specs_id=#{id} and is_delete=0 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();