|
@@ -2,19 +2,24 @@ package com.ym.mec.education.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.ym.mec.education.base.BaseResponse;
|
|
|
import com.ym.mec.education.base.PageResponse;
|
|
|
+import com.ym.mec.education.entity.SysRole;
|
|
|
import com.ym.mec.education.entity.SysUser;
|
|
|
import com.ym.mec.education.enums.ApprovalStatusEnum;
|
|
|
import com.ym.mec.education.req.ApprovalReq;
|
|
|
import com.ym.mec.education.resp.ApprovalResp;
|
|
|
import com.ym.mec.education.service.ApprovalService;
|
|
|
+import com.ym.mec.education.service.ISysRoleService;
|
|
|
import com.ym.mec.education.service.ISysUserService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.snaker.engine.IQueryService;
|
|
|
import org.snaker.engine.access.Page;
|
|
|
import org.snaker.engine.access.QueryFilter;
|
|
|
-import org.snaker.engine.entity.WorkItem;
|
|
|
+import org.snaker.engine.core.AccessService;
|
|
|
+import org.snaker.engine.core.TaskService;
|
|
|
+import org.snaker.engine.entity.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -38,6 +43,10 @@ public class ApprovalServiceImpl implements ApprovalService {
|
|
|
private IQueryService queryService;
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService roleService;
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<ApprovalResp> getProcessingList(ApprovalReq approvalReq) {
|
|
@@ -69,22 +78,110 @@ public class ApprovalServiceImpl implements ApprovalService {
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<ApprovalResp> getLaunchList(ApprovalReq approvalReq) {
|
|
|
- return null;
|
|
|
+ if (Objects.isNull(approvalReq.getUserId())) {
|
|
|
+ return PageResponse.errorParam();
|
|
|
+ }
|
|
|
+ Page<HistoryOrder> page = new Page();
|
|
|
+ page.setPageNo(approvalReq.getPageNo());
|
|
|
+ page.setPageSize(approvalReq.getPageSize());
|
|
|
+ QueryFilter queryFilter = new QueryFilter();
|
|
|
+ queryFilter.setOperator(approvalReq.getUserId().toString());
|
|
|
+ queryService.getHistoryOrders(page, queryFilter);
|
|
|
+ Page<ApprovalResp> pageResult = new Page();
|
|
|
+ BeanUtils.copyProperties(page, pageResult);
|
|
|
+ List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
|
|
|
+ if (!CollectionUtils.isEmpty(page.getResult())) {
|
|
|
+ page.getResult().forEach(item -> {
|
|
|
+ ApprovalResp approvalResp = initApprovalResp(item.getVariable(), userService.getById(item.getCreator()));
|
|
|
+ approvalResp.setOrderId(item.getId()).setApprovalType(item.getProcessName())
|
|
|
+ .setApprovalDate(item.getCreateTime().substring(0, 10));
|
|
|
+ list.add(approvalResp);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ pageResult.setResult(list);
|
|
|
+ return PageResponse.success(pageResult);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public BaseResponse<ApprovalResp> getLaunchInfo(ApprovalReq approvalReq) {
|
|
|
- return null;
|
|
|
+ if (Objects.isNull(approvalReq.getOrderId())) {
|
|
|
+ return BaseResponse.errorParam();
|
|
|
+ }
|
|
|
+ Order order = queryService.getOrder(approvalReq.getOrderId());
|
|
|
+ ApprovalResp approvalResp = initApprovalResp(order.getVariable(), userService.getById(order.getCreator()));
|
|
|
+ QueryFilter queryFilter = new QueryFilter();
|
|
|
+ queryFilter.setOperator(order.getCreator()).orderBy("create_Time desc");
|
|
|
+ List<HistoryTask> historyTaskList = queryService.getHistoryTasks(queryFilter);
|
|
|
+ List<Task> activeTaskList = queryService.getActiveTasks(queryFilter);
|
|
|
+ List<ApprovalResp.ApprovalHistoryInfo> historyInfoList = Lists.newArrayList();
|
|
|
+ ApprovalResp.ApprovalHistoryInfo approvalHistoryInfo = ApprovalResp.getApprovalHistoryInfo();
|
|
|
+ approvalHistoryInfo.setOperator("我").setStatus("发起申请");
|
|
|
+ historyInfoList.add(approvalHistoryInfo);
|
|
|
+ if (!CollectionUtils.isEmpty(historyTaskList)) {
|
|
|
+ historyTaskList.forEach(task -> {
|
|
|
+ ApprovalResp.ApprovalHistoryInfo historyInfo = initApprovalHisotoryVariable(task.getVariable());
|
|
|
+ SysRole role = roleService.getById(task.getOperator());
|
|
|
+ if (Objects.nonNull(role)) {
|
|
|
+ Optional.ofNullable(role.getRoleName()).ifPresent(roleName -> historyInfo.setOperator(roleName));
|
|
|
+ }
|
|
|
+ historyInfoList.add(historyInfo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(activeTaskList)) {
|
|
|
+ historyTaskList.forEach(task -> {
|
|
|
+ ApprovalResp.ApprovalHistoryInfo historyInfo = initApprovalHisotoryVariable(task.getVariable());
|
|
|
+ SysRole role = roleService.getById(task.getOperator());
|
|
|
+ if (Objects.nonNull(role)) {
|
|
|
+ Optional.ofNullable(role.getRoleName()).ifPresent(roleName -> historyInfo.setOperator(roleName));
|
|
|
+ }
|
|
|
+ historyInfoList.add(historyInfo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ approvalResp.setApprovalHistory(historyInfoList);
|
|
|
+ return BaseResponse.success(approvalResp);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public BaseResponse<ApprovalResp> cancel(ApprovalReq approvalReq) {
|
|
|
- return null;
|
|
|
+ if (Objects.isNull(approvalReq.getOrderId()) || Objects.isNull(approvalReq.getUserId())) {
|
|
|
+ return BaseResponse.errorParam();
|
|
|
+ }
|
|
|
+ //查询该实例最新的任务
|
|
|
+ QueryFilter queryFilter = new QueryFilter();
|
|
|
+ queryFilter.setOrderId(approvalReq.getOrderId()).orderBy("create_Time desc");
|
|
|
+ List<Task> taskList = queryService.getActiveTasks(queryFilter);
|
|
|
+ taskList.stream().findFirst().ifPresent(task -> taskService.withdrawTask(task.getId(),
|
|
|
+ approvalReq.getUserId().toString()));
|
|
|
+ return BaseResponse.success("取消成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<ApprovalResp> getCcList(ApprovalReq approvalReq) {
|
|
|
- return null;
|
|
|
+ if (Objects.isNull(approvalReq.getUserId())) {
|
|
|
+ return PageResponse.errorParam();
|
|
|
+ }
|
|
|
+ Page<HistoryOrder> page = new Page();
|
|
|
+ page.setPageNo(approvalReq.getPageNo());
|
|
|
+ page.setPageSize(approvalReq.getPageSize());
|
|
|
+ QueryFilter queryFilter = new QueryFilter();
|
|
|
+ queryFilter.setOperator(approvalReq.getUserId().toString());
|
|
|
+ if (Objects.nonNull(approvalReq.getStatus()) && approvalReq.getStatus() == 0) {
|
|
|
+ //未读
|
|
|
+ queryFilter.setState(AccessService.STATE_ACTIVE);
|
|
|
+ }
|
|
|
+ queryService.getCCWorks(page, queryFilter);
|
|
|
+ Page<ApprovalResp> pageResult = new Page();
|
|
|
+ List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
|
|
|
+ if (!CollectionUtils.isEmpty(page.getResult())) {
|
|
|
+ page.getResult().forEach(item -> {
|
|
|
+ ApprovalResp approvalResp = initApprovalResp(item.getVariable(), userService.getById(item.getCreator()));
|
|
|
+ approvalResp.setOrderId(item.getId()).setApprovalType(item.getProcessName())
|
|
|
+ .setApprovalDate(item.getCreateTime().substring(0, 10));
|
|
|
+ list.add(approvalResp);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ pageResult.setResult(list);
|
|
|
+ return PageResponse.success(pageResult);
|
|
|
}
|
|
|
|
|
|
private Page<ApprovalResp> workItem2Approval(Page<WorkItem> page) {
|
|
@@ -93,19 +190,8 @@ public class ApprovalServiceImpl implements ApprovalService {
|
|
|
List<ApprovalResp> list = new ArrayList<>(page.getResult().size());
|
|
|
if (!CollectionUtils.isEmpty(page.getResult())) {
|
|
|
page.getResult().forEach(item -> {
|
|
|
- ApprovalResp approvalResp = new ApprovalResp();
|
|
|
SysUser user = userService.getById(item.getCreator());
|
|
|
- if (Objects.nonNull(user)) {
|
|
|
- Optional.ofNullable(user.getRealName()).ifPresent(name -> approvalResp.setApplicant(name));
|
|
|
- }
|
|
|
- String orderVariable = item.getOrderVariable();
|
|
|
- if (StringUtils.isNotBlank(orderVariable)) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(orderVariable);
|
|
|
- approvalResp.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
|
|
|
- Optional.ofNullable(jsonObject.getString("startTime")).ifPresent(time -> approvalResp.setStartTime(time));
|
|
|
- Optional.ofNullable(jsonObject.getString("endTime")).ifPresent(time -> approvalResp.setEndTime(time));
|
|
|
- Optional.ofNullable(jsonObject.getString("remark")).ifPresent(remark -> approvalResp.setRemark(remark));
|
|
|
- }
|
|
|
+ ApprovalResp approvalResp = initApprovalResp(item.getOrderVariable(), user);
|
|
|
approvalResp.setTaskId(item.getTaskId()).setApprovalType(item.getProcessName())
|
|
|
.setApprovalDate(item.getOrderCreateTime().substring(0, 10));
|
|
|
list.add(approvalResp);
|
|
@@ -114,4 +200,35 @@ public class ApprovalServiceImpl implements ApprovalService {
|
|
|
pageResult.setResult(list);
|
|
|
return pageResult;
|
|
|
}
|
|
|
+
|
|
|
+ private ApprovalResp initApprovalResp(String variable, SysUser user) {
|
|
|
+ ApprovalResp approvalResp = initApprovalVariable(variable);
|
|
|
+ if (Objects.nonNull(user)) {
|
|
|
+ Optional.ofNullable(user.getRealName()).ifPresent(name -> approvalResp.setApplicant(name));
|
|
|
+ Optional.ofNullable(user.getAvatar()).ifPresent(img -> approvalResp.setApplicantImg(img));
|
|
|
+ }
|
|
|
+ return approvalResp;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ApprovalResp initApprovalVariable(String variable) {
|
|
|
+ ApprovalResp approvalResp = new ApprovalResp();
|
|
|
+ if (StringUtils.isNotBlank(variable)) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(variable);
|
|
|
+ approvalResp.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
|
|
|
+ Optional.ofNullable(jsonObject.getString("startTime")).ifPresent(time -> approvalResp.setStartTime(time));
|
|
|
+ Optional.ofNullable(jsonObject.getString("endTime")).ifPresent(time -> approvalResp.setEndTime(time));
|
|
|
+ Optional.ofNullable(jsonObject.getString("remark")).ifPresent(remark -> approvalResp.setRemark(remark));
|
|
|
+ }
|
|
|
+ return approvalResp;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ApprovalResp.ApprovalHistoryInfo initApprovalHisotoryVariable(String variable) {
|
|
|
+ ApprovalResp.ApprovalHistoryInfo historyInfo = ApprovalResp.getApprovalHistoryInfo();
|
|
|
+ if (StringUtils.isNotBlank(variable)) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(variable);
|
|
|
+ historyInfo.setStatus(ApprovalStatusEnum.getMsgByCode(jsonObject.getString("status")));
|
|
|
+ Optional.ofNullable(jsonObject.getString("reason")).ifPresent(reason -> historyInfo.setReason(reason));
|
|
|
+ }
|
|
|
+ return historyInfo;
|
|
|
+ }
|
|
|
}
|