5 天以前 b5a87e4b0da54ad57f195e52cd06e7824e2e1f54
yys
1.app推送接口
2.数采缓存
3.数采历史数据
已添加5个文件
已修改7个文件
348 ■■■■■ 文件已修改
src/main/java/com/ruoyi/common/enums/FileNameType.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/http/service/controller/JclyController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/http/service/impl/RealTimeEnergyConsumptionServiceImpl.java 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/controller/PdaVersionController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/controller/TempFileController.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/mapper/PdaVersionMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/pojo/PdaVersion.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/pojo/TempFile.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/service/PdaVersionService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/service/impl/PdaVersionServiceImpl.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/pojo/CommonFile.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/common/enums/FileNameType.java
@@ -14,7 +14,8 @@
    SHIP(9),//发货台账
    INSPECTION_PRODUCTION_BEFORE(10),
    INSPECTION_PRODUCTION_AFTER(11),
    INSPECTION(12);//巡检 ç”Ÿäº§å‰
    INSPECTION(12),//巡检 ç”Ÿäº§å‰
    APP(13);
    private final int value;
src/main/java/com/ruoyi/http/service/controller/JclyController.java
@@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.naming.ldap.PagedResultsControl;
@@ -48,4 +49,15 @@
        return AjaxResult.success(maps);
    }
    /**
     * èŽ·å–åŽ†å²æ•°æ®
     */
    @GetMapping("/getHistoryData")
    public AjaxResult getHistoryData(@RequestParam(value = "guid") String guid,
                                     @RequestParam(value = "startTime") long startTime,
                                     @RequestParam(value = "endTime") long endTime) {
        List<Map<String,String>> maps = realTimeEnergyConsumptionService.getHistoryData(guid, startTime, endTime);
        return AjaxResult.success(maps);
    }
}
src/main/java/com/ruoyi/http/service/impl/RealTimeEnergyConsumptionServiceImpl.java
@@ -10,10 +10,13 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
 * @author :yys
