|
|
@@ -1,5 +1,8 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.nacos.common.utils.MD5Utils;
|
|
|
@@ -7,6 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.codec.digest.HmacAlgorithms;
|
|
|
+import org.apache.commons.codec.digest.HmacUtils;
|
|
|
+import org.apache.commons.lang.RandomStringUtils;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
@@ -17,8 +23,7 @@ import org.springblade.manager.dto.ProfilerOffsetResultDTO;
|
|
|
import org.springblade.manager.entity.ProfilerData;
|
|
|
import org.springblade.manager.entity.ProfilerOffset;
|
|
|
import org.springblade.manager.entity.ProfilerStandardSectionBean;
|
|
|
-import org.springblade.manager.entity.profiler.ProfilerResult;
|
|
|
-import org.springblade.manager.entity.profiler.ProfilerSaveDTO;
|
|
|
+import org.springblade.manager.entity.profiler.*;
|
|
|
import org.springblade.manager.service.ProfilerDataService;
|
|
|
import org.springblade.manager.service.ProfilerOffsetService;
|
|
|
import org.springblade.manager.mapper.ProfilerOffsetMapper;
|
|
|
@@ -29,9 +34,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.Instant;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author LHB
|
|
|
@@ -62,12 +67,12 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
if (!save.getAppKey().equals(APP_KEY)) {
|
|
|
return ProfilerResult.error("10006", "appKey错误", "");
|
|
|
}
|
|
|
- String s = MD5Utils.md5Hex(APP_KEY + APP_SECRET + save.getTimestamp(), "UTF-8");
|
|
|
+ String s = MD5Utils.md5Hex(APP_KEY + APP_SECRET + save.getTimestamp(), "UTF-8");
|
|
|
if (!s.equals(save.getSign())) {
|
|
|
return ProfilerResult.error("10007", "sign错误", "");
|
|
|
}
|
|
|
- if(!isValidTimestamp(save.getTimestamp())){
|
|
|
- return ProfilerResult.error("10008","签名验证失败:timeTicks的时间和当前时间必须小于30分钟","");
|
|
|
+ if (!isValidTimestamp(save.getTimestamp())) {
|
|
|
+ return ProfilerResult.error("10008", "签名验证失败:timeTicks的时间和当前时间必须小于30分钟", "");
|
|
|
}
|
|
|
|
|
|
//主键id
|
|
|
@@ -79,18 +84,18 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
try {
|
|
|
jsonObject = JSONUtil.parseObj(save.getData());
|
|
|
} catch (Exception e) {
|
|
|
- return ProfilerResult.error("10009","data参数格式错误","");
|
|
|
+ return ProfilerResult.error("10009", "data参数格式错误", "");
|
|
|
}
|
|
|
//获取基础信息 + 测量者信息
|
|
|
ProfilerOffset offset = jsonObject.getBean("offset", ProfilerOffset.class);
|
|
|
- if(offset == null){
|
|
|
+ if (offset == null) {
|
|
|
offset = new ProfilerOffset();
|
|
|
}
|
|
|
offset.setId(id);
|
|
|
offset.setDeviceCode(deviceCode);
|
|
|
ProfilerOffset info = jsonObject.getBean("info", ProfilerOffset.class);
|
|
|
//把测量者信息赋值给基础信息对象
|
|
|
- if(info != null){
|
|
|
+ if (info != null) {
|
|
|
offset.setChannelName(info.getChannelName());
|
|
|
offset.setConstructionUnit(info.getConstructionUnit());
|
|
|
offset.setDate(info.getDate());
|
|
|
@@ -101,10 +106,10 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
//获取标准断面数据
|
|
|
JSONObject mStandardSectionDataBeanList = jsonObject.getJSONObject("standardSectionBean");
|
|
|
List<ProfilerStandardSectionBean> standardSectionBean = null;
|
|
|
- if(mStandardSectionDataBeanList != null){
|
|
|
+ if (mStandardSectionDataBeanList != null) {
|
|
|
standardSectionBean = mStandardSectionDataBeanList.getBeanList("mStandardSectionDataBeanList", ProfilerStandardSectionBean.class);
|
|
|
- if(standardSectionBean != null){
|
|
|
- standardSectionBean.forEach(f ->{
|
|
|
+ if (standardSectionBean != null) {
|
|
|
+ standardSectionBean.forEach(f -> {
|
|
|
f.setId(SnowFlakeUtil.getId());
|
|
|
f.setOffsetId(id);
|
|
|
});
|
|
|
@@ -112,7 +117,7 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
}
|
|
|
//获取测量数据
|
|
|
List<ProfilerData> data = jsonObject.getBeanList("data", ProfilerData.class);
|
|
|
- if(data != null){
|
|
|
+ if (data != null) {
|
|
|
data.forEach(f -> {
|
|
|
f.setId(SnowFlakeUtil.getId());
|
|
|
f.setOffsetId(id);
|
|
|
@@ -126,10 +131,10 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
}
|
|
|
//保存数据
|
|
|
baseMapper.insert(offset);
|
|
|
- if(CollectionUtil.isNotEmpty(standardSectionBean)){
|
|
|
+ if (CollectionUtil.isNotEmpty(standardSectionBean)) {
|
|
|
beanService.saveBatch(standardSectionBean);
|
|
|
}
|
|
|
- if(CollectionUtil.isNotEmpty(data)){
|
|
|
+ if (CollectionUtil.isNotEmpty(data)) {
|
|
|
dataService.saveBatch(data);
|
|
|
}
|
|
|
return ProfilerResult.success();
|
|
|
@@ -154,9 +159,9 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
@Override
|
|
|
public ProfilerOffsetResultDTO getOne(Long id) {
|
|
|
ProfilerOffset byId = this.getById(id);
|
|
|
- if(byId != null){
|
|
|
+ if (byId != null) {
|
|
|
ProfilerOffsetResultDTO resultDTO = BeanUtil.copyProperties(byId, ProfilerOffsetResultDTO.class);
|
|
|
- if(resultDTO != null){
|
|
|
+ if (resultDTO != null) {
|
|
|
List<ProfilerStandardSectionBean> list = beanService.list(Wrappers.<ProfilerStandardSectionBean>lambdaQuery().eq(ProfilerStandardSectionBean::getOffsetId, id));
|
|
|
List<ProfilerData> list1 = dataService.list(Wrappers.<ProfilerData>lambdaQuery().eq(ProfilerData::getOffsetId, id));
|
|
|
resultDTO.setSectionBeans(list);
|
|
|
@@ -174,11 +179,11 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
boolean update = this.updateById(qProfilerOffset);
|
|
|
|
|
|
List<ProfilerStandardSectionBean> sectionBeans = offset.getSectionBeans();
|
|
|
- if(CollectionUtil.isNotEmpty(sectionBeans)){
|
|
|
+ if (CollectionUtil.isNotEmpty(sectionBeans)) {
|
|
|
beanService.updateBatchById(sectionBeans);
|
|
|
}
|
|
|
List<ProfilerData> data = offset.getData();
|
|
|
- if(CollectionUtil.isNotEmpty(data)){
|
|
|
+ if (CollectionUtil.isNotEmpty(data)) {
|
|
|
dataService.updateBatchById(data);
|
|
|
}
|
|
|
return update;
|
|
|
@@ -192,13 +197,92 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
.eq(StringUtil.isNotBlank(offset.getBackBreak()), ProfilerOffset::getBackBreak, offset.getBackBreak())
|
|
|
.ge(StringUtil.isNotBlank(offset.getStartTime()), ProfilerOffset::getDate, offset.getStartTime())
|
|
|
.le(StringUtil.isNotBlank(offset.getEndTime()), ProfilerOffset::getDate, offset.getEndTime());
|
|
|
- return baseMapper.selectPage(new Page<>(offset.getCurrent(), offset.getSize()),qProfilerOffsetQueryWrapper);
|
|
|
+ return baseMapper.selectPage(new Page<>(offset.getCurrent(), offset.getSize()), qProfilerOffsetQueryWrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<String> getListUserName() {
|
|
|
return baseMapper.getListUserName();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void push() {
|
|
|
+ String baseUrl = "";
|
|
|
+ String url = "/data/openapi/v1/push";
|
|
|
+ //第三方提供的key
|
|
|
+ String clientKey = "";
|
|
|
+ String secret = "";
|
|
|
+ //推送接口 应用id
|
|
|
+ String protocolApiId = "1976105951096934401";
|
|
|
+ //当前时间戳
|
|
|
+ String secTimestamp = String.valueOf(System.currentTimeMillis());
|
|
|
+ //随机字符串
|
|
|
+ String secNonce = RandomStringUtils.randomAlphanumeric(15);
|
|
|
+
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ List<ProfilerOffset> list = this.list(Wrappers.<ProfilerOffset>lambdaQuery().eq(ProfilerOffset::getPush, 0));
|
|
|
+ List<ProfilerOffsetPush> resultDTO = new ArrayList<>();
|
|
|
+ list.forEach(f -> {
|
|
|
+ //获取测量断面
|
|
|
+ List<ProfilerStandardSectionBean> sectionBeans = beanService.list(Wrappers.<ProfilerStandardSectionBean>lambdaQuery().eq(ProfilerStandardSectionBean::getOffsetId, f.getId()));
|
|
|
+ List<ProfilerSectionPush> sectionPushes = ProfilerSectionPush.parameterMapping(sectionBeans);
|
|
|
+ //获取测量数据
|
|
|
+ List<ProfilerData> data = dataService.list(Wrappers.<ProfilerData>lambdaQuery().eq(ProfilerData::getOffsetId, f.getId()));
|
|
|
+ List<ProfilerDataPush> dataPushes = ProfilerDataPush.parameterMapping(data);
|
|
|
+
|
|
|
+ //赋值
|
|
|
+ ProfilerOffsetPush profilerOffsetPush = ProfilerOffsetPush.parameterMapping(f);
|
|
|
+ profilerOffsetPush.setMeasurement_section(sectionPushes);
|
|
|
+ profilerOffsetPush.setReceipt_data(dataPushes);
|
|
|
+ resultDTO.add(profilerOffsetPush);
|
|
|
+ });
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ //
|
|
|
+ jsonObject.set("protocolApiId", protocolApiId);
|
|
|
+ jsonObject.set("data", JSONUtil.toJsonStr(resultDTO));
|
|
|
+
|
|
|
+ //数据json字符串
|
|
|
+ String catLog = jsonObject.toString();
|
|
|
+ //http对象
|
|
|
+ HttpRequest post = HttpUtil.createPost(baseUrl + url);
|
|
|
+ //获取签名字符串
|
|
|
+ String sign = buildStringToSign(post, secTimestamp, secNonce);
|
|
|
+
|
|
|
+ //请求头
|
|
|
+ HashMap<String, String> catLogHeaders = new HashMap<>();
|
|
|
+ catLogHeaders.put("Content-Type", "application/json");
|
|
|
+ //应用ID
|
|
|
+ catLogHeaders.put("Sec-API-Key", clientKey);
|
|
|
+ //当前时间 毫秒值
|
|
|
+ catLogHeaders.put("Sec-Timestamp", secTimestamp);
|
|
|
+ //请求发起时的随机字符串,需要保证唯一性
|
|
|
+ catLogHeaders.put("Sec-Nonce", secNonce);
|
|
|
+ //签名
|
|
|
+ catLogHeaders.put("Sec-Signature", new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secret).hmacHex(sign));
|
|
|
+
|
|
|
+ String catLogBody = post.addHeaders(catLogHeaders).body(catLog).contentType("application/json").execute().body();
|
|
|
+ //响应结果
|
|
|
+ JSONObject result = JSONUtil.parseObj(catLogBody);
|
|
|
+ if ("200".equals(result.getStr("code"))) {
|
|
|
+ list.forEach(f -> f.setPush(1));
|
|
|
+ } else {
|
|
|
+ list.forEach(f -> f.setPush(2));
|
|
|
+ }
|
|
|
+ this.updateBatchById(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static String buildStringToSign(HttpRequest request, String timestamp, String nonce) {
|
|
|
+ return request.getMethod() +
|
|
|
+ "_" +
|
|
|
+ URLUtil.getPath(request.getUrl()) +
|
|
|
+ "_" +
|
|
|
+ timestamp +
|
|
|
+ "_" +
|
|
|
+ nonce;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|