소스 검색

质检-断面仪
1、推送接口开发(待完善)

LHB 1 주 전
부모
커밋
b03d51d0d9

+ 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();
 }

+ 105 - 21
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ProfilerOffsetServiceImpl.java

@@ -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;
+    }
 }