|
|
@@ -4,6 +4,8 @@ import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON; |
|
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
|
import com.ruoyi.business.domain.Apply; |
|
|
|
import com.ruoyi.business.domain.Rebot; |
|
|
|
import com.ruoyi.business.domain.bo.*; |
|
|
@@ -18,6 +20,7 @@ import com.ruoyi.common.enums.ExcTypeStatus; |
|
|
|
import com.ruoyi.common.enums.PlanRunStatus; |
|
|
|
import com.ruoyi.common.enums.RebotStatus; |
|
|
|
import com.ruoyi.common.utils.SecurityUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@@ -41,6 +44,66 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
@Autowired |
|
|
|
private IRebotService rebotService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 指定时间执行 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public boolean runAppBySetTime() throws IllegalAccessException { |
|
|
|
ListRebotBO listRebotBO = new ListRebotBO(); |
|
|
|
listRebotBO.setStatus(RebotStatus.IDLE.getKey()); |
|
|
|
listRebotBO.setPage(1); |
|
|
|
listRebotBO.setSize(100); |
|
|
|
// 只获取空闲的机器人 |
|
|
|
List<ListRebotVO> listRebotVos = YinDaoHttpUtils.listRebot(listRebotBO); |
|
|
|
if (listRebotVos.isEmpty()) { |
|
|
|
log.error("暂无空闲机器人"); |
|
|
|
// 刷新机器人数据 |
|
|
|
// rebotService.syn(new Rebot()); |
|
|
|
return false; |
|
|
|
} |
|
|
|
List<ApplyPlan> applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime).list(); |
|
|
|
listRebotVos.forEach(rebot -> { |
|
|
|
applyPlanList.forEach(e -> { |
|
|
|
if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { |
|
|
|
ApplyStartBO applyStartBO = new ApplyStartBO(); |
|
|
|
applyStartBO.setRobotUuid(e.getAppId()); |
|
|
|
applyStartBO.setAccountName(rebot.getRobotClientName()); |
|
|
|
applyStartBO.setManualTime(e.getManualTime()); |
|
|
|
//high 高 middle 中 low 低 |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
String planParams = e.getPlanParams(); |
|
|
|
if(StringUtils.isNotEmpty(planParams)){ |
|
|
|
JSONArray jsonArray = JSON.parseArray(planParams); |
|
|
|
// 直接转换成List |
|
|
|
List<ApplyStartBO.RobotParam> list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); |
|
|
|
applyStartBO.setPlanParamsList(list); |
|
|
|
} |
|
|
|
try { |
|
|
|
JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); |
|
|
|
ApplyPlan applyPlan = new ApplyPlan(); |
|
|
|
applyPlan.setId(e.getId()); |
|
|
|
applyPlan.setUpdateBy("-1"); |
|
|
|
applyPlan.setUpdateTime(new Date()); |
|
|
|
applyPlan.setTaskUuid(jobStartVO.getJobUuid()); |
|
|
|
applyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); |
|
|
|
this.updateById(applyPlan); |
|
|
|
Rebot updateRebot = new Rebot(); |
|
|
|
updateRebot.setStatus(RebotStatus.RUNNING.getKey()); |
|
|
|
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot); |
|
|
|
} catch (IllegalAccessException ex) { |
|
|
|
throw new RuntimeException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取应用执行结果 |
|
|
|
* |
|
|
@@ -166,6 +229,13 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
applyStartBO.setAccountName(listRebotVO.getRobotClientName()); |
|
|
|
//high 高 middle 中 low 低 |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
String planParams = applyPlan.getPlanParams(); |
|
|
|
if(StringUtils.isNotEmpty(planParams)){ |
|
|
|
JSONArray jsonArray = JSON.parseArray(planParams); |
|
|
|
// 直接转换成List |
|
|
|
List<ApplyStartBO.RobotParam> list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); |
|
|
|
applyStartBO.setPlanParamsList(list); |
|
|
|
} |
|
|
|
JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); |
|
|
|
|
|
|
|
ApplyPlan updateApplyPlan = new ApplyPlan(); |
|
|
@@ -182,11 +252,11 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
if (this.saveOrUpdate(updateApplyPlan)) { |
|
|
|
i++; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return i > 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public boolean save(AddApplyPlanBO addApplyPlanBO) { |
|
|
@@ -204,6 +274,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
applyPlan.setAppType(apply.getAppType()); |
|
|
|
applyPlan.setAppTypeName(apply.getAppTypeName()); |
|
|
|
applyPlan.setManualTime(apply.getManualTime()); |
|
|
|
if(addApplyPlanBO.getSupportParam() == 1){ |
|
|
|
applyPlan.setPlanParams(apply.getParam()); |
|
|
|
} |
|
|
|
applyPlan.setManualTime(apply.getParam()); |
|
|
|
applyPlan.setDeptId(SecurityUtils.getDeptId()); |
|
|
|
|
|
|
|
// try { |
|
|
|