package com.highdatas.mdm.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.highdatas.mdm.entity.Flows;
|
import com.highdatas.mdm.entity.Maintain;
|
import com.highdatas.mdm.entity.MaintainDetail;
|
import com.highdatas.mdm.entity.TUser;
|
import com.highdatas.mdm.pojo.ActivitiBusinessType;
|
import com.highdatas.mdm.pojo.ActivitiStatus;
|
import com.highdatas.mdm.pojo.Page;
|
import com.highdatas.mdm.pojo.Result;
|
import com.highdatas.mdm.service.*;
|
import com.highdatas.mdm.service.act.*;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpSession;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author kimi
|
* @description
|
* @date 2019-12-17 10:48
|
*/
|
|
@Service
|
public class ActivitiServiceImpl implements ActivitiService{
|
@Autowired
|
IdentityService identityService;
|
@Autowired
|
IMaintainService maintainService;
|
|
@Autowired
|
IMaintainDetailService maintainDetailService;
|
|
@Autowired
|
TaskService taskService;
|
|
@Autowired
|
IFlowsService flowsService;
|
|
@Autowired
|
ITUserService userService;
|
|
@Autowired
|
HistoryService historyService;
|
|
@Autowired
|
RepositoryService repositoryService;
|
|
@Autowired
|
RuntimeService runtimeService;
|
|
|
@Override
|
public Flows start(String key, HttpSession session, String maintainId, ActivitiBusinessType type) {
|
identityService.setSession( session);
|
Flows flows = new Flows();
|
String id = UUID.randomUUID().toString().replaceAll("-", "");
|
flows.setId(id);
|
flows.setBusinessId(maintainId);
|
flows.setBusinessType(type);
|
flows.setStatus(ActivitiStatus.working);
|
HashMap<String, Object> variableMap = new HashMap<>();
|
variableMap.put("reasson", "申请审批");
|
String workflowId = identityService.startProcess(id, key, null, variableMap);
|
flows.setWorkflowId(workflowId);
|
flows.setCreateTime(new Date());
|
TUser user = (TUser) session.getAttribute("user");
|
String user_id = user.getUserId();
|
flows.setUserId(user_id);
|
boolean inserted = flowsService.insert(flows);
|
if (inserted) {
|
return flows;
|
} else {
|
return null;
|
}
|
}
|
|
@Override
|
public Result todoTask(HttpSession session, String tableName, Integer pageNo, Integer pageSize) {
|
taskService.setSession(session);
|
List<String> todoTask = taskService.getTodoTask();
|
if (todoTask.size() == 0) {
|
return Result.success(null);
|
}
|
|
Wrapper<Flows> flowsWrapper = new EntityWrapper<Flows>().in("workflow_id", todoTask).eq("business_type", ActivitiBusinessType.maintain);
|
flowsWrapper.orderBy("create_time desc");
|
List<Flows> records = flowsService.selectList(flowsWrapper);
|
|
List<Flows> result = new ArrayList<>();
|
|
if (!StringUtils.isEmpty(tableName)) {
|
records = records.stream()
|
.filter(flows -> maintainService.selectById(flows.getBusinessId()) != null)
|
.filter(flows -> maintainService.selectById(flows.getBusinessId()).getTableName().equalsIgnoreCase(tableName)).collect(Collectors.toList());
|
}
|
Page page = new Page(records.size());
|
page.setPageNo(pageNo);
|
if (pageSize != null) {
|
page.setPageSize(pageSize);
|
}
|
records = records.stream().skip(page.getBeginRecordNo_1()).limit(pageSize).collect(Collectors.toList());
|
|
for (Flows flow : records) {
|
String userId = flow.getUserId();
|
TUser user = userService.selectOne(new EntityWrapper<TUser>().eq("user_id", userId));
|
if (user == null) {
|
continue;
|
}
|
flow.setUserId(user.getUserName());
|
|
String businessId = flow.getBusinessId();
|
int recordCount = maintainDetailService.selectCount(new EntityWrapper<MaintainDetail>().eq("parent_id", businessId));
|
|
if (!StringUtils.isEmpty(tableName)) {
|
Maintain maintain = maintainService.selectById(businessId);
|
if (maintain == null) {
|
continue;
|
}
|
if (!maintain.getTableName().equalsIgnoreCase(tableName)) {
|
continue;
|
}
|
flow.setRecordCount(recordCount);
|
}
|
result.add(flow);
|
}
|
|
com.baomidou.mybatisplus.plugins.Page<Flows> flowPages = new com.baomidou.mybatisplus.plugins.Page<>();
|
flowPages.setRecords(records);
|
flowPages.setSize(pageSize);
|
flowPages.setCurrent(pageNo);
|
flowPages.setTotal(page.getRecordCount());
|
return Result.success(flowPages);
|
}
|
}
|