|
|
@@ -1,5 +1,11 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
+import cn.hutool.http.HttpException;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONConfig;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.nacos.common.utils.MD5Utils;
|
|
|
@@ -7,6 +13,10 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
+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,20 +27,23 @@ 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;
|
|
|
import org.springblade.manager.service.ProfilerStandardSectionBeanService;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springframework.dao.DataAccessException;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
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.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author LHB
|
|
|
@@ -38,6 +51,7 @@ import java.util.List;
|
|
|
* @createDate 2025-10-27 15:58:56
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper, ProfilerOffset>
|
|
|
implements ProfilerOffsetService {
|
|
|
|
|
|
@@ -53,20 +67,20 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
private ProfilerDataService dataService;
|
|
|
@Resource
|
|
|
private ProfilerStandardSectionBeanService beanService;
|
|
|
-
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ProfilerResult save(ProfilerSaveDTO save, MultipartFile file) {
|
|
|
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
|
|
|
@@ -78,18 +92,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());
|
|
|
@@ -100,10 +114,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);
|
|
|
});
|
|
|
@@ -111,7 +125,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);
|
|
|
@@ -125,10 +139,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();
|
|
|
@@ -153,9 +167,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);
|
|
|
@@ -173,11 +187,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;
|
|
|
@@ -188,9 +202,135 @@ public class ProfilerOffsetServiceImpl extends ServiceImpl<ProfilerOffsetMapper,
|
|
|
QueryWrapper<ProfilerOffset> qProfilerOffsetQueryWrapper = new QueryWrapper<>();
|
|
|
qProfilerOffsetQueryWrapper.lambda()
|
|
|
.eq(StringUtil.isNotBlank(offset.getUserName()), ProfilerOffset::getUserName, offset.getUserName())
|
|
|
+ .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)
|
|
|
+ @Scheduled(cron = "0 0 23 ? * FRI")
|
|
|
+ public void push() {
|
|
|
+ String url = "/data/openapi/v1/push";
|
|
|
+
|
|
|
+
|
|
|
+ //从系统参数中获取配置信息
|
|
|
+ String sql = "select param_value from blade_param where param_key = 'profiler.isPush' and is_deleted = 0";
|
|
|
+ Integer isPush = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
|
+ //判断是否上传数据
|
|
|
+ if(isPush != null && isPush == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //从系统参数中获取配置信息
|
|
|
+ String baseUrl = null;
|
|
|
+ try {
|
|
|
+ sql = "select param_value from blade_param where param_key = 'profiler.baseUrl' and is_deleted = 0";
|
|
|
+ baseUrl = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ log.error("系统参数未找到 profiler.baseUrl");
|
|
|
+ }
|
|
|
+
|
|
|
+ String clientKey = null;
|
|
|
+ try {
|
|
|
+ sql = "select param_value from blade_param where param_key = 'profiler.clientKey' and is_deleted = 0";
|
|
|
+ //第三方提供的key
|
|
|
+ clientKey = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ log.error("系统参数未找到 profiler.clientKey");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String secret = null;
|
|
|
+ try {
|
|
|
+ sql = "select param_value from blade_param where param_key = 'profiler.secret' and is_deleted = 0";
|
|
|
+ //第三方提供的key
|
|
|
+ secret = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ log.error("系统参数未找到 profiler.secret");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String protocolApiId = null;
|
|
|
+ try {
|
|
|
+ sql = "select param_value from blade_param where param_key = 'profiler.protocolApiId' and is_deleted = 0";
|
|
|
+ //第三方提供的key
|
|
|
+ protocolApiId = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ log.error("系统参数未找到 profiler.protocolApiId");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(StringUtil.isBlank(baseUrl) || StringUtil.isBlank(clientKey) || StringUtil.isBlank(secret) || StringUtil.isBlank(protocolApiId)){
|
|
|
+ log.error("系统参数未找到配置项");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前时间戳
|
|
|
+ String secTimestamp = String.valueOf(System.currentTimeMillis());
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ List<ProfilerOffset> list = this.list(Wrappers.<ProfilerOffset>lambdaQuery().eq(ProfilerOffset::getPush, 0));
|
|
|
+ log.info("开始推送断面仪数据------{}", DateTime.now());
|
|
|
+ for (ProfilerOffset f : list) {
|
|
|
+ //随机字符串 每次推送都是唯一的
|
|
|
+ String secNonce = UUID.randomUUID().toString();
|
|
|
+ //获取测量断面
|
|
|
+ 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);
|
|
|
+ //设置不忽略空值
|
|
|
+ JSONConfig config = JSONConfig.create().setIgnoreNullValue(false);
|
|
|
+ JSONObject jsonObject = new JSONObject(config);
|
|
|
+ jsonObject.set("protocolApiId", protocolApiId);
|
|
|
+ jsonObject.set("data", profilerOffsetPush);
|
|
|
+
|
|
|
+ //数据json字符串
|
|
|
+ String catLog = jsonObject.toString();
|
|
|
+ //http对象
|
|
|
+ HttpRequest post = HttpUtil.createPost(baseUrl + url);
|
|
|
+ //获取签名字符串
|
|
|
+ String sign = "POST_" + url + "_" + 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));
|
|
|
+
|
|
|
+ try {
|
|
|
+ String catLogBody = post.addHeaders(catLogHeaders).body(catLog).contentType("application/json").execute().body();
|
|
|
+ //响应结果
|
|
|
+ JSONObject result = JSONUtil.parseObj(catLogBody);
|
|
|
+ log.info("推送结果:{}",result);
|
|
|
+ if ("200".equals(result.getStr("code"))) {
|
|
|
+ f.setPush(1);
|
|
|
+ } else {
|
|
|
+ f.setPush(2);
|
|
|
+ }
|
|
|
+ } catch (HttpException e) {
|
|
|
+ f.setPush(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("推送完成------{}", DateTime.now());
|
|
|
+ this.updateBatchById(list);
|
|
|
}
|
|
|
}
|
|
|
|