@ -1,5 +1,6 @@
package com.ccsens.ptos_zero.service ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.io.FileUtil ;
@ -8,9 +9,10 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.ccsens.ptos_zero.bean.po.ProRole ;
import com.ccsens.ptos_zero.bean.po.ProRoleExample ;
import com.ccsens.ptos_zero.bean.po.ProTaskSub ;
import com.ccsens.ptos_zero.bean.po.ProUser ;
import com.ccsens.ptos_zero.bean.vo.DeliverVo ;
import com.ccsens.ptos_zero.persist.dao.* ;
@ -18,6 +20,7 @@ import com.ccsens.ptos_zero.util.Constant;
import com.ccsens.ptos_zero.util.ZeroCodeError ;
import com.ccsens.util.CodeEnum ;
import com.ccsens.util.PropUtil ;
import com.ccsens.util.RestTemplateUtil ;
import com.ccsens.util.WebConstant ;
import com.ccsens.util.exception.BaseException ;
import com.ccsensptos.tallsdk.bean.dto.TallProjectDto ;
@ -681,65 +684,120 @@ public class TallService implements ITallService {
@Override
public PageInfo < TallTaskVo . QueryTask > pageQueryRegularTask ( String token , TallTaskDto . PageQueryRegularTask param ) {
//TODO 根据token获取用户信息
List < TallTaskVo . QueryTask > regularTask = new ArrayList < > ( ) ;
//根据token获取用户信息
TallTokenVo . UserIdByToken userByToken = TokenUtil . getUserByToken ( new TallTokenDto . GetUserByToken ( token , Constant . APP_ID , Constant . APP_SECRET ) ) ;
if ( ObjectUtil . isNull ( userByToken ) ) {
throw new BaseException ( CodeEnum . NOT_LOGIN ) ;
}
//通过手机号获取用户在服务内的userId
ProUser user = null ;
if ( ObjectUtil . isNotNull ( userByToken ) & & StrUtil . isNotBlank ( userByToken . getPhone ( ) ) ) {
user = userDao . getUserIdByPhone ( userByToken . getPhone ( ) ) ;
}
// if(ObjectUtil.isNull(user)){
// throw new BaseException(ZeroCodeError.NOT_USER_SERVER);
// }
//查询用的时间
Long queryTime = System . currentTimeMillis ( ) ;
if ( ObjectUtil . isNotNull ( param . getTaskId ( ) ) ) {
//根据任务id查找任务,以任务的开始时间当做查询的时间点
ProTaskSub proTaskSub = proTaskSubDao . selectByPrimaryKey ( param . getTaskId ( ) ) ;
if ( ObjectUtil . isNotNull ( proTaskSub ) & & proTaskSub . getPlanStartTime ( ) ! = 0L ) {
queryTime = proTaskSub . getPlanStartTime ( ) ;
//调用tall的接口查询所有的任务
String url = com . ccsensptos . tallsdk . util . Constant . GATEWAY_URL + com . ccsensptos . tallsdk . util . Constant . QUERY_ALL_TASK ;
log . info ( "调用接口:{}--" , url ) ;
//接口参数
TallTaskDto . QueryAllTask queryAllTask = new TallTaskDto . QueryAllTask ( ) ;
BeanUtil . copyProperties ( param , queryAllTask ) ;
queryAllTask . setPhone ( userByToken . getPhone ( ) ) ;
String postBody = null ;
try {
//请求接口
postBody = RestTemplateUtil . postBody ( url , queryAllTask ) ;
} catch ( Exception e ) {
log . error ( "查询所有任务--" + e ) ;
}
if ( StrUtil . isNotBlank ( postBody ) ) {
JSONObject jsonObject = JSONObject . parseObject ( postBody ) ;
log . info ( "接口返回:{}" , jsonObject ) ;
Integer code = jsonObject . getInteger ( "code" ) ;
if ( code ! = null & & code = = 200 ) {
JSONArray data = jsonObject . getJSONArray ( "data" ) ;
if ( CollectionUtil . isNotEmpty ( data ) ) {
for ( Object object : data ) {
TallTaskVo . QueryTask queryTask ;
try {
JSONObject object1 = ( JSONObject ) object ;
queryTask = object1 . toJavaObject ( TallTaskVo . QueryTask . class ) ;
regularTask . add ( queryTask ) ;
} catch ( Exception e ) {
log . error ( "项目转换失败" + e ) ;
}
}
}
}
} else {
if ( ObjectUtil . isNotNull ( param . getTimeNode ( ) ) ) {
//没有任务id则根据时间基准线查询当前正在进行的任务(如果多个则选择时间最早的一个)
Long startTime = proTaskSubDao . getTimeByProgressTask ( param . getTimeNode ( ) , param . getRoleId ( ) ) ;
if ( ObjectUtil . isNotNull ( startTime ) ) {
queryTime = startTime ;
}
List < TallTaskVo . QueryTask > tasks = new ArrayList < > ( ) ;
if ( CollectionUtil . isNotEmpty ( regularTask ) ) {
//给任务排序
regularTask . sort ( ( o1 , o2 ) - > {
Long x1 = o1 . getPlanStart ( ) ;
Long x2 = o2 . getPlanStart ( ) ;
int sComp = param . getQueryType ( ) = = 1 ? x1 . compareTo ( x2 ) : x2 . compareTo ( x1 ) ;
if ( sComp ! = 0 ) {
return sComp ;
} else {
Long a1 = o1 . getId ( ) ;
Long a2 = o2 . getId ( ) ;
return param . getQueryType ( ) = = 1 ? a1 . compareTo ( a2 ) : a2 . compareTo ( a1 ) ;
}
} else {
//如果没有时间基准线则按当前时间查询查询任务
Long startTime = proTaskSubDao . getTimeByProgressTask ( System . currentTimeMillis ( ) , param . getRoleId ( ) ) ;
if ( ObjectUtil . isNotNull ( startTime ) ) {
queryTime = startTime ;
} ) ;
//分页
for ( int i = 0 ; i < regularTask . size ( ) & & i < param . getPageSize ( ) ; i + + ) {
TallTaskVo . QueryTask queryTask = regularTask . get ( i ) ;
//TODO 给任务添加插件(本服务任务添加任务名插件,其他服务的任务添加跳转项目的插件)
List < List < TallTaskVo . TaskPluginInfo > > pluginRow = new ArrayList < > ( ) ;
List < TallTaskVo . TaskPluginInfo > pluginCol = new ArrayList < > ( ) ;
if ( Constant . BUSINESS_CODE . equals ( queryTask . getBusinessCode ( ) ) ) {
//任务名插件
TallTaskVo . TaskPluginInfo plugin = new TallTaskVo . TaskPluginInfo ( ) ;
plugin . setRow ( 1 ) ;
plugin . setCol ( 1 ) ;
plugin . setColspan ( 1 ) ;
plugin . setRowspan ( 1 ) ;
plugin . setPluginId ( 1L ) ;
plugin . setInner ( ( byte ) 1 ) ;
pluginCol . add ( plugin ) ;
} else {
//任务名插件
TallTaskVo . TaskPluginInfo plugin = new TallTaskVo . TaskPluginInfo ( ) ;
plugin . setRow ( 1 ) ;
plugin . setCol ( 1 ) ;
plugin . setColspan ( 1 ) ;
plugin . setRowspan ( 1 ) ;
plugin . setPluginId ( 24L ) ;
plugin . setInner ( ( byte ) 1 ) ;
pluginCol . add ( plugin ) ;
}
pluginRow . add ( pluginCol ) ;
queryTask . setPlugins ( pluginRow ) ;
tasks . add ( queryTask ) ;
}
}
//获取任务列表
PageHelper . startPage ( param . getPageNum ( ) , param . getPageSize ( ) ) ;
List < TallTaskVo . QueryTask > regularTask = taskDetailDao . pageQueryRegularTask ( param . getRoleId ( ) , queryTime , param . getTimeUnit ( ) , param . getQueryType ( ) ) ;
PageInfo < TallTaskVo . QueryTask > queryTaskPageInfo = new PageInfo < > ( regularTask ) ;
if ( CollectionUtil . isNotEmpty ( queryTaskPageInfo . getList ( ) ) ) {
if ( param . getQueryType ( ) = = 0 ) {
//向上查找任务顺序是倒的,需要改成正序
List < TallTaskVo . QueryTask > taskList = new ArrayList < > ( ) ;
for ( int i = queryTaskPageInfo . getList ( ) . size ( ) - 1 ; i > = 0 ; i - - ) {
taskList . add ( queryTaskPageInfo . getList ( ) . get ( i ) ) ;
}
queryTaskPageInfo . setList ( taskList ) ;
Collections . reverse ( tasks ) ;
}
//查询任务下的插件
queryPluginForTask ( queryTaskPageInfo . getList ( ) ) ;
//查询任务下的检查人
queryCheckerOfTask ( queryTaskPageInfo . getList ( ) ) ;
//TODO 查询插件展示信息
queryPluginShow ( queryTaskPageInfo . getList ( ) , user = = null ? null : user . getId ( ) ) ;
}
return queryTaskPageInfo ;
return new PageInfo < > ( tasks ) ;
}
@Override
public List < TallTaskVo . QueryTask > queryAllTask ( TallTaskDto . QueryAllTask param ) {
List < TallTaskVo . QueryTask > queryTaskList = null ;
//通过手机号查找服务内的用户
ProUser user = userDao . getUserIdByPhone ( param . getPhone ( ) ) ;
if ( ObjectUtil . isNull ( user ) ) {
return queryTaskList ;
}
//查找用户所属的成员,查找所属的角色
List < Long > roleList = roleDao . allRoleByUserId ( user . getId ( ) ) ;
if ( CollectionUtil . isNotEmpty ( roleList ) ) {
//通过角色和时间等信息,查找任务,如果传入的参数有任务id且code符合当前服务,则排除该任务
String taskId = Constant . BUSINESS_CODE . equals ( param . getBusinessCode ( ) ) ? param . getTaskId ( ) : null ;
PageHelper . startPage ( param . getPageNum ( ) , param . getPageSize ( ) ) ;
queryTaskList = taskDetailDao . getAllTaskByRoleList ( roleList , param . getTimeNode ( ) , param . getTimeUnit ( ) , param . getQueryType ( ) , taskId ) ;
}
return queryTaskList ;
}
}