Authored by zhengyouwei

worksystem

Showing 36 changed files with 1650 additions and 4 deletions
... ... @@ -5,7 +5,7 @@ package com.monitor.common.service;
*/
public interface AlarmMsgService {
public boolean sendSms(String type, String content, String mobile);
boolean sendSms(String type, String content, String mobile);
boolean sendSms(String type, String content, String alarmInfo, String mobile);
}
... ...
package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/9/2.
*/
@Data
public class WorkSystemReq extends PageRequest {
private String handler;
private String id;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/9/2.
* <p>
* 已处理工单表
*/
@Data
public class HandledJob {
public HandledJob() {
}
public HandledJob(String type,String workId, String title, String handler, String handlerRole, int handleType,String handlecType) {
this.type = type;
this.workId = workId;
this.title = title;
this.handler = handler;
this.handlerRole = handlerRole;
this.handleType = handleType;
this.handlecType = handlecType;
}
private int id;
/**
* 工单ID
*/
private String workId;
/**
* 工单主题
*/
private String title;
/**
* 工单类型
*/
private String type;
/**
* 处理人
*/
private String handler;
/**
* 处理人的职责 develop test operator
*/
private String handlerRole;
/**
* 处理类型 1 发起 2 通过 3 驳回 -1 close
*/
private int handleType;
private String handlecType;
/**
*
*/
private String createTime;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/9/2.
* <p>
* 待处理工单列表
*/
@Data
public class PendingJob {
public PendingJob() {
}
public PendingJob(String type,String workId, String title, String handler, String handlerRole, int currentStatus) {
this.type = type;
this.workId = workId;
this.title = title;
this.handler = handler;
this.handlerRole = handlerRole;
this.currentStatus = currentStatus;
}
private int id;
/**
* 工单ID
*/
private String workId;
/**
* 主题
*/
private String title;
/**
* 类型 release or
*/
private String type;
/**
* 待处理人
*/
private String handler;
/**
* 当前状态
*/
private int currentStatus;
/**
* 处理人的职责 develop test operator
*/
private String handlerRole;
private String createTime;
}
... ...
package com.model;
import lombok.Data;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/2.
*
* 发布工单
*/
@Data
public class ReleaseWorkJob {
/**
* id
*/
private String id;
/**
* 主题
*/
private String title;
/**
* 需求说明
*/
private String demand;
/**
* 发布环境 aws,qcloud,qcloudGray
*/
private String environment;
/**
* 平台 java php node
*/
private String platform;
/**
* 具体项目
*/
private String project;
/**
* 开发
*/
private String develop;
/**
* 测试
*/
private String test;
/**
* 运维
*/
private String operator;
/**
* WorkStatus 详见
*
*/
private int status;
/**
* 工单操作记录
*/
private List<HandledJob> handleList;
private String createTime;
private String updateTime;
}
... ...
... ... @@ -20,4 +20,14 @@ public class User {
private String mobile;
/**
* 职责 develop test operator leader
*/
private String role;
/**
* 中文名
*/
private String cName;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/9/7.
*/
@Data
public class WorkJob {
private int id;
/**
* 工单ID
*/
private String workId;
/**
* 主题
*/
private String title;
/**
* 类型 release or
*/
private String type;
private String createTime;
}
... ...
package com.monitor.mysql.mapper;
import com.model.HandledJob;
import com.monitor.model.domain.PageBean;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface HandledJobMapper {
int insert(HandledJob handledJob);
int selectCount(String handler);
List<HandledJob> selectByPage(PageBean page);
List<HandledJob> selectByworkId(String workid);
}
... ...
package com.monitor.mysql.mapper;
import com.model.PendingJob;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface PendingJobMapper {
int insert(PendingJob pendingJob);
List<PendingJob> selectByPage(PageBean page);
int selectCount(String handler);
void delete(String id);
PendingJob selectByid(int id);
PendingJob selectByUser(@Param("workid")String workid,@Param("user")String user);
}
... ...
package com.monitor.mysql.mapper;
import com.model.ReleaseWorkJob;
import com.monitor.model.domain.PageBean;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface ReleaseWorkJobMapper {
int insert(ReleaseWorkJob releaseWorkJob);
int updateStatus(ReleaseWorkJob releaseWorkJob);
int updateResult(ReleaseWorkJob releaseWorkJob);
List<ReleaseWorkJob> selectByPage(PageBean page);
int selectCount();
ReleaseWorkJob selectById(String id);
}
... ...
... ... @@ -32,4 +32,6 @@ public interface UserMapper {
int selectCount();
List<User> selectUsersByRole(String role);
}
... ...
package com.monitor.mysql.mapper;
import com.model.WorkJob;
import com.monitor.model.domain.PageBean;
import lombok.Data;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/7.
*/
public interface WorkJobMapper {
int insert(WorkJob workJob);
int update(WorkJob workJob);
WorkJob selectByWorkId(String workid);
List<WorkJob> selectByPage(PageBean pageBean);
int selectCount();
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.HandledJobMapper" >
<resultMap id="BaseResultMap" type="com.model.HandledJob" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="work_id" property="workId" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="handler_role" property="handlerRole" jdbcType="VARCHAR" />
<result column="handler" property="handler" jdbcType="VARCHAR" />
<result column="handle_cType" property="handlecType" jdbcType="VARCHAR" />
<result column="handle_type" property="handleType" jdbcType="INTEGER" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, work_id, title,type,handler_role,handler,handle_type,handle_cType,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
</sql>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from handled_job
where
handler = #{handler}
</select>
<select id="selectByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from handled_job
where
handler = #{params.handler}
order by id desc
limit #{startIndex},#{pageSize}
</select>
<select id="selectByworkId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from handled_job
where
work_id = #{workid}
order by id
</select>
<insert id="insert" parameterType="com.model.HandledJob" >
insert into handled_job
(work_id,
title,
type,
handler_role,
handler,
handle_type,
handle_cType,
create_time)
values
(#{workId,jdbcType=VARCHAR},
#{title,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{handlerRole,jdbcType=VARCHAR},
#{handler,jdbcType=VARCHAR},
#{handleType,jdbcType=INTEGER},
#{handlecType,jdbcType=VARCHAR},
now())
</insert>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.PendingJobMapper" >
<resultMap id="BaseResultMap" type="com.model.PendingJob" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="work_id" property="workId" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="handler" property="handler" jdbcType="VARCHAR" />
<result column="handler_role" property="handlerRole" jdbcType="VARCHAR" />
<result column="current_status" property="currentStatus" jdbcType="INTEGER" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, work_id, title,type,handler,handler_role,current_status,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
</sql>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from pending_job
where
handler = #{handler}
</select>
<select id="selectByUser" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pending_job
where
handler = #{user}
and work_id = #{workid}
</select>
<select id="selectByid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pending_job
where
id = #{id}
</select>
<select id="selectByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pending_job
where
handler = #{params.handler}
order by id
limit #{startIndex},#{pageSize}
</select>
<insert id="insert" parameterType="com.model.HandledJob" >
insert into pending_job
(work_id,
title,
type,
handler_role,
handler,
current_status,
create_time)
values
(#{workId,jdbcType=VARCHAR},
#{title,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{handlerRole,jdbcType=VARCHAR},
#{handler,jdbcType=VARCHAR},
#{currentStatus,jdbcType=INTEGER},
now())
</insert>
<delete id="delete">
DELETE FROM pending_job where work_id = #{id}
</delete>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.ReleaseWorkJobMapper" >
<resultMap id="BaseResultMap" type="com.model.ReleaseWorkJob" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="demand" property="demand" jdbcType="VARCHAR" />
<result column="environment" property="environment" jdbcType="VARCHAR" />
<result column="platform" property="platform" jdbcType="VARCHAR" />
<result column="project" property="project" jdbcType="VARCHAR" />
<result column="develop" property="develop" jdbcType="VARCHAR" />
<result column="test" property="test" jdbcType="VARCHAR" />
<result column="operator" property="operator" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
<result column="updateTime" property="updateTime" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, title,demand,environment,platform,project,develop,test,operator,status,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime,DATE_FORMAT(update_time,'%Y-%m-%d %H:%i:%S') AS updateTime
</sql>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from release_work_job
where
</select>
<select id="selectByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from release_work_job
order by id desc
limit #{startIndex},#{pageSize}
</select>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from release_work_job
where
id = #{id}
</select>
<insert id="insert" parameterType="com.model.ReleaseWorkJob" >
insert into release_work_job
(
id,
title,
demand,
environment,
platform,
project,
develop,
test,
status,
create_time,
update_time
)
values
(
#{id,jdbcType=VARCHAR},
#{title,jdbcType=VARCHAR},
#{demand,jdbcType=VARCHAR},
#{environment,jdbcType=VARCHAR},
#{platform,jdbcType=VARCHAR},
#{project,jdbcType=VARCHAR},
#{develop,jdbcType=VARCHAR},
#{test,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER},
now(),
now())
</insert>
<update id="updateStatus" parameterType="com.model.ReleaseWorkJob">
UPDATE release_work_job
set
status = #{status,jdbcType=INTEGER},
update_time = now()
where
id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateResult" parameterType="com.model.ReleaseWorkJob">
UPDATE release_work_job
set
status = #{status,jdbcType=INTEGER},
operator = #{operator,jdbcType=INTEGER},
update_time = now()
where
id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -8,10 +8,13 @@
<result column="level" property="level" jdbcType="INTEGER" />
<result column="email" property="email" jdbcType="VARCHAR" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="c_name" property="cName" jdbcType="VARCHAR" />
<result column="role" property="role" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, name, pwd, level, email, mobile
id, name, pwd, level, email, mobile,c_name,role
</sql>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -42,6 +45,13 @@
limit #{startIndex},#{pageSize}
</select>
<select id="selectUsersByRole" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
where role = #{role}
</select>
<delete id="deleteById" parameterType="java.lang.Integer" >
delete from user
where id = #{id,jdbcType=INTEGER}
... ... @@ -54,10 +64,10 @@
<insert id="insert" parameterType="com.model.User" >
insert into user
(name,pwd,level,email,mobile, create_time, update_time)
(name,pwd,level,email,mobile,c_name,role, create_time, update_time)
values
(#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER},
#{email,jdbcType=INTEGER},#{mobile,jdbcType=INTEGER},now(),now())
#{email,jdbcType=VARCHAR},#{mobile,jdbcType=VARCHAR},#{cName,jdbcType=VARCHAR},#{role,jdbcType=VARCHAR},now(),now())
</insert>
<update id="update" parameterType="com.model.User" >
... ... @@ -65,6 +75,8 @@
set level = #{level,jdbcType=INTEGER},
email = #{email,jdbcType=VARCHAR},
mobile = #{mobile,jdbcType=VARCHAR},
role= #{role,jdbcType=VARCHAR},
c_name= #{cName,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.WorkJobMapper" >
<resultMap id="BaseResultMap" type="com.model.WorkJob" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="work_id" property="workId" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, title,work_id,type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
</sql>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from work_job
</select>
<select id="selectByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from work_job
where 1=1
<if test="params.id != null" >
and work_id = #{params.id}
</if>
order by create_time desc
limit #{startIndex},#{pageSize}
</select>
<select id="selectByWorkId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from work_job
where
work_id = #{workid}
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.model.WorkJob" >
insert into work_job
(
title,
type,
create_time
)
values
(#{title,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
now())
</insert>
<update id="update" parameterType="com.model.WorkJob">
UPDATE work_job
set
work_id = #{workId}
where
id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
package com.monitor.other.worksystem.contants;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public class HandleType {
public static final int CREATE = 1;
public static final int PASS = 2;
public static final int REJECT = 3;
public static final int CLOSE = -1;
public static String getCtype(int type){
switch (type){
case CREATE:
return "创建";
case PASS:
return "通过";
case REJECT:
return "拒绝";
case CLOSE:
return "关闭";
default:
return "其他";
}
}
}
... ...
package com.monitor.other.worksystem.contants;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public class HandlerRole {
public static final String DEVELOP = "develop";
public static final String TEST = "test";
public static final String OPERATOR = "operator";
public static final String LEADER = "leader";
}
... ...
package com.monitor.other.worksystem.contants;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public class WorkStatus {
/**
* 创建状态
*/
public static final int CREATED = 0;
/**
* 发起状态
*/
public static final int PUBLISH = 1;
/**
* 测试通过
*/
public static final int TEST_PASS = 2;
/**
* 发布成功
*/
public static final int EXE_SUCCESS = 3;
/**
* 发布失败
*/
public static final int EXE_FAILE = 4;
/**
* 关闭
*/
public static final int CLOSE= -1;
public static String getCstatus(int type){
switch (type){
case CREATED:
return "创建";
case PUBLISH:
return "发起";
case TEST_PASS:
return "测试通过";
case EXE_SUCCESS:
return "发布成功";
case EXE_FAILE:
return "发布失败";
case CLOSE:
return "被关闭";
default:
return "其他";
}
}
}
... ...
package com.monitor.other.worksystem.contants;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public class WorkType {
public static final String RELEASE_PROJECT = "release";
}
... ...
package com.monitor.other.worksystem.ctrl;
import com.model.HandledJob;
import com.model.ReleaseWorkJob;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.other.worksystem.contants.WorkType;
import com.monitor.other.worksystem.service.HandledService;
import com.monitor.other.worksystem.service.ReleaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by zhengyouwei on 2016/9/2.
*
* 已办工单
*/
@Controller
@RequestMapping("/handledWork")
public class HandledCtrl {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private HandledService handledService;
@Autowired
private ReleaseService releaseService;
/**
* 获取用户已办工单
* @param req
* @return
*/
@RequestMapping("/getHandledJobs")
@ResponseBody
public BaseResponse<PageResponse<HandledJob>> getHandledJobs(@RequestBody WorkSystemReq req) {
try {
PageResponse<HandledJob> pageResponse = handledService.getHandledJobs(req);
if (pageResponse == null ){
return new BaseResponse<>();
}
return new BaseResponse<PageResponse<HandledJob>>(pageResponse);
}catch (Exception e){
logger.error("getHandledJobs ~",e);
return new BaseResponse<>();
}
}
/**
* 处理工单
* @return
*/
@RequestMapping("/dealWorkJob")
@ResponseBody
public BaseResponse<Integer> dealWorkJob(@RequestBody HandledJob handledJob) {
try {
int result = 0;
if (WorkType.RELEASE_PROJECT.equals(handledJob.getType())){
result = releaseService.dealWorkJob(handledJob);
}
BaseResponse baseResponse = new BaseResponse<Integer>(result);
if(result == 2){
baseResponse.setMessage("工单不存在");
}
return baseResponse;
}catch (Exception e){
logger.error("dealWorkJob ~",e);
return new BaseResponse<>();
}
}
}
... ...
package com.monitor.other.worksystem.ctrl;
import com.model.HandledJob;
import com.model.PendingJob;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.other.worksystem.service.PendingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by zhengyouwei on 2016/9/2.
* <p>
* 代办工单
*/
@Controller
@RequestMapping("/pendingWork")
public class PendingCtrl {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private PendingService pendingService;
/**
* 获取用户待办工单
*
* @param req
* @return
*/
@RequestMapping("/getPendingJobs")
@ResponseBody
public BaseResponse<PageResponse<PendingJob>> getPendingJobs(@RequestBody WorkSystemReq req) {
try {
PageResponse<PendingJob> pageResponse = pendingService.getPendingJobs(req);
if (pageResponse == null) {
return new BaseResponse<>();
}
return new BaseResponse<PageResponse<PendingJob>>(pageResponse);
} catch (Exception e) {
logger.error("getPendingJobs ~", e);
return new BaseResponse<>();
}
}
/**
* 获取用户待办工单
*
* @return
*/
@RequestMapping("/getPendingJobByUser")
@ResponseBody
public BaseResponse<PendingJob> getPendingJobByUser(String workid, String user) {
try {
PendingJob pendingJob =pendingService.selectCountByUser(workid, user);
return new BaseResponse<PendingJob>(pendingJob);
} catch (Exception e) {
logger.error("getPendingJobByUser ~", e);
return new BaseResponse<>();
}
}
}
... ...
package com.monitor.other.worksystem.ctrl;
import com.model.ReleaseWorkJob;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.other.worksystem.contants.HandlerRole;
import com.monitor.other.worksystem.service.ReleaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by zhengyouwei on 2016/9/2.
*
* 发布工程工单系统
*/
@Controller
@RequestMapping("/releaseWork")
public class ReleaseWorkCtrl {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private ReleaseService releaseService;
/**
* 查询发布工单列表
* @param req
* @return
*/
@RequestMapping("/getReleaseWorkJobs")
@ResponseBody
public BaseResponse<PageResponse<ReleaseWorkJob>> getReleaseWorkJobs(@RequestBody PageRequest req) {
try {
PageResponse<ReleaseWorkJob> pageResponse = releaseService.getReleaseWorkJobs(req);
if (pageResponse == null ){
return new BaseResponse<>();
}
return new BaseResponse<PageResponse<ReleaseWorkJob>>(pageResponse);
}catch (Exception e){
logger.error("getReleaseWorkJobs ~",e);
return new BaseResponse<>();
}
}
/**
* 查询发布工单
* @return
*/
@RequestMapping("/getReleaseWorkJob")
@ResponseBody
public BaseResponse<ReleaseWorkJob> getReleaseWorkJob(String id) {
try {
ReleaseWorkJob releaseWorkJob = releaseService.getReleaseWorkJob(id);
return new BaseResponse<ReleaseWorkJob>(releaseWorkJob);
}catch (Exception e){
logger.error("getReleaseWorkJob ~",e);
return new BaseResponse<>();
}
}
/**
* 发起工单
* @return
*/
@RequestMapping("/createReleaseWorkJob")
@ResponseBody
public BaseResponse<Integer> createReleaseWorkJob(@RequestBody ReleaseWorkJob releaseWorkJob) {
try {
int result = releaseService.createReleaseWorkJob(releaseWorkJob);
return new BaseResponse<Integer>(result);
}catch (Exception e){
logger.error("createReleaseWorkJob ~",e);
return new BaseResponse<>();
}
}
/**
* 发起工单
* @return
*/
@RequestMapping("/checkRole")
@ResponseBody
public BaseResponse<Integer> checkRole(String role) {
if (HandlerRole.DEVELOP.equals(role)){
return new BaseResponse<>(1);
}
return new BaseResponse<>(0);
}
}
... ...
package com.monitor.other.worksystem.ctrl;
import com.model.ReleaseWorkJob;
import com.model.WorkJob;
import com.monitor.model.page.PageRequest;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.other.worksystem.service.WorksService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by zhengyouwei on 2016/9/7.
*/
@Controller
@RequestMapping("/works")
public class WorkJobCtrl {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private WorksService worksService;
/**
* 查询发布工单列表
* @param req
* @return
*/
@RequestMapping("/getWorkJobs")
@ResponseBody
public BaseResponse<PageResponse<WorkJob>> getWorkJobs(@RequestBody WorkSystemReq req) {
try {
PageResponse<WorkJob> pageResponse = worksService.getWorkJobs(req);
if (pageResponse == null ){
return new BaseResponse<>();
}
return new BaseResponse<PageResponse<WorkJob>>(pageResponse);
}catch (Exception e){
logger.error("getWorkJobs ~",e);
return new BaseResponse<>();
}
}
/**
* 查询发布工单
* @return
*/
@RequestMapping("/getWorkJob")
@ResponseBody
public BaseResponse<WorkJob> getWorkJob(String id) {
try {
WorkJob releaseWorkJob = worksService.getWorkJob(id);
return new BaseResponse<WorkJob>(releaseWorkJob);
}catch (Exception e){
logger.error("getReleaseWorkJob ~",e);
return new BaseResponse<>();
}
}
}
... ...
package com.monitor.other.worksystem.service;
import com.model.HandledJob;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.PageResponse;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface HandledService {
PageResponse<HandledJob> getHandledJobs(WorkSystemReq req);
}
... ...
package com.monitor.other.worksystem.service;
import com.model.HandledJob;
import com.model.PendingJob;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.PageResponse;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface PendingService {
PageResponse<PendingJob> getPendingJobs(WorkSystemReq req);
PendingJob selectCountByUser(String workid,String user);
}
... ...
package com.monitor.other.worksystem.service;
import com.model.HandledJob;
import com.model.ReleaseWorkJob;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.PageResponse;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface ReleaseService {
PageResponse<ReleaseWorkJob> getReleaseWorkJobs(PageRequest req);
ReleaseWorkJob getReleaseWorkJob(String id);
int createReleaseWorkJob(ReleaseWorkJob releaseWorkJob);
int dealWorkJob(HandledJob handledJob);
}
... ...
package com.monitor.other.worksystem.service;
import com.model.HandledJob;
import com.model.ReleaseWorkJob;
import com.model.WorkJob;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.PageResponse;
/**
* Created by zhengyouwei on 2016/9/2.
*/
public interface WorksService {
PageResponse<WorkJob> getWorkJobs(PageRequest req);
WorkJob getWorkJob(String id);
}
... ...
package com.monitor.other.worksystem.service.impl;
import com.model.HandledJob;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.HandledJobMapper;
import com.monitor.other.worksystem.service.HandledService;
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 HandledServiceImpl implements HandledService{
@Autowired
private HandledJobMapper handledJobMapper;
/**
* 查询用户已经处理的工单
* @param req
* @return
*/
@Override
public PageResponse<HandledJob> getHandledJobs(WorkSystemReq req) {
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = handledJobMapper.selectCount(req.getHandler());
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return null;
}
// 获取列表
List<HandledJob> list = handledJobMapper.selectByPage(page);
// 获取列表
PageResponse<HandledJob> response = new PageResponse<HandledJob>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(list);
return response;
}
}
... ...
package com.monitor.other.worksystem.service.impl;
import com.model.HandledJob;
import com.model.PendingJob;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.WorkSystemReq;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.PendingJobMapper;
import com.monitor.other.worksystem.service.PendingService;
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 PendingServiceImpl implements PendingService {
@Autowired
private PendingJobMapper pendingJobMapper;
/**
* 查询用户待处理的工单
* @param req
* @return
*/
@Override
public PageResponse<PendingJob> getPendingJobs(WorkSystemReq req) {
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = pendingJobMapper.selectCount(req.getHandler());
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return null;
}
// 获取列表
List<PendingJob> list = pendingJobMapper.selectByPage(page);
// 获取列表
PageResponse<PendingJob> response = new PageResponse<PendingJob>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(list);
return response;
}
@Override
public PendingJob selectCountByUser(String workid, String user) {
return pendingJobMapper.selectByUser(workid,user);
}
}
... ...
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;
}
}
... ...
package com.monitor.other.worksystem.service.impl;
import com.model.HandledJob;
import com.model.PendingJob;
import com.model.ReleaseWorkJob;
import com.model.User;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.mysql.mapper.HandledJobMapper;
import com.monitor.mysql.mapper.PendingJobMapper;
import com.monitor.mysql.mapper.ReleaseWorkJobMapper;
import com.monitor.mysql.mapper.UserMapper;
import com.monitor.other.worksystem.contants.WorkType;
import com.monitor.other.worksystem.service.HandledService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by zhengyouwei on 2016/9/2.
*/
@Service
public class WorkSystemSupport {
@Autowired
private PendingJobMapper pendingJobMapper;
@Autowired
private AlarmMsgService alarmMsgService;
@Autowired
private UserMapper userMapper;
@Autowired
private ReleaseWorkJobMapper releaseWorkJobMapper;
@Autowired
private HandledJobMapper handledJobMapper;
/**
* 单个待办
*
* @param pendingJob
*/
public void addPending(PendingJob pendingJob) {
pendingJobMapper.insert(pendingJob);
User user = userMapper.selectByName(pendingJob.getHandler());
if (StringUtils.isNotBlank(user.getMobile())) {
alarmMsgService.sendSms("work_system", buildSms(pendingJob), user.getMobile());
}
}
/**
* 处理结束发短信
* @param workid
* @param result
*/
public void workend(String workid,String result) {
List<HandledJob> list = handledJobMapper.selectByworkId(workid);
Set<String> mobileSet = new HashSet<String>();
for (HandledJob handledJob : list){
User user = userMapper.selectByName(handledJob.getHandler());
if (StringUtils.isNotBlank(user.getMobile())) {
mobileSet.add(user.getMobile());
}
}
StringBuilder mobileBuilder = new StringBuilder();
for (String str : mobileSet){
mobileBuilder.append(str).append(",");
}
String sms = "您处理过的工单:" + workid +" 已经处理完毕,处理结果:"+result;
alarmMsgService.sendSms("work_system",sms, mobileBuilder.toString());
}
/**
* 群体待办
*
* @param pendingJob
*/
public void addPendingByRole(PendingJob pendingJob) {
String sms = buildSms(pendingJob);
String role = pendingJob.getHandlerRole();
List<User> list = userMapper.selectUsersByRole(role);
StringBuilder mobileBuilder = new StringBuilder();
for (User user : list) {
pendingJob.setHandler(user.getName());
pendingJobMapper.insert(pendingJob);
if (StringUtils.isNotBlank(user.getMobile())) {
mobileBuilder.append(user.getMobile()).append(",");
}
}
alarmMsgService.sendSms("work_system", sms, mobileBuilder.toString().substring(0, mobileBuilder.toString().toString().length() - 1));
}
/**
* 组建短信
*
* @param pendingJob
* @return
*/
public String buildSms(PendingJob pendingJob) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("工单系统有您的待办:");
if (WorkType.RELEASE_PROJECT.equals(pendingJob.getType())) {//项目发布的短信
ReleaseWorkJob releaseWorkJob = releaseWorkJobMapper.selectById(pendingJob.getWorkId());
stringBuilder.append("项目发布,");
stringBuilder.append(releaseWorkJob.getId()).append(",");
stringBuilder.append(releaseWorkJob.getEnvironment()).append(",");
stringBuilder.append(releaseWorkJob.getPlatform()).append(",");
stringBuilder.append(releaseWorkJob.getProject()).append("!");
}
return stringBuilder.toString();
}
}
... ...
package com.monitor.other.worksystem.service.impl;
import com.model.HandledJob;
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.WorkJobMapper;
import com.monitor.other.worksystem.service.WorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by zhengyouwei on 2016/9/7.
*/
@Service
public class WorksServiceImpl implements WorksService {
@Autowired
private WorkJobMapper workJobMapper;
@Override
public PageResponse<WorkJob> getWorkJobs(PageRequest req) {
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = workJobMapper.selectCount();
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return null;
}
// 获取列表
List<WorkJob> list = workJobMapper.selectByPage(page);
// 获取列表
PageResponse<WorkJob> response = new PageResponse<WorkJob>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(list);
return response;
}
@Override
public WorkJob getWorkJob(String id) {
WorkJob workJob = workJobMapper.selectByWorkId(id);
return workJob;
}
}
... ...
... ... @@ -178,6 +178,12 @@ public class UserCtrl {
return "";
}
@RequestMapping("/getUsersByRole")
@ResponseBody
public BaseResponse<List<User>> getUsersByRole(String role) {
List<User> list = userMapper.selectUsersByRole(role);
return new BaseResponse<>(list);
}
}
... ...
... ... @@ -59,6 +59,10 @@
<artifactId>monitor-service-awstools</artifactId>
</dependency>
<dependency>
<groupId>monitor-service</groupId>
<artifactId>monitor-service-worksystem</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
... ...