|
@@ -7,12 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.management.platform.entity.*;
|
|
|
-import com.management.platform.mapper.ProductMapper;
|
|
|
-import com.management.platform.mapper.SysDictMapper;
|
|
|
-import com.management.platform.mapper.SysFormMapper;
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.ProductService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.service.SysFunctionService;
|
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
@@ -37,6 +35,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import java.util.zip.DataFormatException;
|
|
|
|
|
|
/**
|
|
@@ -66,15 +65,54 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
private SysDictMapper sysDictMapper;
|
|
|
@Resource
|
|
|
private ExcelExportServiceImpl excelExportService;
|
|
|
+ @Resource
|
|
|
+ private SysFunctionService sysFunctionService;
|
|
|
+ @Resource
|
|
|
+ private DepartmentMapper departmentMapper;
|
|
|
+ @Resource
|
|
|
+ private DepartmentOtherManagerMapper departmentOtherManagerMapper;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode, Integer pageIndex, Integer pageSize) {
|
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ User targetUsr = userMapper.selectById(request.getHeader("token"));
|
|
|
+ List<Department> departments = departmentMapper.selectList(new LambdaQueryWrapper<Department>().eq(Department::getCompanyId, companyId));
|
|
|
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Product::getCompanyId,companyId);
|
|
|
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
|
|
|
List<SysDict> sysDictOfProductType = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductType"));
|
|
|
List<SysDict> sysDictOfProductUnit = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductUnit"));
|
|
|
+ boolean hasPriviledgeAll = sysFunctionService.hasPriviledge(targetUsr.getRoleId(), "查看全部产品数据");
|
|
|
+ boolean hasPriviledgeDept = sysFunctionService.hasPriviledge(targetUsr.getRoleId(), "查看全部产品数据");
|
|
|
+ //判断查看全部的权限
|
|
|
+ if(!hasPriviledgeAll){
|
|
|
+ //判断查看负责部门的权限
|
|
|
+ if(!hasPriviledgeDept){
|
|
|
+ //都没有就只能看自己创建的
|
|
|
+ queryWrapper.eq(Product::getCreatorId,targetUsr.getId());
|
|
|
+ }else {
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new LambdaQueryWrapper<Department>().eq(Department::getManagerId, targetUsr.getId()));
|
|
|
+ List<DepartmentOtherManager> otherManagerList = departmentOtherManagerMapper.selectList(new LambdaQueryWrapper<DepartmentOtherManager>().eq(DepartmentOtherManager::getOtherManagerId, targetUsr.getId()));
|
|
|
+ List<Integer> deptIds=new ArrayList<>();
|
|
|
+ deptIds.add(-1);
|
|
|
+ List<Integer> managerDeptIds = departmentList.stream().map(Department::getDepartmentId).distinct().collect(Collectors.toList());
|
|
|
+ List<Integer> otherManagerDeptIds = otherManagerList.stream().map(DepartmentOtherManager::getDepartmentId).distinct().collect(Collectors.toList());
|
|
|
+ deptIds.addAll(managerDeptIds);
|
|
|
+ List<Integer> finalDeptIds1 = deptIds;
|
|
|
+ managerDeptIds.forEach(m->{
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(m, departments);
|
|
|
+ finalDeptIds1.addAll(branchDepartment);
|
|
|
+ });
|
|
|
+ deptIds.addAll(otherManagerDeptIds);
|
|
|
+ List<Integer> finalDeptIds = deptIds;
|
|
|
+ otherManagerDeptIds.forEach(o->{
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(o, departments);
|
|
|
+ finalDeptIds.addAll(branchDepartment);
|
|
|
+ });
|
|
|
+ deptIds=deptIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ queryWrapper.in(Product::getCreatorId,deptIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
if(!StringUtils.isEmpty(userId)){
|
|
|
queryWrapper.eq(Product::getCreatorId,userId);
|
|
|
}
|
|
@@ -362,4 +400,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
String fileName="产品表导出_"+ System.currentTimeMillis();
|
|
|
return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,dataList,path);
|
|
|
}
|
|
|
+
|
|
|
+ //递归获取子部门
|
|
|
+ public List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ list.add(departmentId);
|
|
|
+ //搜到子部门进行添加
|
|
|
+ for (Department department : departmentList) {
|
|
|
+ if (departmentId.equals(department.getSuperiorId())) {
|
|
|
+ list.addAll(getBranchDepartment(department.getDepartmentId(), departmentList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|