Преглед изворни кода

Merge branch 'refs/heads/feature-lihb-20251029-push' into dev

LHB пре 2 дана
родитељ
комит
1076f9efc6

+ 12 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/ProfilerOffset.java

@@ -119,6 +119,18 @@ public class ProfilerOffset {
     @ApiModelProperty("文件地址")
     private String fileUrl;
 
+    /**
+     * 是否推送(0-未推送,1-已推送,2-推送失败)
+     */
+    @ApiModelProperty("是否推送(0-未推送,1-已推送,2-推送失败)")
+    private Integer push;
+
+    /**
+     * 推送时间
+     */
+    @ApiModelProperty("推送时间")
+    private LocalDateTime pushTime;
+
     /**
      *  创建时间
      */

+ 59 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/profiler/ProfilerDataPush.java

@@ -0,0 +1,59 @@
+package org.springblade.manager.entity.profiler;
+
+import com.alibaba.druid.util.StringUtils;
+import lombok.Data;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.manager.entity.ProfilerData;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author LHB
+ * 断面仪 测量数据推送对象
+ */
+@Data
+public class ProfilerDataPush {
+    /**
+     * 测点
+     */
+    private String measurement_point;
+    /**
+     * 距离
+     */
+    private String distance;
+    /**
+     * x坐标
+     */
+    private String x_coordinate;
+    /**
+     * z坐标
+     */
+    private String z_coordinate;
+    /**
+     * 超挖值(米)
+     */
+    private String overbreak_value;
+    /**
+     * 欠挖值(米)
+     */
+    private String underbreak_value;
+    public static List<ProfilerDataPush> parameterMapping(List<ProfilerData> data) {
+        return data.stream().map(f -> {
+            ProfilerDataPush sectionPush = new ProfilerDataPush();
+            sectionPush.setMeasurement_point(f.getAngle());
+            sectionPush.setDistance(f.getDist());
+            sectionPush.setX_coordinate(f.getX());
+            sectionPush.setZ_coordinate(f.getZ());
+            if(StringUtil.isNotBlank(f.getBackBreak()) && StringUtils.isNumber(f.getBackBreak())){
+                if(Double.parseDouble(f.getBackBreak()) >= 0){
+                    sectionPush.setOverbreak_value(f.getBackBreak());
+
+                }else{
+                    sectionPush.setUnderbreak_value(f.getBackBreak());
+                }
+            }
+            return sectionPush;
+        }).collect(Collectors.toList());
+    }
+}

+ 66 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/profiler/ProfilerOffsetPush.java

@@ -0,0 +1,66 @@
+package org.springblade.manager.entity.profiler;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import lombok.Data;
+import org.springblade.manager.entity.ProfilerOffset;
+
+import java.util.List;
+
+/**
+ * @author LHB
+ * 断面仪 基础信息推送对象
+ */
+@Data
+public class ProfilerOffsetPush {
+    /**
+     * 上传时间 yyyy-MM-dd
+     */
+    private String report_date;
+    /**
+     * 测量时间 yyyy-MM-dd HH:mm:ss
+     */
+    private String measurement_time;
+    /**
+     * 测量人
+     */
+    private String measurement_person;
+    /**
+     * 桩号
+     */
+    private String pile_number;
+    /**
+     * x方向偏移量(米)
+     */
+    private String x_offset;
+    /**
+     * y方向偏移量(米)
+     */
+    private String y_offset;
+    /**
+     * 仪器高度(米)
+     */
+    private String instrument_height;
+    /**
+     * 测量断面
+     */
+    private List<ProfilerSectionPush> measurement_section;
+    /**
+     * 测量数据
+     */
+    private List<ProfilerDataPush> receipt_data;
+
+
+
+    public static ProfilerOffsetPush parameterMapping(ProfilerOffset push) {
+        ProfilerOffsetPush profilerOffsetPush = new ProfilerOffsetPush();
+        profilerOffsetPush.setReport_date(DateUtil.format(DateTime.now(),"yyyy-MM-dd"));
+        profilerOffsetPush.setMeasurement_time(push.getDate());
+        profilerOffsetPush.setMeasurement_person(push.getUserName());
+        profilerOffsetPush.setPile_number(null);
+        profilerOffsetPush.setX_offset(push.getX0());
+        profilerOffsetPush.setY_offset(push.getZ0());
+        profilerOffsetPush.setInstrument_height(push.getDeviceHeight());
+        return profilerOffsetPush;
+    }
+}

+ 52 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/profiler/ProfilerSectionPush.java

@@ -0,0 +1,52 @@
+package org.springblade.manager.entity.profiler;
+
+import lombok.Data;
+import org.springblade.manager.entity.ProfilerStandardSectionBean;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author LHB
+ * 断面仪 测量断面推送对象
+ */
+@Data
+public class ProfilerSectionPush {
+    /**
+     * 方向
+     */
+    private String direction;
+    /**
+     * 终角
+     */
+    private String final_angle;
+    /**
+     * 起角
+     */
+    private String start_angle;
+    /**
+     * 半径
+     */
+    private String radius;
+    /**
+     * 圆心X
+     */
+    private String center_x;
+    /**
+     * 圆心Y
+     */
+    private String center_y;
+
+    public static List<ProfilerSectionPush> parameterMapping(List<ProfilerStandardSectionBean> sectionBeans) {
+        return sectionBeans.stream().map(f -> {
+            ProfilerSectionPush sectionPush = new ProfilerSectionPush();
+            sectionPush.setDirection(f.getDirection());
+            sectionPush.setFinal_angle(f.getEndAngle());
+            sectionPush.setStart_angle(f.getStartAngle());
+            sectionPush.setRadius(f.getRadius());
+            sectionPush.setCenter_x(f.getX());
+            sectionPush.setCenter_y(f.getY());
+            return sectionPush;
+        }).collect(Collectors.toList());
+    }
+}

+ 9 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ProfilerController.java

@@ -16,6 +16,7 @@ import org.springblade.manager.service.ProfilerOffsetService;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 
 /**
@@ -97,4 +98,12 @@ public class ProfilerController {
         return R.data(offsetService.getListUserName());
     }
 
+    /**
+     * 推送接口
+     */
+    @GetMapping("/push")
+    public R push(){
+        offsetService.push();
+        return R.success("正在推送中");
+    }
 }

+ 4 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/ProfilerOffsetService.java

@@ -7,6 +7,7 @@ import org.springblade.manager.entity.ProfilerOffset;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springblade.manager.entity.profiler.ProfilerResult;
 import org.springblade.manager.entity.profiler.ProfilerSaveDTO;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -27,4 +28,7 @@ public interface ProfilerOffsetService extends IService<ProfilerOffset> {
     Page<ProfilerOffset> getPage(ProfilerOffsetDTO offset);
 
     List<String> getListUserName();
+
+    @Async
+    void push();
 }

+ 156 - 23
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ProfilerOffsetServiceImpl.java

@@ -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,21 +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.Collections;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author LHB
@@ -39,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 {
 
@@ -54,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
@@ -79,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());
@@ -101,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);
                 });
@@ -112,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);
@@ -126,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();
@@ -154,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);
@@ -174,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;
@@ -192,13 +205,133 @@ 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)
+    @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);
+    }
 }