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;