@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.csb.sdk.* ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.njcn.common.pojo.exception.BusinessException ;
import com.njcn.oss.utils.FileStorageUtil ;
@@ -76,12 +77,12 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
private final UserFeignClient userFeignClient ;
@Override
public boolean pushPlan ( List < String > planIds ) {
public String pushPlan ( List < String > planIds ) {
LambdaQueryWrapper < SupvPlan > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . in ( SupvPlan : : getPlanId , planIds ) ;
List < SupvPlan > supvPlanList = supvPlanMapper . selectList ( lambdaQueryWrapper ) ;
if ( CollUtil . isEmpty ( supvPlanList ) ) {
return false ;
return " 为查询数据,请查询数据是否存在! " ;
}
List < PvTerminalTreeVO > deptList = deptFeignClient . allDeptList ( ) . getData ( ) ;
Map < String , PvTerminalTreeVO > mapCode = deptList . stream ( ) . collect ( Collectors . toMap ( PvTerminalTreeVO : : getCode , Function . identity ( ) ) ) ;
@@ -102,7 +103,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
List < DictData > supvVoltageDicList = dicDataFeignClient . getDicDataByTypeCode ( DicDataTypeEnum . DEV_VOLTAGE . getCode ( ) ) . getData ( ) ;
Map < String , DictData > mapVoltage = supvVoltageDicList . stream ( ) . collect ( Collectors . toMap ( DictData : : getId , Function . identity ( ) ) ) ;
List < String > userIds = supvPlanList . stream ( ) . map ( SupvPlan : : getUpd ateBy ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < String > userIds = supvPlanList . stream ( ) . map ( SupvPlan : : getCre ateBy ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < User > userList = userFeignClient . getUserByIdList ( userIds ) . getData ( ) ;
Map < String , User > map = userList . stream ( ) . collect ( Collectors . toMap ( User : : getId , Function . identity ( ) ) ) ;
@@ -202,33 +203,40 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
SendParam param = new SendParam ( ) ;
param . setStats ( supvPlanList ) ;
param . setProvinceId ( " 13B9B47F1E483324E05338297A0A0595 " ) ;
String s = JSON . toJSONString( param ) ;
String s = JSONObject . toJSONStringWithDateFormat ( param , JSON . DEFFAULT_DATE_FORMAT ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 接收电能质量技术监督工作计划数据接口数据: " + s + " 结束----! " ) ;
// Map< String, String> send = send(param, getUrl(1), " pqPlanCreate") ;
// log.info(Thread.currentThread().getName() + "获取返回体 接收电能质量技术监督工作计划数据接口响应结果:" + send + "结束----! " );
// if (send.containsKey("succeed")) {
// String succeed = send.get("succeed");
// String replace = succeed.replace("\\\"", "\"") ;
// Map mapData = JSON.parseObject(replace, Map.class);
// String status = mapData.get("status").toString() ;
// if ("000000".equals(status)) {
// for (SupvPlan supvPlan : supvPlanList) {
// SupvPlan supvPlanPO = new SupvPlan() ;
// supvPlanPO.setPlanId(supvPlan.getPlanId());
// supvPlanPO.setIsUploadHead(1);
// s upvPlanMapper.updateById(supvPlanPO) ;
// }
// } else {
// return false ;
// }
// } else {
// return false ;
// }
return true ;
Map< String, String > send = send ( param , getUrl ( 1 ) , " pqPlanCreate" ) ;
// Map<String, String> send = new HashMap<>( );
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 接收电能质量技术监督工作计划数据接口响应结果: " + send + " 结束----! " ) ;
if ( send . containsKey ( " succeed " ) ) {
String succeed = send . get ( " succeed " ) ;
if ( succeed . indexOf ( " \\ \" " ) ! = - 1 ) {
succeed = succeed . replace ( " \\ \" " , " \" " ) ;
}
Map mapData = JSON . parseObject ( succeed , Map . class ) ;
String status = mapData . get ( " status " ) . toString ( ) ;
if ( " 000000 " . equals ( status ) ) {
for ( SupvPlan supvPlan : supvPlanList ) {
S upvPlan supvPlanPO = new SupvPlan ( ) ;
supvPlanPO . setPlanId ( supvPlan . getPlanId ( ) ) ;
supvPlanPO . setIsUploadHead ( 1 ) ;
supvPlanMapper . updateById ( supvPlanPO ) ;
}
String result = mapData . get ( " result " ) . toString ( ) ;
Map mapCount = JSON . parseObject ( result , Map . class ) ;
String count = mapCount . get ( " count " ) . toString ( ) ;
return " 操作成功:成功数据 " + count + " 条 " ;
} else {
String errors = mapData . get ( " errors " ) . toString ( ) ;
return " 操作失败: " + status + " _ " + errors ;
}
} else {
return " 出现未知错误 " ;
}
}
@Override
public boolean pushQuestion ( List < String > problemIds ) {
public String pushQuestion ( List < String > problemIds , Integer type ) {
LambdaQueryWrapper < SupvProblem > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . in ( SupvProblem : : getProblemId , problemIds ) ;
List < SupvProblem > supvProblemList = supvProblemMapper . selectList ( lambdaQueryWrapper ) ;
@@ -270,35 +278,49 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
SendParam param = new SendParam ( ) ;
param . setStats ( supvProblemList ) ;
param . setProvinceId ( " 13B9B47F1E483324E05338297A0A0595 " ) ;
String s = JSON . toJSONString( param ) ;
String s = JSONObject . toJSONStringWithDateFormat ( param , JSON . DEFFAULT_DATE_FORMAT ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 删除电能质量技术监督工作计划接口数据: " + s + " 结束----! " ) ;
// Map< String, String> send = send(param, getUrl(2), "pqProblemCreate") ;
// Map<String, String> send2 = send(param, getUrl(3), "pqProblemUpdate");
// log.info(Thread.currentThread().getName() + "获取返回体 接收电能质量技术监督实施问题数据接口响应结果:" + send + "结束----! ") ;
// log.info( Thread. currentThread().getName() + " 获取返回体 接收电能质量技术监督实施问题整改 数据接口响应结果:" + send2 + "结束----! ") ;
// if (send.containsKey("succeed")) {
// String succeed = send.get("succeed") ;
// String replace = succeed.replace("\\\"", "\"") ;
// Map map = JSON.parseObject(replace, Map.class) ;
// String status = map.get("status").toString();
// if ("000000".equals(status)) {
// for (SupvProblem supvProblem : supvProblemList) {
// SupvProblem supvProblemPO = new SupvProblem();
// supvProblemPO.setProblemId(supvProblem.getProblemId()) ;
// supvProblemPO.setIsUploadHead(1);
// supvProblemMapper.updateById(supvProblemPO) ;
// }
// } else {
// return false ;
// }
// } else {
// return false ;
// }
return true ;
Map< String, String > send ;
if ( type = = 0 ) {
send = send ( param , getUrl ( 2 ) , " pqProblemCreate " ) ;
log. info ( Thread. currentThread( ) . getName ( ) + " 获取返回体 接收电能质量技术监督实施问题数据接口响应结果:" + send + " 结束----! " ) ;
} else {
System . out . println ( 1 ) ;
send = send ( param , getUrl ( 3 ) , " pqProblemUpdate " ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 接收电能质量技术监督实施问题整改数据接口响应结果: " + send + " 结束----! " ) ;
}
// Map<String, String> send = new HashMap<>();
if ( send . containsKey ( " succeed " ) ) {
String succeed = send . get ( " succeed " ) ;
if ( succeed . indexOf ( " \\ \" " ) ! = - 1 ) {
succeed = succeed . replace ( " \\ \" " , " \" " ) ;
}
Map map = JSON . parseObject ( succeed , Map . class ) ;
String status = map . get ( " status " ) . toString ( ) ;
if ( " 000000 " . equals ( status ) ) {
for ( SupvProblem supvProblem : supvProblemList ) {
SupvProblem supvProblemPO = new SupvProblem ( ) ;
supvProblemPO . setProblemId ( supvProblem . getProblemId ( ) ) ;
supvProblemPO . setIsUploadHead ( 1 ) ;
supvProblemMapper . updateById ( supvProblemPO ) ;
}
String result = map . get ( " result " ) . toString ( ) ;
Map mapCount = JSON . parseObject ( result , Map . class ) ;
String count = mapCount . get ( " count " ) . toString ( ) ;
return " 操作成功:成功数据 " + count + " 条 " ;
} else {
String errors = map . get ( " errors " ) . toString ( ) ;
return " 操作失败: " + status + " _ " + errors ;
}
} else {
return " 出现未知错误 " ;
}
}
@Override
public boolean pushFile ( List < String > busIds ) throws IOException {
public String pushFile ( List < String > busIds ) throws IOException {
StringBuilder stringBuilder = new StringBuilder ( ) ;
LambdaQueryWrapper < SupvFile > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . in ( SupvFile : : getBusiId , busIds ) ;
List < SupvFile > supvFiles = supvFileMapper . selectList ( lambdaQueryWrapper ) ;
@@ -309,14 +331,35 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
String s = objects . toString ( ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 推送附件接口: " + s + " 结束----! " ) ;
//TODO 调用上送接口
// for (SupvFile supvFile : supvFiles) {
// Map map = post FileUrl (getUrl(4), null, supvFile);
// }
return true ;
for ( int i = 0 ; i < supvFiles . size ( ) ; i + + ) {
// Map<String, String> sendFile = send File(getUrl(4), supvFiles.get(i) );
Map < String , String > sendFile = new HashMap < > ( ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 总部提供附件接收接口,省公司调用此接口,完成附件上报响应结果: " + sendFile + " 结束----! " ) ;
if ( sendFile . containsKey ( " succeed " ) ) {
String succeed = sendFile . get ( " succeed " ) ;
if ( succeed . indexOf ( " \\ \" " ) ! = - 1 ) {
succeed = succeed . replace ( " \\ \" " , " \" " ) ;
}
Map map = JSON . parseObject ( succeed , Map . class ) ;
String status = map . get ( " status " ) . toString ( ) ;
if ( " 000000 " . equals ( status ) ) {
String result = map . get ( " result " ) . toString ( ) ;
Map mapCount = JSON . parseObject ( result , Map . class ) ;
String count = mapCount . get ( " count " ) . toString ( ) ;
stringBuilder . append ( " 第 " + i + " 次操作成功:成功数据 " + count + " 条 " ) ;
} else {
String errors = map . get ( " errors " ) . toString ( ) ;
stringBuilder . append ( " 第 " + i + " 次操作失败: " + status + " _ " + errors ) ;
}
} else {
stringBuilder . append ( " 第 " + i + " 次出现未知错误 " ) ;
}
}
return stringBuilder . toString ( ) ;
}
@Override
public boolean pushMonthReportStatistic ( List < String > monthReportId ) {
public String pushMonthReportStatistic ( List < String > monthReportId ) {
LambdaQueryWrapper < SupvReportM > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . in ( SupvReportM : : getMonthReportId , monthReportId ) ;
List < SupvReportM > supvReportMList = supvReportMMapper . selectList ( lambdaQueryWrapper ) ;
@@ -328,34 +371,40 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
SendParam param = new SendParam ( ) ;
param . setStats ( supvReportMList ) ;
param . setProvinceId ( " 13B9B47F1E483324E05338297A0A0595 " ) ;
String s = JSON . toJSONString( param ) ;
String s = JSONObject . toJSONStringWithDateFormat ( param , JSON . DEFFAULT_DATE_FORMAT ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 取消电能质量技术监督工作计划接口数据: " + s + " 结束----! " ) ;
// Map< String, String> send = send(param, getUrl(5), " pqMonthReportCreate") ;
// log.info(Thread.currentThread().getName() + "获取返回体 取消电能质量技术监督工作计划接口响应结果:" + s + "结束----! " );
// if (send.containsKey("succeed")) {
// String succeed = send.get("succeed");
// String replace = succeed.replace("\\\"", "\"") ;
// Map map = JSON.parseObject(replace, Map.class);
// String status = map.get("status").toString() ;
// if ("000000".equals(status)) {
// for (SupvReportM supvReportM : supvReportMList) {
// SupvReportM supvReportMPO = new SupvReportM() ;
// supvReportMPO.setMonthReportId(supvReportM.getMonthReportId());
// supvReportMPO.setIsUploadHead(1);
// s upvReportMMapper.updateById(s upvReportMPO) ;
// }
// } else {
// return false ;
// }
//
// } else {
// return false ;
// }
return true ;
Map< String, String > send = send ( param , getUrl ( 5 ) , " pqMonthReportCreate" ) ;
// Map<String, String> send = new HashMap<>( );
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 取消电能质量技术监督工作计划接口响应结果: " + s + " 结束----! " ) ;
if ( send . containsKey ( " succeed " ) ) {
String succeed = send . get ( " succeed " ) ;
if ( succeed . indexOf ( " \\ \" " ) ! = - 1 ) {
succeed = succeed . replace ( " \\ \" " , " \" " ) ;
}
Map map = JSON . parseObject ( succeed , Map . class ) ;
String status = map . get ( " status " ) . toString ( ) ;
if ( " 000000 " . equals ( status ) ) {
for ( SupvReportM supvReportM : supvReportMList ) {
S upvReportM supvReportMPO = new S upvReportM( ) ;
supvReportMPO . setMonthReportId ( supvReportM . getMonthReportId ( ) ) ;
supvReportMPO . setIsUploadHead ( 1 ) ;
supvReportMMapper . updateById ( supvReportMPO ) ;
}
String result = map . get ( " result " ) . toString ( ) ;
Map mapCount = JSON . parseObject ( result , Map . class ) ;
String count = mapCount . get ( " count " ) . toString ( ) ;
return " 操作成功:成功数据 " + count + " 条 " ;
} else {
String errors = map . get ( " errors " ) . toString ( ) ;
return " 操作失败: " + status + " _ " + errors ;
}
} else {
return " 出现未知错误 " ;
}
}
@Override
public boolean deletePlan ( List < String > planIds ) {
public String deletePlan ( List < String > planIds ) {
//判断是否已经取消上送
LambdaQueryWrapper < SupvPlan > supvPlanLambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
supvPlanLambdaQueryWrapper . in ( SupvPlan : : getIsUploadHead , Stream . of ( 0 , 2 ) . collect ( Collectors . toList ( ) ) ) . in ( SupvPlan : : getPlanId , planIds ) ;
@@ -376,27 +425,34 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
SendParam param = new SendParam ( ) ;
param . setStats ( supvPlanList ) ;
param . setProvinceId ( " 13B9B47F1E483324E05338297A0A0595 " ) ;
String s = JSON . toJSONString( param ) ;
String s = JSONObject . toJSONStringWithDateFormat ( param , JSON . DEFFAULT_DATE_FORMAT ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 删除电能质量技术监督工作计划接口数据: " + s + " 结束----! " ) ;
// Map< String, String> send = send(param, getUrl(6), " pqPlanDelete") ;
// log.info(Thread.currentThread().getName() + "获取返回体 删除电能质量技术监督工作计划接口响应结果:" + s + "结束----! " );
// if (send.containsKey("succeed")) {
// String succeed = send.get("succeed");
// String replace = succeed.replace("\\\"", "\"") ;
// Map map = JSON.parseObject(replace, Map.class);
// String status = map.get("status").toString() ;
// if ("000000".equals(status)) {
// for (SupvPlan supvPlan : supvPlanList) {
// supvPlan.setIsUploadHead(2) ;
// supvPlanMapper.updateById(supvPlan);
// }
// } else {
// return false ;
// }
// } else {
// return false ;
// }
return true ;
Map< String, String > send = send ( param , getUrl ( 6 ) , " pqPlanDelete" ) ;
// Map<String, String> send = new HashMap<>( );
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取返回体 删除电能质量技术监督工作计划接口响应结果: " + s + " 结束----! " ) ;
if ( send . containsKey ( " succeed " ) ) {
String succeed = send . get ( " succeed " ) ;
if ( succeed . indexOf ( " \\ \" " ) ! = - 1 ) {
succeed = succeed . replace ( " \\ \" " , " \" " ) ;
}
Map map = JSON . parseObject ( succeed , Map . class ) ;
String status = map . get ( " status " ) . toString ( ) ;
if ( " 000000 " . equals ( status ) ) {
for ( SupvPlan supvPlan : supvPlanList ) {
supvPlan . setIsUploadHead ( 2 ) ;
supvPlanMapper . updateById ( supvPlan ) ;
}
String result = map . get ( " result " ) . toString ( ) ;
Map mapCount = JSON . parseObject ( result , Map . class ) ;
String countNum = mapCount . get ( " count " ) . toString ( ) ;
return " 操作成功:成功数据 " + countNum + " 条 " ;
} else {
String errors = map . get ( " errors " ) . toString ( ) ;
return " 操作失败: " + status + " _ " + errors ;
}
} else {
return " 出现未知错误 " ;
}
}
public static Map < String , String > send ( SendParam param , String url , String serviceName ) {
@@ -407,7 +463,6 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
} else {
String s = JSON . toJSONString ( param ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 1.信息: " + JSON . toJSONString ( param ) ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 2.信息: " + s ) ;
cb = new ContentBody ( s ) ;
}
//ContentBody传递, 要求使用post方式进行调用
@@ -424,7 +479,6 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
builder . contentBody ( cb ) ;
String token = LoginToken ( ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 3.错误信息: " + token ) ;
builder . putHeaderParamsMap ( " x-token " , token ) ;
builder . putHeaderParamsMap ( " serviceName " , serviceName ) ;
//进行调用,返回结果
@@ -461,6 +515,72 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
return token ;
}
public Map < String , String > sendFile ( String url , SupvFile supvFile ) throws IOException {
String path = supvFile . getFileUrl ( ) ;
if ( StrUtil . isBlank ( path ) ) {
throw new BusinessException ( " 获取文件上传路径为空!请检查原始路径是否存在 " ) ;
}
String attachmentName = supvFile . getAttachmentName ( ) ;
if ( StrUtil . isNotBlank ( attachmentName ) ) {
int i = attachmentName . lastIndexOf ( " . " ) ;
if ( i ! = - 1 ) {
attachmentName = attachmentName . substring ( 0 , i ) ;
}
} else {
throw new BusinessException ( " 不存在文件,文件名称 " ) ;
}
InputStream fileStream = fileStorageUtil . getFileStream ( path ) ;
if ( ObjectUtil . isNull ( fileStream ) ) {
throw new BusinessException ( " 文件服务器,文件不存在 " ) ;
}
Map < String , String > map = new LinkedHashMap < > ( ) ;
//ContentBody传递, 要求使用post方式进行调用
//如果需要传递请求参数 可以拼接到请求URL中, 或者设置paramsMap参数由SDK内部进行拼接
HttpParameters . Builder builder = HttpParameters . newBuilder ( ) ;
builder . requestURL ( " http://25.36.214.86:32234/CSB/WMCenter/powerQuality/file/create " ) // 设置请求的URL,可以拼接URL请求参数
. api ( " zongbuSync " ) // 设置服务名
. version ( " 1.0.0 " ) // 设置版本号
. method ( " post " ) // 设置调用方式, 必须为 post
. contentType ( " application/x-www-form-urlencoded;charset=utf-8 " ) //设置请求content-type
. accessKey ( " 7d4cb2c0afb5468ca56e0654b1a442ef " ) . secretKey ( " lW2xr6zKjbaqVDOSgQpcGrM6Rg0= " ) ; // 设置accessKey 和 设置secretKey
String token = LoginToken ( ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 3.错误信息: " + token ) ;
builder . putHeaderParamsMap ( " x-token " , token ) ;
builder . putHeaderParamsMap ( " serviceName " , " pqFileCreate " ) ;
String uploadTime = supvFile . getUploadTime ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd HH:mm:ss " ) ) ;
// 设置form请求参数
builder . putParamsMap ( " uuid " , supvFile . getFileUrl ( ) )
. putParamsMap ( " attachmentName " , supvFile . getAttachmentName ( ) )
. putParamsMap ( " provinceId " , " 13B9B47F1E483324E05338297A0A0595 " )
. putParamsMap ( " attachmentType " , supvFile . getAttachmentType ( ) )
. putParamsMap ( " busiId " , supvFile . getBusiId ( ) )
. putParamsMap ( " uploaderName " , supvFile . getUploaderName ( ) )
. putParamsMap ( " uploadTime " , uploadTime )
. putParamsMap ( " uploaderId " , supvFile . getUploaderId ( ) ) ;
//设置上传文件
builder . addAttachFile ( " file " , attachmentName , fileStream ) ;
//进行调用,返回结果
try {
HttpReturn ret = HttpCaller . invokeReturn ( builder . build ( ) ) ;
String responseStr = ret . getResponseStr ( ) ; //获取响应的文本串
map . put ( " succeed " , responseStr ) ;
} catch ( HttpCallerException e ) {
// error process
log . info ( Thread . currentThread ( ) . getName ( ) + " 错误信息: " + e ) ;
map . put ( " error " , e . toString ( ) ) ;
}
return map ;
}
/**
* 文件上送提交
*