package com.lxzn.activiti.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.lxzn.activiti.dao.AssignFileStreamMapper;
|
import com.lxzn.activiti.service.IActivitiDefinitionService;
|
import com.lxzn.activiti.service.IAssignFileStreamService;
|
import com.lxzn.activiti.service.IToEquipmentTaskService;
|
import com.lxzn.activiti.service.SecureDocService;
|
import com.lxzn.auth.JwtUtil;
|
import com.lxzn.base.service.IDncLogService;
|
import com.lxzn.framework.domain.activiti.AssignFileStream;
|
import com.lxzn.framework.domain.activiti.ToEquipmentTask;
|
import com.lxzn.framework.domain.activiti.ext.ActTaskExt;
|
import com.lxzn.framework.domain.activiti.ext.AssignFileStreamExt;
|
import com.lxzn.framework.domain.activiti.request.ApproveBatchRequest;
|
import com.lxzn.framework.domain.activiti.request.AssignFileRequest;
|
import com.lxzn.framework.domain.activiti.request.AssignFileStreamQueryRequest;
|
import com.lxzn.framework.domain.activiti.request.TaskRequest;
|
import com.lxzn.framework.domain.activiti.response.ActivitiCode;
|
import com.lxzn.framework.domain.base.DncLog;
|
import com.lxzn.framework.domain.nc.*;
|
import com.lxzn.framework.domain.nc.response.DeviceCode;
|
import com.lxzn.framework.domain.nc.response.DocumentCode;
|
import com.lxzn.framework.domain.ucenter.Department;
|
import com.lxzn.framework.domain.ucenter.response.UcenterCode;
|
import com.lxzn.framework.exception.ExceptionCast;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.model.response.QueryPageResponseResult;
|
import com.lxzn.framework.model.response.ResponseResult;
|
import com.lxzn.framework.model.response.ResultCode;
|
import com.lxzn.framework.utils.LogCodeUtil;
|
import com.lxzn.framework.utils.TelnetUtil;
|
import com.lxzn.framework.utils.ValidateUtil;
|
import com.lxzn.framework.utils.date.DateUtil;
|
import com.lxzn.framework.utils.file.FileUtil;
|
import com.lxzn.nc.service.*;
|
import com.lxzn.ucenter.service.IDepartmentService;
|
import org.activiti.engine.HistoryService;
|
import org.activiti.engine.RuntimeService;
|
import org.activiti.engine.TaskService;
|
import org.activiti.engine.history.HistoricProcessInstance;
|
import org.activiti.engine.runtime.ProcessInstance;
|
import org.activiti.engine.task.Task;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService {
|
private static final String PROCESS_KEY = "assign_nc_to_device";
|
private static final String APPLY_VARIABLE = "apply_user";
|
private static final String APPROVE_VARIABLE = "approve_users";
|
private static final String SEND_CODE = "SEND";
|
|
@Value("${activiti.enable}")
|
private Boolean activeEnable;
|
|
@Autowired
|
private RuntimeService runtimeService;
|
@Autowired
|
private TaskService taskService;
|
@Autowired
|
private IDocInfoService docInfoService;
|
@Autowired
|
private IProcessStreamService processStreamService;
|
@Autowired
|
private IPermissionStreamService permissionStreamService;
|
@Autowired
|
private IDepartmentService departmentService;
|
@Autowired
|
private HistoryService historyService;
|
@Autowired
|
private IDocClassificationService classificationService;
|
@Autowired
|
private IToEquipmentTaskService equipmentTaskService;
|
@Autowired
|
private IDeviceInfoService deviceInfoService;
|
@Autowired
|
private IDocFileService docFileService;
|
@Autowired
|
private IActivitiDefinitionService definitionService;
|
@Autowired
|
private IDocRelativeService docRelativeService;
|
@Autowired
|
private ISynchronizedFlagService synchronizedFlagService;
|
@Autowired
|
private SecureDocService secureDocService;
|
@Autowired
|
private IPartsInfoService partsInfoService;
|
@Autowired
|
private IDncLogService dncLogService;
|
@Autowired
|
private IComponentInfoService componentInfoService;
|
@Value("${securedoc.serverIp}")
|
private String serverIp;
|
@Value("${securedoc.serverPort}")
|
private int serverPort;
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public ResponseResult applyAssignFile(AssignFileStream stream) {
|
synchronized (this){
|
if(activeEnable) {
|
return applyAssignFileActiveTest(stream);
|
}else {
|
boolean b = applyAssignFileNonActive(stream);
|
if (b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
} else {
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
}
|
}
|
|
}
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public ResponseResult applyAssignFileActiveTest(AssignFileStream stream) {
|
boolean btelnetPort = TelnetUtil.telnetPort(serverIp,serverPort,10);
|
if (!btelnetPort) {
|
return new ResponseResult(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
//校验开始
|
if(stream == null)
|
return new ResponseResult(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getProcessId()) || !ValidateUtil.validateString(stream.getDocId())
|
|| !ValidateUtil.validateString(stream.getFileId()))
|
return new ResponseResult(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
if(!ValidateUtil.validateString(stream.getDeviceId()))
|
return new ResponseResult(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return new ResponseResult(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 5, stream.getProcessId());
|
if(docInfo == null || docInfo.getDocStatus() == 3)
|
return new ResponseResult(ActivitiCode.ACT_DOC_ERROR);
|
DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId());
|
if(deviceDoc != null)
|
return new ResponseResult(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId(),docInfo.getDocSuffix());
|
if(deviceDoc != null)
|
return new ResponseResult(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId());
|
if(deviceInfo == null)
|
return new ResponseResult(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
ProcessStream processStream = processStreamService.getById(stream.getProcessId());
|
if(processStream == null)
|
return new ResponseResult(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
stream.setProductId(processStream.getProductId());
|
stream.setComponentId(processStream.getComponentId());
|
stream.setPartsId(processStream.getPartsId());
|
List<PermissionStream> permissionStreams = null;
|
if(ValidateUtil.validateString(processStream.getPartsId())) {
|
//进入零件
|
permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
|
}else if(ValidateUtil.validateString(processStream.getComponentId())) {
|
//进入部件的处理
|
permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
|
}
|
if(permissionStreams == null || permissionStreams.isEmpty())
|
return new ResponseResult(ActivitiCode.ACT_NODE_DEPART_NONE);
|
List<String> departIds = new ArrayList<>();
|
Map<String, Department> map = departmentService.getMapByUserId(userId);
|
permissionStreams.forEach(item -> {
|
if(map.containsKey(item.getDepartId())) {
|
departIds.add(item.getDepartId());
|
}
|
});
|
if(departIds.isEmpty())
|
return new ResponseResult(ActivitiCode.ACT_USER_NOT_PERM);
|
//获取部门审批人
|
List<String> userIdList = definitionService.getByDepartIds(departIds);
|
if(userIdList == null || userIdList.isEmpty())
|
return new ResponseResult(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//校验结束
|
String streamId = IdWorker.getIdStr();
|
stream.setStreamId(streamId);
|
stream.setApplyUserId(userId);
|
stream.setApplyTime(DateUtil.getNow());
|
stream.setStatus(1);
|
DocFile docFile = docFileService.getById(stream.getFileId());
|
String newPath = "/securedoc" + docFile.getFilePath();
|
stream.setSecurePath(newPath);
|
//保存流程业务对象
|
boolean b = super.save(stream);
|
if(!b)
|
return new ResponseResult(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
//保存流程任务
|
String approveUsers = String.join(",", userIdList);
|
Map<String, Object> avariableMap = new HashMap<>();
|
avariableMap.put(APPLY_VARIABLE, userId);
|
avariableMap.put(APPROVE_VARIABLE, approveUsers);
|
//启动流程
|
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, streamId, avariableMap);
|
if(processInstance == null)
|
return new ResponseResult(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//查询当前流程用户流程任务
|
Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId)
|
.processInstanceId(processInstance.getId()).singleResult();
|
if(task == null)
|
return new ResponseResult(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//完成流程任务
|
taskService.complete(task.getId());
|
//复制文件,进行预定密 TODO
|
b = FileUtil.copyFile(docFile.getFilePath(), newPath, docFile.getFileEncodeName());
|
if(!b){
|
return new ResponseResult(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
}
|
String absPath = FileUtil.getFileAbsPath(newPath, docFile.getFileEncodeName());
|
if(absPath == null){
|
return new ResponseResult(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
}
|
try {
|
secureDocService.binByFileLable(absPath);
|
}catch (Exception e) {
|
return new ResponseResult(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean applyAssignFileActive(AssignFileStream stream) {
|
boolean btelnetPort = TelnetUtil.telnetPort(serverIp,serverPort,10);
|
if (!btelnetPort) {
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
//校验开始
|
if(stream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getProcessId()) || !ValidateUtil.validateString(stream.getDocId())
|
|| !ValidateUtil.validateString(stream.getFileId()))
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
if(!ValidateUtil.validateString(stream.getDeviceId()))
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 5, stream.getProcessId());
|
if(docInfo == null || docInfo.getDocStatus() == 3)
|
ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
|
DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId(),docInfo.getDocSuffix());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId());
|
if(deviceInfo == null)
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
ProcessStream processStream = processStreamService.getById(stream.getProcessId());
|
if(processStream == null)
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
stream.setProductId(processStream.getProductId());
|
stream.setComponentId(processStream.getComponentId());
|
stream.setPartsId(processStream.getPartsId());
|
List<PermissionStream> permissionStreams = null;
|
if(ValidateUtil.validateString(processStream.getPartsId())) {
|
//进入零件
|
permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
|
}else if(ValidateUtil.validateString(processStream.getComponentId())) {
|
//进入部件的处理
|
permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
|
}
|
if(permissionStreams == null || permissionStreams.isEmpty())
|
ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
|
List<String> departIds = new ArrayList<>();
|
Map<String, Department> map = departmentService.getMapByUserId(userId);
|
permissionStreams.forEach(item -> {
|
if(map.containsKey(item.getDepartId())) {
|
departIds.add(item.getDepartId());
|
}
|
});
|
if(departIds.isEmpty())
|
ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM);
|
//获取部门审批人
|
List<String> userIdList = definitionService.getByDepartIds(departIds);
|
if(userIdList == null || userIdList.isEmpty())
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//校验结束
|
String streamId = IdWorker.getIdStr();
|
stream.setStreamId(streamId);
|
stream.setApplyUserId(userId);
|
stream.setApplyTime(DateUtil.getNow());
|
stream.setStatus(1);
|
DocFile docFile = docFileService.getById(stream.getFileId());
|
String newPath = "/securedoc" + docFile.getFilePath();
|
stream.setSecurePath(newPath);
|
//保存流程业务对象
|
boolean b = super.save(stream);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
//保存流程任务
|
String approveUsers = String.join(",", userIdList);
|
Map<String, Object> avariableMap = new HashMap<>();
|
avariableMap.put(APPLY_VARIABLE, userId);
|
avariableMap.put(APPROVE_VARIABLE, approveUsers);
|
//启动流程
|
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, streamId, avariableMap);
|
if(processInstance == null)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//查询当前流程用户流程任务
|
Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId)
|
.processInstanceId(processInstance.getId()).singleResult();
|
if(task == null)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE);
|
//完成流程任务
|
taskService.complete(task.getId());
|
//复制文件,进行预定密 TODO
|
b = FileUtil.copyFile(docFile.getFilePath(), newPath, docFile.getFileEncodeName());
|
if(!b){
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
}
|
String absPath = FileUtil.getFileAbsPath(newPath, docFile.getFileEncodeName());
|
if(absPath == null){
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR);
|
}
|
try {
|
secureDocService.binByFileLable(absPath);
|
}catch (Exception e) {
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean applyAssignFileNonActive(AssignFileStream stream) {
|
if(stream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getProcessId()) || !ValidateUtil.validateString(stream.getDocId())
|
|| !ValidateUtil.validateString(stream.getFileId()))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(stream.getDeviceId()))
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 5, stream.getProcessId());
|
if(docInfo == null || docInfo.getDocStatus() == 3)
|
ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
|
DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId(),deviceDoc.getDocSuffix());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId());
|
if(deviceInfo == null)
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
ProcessStream processStream = processStreamService.getById(stream.getProcessId());
|
if(processStream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
stream.setProductId(processStream.getProductId());
|
stream.setComponentId(processStream.getComponentId());
|
stream.setPartsId(processStream.getPartsId());
|
List<PermissionStream> permissionStreams = null;
|
if(ValidateUtil.validateString(processStream.getPartsId())) {
|
//进入零件
|
permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId());
|
}else if(ValidateUtil.validateString(processStream.getComponentId())) {
|
//进入部件的处理
|
permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId());
|
}
|
if(permissionStreams == null || permissionStreams.isEmpty())
|
ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
|
List<String> departIds = new ArrayList<>();
|
Map<String, Department> map = departmentService.getMapByUserId(userId);
|
permissionStreams.forEach(item -> {
|
if(map.containsKey(item.getDepartId())) {
|
departIds.add(item.getDepartId());
|
}
|
});
|
if(departIds.isEmpty())
|
ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM);
|
deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId(),docInfo.getDocSuffix());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
//插入文档到设备发送文档
|
DocClassification classification = classificationService.getByCode(SEND_CODE);
|
if(classification == null)
|
ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
|
DocFile docFile = docFileService.getById(stream.getFileId());
|
if(docFile == null)
|
ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
|
DocRelative docRelative = new DocRelative();
|
docRelative.setDocId(docInfo.getDocId());
|
docRelative.setClassificationId(classification.getClassificationId());
|
docRelative.setAttributionType(4);
|
docRelative.setAttributionId(stream.getDeviceId());
|
boolean b = docRelativeService.save(docRelative);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
//插入文件传输任务表
|
ToEquipmentTask equipmentTask = new ToEquipmentTask();
|
//不能直接从doc中拿fileId 和version 可能会存在斌更
|
//equipmentTask.setFileId(docInfo.getPublishFileId());
|
//equipmentTask.setDocVersion(docInfo.getPublishVersion());
|
equipmentTask.setDocId(docInfo.getDocId());
|
equipmentTask.setSyncFlag(1);
|
equipmentTask.setDeviceNo(deviceInfo.getDeviceNo());
|
equipmentTask.setDeviceId(deviceInfo.getDeviceId());
|
equipmentTask.setDepartId(deviceInfo.getDepartId());
|
//文件相关信息
|
equipmentTask.setFileId(docFile.getFileId());
|
equipmentTask.setDocVersion(docFile.getDocVersion());
|
equipmentTask.setFileName(docInfo.getDocName());
|
equipmentTask.setFileEncodeName(docFile.getFileEncodeName());
|
equipmentTask.setFilePath(docFile.getFilePath());
|
equipmentTask.setFileSuffix(docFile.getFileSuffix());
|
equipmentTask.setFileSize(docFile.getFileSize());
|
b = equipmentTaskService.save(equipmentTask);
|
if(!b) {
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
}
|
return synchronizedFlagService.updateFlag(0);
|
}
|
|
@Override
|
public List<ActTaskExt> getUndoTaskList() {
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return null;
|
List<Task> list = taskService.createTaskQuery().taskCandidateOrAssigned(userId).list();
|
if(list == null || list.isEmpty())
|
return null;
|
List<ActTaskExt> extList = new ArrayList<>();
|
list.forEach(item -> {
|
ActTaskExt ext = new ActTaskExt();
|
ext.instanceOfTask(item);
|
|
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(
|
item.getProcessInstanceId()).singleResult();
|
if(historicProcessInstance == null || !ValidateUtil.validateString(historicProcessInstance.getBusinessKey())) {
|
ExceptionCast.cast(ActivitiCode.ACT_PROC_INST_ERROR);
|
}
|
ext.setBusinessKey(historicProcessInstance.getBusinessKey());
|
AssignFileStreamExt streamDetail = getAssignFileStreamDetail(historicProcessInstance.getBusinessKey());
|
if(streamDetail == null)
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_DETAIL_ERROR);
|
ext.setAssignFileStream(streamDetail);
|
extList.add(ext);
|
});
|
return extList;
|
}
|
|
@Override
|
public AssignFileStreamExt getAssignFileStreamDetail(String streamId) {
|
if(!ValidateUtil.validateString(streamId))
|
return null;
|
return super.getBaseMapper().getAssignFileStreamDetail(streamId);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean approveAssignFile(String taskId, String streamId, AssignFileStream stream) {
|
boolean btelnetPort = TelnetUtil.telnetPort(serverIp,serverPort,10);
|
if (!btelnetPort) {
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
if(!ValidateUtil.validateString(taskId) || !ValidateUtil.validateString(streamId) || stream == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
if(!ValidateUtil.validateInteger(stream.getStatus()))
|
ExceptionCast.cast(ActivitiCode.ACT_STATUS_ERROR);
|
AssignFileStream en = super.getById(streamId);
|
if(en == null)
|
ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_DETAIL_ERROR);
|
Task task = taskService.createTaskQuery().taskId(taskId).taskCandidateOrAssigned(userId).singleResult();
|
if(task == null)
|
ExceptionCast.cast(ActivitiCode.ACT_TASK_ERROR);
|
if(!ValidateUtil.validateString(task.getAssignee())) {
|
//拾取任务
|
taskService.claim(task.getId(), userId);
|
//完成任务
|
taskService.complete(task.getId());
|
}else {
|
//完成任务
|
taskService.complete(task.getId());
|
}
|
//更新对象封装
|
AssignFileStream up = new AssignFileStream();
|
up.setApproveContent(stream.getApproveContent());
|
up.setStatus(stream.getStatus());
|
up.setApproveUserId(userId);
|
up.setApproveTime(DateUtil.getNow());
|
up.setStreamId(streamId);
|
boolean b = super.updateById(up);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
if(up.getStatus() == 2) {
|
//同意操作
|
DocInfo docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getProcessId());
|
if(docInfo == null || docInfo.getDocStatus() == 3)
|
ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
|
DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),4, en.getDeviceId());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId(),docInfo.getDocSuffix());
|
if(deviceDoc != null)
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);
|
//插入文档到设备发送文档
|
DocClassification classification = classificationService.getByCode(SEND_CODE);
|
if(classification == null)
|
ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
|
DeviceInfo deviceInfo = deviceInfoService.getById(en.getDeviceId());
|
if(deviceInfo == null)
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
DocFile docFile = docFileService.getById(en.getFileId());
|
if(docFile == null)
|
ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
|
DocRelative docRelative = new DocRelative();
|
docRelative.setDocId(docInfo.getDocId());
|
docRelative.setClassificationId(classification.getClassificationId());
|
docRelative.setAttributionType(4);
|
docRelative.setAttributionId(en.getDeviceId());
|
b = docRelativeService.save(docRelative);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
//插入文件传输任务表
|
ToEquipmentTask equipmentTask = new ToEquipmentTask();
|
//不能直接从doc中拿fileId 和version 可能会存在斌更
|
//equipmentTask.setFileId(docInfo.getPublishFileId());
|
//equipmentTask.setDocVersion(docInfo.getPublishVersion());
|
equipmentTask.setDocId(docInfo.getDocId());
|
equipmentTask.setApplyTime(en.getApplyTime());
|
equipmentTask.setApplyUser(en.getApplyUserId());
|
equipmentTask.setSyncFlag(1);
|
equipmentTask.setDeviceNo(deviceInfo.getDeviceNo());
|
equipmentTask.setDeviceId(deviceInfo.getDeviceId());
|
equipmentTask.setDepartId(deviceInfo.getDepartId());
|
//文件相关信息
|
equipmentTask.setFileId(docFile.getFileId());
|
equipmentTask.setDocVersion(docFile.getDocVersion());
|
equipmentTask.setFileName(docInfo.getDocName());
|
equipmentTask.setFileEncodeName(docFile.getFileEncodeName());
|
equipmentTask.setFilePath(en.getSecurePath());
|
equipmentTask.setFileSuffix(docFile.getFileSuffix());
|
equipmentTask.setFileSize(docFile.getFileSize());
|
b = equipmentTaskService.save(equipmentTask);
|
if(!b) {
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
}
|
String absPath = FileUtil.getFileAbsPath(equipmentTask.getFilePath(), equipmentTask.getFileEncodeName());
|
if(absPath == null){
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
}
|
try {
|
secureDocService.editLabelByPath(absPath);
|
}catch (Exception e) {
|
ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE);
|
}
|
|
return synchronizedFlagService.updateFlag(0);
|
}else if(up.getStatus() == 3) {
|
//拒绝操作 什么也不做
|
return true;
|
}else {
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean applyBatchAssignFile(AssignFileRequest assignFileRequest) {
|
if(assignFileRequest == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
String[] deviceIds = assignFileRequest.getDeviceIds();
|
if(deviceIds == null || deviceIds.length < 1)
|
ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE);
|
AssignFileStream stream;
|
for(String id : deviceIds) {
|
stream = new AssignFileStream();
|
stream.setProcessId(assignFileRequest.getProcessId());
|
stream.setDocId(assignFileRequest.getDocId());
|
stream.setFileId(assignFileRequest.getFileId());
|
stream.setApplyReason(assignFileRequest.getApplyReason());
|
stream.setDeviceId(id);
|
ResponseResult b = applyAssignFile(stream);
|
if(!b.isSuccess())
|
ExceptionCast.cast(ActivitiCode.ACT_APPLY_ERROR);
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean approveBatchAssignFile(ApproveBatchRequest approveBatchRequest) {
|
if(approveBatchRequest == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
List<TaskRequest> list = approveBatchRequest.getTaskArr();
|
if(list == null || list.isEmpty())
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
list.forEach(item -> {
|
AssignFileStream stream = new AssignFileStream();
|
stream.setApproveContent(approveBatchRequest.getApproveContent());
|
stream.setStatus(approveBatchRequest.getStatus());
|
boolean b = approveAssignFile(item.getId(), item.getBusinessKey(), stream);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
});
|
return synchronizedFlagService.updateFlag(0);
|
}
|
|
@Override
|
public QueryPageResponseResult<AssignFileStreamExt> findPageList(int page, int size, AssignFileStreamQueryRequest request) {
|
if(page < 1 || size < 1) {
|
ExceptionCast.cast(CommonCode.INVALID_PAGE);
|
}
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
LambdaQueryWrapper<AssignFileStreamExt> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(AssignFileStreamExt::getApproveUserId, userId);
|
lambdaQueryWrapper.orderByDesc(AssignFileStreamExt::getApproveTime);
|
IPage<AssignFileStreamExt> pageData = new Page<>(page, size);
|
if(request != null) {
|
if(ValidateUtil.validateString(request.getAscStr())) {
|
String[] ascArr = request.getAscStr().split(",");
|
((Page<AssignFileStreamExt>) pageData).setAsc(ascArr);
|
}
|
if(ValidateUtil.validateString(request.getDescStr())) {
|
String[] descStr = request.getDescStr().split(",");
|
((Page<AssignFileStreamExt>) pageData).setDesc(descStr);
|
}
|
}
|
IPage<AssignFileStreamExt> streamExtIPage = super.getBaseMapper().findByPage(pageData, lambdaQueryWrapper);
|
return new QueryPageResponseResult<>(CommonCode.SUCCESS, streamExtIPage);
|
}
|
|
@Override
|
public QueryPageResponseResult<AssignFileStreamExt> findPageListByDocId(int page, int size, String docId) {
|
if(page < 1 || size < 1) {
|
ExceptionCast.cast(CommonCode.INVALID_PAGE);
|
}
|
if(!ValidateUtil.validateString(docId))
|
ExceptionCast.cast(ActivitiCode.ACT_DOC_ID_NONE);
|
QueryWrapper<AssignFileStreamExt> queryWrapper = Wrappers.query();
|
queryWrapper.eq("a.doc_id", docId);
|
queryWrapper.orderByDesc("approve_time");
|
IPage<AssignFileStreamExt> pageData = new Page<>(page, size);
|
IPage<AssignFileStreamExt> streamExtIPage = super.getBaseMapper().findByPage(pageData, queryWrapper);
|
return new QueryPageResponseResult<>(CommonCode.SUCCESS, streamExtIPage);
|
}
|
|
@Override
|
public Boolean getActiveEnable() {
|
if(activeEnable != null) {
|
return activeEnable;
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean transferDocFile(String pnCode, String deviceNo) {
|
List<ProcessStream> streams = processStreamService.validateDeviceProcessInfo(pnCode, deviceNo);
|
DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);
|
if(deviceInfo == null)
|
ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
|
//删除原来设备下的所有文档
|
docRelativeService.deleteByDocAttr(4, deviceInfo.getDeviceId());
|
List<DocInfo> docInfoList = docInfoService.getByProcessIds(streams);
|
if(docInfoList == null || docInfoList.isEmpty())
|
ExceptionCast.cast(DocumentCode.DOC_NOT_EXIST);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
for(DocInfo docInfo : docInfoList) {
|
DocFile docFile = docFileService.getById(docInfo.getPublishFileId());
|
if(docFile == null)
|
ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR);
|
//插入文档到设备发送文档
|
DocClassification classification = classificationService.getByCode(SEND_CODE);
|
if(classification == null)
|
ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR);
|
DocRelative docRelative = new DocRelative();
|
docRelative.setDocId(docInfo.getDocId());
|
docRelative.setClassificationId(classification.getClassificationId());
|
docRelative.setAttributionType(4);
|
docRelative.setAttributionId(deviceInfo.getDeviceId());
|
boolean b = docRelativeService.save(docRelative);
|
if(!b)
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
//插入文件传输任务表
|
ToEquipmentTask equipmentTask = new ToEquipmentTask();
|
//不能直接从doc中拿fileId 和version 可能会存在斌更
|
//equipmentTask.setFileId(docInfo.getPublishFileId());
|
//equipmentTask.setDocVersion(docInfo.getPublishVersion());
|
equipmentTask.setDocId(docInfo.getDocId());
|
equipmentTask.setSyncFlag(1);
|
equipmentTask.setDeviceNo(deviceInfo.getDeviceNo());
|
equipmentTask.setDeviceId(deviceInfo.getDeviceId());
|
equipmentTask.setDepartId(deviceInfo.getDepartId());
|
//文件相关信息
|
equipmentTask.setFileId(docFile.getFileId());
|
equipmentTask.setDocVersion(docFile.getDocVersion());
|
equipmentTask.setFileName(docInfo.getDocName());
|
equipmentTask.setFileEncodeName(docFile.getFileEncodeName());
|
equipmentTask.setFilePath(docFile.getFilePath());
|
equipmentTask.setFileSuffix(docFile.getFileSuffix());
|
equipmentTask.setFileSize(docFile.getFileSize());
|
b = equipmentTaskService.save(equipmentTask);
|
if(!b) {
|
ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR);
|
}
|
}
|
return synchronizedFlagService.updateFlag(0);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean disPatchTaskNc(String equipmentId, String workshop, String partsCode,
|
String processCode, String description,String id) {
|
DncLog dncLog = new DncLog();
|
dncLog.setContentName(equipmentId + "设备程序下发");
|
dncLog.setEquipmentId(equipmentId);
|
dncLog.setWorkshopNo(workshop);
|
dncLog.setNcType(LogCodeUtil.ndc_code);
|
dncLog.setMesTaskId(id);
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
boolean btelnetPort = TelnetUtil.telnetPort(serverIp,serverPort,10);
|
if (!btelnetPort) {
|
dncLog.setRemarks("网闸异常");
|
dncLogService.save(dncLog);
|
return false;
|
}
|
|
ComponentInfo compTotal = componentInfoService.getByCode(workshop);
|
if (compTotal == null) {
|
dncLog.setRemarks("无此车间部件信息");
|
dncLogService.save(dncLog);
|
return false;
|
}
|
List<ComponentInfo> componentInfoList = componentInfoService.getByParentId(compTotal.getComponentId());
|
List<String> comlist = new ArrayList<>();
|
if (componentInfoList != null && !componentInfoList.isEmpty()) {
|
for (ComponentInfo cc : componentInfoList) {
|
comlist.add(cc.getComponentId());
|
}
|
} else {
|
dncLog.setRemarks("无型别部件信息");
|
dncLogService.save(dncLog);
|
return false;
|
}
|
PartsInfo part = partsInfoService.getByCodeAndComIdList(partsCode,comlist);
|
if (part == null) {
|
dncLog.setRemarks("无此零件信息"+"__" + partsCode );
|
dncLogService.save(dncLog);
|
return false;
|
}
|
processCode = processCode.split("_")[0];
|
ProcessStream stream = processStreamService.findByProcessEquipment(equipmentId,
|
processCode,description,compTotal.getComponentId(),part.getPartsId());
|
if (stream == null) {
|
dncLog.setRemarks("无此工序信息"+"__" + processCode );
|
dncLogService.save(dncLog);
|
return false;
|
}
|
DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(equipmentId);
|
if(deviceInfo == null) {
|
dncLog.setRemarks("DNC中设备不存在,无此设备的程序下发_" + equipmentId);
|
dncLogService.save(dncLog);
|
return false;
|
}
|
/*
|
//删除原来设备下的所有文档
|
docRelativeService.deleteByDocAttr(4, deviceInfo.getDeviceId());*/
|
List<ProcessStream> streams = new ArrayList<>();
|
streams.add(stream);
|
List<DocInfo> docInfoList = docInfoService.getByProcessIds(streams);
|
if(docInfoList == null || docInfoList.isEmpty()) {
|
return false;
|
}
|
/* String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId)) {
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
}*/
|
for(DocInfo docInfo : docInfoList) {
|
DocFile docFile = docFileService.getById(docInfo.getPublishFileId());
|
if(docFile == null)
|
return false;
|
//插入文档到设备发送文档
|
DocClassification classification = classificationService.getByCode(SEND_CODE);
|
if(classification == null)
|
return false;
|
DocRelative docRelative = new DocRelative();
|
docRelative.setDocId(docInfo.getDocId());
|
docRelative.setClassificationId(classification.getClassificationId());
|
docRelative.setAttributionType(4);
|
docRelative.setAttributionId(deviceInfo.getDeviceId());
|
boolean b = docRelativeService.save(docRelative);
|
if(!b) {
|
return false;
|
}
|
//插入文件传输任务表
|
ToEquipmentTask equipmentTask = new ToEquipmentTask();
|
//不能直接从doc中拿fileId 和version 可能会存在斌更
|
String newPath = "/securedoc" + docFile.getFilePath();
|
//equipmentTask.setFileId(docInfo.getPublishFileId());
|
//equipmentTask.setDocVersion(docInfo.getPublishVersion());
|
equipmentTask.setDocId(docInfo.getDocId());
|
equipmentTask.setSyncFlag(1);
|
equipmentTask.setDeviceNo(deviceInfo.getDeviceNo());
|
equipmentTask.setDeviceId(deviceInfo.getDeviceId());
|
equipmentTask.setDepartId(deviceInfo.getDepartId());
|
//文件相关信息
|
equipmentTask.setFileId(docFile.getFileId());
|
equipmentTask.setDocVersion(docFile.getDocVersion());
|
equipmentTask.setFileName(docInfo.getDocName());
|
equipmentTask.setFileEncodeName(docFile.getFileEncodeName());
|
equipmentTask.setFilePath(docFile.getFilePath());
|
equipmentTask.setFileSuffix(docFile.getFileSuffix());
|
equipmentTask.setFileSize(docFile.getFileSize());
|
b = equipmentTaskService.save(equipmentTask);
|
if(!b) {
|
return false;
|
}
|
//复制文件,进行预定密 TODO
|
b = FileUtil.copyFile(docFile.getFilePath(), newPath, docFile.getFileEncodeName());
|
if(!b){
|
return false;
|
}
|
String absPath = FileUtil.getFileAbsPath(newPath, docFile.getFileEncodeName());
|
if(absPath == null){
|
return false;
|
}
|
try {
|
secureDocService.binByFileLable(absPath);
|
} catch (Exception e) {
|
return false;
|
}
|
try {
|
secureDocService.editLabelByPath(absPath);
|
}catch (Exception e) {
|
return false;
|
}
|
|
}
|
dncLog.setIsSuccess(LogCodeUtil.success_is_true);
|
dncLog.setRemarks("下发成功");
|
dncLogService.save(dncLog);
|
return synchronizedFlagService.updateFlag(0);
|
}
|
}
|