|
@@ -1,11 +1,30 @@
|
|
|
package com.wtkj.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.wtkj.dto.ProjectPageDTO;
|
|
|
import com.wtkj.entity.Project;
|
|
|
+import com.wtkj.entity.ProjectAuth;
|
|
|
import com.wtkj.mapper.ProjectMapper;
|
|
|
+import com.wtkj.service.IAsyncService;
|
|
|
+import com.wtkj.service.IProjectAuthService;
|
|
|
import com.wtkj.service.IProjectService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.BladeUser;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.system.entity.Dept;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.wtkj.MagicValue.STAFF_ADMIN;
|
|
|
|
|
|
/**
|
|
|
* @author Blizzard
|
|
@@ -15,4 +34,81 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class ProjectServiceImpl extends BaseServiceImpl<ProjectMapper, Project> implements IProjectService {
|
|
|
+
|
|
|
+ private final IAsyncService asyncService;
|
|
|
+ private final ISysClient sysClient;
|
|
|
+ private final IProjectAuthService projectAuthService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean submit(Project project) {
|
|
|
+ boolean flag = false;
|
|
|
+ BladeUser user = AuthUtil.getUser();
|
|
|
+ if (project.getId() == null) {
|
|
|
+ flag = this.save(project);
|
|
|
+ asyncService.createProject(project, user);
|
|
|
+ } else {
|
|
|
+ flag = this.updateById(project);
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<Project> getPage(ProjectPageDTO dto, IPage<Project> page) {
|
|
|
+ LambdaQueryWrapper<Project> lqw = new LambdaQueryWrapper<>();
|
|
|
+ //判断当前登录用户的身份 是业主还是服务机构
|
|
|
+ String deptIdStr = AuthUtil.getDeptId();
|
|
|
+ Long deptId = Long.valueOf(deptIdStr);
|
|
|
+ R<Dept> rpc = sysClient.getDept(deptId);
|
|
|
+ if (rpc.isSuccess()) {
|
|
|
+ //项目名称
|
|
|
+ if (dto.getName() != null) {
|
|
|
+ lqw.eq(Project::getName, dto.getName());
|
|
|
+ }
|
|
|
+ //区域
|
|
|
+ if (dto.getAreaCode() != null) {
|
|
|
+ lqw.eq(Project::getAreaCode, dto.getAreaCode());
|
|
|
+ }
|
|
|
+ Integer deptCategory = rpc.getData().getDeptCategory();
|
|
|
+ //如果是业主 即查询主管单位是该deptId的项目
|
|
|
+ if (deptCategory != null && deptCategory.equals(3)) {
|
|
|
+ //主管单位 业主自己
|
|
|
+ lqw.eq(Project::getCompetentUnit, deptId);
|
|
|
+ //协作单位
|
|
|
+ lqw.like(StringUtil.isNotBlank(dto.getCooperationUint()), Project::getCooperationUint, dto.getCooperationUint());
|
|
|
+ } else {
|
|
|
+ //主管单位
|
|
|
+ lqw.eq(Project::getCompetentUnit, dto.getCompetentUnit());
|
|
|
+ //如果不是业主 ---> 判断是否是服务商的管理员 服务商管理员可以查看所有的项目
|
|
|
+ String userRole = AuthUtil.getUserRole();
|
|
|
+ if (userRole != null && userRole.equals(STAFF_ADMIN)) {
|
|
|
+ List<ProjectAuth> auths = projectAuthService.getByDeptAndUser(deptId, null);
|
|
|
+ if (!CollectionUtils.isEmpty(auths)) {
|
|
|
+ Set<Long> projectIds = auths.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet());
|
|
|
+ lqw.in(Project::getId, projectIds);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //不是服务机构管理员 则会是项目经理或者任务执行人 从项目权限表里取
|
|
|
+ List<ProjectAuth> auths = projectAuthService.getByDeptAndUser(deptId, AuthUtil.getUserId());
|
|
|
+ if (!CollectionUtils.isEmpty(auths)) {
|
|
|
+ Set<Long> projectIds = auths.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet());
|
|
|
+ lqw.in(Project::getId, projectIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //待完成任务数排序
|
|
|
+ if (dto.getTodoAsc().equals(1)) {
|
|
|
+ lqw.orderByAsc(Project::getTodoTask);
|
|
|
+ } else {
|
|
|
+ lqw.orderByDesc(Project::getTodoTask);
|
|
|
+ }
|
|
|
+ //截止时间排序
|
|
|
+ if (dto.getEndTimeAsc().equals(1)) {
|
|
|
+ lqw.orderByAsc(Project::getEndTime);
|
|
|
+ } else {
|
|
|
+ lqw.orderByDesc(Project::getEndTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.page(page, lqw);
|
|
|
+ }
|
|
|
+
|
|
|
}
|