appId;
+
+
+ /** 应用类型枚举(app:应用 activity:指令) */
+ @Excel(name = "应用类型枚举", readConverterExp = "a=pp:应用,a=ctivity:指令")
+ @ApiModelProperty(name="appType",value = "应用类型枚举")
+ private String appType;
+
+ /** 预计人工耗时 */
+ @Excel(name = "预计人工耗时")
+ @ApiModelProperty(name="manualTime",value = "预计人工耗时")
+ private String manualTime;
+
+ /** 参数 */
+ @Excel(name = "参数")
+ @ApiModelProperty(name="planParams",value = "参数")
+ private String planParams;
+
+ /** 等待超时时间 */
+ @Excel(name = "等待超时时间")
+ @ApiModelProperty(name="waitTimeout",value = "等待超时时间")
+ private String waitTimeout;
+
+ /** 优先级 */
+ @Excel(name = "优先级")
+ @ApiModelProperty(name="priority",value = "优先级")
+ private Integer priority;
+
+
+ /** 执行类型(0立即执行 1指定时间执行 2周期执行) */
+ @Excel(name = "执行类型", readConverterExp = "0=立即执行,1=指定时间执行,2=周期执行")
+ @ApiModelProperty(name="excType",value = "执行类型")
+ private String excType;
+
+
+ /** 执行时间 */
+ @JsonFormat(pattern = "yyyy-MM-dd")
+ @Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd")
+ @ApiModelProperty(name="excTime",value = "执行时间")
+ private Date excTime;
+
+ /** 执行表达式 */
+ @Excel(name = "执行表达式")
+ @ApiModelProperty(name="cronExpression",value = "执行表达式")
+ private String cronExpression;
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+ .append("id", getId())
+ .append("planName", getPlanName())
+ .append("planType", getPlanType())
+ .append("robotName", getRobotName())
+ .append("appTypeName", getAppTypeName())
+ .append("appName", getAppName())
+ .append("appId", getAppId())
+ .append("appType", getAppType())
+ .append("manualTime", getManualTime())
+ .append("params", getParams())
+ .append("waitTimeout", getWaitTimeout())
+ .append("priority", getPriority())
+ .append("createBy", getCreateBy())
+ .append("createTime", getCreateTime())
+ .append("updateBy", getUpdateBy())
+ .append("updateTime", getUpdateTime())
+ .append("remark", getRemark())
+ .append("deleted", getDeleted())
+ .toString();
+ }
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/ApplyStartBO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/ApplyStartBO.java
new file mode 100644
index 0000000..20875d3
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/ApplyStartBO.java
@@ -0,0 +1,97 @@
+package com.ruoyi.business.domain.bo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 应用信息管理对象 ct_apply
+ *
+ * @author LiuChengRan
+ * @date 2024-06-13
+ */
+@Data
+@Builder(toBuilder = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@ApiModel(value = "ApplyStartBO", description = "启动应用")
+public class ApplyStartBO {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 指定的机器人名称
+ *
+ * 与robotClientGroupUuid二选一
+ */
+ private String accountName;
+
+ /**
+ * 机器人分组Id
+ *
+ * 与accountName二选一
+ */
+ private String robotClientGroupUuid;
+
+ /**
+ * 需要运行的应用
+ *
+ * 必填
+ */
+ private String robotUuid;
+ /** 计划参数 */
+ @Excel(name = "计划参数")
+ @ApiModelProperty(name="planParams",value = "计划参数")
+ private String planParams;
+ /**
+ * 应用运行参数
+ *
+ * 非必填
+ */
+ private List planParamsList;
+
+ /**
+ * 等待超时时间
+ *
+ * @see com.xybot.api.sdk.enums.WaitTimeoutEnum
+ *
+ * 非必填,不填,默认为10分钟
+ */
+ private String waitTimeout;
+
+ /**
+ * 优先级
+ *
+ * @see com.xybot.api.sdk.enums.PriorityEnum
+ * 非必填,不填,默认为middle
+ */
+ private String priority;
+
+ @Excel(name = "所属公司")
+ @ApiModelProperty(name = "deptId", value = "所属公司")
+ private Long deptId;
+
+ /**
+ * 应用运行参数
+ */
+ @Data
+ private static class RobotParam {
+ // 参数名
+ private String name;
+ // 参数值
+ private String value;
+ // 参数类型
+ private String type;
+
+ }
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java
new file mode 100644
index 0000000..ed79165
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java
@@ -0,0 +1,19 @@
+package com.ruoyi.business.domain.bo;
+
+import lombok.Data;
+
+/**
+ * 停止job请求
+ *
+ * @author boyi
+ * @since 2022/8/26 10:16
+ */
+@Data
+public class JobQueryBO {
+
+ /**
+ * 应用运行的uuid, 由job/start接口返回
+ */
+ private String jobUuid;
+}
+
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java
new file mode 100644
index 0000000..1676add
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java
@@ -0,0 +1,104 @@
+package com.ruoyi.business.domain.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 查询job响应
+ *
+ * @author boyi
+ * @since 2022/8/26 10:17
+ */
+@Data
+public class JobQueryVO {
+
+ /**
+ * 启动的任务的uuid
+ *
+ * 不为空
+ */
+ private String jobUuid;
+
+ /**
+ * 任务状态
+ *
+ * 不为空
+ * @see com.xybot.api.sdk.enums.JobStatusEnum
+ */
+ private String status;
+
+ /**
+ * 任务状态名称
+ *
+ * 不为空
+ *
+ * @see com.xybot.api.sdk.enums.JobStatusEnum
+ */
+ private String statusName;
+
+ /**
+ * 运行的应用
+ *
+ * 不为空
+ */
+ private String robotUuid;
+
+ /**
+ * 运行的应用名称
+ *
+ * 不为空
+ */
+ private String robotName;
+
+ /**
+ * 任务开始运行的时间
+ */
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date startTime;
+
+ /**
+ * 任务结束运行的时间
+ */
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date endTime;
+
+ /**
+ * 备注
+ */
+ private String remark;
+
+ /**
+ * 应用运行参数
+ */
+ private RobotParam robotParams;
+
+ /**
+ * 机器人账号
+ *
+ * 不为空
+ */
+ private String robotClientUuid;
+
+ /**
+ * 机器人名称
+ *
+ * 不为空
+ */
+ private String robotClientName;
+
+ /**
+ * 应用运行参数
+ */
+ @Data
+ private static class RobotParam {
+ // 参数名
+ private String name;
+ // 参数值
+ private String value;
+ // 参数类型
+ private String type;
+
+ }
+}
\ No newline at end of file
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobStartVO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobStartVO.java
new file mode 100644
index 0000000..32c992b
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobStartVO.java
@@ -0,0 +1,18 @@
+package com.ruoyi.business.domain.vo;
+
+import lombok.Data;
+
+/**
+ * jobStart响应
+ *
+ * @author boyi
+ * @since 2022/8/24 10:54
+ */
+@Data
+public class JobStartVO {
+
+ /**
+ * 启动的job的uuid
+ */
+ private String jobUuid;
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanLogMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanLogMapper.java
new file mode 100644
index 0000000..8729312
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanLogMapper.java
@@ -0,0 +1,24 @@
+package com.ruoyi.business.mapper;
+
+import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.business.domain.ApplyPlanLog;
+
+/**
+ * 应用执行结果记录管理Mapper接口
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+public interface ApplyPlanLogMapper extends BaseMapper
+{
+
+ /**
+ * 查询应用执行结果记录管理列表
+ *
+ * @param applyPlanLog 应用执行结果记录管理
+ * @return 应用执行结果记录管理集合
+ */
+ List selectApplyPlanLogList(ApplyPlanLog applyPlanLog);
+
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanMapper.java
new file mode 100644
index 0000000..69bfaa5
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyPlanMapper.java
@@ -0,0 +1,24 @@
+package com.ruoyi.business.mapper;
+
+import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.business.domain.ApplyPlan;
+
+/**
+ * 应用执行计划管理Mapper接口
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+public interface ApplyPlanMapper extends BaseMapper
+{
+
+ /**
+ * 查询应用执行计划管理列表
+ *
+ * @param applyPlan 应用执行计划管理
+ * @return 应用执行计划管理集合
+ */
+ List selectApplyPlanList(ApplyPlan applyPlan);
+
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanLogService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanLogService.java
new file mode 100644
index 0000000..000035a
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanLogService.java
@@ -0,0 +1,24 @@
+package com.ruoyi.business.service;
+
+import java.util.List;
+import com.ruoyi.business.domain.ApplyPlanLog;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 应用执行结果记录管理Service接口
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+public interface IApplyPlanLogService extends IService
+{
+
+ /**
+ * 查询应用执行结果记录管理列表
+ *
+ * @param applyPlanLog 应用执行结果记录管理
+ * @return 应用执行结果记录管理集合
+ */
+ List list(ApplyPlanLog applyPlanLog);
+
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java
new file mode 100644
index 0000000..1c3c215
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java
@@ -0,0 +1,45 @@
+package com.ruoyi.business.service;
+
+import java.util.List;
+
+import com.ruoyi.business.domain.ApplyPlan;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.business.domain.bo.AddApplyPlanBO;
+
+/**
+ * 应用执行计划管理Service接口
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+public interface IApplyPlanService extends IService {
+
+ /**
+ * 执行计划
+ * @param addApplyPlanBO
+ * @return
+ */
+ boolean execPlan() throws IllegalAccessException;
+
+ /**
+ * 创建计划
+ * @param addApplyPlanBO
+ * @return
+ */
+ boolean save(AddApplyPlanBO addApplyPlanBO);
+
+ /**
+ * 修改计划
+ * @param addApplyPlanBO
+ * @return
+ */
+ boolean update(AddApplyPlanBO addApplyPlanBO);
+ /**
+ * 查询应用执行计划管理列表
+ *
+ * @param applyPlan 应用执行计划管理
+ * @return 应用执行计划管理集合
+ */
+ List list(ApplyPlan applyPlan);
+
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java
index 1742379..6f169a8 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java
@@ -4,6 +4,11 @@ import java.util.List;
import com.ruoyi.business.domain.Apply;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.business.domain.Rebot;
+import com.ruoyi.business.domain.bo.ApplyStartBO;
+import com.ruoyi.business.domain.bo.JobQueryBO;
+import com.ruoyi.business.domain.vo.JobQueryVO;
+import com.ruoyi.business.domain.vo.JobStartVO;
+import com.ruoyi.common.annotation.DataScope;
/**
* 应用信息管理Service接口
@@ -14,10 +19,20 @@ import com.ruoyi.business.domain.Rebot;
public interface IApplyService extends IService
{
/**
- * 同步机器人数据
+ * 启动应用
* @return
*/
- void syn(Apply apply);
+ JobStartVO appStart(ApplyStartBO applyStartBO) throws IllegalAccessException;
+ /**
+ * 查询应用运行结果
+ * @return
+ */
+ JobQueryVO queryAppStartResult(JobQueryBO jobQueryBO) throws IllegalAccessException;
+ /**
+ * 同步应用数据
+ * @return
+ */
+ void syn(Apply apply) throws IllegalAccessException;
/**
* 查询应用信息管理列表
*
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IRebotService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IRebotService.java
index 716df27..a1d5299 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IRebotService.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IRebotService.java
@@ -17,7 +17,7 @@ public interface IRebotService extends IService
* 同步机器人数据
* @return
*/
- void syn(Rebot rebot);
+ void syn(Rebot rebot) throws IllegalAccessException;
/**
* 查询机器人管理列表
*
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanLogServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanLogServiceImpl.java
new file mode 100644
index 0000000..7f622e2
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanLogServiceImpl.java
@@ -0,0 +1,34 @@
+package com.ruoyi.business.service.impl;
+
+import java.util.List;
+import com.ruoyi.common.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.business.mapper.ApplyPlanLogMapper;
+import com.ruoyi.business.domain.ApplyPlanLog;
+import com.ruoyi.business.service.IApplyPlanLogService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 应用执行结果记录管理Service业务层处理
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+@Service
+public class ApplyPlanLogServiceImpl extends ServiceImpl implements IApplyPlanLogService
+{
+
+
+ /**
+ * 查询应用执行结果记录管理列表
+ *
+ * @param applyPlanLog 应用执行结果记录管理
+ * @return 应用执行结果记录管理
+ */
+ @Override
+ public List list(ApplyPlanLog applyPlanLog)
+ {
+ return baseMapper.selectApplyPlanLogList(applyPlanLog);
+ }
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java
new file mode 100644
index 0000000..2542dbd
--- /dev/null
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java
@@ -0,0 +1,139 @@
+package com.ruoyi.business.service.impl;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.ruoyi.business.domain.Apply;
+import com.ruoyi.business.domain.Rebot;
+import com.ruoyi.business.domain.bo.AddApplyPlanBO;
+import com.ruoyi.business.domain.bo.ApplyStartBO;
+import com.ruoyi.business.domain.bo.ListApplyBO;
+import com.ruoyi.business.domain.bo.ListRebotBO;
+import com.ruoyi.business.domain.vo.JobStartVO;
+import com.ruoyi.business.domain.vo.ListRebotVO;
+import com.ruoyi.business.service.IApplyService;
+import com.ruoyi.business.service.IRebotService;
+import com.ruoyi.business.util.YinDaoHttpUtils;
+import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.enums.ExcTypeStatus;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.business.mapper.ApplyPlanMapper;
+import com.ruoyi.business.domain.ApplyPlan;
+import com.ruoyi.business.service.IApplyPlanService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.transaction.annotation.Transactional;
+
+import static cn.hutool.json.XMLTokener.entity;
+
+/**
+ * 应用执行计划管理Service业务层处理
+ *
+ * @author LiuChengRan
+ * @date 2024-06-14
+ */
+@Service
+public class ApplyPlanServiceImpl extends ServiceImpl implements IApplyPlanService {
+ @Autowired
+ private IApplyService applyService;
+
+ @Autowired
+ private IRebotService rebotService;
+
+ /**
+ * 执行计划(针对立即执行的计划)
+ *
+ * @return
+ */
+ @Override
+ @Transactional
+ public boolean execPlan() throws IllegalAccessException {
+ ListRebotBO listRebotBO = new ListRebotBO();
+ listRebotBO.setStatus("idle");
+ listRebotBO.setPage(1);
+ listRebotBO.setSize(100);
+ // 只获取空闲的机器人
+ List listRebotVOS = YinDaoHttpUtils.listRebot(listRebotBO);
+ if (listRebotVOS.isEmpty()) {
+ log.error("暂无空闲机器人");
+ // 刷新机器人数据
+// rebotService.syn(new Rebot());
+ }
+ for (ListRebotVO listRebotVO : listRebotVOS) {
+ List list = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.ONE.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getPriority).list();
+ if (list.isEmpty()) {
+ log.debug("没有等待执行的计划");
+ break;
+ }
+ ApplyStartBO applyStartBO = new ApplyStartBO();
+ ApplyPlan applyPlan = list.get(0);
+ applyStartBO.setRobotUuid(applyPlan.getAppId());
+ applyStartBO.setAccountName(listRebotVO.getRobotClientName());
+ //high 高 middle 中 low 低
+ applyStartBO.setPriority("high");
+ JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO);
+ ApplyPlan updateApplyPlan = new ApplyPlan();
+ updateApplyPlan.setId(applyPlan.getId());
+ updateApplyPlan.setUpdateBy("-1");
+ updateApplyPlan.setUpdateTime(new Date());
+ updateApplyPlan.setTaskUuid(jobStartVO.getJobUuid());
+ this.updateById(updateApplyPlan);
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean save(AddApplyPlanBO addApplyPlanBO) {
+ List applyPlanList = new ArrayList<>();
+ Map> appMap = applyService.lambdaQuery().in(Apply::getAppId, addApplyPlanBO.getAppId()).list().stream().collect(Collectors.groupingBy(Apply::getAppId));
+ addApplyPlanBO.getAppId().forEach(e -> {
+ ApplyPlan applyPlan = new ApplyPlan();
+ BeanUtils.copyBeanProp(applyPlan, addApplyPlanBO);
+ Apply apply = appMap.get(e).get(0);
+ applyPlan.setAppName(apply.getAppName());
+ applyPlan.setAppId(apply.getAppId());
+ applyPlan.setAppType(apply.getAppType());
+ applyPlan.setAppTypeName(apply.getAppTypeName());
+ applyPlanList.add(applyPlan);
+ });
+
+ return super.saveBatch(applyPlanList);
+ }
+
+ @Override
+ public boolean update(AddApplyPlanBO addApplyPlanBO) {
+ List applyPlanList = new ArrayList<>();
+ Map> appMap = applyService.lambdaQuery().in(Apply::getAppId, addApplyPlanBO.getAppId()).eq(Apply::getDeptId, SecurityUtils.getDeptId()).list().stream().collect(Collectors.groupingBy(Apply::getAppId));
+ addApplyPlanBO.getAppId().forEach(e -> {
+ ApplyPlan applyPlan = new ApplyPlan();
+ BeanUtils.copyBeanProp(applyPlan, addApplyPlanBO);
+ Apply apply = appMap.get(e).get(0);
+ applyPlan.setAppName(apply.getAppName());
+ applyPlan.setAppId(apply.getAppId());
+ applyPlan.setAppType(apply.getAppType());
+ applyPlan.setAppTypeName(apply.getAppTypeName());
+ applyPlanList.add(applyPlan);
+ });
+
+ return super.updateBatchById(applyPlanList);
+ }
+
+ /**
+ * 查询应用执行计划管理列表
+ *
+ * @param applyPlan 应用执行计划管理
+ * @return 应用执行计划管理
+ */
+ @Override
+ @DataScope(deptAlias = "d")
+ public List list(ApplyPlan applyPlan) {
+ return baseMapper.selectApplyPlanList(applyPlan);
+ }
+}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java
index 73e1c5a..24c93d1 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java
@@ -6,15 +6,21 @@ import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.business.domain.Rebot;
+import com.ruoyi.business.domain.bo.ApplyStartBO;
+import com.ruoyi.business.domain.bo.JobQueryBO;
import com.ruoyi.business.domain.bo.ListApplyBO;
import com.ruoyi.business.domain.bo.ListRebotBO;
+import com.ruoyi.business.domain.vo.JobQueryVO;
+import com.ruoyi.business.domain.vo.JobStartVO;
import com.ruoyi.business.domain.vo.ListApplyVO;
import com.ruoyi.business.domain.vo.ListRebotVO;
import com.ruoyi.business.util.YinDaoHttpUtils;
import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ApplyMapper;
@@ -25,13 +31,37 @@ import org.springframework.transaction.annotation.Transactional;
/**
* 应用信息管理Service业务层处理
- *
+ *
* @author LiuChengRan
* @date 2024-06-13
*/
@Service
-public class ApplyServiceImpl extends ServiceImpl implements IApplyService
-{
+public class ApplyServiceImpl extends ServiceImpl implements IApplyService {
+
+ @Autowired
+ private ISysDeptService sysDeptService;
+ /**
+ * 启动应用
+ *
+ * @param applyStartBO
+ */
+ @Override
+ @Transactional
+ public JobStartVO appStart(ApplyStartBO applyStartBO) throws IllegalAccessException {
+ JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO);
+ return jobStartVO;
+ }
+
+ /**
+ * 查询应用运行结果
+ *
+ * @param jobQueryBO
+ */
+ @Override
+ public JobQueryVO queryAppStartResult(JobQueryBO jobQueryBO) throws IllegalAccessException {
+ JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO);
+ return jobQueryVO;
+ }
/**
@@ -40,50 +70,64 @@ public class ApplyServiceImpl extends ServiceImpl implements
* @return
*/
@Override
- @DataScope(deptAlias = "d", userAlias = "u")
+ @DataScope(deptAlias = "apply")
@Transactional
- public void syn(Apply entity) {
+ public void syn(Apply entity) throws IllegalAccessException {
ListApplyBO listApplyBO = new ListApplyBO();
listApplyBO.setPage(1);
- listApplyBO.setSize(10000);
+ // 影刀最大限制
+ listApplyBO.setSize(100);
List applyList = baseMapper.selectApplyList(new Apply());
Map> applyMap = applyList.stream().collect(Collectors.groupingBy(Apply::getAppId));
List listApplyVOList = YinDaoHttpUtils.listApp(listApplyBO);
// 获取客户端名称集合
List appIdList = listApplyVOList.stream().map(ListApplyVO::getAppId).collect(Collectors.toList());
+ // 只能移除当前用户部门的
this.remove(new LambdaUpdateWrapper().notIn(Apply::getAppId, appIdList).eq(Apply::getDeptId, SecurityUtils.getDeptId()));
+
+ Map> deptMap = sysDeptService.selectDeptAllList(new SysDept()).stream().collect(Collectors.groupingBy(SysDept::getDeptName));
listApplyVOList.forEach(listRebotVO -> {
// 数据库里是否存在
List applys = applyMap.get(listRebotVO.getAppId());
+ String[] deptName = listRebotVO.getAppName().split("-");
+ List sysDepts = deptMap.get(deptName[0]);
+
if (null == applys) {
Apply newApply = new Apply();
BeanUtils.copyBeanProp(newApply, listRebotVO);
- newApply.setAppCreateTime(listRebotVO.getAppCreateTime());
- newApply.setAppUpdateTime(listRebotVO.getAppUpdateTime());
- newApply.setDeptId(SecurityUtils.getDeptId());
+ newApply.setAppCreateTime(listRebotVO.getCreateTime());
+ newApply.setAppUpdateTime(listRebotVO.getUpdateTime());
+ if(null != sysDepts){
+ newApply.setDeptId(sysDepts.get(0).getDeptId());
+ newApply.setDeptName(sysDepts.get(0).getDeptName());
+ }
save(newApply);
} else {
Apply apply = applys.get(0);
- Apply newApply =new Apply();
+ Apply newApply = new Apply();
BeanUtils.copyBeanProp(newApply, listRebotVO);
- newApply.setAppCreateTime(listRebotVO.getAppCreateTime());
- newApply.setAppUpdateTime(listRebotVO.getAppUpdateTime());
+ newApply.setAppCreateTime(listRebotVO.getCreateTime());
+ newApply.setAppUpdateTime(listRebotVO.getUpdateTime());
newApply.setId(apply.getId());
- newApply.setDeptId(SecurityUtils.getDeptId());
+ if(null != sysDepts){
+ newApply.setDeptId(sysDepts.get(0).getDeptId());
+ newApply.setDeptName(sysDepts.get(0).getDeptName());
+ }
updateById(newApply);
}
});
}
+
/**
* 查询应用信息管理列表
- *
+ *
* @param apply 应用信息管理
* @return 应用信息管理
*/
@Override
- public List list(Apply apply)
- {
+ @DataScope(deptAlias = "apply")
+ public List list(Apply apply) {
return baseMapper.selectApplyList(apply);
}
}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/RebotServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/RebotServiceImpl.java
index 5909100..e43e6ac 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/RebotServiceImpl.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/RebotServiceImpl.java
@@ -9,7 +9,10 @@ import com.ruoyi.business.domain.bo.ListRebotBO;
import com.ruoyi.business.domain.vo.ListRebotVO;
import com.ruoyi.business.util.YinDaoHttpUtils;
import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.service.ISysDeptService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.RebotMapper;
import com.ruoyi.business.domain.Rebot;
@@ -25,27 +28,26 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Service
public class RebotServiceImpl extends ServiceImpl implements IRebotService {
-
-
/**
* 同步机器人数据
*
* @return
*/
@Override
- @DataScope(deptAlias = "d", userAlias = "u")
@Transactional
- public void syn(Rebot entity) {
+ public void syn(Rebot entity) throws IllegalAccessException {
ListRebotBO listRebotBO = new ListRebotBO();
listRebotBO.setPage(1);
- listRebotBO.setSize(10000);
+ listRebotBO.setSize(100);
List rebotsList = baseMapper.selectRebotList(new Rebot());
Map> rebotMap = rebotsList.stream().collect(Collectors.groupingBy(Rebot::getRobotClientName));
List listRebotVoList = YinDaoHttpUtils.listRebot(listRebotBO);
// 获取客户端名称集合
List clientNameList = listRebotVoList.stream().map(ListRebotVO::getRobotClientName).collect(Collectors.toList());
- this.remove(new LambdaUpdateWrapper().notIn(Rebot::getRobotClientName, clientNameList).eq(Rebot::getDeptId, SecurityUtils.getDeptId()));
+ // 删除不存在的机器人
+ this.remove(new LambdaUpdateWrapper().notIn(Rebot::getRobotClientName, clientNameList));
+
listRebotVoList.forEach(listRebotVO -> {
// 数据库里是否存在
List rebots = rebotMap.get(listRebotVO.getRobotClientName());
@@ -56,7 +58,6 @@ public class RebotServiceImpl extends ServiceImpl implements
rebot.setRobotClientName(listRebotVO.getRobotClientName());
rebot.setWindowsAccount(listRebotVO.getWindowsAccount());
rebot.setClientIp(listRebotVO.getClientIp());
- rebot.setDeptId(SecurityUtils.getDeptId());
save(rebot);
} else {
Rebot rebot = rebots.get(0);
@@ -65,7 +66,6 @@ public class RebotServiceImpl extends ServiceImpl implements
rebot.setRobotClientName(listRebotVO.getRobotClientName());
rebot.setWindowsAccount(listRebotVO.getWindowsAccount());
rebot.setClientIp(listRebotVO.getClientIp());
- rebot.setDeptId(SecurityUtils.getDeptId());
updateById(rebot);
}
});
@@ -78,6 +78,7 @@ public class RebotServiceImpl extends ServiceImpl implements
* @return 机器人管理
*/
@Override
+ @DataScope(deptAlias = "d", userAlias = "u")
public List list(Rebot rebot) {
return baseMapper.selectRebotList(rebot);
}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java b/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java
index b450c37..7ddca8b 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java
@@ -2,17 +2,23 @@ package com.ruoyi.business.util;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
+import com.ruoyi.business.domain.bo.ApplyStartBO;
+import com.ruoyi.business.domain.bo.JobQueryBO;
import com.ruoyi.business.domain.bo.ListApplyBO;
import com.ruoyi.business.domain.bo.ListRebotBO;
+import com.ruoyi.business.domain.vo.JobQueryVO;
+import com.ruoyi.business.domain.vo.JobStartVO;
import com.ruoyi.business.domain.vo.ListApplyVO;
import com.ruoyi.business.domain.vo.ListRebotVO;
import com.ruoyi.business.yddoman.BaseDTO;
import com.ruoyi.business.yddoman.CreateTokenDTO;
import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.BeanToMapUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,31 +40,81 @@ public class YinDaoHttpUtils {
private static final String CLIENT_LIST = REQUEST_PREFIX + "/dispatch/v2/client/list";
// 查询应用列表
private static final String APP_LIST = REQUEST_PREFIX + "/app/open/query/list";
+ // 启动应用
+ private static final String APP_START = REQUEST_PREFIX + "/dispatch/v2/job/start";
+ // 启动应用
+ private static final String QUERY_APP_START_RESULT = REQUEST_PREFIX + "/dispatch/v2/job/query";
/**
- * 查询机器人列表
+ * 启动应用
+ */
+ public static JobStartVO appStart(ApplyStartBO applyStartBO) throws IllegalAccessException {
+ // 实体类转map
+ Map data = BeanToMapUtil.convertEntityToMap(applyStartBO);
+ BaseDTO baseDTO = sendPost(APP_START, data);
+ return JSON.parseObject(baseDTO.getData().toString(), JobStartVO.class);
+ }
+
+ /**
+ * 查询应用运行结果
+ */
+ public static JobQueryVO queryAppStartResult(JobQueryBO jobQueryBO) throws IllegalAccessException {
+ // 实体类转map
+ Map data = BeanToMapUtil.convertEntityToMap(jobQueryBO);
+ BaseDTO baseDTO = sendPost(QUERY_APP_START_RESULT, data);
+ return JSON.parseObject(baseDTO.getData().toString(), JobQueryVO.class);
+ }
+
+ /**
+ * 查询应用列表
*/
- public static List listApp(ListApplyBO ListApplyBO) {
- Map data = new HashMap<>();
- data.put("page", ListApplyBO.getPage().toString());
- data.put("size", ListApplyBO.getSize().toString());
+ public static List listApp(ListApplyBO ListApplyBO) throws IllegalAccessException {
+ Map data = BeanToMapUtil.convertEntityToMap(ListApplyBO);
BaseDTO baseDTO = sendPost(APP_LIST, data);
- return JSON.parseArray(baseDTO.getData().toString(), ListApplyVO.class);
+ BaseDTO.Page page = baseDTO.getPage();
+ List allList = new ArrayList<>();
+ boolean isNext = true;
+ while (isNext) {
+ List ListApplyVos = JSON.parseArray(baseDTO.getData().toString(), ListApplyVO.class);
+ allList.addAll(ListApplyVos);
+ data = new HashMap<>();
+ data.put("page", page.getPage() + 1);
+ data.put("size", ListApplyBO.getSize());
+ if (page.getPage() + 1 > page.getPages()) {
+ isNext = false;
+ } else {
+ baseDTO = sendGet(APP_LIST, data);
+ page = baseDTO.getPage();
+ }
+ }
+ return allList;
}
/**
* 查询机器人列表
*/
- public static List listRebot(ListRebotBO listRebotBO) {
- Map data = new HashMap<>();
- data.put("page", listRebotBO.getPage().toString());
- data.put("size", listRebotBO.getSize().toString());
-// data.put("status", listRebotBO.getStatus());
-// data.put("key", listRebotBO.getKey());
-// data.put("robotClientUuid", "176befff-0dc4-4df1-badf-346305c28ae8");
+ public static List listRebot(ListRebotBO listRebotBO) throws IllegalAccessException {
+ Map data = BeanToMapUtil.convertEntityToMap(listRebotBO);
BaseDTO baseDTO = sendGet(CLIENT_LIST, data);
- return JSON.parseArray(baseDTO.getData().toString(), ListRebotVO.class);
+ BaseDTO.Page page = baseDTO.getPage();
+ List allList = new ArrayList<>();
+ boolean isNext = true;
+ while (isNext) {
+ List listRebotVOS = JSON.parseArray(baseDTO.getData().toString(), ListRebotVO.class);
+ allList.addAll(listRebotVOS);
+ data = new HashMap<>();
+ data.put("page", page.getPage() + 1 + "");
+ data.put("size", listRebotBO.getSize().toString());
+ if (page.getPage() + 1 > page.getPages()) {
+ isNext = false;
+ } else {
+ baseDTO = sendGet(CLIENT_LIST, data);
+ page = baseDTO.getPage();
+ }
+
+ }
+ return allList;
}
diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/yddoman/BaseDTO.java b/ruoyi-business/src/main/java/com/ruoyi/business/yddoman/BaseDTO.java
index 82110ba..e18efb9 100644
--- a/ruoyi-business/src/main/java/com/ruoyi/business/yddoman/BaseDTO.java
+++ b/ruoyi-business/src/main/java/com/ruoyi/business/yddoman/BaseDTO.java
@@ -4,16 +4,25 @@ import lombok.Data;
/**
* 影刀统一响应父类
- *
+ *
* @author #author#
*/
@Data
-public class BaseDTO
-{
+public class BaseDTO {
private Integer code;
private Boolean success;
private String msg;
private Object data;
+ private Page page;
+ @Data
+ public static class Page {
+ private Integer page;
+ private Integer total;
+ private Integer size;
+ private Integer pages;
+ private Integer offset;
+ private String order;
+ }
}
diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml
index 0a2cacb..165e5f8 100644
--- a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml
+++ b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml
@@ -33,6 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+
+
+
@@ -49,30 +53,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
- id,
- owner_name,
- owner_account,
- owner_id,
- app_id,
- app_name,
- app_type_name,
- app_type,
- app_create_time,
- app_update_time,
- version,
- support_param,
- icon,
- manual_time,
- create_by,
- create_time,
- update_by,
- update_time,
- remark,
- deleted
+ apply.id,
+ apply.owner_name,
+ apply.owner_account,
+ apply.owner_id,
+ apply.app_id,
+ apply.app_name,
+ apply.app_type_name,
+ apply.app_type,
+ apply.app_create_time,
+ apply.app_update_time,
+ apply.version,
+ apply.support_param,
+ apply.icon,
+ apply.manual_time,
+ apply.dept_id,
+ apply.dept_name,
+ apply.create_by,
+ apply.create_time,
+ apply.update_by,
+ apply.update_time,
+ apply.remark,
+ apply.deleted
+
\ No newline at end of file
diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml
new file mode 100644
index 0000000..1701b2c
--- /dev/null
+++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ select
+ id,
+ job_uuid,
+ plan_name,
+ plan_type,
+ robot_name,
+ app_type_name,
+ app_name,
+ app_id,
+ status,
+ status_name,
+ start_time,
+ end_time,
+ manual_time,
+ plan_time,
+ time_saving,
+ create_by,
+ create_time,
+ update_by,
+ update_time,
+ remark,
+ deleted
+
+
+
\ No newline at end of file
diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml
new file mode 100644
index 0000000..fba1a5a
--- /dev/null
+++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ select
+ plan.id,
+ plan.plan_name,
+ plan.plan_type,
+ plan.robot_name,
+ plan.app_type_name,
+ plan.app_name,
+ plan.app_id,
+ plan.app_type,
+ plan.manual_time,
+ plan.plan_params,
+ plan.wait_timeout,
+ plan.priority,
+ plan.exc_type,
+ plan.exc_time,
+ plan.cron_expression,
+ plan.task_uuid,
+ plan.create_by,
+ plan.create_time,
+ plan.update_by,
+ plan.update_time,
+ plan.remark,
+ plan.deleted
+
+
+
+
\ No newline at end of file
diff --git a/ruoyi-business/src/main/resources/mapper/business/RebotMapper.xml b/ruoyi-business/src/main/resources/mapper/business/RebotMapper.xml
index 98501f1..d7d95db 100644
--- a/ruoyi-business/src/main/resources/mapper/business/RebotMapper.xml
+++ b/ruoyi-business/src/main/resources/mapper/business/RebotMapper.xml
@@ -57,19 +57,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
\ No newline at end of file
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/ExcTypeStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ExcTypeStatus.java
new file mode 100644
index 0000000..a2a7e75
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ExcTypeStatus.java
@@ -0,0 +1,35 @@
+package com.ruoyi.common.enums;
+
+/**
+ * 机器人状态枚举
+ */
+
+public enum ExcTypeStatus {
+ ONE("0", "立即执行"),
+ TWO("1", "指定时间执行"),
+ TREE("2", "周期执行");
+
+ private String key;
+ private String value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ ExcTypeStatus(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/RebotStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/RebotStatus.java
new file mode 100644
index 0000000..76e8ef8
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/RebotStatus.java
@@ -0,0 +1,39 @@
+package com.ruoyi.common.enums;
+
+import lombok.Data;
+
+/**
+ * 机器人状态枚举
+ */
+
+public enum RebotStatus {
+ CONNECTED("connected", "已连接"),
+ IDLE("idle", "空闲"),
+ ALLOCATED("allocated", "已分配"),
+ RUNNING("running", "运行中"),
+ OFFLINE("offline", "离线");
+
+ private String key;
+ private String value;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ RebotStatus(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanToMapUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanToMapUtil.java
new file mode 100644
index 0000000..d7ebe37
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/BeanToMapUtil.java
@@ -0,0 +1,30 @@
+package com.ruoyi.common.utils;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 实体类转map
+ */
+public class BeanToMapUtil {
+ public static Map convertEntityToMap(T entity) throws IllegalAccessException {
+ Map map = new HashMap<>();
+ // 获取对象的类
+ Class> clazz = entity.getClass();
+ // 获取类中的所有字段
+ Field[] fields = clazz.getDeclaredFields();
+ // 遍历字段,将字段名和值存入Map
+ for (Field field : fields) {
+ // 设置字段可访问(非public字段需要设置访问权限)
+ field.setAccessible(true);
+ // 获取字段名
+ String fieldName = field.getName();
+ // 获取字段值
+ Object fieldValue = field.get(entity);
+ // 将字段名和值存入Map
+ map.put(fieldName, fieldValue);
+ }
+ return map;
+ }
+}
diff --git a/ruoyi-quartz/pom.xml b/ruoyi-quartz/pom.xml
index 1922bcf..5084016 100644
--- a/ruoyi-quartz/pom.xml
+++ b/ruoyi-quartz/pom.xml
@@ -35,6 +35,12 @@
ruoyi-common