@@ -23,11 +26,15 @@
@Slf4j
public class RealTimeEnergyConsumptionServiceImpl implements RealTimeEnergyConsumptionService {
    private static final long REMOTE_CACHE_TTL_SECONDS = 10L;
    private static final String URL = "https://new.e-elitech.cn/api/data-api";
    private static final String TOKEN_URL = "/elitechAccess/getToken";
    private static final String REAL_TIME_URL = "/elitechAccess/v2/getRealTimeData";
    private static final String REAL_HISTORY_URL = URL + "/elitechAccess/v2/getHistoryData";
    private static final String KET_ID = "75804708";
@@ -37,12 +44,13 @@
    private static final String PASS_WORD = "y17775163675";
    private static final String REAL_TIME_CACHE_PREFIX = "JCLY:REAL_TIME:";
    private static final String HISTORY_CACHE_PREFIX = "JCLY:HISTORY:";
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    /**
     * æ ¹æ® paramCode æå–探头参数。
     */
    private static JSONObject getProbeParam(JSONArray paramList, String targetCode) {
        if (paramList == null) {
            return new JSONObject();
@@ -56,9 +64,68 @@
        return new JSONObject();
    }
    /**
     * å®žæ—¶èŽ·å–æ¸©æ¹¿åº¦ã€å…‰ç…§ã€äºŒæ°§åŒ–ç¢³æ•°æ®ã€‚
     */
    public List<Map<String, String>> getHistoryData(String guid, long startTime, long endTime) {
        List<Map<String, String>> resultList = new ArrayList<>();
        String historyData = requestHistoryData(getToken(), guid, startTime, endTime);
        Map<String, Object> resultMap = JSON.parseObject(historyData, Map.class);
        if (!Integer.valueOf(0).equals(resultMap.get("code"))) {
            return resultList;
        }
        JSONArray historyList = JSON.parseArray(String.valueOf(resultMap.get("data")));
        if (historyList == null || historyList.isEmpty()) {
            return resultList;
        }
        for (int i = 0; i < historyList.size(); i++) {
            JSONObject historyObj = historyList.getJSONObject(i);
            Map<String, String> historyItem = new HashMap<>();
            historyItem.put("guid", firstNonBlank(
                    historyObj.getString("deviceGuid"),
                    historyObj.getString("guid"),
                    guid
            ));
            historyItem.put("subUId", stringValue(historyObj.get("subUid")));
            historyItem.put("monitorTimeStamp", stringValue(historyObj.get("monitorTimeStamp")));
            historyItem.put("monitorTimeStr", historyObj.getString("monitorTimeStr"));
            historyItem.put("position", historyObj.getString("position"));
            historyItem.put("address", historyObj.getString("address"));
            JSONArray paramList = historyObj.getJSONArray("data");
            if (paramList != null && !paramList.isEmpty()) {
                for (int j = 0; j < paramList.size(); j++) {
                    JSONObject paramObj = paramList.getJSONObject(j);
                    String paramName = paramObj.getString("paramName");
                    String paramCode = paramObj.getString("paramCode");
                    String value = paramObj.getString("value");
                    String unitCode = paramObj.getString("unitCode");
                    String fullValue = value == null ? null : value + (unitCode == null ? "" : unitCode);
                    switch (paramName) {
                        case "探头1":
                            historyItem.put("light", fullValue);
                            break;
                        case "探头2":
                            historyItem.put("temperature", fullValue);
                            break;
                        case "探头3":
                            historyItem.put("humidity", fullValue);
                            break;
                        case "探头4":
                            historyItem.put("co2", fullValue);
                            break;
                        default:
                            if (paramCode != null) {
                                historyItem.put(paramCode, fullValue);
                            }
                            break;
                    }
                }
            }
            resultList.add(historyItem);
        }
        return resultList;
    }
    public List<Map<String, String>> getRealData(List<String> guidList) {
        log.info("开始获取实时数据");
        List<Map<String, String>> listMaps = new ArrayList<>();
@@ -78,6 +145,15 @@
            JSONObject deviceObj = deviceList.getJSONObject(deviceIndex);
            JSONArray paramList = deviceObj.getJSONArray("data");
            Map<String, String> deviceData = new HashMap<>();
            String deviceGuid = firstNonBlank(
                    deviceObj.getString("deviceGuid"),
                    deviceObj.getString("guid"),
                    deviceObj.getString("devGuid"),
                    deviceObj.getString("sn")
            );
            if (deviceGuid != null) {
                deviceData.put("guid", deviceGuid);
            }
            for (String code : targetCodes) {
                JSONObject paramObj = getProbeParam(paramList, code);
                if (paramObj.isEmpty()) {
@@ -144,14 +220,61 @@
        return cleanedToken.isEmpty() ? null : cleanedToken;
    }
    public static String getRealTimeData(String token, List<String> guidList) {
    private String firstNonBlank(String... values) {
        for (String value : values) {
            if (value != null && !value.trim().isEmpty()) {
                return value;
            }
        }
        return null;
    }
    private String stringValue(Object value) {
        return value == null ? null : String.valueOf(value);
    }
    public String getRealTimeData(String token, List<String> guidList) {
        Map<String, Object> param = new HashMap<>();
        param.put("keyId", KET_ID);
        param.put("keySecret", KEY_SECRET);
        param.put("deviceGuids", guidList);
        log.info("请求参数:{}", JSON.toJSONString(param));
        String cacheKey = REAL_TIME_CACHE_PREFIX + JSON.toJSONString(param);
        String cachedResult = sanitizeToken(redisTemplate.opsForValue().get(cacheKey));
        if (cachedResult != null) {
            log.info("命中实时数据缓存:{}", cacheKey);
            return cachedResult;
        }
        String result = HttpUtils.sendPostJson(URL + REAL_TIME_URL, JSON.toJSONString(param), token);
        log.info("返回结果:{}", result);
        cacheRemoteResponse(cacheKey, result);
        return result;
    }
    public String requestHistoryData(String token, String guid, long startTime, long endTime) {
        Map<String, Object> param = new HashMap<>();
        param.put("keyId", KET_ID);
        param.put("keySecret", KEY_SECRET);
        param.put("deviceGuid", guid);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        log.info("历史数据请求参数:{}", JSON.toJSONString(param));
        String cacheKey = HISTORY_CACHE_PREFIX + JSON.toJSONString(param);
        String cachedResult = sanitizeToken(redisTemplate.opsForValue().get(cacheKey));
        if (cachedResult != null) {
            log.info("命中历史数据缓存:{}", cacheKey);
            return cachedResult;
        }
        String result = HttpUtils.sendPostJson(REAL_HISTORY_URL, JSON.toJSONString(param), token);
        log.info("历史数据返回结果:{}", result);
        cacheRemoteResponse(cacheKey, result);
        return result;
    }
    private void cacheRemoteResponse(String cacheKey, String result) {
        if (result == null || result.trim().isEmpty()) {
            return;
        }
        redisTemplate.opsForValue().set(cacheKey, result, REMOTE_CACHE_TTL_SECONDS, TimeUnit.SECONDS);
    }
}
src/main/java/com/ruoyi/other/controller/PdaVersionController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package com.ruoyi.other.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.other.pojo.PdaVersion;
import com.ruoyi.other.service.PdaVersionService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/app")
@AllArgsConstructor
public class PdaVersionController {
    private PdaVersionService pdaVersionService;
    @ApiOperation("查询所有版本")
    @GetMapping("/getAllVersion")
    public R getAllVersion(Page<PdaVersion> page, PdaVersion pdaVersion) {
        return R.ok(pdaVersionService.getAllVersion(page, pdaVersion));
    }
    @ApiOperation("上传apk")
    @PostMapping("/uploadApk")
    public R uploadApk(@RequestParam("file") MultipartFile file, String name, String version) {
        return R.ok(pdaVersionService.uploadApk(file, name, version));
    }
}
src/main/java/com/ruoyi/other/controller/TempFileController.java
@@ -4,8 +4,6 @@
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.other.service.TempFileService;
import com.ruoyi.purchase.dto.ProductRecordDto;
import com.ruoyi.purchase.dto.TicketRegistrationDto;
import com.ruoyi.purchase.service.ITicketRegistrationService;
import com.ruoyi.purchase.service.impl.TicketRegistrationServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
src/main/java/com/ruoyi/other/mapper/PdaVersionMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,9 @@
package com.ruoyi.other.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.other.pojo.PdaVersion;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PdaVersionMapper extends BaseMapper<PdaVersion> {
}
src/main/java/com/ruoyi/other/pojo/PdaVersion.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,60 @@
package com.ruoyi.other.pojo;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.sales.pojo.CommonFile;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
@Data
@TableName("pda_version")
@ApiModel(value = "PdaVersion", description = "PDA版本信息表")
public class PdaVersion implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("主键ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("版本号")
    private String version;
    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    @ApiModelProperty("创建人")
    @TableField(fill = FieldFill.INSERT)
    private Integer createUser;
    @ApiModelProperty("更新人")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateUser;
    @ApiModelProperty("租户ID")
    @TableField(fill = FieldFill.INSERT)
    private Long tenantId;
    @TableField(exist = false)
    private List<CommonFile> commonFileList;
    @TableField(fill = FieldFill.INSERT)
    private Long deptId;
}
src/main/java/com/ruoyi/other/pojo/TempFile.java
@@ -1,14 +1,18 @@
package com.ruoyi.other.pojo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@TableName("temp_file")
public class TempFile {
public class TempFile implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId
@@ -17,4 +21,12 @@
    private String tempPath;       // ä¸´æ—¶å­˜å‚¨è·¯å¾„
    private LocalDateTime expireTime; // è¿‡æœŸæ—¶é—´
    private Integer type;       // å…³è”表类型
    private Long fileSize;       // æ–‡ä»¶å¤§å°
    @ApiModelProperty(value = "创建用户")
    @TableField(fill = FieldFill.INSERT)
    private Integer createUser;
    @TableField(fill = FieldFill.INSERT)
    private Long deptId;
}
src/main/java/com/ruoyi/other/service/PdaVersionService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package com.ruoyi.other.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.other.pojo.PdaVersion;
import org.springframework.web.multipart.MultipartFile;
public interface PdaVersionService extends IService<PdaVersion> {
    IPage<PdaVersion> getAllVersion(Page<PdaVersion> page, PdaVersion pdaVersion);
    boolean uploadApk(MultipartFile file, String name, String version);
}
src/main/java/com/ruoyi/other/service/impl/PdaVersionServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,60 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.other.mapper.PdaVersionMapper;
import com.ruoyi.other.pojo.PdaVersion;
import com.ruoyi.other.service.PdaVersionService;
import com.ruoyi.other.service.TempFileService;
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class PdaVersionServiceImpl extends ServiceImpl<PdaVersionMapper, PdaVersion> implements PdaVersionService {
    private final PdaVersionMapper pdaVersionMapper;
    private final TempFileService tempFileService;
    private final CommonFileServiceImpl commonFileService;
    @Override
    public IPage<PdaVersion> getAllVersion(Page<PdaVersion> page, PdaVersion pdaVersion) {
        LambdaQueryWrapper<PdaVersion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(PdaVersion::getCreateTime);
        Page<PdaVersion> pdaVersionPage = pdaVersionMapper.selectPage(page, queryWrapper);
        pdaVersionPage.getRecords().forEach(item ->{
            item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.APP.getValue()));
        });
        return pdaVersionPage;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean uploadApk(MultipartFile file, String name, String version) {
        // å‚数校验
        Assert.notNull(file, "文件不能为空");
        Assert.hasText(version, "版本号不能为空");
        try {
            PdaVersion pdaVersion = new PdaVersion();
            pdaVersion.setName(name);
            pdaVersion.setVersion(version);
            pdaVersionMapper.insert(pdaVersion);
            tempFileService.uploadByCommon(file, FileNameType.APP.getValue(), pdaVersion.getId());
            return true;
        } catch (Exception e) {
            throw new RuntimeException("上传APK失败: " + e.getMessage());
        }
    }
}
src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
@@ -9,16 +9,13 @@
import com.ruoyi.sales.mapper.CommonFileMapper;
import com.ruoyi.sales.pojo.CommonFile;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.util.URLEncoder;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -76,6 +73,7 @@
        tempFileRecord.setTempPath(tempFilePath.toString());
        tempFileRecord.setExpireTime(LocalDateTime.now().plusHours(2)); // 2小时后过期
        tempFileRecord.setType(type);
        tempFileRecord.setFileSize(file.getSize());
        tempFileMapper.insert(tempFileRecord);
        return tempFileRecord;
    }
@@ -151,6 +149,7 @@
                fileRecord.setUrl(formalFilePath.toString());
                fileRecord.setCreateTime(LocalDateTime.now());
                fileRecord.setType(fileType);
                fileRecord.setFileSize(tempFile.getFileSize());
                commonFileMapper.insert(fileRecord);
                // åˆ é™¤ä¸´æ—¶æ–‡ä»¶è®°å½•
src/main/java/com/ruoyi/sales/pojo/CommonFile.java
@@ -30,6 +30,8 @@
    /** å…³è”表 */
    private Integer type;
    private Long fileSize;       // æ–‡ä»¶å¤§å°
    /** åˆ›å»ºæ—¶é—´ */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;