|
|
package com.monitor.other.worksystem.service.impl;
|
|
|
|
|
|
import com.model.HandledJob;
|
|
|
import com.model.PendingJob;
|
|
|
import com.model.ReleaseWorkJob;
|
|
|
import com.model.WorkJob;
|
|
|
import com.monitor.model.domain.PageBean;
|
|
|
import com.monitor.model.page.PageRequest;
|
|
|
import com.monitor.model.response.PageResponse;
|
|
|
import com.monitor.mysql.mapper.HandledJobMapper;
|
|
|
import com.monitor.mysql.mapper.PendingJobMapper;
|
|
|
import com.monitor.mysql.mapper.ReleaseWorkJobMapper;
|
|
|
import com.monitor.mysql.mapper.WorkJobMapper;
|
|
|
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.ReleaseService;
|
|
|
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 ReleaseServiceImpl implements ReleaseService {
|
|
|
|
|
|
@Autowired
|
|
|
private ReleaseWorkJobMapper releaseWorkJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private HandledJobMapper handledJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PendingJobMapper pendingJobMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private WorkSystemSupport workSystemSupport;
|
|
|
|
|
|
@Autowired
|
|
|
private WorkJobMapper workJobMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询工单列表
|
|
|
*
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public PageResponse<ReleaseWorkJob> getReleaseWorkJobs(PageRequest req) {
|
|
|
// 组装分页对象
|
|
|
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
|
|
|
req.getPageSize(), req);
|
|
|
// 先查询符合条件的总数量
|
|
|
int total = releaseWorkJobMapper.selectCount();
|
|
|
// 数量为0 直接返回
|
|
|
if (total == 0) {
|
|
|
// 返回初始page对象
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 获取列表
|
|
|
List<ReleaseWorkJob> list = releaseWorkJobMapper.selectByPage(page);
|
|
|
// 获取列表
|
|
|
PageResponse<ReleaseWorkJob> response = new PageResponse<ReleaseWorkJob>();
|
|
|
response.setCurrentPage(req.getCurrentPage());
|
|
|
response.setPageSize(req.getPageSize());
|
|
|
response.setTotal(total);
|
|
|
response.setRows(list);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据工单ID查询工单
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public ReleaseWorkJob getReleaseWorkJob(String id) {
|
|
|
ReleaseWorkJob releaseWorkJob = releaseWorkJobMapper.selectById(id);
|
|
|
//获取工单操作记录
|
|
|
List<HandledJob> list = handledJobMapper.selectByworkId(id);
|
|
|
releaseWorkJob.setHandleList(list);
|
|
|
return releaseWorkJob;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建工单
|
|
|
*
|
|
|
* @param releaseWorkJob
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public int createReleaseWorkJob(ReleaseWorkJob releaseWorkJob) {
|
|
|
|
|
|
//插入工单表
|
|
|
WorkJob workJob = new WorkJob();
|
|
|
workJob.setType(WorkType.RELEASE_PROJECT);
|
|
|
workJob.setTitle(releaseWorkJob.getTitle());
|
|
|
workJobMapper.insert(workJob);
|
|
|
|
|
|
//生成工单id
|
|
|
String workId = WorkType.RELEASE_PROJECT + StringUtils.leftPad(workJob.getId()+"",7,"0");
|
|
|
workJob.setWorkId(workId);
|
|
|
workJobMapper.update(workJob);
|
|
|
|
|
|
releaseWorkJob.setId(workId);
|
|
|
//插入发布工单表
|
|
|
releaseWorkJob.setStatus(WorkStatus.PUBLISH);
|
|
|
int result = releaseWorkJobMapper.insert(releaseWorkJob);
|
|
|
if (result < 1) {
|
|
|
return -1;
|
|
|
}
|
|
|
//插入用户处理工单表
|
|
|
HandledJob handledJob = new HandledJob(WorkType.RELEASE_PROJECT, releaseWorkJob.getId(), releaseWorkJob.getTitle(), releaseWorkJob.getDevelop(), HandlerRole.DEVELOP,HandleType.CREATE,HandleType.getCtype(HandleType.CREATE) );
|
|
|
|
|
|
handledJobMapper.insert(handledJob);
|
|
|
|
|
|
//插入用户待处理工单表
|
|
|
PendingJob pendingJob = new PendingJob(WorkType.RELEASE_PROJECT, releaseWorkJob.getId(), releaseWorkJob.getTitle(), releaseWorkJob.getTest(), HandlerRole.TEST, WorkStatus.PUBLISH);
|
|
|
workSystemSupport.addPending(pendingJob);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int dealWorkJob(HandledJob handledJob) {
|
|
|
//查询待处理工单是否还存在
|
|
|
PendingJob pendingJob = pendingJobMapper.selectByid(handledJob.getId());
|
|
|
if (pendingJob == null) {//工单不存在,则返回
|
|
|
return 2;
|
|
|
}
|
|
|
ReleaseWorkJob releaseWorkJob = releaseWorkJobMapper.selectById(pendingJob.getWorkId());
|
|
|
|
|
|
//删除该工单的待处理
|
|
|
pendingJobMapper.delete(releaseWorkJob.getId());
|
|
|
|
|
|
handledJob.setWorkId(releaseWorkJob.getId());
|
|
|
handledJob.setTitle(releaseWorkJob.getTitle());
|
|
|
handledJob.setType(WorkType.RELEASE_PROJECT);
|
|
|
handledJob.setHandlecType(HandleType.getCtype(handledJob.getHandleType()));
|
|
|
//插入用户处理列表
|
|
|
handledJobMapper.insert(handledJob);
|
|
|
|
|
|
int handleType = handledJob.getHandleType();
|
|
|
//如果关闭则直接关闭
|
|
|
if (handleType == HandleType.CLOSE) {
|
|
|
releaseWorkJob.setStatus(WorkStatus.CLOSE);
|
|
|
releaseWorkJob.setOperator(handledJob.getHandler());
|
|
|
releaseWorkJobMapper.updateResult(releaseWorkJob);//关闭工单
|
|
|
workSystemSupport.workend(releaseWorkJob.getId(),WorkStatus.getCstatus(WorkStatus.CLOSE));
|
|
|
return 1;
|
|
|
}
|
|
|
int currentStatus = pendingJob.getCurrentStatus();
|
|
|
if(currentStatus == WorkStatus.CREATED){//创建状态
|
|
|
if(handleType == HandleType.PASS){//发布
|
|
|
releaseWorkJob.setStatus(WorkStatus.PUBLISH);
|
|
|
releaseWorkJobMapper.updateStatus(releaseWorkJob);
|
|
|
PendingJob newPendingJob = new PendingJob(WorkType.RELEASE_PROJECT, releaseWorkJob.getId(), releaseWorkJob.getTitle(), releaseWorkJob.getTest(), HandlerRole.TEST, WorkStatus.PUBLISH);
|
|
|
workSystemSupport.addPendingByRole(newPendingJob);
|
|
|
}
|
|
|
} else if (currentStatus == WorkStatus.PUBLISH) {//发布状态
|
|
|
if(handleType == HandleType.PASS){//通过测试
|
|
|
releaseWorkJob.setStatus(WorkStatus.TEST_PASS);
|
|
|
releaseWorkJobMapper.updateStatus(releaseWorkJob);
|
|
|
PendingJob newPendingJob = new PendingJob(WorkType.RELEASE_PROJECT, releaseWorkJob.getId(), releaseWorkJob.getTitle(), null, HandlerRole.OPERATOR, WorkStatus.TEST_PASS);
|
|
|
workSystemSupport.addPendingByRole(newPendingJob);
|
|
|
}else{//未通过测试
|
|
|
releaseWorkJob.setStatus(WorkStatus.CREATED);//置为初始状态
|
|
|
releaseWorkJobMapper.updateStatus(releaseWorkJob);
|
|
|
//插入用户待处理工单表
|
|
|
PendingJob newPendingJob = new PendingJob(WorkType.RELEASE_PROJECT, releaseWorkJob.getId(), releaseWorkJob.getTitle(), releaseWorkJob.getDevelop(), HandlerRole.DEVELOP, WorkStatus.CREATED);
|
|
|
workSystemSupport.addPending(newPendingJob);
|
|
|
}
|
|
|
}else if(currentStatus == WorkStatus.TEST_PASS) {//测试通过的工单
|
|
|
releaseWorkJob.setOperator(handledJob.getHandler());
|
|
|
if(handleType == HandleType.PASS){//发布成功
|
|
|
releaseWorkJob.setStatus(WorkStatus.EXE_SUCCESS);
|
|
|
workSystemSupport.workend(releaseWorkJob.getId(),WorkStatus.getCstatus(WorkStatus.EXE_SUCCESS));
|
|
|
}else {//发布失败
|
|
|
releaseWorkJob.setStatus(WorkStatus.EXE_FAILE);
|
|
|
workSystemSupport.workend(releaseWorkJob.getId(),WorkStatus.getCstatus(WorkStatus.EXE_FAILE));
|
|
|
}
|
|
|
releaseWorkJobMapper.updateResult(releaseWorkJob);//填写工单结果
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
} |
...
|
...
|
|