This commit is contained in:
lijiaqi 2023-10-24 13:43:34 +08:00
parent 74e426db33
commit bf461d7880
5 changed files with 147 additions and 2 deletions

View File

@ -262,4 +262,23 @@ public class WorkFlowController extends BaseController {
endTime);
}
/**
* 已处理
*/
@GetMapping(value = "/getDoneFlowList")
@ApiOperation(value = "已处理")
@ApiImplicitParams({
@ApiImplicitParam(name = "current", value = "当前页", dataType = "Integer"),
@ApiImplicitParam(name = "size", value = "每页条数", dataType = "Integer")
})
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = WorkFlowDto.class)
}),
order = 13
)
public AjaxResult getDoneFlowList() {
return workFlowService.getDoneFlowList(getPage());
}
}

View File

@ -14,7 +14,7 @@ public class WorkFlowStepVo {
@ApiModelProperty(value = "表单数据")
private String data;
@ApiModelProperty(value = "执行状态 REFUSE 驳回 PASS 通过 SUBMIT 已提交")
@ApiModelProperty(value = "执行状态 REFUSE 驳回 PASS 通过 SUBMIT 已提交 REFUSE_SUPERIOR 驳回上级")
@NotBlank(message = "执行状态不能为空")
private String status;

View File

@ -1,5 +1,6 @@
package com.ydool.oa.workFlow.data.vo;
import com.ydool.oa.workFlow.data.entity.WorkFlow;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -20,4 +21,6 @@ public class WorkFlowVo {
@ApiModelProperty(value = "关联的预算流程id 用于维修决算 前提必须有预算申请并且通过")
private String workFlowId;
private WorkFlow workFlow;
}

View File

@ -21,7 +21,10 @@ public enum WorkFlowStepStatusEnum {
* 结束
*/
DONE("DONE", "结束"),
;
/**
* 驳回上一级
*/
REFUSE_SUPERIOR("REFUSE_SUPERIOR", "驳回上一级");
/**

View File

@ -32,6 +32,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
@ -156,12 +158,112 @@ public class WorkFlowService extends BaseService<WorkFlowMapper, WorkFlow> {
return this.refuse(workFlow, vo.getRemarks());
case "SUBMIT":
// 4.3 提交
if (StrUtil.isBlank(vo.getData())) return AjaxResult.fail("表单数据不能为空");
if (workFlow.getStep() == 1) {
// 4.3.1 如果是第一步则修改流程提交数据
workFlow.setData(vo.getData());
boolean flag = updateById(workFlow);
// 4.3.2 修改流程步骤状态为已提交并改为开始节点
WorkFlowStep workFlowStep = workFlowStepService.getOne(new QueryWrapper<WorkFlowStep>().lambda()
.eq(WorkFlowStep::getFlowId, workFlow.getId())
.eq(WorkFlowStep::getStep, workFlow.getStep())
.eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString())
.last("limit 1")
);
workFlowStep.setStatus(WorkFlowStepStatusEnum.SUBMIT.getStatus());
workFlowStep.setStepType(WorkFlowStepTypeEnum.START.getType());
flag = workFlowStepService.updateById(workFlowStep);
// 4.3.3.保存流程步骤日志
WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData());
flag = workFlowStepLogService.save(workFlowStepLog);
// 4.3.4.判断是否进入下一步
return flag ? workFlowTypeFactory.getWorkFlowType(workFlow.getType()).first(workFlow) : AjaxResult.fail("发起失败");
}
return workFlowTypeFactory.getWorkFlowType(workFlow.getType()).execute(vo, workFlow);
case "REFUSE_SUPERIOR":
// 4.4 驳回上级
return this.refuseSuperior(workFlow, vo.getRemarks());
default:
return AjaxResult.fail("执行状态类型错误");
}
}
/**
* 驳回上级
*
* @param workFlow
* @param remarks
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult refuseSuperior(WorkFlow workFlow, String remarks) {
if (workFlow.getStep() == 1) return AjaxResult.fail("该流程已经是第一步,无法驳回上一级");
if (workFlow.getStepType().equals(WorkFlowStepTypeEnum.END.getType()))
return AjaxResult.fail("该流程已经结束,无法驳回上一级");
// 1.修改流程状态为驳回上级
WorkFlowStep workFlowStep = workFlowStepService.getOne(new QueryWrapper<WorkFlowStep>().lambda()
.eq(WorkFlowStep::getFlowId, workFlow.getId())
.eq(WorkFlowStep::getStep, workFlow.getStep())
.eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString())
.last("limit 1")
);
workFlowStep.setRemarks(remarks);
workFlowStep.setStatus(WorkFlowStepStatusEnum.REFUSE_SUPERIOR.getStatus());
// 2.记录流程日志
WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData());
boolean flag = workFlowStepLogService.save(workFlowStepLog);
// 3.找到上一步的环节集合
List<WorkFlowStep> superiorWorkFlowStepList = workFlowStepService.list(new QueryWrapper<WorkFlowStep>().lambda()
.eq(WorkFlowStep::getFlowId, workFlow.getId())
.eq(WorkFlowStep::getStep, workFlow.getStep() - 1)
.last("limit 1")
);
// 4.删除当前环节
flag = workFlowStepService.remove(new QueryWrapper<WorkFlowStep>()
.lambda()
.eq(WorkFlowStep::getFlowId, workFlow.getId())
.eq(WorkFlowStep::getStep, workFlow.getStep())
);
// 5.修改上一步流程状态集合为未开始
for (WorkFlowStep step : superiorWorkFlowStepList) {
step.setStatus(WorkFlowStepStatusEnum.NOT_START.getStatus());
// 如果上一步是开始节点则修改为填写节点
if (workFlow.getStep() - 1 == 1) {
step.setStepType(WorkFlowStepTypeEnum.WRITE.getType());
}
}
flag = workFlowStepService.updateBatchById(superiorWorkFlowStepList);
// 6.修改流程状态为上一步
workFlow.setStep(workFlow.getStep() - 1);
workFlow.setStepType(superiorWorkFlowStepList.get(0).getStepType());
flag = updateById(workFlow);
// 7.通知上一级人员审批被驳回
User user = userService.getById(workFlow.getUserId());
User loginUser = userService.getById(StpUtil.getLoginIdAsString());
String title = user.getUserName() + "" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "已被" + loginUser.getUserName() + "驳回给您,请重新处理";
List<WorkFlowNotice> workFlowNoticeList = new ArrayList<WorkFlowNotice>();
for (WorkFlowStep step : superiorWorkFlowStepList) {
WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, step.getUserId());
workFlowNoticeList.add(workFlowNotice);
}
flag = workFlowNoticeService.saveBatch(workFlowNoticeList);
if (flag) {
return AjaxResult.ok().msg("驳回上一级成功");
} else {
throw new ResultException("驳回上一级失败");
}
}
/**
* 驳回流程
*
@ -375,5 +477,23 @@ public class WorkFlowService extends BaseService<WorkFlowMapper, WorkFlow> {
}
/**
* 已处理的流程
*
* @param page
* @return
*/
public AjaxResult getDoneFlowList(Page page) {
Page<WorkFlow> pageList = page(page, new QueryWrapper<WorkFlow>().lambda()
.eq(WorkFlow::getStatus, WorkFlowStatusEnum.ACTIVE.getStatus())
.eq(WorkFlow::getStepType, WorkFlowStepTypeEnum.APPROVAL.getType())
.exists(
"select 1 from t_work_flow_step_log step_log where t_work_flow.id = step_log.flow_id " +
" and step_log.user_id = '" + StpUtil.getLoginIdAsString() + "'"
)
.orderByDesc(WorkFlow::getCreatedAt)
);
return AjaxResult.ok().data(WorkFlowWrapper.INSTANCE.toDto(pageList));
}
}