@@ -43,7 +43,7 @@ user: | |||||
# 密码最大错误次数 | # 密码最大错误次数 | ||||
maxRetryCount: 5 | maxRetryCount: 5 | ||||
# 密码锁定时间(默认10分钟) | # 密码锁定时间(默认10分钟) | ||||
lockTime: 10 | |||||
lockTime: 5 | |||||
# Spring配置 | # Spring配置 | ||||
spring: | spring: | ||||
@@ -1,10 +1,19 @@ | |||||
package com.ruoyi.business.controller; | package com.ruoyi.business.controller; | ||||
import java.util.ArrayList; | |||||
import java.util.List; | import java.util.List; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.stream.Collectors; | |||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; | |||||
import com.ruoyi.business.domain.ApplyPlan; | |||||
import com.ruoyi.business.domain.ApplyPlanLog; | |||||
import com.ruoyi.business.domain.Rebot; | import com.ruoyi.business.domain.Rebot; | ||||
import com.ruoyi.business.domain.vo.ListApplyVO; | |||||
import com.ruoyi.business.service.IApplyPlanLogService; | |||||
import com.ruoyi.business.service.IApplyPlanService; | |||||
import com.ruoyi.common.enums.PlanRunStatus; | |||||
import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
@@ -41,6 +50,22 @@ public class ApplyController extends BaseController { | |||||
@Autowired | @Autowired | ||||
private IApplyService applyService; | private IApplyService applyService; | ||||
@Autowired | |||||
private IApplyPlanService applyPlanService; | |||||
@Autowired | |||||
private IApplyPlanLogService applyPlanLogService; | |||||
/** | |||||
* 同步应用数据 | |||||
*/ | |||||
@ApiOperation(value = "修改应用实际执行时间", httpMethod = "POST", response = Rebot.class) | |||||
@PostMapping("/updateRunDate") | |||||
public AjaxResult updateRunDate(@RequestBody Apply apply) throws IllegalAccessException { | |||||
return toAjax(applyService.updateRunDate(apply)); | |||||
} | |||||
/** | /** | ||||
* 同步应用数据 | * 同步应用数据 | ||||
*/ | */ | ||||
@@ -68,8 +93,24 @@ public class ApplyController extends BaseController { | |||||
@ApiOperation(value = "查询应用信息管理列表", httpMethod = "GET", response = Apply.class) | @ApiOperation(value = "查询应用信息管理列表", httpMethod = "GET", response = Apply.class) | ||||
@GetMapping("/list") | @GetMapping("/list") | ||||
public TableDataInfo list(Apply apply) { | public TableDataInfo list(Apply apply) { | ||||
// 获取所有计划 | |||||
List<ApplyPlan> planList = applyPlanService.lambdaQuery().isNotNull(ApplyPlan::getManualTime) | |||||
.and(e -> e.in(ApplyPlan::getExcType, "0", "1") | |||||
.eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).or().eq(ApplyPlan::getExcType, "2")) | |||||
.list(); | |||||
// 只过滤执行计划的id | |||||
List<String> planIdList = planList.stream().filter(e -> "2".equals(e.getExcType())).map(ApplyPlan::getId).collect(Collectors.toList()); | |||||
// 获取所有 设置了时间并且是完成状态的计划记录 | |||||
LambdaQueryChainWrapper<ApplyPlanLog> qw = applyPlanLogService.lambdaQuery(); | |||||
List<ApplyPlanLog> planLogList = null; | |||||
if (planIdList.isEmpty()) { | |||||
planLogList = new ArrayList<>(); | |||||
} else { | |||||
planLogList = qw.in(ApplyPlanLog::getPlanId, planIdList).isNotNull(ApplyPlanLog::getUpdateTime).list(); | |||||
} | |||||
startPage(); | startPage(); | ||||
List<Apply> list = applyService.list(apply); | |||||
List<ListApplyVO> list = applyService.list(planList, planLogList, apply); | |||||
return getDataTable(list); | return getDataTable(list); | ||||
} | } | ||||
@@ -80,8 +121,12 @@ public class ApplyController extends BaseController { | |||||
@Log(title = "应用信息管理", businessType = BusinessType.EXPORT) | @Log(title = "应用信息管理", businessType = BusinessType.EXPORT) | ||||
@PostMapping("/export") | @PostMapping("/export") | ||||
public void export(HttpServletResponse response, Apply apply) { | public void export(HttpServletResponse response, Apply apply) { | ||||
List<Apply> list = applyService.list(apply); | |||||
ExcelUtil<Apply> util = new ExcelUtil<Apply>(Apply.class); | |||||
// 获取所有执行成功的计划 | |||||
List<ApplyPlan> planList = applyPlanService.lambdaQuery().eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).list(); | |||||
// 获取所有计划记录 | |||||
List<ApplyPlanLog> planLogList = applyPlanLogService.list(); | |||||
List<ListApplyVO> list = applyService.list(planList, planLogList, apply); | |||||
ExcelUtil<ListApplyVO> util = new ExcelUtil<ListApplyVO>(ListApplyVO.class); | |||||
util.exportExcel(response, list, "应用信息管理数据"); | util.exportExcel(response, list, "应用信息管理数据"); | ||||
} | } | ||||
@@ -1,5 +1,6 @@ | |||||
package com.ruoyi.business.controller; | package com.ruoyi.business.controller; | ||||
import java.text.ParseException; | |||||
import java.util.List; | import java.util.List; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
@@ -45,10 +46,7 @@ public class ApplyPlanController extends BaseController { | |||||
@PostMapping("/callBack/updatePlanStatus") | @PostMapping("/callBack/updatePlanStatus") | ||||
public void updatePlanStatus(@RequestParam(required = false) String bodyMd5, @RequestParam(required = false) Long timestamp, | public void updatePlanStatus(@RequestParam(required = false) String bodyMd5, @RequestParam(required = false) Long timestamp, | ||||
@RequestParam(required = false) String sign, @RequestBody String body) { | @RequestParam(required = false) String sign, @RequestBody String body) { | ||||
log.info("fake callback: bodyMd5:{}", bodyMd5); | |||||
log.info("fake callback: sign:{}", sign); | |||||
log.info("fake callback: timestamp:{}", timestamp); | |||||
log.info("fake callback: body:{}", body); | |||||
log.info("影刀回调成功:bodyMd5:{},sign:{},timestamp:{},body:{}", bodyMd5,sign,timestamp,body); | |||||
YinDaoCallBackBO yinDaoCallBackBO = JSONObject.parseObject(body, YinDaoCallBackBO.class); | YinDaoCallBackBO yinDaoCallBackBO = JSONObject.parseObject(body, YinDaoCallBackBO.class); | ||||
// 获取应用名称 task_uuid | // 获取应用名称 task_uuid | ||||
@@ -63,6 +61,24 @@ public class ApplyPlanController extends BaseController { | |||||
// } | // } | ||||
} | } | ||||
/** | |||||
* 修改运行时间 | |||||
*/ | |||||
@ApiOperation(value = "修改运行时间", httpMethod = "POST", response = ApplyPlan.class) | |||||
@PostMapping("/updateRunTime") | |||||
public AjaxResult updateRunTime(@RequestBody ApplyPlan applyPlan) throws ParseException { | |||||
return toAjax(applyPlanService.updateRunTime(applyPlan)); | |||||
} | |||||
/** | |||||
* 重新运行 | |||||
*/ | |||||
@ApiOperation(value = "启用或禁用", httpMethod = "POST", response = ApplyPlan.class) | |||||
@PostMapping("/stopOrStart") | |||||
public AjaxResult appRetry(@RequestBody ApplyPlan applyPlan) throws IllegalAccessException { | |||||
return toAjax(applyPlanService.updateById(applyPlan)); | |||||
} | |||||
/** | /** | ||||
* 重新运行 | * 重新运行 | ||||
*/ | */ | ||||
@@ -120,7 +136,7 @@ public class ApplyPlanController extends BaseController { | |||||
@ApiOperation(value = "新增应用执行计划管理", httpMethod = "POST") | @ApiOperation(value = "新增应用执行计划管理", httpMethod = "POST") | ||||
@Log(title = "应用执行计划管理", businessType = BusinessType.INSERT) | @Log(title = "应用执行计划管理", businessType = BusinessType.INSERT) | ||||
@PostMapping | @PostMapping | ||||
public AjaxResult add(@RequestBody AddApplyPlanBO addApplyPlanBO) { | |||||
public AjaxResult add(@RequestBody AddApplyPlanBO addApplyPlanBO) throws ParseException { | |||||
// 随机分配 | // 随机分配 | ||||
addApplyPlanBO.setPlanType("1"); | addApplyPlanBO.setPlanType("1"); | ||||
addApplyPlanBO.setWaitTimeout("10m"); | addApplyPlanBO.setWaitTimeout("10m"); | ||||
@@ -40,6 +40,19 @@ public class ApplyPlanLogController extends BaseController | |||||
@Autowired | @Autowired | ||||
private IApplyPlanLogService applyPlanLogService; | private IApplyPlanLogService applyPlanLogService; | ||||
/** | |||||
* 根据计划查询所有执行日志 | |||||
*/ | |||||
@ApiOperation(value="根据计划查询所有执行日志", httpMethod = "GET", response = ApplyPlanLog.class) | |||||
@GetMapping("/listAll") | |||||
public AjaxResult listAll(String planId) | |||||
{ | |||||
ApplyPlanLog applyPlanLog = new ApplyPlanLog(); | |||||
applyPlanLog.setPlanId(planId); | |||||
List<ApplyPlanLog> list = applyPlanLogService.list(applyPlanLog); | |||||
return AjaxResult.success(list); | |||||
} | |||||
/** | /** | ||||
* 查询应用执行结果记录管理列表 | * 查询应用执行结果记录管理列表 | ||||
*/ | */ | ||||
@@ -80,7 +80,6 @@ public class ResourceLibraryController extends BaseController { | |||||
List<ResourceLibrary> list = resourceLibraryService.list(resourceLibrary, null); | List<ResourceLibrary> list = resourceLibraryService.list(resourceLibrary, null); | ||||
return getDataTable(list); | return getDataTable(list); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
@@ -114,6 +113,16 @@ public class ResourceLibraryController extends BaseController { | |||||
return success(resourceLibraryService.getById(id)); | return success(resourceLibraryService.getById(id)); | ||||
} | } | ||||
/** | |||||
* 批量修改资源信息 | |||||
*/ | |||||
@ApiOperation(value = "批量修改资源信息", httpMethod = "POST") | |||||
@Log(title = "批量修改资源信息", businessType = BusinessType.INSERT) | |||||
@PostMapping("/updateBatch") | |||||
public AjaxResult updateBatch(@RequestBody AddBatchResourceLibraryBO addBatchResourceLibraryBO) { | |||||
return toAjax(resourceLibraryService.updateBatch(addBatchResourceLibraryBO)); | |||||
} | |||||
/** | /** | ||||
* 批量新增资源信息 | * 批量新增资源信息 | ||||
*/ | */ | ||||
@@ -179,6 +179,11 @@ public class ApplyPlan extends BaseEntity | |||||
@ApiModelProperty(name="deptName",value = "部门名称") | @ApiModelProperty(name="deptName",value = "部门名称") | ||||
private String deptName; | private String deptName; | ||||
/** 是否启用 */ | |||||
@Excel(name = "是否启用") | |||||
@ApiModelProperty(name="enabled",value = "是否启用(0启用 1禁用)") | |||||
private String enabled; | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
@@ -37,100 +37,32 @@ public class ApplyPlanLog extends BaseEntity | |||||
/** 启动的任务的uuid */ | |||||
@Excel(name = "启动的任务的uuid") | |||||
@ApiModelProperty(name="jobUuid",value = "启动的任务的uuid") | |||||
private String jobUuid; | |||||
/** 计划名称 */ | |||||
@Excel(name = "计划名称") | |||||
@ApiModelProperty(name="planName",value = "计划名称") | |||||
private String planName; | |||||
/** 执行类型(0指定机器人 1随机分配空闲) */ | |||||
@Excel(name = "执行类型", readConverterExp = "0=指定机器人,1=随机分配空闲") | |||||
@ApiModelProperty(name="planType",value = "执行类型") | |||||
private String planType; | |||||
/** 计划执行的机器人名称 */ | |||||
@Excel(name = "计划执行的机器人名称") | |||||
@ApiModelProperty(name="robotName",value = "计划执行的机器人名称") | |||||
private String robotName; | |||||
/** 应用类型名称 */ | |||||
@Excel(name = "应用类型名称") | |||||
@ApiModelProperty(name="appTypeName",value = "应用类型名称") | |||||
private String appTypeName; | |||||
/** 应用名称 */ | |||||
@Excel(name = "应用名称") | |||||
@ApiModelProperty(name="appName",value = "应用名称") | |||||
private String appName; | |||||
/** appid */ | |||||
@Excel(name = "appid") | |||||
@ApiModelProperty(name="appId",value = "appid") | |||||
/** 计划id */ | |||||
@Excel(name = "计划id") | |||||
@ApiModelProperty(name="planId",value = "计划id") | |||||
private String planId; | |||||
/** 所属应用id */ | |||||
@Excel(name = "所属应用id") | |||||
@ApiModelProperty(name="appId",value = "所属应用id") | |||||
private String appId; | private String appId; | ||||
/** 任务状态 */ | |||||
@Excel(name = "任务状态") | |||||
@ApiModelProperty(name="status",value = "任务状态") | |||||
private String status; | |||||
/** 任务状态名称 */ | |||||
@Excel(name = "任务状态名称") | |||||
@ApiModelProperty(name="statusName",value = "任务状态名称") | |||||
private String statusName; | |||||
/** 任务开始运行的时间 */ | |||||
@JsonFormat(pattern = "yyyy-MM-dd") | |||||
@Excel(name = "任务开始运行的时间", width = 30, dateFormat = "yyyy-MM-dd") | |||||
@ApiModelProperty(name="startTime",value = "任务开始运行的时间") | |||||
private Date startTime; | |||||
/** 任务结束运行的时间 */ | |||||
@JsonFormat(pattern = "yyyy-MM-dd") | |||||
@Excel(name = "任务结束运行的时间", width = 30, dateFormat = "yyyy-MM-dd") | |||||
@ApiModelProperty(name="endTime",value = "任务结束运行的时间") | |||||
private Date endTime; | |||||
/** 预计人工耗时 */ | |||||
@Excel(name = "预计人工耗时") | |||||
@ApiModelProperty(name="manualTime",value = "预计人工耗时") | |||||
private String manualTime; | |||||
/** 计划job_uuid */ | |||||
@Excel(name = "计划job_uuid") | |||||
@ApiModelProperty(name="jobUuid",value = "计划job_uuid") | |||||
private String jobUuid; | |||||
/** 实际耗时 */ | |||||
@Excel(name = "实际耗时") | |||||
@ApiModelProperty(name="planTime",value = "实际耗时") | |||||
private String planTime; | |||||
/** 节约时间 */ | |||||
@Excel(name = "节约时间") | |||||
@ApiModelProperty(name="timeSaving",value = "节约时间") | |||||
private String timeSaving; | |||||
/** 输出内容 */ | |||||
@Excel(name = "输出内容") | |||||
@ApiModelProperty(name="outParam",value = "输出内容") | |||||
private String outParam; | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||||
.append("id", getId()) | .append("id", getId()) | ||||
.append("jobUuid", getJobUuid()) | |||||
.append("planName", getPlanName()) | |||||
.append("planType", getPlanType()) | |||||
.append("robotName", getRobotName()) | |||||
.append("appTypeName", getAppTypeName()) | |||||
.append("appName", getAppName()) | |||||
.append("appId", getAppId()) | |||||
.append("status", getStatus()) | |||||
.append("statusName", getStatusName()) | |||||
.append("startTime", getStartTime()) | |||||
.append("endTime", getEndTime()) | |||||
.append("manualTime", getManualTime()) | |||||
.append("planTime", getPlanTime()) | |||||
.append("timeSaving", getTimeSaving()) | |||||
.append("createBy", getCreateBy()) | .append("createBy", getCreateBy()) | ||||
.append("createTime", getCreateTime()) | .append("createTime", getCreateTime()) | ||||
.append("updateBy", getUpdateBy()) | .append("updateBy", getUpdateBy()) | ||||
@@ -84,10 +84,20 @@ public class ListApplyVO extends BaseEntity | |||||
@Excel(name = "预计人工耗时") | @Excel(name = "预计人工耗时") | ||||
@ApiModelProperty(name="manualTime",value = "预计人工耗时") | @ApiModelProperty(name="manualTime",value = "预计人工耗时") | ||||
private String manualTime; | private String manualTime; | ||||
/** 总计节约时间 */ | |||||
@Excel(name = "总计节约时间") | |||||
@ApiModelProperty(name="timeSaving",value = "总计节约时间") | |||||
private String timeSaving; | |||||
/** 所属公司 */ | /** 所属公司 */ | ||||
@Excel(name = "所属公司") | @Excel(name = "所属公司") | ||||
@ApiModelProperty(name="deptId",value = "所属公司") | @ApiModelProperty(name="deptId",value = "所属公司") | ||||
private Long deptId; | private Long deptId; | ||||
/** 部门名称 */ | |||||
@Excel(name = "部门名称") | |||||
@ApiModelProperty(name="deptName",value = "部门名称") | |||||
private String deptName; | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||||
@@ -3,6 +3,7 @@ package com.ruoyi.business.mapper; | |||||
import java.util.List; | import java.util.List; | ||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
import com.ruoyi.business.domain.Apply; | import com.ruoyi.business.domain.Apply; | ||||
import com.ruoyi.business.domain.vo.ListApplyVO; | |||||
/** | /** | ||||
* 应用信息管理Mapper接口 | * 应用信息管理Mapper接口 | ||||
@@ -19,7 +20,7 @@ public interface ApplyMapper extends BaseMapper<Apply> | |||||
* @param apply 应用信息管理 | * @param apply 应用信息管理 | ||||
* @return 应用信息管理集合 | * @return 应用信息管理集合 | ||||
*/ | */ | ||||
List<Apply> selectApplyList(Apply apply); | |||||
List<ListApplyVO> selectApplyList(Apply apply); | |||||
/** | /** | ||||
* 查询所有应用信息列表 | * 查询所有应用信息列表 | ||||
@@ -1,5 +1,6 @@ | |||||
package com.ruoyi.business.service; | package com.ruoyi.business.service; | ||||
import java.text.ParseException; | |||||
import java.util.List; | import java.util.List; | ||||
import com.ruoyi.business.domain.ApplyPlan; | import com.ruoyi.business.domain.ApplyPlan; | ||||
@@ -17,6 +18,15 @@ import com.ruoyi.business.domain.vo.JobQueryVO; | |||||
* @date 2024-06-14 | * @date 2024-06-14 | ||||
*/ | */ | ||||
public interface IApplyPlanService extends IService<ApplyPlan> { | public interface IApplyPlanService extends IService<ApplyPlan> { | ||||
/** | |||||
* 修改运行时间 | |||||
* @param applyPlan | |||||
* @return | |||||
*/ | |||||
boolean updateRunTime(ApplyPlan applyPlan) throws ParseException; | |||||
/** | /** | ||||
* 影刀回调逻辑 | * 影刀回调逻辑 | ||||
* | * | ||||
@@ -76,7 +86,7 @@ public interface IApplyPlanService extends IService<ApplyPlan> { | |||||
* @param addApplyPlanBO | * @param addApplyPlanBO | ||||
* @return | * @return | ||||
*/ | */ | ||||
boolean save(AddApplyPlanBO addApplyPlanBO); | |||||
boolean save(AddApplyPlanBO addApplyPlanBO) throws ParseException; | |||||
/** | /** | ||||
* 修改计划 | * 修改计划 | ||||
@@ -3,11 +3,14 @@ package com.ruoyi.business.service; | |||||
import java.util.List; | import java.util.List; | ||||
import com.ruoyi.business.domain.Apply; | import com.ruoyi.business.domain.Apply; | ||||
import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||
import com.ruoyi.business.domain.ApplyPlan; | |||||
import com.ruoyi.business.domain.ApplyPlanLog; | |||||
import com.ruoyi.business.domain.Rebot; | import com.ruoyi.business.domain.Rebot; | ||||
import com.ruoyi.business.domain.bo.ApplyStartBO; | import com.ruoyi.business.domain.bo.ApplyStartBO; | ||||
import com.ruoyi.business.domain.bo.JobQueryBO; | import com.ruoyi.business.domain.bo.JobQueryBO; | ||||
import com.ruoyi.business.domain.vo.JobQueryVO; | import com.ruoyi.business.domain.vo.JobQueryVO; | ||||
import com.ruoyi.business.domain.vo.JobStartVO; | import com.ruoyi.business.domain.vo.JobStartVO; | ||||
import com.ruoyi.business.domain.vo.ListApplyVO; | |||||
import com.ruoyi.common.annotation.DataScope; | import com.ruoyi.common.annotation.DataScope; | ||||
/** | /** | ||||
@@ -39,7 +42,7 @@ public interface IApplyService extends IService<Apply> | |||||
* @param apply 应用信息管理 | * @param apply 应用信息管理 | ||||
* @return 应用信息管理集合 | * @return 应用信息管理集合 | ||||
*/ | */ | ||||
List<Apply> list(Apply apply); | |||||
List<ListApplyVO> list(List<ApplyPlan> planList, List<ApplyPlanLog> planLogList, Apply apply); | |||||
/** | /** | ||||
* 查询所有应用信息列表 | * 查询所有应用信息列表 | ||||
@@ -49,4 +52,10 @@ public interface IApplyService extends IService<Apply> | |||||
*/ | */ | ||||
List<Apply> listAll(Apply apply); | List<Apply> listAll(Apply apply); | ||||
/** | |||||
* 修改应用实际执行时间 | |||||
* @param apply | |||||
* @return | |||||
*/ | |||||
boolean updateRunDate(Apply apply); | |||||
} | } |
@@ -14,6 +14,13 @@ import com.ruoyi.business.domain.bo.AddBatchResourceLibraryBO; | |||||
*/ | */ | ||||
public interface IResourceLibraryService extends IService<ResourceLibrary> { | public interface IResourceLibraryService extends IService<ResourceLibrary> { | ||||
/** | |||||
* 批量修改参数 | |||||
* @param addBatchResourceLibraryBO | |||||
* @return | |||||
*/ | |||||
boolean updateBatch(AddBatchResourceLibraryBO addBatchResourceLibraryBO); | |||||
/** | /** | ||||
* 批量添加参数 | * 批量添加参数 | ||||
* | * | ||||
@@ -1,5 +1,7 @@ | |||||
package com.ruoyi.business.service.impl; | package com.ruoyi.business.service.impl; | ||||
import java.math.BigDecimal; | |||||
import java.math.RoundingMode; | |||||
import java.text.ParseException; | import java.text.ParseException; | ||||
import java.time.ZoneId; | import java.time.ZoneId; | ||||
import java.time.ZonedDateTime; | import java.time.ZonedDateTime; | ||||
@@ -11,17 +13,13 @@ import java.util.stream.Collectors; | |||||
import com.alibaba.fastjson2.JSON; | import com.alibaba.fastjson2.JSON; | ||||
import com.alibaba.fastjson2.JSONArray; | import com.alibaba.fastjson2.JSONArray; | ||||
import com.alibaba.fastjson2.JSONObject; | import com.alibaba.fastjson2.JSONObject; | ||||
import com.ruoyi.business.domain.Apply; | |||||
import com.ruoyi.business.domain.Rebot; | |||||
import com.ruoyi.business.domain.ResourceLibrary; | |||||
import com.ruoyi.business.domain.*; | |||||
import com.ruoyi.business.domain.bo.*; | import com.ruoyi.business.domain.bo.*; | ||||
import com.ruoyi.business.domain.vo.JobQueryLogVO; | import com.ruoyi.business.domain.vo.JobQueryLogVO; | ||||
import com.ruoyi.business.domain.vo.JobQueryVO; | import com.ruoyi.business.domain.vo.JobQueryVO; | ||||
import com.ruoyi.business.domain.vo.JobStartVO; | import com.ruoyi.business.domain.vo.JobStartVO; | ||||
import com.ruoyi.business.domain.vo.ListRebotVO; | import com.ruoyi.business.domain.vo.ListRebotVO; | ||||
import com.ruoyi.business.service.IApplyService; | |||||
import com.ruoyi.business.service.IRebotService; | |||||
import com.ruoyi.business.service.IResourceLibraryService; | |||||
import com.ruoyi.business.service.*; | |||||
import com.ruoyi.business.util.YinDaoHttpUtils; | import com.ruoyi.business.util.YinDaoHttpUtils; | ||||
import com.ruoyi.business.yddoman.BaseDTO; | import com.ruoyi.business.yddoman.BaseDTO; | ||||
import com.ruoyi.common.annotation.DataScope; | import com.ruoyi.common.annotation.DataScope; | ||||
@@ -42,8 +40,6 @@ import org.springframework.data.redis.core.RedisTemplate; | |||||
import org.springframework.scheduling.support.CronSequenceGenerator; | import org.springframework.scheduling.support.CronSequenceGenerator; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import com.ruoyi.business.mapper.ApplyPlanMapper; | 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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
@@ -67,6 +63,47 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
@Autowired | @Autowired | ||||
private RedissonClient redissonClient; | private RedissonClient redissonClient; | ||||
@Autowired | |||||
private IApplyPlanLogService applyPlanLogService; | |||||
@Autowired | |||||
private IApplyPlanService applyPlanService; | |||||
/** | |||||
* 修改运行时间 | |||||
* | |||||
* @param entity | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public boolean updateRunTime(ApplyPlan entity) throws ParseException { | |||||
ApplyPlan applyPlan = this.getById(entity.getId()); | |||||
final CronExpression cron = new CronExpression(applyPlan.getCronExpression()); | |||||
// 下次执行时间 | |||||
Date nextDate = null; | |||||
if (Objects.isNull(applyPlan.getLastExecTime())) { | |||||
Date date = new Date(); | |||||
log.debug("当前时间:" + date); | |||||
nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 | |||||
log.debug("下次时间:" + nextDate); | |||||
applyPlan.setNextExecTime(nextDate); | |||||
} else { | |||||
log.debug("当前时间:" + applyPlan.getNextExecTime()); | |||||
nextDate = cron.getNextValidTimeAfter(applyPlan.getLastExecTime());//下次执行时间 | |||||
log.debug("下次时间:" + nextDate); | |||||
// 如果当前时间大于下次运行时间 证明已经超过计划执行时间,下次时间以当前时间为主 | |||||
Date date = new Date(); | |||||
if (date.compareTo(nextDate) > 0) { | |||||
nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 | |||||
applyPlan.setNextExecTime(nextDate); | |||||
} else { | |||||
nextDate = cron.getNextValidTimeAfter(applyPlan.getLastExecTime());//下次执行时间 | |||||
applyPlan.setNextExecTime(nextDate); | |||||
} | |||||
} | |||||
return this.updateById(applyPlan); | |||||
} | |||||
/** | /** | ||||
* 影刀回调 | * 影刀回调 | ||||
* | * | ||||
@@ -74,28 +111,68 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
@Transactional | |||||
public boolean ydCallBack(YinDaoCallBackBO yinDaoCallBackBO) { | public boolean ydCallBack(YinDaoCallBackBO yinDaoCallBackBO) { | ||||
ApplyPlan applyPlan = this.lambdaQuery().eq(ApplyPlan::getTaskUuid, yinDaoCallBackBO.getJobUuid()).one(); | |||||
applyPlan.setStartTime(DateUtils.parseDate(yinDaoCallBackBO.getStartTime())); | |||||
applyPlan.setEndTime(DateUtils.parseDate(yinDaoCallBackBO.getStartTime())); | |||||
applyPlan.setTaskStatus(yinDaoCallBackBO.getStatus()); | |||||
boolean isUpdate = this.updateById(applyPlan); | |||||
// 终态 | |||||
List<String> finalState = new ArrayList<>(); | |||||
finalState.add(PlanRunStatus.FINISH.getKey()); | |||||
finalState.add(PlanRunStatus.STOPPED.getKey()); | |||||
finalState.add(PlanRunStatus.ERROR.getKey()); | |||||
finalState.add(PlanRunStatus.SKIPPED.getKey()); | |||||
finalState.add(PlanRunStatus.CANCEL.getKey()); | |||||
// 如果是终态 | |||||
if (StringUtils.isNotEmpty(yinDaoCallBackBO.getRobotClientName()) && finalState.contains(yinDaoCallBackBO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
return rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, yinDaoCallBackBO.getRobotClientName()).update(rebot); | |||||
} else { | |||||
return isUpdate; | |||||
RLock lock = redissonClient.getLock("updateResult"); | |||||
try { | |||||
// 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 | |||||
boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | |||||
if (isLocked) { | |||||
ApplyPlan applyPlan = this.lambdaQuery().eq(ApplyPlan::getTaskUuid, yinDaoCallBackBO.getJobUuid()).one(); | |||||
applyPlan.setStartTime(DateUtils.parseDate(yinDaoCallBackBO.getStartTime())); | |||||
applyPlan.setEndTime(DateUtils.parseDate(yinDaoCallBackBO.getEndTime())); | |||||
BigDecimal planTime = new BigDecimal((double) (Long.parseLong(yinDaoCallBackBO.getEndTime()) - Long.parseLong(yinDaoCallBackBO.getStartTime())) / (60 * 1000)).setScale(2, RoundingMode.HALF_UP); | |||||
applyPlan.setPlanTime(planTime + ""); | |||||
applyPlan.setTaskStatus(yinDaoCallBackBO.getStatus()); | |||||
if (!yinDaoCallBackBO.getResult().isEmpty()) { | |||||
applyPlan.setOutParam(yinDaoCallBackBO.getResult().get(0).getValue()); | |||||
// 记录响应参数 | |||||
ApplyPlanLog applyPlanLog = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getJobUuid, yinDaoCallBackBO.getJobUuid()).one(); | |||||
if (null == applyPlanLog) { | |||||
applyPlanLog = new ApplyPlanLog(); | |||||
applyPlanLog.setCreateBy("系统创建"); | |||||
applyPlanLog.setCreateTime(new Date()); | |||||
} else { | |||||
applyPlanLog.setUpdateBy("系统创建"); | |||||
applyPlanLog.setUpdateTime(new Date()); | |||||
} | |||||
applyPlanLog.setJobUuid(yinDaoCallBackBO.getJobUuid()); | |||||
applyPlanLog.setAppId(applyPlan.getAppId()); | |||||
applyPlanLog.setOutParam(applyPlan.getOutParam()); | |||||
applyPlanLogService.saveOrUpdate(applyPlanLog); | |||||
} | |||||
applyPlan.setUpdateBy("系统修改"); | |||||
applyPlan.setUpdateTime(new Date()); | |||||
boolean isUpdate = this.updateById(applyPlan); | |||||
// 终态 | |||||
List<String> finalState = new ArrayList<>(); | |||||
finalState.add(PlanRunStatus.FINISH.getKey()); | |||||
finalState.add(PlanRunStatus.STOPPED.getKey()); | |||||
finalState.add(PlanRunStatus.ERROR.getKey()); | |||||
finalState.add(PlanRunStatus.SKIPPED.getKey()); | |||||
finalState.add(PlanRunStatus.CANCEL.getKey()); | |||||
// 如果是终态 | |||||
if (StringUtils.isNotEmpty(yinDaoCallBackBO.getRobotClientName()) && finalState.contains(yinDaoCallBackBO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
rebot.setUpdateBy("系统修改"); | |||||
rebot.setUpdateTime(new Date()); | |||||
return rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, yinDaoCallBackBO.getRobotClientName()).update(rebot); | |||||
} else { | |||||
return isUpdate; | |||||
} | |||||
} | |||||
} catch (InterruptedException e) { | |||||
e.printStackTrace(); | |||||
} finally { | |||||
if (lock.isHeldByCurrentThread()) { | |||||
// 释放锁 | |||||
lock.unlock(); | |||||
} | |||||
} | } | ||||
return true; | |||||
} | } | ||||
/** | /** | ||||
@@ -139,7 +216,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
// 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 | // 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 | ||||
boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | ||||
if (isLocked) { | if (isLocked) { | ||||
List<ApplyPlan> applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime).list(); | |||||
List<ApplyPlan> applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()) | |||||
.isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime) | |||||
.eq(ApplyPlan::getEnabled, "0") | |||||
.list(); | |||||
if (applyPlanList.isEmpty()) { | if (applyPlanList.isEmpty()) { | ||||
return false; | return false; | ||||
} | } | ||||
@@ -224,28 +304,22 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | ||||
if (isLocked) { | if (isLocked) { | ||||
// 先查计划,避免每次命中第三方接口 | // 先查计划,避免每次命中第三方接口 | ||||
List<ApplyPlan> applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()).ne(ApplyPlan::getTaskStatus, PlanRunStatus.RUNNING.getKey()).ne(ApplyPlan::getTaskStatus, PlanRunStatus.CREATED.getKey()).list(); | |||||
List<ApplyPlan> applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()) | |||||
.ne(ApplyPlan::getTaskStatus, PlanRunStatus.RUNNING.getKey()) | |||||
.ne(ApplyPlan::getTaskStatus, PlanRunStatus.CREATED.getKey()) | |||||
.eq(ApplyPlan::getEnabled, "0") | |||||
.list(); | |||||
if (applyPlanList.isEmpty()) { | if (applyPlanList.isEmpty()) { | ||||
return false; | return false; | ||||
} | } | ||||
// 需要执行的计划 | // 需要执行的计划 | ||||
List<ApplyPlan> execApplyPlan = new ArrayList<>(); | List<ApplyPlan> execApplyPlan = new ArrayList<>(); | ||||
applyPlanList.forEach(e -> { | applyPlanList.forEach(e -> { | ||||
try { | |||||
CronExpression cron = new CronExpression(e.getCronExpression()); | |||||
// 如果该计划没有执行过 | |||||
if (Objects.isNull(e.getLastExecTime())) { | |||||
// 执行一次 | |||||
execApplyPlan.add(e); | |||||
} else { | |||||
// 根据表达式返回下一个执行时间 | |||||
if (new Date().compareTo(e.getNextExecTime()) > -1) { | |||||
execApplyPlan.add(e); | |||||
} | |||||
} | |||||
} catch (ParseException ex) { | |||||
log.error(e.getPlanName() + "的时间表达式错误!"); | |||||
throw new RuntimeException(ex); | |||||
Date date = new Date(); | |||||
// 当前时间大于下次时间 | |||||
if (date.compareTo(e.getNextExecTime()) > -1) { | |||||
// 执行一次 | |||||
execApplyPlan.add(e); | |||||
} | } | ||||
}); | }); | ||||
if (execApplyPlan.isEmpty()) { | if (execApplyPlan.isEmpty()) { | ||||
@@ -288,11 +362,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
// 如果应用支持参数 | // 如果应用支持参数 | ||||
if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { | if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { | ||||
// 获取参数 | |||||
if (StringUtils.isNotEmpty(e.getPlanParams())) { | |||||
applyStartBO.setPlanParams(e.getPlanParams()); | |||||
List<ApplyStartBO.RobotParam> paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); | |||||
applyStartBO.setParams(paramList); | |||||
List<ResourceLibrary> list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, e.getAppId()).list(); | |||||
if (!list.isEmpty()) { | |||||
List<ApplyStartBO.RobotParam> robotParamList = list.stream().map(param -> { | |||||
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); | |||||
robotParam.setType(param.getResourceType()); | |||||
robotParam.setName(param.getResourceName()); | |||||
robotParam.setValue(param.getResourceValue()); | |||||
return robotParam; | |||||
}).collect(Collectors.toList()); | |||||
applyStartBO.setParams(robotParamList); | |||||
// 记录已经执行的参数 | |||||
String jsonString = JSON.toJSONString(robotParamList); | |||||
applyStartBO.setPlanParams(jsonString); | |||||
} | } | ||||
} | } | ||||
@@ -304,20 +386,21 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
applyPlan.setUpdateTime(new Date()); | applyPlan.setUpdateTime(new Date()); | ||||
applyPlan.setTaskUuid(jobStartVO.getJobUuid()); | applyPlan.setTaskUuid(jobStartVO.getJobUuid()); | ||||
applyPlan.setTaskStatus(PlanRunStatus.RUNNING.getKey()); | applyPlan.setTaskStatus(PlanRunStatus.RUNNING.getKey()); | ||||
// 实际执行的参数 | |||||
applyPlan.setPlanParams(applyStartBO.getPlanParams()); | |||||
// 根据表达式返回下一个执行时间 | // 根据表达式返回下一个执行时间 | ||||
log.debug("表达式:" + e.getCronExpression()); | log.debug("表达式:" + e.getCronExpression()); | ||||
// 设置时区,例如设置为中国时区 | |||||
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("Asia/Shanghai").toString()); | |||||
final CronExpression cron = new CronExpression(e.getCronExpression()); | final CronExpression cron = new CronExpression(e.getCronExpression()); | ||||
Date nextDate = null; | Date nextDate = null; | ||||
if (Objects.isNull(e.getLastExecTime())) { | |||||
// 如果上次时间为空,下次执行时间也为空 下次时间以当前时间计算,上次时间为当前时间 | |||||
if (Objects.isNull(e.getLastExecTime()) && Objects.isNull(e.getNextExecTime())) { | |||||
Date date = new Date(); | Date date = new Date(); | ||||
log.debug("当前时间:" + date); | log.debug("当前时间:" + date); | ||||
nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 | nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 | ||||
log.debug("下次时间:" + nextDate); | log.debug("下次时间:" + nextDate); | ||||
applyPlan.setLastExecTime(date); | applyPlan.setLastExecTime(date); | ||||
applyPlan.setNextExecTime(nextDate); | applyPlan.setNextExecTime(nextDate); | ||||
// 上次时间记录为下次时间,下次时间更新为计划下次时间 | |||||
} else { | } else { | ||||
applyPlan.setLastExecTime(e.getNextExecTime()); | applyPlan.setLastExecTime(e.getNextExecTime()); | ||||
log.debug("当前时间:" + e.getNextExecTime()); | log.debug("当前时间:" + e.getNextExecTime()); | ||||
@@ -333,6 +416,20 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { | if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { | ||||
ids.add(e.getId()); | ids.add(e.getId()); | ||||
} | } | ||||
// 记录执行日志 | |||||
ApplyPlanLog applyPlanLog = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getJobUuid, jobStartVO.getJobUuid()).one(); | |||||
if (null == applyPlanLog) { | |||||
applyPlanLog = new ApplyPlanLog(); | |||||
applyPlanLog.setCreateBy("系统创建"); | |||||
applyPlanLog.setCreateTime(new Date()); | |||||
} else { | |||||
applyPlanLog.setUpdateBy("系统修改"); | |||||
applyPlanLog.setUpdateTime(new Date()); | |||||
} | |||||
applyPlanLog.setJobUuid(jobStartVO.getJobUuid()); | |||||
applyPlanLog.setAppId(e.getAppId()); | |||||
applyPlanLog.setPlanId(applyPlan.getId()); | |||||
applyPlanLogService.saveOrUpdate(applyPlanLog); | |||||
} catch (IllegalAccessException ex) { | } catch (IllegalAccessException ex) { | ||||
throw new RuntimeException(ex); | throw new RuntimeException(ex); | ||||
} catch (ParseException ex) { | } catch (ParseException ex) { | ||||
@@ -361,71 +458,102 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
@Override | @Override | ||||
@Transactional | @Transactional | ||||
public void queryAppStartResult() throws IllegalAccessException { | public void queryAppStartResult() throws IllegalAccessException { | ||||
// 不查询的状态 | |||||
List<String> noStatus = new ArrayList<>(); | |||||
noStatus.add(PlanRunStatus.FINISH.getKey()); | |||||
noStatus.add(PlanRunStatus.STOPPED.getKey()); | |||||
noStatus.add(PlanRunStatus.ERROR.getKey()); | |||||
noStatus.add(PlanRunStatus.SKIPPED.getKey()); | |||||
noStatus.add(PlanRunStatus.CANCEL.getKey()); | |||||
// 查询任务运行状态非空非终态并且已经创建的任务 | |||||
List<ApplyPlan> list = this.lambdaQuery().notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskUuid).isNotNull(ApplyPlan::getTaskStatus).orderByAsc(ApplyPlan::getPriority).list(); | |||||
if (list.isEmpty()) { | |||||
log.debug("没有需要更新状态的计划任务"); | |||||
return; | |||||
} | |||||
for (ApplyPlan applyPlan : list) { | |||||
JobQueryBO jobQueryBO = new JobQueryBO(); | |||||
jobQueryBO.setJobUuid(applyPlan.getTaskUuid()); | |||||
JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO); | |||||
// 如果状态不一致,更新最新状态 | |||||
if (jobQueryVO != null && !applyPlan.getTaskStatus().equals(jobQueryVO.getStatus())) { | |||||
// 修改的任务计划 | |||||
ApplyPlan updateApplyPlan = new ApplyPlan(); | |||||
updateApplyPlan.setTaskStatus(jobQueryVO.getStatus()); | |||||
if (null != jobQueryVO.getEndTime()) { | |||||
updateApplyPlan.setEndTime(jobQueryVO.getEndTime()); | |||||
updateApplyPlan.setStartTime(jobQueryVO.getStartTime()); | |||||
if (!Objects.isNull(updateApplyPlan.getEndTime()) && !Objects.isNull(updateApplyPlan.getStartTime())) { | |||||
long diff = updateApplyPlan.getEndTime().getTime() - updateApplyPlan.getStartTime().getTime(); | |||||
long planTime = diff / (60 * 1000); | |||||
updateApplyPlan.setPlanTime(planTime + ""); | |||||
if (!Objects.isNull(applyPlan.getManualTime())) { | |||||
updateApplyPlan.setTimeSaving((Long.parseLong(applyPlan.getManualTime()) - planTime) + ""); | |||||
RLock lock = redissonClient.getLock("updateResult"); | |||||
try { | |||||
// 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 | |||||
boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); | |||||
if (isLocked) { | |||||
// 不查询的状态 | |||||
List<String> noStatus = new ArrayList<>(); | |||||
noStatus.add(PlanRunStatus.FINISH.getKey()); | |||||
noStatus.add(PlanRunStatus.STOPPED.getKey()); | |||||
noStatus.add(PlanRunStatus.ERROR.getKey()); | |||||
noStatus.add(PlanRunStatus.SKIPPED.getKey()); | |||||
noStatus.add(PlanRunStatus.CANCEL.getKey()); | |||||
// 查询任务运行状态非空非终态并且已经创建的任务 | |||||
List<ApplyPlan> list = this.lambdaQuery().notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskUuid).isNotNull(ApplyPlan::getTaskStatus).orderByAsc(ApplyPlan::getPriority).list(); | |||||
if (list.isEmpty()) { | |||||
log.debug("没有需要更新状态的计划任务"); | |||||
return; | |||||
} | |||||
for (ApplyPlan applyPlan : list) { | |||||
JobQueryBO jobQueryBO = new JobQueryBO(); | |||||
jobQueryBO.setJobUuid(applyPlan.getTaskUuid()); | |||||
JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO); | |||||
// 如果状态不一致,更新最新状态 | |||||
if (jobQueryVO != null && !applyPlan.getTaskStatus().equals(jobQueryVO.getStatus())) { | |||||
// 修改的任务计划 | |||||
ApplyPlan updateApplyPlan = new ApplyPlan(); | |||||
updateApplyPlan.setTaskStatus(jobQueryVO.getStatus()); | |||||
if (null != jobQueryVO.getEndTime()) { | |||||
updateApplyPlan.setEndTime(jobQueryVO.getEndTime()); | |||||
updateApplyPlan.setStartTime(jobQueryVO.getStartTime()); | |||||
if (!Objects.isNull(updateApplyPlan.getEndTime()) && !Objects.isNull(updateApplyPlan.getStartTime())) { | |||||
long diff = updateApplyPlan.getEndTime().getTime() - updateApplyPlan.getStartTime().getTime(); | |||||
BigDecimal planTime = new BigDecimal((double) diff / (60 * 1000)).setScale(2, RoundingMode.HALF_UP); | |||||
updateApplyPlan.setPlanTime(planTime + ""); | |||||
if (!Objects.isNull(applyPlan.getManualTime())) { | |||||
updateApplyPlan.setTimeSaving((new BigDecimal(applyPlan.getManualTime()).subtract(planTime)) + ""); | |||||
} | |||||
} | |||||
} | |||||
updateApplyPlan.setId(applyPlan.getId()); | |||||
updateApplyPlan.setUpdateBy("系统修改"); | |||||
updateApplyPlan.setUpdateTime(new Date()); | |||||
// 如果是终态并且有响应参数 获取返回值 | |||||
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); | |||||
if (finishStatus.contains(jobQueryVO.getStatus())) { | |||||
List<JobQueryVO.RobotParam> outputs = jobQueryVO.getRobotParams().getOutputs(); | |||||
if (null != outputs && !outputs.isEmpty()) { | |||||
JobQueryVO.RobotParam robotParam = outputs.get(0); | |||||
updateApplyPlan.setOutParam(robotParam.getValue()); | |||||
} | |||||
} | |||||
updateApplyPlan.setRemark(jobQueryVO.getRemark()); | |||||
this.updateById(updateApplyPlan); | |||||
if ("2".equals(applyPlan.getExcType())) { | |||||
ApplyPlanLog applyPlanLog = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getJobUuid, applyPlan.getTaskUuid()).one(); | |||||
// 记录响应参数 | |||||
if (applyPlanLog == null) { | |||||
applyPlanLog = new ApplyPlanLog(); | |||||
applyPlanLog.setCreateBy("系统创建"); | |||||
applyPlanLog.setCreateTime(new Date()); | |||||
} else { | |||||
applyPlanLog.setUpdateBy("系统创建"); | |||||
applyPlanLog.setUpdateTime(new Date()); | |||||
} | |||||
applyPlanLog.setJobUuid(jobQueryVO.getJobUuid()); | |||||
applyPlanLog.setAppId(applyPlan.getAppId()); | |||||
applyPlanLog.setOutParam(updateApplyPlan.getOutParam()); | |||||
applyPlanLogService.saveOrUpdate(applyPlanLog); | |||||
} | } | ||||
} | } | ||||
} | |||||
updateApplyPlan.setId(applyPlan.getId()); | |||||
updateApplyPlan.setUpdateBy("系统修改"); | |||||
updateApplyPlan.setUpdateTime(new Date()); | |||||
// 如果是终态并且有响应参数 获取返回值 | |||||
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); | |||||
if (finishStatus.contains(jobQueryVO.getStatus())) { | |||||
List<JobQueryVO.RobotParam> outputs = jobQueryVO.getRobotParams().getOutputs(); | |||||
if (null != outputs && !outputs.isEmpty()) { | |||||
JobQueryVO.RobotParam robotParam = outputs.get(0); | |||||
updateApplyPlan.setOutParam(robotParam.getValue()); | |||||
// 如果是终态改变机器人状态 | |||||
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); | |||||
if (finishStatus.contains(jobQueryVO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
rebot.setUpdateBy("系统修改"); | |||||
rebot.setUpdateTime(new Date()); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); | |||||
} else if (PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.RUNNING.getKey()); | |||||
rebot.setUpdateBy("系统修改"); | |||||
rebot.setUpdateTime(new Date()); | |||||
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); | |||||
} | } | ||||
} | } | ||||
updateApplyPlan.setRemark(jobQueryVO.getRemark()); | |||||
this.updateById(updateApplyPlan); | |||||
} | } | ||||
// 如果是终态改变机器人状态 | |||||
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); | |||||
if (finishStatus.contains(jobQueryVO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
rebot.setUpdateBy("系统修改"); | |||||
rebot.setUpdateTime(new Date()); | |||||
rebot.setStatus(RebotStatus.IDLE.getKey()); | |||||
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); | |||||
} else if (PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())) { | |||||
Rebot rebot = new Rebot(); | |||||
rebot.setStatus(RebotStatus.RUNNING.getKey()); | |||||
rebot.setUpdateBy("系统修改"); | |||||
rebot.setUpdateTime(new Date()); | |||||
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); | |||||
} catch (InterruptedException e) { | |||||
e.printStackTrace(); | |||||
} finally { | |||||
if (lock.isHeldByCurrentThread()) { | |||||
// 释放锁 | |||||
lock.unlock(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -491,10 +619,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
applyStartBO.setAccountName(listRebotVO.getRobotClientName()); | applyStartBO.setAccountName(listRebotVO.getRobotClientName()); | ||||
// 如果应用支持参数 | // 如果应用支持参数 | ||||
if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { | if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { | ||||
if (StringUtils.isNotEmpty(applyPlan.getPlanParams())) { | |||||
applyStartBO.setPlanParams(applyPlan.getPlanParams()); | |||||
List<ApplyStartBO.RobotParam> paramList = JSON.parseArray(applyPlan.getPlanParams(), ApplyStartBO.RobotParam.class); | |||||
applyStartBO.setParams(paramList); | |||||
List<ResourceLibrary> list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyPlan.getAppId()).list(); | |||||
if (!list.isEmpty()) { | |||||
List<ApplyStartBO.RobotParam> robotParamList = list.stream().map(e -> { | |||||
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); | |||||
robotParam.setType(e.getResourceType()); | |||||
robotParam.setName(e.getResourceName()); | |||||
robotParam.setValue(e.getResourceValue()); | |||||
return robotParam; | |||||
}).collect(Collectors.toList()); | |||||
applyStartBO.setParams(robotParamList); | |||||
// 记录已经执行的参数 | |||||
String jsonString = JSON.toJSONString(robotParamList); | |||||
applyStartBO.setPlanParams(jsonString); | |||||
} | } | ||||
} | } | ||||
JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); | JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); | ||||
@@ -511,8 +648,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
updateApplyPlan.setRobotName(listRebotVO.getRobotClientName()); | updateApplyPlan.setRobotName(listRebotVO.getRobotClientName()); | ||||
updateApplyPlan.setManualTime(applyPlan.getManualTime()); | updateApplyPlan.setManualTime(applyPlan.getManualTime()); | ||||
updateApplyPlan.setDeptId(applyStartBO.getDeptId()); | updateApplyPlan.setDeptId(applyStartBO.getDeptId()); | ||||
updateApplyPlan.setPlanParams(applyStartBO.getPlanParams()); | |||||
applyPlan.setTaskUuid(jobStartVO.getJobUuid()); | applyPlan.setTaskUuid(jobStartVO.getJobUuid()); | ||||
if (this.saveOrUpdate(updateApplyPlan)) { | if (this.saveOrUpdate(updateApplyPlan)) { | ||||
// 移除当前对象,防止重复跑 | |||||
applyPlans.remove(0); | applyPlans.remove(0); | ||||
i++; | i++; | ||||
} | } | ||||
@@ -532,7 +671,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
@Override | @Override | ||||
@Transactional | @Transactional | ||||
public boolean save(AddApplyPlanBO addApplyPlanBO) { | |||||
public boolean save(AddApplyPlanBO addApplyPlanBO) throws ParseException { | |||||
// 指定时间执行 | // 指定时间执行 | ||||
if (addApplyPlanBO.getExcType().equals("1") && null == addApplyPlanBO.getExcTime()) { | if (addApplyPlanBO.getExcType().equals("1") && null == addApplyPlanBO.getExcTime()) { | ||||
throw new ServiceException("指定时间执行时间不能为空"); | throw new ServiceException("指定时间执行时间不能为空"); | ||||
@@ -557,6 +696,14 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan | |||||
AtomicBoolean insert = new AtomicBoolean(false); | AtomicBoolean insert = new AtomicBoolean(false); | ||||
ApplyPlan applyPlan = new ApplyPlan(); | ApplyPlan applyPlan = new ApplyPlan(); | ||||
if ("2".equals(addApplyPlanBO.getExcType())) { | |||||
final CronExpression cron = new CronExpression(addApplyPlanBO.getCronExpression()); | |||||
Date date = new Date(); | |||||
log.debug("当前时间:" + date); | |||||
Date nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 | |||||
log.debug("下次时间:" + nextDate); | |||||
applyPlan.setNextExecTime(nextDate); | |||||
} | |||||
BeanUtils.copyBeanProp(applyPlan, addApplyPlanBO); | BeanUtils.copyBeanProp(applyPlan, addApplyPlanBO); | ||||
Apply apply = appMap.get(addApplyPlanBO.getAppId()).get(0); | Apply apply = appMap.get(addApplyPlanBO.getAppId()).get(0); | ||||
applyPlan.setAppName(apply.getAppName()); | applyPlan.setAppName(apply.getAppName()); | ||||
@@ -1,34 +1,33 @@ | |||||
package com.ruoyi.business.service.impl; | package com.ruoyi.business.service.impl; | ||||
import java.math.BigDecimal; | |||||
import java.math.RoundingMode; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Optional; | |||||
import java.util.concurrent.atomic.AtomicReference; | |||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||||
import com.ruoyi.business.domain.ApplyPlan; | |||||
import com.ruoyi.business.domain.Rebot; | |||||
import com.ruoyi.business.domain.ResourceLibrary; | |||||
import com.ruoyi.business.domain.*; | |||||
import com.ruoyi.business.domain.bo.ApplyStartBO; | import com.ruoyi.business.domain.bo.ApplyStartBO; | ||||
import com.ruoyi.business.domain.bo.JobQueryBO; | import com.ruoyi.business.domain.bo.JobQueryBO; | ||||
import com.ruoyi.business.domain.bo.ListApplyBO; | 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.JobQueryVO; | ||||
import com.ruoyi.business.domain.vo.JobStartVO; | import com.ruoyi.business.domain.vo.JobStartVO; | ||||
import com.ruoyi.business.domain.vo.ListApplyVO; | import com.ruoyi.business.domain.vo.ListApplyVO; | ||||
import com.ruoyi.business.domain.vo.ListRebotVO; | |||||
import com.ruoyi.business.service.IApplyPlanService; | import com.ruoyi.business.service.IApplyPlanService; | ||||
import com.ruoyi.business.service.IResourceLibraryService; | import com.ruoyi.business.service.IResourceLibraryService; | ||||
import com.ruoyi.business.util.YinDaoHttpUtils; | import com.ruoyi.business.util.YinDaoHttpUtils; | ||||
import com.ruoyi.common.annotation.DataScope; | import com.ruoyi.common.annotation.DataScope; | ||||
import com.ruoyi.common.core.domain.entity.SysDept; | import com.ruoyi.common.core.domain.entity.SysDept; | ||||
import com.ruoyi.common.utils.DateUtils; | |||||
import com.ruoyi.common.enums.PlanRunStatus; | |||||
import com.ruoyi.common.utils.SecurityUtils; | import com.ruoyi.common.utils.SecurityUtils; | ||||
import com.ruoyi.common.utils.bean.BeanUtils; | import com.ruoyi.common.utils.bean.BeanUtils; | ||||
import com.ruoyi.system.service.ISysDeptService; | import com.ruoyi.system.service.ISysDeptService; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import com.ruoyi.business.mapper.ApplyMapper; | import com.ruoyi.business.mapper.ApplyMapper; | ||||
import com.ruoyi.business.domain.Apply; | |||||
import com.ruoyi.business.service.IApplyService; | import com.ruoyi.business.service.IApplyService; | ||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
@@ -88,19 +87,24 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements | |||||
listApplyBO.setPage(1); | listApplyBO.setPage(1); | ||||
// 影刀最大限制 | // 影刀最大限制 | ||||
listApplyBO.setSize(100); | listApplyBO.setSize(100); | ||||
List<Apply> applyList = baseMapper.selectApplyList(new Apply()); | |||||
Map<String, List<Apply>> applyMap = applyList.stream().collect(Collectors.groupingBy(Apply::getAppId)); | |||||
List<ListApplyVO> applyList = baseMapper.selectApplyList(new Apply()); | |||||
Map<String, List<ListApplyVO>> applyMap = applyList.stream().collect(Collectors.groupingBy(ListApplyVO::getAppId)); | |||||
List<ListApplyVO> listApplyVOList = YinDaoHttpUtils.listApp(listApplyBO); | List<ListApplyVO> listApplyVOList = YinDaoHttpUtils.listApp(listApplyBO); | ||||
// 获取客户端名称集合 | // 获取客户端名称集合 | ||||
List<String> appIdList = listApplyVOList.stream().map(ListApplyVO::getAppId).collect(Collectors.toList()); | List<String> appIdList = listApplyVOList.stream().map(ListApplyVO::getAppId).collect(Collectors.toList()); | ||||
// 只能移除当前用户部门的 | |||||
this.remove(new LambdaUpdateWrapper<Apply>().notIn(Apply::getAppId, appIdList).eq(Apply::getDeptId, SecurityUtils.getDeptId())); | |||||
// 是否管理员 | |||||
long count = SecurityUtils.getLoginUser().getUser().getRoles().stream().filter(e -> e.getRoleId() == 1).count(); | |||||
if (count > 0) { | |||||
this.remove(new LambdaUpdateWrapper<Apply>().notIn(Apply::getAppId, appIdList)); | |||||
} else { | |||||
// 只能移除当前用户部门的 | |||||
this.remove(new LambdaUpdateWrapper<Apply>().notIn(Apply::getAppId, appIdList).eq(Apply::getDeptId, SecurityUtils.getDeptId())); | |||||
} | |||||
Map<String, List<SysDept>> deptMap = sysDeptService.selectDeptAllList(new SysDept()).stream().collect(Collectors.groupingBy(SysDept::getDeptName)); | Map<String, List<SysDept>> deptMap = sysDeptService.selectDeptAllList(new SysDept()).stream().collect(Collectors.groupingBy(SysDept::getDeptName)); | ||||
listApplyVOList.forEach(listRebotVO -> { | listApplyVOList.forEach(listRebotVO -> { | ||||
// 数据库里是否存在 | // 数据库里是否存在 | ||||
List<Apply> applys = applyMap.get(listRebotVO.getAppId()); | |||||
List<ListApplyVO> applys = applyMap.get(listRebotVO.getAppId()); | |||||
String[] deptName = listRebotVO.getAppName().split("-"); | String[] deptName = listRebotVO.getAppName().split("-"); | ||||
List<SysDept> sysDepts = deptMap.get(deptName[0]); | List<SysDept> sysDepts = deptMap.get(deptName[0]); | ||||
@@ -115,7 +119,7 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements | |||||
} | } | ||||
save(newApply); | save(newApply); | ||||
} else { | } else { | ||||
Apply apply = applys.get(0); | |||||
ListApplyVO apply = applys.get(0); | |||||
Apply newApply = new Apply(); | Apply newApply = new Apply(); | ||||
BeanUtils.copyBeanProp(newApply, listRebotVO); | BeanUtils.copyBeanProp(newApply, listRebotVO); | ||||
newApply.setAppCreateTime(listRebotVO.getCreateTime()); | newApply.setAppCreateTime(listRebotVO.getCreateTime()); | ||||
@@ -148,8 +152,46 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements | |||||
*/ | */ | ||||
@Override | @Override | ||||
@DataScope(deptAlias = "apply") | @DataScope(deptAlias = "apply") | ||||
public List<Apply> list(Apply apply) { | |||||
return baseMapper.selectApplyList(apply); | |||||
public List<ListApplyVO> list(List<ApplyPlan> planList, List<ApplyPlanLog> planLogList, Apply apply) { | |||||
// 按照appId分组 | |||||
Map<String, List<ApplyPlan>> planMap = planList.stream().collect(Collectors.groupingBy(ApplyPlan::getAppId)); | |||||
// 日志按照app分组 | |||||
Map<String, List<ApplyPlanLog>> planLogMap = planLogList.stream().collect(Collectors.groupingBy(ApplyPlanLog::getAppId)); | |||||
List<ListApplyVO> listApplyVOS = baseMapper.selectApplyList(apply); | |||||
List<ListApplyVO> newList = listApplyVOS.stream().map(e -> { | |||||
// 根据appId获取执行计划 | |||||
List<ApplyPlan> applyPlans = planMap.get(e.getAppId()); | |||||
// 应用没有设置时间 | |||||
if (null == applyPlans) { | |||||
return e; | |||||
} | |||||
// 总计节约时间 (分钟) | |||||
AtomicReference<BigDecimal> planTime = new AtomicReference<>(BigDecimal.ZERO); | |||||
applyPlans.forEach(plan -> { | |||||
// 如果是周期执行 | |||||
if ("2".equals(plan.getExcType())) { | |||||
// 获取执行日志 | |||||
List<ApplyPlanLog> applyPlanLogs = planLogMap.get(e.getAppId()); | |||||
// 日志总计节约时间 | |||||
AtomicReference<BigDecimal> logPlanTime = new AtomicReference<>(BigDecimal.ZERO); | |||||
applyPlanLogs.forEach(log -> { | |||||
// 实际运行时间 | |||||
long runDate = log.getUpdateTime().getTime() - log.getCreateTime().getTime(); | |||||
// 转为分钟 | |||||
BigDecimal min = new BigDecimal((double) runDate / (1000 * 60)).setScale(2, RoundingMode.HALF_UP); | |||||
logPlanTime.set(logPlanTime.get().add(min)); | |||||
}); | |||||
planTime.set(planTime.get().add(logPlanTime.get())); | |||||
// planTime.set(planTime.get() + logPlanTime.get()); | |||||
} else { | |||||
planTime.set(planTime.get().add(new BigDecimal(Long.parseLong(plan.getTimeSaving())))); | |||||
} | |||||
}); | |||||
e.setTimeSaving(planTime.get() + ""); | |||||
return e; | |||||
}).collect(Collectors.toList()); | |||||
return newList; | |||||
} | } | ||||
/** | /** | ||||
@@ -163,4 +205,28 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements | |||||
public List<Apply> listAll(Apply apply) { | public List<Apply> listAll(Apply apply) { | ||||
return baseMapper.selectApplyAllList(apply); | return baseMapper.selectApplyAllList(apply); | ||||
} | } | ||||
/** | |||||
* 修改应用实际执行时间 | |||||
* | |||||
* @param apply | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public boolean updateRunDate(Apply apply) { | |||||
// 根据appId获取计划 | |||||
List<ApplyPlan> appList = applyPlanService.lambdaQuery().eq(ApplyPlan::getAppId, apply.getAppId()).list(); | |||||
appList.forEach(e -> { | |||||
e.setManualTime(apply.getManualTime()); | |||||
if (PlanRunStatus.FINISH.getKey().equals(e.getTaskStatus())) { | |||||
// 计算节约时间 | |||||
long diff = Long.parseLong(e.getManualTime()) - Long.parseLong(Optional.ofNullable(e.getPlanTime()).orElse("0")); | |||||
e.setTimeSaving(diff + ""); | |||||
} | |||||
applyPlanService.updateById(e); | |||||
}); | |||||
return super.updateById(apply); | |||||
} | |||||
} | } |
@@ -30,6 +30,25 @@ public class ResourceLibraryServiceImpl extends ServiceImpl<ResourceLibraryMappe | |||||
@Autowired | @Autowired | ||||
private IApplyService applyService; | private IApplyService applyService; | ||||
/** | |||||
* 批量修改参数 | |||||
* @param addBatchResourceLibraryBO | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public boolean updateBatch(AddBatchResourceLibraryBO addBatchResourceLibraryBO) { | |||||
// 参数集合 | |||||
List<ResourceLibrary> resourceLibraries = new ArrayList<>(); | |||||
addBatchResourceLibraryBO.getList().forEach(e -> { | |||||
ResourceLibrary resourceLibrary = new ResourceLibrary(); | |||||
resourceLibrary.setId(e.getId()); | |||||
resourceLibrary.setResourceValue(e.getResourceValue()); | |||||
resourceLibraries.add(resourceLibrary); | |||||
}); | |||||
return super.updateBatchById(resourceLibraries); | |||||
} | |||||
/** | /** | ||||
* 批量添加参数 | * 批量添加参数 | ||||
* | * | ||||
@@ -55,6 +55,8 @@ public class YinDaoHttpUtils { | |||||
List<ApplyStartBO.RobotParam> robotParams = JSON.parseArray(applyStartBO.getPlanParams(), ApplyStartBO.RobotParam.class); | List<ApplyStartBO.RobotParam> robotParams = JSON.parseArray(applyStartBO.getPlanParams(), ApplyStartBO.RobotParam.class); | ||||
List<ApplyStartBO.RobotParam> newParamList = robotParams.stream().peek(e -> { | List<ApplyStartBO.RobotParam> newParamList = robotParams.stream().peek(e -> { | ||||
if ("file".equals(e.getType())) { | if ("file".equals(e.getType())) { | ||||
// e.setValue(SERVER_URL + e.getValue()); | |||||
e.setType("str"); | |||||
e.setValue(SERVER_URL + e.getValue()); | e.setValue(SERVER_URL + e.getValue()); | ||||
} | } | ||||
}).collect(Collectors.toList()); | }).collect(Collectors.toList()); | ||||
@@ -51,6 +51,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
<result property="deleted" column="deleted" /> | <result property="deleted" column="deleted" /> | ||||
</resultMap> | </resultMap> | ||||
<!--应用信息管理对象 ct_apply--> | |||||
<resultMap type="ListApplyVO" id="ListApplyVOResult" extends="ApplyResult"> | |||||
</resultMap> | |||||
<sql id="selectApplyVo"> | <sql id="selectApplyVo"> | ||||
select | select | ||||
apply.id,<!-- 主键 --> | apply.id,<!-- 主键 --> | ||||
@@ -77,7 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
apply.deleted | apply.deleted | ||||
</sql> | </sql> | ||||
<select id="selectApplyList" parameterType="Apply" resultMap="ApplyResult"> | |||||
<select id="selectApplyList" parameterType="Apply" resultMap="ListApplyVOResult"> | |||||
<include refid="selectApplyVo"/> | <include refid="selectApplyVo"/> | ||||
from ct_apply apply | from ct_apply apply | ||||
<where> | <where> | ||||
@@ -9,32 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
<result property="id" column="id" /> | <result property="id" column="id" /> | ||||
<!-- 启动的任务的uuid --> | <!-- 启动的任务的uuid --> | ||||
<result property="jobUuid" column="job_uuid" /> | <result property="jobUuid" column="job_uuid" /> | ||||
<!-- 计划名称 --> | |||||
<result property="planName" column="plan_name" /> | |||||
<!-- 执行类型(0指定机器人 1随机分配空闲) --> | |||||
<result property="planType" column="plan_type" /> | |||||
<!-- 计划执行的机器人名称 --> | |||||
<result property="robotName" column="robot_name" /> | |||||
<!-- 应用类型名称 --> | |||||
<result property="appTypeName" column="app_type_name" /> | |||||
<!-- 应用名称 --> | |||||
<result property="appName" column="app_name" /> | |||||
<!-- appid --> | |||||
<!-- 所属应用id --> | |||||
<result property="appId" column="app_id" /> | <result property="appId" column="app_id" /> | ||||
<!-- 任务状态 --> | |||||
<result property="status" column="status" /> | |||||
<!-- 任务状态名称 --> | |||||
<result property="statusName" column="status_name" /> | |||||
<!-- 任务开始运行的时间 --> | |||||
<result property="startTime" column="start_time" /> | |||||
<!-- 任务结束运行的时间 --> | |||||
<result property="endTime" column="end_time" /> | |||||
<!-- 预计人工耗时 --> | |||||
<result property="manualTime" column="manual_time" /> | |||||
<!-- 实际耗时 --> | |||||
<result property="planTime" column="plan_time" /> | |||||
<!-- 节约时间 --> | |||||
<result property="timeSaving" column="time_saving" /> | |||||
<!-- 计划id --> | |||||
<result property="planId" column="plan_id" /> | |||||
<!-- 输出 --> | |||||
<result property="outParam" column="out_param" /> | |||||
<!-- 创建者 --> | <!-- 创建者 --> | ||||
<result property="createBy" column="create_by" /> | <result property="createBy" column="create_by" /> | ||||
<!-- 创建时间 --> | <!-- 创建时间 --> | ||||
@@ -52,20 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
<sql id="selectApplyPlanLogVo"> | <sql id="selectApplyPlanLogVo"> | ||||
select | select | ||||
id,<!-- 主键 --> | id,<!-- 主键 --> | ||||
job_uuid,<!-- 启动的任务的uuid --> | |||||
plan_name,<!-- 计划名称 --> | |||||
plan_type,<!-- 执行类型(0指定机器人 1随机分配空闲) --> | |||||
robot_name,<!-- 计划执行的机器人名称 --> | |||||
app_type_name,<!-- 应用类型名称 --> | |||||
app_name,<!-- 应用名称 --> | |||||
app_id,<!-- appid --> | |||||
status,<!-- 任务状态 --> | |||||
status_name,<!-- 任务状态名称 --> | |||||
start_time,<!-- 任务开始运行的时间 --> | |||||
end_time,<!-- 任务结束运行的时间 --> | |||||
manual_time,<!-- 预计人工耗时 --> | |||||
plan_time,<!-- 实际耗时 --> | |||||
time_saving,<!-- 节约时间 --> | |||||
job_uuid,<!-- 计划jobuuid --> | |||||
app_id,<!-- 所属应用id --> | |||||
plan_id,<!-- 计划id --> | |||||
out_param,<!-- 输出 --> | |||||
create_by,<!-- 创建者 --> | create_by,<!-- 创建者 --> | ||||
create_time,<!-- 创建时间 --> | create_time,<!-- 创建时间 --> | ||||
update_by,<!-- 更新者 --> | update_by,<!-- 更新者 --> | ||||
@@ -79,13 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||||
<where> | <where> | ||||
deleted = 0 | deleted = 0 | ||||
<if test="jobUuid != null and jobUuid != ''"> and job_uuid = #{jobUuid}</if> | <if test="jobUuid != null and jobUuid != ''"> and job_uuid = #{jobUuid}</if> | ||||
<if test="planName != null and planName != ''"> and plan_name like concat(#{planName}, '%')</if> | |||||
<if test="robotName != null and robotName != ''"> and robot_name like concat(#{robotName}, '%')</if> | |||||
<if test="appTypeName != null and appTypeName != ''"> and app_type_name like concat(#{appTypeName}, '%')</if> | |||||
<if test="appName != null and appName != ''"> and app_name like concat(#{appName}, '%')</if> | |||||
<if test="appId != null and appId != ''"> and app_id = #{appId}</if> | |||||
<if test="status != null and status != ''"> and status = #{status}</if> | |||||
<if test="statusName != null and statusName != ''"> and status_name like concat(#{statusName}, '%')</if> | |||||
<if test="planId != null and planId != ''"> and plan_id = #{planId}</if> | |||||
</where> | </where> | ||||
ORDER BY create_time desc | |||||
</select> | </select> | ||||
</mapper> | </mapper> |
@@ -57,6 +57,8 @@ | |||||
<result property="deptId" column="dept_id"/> | <result property="deptId" column="dept_id"/> | ||||
<!-- 部门名称 --> | <!-- 部门名称 --> | ||||
<result property="deptName" column="dept_name"/> | <result property="deptName" column="dept_name"/> | ||||
<!-- 是否启用 --> | |||||
<result property="enabled" column="enabled"/> | |||||
<!-- 创建者 --> | <!-- 创建者 --> | ||||
<result property="createBy" column="create_by"/> | <result property="createBy" column="create_by"/> | ||||
<!-- 创建时间 --> | <!-- 创建时间 --> | ||||
@@ -100,6 +102,7 @@ | |||||
plan.time_saving,<!-- 节约时间 --> | plan.time_saving,<!-- 节约时间 --> | ||||
plan.dept_id,<!-- 部门id --> | plan.dept_id,<!-- 部门id --> | ||||
plan.dept_name,<!-- 部门名称 --> | plan.dept_name,<!-- 部门名称 --> | ||||
plan.enabled,<!-- 是否启用 --> | |||||
plan.create_by,<!-- 创建者 --> | plan.create_by,<!-- 创建者 --> | ||||
plan.create_time,<!-- 创建时间 --> | plan.create_time,<!-- 创建时间 --> | ||||
plan.update_by,<!-- 更新者 --> | plan.update_by,<!-- 更新者 --> | ||||
@@ -93,7 +93,7 @@ public abstract class AbstractQuartzJob implements Job | |||||
} | } | ||||
// 写入数据库当中 | // 写入数据库当中 | ||||
SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); | |||||
// SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); | |||||
} | } | ||||
/** | /** | ||||