15 changed files with 450 additions and 27 deletions
@ -0,0 +1,41 @@ |
|||
package com.ccsens.ptos_tall.api; |
|||
|
|||
import com.ccsens.ptos_tall.bean.dto.BusinessDto; |
|||
import com.ccsens.ptos_tall.bean.dto.TaskDto; |
|||
import com.ccsens.ptos_tall.bean.vo.TaskVo; |
|||
import com.ccsens.ptos_tall.service.ITaskService; |
|||
import com.ccsens.util.JsonResponse; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.annotation.Resource; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
@Api(tags = "任务相关" , description = " ") |
|||
@RestController |
|||
@RequestMapping("/task") |
|||
@Slf4j |
|||
public class TaskController { |
|||
@Resource |
|||
private ITaskService taskService; |
|||
|
|||
@ApiOperation(value = "查找用户在本域所有服务内的所有任务", notes = "") |
|||
@RequestMapping(value = "/allTask", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
|||
public JsonResponse<List<TaskVo.QueryTask>> queryAllTaskByUserId(@ApiParam @Validated @RequestBody TaskDto.QueryAllTask params) throws Exception{ |
|||
log.info("查找用户在本域所有服务内的所有任务:{}",params); |
|||
List<TaskVo.QueryTask> queryTasks = taskService.queryAllTaskByUserId(params); |
|||
log.info("返回用户在本域所有服务内的所有任务"); |
|||
return JsonResponse.newInstance().ok(queryTasks); |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.ccsens.ptos_tall.bean.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
@Data |
|||
public class TaskDto { |
|||
|
|||
@Data |
|||
@ApiModel("查找用户的所有任务") |
|||
public static class QueryAllTask { |
|||
@ApiModelProperty("userId") |
|||
private Long userId; |
|||
@ApiModelProperty("手机号") |
|||
private String phone; |
|||
@ApiModelProperty("codes") |
|||
private List<String> codes; |
|||
@ApiModelProperty("时间基准点 默认当前") |
|||
private Long timeNode = System.currentTimeMillis(); |
|||
@ApiModelProperty("时间颗粒度 默认天") |
|||
private int timeUnit = 4; |
|||
@ApiModelProperty("0向上查找 1向下查找(默认) 下查包含自己,上查不包含") |
|||
private int queryType = 1; |
|||
@ApiModelProperty("第几页") |
|||
private Integer pageNum = 1; |
|||
@ApiModelProperty("每页几条信息") |
|||
private Integer pageSize = 10; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,116 @@ |
|||
package com.ccsens.ptos_tall.bean.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
@Data |
|||
public class TaskVo { |
|||
@Data |
|||
@ApiModel("查看定期任务返回值") |
|||
public static class QueryTask{ |
|||
@ApiModelProperty("任务id(任务分解id)") |
|||
private Long id; |
|||
@ApiModelProperty("详情id") |
|||
private Long detailId; |
|||
@ApiModelProperty("任务名") |
|||
private String name; |
|||
@ApiModelProperty("任务详情") |
|||
private String description; |
|||
@ApiModelProperty("计划开始时间") |
|||
private Long planStart; |
|||
@ApiModelProperty("计划时长") |
|||
private Long planDuration; |
|||
@ApiModelProperty("计划结束时长") |
|||
private Long planEnd; |
|||
@ApiModelProperty("实际开始时间") |
|||
private Long realStart; |
|||
@ApiModelProperty("实际时长") |
|||
private Long realDuration; |
|||
@ApiModelProperty("实际结束时长") |
|||
private Long realEnd; |
|||
@ApiModelProperty("任务状态 0未开始 1进行中 2暂停中 3已完成") |
|||
private int process; |
|||
@ApiModelProperty("任务流转策略 -1不跳转 0直接跳转 如果是其他正整数 就是多少毫秒后跳转 ") |
|||
private Long skip; |
|||
@ApiModelProperty("跳转的任务id") |
|||
private Long skipTaskId; |
|||
@ApiModelProperty("任务面板") |
|||
private PanelInfo panel; |
|||
@ApiModelProperty("检查人列表") |
|||
private List<CheckerOfTask> checkerList; |
|||
@ApiModelProperty("插件") |
|||
private List<List<TaskPluginInfo>> plugins; |
|||
|
|||
@ApiModelProperty("项目id") |
|||
private Long projectId; |
|||
@ApiModelProperty("负责人id") |
|||
private Long executorRoleId; |
|||
@ApiModelProperty("所属服务的code") |
|||
private String businessCode; |
|||
@ApiModelProperty("服务的url") |
|||
private String businessUrl; |
|||
} |
|||
|
|||
@Data |
|||
@ApiModel("任务下的检查人") |
|||
public static class CheckerOfTask { |
|||
@ApiModelProperty("角色id") |
|||
private Long roleId; |
|||
@ApiModelProperty("名字") |
|||
private String name; |
|||
} |
|||
|
|||
@Data |
|||
@ApiModel("任务面板信息") |
|||
public static class PanelInfo{ |
|||
@ApiModelProperty("背景色") |
|||
private String backgroundColor; |
|||
@ApiModelProperty("圆角") |
|||
private String borderRadius; |
|||
@ApiModelProperty("边框") |
|||
private String border; |
|||
@ApiModelProperty("阴影") |
|||
private String shadow; |
|||
@ApiModelProperty("宽") |
|||
private String width; |
|||
@ApiModelProperty("高") |
|||
private String height; |
|||
@ApiModelProperty("行") |
|||
private int row; |
|||
@ApiModelProperty("列") |
|||
private int col; |
|||
} |
|||
|
|||
@Data |
|||
@ApiModel("任务下的插件信息") |
|||
public static class TaskPluginInfo{ |
|||
@ApiModelProperty("插件任务关联id") |
|||
private Long pluginTaskId; |
|||
@ApiModelProperty("插件id") |
|||
private Long pluginId; |
|||
@ApiModelProperty("插件和服务关联的id") |
|||
private Long businessPluginId; |
|||
@ApiModelProperty("插件code") |
|||
private String pluginCode; |
|||
@ApiModelProperty("是否是内置组件 0否 1是") |
|||
private Byte inner; |
|||
@ApiModelProperty("参数") |
|||
private String param; |
|||
@ApiModelProperty("行") |
|||
private int row; |
|||
@ApiModelProperty("列") |
|||
private int col; |
|||
@ApiModelProperty("跨行") |
|||
private int rowspan; |
|||
@ApiModelProperty("跨列") |
|||
private int colspan; |
|||
@ApiModelProperty("插件在时间轴的展示信息") |
|||
private String data; |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.ccsens.ptos_tall.service; |
|||
|
|||
import com.ccsens.ptos_tall.bean.dto.TaskDto; |
|||
import com.ccsens.ptos_tall.bean.vo.TaskVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
public interface ITaskService { |
|||
|
|||
/** |
|||
* 查找用户在服务下的所有任务 |
|||
* @param params useId和时间等 |
|||
* @return 返回任务列表 |
|||
*/ |
|||
List<TaskVo.QueryTask> queryAllTaskByUserId(TaskDto.QueryAllTask params); |
|||
} |
@ -0,0 +1,93 @@ |
|||
package com.ccsens.ptos_tall.service; |
|||
|
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.ccsens.ptos_tall.bean.dto.ProjectDto; |
|||
import com.ccsens.ptos_tall.bean.dto.TaskDto; |
|||
import com.ccsens.ptos_tall.bean.po.OpenBusiness; |
|||
import com.ccsens.ptos_tall.bean.po.OpenBusinessExample; |
|||
import com.ccsens.ptos_tall.bean.vo.ProjectVo; |
|||
import com.ccsens.ptos_tall.bean.vo.TaskVo; |
|||
import com.ccsens.ptos_tall.persist.mapper.OpenBusinessMapper; |
|||
import com.ccsens.ptos_tall.util.PtOsConstant; |
|||
import com.ccsens.util.RestTemplateUtil; |
|||
import com.ccsens.util.WebConstant; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Propagation; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) |
|||
public class TaskService implements ITaskService { |
|||
|
|||
@Resource |
|||
private OpenBusinessMapper businessMapper; |
|||
|
|||
@Override |
|||
public List<TaskVo.QueryTask> queryAllTaskByUserId(TaskDto.QueryAllTask params) { |
|||
List<TaskVo.QueryTask> allTask = new ArrayList<>(); |
|||
|
|||
//根据code查询服务
|
|||
//查询本域所有在线的业务信息
|
|||
Long lastAnswerTime = System.currentTimeMillis() - PtOsConstant.LAST_ANSWER_TIME; |
|||
OpenBusinessExample businessExample = new OpenBusinessExample(); |
|||
if(CollectionUtil.isEmpty(params.getCodes())) { |
|||
businessExample.createCriteria().andLastAnswerTimeGreaterThanOrEqualTo(lastAnswerTime).andTypeEqualTo((byte) 0); |
|||
}else { |
|||
businessExample.createCriteria().andLastAnswerTimeGreaterThanOrEqualTo(lastAnswerTime).andTypeEqualTo((byte) 0).andCodeIn(params.getCodes()); |
|||
} |
|||
List<OpenBusiness> openBusinessList = businessMapper.selectByExample(businessExample); |
|||
//循环调用服务内的接口查询任务信息
|
|||
//遍历业务
|
|||
if(CollectionUtil.isNotEmpty(openBusinessList)){ |
|||
for (OpenBusiness business : openBusinessList) { |
|||
String url = business.getUrl() + "/tall/task/allTask"; |
|||
log.info("调用接口:{}--", url); |
|||
String postBody = null; |
|||
try{ |
|||
postBody = RestTemplateUtil.postBody(url, params); |
|||
}catch (Exception e){ |
|||
log.error("查询任务列表--" + business.getName() + e); |
|||
} |
|||
if(StrUtil.isBlank(postBody)){ |
|||
continue; |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(postBody); |
|||
log.info("接口返回:{}", jsonObject); |
|||
//请求正确返回则修改最后应答时间,否则无操作
|
|||
Integer code = jsonObject.getInteger("code"); |
|||
if (code == null || code != 200) { |
|||
continue; |
|||
} |
|||
JSONArray data = jsonObject.getJSONArray("data"); |
|||
if(CollectionUtil.isNotEmpty(data)){ |
|||
for (Object object : data) { |
|||
TaskVo.QueryTask queryTask; |
|||
try { |
|||
JSONObject object1 = (JSONObject) object; |
|||
queryTask = object1.toJavaObject(TaskVo.QueryTask.class); |
|||
allTask.add(queryTask); |
|||
}catch (Exception e){ |
|||
log.error("项目转换失败"+e); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return allTask; |
|||
} |
|||
} |
Loading…
Reference in new issue