|
|
package com.monitor.other.worksystem.service.impl;
|
|
|
|
|
|
import com.model.*;
|
|
|
import com.monitor.mysql.mapper.*;
|
|
|
import com.monitor.other.worksystem.contants.HandleType;
|
|
|
import com.monitor.other.worksystem.contants.HandlerRole;
|
|
|
import com.monitor.other.worksystem.contants.WorkStatus;
|
|
|
import com.monitor.other.worksystem.contants.WorkType;
|
|
|
import com.monitor.other.worksystem.service.DBService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by zhengyouwei on 2016/9/2.
|
|
|
*/
|
|
|
@Service
|
|
|
public class DBServiceImpl implements DBService {
|
|
|
|
|
|
@Autowired
|
|
|
private DBWorkJobMapper dbWorkJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private HandledJobMapper handledJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PendingJobMapper pendingJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private WorkSystemSupport workSystemSupport;
|
|
|
|
|
|
@Autowired
|
|
|
private WorkJobMapper workJobMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据工单ID查询工单
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public DBWorkJob getDBWorkJob(String id) {
|
|
|
DBWorkJob dbWorkJob = dbWorkJobMapper.selectById(id);
|
|
|
//获取工单操作记录
|
|
|
List<HandledJob> list = handledJobMapper.selectByworkId(id);
|
|
|
dbWorkJob.setHandleList(list);
|
|
|
return dbWorkJob;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建工单
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public int createDBWorkJob(DBWorkJob dbWorkJob) {
|
|
|
|
|
|
//插入工单表
|
|
|
WorkJob workJob = new WorkJob();
|
|
|
workJob.setType(WorkType.DB_PROJECT);
|
|
|
workJob.setTitle(dbWorkJob.getTitle());
|
|
|
workJobMapper.insert(workJob);
|
|
|
|
|
|
//生成工单id
|
|
|
String workId = WorkType.DB_PROJECT + StringUtils.leftPad(workJob.getId() + "", 7, "0");
|
|
|
workJob.setWorkId(workId);
|
|
|
workJobMapper.update(workJob);
|
|
|
|
|
|
dbWorkJob.setId(workId);
|
|
|
//插入发布工单表
|
|
|
dbWorkJob.setStatus(WorkStatus.PUBLISH);
|
|
|
int result = dbWorkJobMapper.insert(dbWorkJob);
|
|
|
if (result < 1) {
|
|
|
return -1;
|
|
|
}
|
|
|
//插入用户处理工单表
|
|
|
HandledJob handledJob = new HandledJob(WorkType.DB_PROJECT, dbWorkJob.getId(), dbWorkJob.getTitle(), dbWorkJob.getDevelop(), HandlerRole.DEVELOP, HandleType.CREATE, HandleType.getCtype(HandleType.CREATE));
|
|
|
|
|
|
handledJobMapper.insert(handledJob);
|
|
|
|
|
|
//插入用户待处理工单表
|
|
|
PendingJob pendingJob = new PendingJob(WorkType.DB_PROJECT, dbWorkJob.getId(), dbWorkJob.getTitle(), null, HandlerRole.DBA, WorkStatus.PUBLISH);
|
|
|
workSystemSupport.addPendingByRole(pendingJob, false);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int dealWorkJob(HandledJob handledJob) {
|
|
|
//查询待处理工单是否还存在
|
|
|
PendingJob pendingJob = pendingJobMapper.selectByid(handledJob.getId());
|
|
|
if (pendingJob == null) {//工单不存在,则返回
|
|
|
return 2;
|
|
|
}
|
|
|
DBWorkJob dbWorkJob = dbWorkJobMapper.selectById(pendingJob.getWorkId());
|
|
|
|
|
|
//删除该工单的待处理
|
|
|
pendingJobMapper.delete(dbWorkJob.getId());
|
|
|
|
|
|
handledJob.setWorkId(dbWorkJob.getId());
|
|
|
handledJob.setTitle(dbWorkJob.getTitle());
|
|
|
handledJob.setType(WorkType.DB_PROJECT);
|
|
|
handledJob.setHandlecType(HandleType.getCtype(handledJob.getHandleType()));
|
|
|
//插入用户处理列表
|
|
|
handledJobMapper.insert(handledJob);
|
|
|
|
|
|
int handleType = handledJob.getHandleType();
|
|
|
//如果关闭则直接关闭
|
|
|
if (handleType == HandleType.CLOSE) {
|
|
|
dbWorkJob.setStatus(WorkStatus.CLOSE);
|
|
|
dbWorkJob.setDba(handledJob.getHandler());
|
|
|
dbWorkJobMapper.update(dbWorkJob);//关闭工单
|
|
|
workSystemSupport.workend(dbWorkJob.getId(), WorkType.DB_PROJECT, dbWorkJob.getTitle(), WorkStatus.getCstatus(WorkStatus.CLOSE));
|
|
|
return 1;
|
|
|
}
|
|
|
int currentStatus = pendingJob.getCurrentStatus();
|
|
|
if (currentStatus == WorkStatus.PUBLISH) {
|
|
|
dbWorkJob.setDba(handledJob.getHandler());
|
|
|
if (handleType == HandleType.PASS) {//发布成功
|
|
|
dbWorkJob.setStatus(WorkStatus.EXE_SUCCESS);
|
|
|
workSystemSupport.workend(dbWorkJob.getId(), WorkType.DB_PROJECT, dbWorkJob.getTitle(), WorkStatus.getCstatus(WorkStatus.EXE_SUCCESS));
|
|
|
} else {//发布失败
|
|
|
dbWorkJob.setStatus(WorkStatus.EXE_FAILE);
|
|
|
workSystemSupport.workend(dbWorkJob.getId(), WorkType.DB_PROJECT, dbWorkJob.getTitle(), WorkStatus.getCstatus(WorkStatus.EXE_FAILE));
|
|
|
}
|
|
|
dbWorkJobMapper.update(dbWorkJob);//填写工单结果
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
} |
...
|
...
|
|