c4cd8b6f5d
- 新增CurveCache实现Redis曲线数据缓存与分布式锁机制,避免重复请求 - 增加CurveHandler支持目标曲线接口,通过EQ API获取并缓存曲线数据 - Config新增EqualizeConfig配置,支持环境变量动态配置 - Repository新增CurveRepository,按brand和name查询模型与目标曲线数据 - 路由更新,集成/getCurve接口处理目标曲线请求 - OTA模型字段优化,bool类型改为BoolInt,实现数据库int与JSON bool映射 - 统一响应格式,调整response包中OK和Fail函数消息字段命名 - 修改服务端配置默认DB IP,支持Equalize参数传递到路由层 - 新增CSV解析实现,从文件读取测量与目标曲线数据 - 修改OTA处理逻辑,修复定向升级判断bug - Java层新增EqualizeController和ModelService对应功能,保持客户端接口兼容与调用逻辑一致
155 lines
5.1 KiB
Java
155 lines
5.1 KiB
Java
package com.luxsin.app.controller;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.luxsin.app.annotation.Base64Response;
|
|
import com.luxsin.app.bean.OTA;
|
|
import com.luxsin.app.service.BrandService;
|
|
import com.luxsin.app.service.ModelService;
|
|
import com.luxsin.app.service.OTAService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.eafon.data.EResponseTool;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import java.time.LocalDate;
|
|
import java.util.Map;
|
|
|
|
@Slf4j
|
|
@RestController
|
|
@CrossOrigin(origins = "*")
|
|
public class EqualizeController {
|
|
private final ModelService modelService;
|
|
|
|
private final OTAService otaService;
|
|
|
|
private final RedisTemplate<String, String> redisTemplate;
|
|
|
|
private final BrandService brandService;
|
|
public EqualizeController(ModelService modelService, OTAService otaService, RedisTemplate<String, String> redisTemplate, BrandService brandService) {
|
|
this.modelService = modelService;
|
|
this.otaService = otaService;
|
|
this.redisTemplate = redisTemplate;
|
|
this.brandService = brandService;
|
|
}
|
|
|
|
/**
|
|
* 耳机列表
|
|
* @param key
|
|
* @param count
|
|
* @return
|
|
*/
|
|
@GetMapping("modelList")
|
|
@Base64Response
|
|
public String getModelList(String key, @RequestParam(value = "count", defaultValue = "100") int count){
|
|
return modelService.modelList(key, count);
|
|
}
|
|
|
|
/**
|
|
* 目标曲线
|
|
* @param brand
|
|
* @param name
|
|
* @param target
|
|
* @return
|
|
*/
|
|
@GetMapping("getCurve")
|
|
@Base64Response
|
|
public String getCurve(String brand, String name, String target, @RequestParam(value = "includeRaw", defaultValue = "false") boolean includeRaw){
|
|
String result = modelService.getCurvePoint(brand, name, target);
|
|
if(!includeRaw){
|
|
JSONObject resp = JSONUtil.parseObj(result);
|
|
if(resp.containsKey("code") && resp.getInt("code") != 0){
|
|
resp.remove("fr");
|
|
}
|
|
return resp.toString();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@GetMapping("modelCurve")
|
|
@Base64Response
|
|
public String modelCurve(String brand, String name){
|
|
return modelService.getModelCurve(brand, name);
|
|
}
|
|
|
|
@GetMapping("test/modelCurve")
|
|
public String testModelCurve(String brand, String name){
|
|
return modelService.getModelCurve(brand, name);
|
|
}
|
|
|
|
@GetMapping("test/getCurve")
|
|
public String testGetCurve(String brand, String name, String target,
|
|
@RequestParam(value = "includeRaw", defaultValue = "false") boolean includeRaw){
|
|
String result = modelService.getCurvePoint(brand, name, target);
|
|
if(!includeRaw){
|
|
JSONObject resp = JSONUtil.parseObj(result);
|
|
if(resp.containsKey("code") && resp.getInt("code") != 0){
|
|
resp.remove("fr");
|
|
}
|
|
return resp.toString();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 升级
|
|
* @param model
|
|
* @param hw
|
|
* @param mac
|
|
* @param beta
|
|
* @return
|
|
*/
|
|
@GetMapping("ota")
|
|
public EResponseTool<OTA> OTA(String model, String hw, @RequestParam(value = "mac", defaultValue = "null") String mac,
|
|
@RequestParam(value = "beta", defaultValue = "0") int beta){
|
|
return otaService.getOTA(model, hw, mac, beta);
|
|
}
|
|
|
|
/**
|
|
* 上报用户设备信息
|
|
* @param mac
|
|
* @param model
|
|
* @return
|
|
*/
|
|
@GetMapping("reportDevInfo")
|
|
public EResponseTool<String> reportDevInfo(String mac, String model,String ver,
|
|
@RequestHeader(value = "X-Forwarded-For", required = false) String xForwardedFor){
|
|
if(StrUtil.isEmpty(mac) || StrUtil.isEmpty(model)){
|
|
return EResponseTool.error(EResponseTool.ResultCode.VALIDATE_FAILED);
|
|
}
|
|
log.info("report dev info remote ip = {}, now time = {}", xForwardedFor, DateUtil.now());
|
|
ver = null == ver ? "" : ver;
|
|
xForwardedFor = null == xForwardedFor ? "" : xForwardedFor;
|
|
|
|
redisTemplate.opsForHash().put("devices", mac, JSONUtil.toJsonStr(Map.of("mac_addr", mac, "model", model,
|
|
"active_date", LocalDate.now().toString(),
|
|
"ip_addr", xForwardedFor,
|
|
"ver", ver)));
|
|
return EResponseTool.success();
|
|
}
|
|
|
|
/**
|
|
* 获取品牌列表
|
|
* @param brandName
|
|
* @return
|
|
*/
|
|
@GetMapping("getBrand")
|
|
@Base64Response
|
|
public String getBrand(String brandName){
|
|
return brandService.brandList(brandName);
|
|
}
|
|
|
|
/**
|
|
* 获取型号列表
|
|
* @param brandName
|
|
* @param modelName
|
|
* @return
|
|
*/
|
|
@GetMapping("getModel")
|
|
@Base64Response
|
|
public String getModel(String brandName, String modelName){
|
|
return modelService.getModels(brandName, modelName);
|
|
}
|
|
}
|