This commit is contained in:
杜建超 2020-09-29 19:31:45 +08:00
parent e2e5bf581e
commit 76d4a18cb8
12 changed files with 205 additions and 74 deletions

View File

@ -1,5 +1,6 @@
package com.lz.modules.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
@ -13,14 +14,19 @@ import com.lz.modules.app.resp.ReportChartResp;
import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.flow.service.StaffRoleService;
import com.lz.modules.sys.controller.AbstractController;
import com.lz.modules.sys.service.app.ChartService;
import com.lz.modules.sys.service.app.ResultRecordService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author: djc
@ -40,6 +46,8 @@ public class ReportResultController extends AbstractController{
private StaffService staffService;
@Autowired
private ChartService chartService;
@Autowired
private StaffRoleService staffRoleService;
@RequestMapping("chart")
@ -119,6 +127,7 @@ public class ReportResultController extends AbstractController{
return R.ok().put("data",ownResultResp);
}
}

View File

@ -1,18 +1,30 @@
package com.lz.modules.app.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.app.dao.DepartmentsDao;
import com.lz.modules.app.entity.DepartmentsEntity;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.enums.ResultRecordStatusEnum;
import com.lz.modules.app.resp.Step;
import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.flow.entity.RecordAuth;
import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.flow.model.FlowModel;
import com.lz.modules.flow.service.RecordAuthService;
import com.lz.modules.flow.service.StaffRoleService;
import com.lz.modules.sys.dao.SysUserDao;
import com.lz.modules.sys.entity.SysUserEntity;
import com.lz.modules.sys.entity.app.ResultRecord;
import com.lz.modules.sys.service.SysUserService;
import com.lz.modules.sys.service.app.ResultDetailService;
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.web.bind.annotation.RequestMapping;
@ -23,7 +35,10 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@Slf4j
@RestController
public class TestController {
@ -42,6 +57,14 @@ public class TestController {
@Autowired
private DepartmentsStaffRelateService departmentsStaffRelateService;
@Autowired
private StaffRoleService staffRoleService;
@Autowired
private SysUserDao sysUserDao;
@Autowired
private SysUserService sysUserService;
@Autowired
private RecordAuthService recordAuthService;
@RequestMapping("/test/xx")
public void test(){
@ -153,4 +176,54 @@ public class TestController {
}
@RequestMapping("/test/init")
public void testinit(){
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId("1");
//获取部门下所有人员
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
List<Object> collect=resultRecordService.listObjs(new QueryWrapper<ResultRecord>()
.eq("is_delete", 0)
.eq("type", 2)
.like("month_time","2020-09")
.in("department_id",allDeparmentIds)
.in("staff_id",staffIds)
.select(" DISTINCT staff_id"));
List<String> collect1 = new ArrayList<>();
if(CollectionUtils.isNotEmpty(collect)){
collect1 = collect.stream().map(o -> o.toString()).collect(Collectors.toList());
System.out.println();
}
staffIds.removeAll(collect1);
staffIds.forEach(new Consumer<String>() {
@Override
public void accept(String s) {
List<RecordAuth> listAuth = new ArrayList<>();
try {
ResultRecord resultRecord = resultRecordService.initResult(Long.valueOf(s), 2, 8l);
} catch (Exception e) {
log.info("失败账户" + s);
log.error("" ,e);
return;
}
//ResultRecord resultRecord = resultRecordService.createResultRecord(Long.valueOf(s), 1, 7l);
System.out.println();
/* DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(Long.valueOf(s));
DepartmentsEntity departmentsEntity = departmentsService.selectByDepartmentId(departmentsStaffRelateEntity.getDepartmentId());
StaffEntity staffEntity = staffService.selectStaffById(Long.valueOf(s));
ResultRecord resultRecord = new ResultRecord();
resultRecord.setStaffId(Long.valueOf(s));
resultRecord.setType(2);
resultRecord.setDepartmentId(departmentsStaffRelateEntity.getDepartmentId());
resultRecord.setDepartmentName(departmentsEntity.getDepartmentName());
resultRecord.setStaffName(staffEntity.getName());
//resultRecord.setFlowStaffIdRole();
resultRecordService.insertResultRecord(resultRecord);*/
}
});
System.out.println();
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lz.modules.app.dto.*;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.req.ReportListReq;
import com.lz.modules.equipment.entity.model.FindByNameModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -78,5 +79,5 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
List<StaffEntity> selectAll();
List<ReportProgressListDto> getPositionByStaffIds(@Param("staffIds") List<String> staffIds,@Param("page") IPage page);
List<ReportProgressListDto> getPositionByStaffIds(@Param("req") ReportListReq req, @Param("staffIds") List<String> staffIds, @Param("page") IPage page);
}

View File

@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* 系统用户
@ -46,4 +47,6 @@ public interface SysUserDao extends BaseMapper<SysUserEntity> {
List<Long> queryMenuIdListByRoleId(@Param("roleId") Long roleId);
List<Long> queryMenuIdListByRoleIds(@Param("roleIds") Set<Long> roleIds);
}

View File

@ -62,7 +62,7 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
ResultRecord selectResultRecordByStaffIdStatus(@Param("staffId") Long staffId, @Param("status") int status);
List<ReportProgressListDto> targetReportList(@Param("req")ReportListReq req, @Param("staffIds") List<String> staffIds, @Param("page") IPage page);
List<ReportProgressListDto> targetReportList(@Param("req")ReportListReq req, @Param("staffIds") List<String> staffIds,@Param("page") IPage page);
ResultRecord selectLastResultRecordByStaffIdType(@Param("staffId") Long staffId, @Param("type") int type);
}

View File

@ -15,6 +15,7 @@ import org.apache.catalina.User;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@ -66,4 +67,6 @@ public interface SysUserService extends IService<SysUserEntity> {
boolean updatePassword(SysUserEntity user, String password, String newPassword);
List<Long> queryMenuIdListByRoleId(Long roleId);
List<Long> queryMenuIdListByRoleIds(Set<Long> roleIds);
}

View File

@ -161,21 +161,26 @@ public class ChartServiceImpl implements ChartService {
List<String> allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId(req.getDepartmentId());
//获取部门下所有人员
List<String> staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds);
List<String> copyStaffIds = Lists.newArrayList();
//获取真实状态
List<Integer> groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus());
req.setRealStatus(groupStatus);
//获取处理过业绩目标的人员
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page -> this.targetReportList(req, staffIds, page)
);
return pageUtils;
/*
List<String> copyStaffIds = Lists.newArrayList();
ReportListReq copyReq = new ReportListReq();
copyStaffIds.addAll(staffIds);
if(req.getStatus()!=null){
if(req.getStatus()!=null){
if(req.getStatus() != ResultRecordStatusEnum.CREATE.getStatus()){
//获取真实状态
List<Integer> groupStatus = ResultRecordStatusEnum.getGroupStatus(req.getStatus());
req.setRealStatus(groupStatus);
//获取处理过业绩目标的人员
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page -> this.targetReportList(req, staffIds, page)
);
return pageUtils;
}else { // 状态为0的数据存在两张表单独处理
@ -212,61 +217,64 @@ public class ChartServiceImpl implements ChartService {
copyList.addAll(list);
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", 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.isNotEmpty(list)){
List<String> collect = list.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList());
staffIds.removeAll(collect);
}
if(StringUtil.isNotBlank(req.getLevel()) || StringUtil.isNotBlank(req.getStaffName())){
*//*************************************数据拼接逻辑****************************************//*
if(list.size()<req.getPageSize()){
List<String> commitStaffIds = new ArrayList<>();
//已提交
List<Object> objects = resultRecordService.listObjs(new QueryWrapper<ResultRecord>()
.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.isNotEmpty(list)){
List<String> collect = list.stream().map(reportProgressListDto -> reportProgressListDto.getStaffId()).collect(Collectors.toList());
staffIds.removeAll(collect);
}
if(CollectionUtils.isEmpty(staffIds)){
return pageUtils;
}
int addSize = req.getPageSize()-list.size();
int addStart = req.getCurrPage() -totalPage;
//如果相差大于0 则需找到最后一页得个数 补齐得时候减去这些个数
if(addStart>0){
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 -> this.targetReportList(copyReq, copyStaffIds, page)
);
int sub = ps.getList().size();
addStart = (addStart-1) * req.getPageSize() + (copyReq.getPageSize()-sub);
copyReq.setCurrPage(pageUtils.getTotalPage());
copyReq.setPageSize(req.getPageSize());
PageUtils ps = PageUtils.startPage(copyReq.getCurrPage(),copyReq.getPageSize()).doSelect(
page -> this.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;
addStart = addStart>staffIds.size()?0:addStart;
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();
copyList.addAll(addResult.getList());
data.setList(copyList);
data.setPageSize(req.getPageSize());
data.setCurrPage(req.getCurrPage());
data.setTotalCount(copyStaffIds.size());
data.setTotalPage(PageUtil.totalPage(copyStaffIds.size(),req.getPageSize()));
return data;
}
int addEnd = addSize + addStart;
addEnd = addEnd>staffIds.size()?staffIds.size():addEnd;
addStart = addStart>staffIds.size()?0:addStart;
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();
copyList.addAll(addResult.getList());
data.setList(copyList);
data.setPageSize(req.getPageSize());
data.setCurrPage(req.getCurrPage());
data.setTotalCount(copyStaffIds.size());
data.setTotalPage(PageUtil.totalPage(copyStaffIds.size(),req.getPageSize()));
return data;
}
PageUtils data = new PageUtils();
data.setList(list);
data.setPageSize(req.getPageSize());
@ -275,7 +283,8 @@ public class ChartServiceImpl implements ChartService {
data.setTotalPage(PageUtil.totalPage(copyStaffIds.size(),req.getPageSize()));
return data;
}
}*/
}
@ -353,7 +362,7 @@ public class ChartServiceImpl implements ChartService {
@Override
public List<ReportProgressListDto> targetReportList(ReportListReq req, List<String> staffIds, IPage page) {
List<ReportProgressListDto> reportProgressListDtos = resultRecordMapper.targetReportList(req, staffIds, page);
List<ReportProgressListDto> reportProgressListDtos = resultRecordMapper.targetReportList(req, staffIds,page);
//由于使用了 maxId 需要拿到id 获取最新数据
if(CollectionUtils.isNotEmpty(reportProgressListDtos)){
reportProgressListDtos.forEach(reportProgressListDto -> {
@ -432,7 +441,7 @@ public class ChartServiceImpl implements ChartService {
//根据用户组拼接未提交分页数据
private PageUtils buildPageByStaffIds(ReportListReq req,List<String> staffIds){
PageUtils pageUtils = PageUtils.startPage(req.getCurrPage(),req.getPageSize()).doSelect(
page ->staffDao.getPositionByStaffIds(staffIds,page)
page ->staffDao.getPositionByStaffIds(req,staffIds,page)
);
//本次分页数据
List<ReportProgressListDto> dataList = pageUtils.getList();

View File

@ -10,6 +10,8 @@ package com.lz.modules.sys.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.lz.common.utils.Constant;
import com.lz.common.utils.MapUtils;
import com.lz.modules.flow.entity.FlowDepartment;
@ -22,11 +24,13 @@ import com.lz.modules.sys.entity.SysUserEntity;
import com.lz.modules.sys.service.SysMenuService;
import com.lz.modules.sys.service.SysRoleMenuService;
import com.lz.modules.sys.service.SysUserService;
import com.lz.modules.sys.service.app.ChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Service("sysMenuService")
@ -42,6 +46,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> i
@Autowired
private StaffRoleService staffRoleService;
@Autowired
private ChartService chartService;
@Override
public List<SysMenuEntity> queryListParentId(Long parentId, List<Long> menuIdList) {
List<SysMenuEntity> menuList = queryListParentId(parentId);
@ -88,7 +95,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> i
roleId = 14l;
}
}
menuIdList = sysUserService.queryMenuIdListByRoleId(roleId);
Set<Long> roleIds = Sets.newHashSet(roleId);
if(chartService.hrOrBoss(user.getUserId())){
roleIds.add(19L);
roleIds.add(20L);
}
if(chartService.leader(user.getUserId())){
roleIds.add(20L);
}
menuIdList = sysUserService.queryMenuIdListByRoleIds(roleIds);
}
return getAllMenuList(menuIdList);
}

View File

@ -28,10 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
@ -154,6 +151,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
}
@Override
public List<Long> queryMenuIdListByRoleIds(Set<Long> roleIds) {
return baseMapper.queryMenuIdListByRoleIds(roleIds);
}
/**
* 检查角色是否越权
*/

View File

@ -3,9 +3,9 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-bp1xhc66ruz72t68p.mysql.rds.aliyuncs.com:3306/lz_manger?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: lz_manger
password: N8zfBwhOC
url: jdbc:mysql://172.16.157.238:3306/lz_management?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: ldd_biz
password: Hello1234
initial-size: 10
max-active: 100
min-idle: 10

View File

@ -457,6 +457,8 @@
<foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
<if test="req.staffName != null and req.staffName !=''">
and name LIKE CONCAT('%',#{req.staffName},'%')
</if>
</select>
</mapper>

View File

@ -66,4 +66,17 @@
</select>
<select id="queryMenuIdListByRoleIds" resultType="java.lang.Long">
select distinct rm.menu_id from sys_user_role ur
LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
<if test="roleIds !=null and roleIds.size()>0">
where ur.role_id in
<foreach collection="roleIds" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</select>
</mapper>