13 changed files with 185 additions and 114 deletions
@ -1,10 +1,12 @@
|
||||
package com.biutag.mapper.system; |
||||
|
||||
import com.biutag.core.basics.IBaseMapper; |
||||
import com.biutag.entity.system.Post; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* 系统岗位Mapper |
||||
*/ |
||||
@Mapper |
||||
public interface PostMapper extends IBaseMapper<Post> { |
||||
} |
||||
} |
||||
|
||||
@ -1,17 +0,0 @@
|
||||
package com.biutag.lan.crontab; |
||||
|
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
|
||||
/** |
||||
* 具体的定时任务 |
||||
*/ |
||||
@Component("myJob") |
||||
public class MyJob { |
||||
|
||||
public void handle(String s) { |
||||
// System.out.println("有参数定时任务执行逻辑 : " + s);
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.Favorite; |
||||
|
||||
public interface FavoriteMapper extends BaseMapper<Favorite> { |
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.FlowNode; |
||||
|
||||
public interface FlowNodeMapper extends BaseMapper<FlowNode> { |
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.MailCategory; |
||||
|
||||
public interface MailCategoryMapper extends BaseMapper<MailCategory> { |
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.MailFlow; |
||||
|
||||
public interface MailFlowMapper extends BaseMapper<MailFlow> { |
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.Mail; |
||||
|
||||
public interface MailMapper extends BaseMapper<Mail> { |
||||
} |
||||
@ -0,0 +1,7 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.MailSourceEtl; |
||||
|
||||
public interface MailSourceEtlMapper extends BaseMapper<MailSourceEtl> { |
||||
} |
||||
@ -0,0 +1,8 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.lan.domain.MailSource; |
||||
|
||||
public interface MailSourceMapper extends BaseMapper<MailSource> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
package com.biutag.lan.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.lan.domain.Work; |
||||
import com.biutag.lan.domain.vo.WorkVo; |
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
public interface WorkMapper extends BaseMapper<Work> { |
||||
|
||||
Page<WorkVo> selectPageTodo(@Param("page") Page<Work> page, @Param(Constants.WRAPPER) QueryWrapper<Work> queryWrapper); |
||||
|
||||
} |
||||
@ -0,0 +1,117 @@
|
||||
package com.biutag.lan.service; |
||||
|
||||
import cn.hutool.core.date.DateUnit; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import cn.hutool.extra.spring.SpringUtil; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.exception.BusinessException; |
||||
import com.biutag.lan.AdminThreadLocal; |
||||
import com.biutag.lan.domain.FlowNode; |
||||
import com.biutag.lan.domain.Mail; |
||||
import com.biutag.lan.domain.MailFlow; |
||||
import com.biutag.lan.domain.MailSource; |
||||
import com.biutag.lan.domain.bo.FlowAction; |
||||
import com.biutag.lan.domain.vo.MailFlowDetail; |
||||
import com.biutag.lan.domain.vo.MailVo; |
||||
import com.biutag.lan.flow.Action; |
||||
import com.biutag.lan.flow.Flow; |
||||
import com.biutag.lan.flow.node.FirstSignFlow; |
||||
import com.biutag.lan.mapper.MailMapper; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.util.Comparator; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
import java.util.stream.Collectors; |
||||
|
||||
@RequiredArgsConstructor |
||||
@Service |
||||
public class MailService extends ServiceImpl<MailMapper, Mail> { |
||||
|
||||
private final MailSourceService mailSourceService; |
||||
|
||||
private final MailFlowService mailFlowService; |
||||
|
||||
private final FavoriteService favoriteService; |
||||
|
||||
@Lazy |
||||
@Autowired |
||||
private List<Flow> flowNodes; |
||||
|
||||
public MailFlowDetail getMailFlowDetail(String mailId) { |
||||
MailSource mailSource = mailSourceService.getById(mailId); |
||||
Flow flow; |
||||
Mail mail; |
||||
if (!mailSource.getSignFlag()) { |
||||
flow = SpringUtil.getBean(FirstSignFlow.class); |
||||
mail = mailSource.toMail(); |
||||
// 将流程开始时间设置为
|
||||
mail.setFlowLimitedLastHandlerTime(mailSource.getCreateTime()); |
||||
} else { |
||||
mail = getById(mailId); |
||||
flow = flowNodes.stream() |
||||
.filter(item -> mail.getFlowKey().equals(item.getFlowNode().getKey())) |
||||
.findFirst().orElseThrow(() -> new BusinessException("没有该流程节点")); |
||||
} |
||||
List<MailFlow> flows = mailFlowService.list(mailId) |
||||
// 时间倒叙
|
||||
.stream().sorted(Comparator.comparing(MailFlow::getCreateTime).reversed()).collect(Collectors.toList()); |
||||
FlowNode flowNode = flow.getFlowNode(); |
||||
MailVo mailVo = new MailVo(); |
||||
BeanUtils.copyProperties(mail, mailVo); |
||||
// 剩余时间
|
||||
long flowRemainingTime = flowNode.getLimitedTime() - Duration.between(mail.getFlowLimitedLastHandlerTime(), LocalDateTime.now()).getSeconds(); |
||||
mailVo.setFlowRemainingTime(flowRemainingTime); |
||||
// 剩余时间百分比
|
||||
int flowRemainingTimePercentage = flowRemainingTime <= 0 ? 0 : |
||||
Long.valueOf(flowRemainingTime * 100 / flowNode.getLimitedTime()).intValue(); |
||||
mailVo.setFlowRemainingTimePercentage(flowRemainingTimePercentage); |
||||
return new MailFlowDetail().setMail(mailVo) |
||||
.setIsFav(Objects.nonNull(favoriteService.get(mailId, AdminThreadLocal.getEmpNo()))) |
||||
.setFlows(flows) |
||||
.setFlowNode(flowNode) |
||||
.setActions(flow.getActions()); |
||||
} |
||||
|
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean next(FlowAction flowAction) { |
||||
Flow flow = flowNodes.stream() |
||||
.filter(item -> item.getFlowNode().getKey().equals(flowAction.getFlowKey())) |
||||
.findFirst().orElseThrow(() -> new BusinessException("没有该流程节点")); |
||||
LocalDateTime now = LocalDateTime.now(); |
||||
LocalDateTime lastHandlerTime = mailFlowService.getMailLastHandlerTime(flowAction.getMailId()); |
||||
|
||||
long consumingTime = DateUtil.between(Date.from(lastHandlerTime.atZone(ZoneId.systemDefault()).toInstant()), new Date(), DateUnit.SECOND); |
||||
|
||||
Action action = flow.getActions().stream().filter(item -> item.getKey().equals(flowAction.getNextActionKey())).findFirst().get(); |
||||
// 保存当前流程数据
|
||||
MailFlow mailFlow = new MailFlow() |
||||
.setMailId(flowAction.getMailId()) |
||||
.setFlowKey(flow.getFlowNode().getKey()) |
||||
.setFlowAfterName(action.getFlowAfterName()) |
||||
.setHandlerName(AdminThreadLocal.getPoliceName()) |
||||
.setHandlerEmpNo(AdminThreadLocal.getEmpNo()) |
||||
.setHandlerDeptId(AdminThreadLocal.getDeptId()) |
||||
.setHandlerDeptName(AdminThreadLocal.getDeptName()) |
||||
.setHandlerRoleId(AdminThreadLocal.getRoleIds().get(0)) |
||||
.setHandlerRoleName(AdminThreadLocal.getRoleName()) |
||||
.setLimitedTime(flow.getFlowNode().getLimitedTime()) |
||||
.setConsumingTime(consumingTime) |
||||
.setCreateTime(now); |
||||
mailFlowService.save(mailFlow); |
||||
|
||||
// 下一节点操作
|
||||
flow.next(flowAction.getNextActionKey(), flowAction.getMailId(), flowAction.getData()); |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
@ -1,45 +0,0 @@
|
||||
package com.biutag.lan.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@ApiModel("计划任务详情Vo") |
||||
public class CrontabDetailVo implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "任务ID") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "任务分组") |
||||
private String types; |
||||
|
||||
@ApiModelProperty(value = "任务名称") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "执行命令") |
||||
private String command; |
||||
|
||||
@ApiModelProperty(value = "执行规则") |
||||
private String rules; |
||||
|
||||
@ApiModelProperty(value = "备注信息") |
||||
private String remark; |
||||
|
||||
@ApiModelProperty(value = "错误信息") |
||||
private String error; |
||||
|
||||
@ApiModelProperty(value = "执行状态: 1=正在运行, 2=任务停止, 3=发生错误") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "执行策略: 1=立即执行, 2=执行一次, 3=放弃执行") |
||||
private Integer strategy; |
||||
|
||||
@ApiModelProperty(value = "并发执行: 0=否, 1=是") |
||||
private Integer concurrent; |
||||
|
||||
} |
||||
@ -1,51 +0,0 @@
|
||||
package com.biutag.lan.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@ApiModel("计划任务列表Vo") |
||||
public class CrontabListedVo implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "任务ID") |
||||
private Integer id; // 执行ID
|
||||
|
||||
@ApiModelProperty(value = "任务分组") |
||||
private String groups; |
||||
|
||||
@ApiModelProperty(value = "任务名称") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "执行命令") |
||||
private String command; |
||||
|
||||
@ApiModelProperty(value = "执行规则") |
||||
private String rules; |
||||
|
||||
@ApiModelProperty(value = "错误信息") |
||||
private String error; |
||||
|
||||
@ApiModelProperty(value = "执行状态: [1=正在运行, 2=任务停止, 3=发生错误]") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "执行策略: [1=立即执行, 2=执行一次, 3=放弃执行]") |
||||
private Integer strategy; |
||||
|
||||
@ApiModelProperty(value = "并发执行: [0=否, 1=是]") |
||||
private Integer concurrent; |
||||
|
||||
@ApiModelProperty(value = "开始时间") |
||||
private String startTime; |
||||
|
||||
@ApiModelProperty(value = "结束时间") |
||||
private String endTime; |
||||
|
||||
@ApiModelProperty(value = "执行耗时") |
||||
private Long taskTime; |
||||
|
||||
} |
||||
Loading…
Reference in new issue