65 lines
2.1 KiB
Java
65 lines
2.1 KiB
Java
|
|
package cn.palmte.work.service;
|
|||
|
|
|
|||
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|||
|
|
import org.springframework.stereotype.Service;
|
|||
|
|
import org.springframework.util.CollectionUtils;
|
|||
|
|
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.stream.Collectors;
|
|||
|
|
|
|||
|
|
import javax.persistence.EntityManager;
|
|||
|
|
import javax.persistence.TypedQuery;
|
|||
|
|
|
|||
|
|
import cn.palmte.work.model.Admin;
|
|||
|
|
import cn.palmte.work.model.enums.ProcessStatus;
|
|||
|
|
import lombok.RequiredArgsConstructor;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
|
|||
|
|
* @since 2.0 2022/12/23 09:39
|
|||
|
|
*/
|
|||
|
|
@Service
|
|||
|
|
@RequiredArgsConstructor
|
|||
|
|
public class ProjectProcessService {
|
|||
|
|
|
|||
|
|
private final JdbcTemplate jdbcTemplate;
|
|||
|
|
private final EntityManager entityManager;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 更新流程 审批人,和状态
|
|||
|
|
*
|
|||
|
|
* @param processId 流程Id
|
|||
|
|
* @param auditId 审批人ID
|
|||
|
|
* @param status 流程状态 可以为空,为空的时候不修改
|
|||
|
|
*/
|
|||
|
|
public void updateAudit(int processId, ProcessStatus status, List<Integer> auditId) {
|
|||
|
|
String currentAudit = getCurrentAudit(auditId);
|
|||
|
|
String currentAuditId = auditId.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|||
|
|
if (status != null) {
|
|||
|
|
if (!CollectionUtils.isEmpty(auditId)) {
|
|||
|
|
jdbcTemplate.update(
|
|||
|
|
"update project_process set current_audit=?,current_audit_id=?,status=? where id=?", currentAudit, currentAuditId, status.getValue(), processId);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
jdbcTemplate.update("update project_process set current_audit=?,current_audit_id=? where id=?", currentAudit, currentAuditId, processId);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private String getCurrentAudit(List<Integer> auditId) {
|
|||
|
|
TypedQuery<Admin> query = entityManager.createQuery("from Admin where id in (:ids)", Admin.class);
|
|||
|
|
query.setParameter("ids", auditId);
|
|||
|
|
List<Admin> resultList = query.getResultList();
|
|||
|
|
return resultList.stream().map(Admin::getRealName)
|
|||
|
|
.collect(Collectors.joining(","));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 只更新状态
|
|||
|
|
*/
|
|||
|
|
public void updateProcessStatus(int processId, ProcessStatus status) {
|
|||
|
|
jdbcTemplate.update("update project_process set `status`=? where id=?", status.getValue(), processId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|