diff --git a/mailbox-common/src/main/java/com/biutag/mapper/system/PostMapper.java b/mailbox-common/src/main/java/com/biutag/mapper/system/PostMapper.java index 07c62bd..27231cc 100644 --- a/mailbox-common/src/main/java/com/biutag/mapper/system/PostMapper.java +++ b/mailbox-common/src/main/java/com/biutag/mapper/system/PostMapper.java @@ -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 { -} \ No newline at end of file +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/crontab/MyJob.java b/mailbox-lan/src/main/java/com/biutag/lan/crontab/MyJob.java deleted file mode 100644 index 1e02b6f..0000000 --- a/mailbox-lan/src/main/java/com/biutag/lan/crontab/MyJob.java +++ /dev/null @@ -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); - } - -} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/FavoriteMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/FavoriteMapper.java new file mode 100644 index 0000000..c2b7afc --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/FavoriteMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/FlowNodeMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/FlowNodeMapper.java new file mode 100644 index 0000000..2504ab6 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/FlowNodeMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailCategoryMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailCategoryMapper.java new file mode 100644 index 0000000..75c9921 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailCategoryMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailFlowMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailFlowMapper.java new file mode 100644 index 0000000..f6fe875 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailFlowMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailMapper.java new file mode 100644 index 0000000..18902ad --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceEtlMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceEtlMapper.java new file mode 100644 index 0000000..8017ada --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceEtlMapper.java @@ -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 { +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceMapper.java new file mode 100644 index 0000000..5cbda79 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/MailSourceMapper.java @@ -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 { + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java new file mode 100644 index 0000000..7b51f8a --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java @@ -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 { + + Page selectPageTodo(@Param("page") Page page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper); + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/MailService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/MailService.java new file mode 100644 index 0000000..b8e7cf4 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/MailService.java @@ -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 { + + private final MailSourceService mailSourceService; + + private final MailFlowService mailFlowService; + + private final FavoriteService favoriteService; + + @Lazy + @Autowired + private List 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 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; + } + +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabDetailVo.java b/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabDetailVo.java deleted file mode 100644 index af72691..0000000 --- a/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabDetailVo.java +++ /dev/null @@ -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; - -} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabListedVo.java b/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabListedVo.java deleted file mode 100644 index 03fda5f..0000000 --- a/mailbox-lan/src/main/java/com/biutag/lan/vo/CrontabListedVo.java +++ /dev/null @@ -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; - -}