代码接口调试提交
This commit is contained in:
parent
b03fbd81fa
commit
dbb14db432
|
|
@ -236,4 +236,19 @@ public class PmTaskController extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行一次任务,不管其他状态
|
||||
*/
|
||||
@Log(title = "立即执行一次任务", businessType = BusinessType.OTHER)
|
||||
@GetMapping("executeOnceJob")
|
||||
public AjaxResult executeOnceJob(@RequestBody PmTask o)
|
||||
{
|
||||
try {
|
||||
return service.executeOnceJob(o);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error("系统异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.bonus.job.domain;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.message.dao.GroupVo;
|
||||
import com.bonus.message.dao.WorkerVo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
|
@ -49,6 +50,16 @@ public class PmTask {
|
|||
*/
|
||||
private List<WorkerVo> workerList;
|
||||
|
||||
/**
|
||||
* 组列表
|
||||
*/
|
||||
private List<WorkerVo> groupList;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private Integer sex;
|
||||
|
||||
private String loopTime;
|
||||
|
||||
private String loopId;
|
||||
|
|
|
|||
|
|
@ -40,4 +40,8 @@ public interface PmTaskMapper {
|
|||
int updateOneWorkerData(WorkerVo o);
|
||||
|
||||
String getMsgData(WorkerVo o);
|
||||
|
||||
List<WorkerVo> getGroupByTaskId(Integer id);
|
||||
|
||||
Integer getWorkerSexByTaskId(Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,12 @@ public interface WorkerJobMapper {
|
|||
* @param userList
|
||||
*/
|
||||
void insertTaskRecord(List<WorkerVo> userList);
|
||||
|
||||
/**
|
||||
* 获取人员生日任务列表
|
||||
*
|
||||
* @param jobId
|
||||
* @return
|
||||
*/
|
||||
List<WorkerVo> getHappyBirthDayWorkerByJobId(String jobId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,6 @@ public interface PmTaskService{
|
|||
AjaxResult getMessageBalance();
|
||||
|
||||
AjaxResult updateTaskStatus(PmTask task) throws SchedulerException;
|
||||
|
||||
AjaxResult executeOnceJob(PmTask o) throws SchedulerException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -41,6 +39,8 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
@Transactional
|
||||
@Override
|
||||
public AjaxResult insert(PmTask task) throws SchedulerException, TaskException {
|
||||
//客户要求初始状态为开启
|
||||
task.setTaskStatus("0");
|
||||
//处理job数据
|
||||
SysJob job = new SysJob();
|
||||
job.setJobName(task.getTaskName());
|
||||
|
|
@ -50,6 +50,7 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
job.setMisfirePolicy(task.getMisfirePolicy());
|
||||
job.setConcurrent(task.getConcurrent());
|
||||
job.setStatus(task.getTaskStatus());
|
||||
|
||||
job.setCreateBy(SecurityUtils.getUsername());
|
||||
//验证job数据
|
||||
AjaxResult ajaxResult = verifyJob(job);
|
||||
|
|
@ -62,10 +63,34 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
job.setRelationId(task.getId());
|
||||
job.setRelationType("短信");
|
||||
if(insert > 0){
|
||||
|
||||
int i = jobService.insertJob(job);
|
||||
task.getWorkerList().forEach(worker -> worker.setTaskId(task.getId()));
|
||||
mapper.insertTaskWorker(task.getWorkerList());
|
||||
List<WorkerVo> allList = new ArrayList<>();
|
||||
List<WorkerVo> workerList = task.getWorkerList();
|
||||
if (workerList != null && !workerList.isEmpty()) {
|
||||
workerList.forEach(worker -> {
|
||||
worker.setTaskId(task.getId());
|
||||
worker.setType("1");
|
||||
});
|
||||
allList.addAll(workerList);
|
||||
}
|
||||
List<WorkerVo> groupList = task.getGroupList();
|
||||
if (groupList != null && !groupList.isEmpty()) {
|
||||
groupList.forEach(worker ->{
|
||||
worker.setTaskId(task.getId());
|
||||
worker.setType("2");
|
||||
});
|
||||
allList.addAll(groupList);
|
||||
}
|
||||
if(task.getSex() != null){
|
||||
WorkerVo bean = new WorkerVo();
|
||||
bean.setId(task.getSex());
|
||||
bean.setTaskId(task.getId());
|
||||
bean.setType("3");
|
||||
allList.add(bean);
|
||||
}
|
||||
if (!allList.isEmpty()){
|
||||
mapper.insertTaskWorker(allList);
|
||||
}
|
||||
}
|
||||
return insert > 0 ? AjaxResult.success("添加成功",task) : AjaxResult.error("添加失败");
|
||||
}
|
||||
|
|
@ -74,8 +99,15 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
public PmTask getById(PmTask task) {
|
||||
PmTask byId = mapper.getById(task);
|
||||
if(byId != null && byId.getId() != null){
|
||||
//单人
|
||||
List<WorkerVo> list = mapper.getWorkerByTaskId(task.getId());
|
||||
byId.setWorkerList(list);
|
||||
//分组
|
||||
List<WorkerVo> groupList = mapper.getGroupByTaskId(task.getId());
|
||||
byId.setGroupList(list);
|
||||
//按性别群发
|
||||
Integer sex = mapper.getWorkerSexByTaskId(task.getId());
|
||||
byId.setSex(sex);
|
||||
}
|
||||
return byId;
|
||||
}
|
||||
|
|
@ -103,9 +135,34 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
int update = mapper.update(task);
|
||||
if(update > 0){
|
||||
int i = jobService.updateJob(job);
|
||||
task.getWorkerList().forEach(worker -> worker.setTaskId(task.getId()));
|
||||
List<WorkerVo> allList = new ArrayList<>();
|
||||
List<WorkerVo> workerList = task.getWorkerList();
|
||||
if (workerList != null && !workerList.isEmpty()) {
|
||||
workerList.forEach(worker -> {
|
||||
worker.setTaskId(task.getId());
|
||||
worker.setType("1");
|
||||
});
|
||||
allList.addAll(workerList);
|
||||
}
|
||||
List<WorkerVo> groupList = task.getGroupList();
|
||||
if (groupList != null && !groupList.isEmpty()) {
|
||||
groupList.forEach(worker ->{
|
||||
worker.setTaskId(task.getId());
|
||||
worker.setType("2");
|
||||
});
|
||||
allList.addAll(groupList);
|
||||
}
|
||||
if(task.getSex() != null){
|
||||
WorkerVo bean = new WorkerVo();
|
||||
bean.setId(task.getSex());
|
||||
bean.setTaskId(task.getId());
|
||||
bean.setType("3");
|
||||
allList.add(bean);
|
||||
}
|
||||
mapper.delTaskWorker(task);
|
||||
mapper.insertTaskWorker(task.getWorkerList());
|
||||
if (!allList.isEmpty()){
|
||||
mapper.insertTaskWorker(allList);
|
||||
}
|
||||
}
|
||||
return update > 0 ? AjaxResult.success("修改成功",task) : AjaxResult.error("修改失败");
|
||||
}
|
||||
|
|
@ -160,6 +217,7 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
public AjaxResult oneWorkerResend(WorkerVo o) {
|
||||
//1.先去查短信内容
|
||||
String sendContent = mapper.getMsgData(o);
|
||||
o.setSendContent(sendContent);
|
||||
List<WorkerVo> userList = new ArrayList<>();
|
||||
userList.add(o);
|
||||
MessageSendUtil messageSendUtil = new MessageSendUtil();
|
||||
|
|
@ -198,6 +256,12 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
* @param task
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult updateTaskStatus(PmTask task) throws SchedulerException {
|
||||
SysJob newJob = jobService.selectJobById(task.getJobId());
|
||||
|
|
@ -206,6 +270,20 @@ public class PmTaskServiceImpl implements PmTaskService{
|
|||
return i > 0 ? AjaxResult.success("更新成功") : AjaxResult.error("更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行一次任务
|
||||
* @param o
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult executeOnceJob(PmTask o) throws SchedulerException {
|
||||
//处理job数据
|
||||
SysJob job = jobService.selectJobById(o.getJobId());
|
||||
boolean run = jobService.run(job);
|
||||
return run ? AjaxResult.success("执行成功") : AjaxResult.error("执行失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验cron表达式
|
||||
* @param job
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class WorkerSendMsgTask{
|
|||
SnowflakeIdGenerator idGen = new SnowflakeIdGenerator(1, 1);
|
||||
|
||||
/**
|
||||
* schedule
|
||||
* 人员短信调度执行
|
||||
*/
|
||||
public void sendMsg(String jobId){
|
||||
|
|
@ -46,7 +47,19 @@ public class WorkerSendMsgTask{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* schedule
|
||||
* 默认任务生日任务
|
||||
*/
|
||||
public void sendHappyBirthDayMsg(String jobId){
|
||||
try{
|
||||
//查询过生日的人员和短信内容
|
||||
List<WorkerVo> list = mapper.getHappyBirthDayWorkerByJobId(jobId);
|
||||
sendInBatches(list);
|
||||
}catch (Exception e){
|
||||
logger.error("人员短信调度,{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量发送短信
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.bonus.message.controller;
|
|||
import com.bonus.common.core.controller.BaseController;
|
||||
import com.bonus.common.core.domain.AjaxResult;
|
||||
import com.bonus.common.core.page.TableDataInfo;
|
||||
import com.bonus.common.utils.SecurityUtils;
|
||||
import com.bonus.message.dao.GroupVo;
|
||||
import com.bonus.message.dao.WorkerVo;
|
||||
import com.bonus.message.service.GroupService;
|
||||
|
|
@ -45,6 +46,8 @@ public class GroupController extends BaseController {
|
|||
@PostMapping("/addGroup")
|
||||
public AjaxResult addGroup(@RequestBody GroupVo groupVo) {
|
||||
try {
|
||||
String userName = SecurityUtils.getLoginUser().getUser().getUserName();
|
||||
groupVo.setCreateUser(userName);
|
||||
int res = groupService.addGroup(groupVo);
|
||||
if (res ==1) {
|
||||
return AjaxResult.success();
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ public class GroupVo {
|
|||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人员
|
||||
*/
|
||||
private String createUser;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ public class WorkerVo {
|
|||
*/
|
||||
private String keyWord;
|
||||
|
||||
/**
|
||||
* 类别
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -104,6 +104,11 @@ public class WorkerServiceImpl implements WorkerService {
|
|||
if (sysDept != null){
|
||||
workerVo.setOrgId(sysDept.getDeptId().intValue());
|
||||
}
|
||||
if (workerVo.getSex().trim().equals("男")) {
|
||||
workerVo.setSex("1");
|
||||
} else {
|
||||
workerVo.setSex("0");
|
||||
}
|
||||
addWorker(workerVo);
|
||||
}
|
||||
return "导入成功";
|
||||
|
|
|
|||
|
|
@ -68,13 +68,14 @@ spring:
|
|||
# redis 配置
|
||||
redis:
|
||||
# 地址
|
||||
host: 192.168.0.14
|
||||
# 端口,默认为6379
|
||||
port: 2004
|
||||
# 数据库索引
|
||||
# host: 192.168.0.14
|
||||
# port: 2004
|
||||
# database: 6
|
||||
# password: Plzbns@Redis123!
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
database: 6
|
||||
# 密码
|
||||
password: Plzbns@Redis123!
|
||||
password:
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.message.mapper.GroupMapper">
|
||||
<insert id="addGroup" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into pm_group (group_name,remark,create_time)
|
||||
values (#{groupName},#{remark},#{createTime})
|
||||
insert into pm_group (group_name,remark,create_user)
|
||||
values (#{groupName},#{remark},#{createUser})
|
||||
</insert>
|
||||
<insert id="addGroupDetails">
|
||||
insert into bm_group_details (group_id,worker_id)
|
||||
|
|
@ -20,9 +20,6 @@
|
|||
<if test="remark!= null " >
|
||||
remark=#{remark},
|
||||
</if>
|
||||
<if test="updateTime!= null " >
|
||||
update_time=#{updateTime},
|
||||
</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
|
@ -38,7 +35,9 @@
|
|||
<if test="groupName!= null " >
|
||||
and group_name like concat('%', #{groupName}, '%')
|
||||
</if>
|
||||
|
||||
<if test="createUser!= null" >
|
||||
and create_user like concat('%', #{createUser}, '%')
|
||||
</if>
|
||||
</select>
|
||||
<select id="getWorkerList" resultType="com.bonus.message.dao.WorkerVo">
|
||||
select pw.id,pw.worker_name,pw.org_id,pw.sex,pw.phone
|
||||
|
|
|
|||
|
|
@ -80,14 +80,14 @@
|
|||
bm.worker_id as id, w.worker_name, w.phone
|
||||
from bm_task_worker bm
|
||||
left join pm_worker w on bm.worker_id = w.id
|
||||
where bm.task_id = #{taskId}
|
||||
where bm.task_id = #{taskId} and bm.type = '1'
|
||||
</select>
|
||||
|
||||
<insert id="insertTaskWorker">
|
||||
insert into bm_task_worker (task_id, worker_id)
|
||||
insert into bm_task_worker (task_id, worker_id,type)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.taskId},#{item.id})
|
||||
(#{item.taskId},#{item.id},#{item.type})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
|
@ -114,6 +114,12 @@
|
|||
LEFT JOIN bm_task_record btw ON btw.task_id = pt.id
|
||||
WHERE
|
||||
pt.id = #{id}
|
||||
<if test="taskName != null">
|
||||
and pt.task_name like concat('%',#{taskName},'%')
|
||||
</if>
|
||||
<if test="msgType != null">
|
||||
and pt.msg_type = #{msgType}
|
||||
</if>
|
||||
GROUP BY
|
||||
btw.loop_id
|
||||
</select>
|
||||
|
|
@ -141,6 +147,7 @@
|
|||
btw.id,
|
||||
w.worker_name,
|
||||
btw.phone,
|
||||
sd.dept_name AS orgName,
|
||||
btw.send_time,
|
||||
btw.submit_status,
|
||||
btw.reason,
|
||||
|
|
@ -148,6 +155,7 @@
|
|||
FROM
|
||||
bm_task_record btw
|
||||
left join pm_worker w on btw.worker_id = w.id
|
||||
left join sys_dept sd on w.org_id = sd.dept_id
|
||||
WHERE
|
||||
btw.loop_id = #{loopId}
|
||||
</select>
|
||||
|
|
@ -165,4 +173,19 @@
|
|||
WHERE
|
||||
btw.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getGroupByTaskId" resultType="com.bonus.message.dao.WorkerVo">
|
||||
select
|
||||
pg.id as id, pg.group_name as workerName
|
||||
from bm_task_worker bm
|
||||
left join pm_group pg on bm.worker_id = pg.id
|
||||
where bm.task_id = #{taskId} and bm.type = '2'
|
||||
</select>
|
||||
|
||||
<select id="getWorkerSexByTaskId" resultType="Integer">
|
||||
select
|
||||
bm.worker_id
|
||||
from bm_task_worker bm
|
||||
where bm.task_id = #{taskId} and bm.type = '3'
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -21,12 +21,49 @@
|
|||
|
||||
|
||||
<select id="getWorkerByJobId" resultType="com.bonus.message.dao.WorkerVo">
|
||||
select
|
||||
pt.task_name, pt.send_content, w.worker_name, w.phone,pt.id as taskId, w.id
|
||||
from pm_task pt
|
||||
left join bm_task_worker bm on pt.id = bm.task_id
|
||||
left join pm_worker w on bm.worker_id = w.id
|
||||
where pt.id = #{jobId}
|
||||
SELECT
|
||||
pt.task_name,
|
||||
pt.send_content,
|
||||
w.worker_name,
|
||||
w.phone,
|
||||
pt.id AS taskId,
|
||||
w.id
|
||||
FROM
|
||||
bm_task_worker bm
|
||||
LEFT JOIN pm_task pt ON pt.id = bm.task_id
|
||||
LEFT JOIN pm_worker w ON bm.worker_id = w.id
|
||||
WHERE
|
||||
pt.id = #{jobId} AND type = 1
|
||||
UNION
|
||||
SELECT
|
||||
pt.task_name,
|
||||
pt.send_content,
|
||||
w.worker_name,
|
||||
w.phone,
|
||||
pt.id AS taskId,
|
||||
w.id
|
||||
FROM
|
||||
bm_task_worker bm
|
||||
LEFT JOIN pm_task pt ON pt.id = bm.task_id
|
||||
LEFT JOIN pm_group g ON bm.worker_id = g.id
|
||||
LEFT JOIN bm_group_details pgw ON g.id = pgw.group_id
|
||||
LEFT JOIN pm_worker w ON pgw.worker_id = w.id
|
||||
WHERE
|
||||
pt.id = #{jobId} AND type = 2
|
||||
UNION
|
||||
SELECT
|
||||
pt.task_name,
|
||||
pt.send_content,
|
||||
w.worker_name,
|
||||
w.phone,
|
||||
pt.id AS taskId,
|
||||
w.id
|
||||
FROM
|
||||
bm_task_worker bm
|
||||
LEFT JOIN pm_task pt ON pt.id = bm.task_id
|
||||
LEFT JOIN pm_worker w ON bm.worker_id = w.sex
|
||||
WHERE
|
||||
pt.id = #{jobId} AND type = 3
|
||||
</select>
|
||||
|
||||
<insert id="insertTaskRecord">
|
||||
|
|
@ -36,4 +73,18 @@
|
|||
(#{item.taskId}, #{item.loopId}, #{item.id}, #{item.phone}, #{item.batchNumber}, #{item.submitStatus}, #{item.sendTime}, #{item.reason})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="getHappyBirthDayWorkerByJobId" resultType="com.bonus.message.dao.WorkerVo">
|
||||
SELECT
|
||||
pt.task_name,
|
||||
pt.send_content,
|
||||
w.worker_name,
|
||||
w.phone,
|
||||
pt.id AS taskId,
|
||||
w.id
|
||||
FROM pm_task pt, pm_worker w
|
||||
WHERE
|
||||
pt.id = #{jobId}
|
||||
AND w.birthday = CURRENT_DATE;
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue