|
@@ -4,222 +4,323 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.management.platform.entity.Project;
|
|
|
import com.management.platform.entity.ProjectClosureApplier;
|
|
import com.management.platform.entity.ProjectClosureApplier;
|
|
|
import com.management.platform.entity.ProjectClosureApply;
|
|
import com.management.platform.entity.ProjectClosureApply;
|
|
|
import com.management.platform.entity.ProjectClosureApprovalLog;
|
|
import com.management.platform.entity.ProjectClosureApprovalLog;
|
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
import com.management.platform.mapper.ProjectClosureApplierMapper;
|
|
import com.management.platform.mapper.ProjectClosureApplierMapper;
|
|
|
import com.management.platform.mapper.ProjectClosureApplyMapper;
|
|
import com.management.platform.mapper.ProjectClosureApplyMapper;
|
|
|
import com.management.platform.mapper.ProjectClosureApprovalLogMapper;
|
|
import com.management.platform.mapper.ProjectClosureApprovalLogMapper;
|
|
|
-import com.management.platform.mapper.ProjectClosureAttachmentMapper;
|
|
|
|
|
import com.management.platform.service.ProjectClosureApplyService;
|
|
import com.management.platform.service.ProjectClosureApplyService;
|
|
|
|
|
+import com.management.platform.service.ProjectService;
|
|
|
|
|
+import com.management.platform.service.UserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * <p>
|
|
|
|
|
- * 项目结项申请表 服务实现类
|
|
|
|
|
- * </p>
|
|
|
|
|
- *
|
|
|
|
|
- * @author Seyason
|
|
|
|
|
- * @since 2026-05-12
|
|
|
|
|
|
|
+ * 项目结项申请:提交、多级审批、通过后完成项目
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class ProjectClosureApplyServiceImpl extends ServiceImpl<ProjectClosureApplyMapper, ProjectClosureApply> implements ProjectClosureApplyService {
|
|
public class ProjectClosureApplyServiceImpl extends ServiceImpl<ProjectClosureApplyMapper, ProjectClosureApply> implements ProjectClosureApplyService {
|
|
|
|
|
|
|
|
|
|
+ private static final DateTimeFormatter DT_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private ProjectClosureApplierMapper closureApplierMapper;
|
|
private ProjectClosureApplierMapper closureApplierMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private ProjectClosureApprovalLogMapper approvalLogMapper;
|
|
private ProjectClosureApprovalLogMapper approvalLogMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
- private ProjectClosureAttachmentMapper attachmentMapper;
|
|
|
|
|
|
|
+ private ProjectService projectService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserService userService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public ProjectClosureApply submitApply(Integer projectId, Integer userId, String reason, List<Integer> attachmentIds) {
|
|
|
|
|
- // 1. 获取项目信息(需要通过项目Service获取实际项目名称和编码)
|
|
|
|
|
- String projectName = "项目-" + projectId;
|
|
|
|
|
- String projectCode = "CODE-" + projectId;
|
|
|
|
|
-
|
|
|
|
|
- // 2. 创建申请记录
|
|
|
|
|
|
|
+ public ProjectClosureApply submitApply(Integer projectId, String userId, String reason, List<Integer> attachmentIds) {
|
|
|
|
|
+ if (projectId == null || !StringUtils.hasText(userId)) {
|
|
|
|
|
+ throw new RuntimeException("参数不完整");
|
|
|
|
|
+ }
|
|
|
|
|
+ Project project = projectService.getById(projectId);
|
|
|
|
|
+ if (project == null) {
|
|
|
|
|
+ throw new RuntimeException("项目不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (project.getStatus() == null || project.getStatus() != 1) {
|
|
|
|
|
+ throw new RuntimeException("仅进行中的项目可发起结项申请");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean canApply = Objects.equals(userId, project.getCreatorId()) || Objects.equals(userId, project.getInchargerId());
|
|
|
|
|
+ if (!canApply) {
|
|
|
|
|
+ throw new RuntimeException("仅项目负责人或创建人可发起结项申请");
|
|
|
|
|
+ }
|
|
|
|
|
+ long pending = this.count(new QueryWrapper<ProjectClosureApply>()
|
|
|
|
|
+ .eq("project_id", projectId)
|
|
|
|
|
+ .in("approval_status", 0, 1));
|
|
|
|
|
+ if (pending > 0) {
|
|
|
|
|
+ throw new RuntimeException("该项目已有进行中的结项申请");
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer companyId = project.getCompanyId();
|
|
|
|
|
+ List<ProjectClosureApplier> flow = getApprovalFlow(companyId);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(flow)) {
|
|
|
|
|
+ throw new RuntimeException("未配置结项审批人,请在系统设置中配置后再申请");
|
|
|
|
|
+ }
|
|
|
|
|
+ User applicant = userService.getById(userId);
|
|
|
|
|
+ String applicantName = applicant != null && StringUtils.hasText(applicant.getName()) ? applicant.getName() : userId;
|
|
|
|
|
+
|
|
|
ProjectClosureApply apply = new ProjectClosureApply();
|
|
ProjectClosureApply apply = new ProjectClosureApply();
|
|
|
apply.setProjectId(projectId);
|
|
apply.setProjectId(projectId);
|
|
|
- apply.setProjectName(projectName);
|
|
|
|
|
- apply.setProjectCode(projectCode);
|
|
|
|
|
|
|
+ apply.setProjectName(project.getProjectName());
|
|
|
|
|
+ apply.setProjectCode(project.getProjectCode());
|
|
|
apply.setApplicantId(userId);
|
|
apply.setApplicantId(userId);
|
|
|
- apply.setApplicantName("用户" + userId); // TODO: 从用户表查询
|
|
|
|
|
|
|
+ apply.setApplicantName(applicantName);
|
|
|
apply.setCurrentStep(0);
|
|
apply.setCurrentStep(0);
|
|
|
- apply.setApprovalStatus(0); // 待审批
|
|
|
|
|
|
|
+ apply.setApprovalStatus(1);
|
|
|
apply.setRemark(reason);
|
|
apply.setRemark(reason);
|
|
|
apply.setCreateTime(LocalDateTime.now());
|
|
apply.setCreateTime(LocalDateTime.now());
|
|
|
apply.setUpdateTime(LocalDateTime.now());
|
|
apply.setUpdateTime(LocalDateTime.now());
|
|
|
-
|
|
|
|
|
- // 保存申请记录
|
|
|
|
|
|
|
+
|
|
|
|
|
+ ProjectClosureApplier first = flow.get(0);
|
|
|
|
|
+ apply.setCurrentApproverId(first.getApproverUserId());
|
|
|
|
|
+ apply.setCurrentApproverName(first.getApproverName());
|
|
|
|
|
+
|
|
|
this.save(apply);
|
|
this.save(apply);
|
|
|
-
|
|
|
|
|
- // 3. 保存附件
|
|
|
|
|
if (!CollectionUtils.isEmpty(attachmentIds)) {
|
|
if (!CollectionUtils.isEmpty(attachmentIds)) {
|
|
|
- for (Integer attachmentId : attachmentIds) {
|
|
|
|
|
- // TODO: 从附件Service获取附件信息并保存到project_closure_attachment表
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 附件表关联可按 attachmentIds 扩展,当前仅保存申请主表
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 4. 获取审批流程,设置第一个审批人
|
|
|
|
|
- this.setNextApprover(apply.getId());
|
|
|
|
|
-
|
|
|
|
|
|
|
+ decorateApply(apply, userId, companyId);
|
|
|
return apply;
|
|
return apply;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<ProjectClosureApplier> getApprovalFlow(Integer timeTypeId) {
|
|
|
|
|
|
|
+ public List<ProjectClosureApplier> getApprovalFlow(Integer companyId) {
|
|
|
|
|
+ if (companyId == null) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
QueryWrapper<ProjectClosureApplier> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<ProjectClosureApplier> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("time_type_id", timeTypeId)
|
|
|
|
|
- .eq("status", 1) // 启用状态
|
|
|
|
|
- .orderByAsc("sort_order");
|
|
|
|
|
|
|
+ wrapper.eq("time_type_id", companyId)
|
|
|
|
|
+ .eq("status", 1)
|
|
|
|
|
+ .orderByAsc("sort_order");
|
|
|
return closureApplierMapper.selectList(wrapper);
|
|
return closureApplierMapper.selectList(wrapper);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean approve(Integer applyId, Integer applierId, String comment, Integer action) {
|
|
|
|
|
- // 1. 获取申请记录
|
|
|
|
|
|
|
+ public boolean approve(Integer applyId, String applierId, String comment, Integer action) {
|
|
|
|
|
+ if (applyId == null || !StringUtils.hasText(applierId) || action == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
|
if (apply == null) {
|
|
if (apply == null) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 2. 检查是否是当前审批人
|
|
|
|
|
- if (!applierId.equals(apply.getCurrentApproverId())) {
|
|
|
|
|
|
|
+ if (!Objects.equals(applierId, apply.getCurrentApproverId())) {
|
|
|
throw new RuntimeException("您不是当前审批人");
|
|
throw new RuntimeException("您不是当前审批人");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 3. 创建审批记录
|
|
|
|
|
|
|
+ int as = apply.getApprovalStatus() == null ? -1 : apply.getApprovalStatus();
|
|
|
|
|
+ if (as != 0 && as != 1) {
|
|
|
|
|
+ throw new RuntimeException("该申请已结束审批");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean pass = Objects.equals(action, 2) || Objects.equals(action, 1);
|
|
|
|
|
+ boolean reject = Objects.equals(action, 3);
|
|
|
|
|
+
|
|
|
|
|
+ User approver = userService.getById(applierId);
|
|
|
|
|
+ String approverName = approver != null && StringUtils.hasText(approver.getName()) ? approver.getName() : applierId;
|
|
|
|
|
+
|
|
|
ProjectClosureApprovalLog log = new ProjectClosureApprovalLog();
|
|
ProjectClosureApprovalLog log = new ProjectClosureApprovalLog();
|
|
|
log.setApplyId(applyId);
|
|
log.setApplyId(applyId);
|
|
|
log.setApproverId(applierId);
|
|
log.setApproverId(applierId);
|
|
|
- log.setApproverName("用户" + applierId); // TODO: 从用户表查询
|
|
|
|
|
- log.setAction(action);
|
|
|
|
|
|
|
+ log.setApproverName(approverName);
|
|
|
|
|
+ log.setAction(pass ? 2 : 3);
|
|
|
log.setOpinion(comment);
|
|
log.setOpinion(comment);
|
|
|
log.setCreateTime(LocalDateTime.now());
|
|
log.setCreateTime(LocalDateTime.now());
|
|
|
approvalLogMapper.insert(log);
|
|
approvalLogMapper.insert(log);
|
|
|
-
|
|
|
|
|
- // 4. 根据审批结果处理
|
|
|
|
|
- if (action == 1) { // 同意
|
|
|
|
|
- apply.setCurrentStep(apply.getCurrentStep() + 1);
|
|
|
|
|
-
|
|
|
|
|
- // 检查是否还有下一个审批人
|
|
|
|
|
- ProjectClosureApplier nextApplier = this.getNextApprover(apply.getProjectId(), apply.getCurrentStep());
|
|
|
|
|
- if (nextApplier != null) {
|
|
|
|
|
- // 还有下一个审批人
|
|
|
|
|
- apply.setCurrentApproverId(nextApplier.getApproverUserId());
|
|
|
|
|
- apply.setCurrentApproverName(nextApplier.getApproverName());
|
|
|
|
|
- apply.setApprovalStatus(1); // 审批中
|
|
|
|
|
- this.updateById(apply);
|
|
|
|
|
- } else {
|
|
|
|
|
- // 所有审批人都同意
|
|
|
|
|
- apply.setApprovalStatus(2); // 已通过
|
|
|
|
|
- this.updateById(apply);
|
|
|
|
|
- // 调用审批通过回调
|
|
|
|
|
- this.onApprovalPassed(applyId);
|
|
|
|
|
- }
|
|
|
|
|
- } else { // 驳回
|
|
|
|
|
- apply.setApprovalStatus(3); // 已驳回
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Project project = projectService.getById(apply.getProjectId());
|
|
|
|
|
+ Integer companyId = project != null ? project.getCompanyId() : null;
|
|
|
|
|
+ List<ProjectClosureApplier> flow = companyId != null ? getApprovalFlow(companyId) : new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (reject) {
|
|
|
|
|
+ apply.setApprovalStatus(3);
|
|
|
|
|
+ apply.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ this.updateById(apply);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!pass) {
|
|
|
|
|
+ throw new RuntimeException("不支持的审批操作");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int nextStepIndex = (apply.getCurrentStep() == null ? 0 : apply.getCurrentStep()) + 1;
|
|
|
|
|
+ apply.setCurrentStep(nextStepIndex);
|
|
|
|
|
+ if (nextStepIndex >= flow.size()) {
|
|
|
|
|
+ apply.setApprovalStatus(2);
|
|
|
|
|
+ apply.setCurrentApproverId(null);
|
|
|
|
|
+ apply.setCurrentApproverName(null);
|
|
|
|
|
+ apply.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ this.updateById(apply);
|
|
|
|
|
+ onApprovalPassed(applyId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ProjectClosureApplier next = flow.get(nextStepIndex);
|
|
|
|
|
+ apply.setCurrentApproverId(next.getApproverUserId());
|
|
|
|
|
+ apply.setCurrentApproverName(next.getApproverName());
|
|
|
|
|
+ apply.setApprovalStatus(1);
|
|
|
|
|
+ apply.setUpdateTime(LocalDateTime.now());
|
|
|
this.updateById(apply);
|
|
this.updateById(apply);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Map<String, Object> getProgress(Integer applyId) {
|
|
|
|
|
|
|
+ public Map<String, Object> getProgress(Integer applyId, String viewerUserId) {
|
|
|
|
|
+ Map<String, Object> progress = new HashMap<>();
|
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
|
if (apply == null) {
|
|
if (apply == null) {
|
|
|
- return new HashMap<>();
|
|
|
|
|
|
|
+ return progress;
|
|
|
|
|
+ }
|
|
|
|
|
+ Project project = projectService.getById(apply.getProjectId());
|
|
|
|
|
+ Integer companyId = project != null ? project.getCompanyId() : null;
|
|
|
|
|
+ List<ProjectClosureApplier> flowList = companyId != null ? getApprovalFlow(companyId) : new ArrayList<>();
|
|
|
|
|
+ List<Map<String, Object>> flow = new ArrayList<>();
|
|
|
|
|
+ for (ProjectClosureApplier step : flowList) {
|
|
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
|
|
+ row.put("approverName", step.getApproverName());
|
|
|
|
|
+ row.put("approverUserId", step.getApproverUserId());
|
|
|
|
|
+ flow.add(row);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- Map<String, Object> progress = new HashMap<>();
|
|
|
|
|
- progress.put("apply", apply);
|
|
|
|
|
- progress.put("logs", approvalLogMapper.selectList(
|
|
|
|
|
- new QueryWrapper<ProjectClosureApprovalLog>()
|
|
|
|
|
- .eq("apply_id", applyId)
|
|
|
|
|
- .orderByDesc("create_time")
|
|
|
|
|
- ));
|
|
|
|
|
-
|
|
|
|
|
- // 获取审批流程
|
|
|
|
|
- ProjectClosureApply actualApply = this.getById(applyId);
|
|
|
|
|
- // TODO: 需要通过项目ID获取timeTypeId,然后获取审批流程
|
|
|
|
|
- List<ProjectClosureApplier> flow = new ArrayList<>();
|
|
|
|
|
progress.put("flow", flow);
|
|
progress.put("flow", flow);
|
|
|
-
|
|
|
|
|
|
|
+ boolean canApprove = StringUtils.hasText(viewerUserId)
|
|
|
|
|
+ && Objects.equals(viewerUserId, apply.getCurrentApproverId())
|
|
|
|
|
+ && (apply.getApprovalStatus() != null && (apply.getApprovalStatus() == 0 || apply.getApprovalStatus() == 1));
|
|
|
|
|
+ progress.put("canApprove", canApprove);
|
|
|
return progress;
|
|
return progress;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<ProjectClosureApprovalLog> getApprovalLogs(Integer applyId) {
|
|
public List<ProjectClosureApprovalLog> getApprovalLogs(Integer applyId) {
|
|
|
- return approvalLogMapper.selectList(
|
|
|
|
|
- new QueryWrapper<ProjectClosureApprovalLog>()
|
|
|
|
|
- .eq("apply_id", applyId)
|
|
|
|
|
- .orderByDesc("create_time")
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ List<ProjectClosureApprovalLog> logs = approvalLogMapper.selectList(
|
|
|
|
|
+ new QueryWrapper<ProjectClosureApprovalLog>()
|
|
|
|
|
+ .eq("apply_id", applyId)
|
|
|
|
|
+ .orderByAsc("create_time"));
|
|
|
|
|
+ for (ProjectClosureApprovalLog log : logs) {
|
|
|
|
|
+ log.setApplierName(log.getApproverName());
|
|
|
|
|
+ log.setComment(log.getOpinion());
|
|
|
|
|
+ if (log.getCreateTime() != null) {
|
|
|
|
|
+ log.setApproveTime(log.getCreateTime().format(DT_FMT));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return logs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public IPage<ProjectClosureApply> getMyPendingApproval(Integer userId, int current, int size) {
|
|
|
|
|
|
|
+ public IPage<ProjectClosureApply> getMyPendingApproval(String userId, int current, int size, Integer status) {
|
|
|
Page<ProjectClosureApply> page = new Page<>(current, size);
|
|
Page<ProjectClosureApply> page = new Page<>(current, size);
|
|
|
|
|
+ User viewer = userService.getById(userId);
|
|
|
|
|
+ if (viewer == null || viewer.getCompanyId() == null) {
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer companyId = viewer.getCompanyId();
|
|
|
QueryWrapper<ProjectClosureApply> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<ProjectClosureApply> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("current_approver_id", userId)
|
|
|
|
|
- .in("approval_status", 0, 1) // 待审批或审批中
|
|
|
|
|
- .orderByDesc("create_time");
|
|
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ wrapper.inSql("project_id", "select id from project where company_id = " + companyId)
|
|
|
|
|
+ .and(w -> w.eq("current_approver_id", userId).or().eq("applicant_id", userId));
|
|
|
|
|
+ int st = status == null ? 0 : status;
|
|
|
|
|
+ if (st == 1) {
|
|
|
|
|
+ wrapper.in("approval_status", 0, 1);
|
|
|
|
|
+ } else if (st == 2) {
|
|
|
|
|
+ wrapper.eq("approval_status", 2);
|
|
|
|
|
+ } else if (st == 3) {
|
|
|
|
|
+ wrapper.eq("approval_status", 3);
|
|
|
|
|
+ } else if (st == 4) {
|
|
|
|
|
+ wrapper.eq("approval_status", 4);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc("create_time");
|
|
|
|
|
+ IPage<ProjectClosureApply> result = this.page(page, wrapper);
|
|
|
|
|
+ for (ProjectClosureApply row : result.getRecords()) {
|
|
|
|
|
+ decorateApply(row, userId, companyId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public IPage<ProjectClosureApply> getMyApplyList(Integer userId, int current, int size) {
|
|
|
|
|
|
|
+ public IPage<ProjectClosureApply> getMyApplyList(String userId, int current, int size) {
|
|
|
Page<ProjectClosureApply> page = new Page<>(current, size);
|
|
Page<ProjectClosureApply> page = new Page<>(current, size);
|
|
|
|
|
+ User viewer = userService.getById(userId);
|
|
|
|
|
+ Integer companyId = viewer != null ? viewer.getCompanyId() : null;
|
|
|
QueryWrapper<ProjectClosureApply> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<ProjectClosureApply> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("applicant_id", userId)
|
|
|
|
|
- .orderByDesc("create_time");
|
|
|
|
|
- return this.page(page, wrapper);
|
|
|
|
|
|
|
+ wrapper.eq("applicant_id", userId);
|
|
|
|
|
+ if (companyId != null) {
|
|
|
|
|
+ wrapper.inSql("project_id", "select id from project where company_id = " + companyId);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc("create_time");
|
|
|
|
|
+ IPage<ProjectClosureApply> result = this.page(page, wrapper);
|
|
|
|
|
+ for (ProjectClosureApply row : result.getRecords()) {
|
|
|
|
|
+ decorateApply(row, userId, companyId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void onApprovalPassed(Integer applyId) {
|
|
public void onApprovalPassed(Integer applyId) {
|
|
|
- // 审批通过后,更新项目状态
|
|
|
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
ProjectClosureApply apply = this.getById(applyId);
|
|
|
- if (apply != null) {
|
|
|
|
|
- // TODO: 调用项目Service更新项目状态为"已结项"
|
|
|
|
|
- // projectService.updateStatus(apply.getProjectId(), ProjectStatus.CLOSED);
|
|
|
|
|
|
|
+ if (apply == null) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ Project upd = new Project();
|
|
|
|
|
+ upd.setId(apply.getProjectId());
|
|
|
|
|
+ upd.setStatus(2);
|
|
|
|
|
+ upd.setFinishDate(LocalDate.now());
|
|
|
|
|
+ projectService.updateById(upd);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取下一个审批人
|
|
|
|
|
- */
|
|
|
|
|
- private ProjectClosureApplier getNextApprover(Integer projectId, int currentStep) {
|
|
|
|
|
- // TODO: 需要通过项目获取timeTypeId,然后查询审批人
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ProjectClosureApply getApplyView(Integer id, String viewerUserId) {
|
|
|
|
|
+ ProjectClosureApply apply = this.getById(id);
|
|
|
|
|
+ if (apply == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Project project = projectService.getById(apply.getProjectId());
|
|
|
|
|
+ Integer companyId = project != null ? project.getCompanyId() : null;
|
|
|
|
|
+ decorateApply(apply, viewerUserId, companyId);
|
|
|
|
|
+ return apply;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置下一个审批人
|
|
|
|
|
- */
|
|
|
|
|
- private void setNextApprover(Integer applyId) {
|
|
|
|
|
- ProjectClosureApply apply = this.getById(applyId);
|
|
|
|
|
- if (apply != null) {
|
|
|
|
|
- ProjectClosureApplier firstApprover = this.getNextApprover(apply.getProjectId(), 0);
|
|
|
|
|
- if (firstApprover != null) {
|
|
|
|
|
- apply.setCurrentApproverId(firstApprover.getApproverUserId());
|
|
|
|
|
- apply.setCurrentApproverName(firstApprover.getApproverName());
|
|
|
|
|
- this.updateById(apply);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private void decorateApply(ProjectClosureApply apply, String viewerUserId, Integer companyId) {
|
|
|
|
|
+ int total = companyId != null ? getApprovalFlow(companyId).size() : 0;
|
|
|
|
|
+ apply.setTotalStep(total);
|
|
|
|
|
+ apply.setReason(apply.getRemark());
|
|
|
|
|
+ apply.setCurrentApplierName(apply.getCurrentApproverName());
|
|
|
|
|
+ if (apply.getCreateTime() != null) {
|
|
|
|
|
+ apply.setApplyTime(apply.getCreateTime().format(DT_FMT));
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer s = apply.getApprovalStatus();
|
|
|
|
|
+ if (s == null) {
|
|
|
|
|
+ apply.setStatus(1);
|
|
|
|
|
+ } else if (s == 0 || s == 1) {
|
|
|
|
|
+ apply.setStatus(1);
|
|
|
|
|
+ } else if (s == 2) {
|
|
|
|
|
+ apply.setStatus(2);
|
|
|
|
|
+ } else if (s == 3) {
|
|
|
|
|
+ apply.setStatus(3);
|
|
|
|
|
+ } else if (s == 4) {
|
|
|
|
|
+ apply.setStatus(4);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ apply.setStatus(1);
|
|
|
}
|
|
}
|
|
|
|
|
+ int cs = apply.getCurrentStep() == null ? 0 : apply.getCurrentStep();
|
|
|
|
|
+ apply.setCurrentStepDisplay(total > 0 ? (cs + 1) + "/" + total : "-");
|
|
|
|
|
+ boolean can = StringUtils.hasText(viewerUserId)
|
|
|
|
|
+ && Objects.equals(viewerUserId, apply.getCurrentApproverId())
|
|
|
|
|
+ && (s != null && (s == 0 || s == 1));
|
|
|
|
|
+ apply.setCanApprove(can);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|