Merge branch 'jackson'

This commit is contained in:
2025-07-27 14:23:21 +08:00
46 changed files with 805 additions and 254 deletions

17
pom.xml
View File

@@ -20,7 +20,6 @@
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
<hutool-all.version>5.8.24</hutool-all.version> <hutool-all.version>5.8.24</hutool-all.version>
<fastjson.version>1.2.83</fastjson.version>
<knife4j-spring-boot-starter.version>2.0.7</knife4j-spring-boot-starter.version> <knife4j-spring-boot-starter.version>2.0.7</knife4j-spring-boot-starter.version>
<pagehelper.version>5.3.1</pagehelper.version> <pagehelper.version>5.3.1</pagehelper.version>
<!--跳过单元测试--> <!--跳过单元测试-->
@@ -122,11 +121,19 @@
<artifactId>core</artifactId> <artifactId>core</artifactId>
<version>3.3.3</version> <version>3.3.3</version>
</dependency> </dependency>
<!-- json处理工具 -->
<!-- Jackson JSON处理库 -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>fastjson</artifactId> <artifactId>jackson-databind</artifactId>
<version>${fastjson.version}</version> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency> </dependency>
<!-- 引入commons-lang3 工具类 --> <!-- 引入commons-lang3 工具类 -->

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.aspectj; package com.ycwl.basic.aspectj;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.annotation.IgnoreLogReq; import com.ycwl.basic.annotation.IgnoreLogReq;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
@@ -67,10 +67,10 @@ public class RequestParameterAspectj {
} }
if (parameterUrlMap.isEmpty()) { if (parameterUrlMap.isEmpty()) {
LOGGER.info("当前请求的路径为-> {} 请求方式为-> {} 参数为-> {}", requestURI, method, JSON.toJSONString(parameterValueSet)); LOGGER.info("当前请求的路径为-> {} 请求方式为-> {} 参数为-> {}", requestURI, method, JacksonUtil.toJSONString(parameterValueSet));
} else { } else {
LOGGER.info("当前请求的路径为-> {} 请求方式为-> {} 参数为-> {} 路径传参为-> {}", requestURI, method, LOGGER.info("当前请求的路径为-> {} 请求方式为-> {} 参数为-> {} 路径传参为-> {}", requestURI, method,
JSON.toJSONString(parameterValueSet), JSON.toJSONString(parameterUrlMap)); JacksonUtil.toJSONString(parameterValueSet), JacksonUtil.toJSONString(parameterUrlMap));
} }
} }
return joinPoint.proceed(); return joinPoint.proceed();

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.controller.extern; package com.ycwl.basic.controller.extern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.annotation.IgnoreToken; import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.mapper.FaceMapper; import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.MemberMapper; import com.ycwl.basic.mapper.MemberMapper;
@@ -184,7 +184,7 @@ public class LyCompatibleController {
} }
String openId = headersMap.get("client"); String openId = headersMap.get("client");
if (redisTemplate.hasKey("ly:"+openId)) { if (redisTemplate.hasKey("ly:"+openId)) {
return JSON.parseObject(redisTemplate.opsForValue().get("ly:"+openId), R.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get("ly:"+openId), R.class);
} }
MemberRespVO member = memberMapper.getByOpenId(openId); MemberRespVO member = memberMapper.getByOpenId(openId);
if (member == null) { if (member == null) {
@@ -248,7 +248,7 @@ public class LyCompatibleController {
.put("face_id", faceVO.getId().toString()) .put("face_id", faceVO.getId().toString())
.put("newvideo", videoList) .put("newvideo", videoList)
.put("newuservideo", userVideoList); .put("newuservideo", userVideoList);
redisTemplate.opsForValue().set("ly:"+openId, JSON.toJSONString(response), 5, TimeUnit.SECONDS); redisTemplate.opsForValue().set("ly:"+openId, JacksonUtil.toJSONString(response), 5, TimeUnit.SECONDS);
log.info("> {}", response); log.info("> {}", response);
return response; return response;
} }

View File

@@ -3,7 +3,7 @@ package com.ycwl.basic.controller.viid;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadFactoryBuilder; import cn.hutool.core.thread.ThreadFactoryBuilder;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.annotation.IgnoreLogReq; import com.ycwl.basic.annotation.IgnoreLogReq;
import com.ycwl.basic.annotation.IgnoreToken; import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter; import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
@@ -377,7 +377,7 @@ public class ViidController {
String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename); String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename);
scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename); scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename);
source.setUrl(_sourceUrl); source.setUrl(_sourceUrl);
source.setPosJson(JSON.toJSONString(facePosition)); source.setPosJson(JacksonUtil.toJSONString(facePosition));
sourceMapper.add(source); sourceMapper.add(source);
} }
}); });

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.device.checker.helper; package com.ycwl.basic.device.checker.helper;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity; import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity; import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
import lombok.Setter; import lombok.Setter;
@@ -13,7 +13,7 @@ public abstract class CommonDeviceChecker<C> {
protected DeviceConfigEntity deviceConfig; protected DeviceConfigEntity deviceConfig;
public CommonDeviceChecker(String configJson) { public CommonDeviceChecker(String configJson) {
config = JSON.parseObject(configJson, getConfigClass()); config = JacksonUtil.parseObject(configJson, getConfigClass());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.device.operator; package com.ycwl.basic.device.operator;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.device.entity.common.FileObject; import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.storage.StorageFactory; import com.ycwl.basic.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter; import com.ycwl.basic.storage.adapters.IStorageAdapter;
@@ -28,7 +28,7 @@ public class AliOssStorageOperator extends ADeviceStorageOperator {
@Override @Override
public void loadConfig(String configJson) { public void loadConfig(String configJson) {
AliOssStorageConfig config = JSON.parseObject(configJson, AliOssStorageConfig.class); AliOssStorageConfig config = JacksonUtil.parseObject(configJson, AliOssStorageConfig.class);
adapter = StorageFactory.get(StorageType.ALI_OSS, config); adapter = StorageFactory.get(StorageType.ALI_OSS, config);
} }

View File

@@ -1,7 +1,6 @@
package com.ycwl.basic.device.operator; package com.ycwl.basic.device.operator;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ycwl.basic.device.entity.common.FileObject; import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.vpt_passive.VptPassiveStorageConfig; import com.ycwl.basic.device.entity.vpt_passive.VptPassiveStorageConfig;
@@ -29,10 +28,8 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
public Long scenicId; public Long scenicId;
public Long deviceId; public Long deviceId;
public String deviceNo; public String deviceNo;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date startTime; public Date startTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date endTime; public Date endTime;
} }
@@ -75,7 +72,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
@Override @Override
public void loadConfig(String configJson) { public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, VptPassiveStorageConfig.class); this.config = JacksonUtil.parseObject(configJson, VptPassiveStorageConfig.class);
} }
@Override @Override
@@ -94,7 +91,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
if (redisTemplate == null) { if (redisTemplate == null) {
taskList.add(task); taskList.add(task);
} else { } else {
redisTemplate.opsForValue().set(String.format(TASK_KEY, task.scenicId, task.deviceNo) + task.taskId, JSON.toJSONString(task), 10 * 60L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(TASK_KEY, task.scenicId, task.deviceNo) + task.taskId, JacksonUtil.toJSONString(task), 10 * 60L, TimeUnit.SECONDS);
} }
log.info("任务{}获取视频开始!共{}", task.taskId, taskList.size()); log.info("任务{}获取视频开始!共{}", task.taskId, taskList.size());
Date taskStartTime = new Date(); Date taskStartTime = new Date();

View File

@@ -3,8 +3,8 @@ package com.ycwl.basic.device.operator;
import cn.hutool.crypto.digest.MD5; import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.device.entity.common.FileObject; import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.wvp_active.WvpActiveStorageConfig; import com.ycwl.basic.device.entity.wvp_active.WvpActiveStorageConfig;
import com.ycwl.basic.storage.exceptions.StorageConfigException; import com.ycwl.basic.storage.exceptions.StorageConfigException;
@@ -30,7 +30,7 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
@Override @Override
public void loadConfig(String configJson) { public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, WvpActiveStorageConfig.class); this.config = JacksonUtil.parseObject(configJson, WvpActiveStorageConfig.class);
} }
@Override @Override
@@ -55,13 +55,14 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
String password = MD5.create().digestHex(this.config.getLoginPassword()); String password = MD5.create().digestHex(this.config.getLoginPassword());
params.put("password", password); params.put("password", password);
String jsonResult = HttpUtil.get(url, params); String jsonResult = HttpUtil.get(url, params);
JSONObject result = JSON.parseObject(jsonResult); Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
if (result.getInteger("code") == 0) { Integer code = (Integer) result.get("code");
JSONObject data = result.getJSONObject("data"); if (code != null && code == 0) {
this.token = data.getString("accessToken"); Map<String, Object> data = (Map<String, Object>) result.get("data");
this.token = (String) data.get("accessToken");
return this.token; return this.token;
} else { } else {
throw new StorageConfigException("获取token失败,原因为:" + result.getString("msg")); throw new StorageConfigException("获取token失败,原因为:" + result.get("msg"));
} }
} }
public List<FileObject> listDirByDtRange(Date startDate, Date endDate) { public List<FileObject> listDirByDtRange(Date startDate, Date endDate) {
@@ -75,19 +76,23 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
params.put("page", 1); params.put("page", 1);
params.put("count", 100); params.put("count", 100);
String jsonResult = HttpRequest.get(url).form(params).header("Access-Token", getToken()).execute().body(); String jsonResult = HttpRequest.get(url).form(params).header("Access-Token", getToken()).execute().body();
JSONObject result = JSON.parseObject(jsonResult); Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
if (result.getInteger("code") == 0) { Integer code = (Integer) result.get("code");
JSONObject data = result.getJSONObject("data"); if (code != null && code == 0) {
List<JSONObject> recordList = data.getJSONArray("list").toJavaList(JSONObject.class); Map<String, Object> data = (Map<String, Object>) result.get("data");
List<Map<String, Object>> recordList = JacksonUtil.parseObject(JacksonUtil.toJSONString(((Map<String, Object>) result.get("data")).get("list")), new TypeReference<List<Map<String, Object>>>() {});
return recordList.stream() return recordList.stream()
.map(record -> { .map(record -> {
FileObject object = new FileObject(); FileObject object = new FileObject();
object.setName(record.getString("id")); object.setName((String) record.get("id"));
object.setPath(record.getString("folder")); object.setPath((String) record.get("folder"));
object.setUrl(getUrlForDownload(record.getInteger("id"))); Integer recordId = (Integer) record.get("id");
object.setUrl(getUrlForDownload(recordId != null ? recordId : 0));
object.setNeedDownload(true); object.setNeedDownload(true);
object.setCreateTime(new Date(record.getLongValue("startTime"))); Number startTime = (Number) record.get("startTime");
object.setEndTime(new Date(record.getLongValue("endTime"))); Number endTime = (Number) record.get("endTime");
object.setCreateTime(new Date(startTime != null ? startTime.longValue() : 0));
object.setEndTime(new Date(endTime != null ? endTime.longValue() : 0));
return object; return object;
}) })
.sorted(Comparator.comparing(FileObject::getCreateTime)) .sorted(Comparator.comparing(FileObject::getCreateTime))
@@ -100,10 +105,11 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
// assume path is recordId // assume path is recordId
String url = this.config.getHost() + "/api/cloud/record/play/path?recordId=" + id; String url = this.config.getHost() + "/api/cloud/record/play/path?recordId=" + id;
String jsonResult = HttpRequest.get(url).header("Access-Token", getToken()).execute().body(); String jsonResult = HttpRequest.get(url).header("Access-Token", getToken()).execute().body();
JSONObject result = JSON.parseObject(jsonResult); Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
if (result.getInteger("code") == 0) { Integer code = (Integer) result.get("code");
JSONObject data = result.getJSONObject("data"); if (code != null && code == 0) {
String httpPath = data.getString("httpPath"); Map<String, Object> data = (Map<String, Object>) result.get("data");
String httpPath = (String) data.get("httpPath");
if (StringUtils.isBlank(this.config.getZlmHost())) { if (StringUtils.isBlank(this.config.getZlmHost())) {
return httpPath; return httpPath;
} }
@@ -114,7 +120,7 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
} }
return this.config.getZlmHost() + uri.getPath() + "?" + uri.getQuery(); return this.config.getZlmHost() + uri.getPath() + "?" + uri.getQuery();
} else { } else {
throw new StorageUnsupportedException("获取播放地址失败,原因为:" + result.getString("msg")); throw new StorageUnsupportedException("获取播放地址失败,原因为:" + result.get("msg"));
} }
} }

View File

@@ -1,7 +1,6 @@
package com.ycwl.basic.device.operator; package com.ycwl.basic.device.operator;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ycwl.basic.device.entity.common.FileObject; import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.wvp_passive.WvpPassiveStorageConfig; import com.ycwl.basic.device.entity.wvp_passive.WvpPassiveStorageConfig;
@@ -28,10 +27,8 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
public Long scenicId; public Long scenicId;
public Long deviceId; public Long deviceId;
public String deviceNo; public String deviceNo;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date startTime; public Date startTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date endTime; public Date endTime;
} }
@@ -72,7 +69,7 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
@Override @Override
public void loadConfig(String configJson) { public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, WvpPassiveStorageConfig.class); this.config = JacksonUtil.parseObject(configJson, WvpPassiveStorageConfig.class);
} }
@Override @Override
@@ -91,7 +88,7 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
if (redisTemplate == null) { if (redisTemplate == null) {
taskList.add(task); taskList.add(task);
} else { } else {
redisTemplate.opsForValue().set(String.format(TASK_KEY, task.scenicId, task.deviceNo) + task.taskId, JSON.toJSONString(task), 10 * 60L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(TASK_KEY, task.scenicId, task.deviceNo) + task.taskId, JacksonUtil.toJSONString(task), 10 * 60L, TimeUnit.SECONDS);
} }
Date taskStartTime = new Date(); Date taskStartTime = new Date();
while (true) { while (true) {

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.mobile.goods; package com.ycwl.basic.model.mobile.goods;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -42,6 +43,8 @@ public class GoodsDetailVO {
private Integer isFree; private Integer isFree;
private Integer parts; private Integer parts;
private Integer sort; private Integer sort;
@JsonProperty("sourceType")
public Integer getSourceType() { public Integer getSourceType() {
return goodsType; return goodsType;
} }

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.mobile.goods; package com.ycwl.basic.model.mobile.goods;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -56,6 +57,7 @@ public class VideoGoodsDetailVO {
private Integer width; private Integer width;
private BigDecimal duration; private BigDecimal duration;
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.model.mobile.order; package com.ycwl.basic.model.mobile.order;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -18,6 +19,7 @@ public class IsBuyBatchRespVO {
private BigDecimal couponPrice = BigDecimal.ZERO; private BigDecimal couponPrice = BigDecimal.ZERO;
private BigDecimal slashPrice; private BigDecimal slashPrice;
@JsonProperty("price")
public BigDecimal getPrice() { public BigDecimal getPrice() {
if (origPrice == null) { if (origPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;
@@ -27,6 +29,7 @@ public class IsBuyBatchRespVO {
} }
return origPrice.subtract(couponPrice); return origPrice.subtract(couponPrice);
} }
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.model.mobile.order; package com.ycwl.basic.model.mobile.order;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -17,6 +18,7 @@ public class IsBuyRespVO {
private BigDecimal couponPrice = BigDecimal.ZERO; private BigDecimal couponPrice = BigDecimal.ZERO;
private BigDecimal slashPrice; private BigDecimal slashPrice;
@JsonProperty("price")
public BigDecimal getPrice() { public BigDecimal getPrice() {
if (origPrice == null) { if (origPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;
@@ -26,6 +28,7 @@ public class IsBuyRespVO {
} }
return origPrice.subtract(couponPrice); return origPrice.subtract(couponPrice);
} }
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.model.mobile.statistic.resp; package com.ycwl.basic.model.mobile.statistic.resp;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@@ -45,11 +46,13 @@ public class AppStatisticsFunnelVO {
private BigDecimal refundOfOrderAmount; // ro3 private BigDecimal refundOfOrderAmount; // ro3
// 镜头检测游客数_扫码访问人数_转化率 // 镜头检测游客数_扫码访问人数_转化率
@JsonProperty("csom_scaom")
public String getCsom_scaom() { public String getCsom_scaom() {
return "-"; // TODO: REAL return "-"; // TODO: REAL
} }
// 扫码访问人数_上传头像人数_转化率 // 扫码访问人数_上传头像人数_转化率
@JsonProperty("scaom_ufom")
public String getScaom_ufom() { public String getScaom_ufom() {
if (uploadFaceOfMemberNum == 0 || scanCodeVisitorOfMemberNum == 0) { if (uploadFaceOfMemberNum == 0 || scanCodeVisitorOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -60,6 +63,7 @@ public class AppStatisticsFunnelVO {
.toString(); .toString();
} }
// 上传头像人数_推送订阅人数_转化率 // 上传头像人数_推送订阅人数_转化率
@JsonProperty("ufom_pom")
public String getUfom_pom() { public String getUfom_pom() {
if (pushOfMemberNum == 0 || uploadFaceOfMemberNum == 0) { if (pushOfMemberNum == 0 || uploadFaceOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -70,6 +74,7 @@ public class AppStatisticsFunnelVO {
.toString(); .toString();
} }
// 推送订阅人数_生成视频人数_转化率 // 推送订阅人数_生成视频人数_转化率
@JsonProperty("pom_cvom")
public String getPom_cvom() { public String getPom_cvom() {
if (completeVideoOfMemberNum == 0 || pushOfMemberNum == 0) { if (completeVideoOfMemberNum == 0 || pushOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -80,6 +85,7 @@ public class AppStatisticsFunnelVO {
.toString(); .toString();
} }
// 生成视频人数_预览视频人数_转化率 // 生成视频人数_预览视频人数_转化率
@JsonProperty("cvom_pvom")
public String getCvom_pvom() { public String getCvom_pvom() {
if (previewVideoOfMemberNum == 0 || completeVideoOfMemberNum == 0) { if (previewVideoOfMemberNum == 0 || completeVideoOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -90,6 +96,7 @@ public class AppStatisticsFunnelVO {
.toString(); .toString();
} }
// 预览视频人数_点击购买人数_转化率 // 预览视频人数_点击购买人数_转化率
@JsonProperty("pvom_cpom")
public String getPvom_cpom() { public String getPvom_cpom() {
if (clickOnPayOfMemberNum == 0 || previewVideoOfMemberNum == 0) { if (clickOnPayOfMemberNum == 0 || previewVideoOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -100,6 +107,7 @@ public class AppStatisticsFunnelVO {
.toString(); .toString();
} }
// 点击购买人数_支付订单人数_转化率 // 点击购买人数_支付订单人数_转化率
@JsonProperty("cpom_pom")
public String getCpom_pom() { public String getCpom_pom() {
if (payOfMemberNum == 0 || clickOnPayOfMemberNum == 0) { if (payOfMemberNum == 0 || clickOnPayOfMemberNum == 0) {
return "0.00"; return "0.00";
@@ -112,6 +120,7 @@ public class AppStatisticsFunnelVO {
public BigDecimal payOfOrderAmount() { public BigDecimal payOfOrderAmount() {
return payOfOrderAmount; return payOfOrderAmount;
} }
@JsonProperty("payOfOrderAmount")
public String getPayOfOrderAmount() { public String getPayOfOrderAmount() {
if (payOfOrderAmount == null) { if (payOfOrderAmount == null) {
return "0.00"; return "0.00";
@@ -121,6 +130,7 @@ public class AppStatisticsFunnelVO {
public BigDecimal refundOfOrderAmount() { public BigDecimal refundOfOrderAmount() {
return refundOfOrderAmount; return refundOfOrderAmount;
} }
@JsonProperty("refundOfOrderAmount")
public String getRefundOfOrderAmount() { public String getRefundOfOrderAmount() {
if (refundOfOrderAmount == null) { if (refundOfOrderAmount == null) {
return "0.00"; return "0.00";

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.pc.device.entity; package com.ycwl.basic.model.pc.device.entity;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
@@ -73,10 +74,10 @@ public class DeviceConfigEntity {
return Collections.singletonList(new DeviceCropConfig()); return Collections.singletonList(new DeviceCropConfig());
} }
if (StringUtils.startsWith(cropConfig, "{")) { if (StringUtils.startsWith(cropConfig, "{")) {
return Collections.singletonList(JSON.parseObject(cropConfig, DeviceCropConfig.class)); return Collections.singletonList(JacksonUtil.parseObject(cropConfig, DeviceCropConfig.class));
} }
if (StringUtils.startsWith(cropConfig, "[")) { if (StringUtils.startsWith(cropConfig, "[")) {
return JSON.parseArray(cropConfig, DeviceCropConfig.class); return JacksonUtil.parseObject(cropConfig, new TypeReference<List<DeviceCropConfig>>() {});
} }
return Collections.singletonList(new DeviceCropConfig()); return Collections.singletonList(new DeviceCropConfig());
} }

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.model.pc.faceDetectLog.entity; package com.ycwl.basic.model.pc.faceDetectLog.entity;
import com.alibaba.fastjson.JSONArray; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference;
import com.aliyuncs.facebody.model.v20191230.SearchFaceRequest; import com.aliyuncs.facebody.model.v20191230.SearchFaceRequest;
import com.aliyuncs.facebody.model.v20191230.SearchFaceResponse; import com.aliyuncs.facebody.model.v20191230.SearchFaceResponse;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
@@ -54,7 +54,7 @@ public class FaceDetectLog {
} }
public FaceDetectLog fillResponse(Object response) { public FaceDetectLog fillResponse(Object response) {
this.matchRawResult = JSONObject.toJSONString(response); this.matchRawResult = JacksonUtil.toJSONString(response);
return this; return this;
} }
@@ -62,14 +62,14 @@ public class FaceDetectLog {
if (matchLocalRecord == null) { if (matchLocalRecord == null) {
return null; return null;
} }
return JSONArray.parseArray(matchLocalRecord, MatchLocalRecord.class); return JacksonUtil.parseObject(matchLocalRecord, new TypeReference<List<MatchLocalRecord>>() {});
} }
public void matchLocalRecord(List matchLocalRecord) { public void matchLocalRecord(List matchLocalRecord) {
if (matchLocalRecord == null) { if (matchLocalRecord == null) {
this.matchLocalRecord = null; this.matchLocalRecord = null;
} else { } else {
this.matchLocalRecord = JSONArray.toJSONString(matchLocalRecord); this.matchLocalRecord = JacksonUtil.toJSONString(matchLocalRecord);
} }
} }

View File

@@ -2,6 +2,7 @@ package com.ycwl.basic.model.pc.order.entity;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -91,6 +92,7 @@ public class OrderEntity {
*/ */
private Date refundAt; private Date refundAt;
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.pc.order.resp; package com.ycwl.basic.model.pc.order.resp;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -88,6 +89,7 @@ public class OrderAppRespVO {
// 订单明细 // 订单明细
private List<OrderItemVO> orderItemList; private List<OrderItemVO> orderItemList;
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.pc.order.resp; package com.ycwl.basic.model.pc.order.resp;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ycwl.basic.model.mobile.goods.GoodsDetailVO; import com.ycwl.basic.model.mobile.goods.GoodsDetailVO;
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity; import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
import lombok.Data; import lombok.Data;
@@ -112,6 +113,7 @@ public class OrderRespVO {
private String scenicName; private String scenicName;
private List<GoodsDetailVO> goodsList; private List<GoodsDetailVO> goodsList;
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.model.pc.video.resp; package com.ycwl.basic.model.pc.video.resp;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -62,6 +63,7 @@ public class VideoRespVO {
private Integer width; private Integer width;
private BigDecimal duration; private BigDecimal duration;
@JsonProperty("discountPrice")
public BigDecimal getDiscountPrice() { public BigDecimal getDiscountPrice() {
if (slashPrice == null) { if (slashPrice == null) {
return BigDecimal.ZERO; return BigDecimal.ZERO;

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.model.viid.entity; package com.ycwl.basic.model.viid.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
@Data @Data
@@ -10,9 +11,11 @@ public class FacePositionObject {
private Integer ltY; private Integer ltY;
private Integer rbX; private Integer rbX;
private Integer rbY; private Integer rbY;
@JsonProperty("width")
public Integer getWidth(){ public Integer getWidth(){
return rbX - ltX; return rbX - ltX;
} }
@JsonProperty("height")
public Integer getHeight(){ public Integer getHeight(){
return rbY - ltY; return rbY - ltY;
} }

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.notify.adapters; package com.ycwl.basic.notify.adapters;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.notify.entity.NotifyContent; import com.ycwl.basic.notify.entity.NotifyContent;
import com.ycwl.basic.notify.entity.WxMpSrvConfig; import com.ycwl.basic.notify.entity.WxMpSrvConfig;
@@ -45,15 +45,16 @@ public class WxMpSrvNotifyAdapter implements INotifyAdapter{
} }
String url = String.format(ACCESS_TOKEN_URL, config.getAppId(), config.getAppSecret()); String url = String.format(ACCESS_TOKEN_URL, config.getAppId(), config.getAppSecret());
String response = HttpUtil.get(url); String response = HttpUtil.get(url);
JSONObject jsonObject = JSONObject.parseObject(response); Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
ACCESS_TOKEN = jsonObject.getString("access_token"); ACCESS_TOKEN = (String) jsonObject.get("access_token");
expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000); Integer expiresIn = (Integer) jsonObject.get("expires_in");
expireTime = new Date(System.currentTimeMillis() + (expiresIn != null ? expiresIn : 7200) * 1000);
return ACCESS_TOKEN; return ACCESS_TOKEN;
} }
public void sendServiceNotification(Map<String, Object> params) { public void sendServiceNotification(Map<String, Object> params) {
String url = String.format(SEND_TEMPLATE_MESSAGE_URL, getAccessToken()); String url = String.format(SEND_TEMPLATE_MESSAGE_URL, getAccessToken());
String response = HttpUtil.post(url, JSONObject.toJSONString(params)); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
System.out.println(response); System.out.println(response);
} }
} }

View File

@@ -2,8 +2,7 @@ package com.ycwl.basic.pay.adapter;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.pay.entity.CancelOrderRequest; import com.ycwl.basic.pay.entity.CancelOrderRequest;
import com.ycwl.basic.pay.entity.CongMingPayConfig; import com.ycwl.basic.pay.entity.CongMingPayConfig;
import com.ycwl.basic.pay.entity.CreateOrderRequest; import com.ycwl.basic.pay.entity.CreateOrderRequest;
@@ -78,17 +77,17 @@ public class CongMingPayAdapter implements IPayAdapter {
params.put("s_source", "mini_app"); params.put("s_source", "mini_app");
params.put("sign", parseSign(params, config.getApiKey())); params.put("sign", parseSign(params, config.getApiKey()));
System.out.println(url); System.out.println(url);
System.out.println(JSON.toJSONString(params)); System.out.println(JacksonUtil.toJSONString(params));
String response = HttpUtil.post(url, JSON.toJSONString(params)); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
JSONObject json = JSONObject.parseObject(response); Map<String, Object> json = JacksonUtil.parseObject(response, Map.class);
System.out.println(json); System.out.println(json);
if (StringUtils.equals(json.getString("result_code"), "fail")) { if (StringUtils.equals((String) json.get("result_code"), "fail")) {
throw new PayException("查询异常!异常提示:" + json.getString("error_msg")); throw new PayException("查询异常!异常提示:" + json.get("error_msg"));
} }
resp.setSkipPay(false); resp.setSkipPay(false);
resp.setSuccess(true); resp.setSuccess(true);
resp.setOrderNo(json.getString("order_id")); resp.setOrderNo((String) json.get("order_id"));
resp.setExtData(json.toJavaObject(Map.class)); resp.setExtData(JacksonUtil.toJavaObject(json, Map.class));
return resp; return resp;
} }
@@ -134,24 +133,24 @@ public class CongMingPayAdapter implements IPayAdapter {
params.put("shop_id", config.getShopId()); params.put("shop_id", config.getShopId());
params.put("order_id", orderNo); params.put("order_id", orderNo);
params.put("sign", parseSign(params, config.getApiKey())); params.put("sign", parseSign(params, config.getApiKey()));
String response = HttpUtil.post(url, JSON.toJSONString(params)); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
JSONObject json = JSONObject.parseObject(response); Map<String, Object> json = JacksonUtil.parseObject(response, Map.class);
System.out.println(json); System.out.println(json);
if (StringUtils.equals(json.getString("result_code"), "fail")) { if (StringUtils.equals((String) json.get("result_code"), "fail")) {
throw new PayException("查询异常!异常提示:" + json.getString("error_msg")); throw new PayException("查询异常!异常提示:" + json.get("error_msg"));
} }
resp.setOriginalResponse(json); resp.setOriginalResponse(json);
resp.setValid(true); resp.setValid(true);
resp.setOrderPriceInYuan(json.getBigDecimal("pay_ble")); resp.setOrderPriceInYuan((BigDecimal) json.get("pay_ble"));
resp.setPayPriceInYuan(json.getBigDecimal("paid_out")); resp.setPayPriceInYuan((BigDecimal) json.get("paid_out"));
resp.setOrderNo(json.getString("order_id")); resp.setOrderNo((String) json.get("order_id"));
switch (json.getString("order_status")) { switch ((String) json.get("order_status")) {
case "2": case "2":
resp.setState(PayResponse.PAY_STATE.NOT_PAY); resp.setState(PayResponse.PAY_STATE.NOT_PAY);
break; break;
case "1": case "1":
resp.setState(PayResponse.PAY_STATE.SUCCESS); resp.setState(PayResponse.PAY_STATE.SUCCESS);
resp.setPayTime(json.getString("time_end")); resp.setPayTime((String) json.get("time_end"));
break; break;
case "0": case "0":
resp.setState(PayResponse.PAY_STATE.FAIL); resp.setState(PayResponse.PAY_STATE.FAIL);
@@ -178,11 +177,11 @@ public class CongMingPayAdapter implements IPayAdapter {
params.put("money", request.getRefundPriceInYuan().toString()); params.put("money", request.getRefundPriceInYuan().toString());
params.put("refund_order_id", request.getRefundNo()); params.put("refund_order_id", request.getRefundNo());
params.put("sign", parseSign(params, config.getApiKey())); params.put("sign", parseSign(params, config.getApiKey()));
String response = HttpUtil.post(url, JSON.toJSONString(params)); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
JSONObject json = JSONObject.parseObject(response); Map<String, Object> json = JacksonUtil.parseObject(response, Map.class);
System.out.println(json); System.out.println(json);
if (StringUtils.equalsIgnoreCase(json.getString("result_code"), "fail")) { if (StringUtils.equalsIgnoreCase((String) json.get("result_code"), "fail")) {
throw new PayException("退款异常!异常提示:" + json.getString("error_msg")); throw new PayException("退款异常!异常提示:" + json.get("error_msg"));
} }
return resp; return resp;
} }
@@ -219,10 +218,10 @@ public class CongMingPayAdapter implements IPayAdapter {
params.put("order_id", request.getOrderNo()); params.put("order_id", request.getOrderNo());
params.put("error_msg", request.getReason()); params.put("error_msg", request.getReason());
params.put("sign", parseSign(params, config.getApiKey())); params.put("sign", parseSign(params, config.getApiKey()));
String response = HttpUtil.post(url, JSON.toJSONString(params)); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
JSONObject json = JSONObject.parseObject(response); Map<String, Object> json = JacksonUtil.parseObject(response, Map.class);
if (StringUtils.equals(json.getString("result_code"), "fail")) { if (StringUtils.equals((String) json.get("result_code"), "fail")) {
throw new PayException("取消订单异常!异常提示:" + json.getString("error_msg")); throw new PayException("取消订单异常!异常提示:" + json.get("error_msg"));
} }
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.profitsharing.entity; package com.ycwl.basic.profitsharing.entity;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.profitsharing.enums.ProfitSharingWxPayType; import com.ycwl.basic.profitsharing.enums.ProfitSharingWxPayType;
import lombok.Data; import lombok.Data;
@@ -29,10 +29,10 @@ public class ProfitSharingUser {
private BigDecimal realRate; private BigDecimal realRate;
public void setWxPayConfig(String wxPayConfig) { public void setWxPayConfig(String wxPayConfig) {
this.wxPayConfig = JSON.parseObject(wxPayConfig, Map.class); this.wxPayConfig = JacksonUtil.parseObject(wxPayConfig, Map.class);
} }
public String getWxPayConfig() { public String getWxPayConfig() {
return JSON.toJSONString(wxPayConfig); return JacksonUtil.toJSONString(wxPayConfig);
} }
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.profitsharing.repository; package com.ycwl.basic.profitsharing.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.profitsharing.entity.ProfitSharingConfig; import com.ycwl.basic.profitsharing.entity.ProfitSharingConfig;
import com.ycwl.basic.profitsharing.mapper.ProfitSharingConfigMapper; import com.ycwl.basic.profitsharing.mapper.ProfitSharingConfigMapper;
import com.ycwl.basic.profitsharing.mapper.ProfitSharingUserMapper; import com.ycwl.basic.profitsharing.mapper.ProfitSharingUserMapper;
@@ -20,12 +20,12 @@ public class ProfitSharingRepository {
public ProfitSharingConfig getScenicConfig(Long id) { public ProfitSharingConfig getScenicConfig(Long id) {
if (redisTemplate.hasKey(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id))) { if (redisTemplate.hasKey(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id)), ProfitSharingConfig.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id)), ProfitSharingConfig.class);
} }
ProfitSharingConfig scenicConfig = configMapper.findByScenicId(id); ProfitSharingConfig scenicConfig = configMapper.findByScenicId(id);
if (scenicConfig != null) { if (scenicConfig != null) {
scenicConfig.setUsers(userMapper.findByConfigId(scenicConfig.getId())); scenicConfig.setUsers(userMapper.findByConfigId(scenicConfig.getId()));
redisTemplate.opsForValue().set(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id), JSONObject.toJSONString(scenicConfig)); redisTemplate.opsForValue().set(String.format(PROFIT_SHARING_SCENIC_CONFIG_CACHE_KEY, id), JacksonUtil.toJSONString(scenicConfig));
} }
return scenicConfig; return scenicConfig;
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.DeviceMapper; import com.ycwl.basic.mapper.DeviceMapper;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity; import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity; import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
@@ -27,26 +27,26 @@ public class DeviceRepository {
public DeviceEntity getDevice(Long deviceId) { public DeviceEntity getDevice(Long deviceId) {
if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceId))) { if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceId)), DeviceEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceId)), DeviceEntity.class);
} }
DeviceEntity device = deviceMapper.getByDeviceId(deviceId); DeviceEntity device = deviceMapper.getByDeviceId(deviceId);
if (null != device) { if (null != device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 3, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
} }
return device; return device;
} }
public DeviceEntity getDeviceByDeviceNo(String deviceNo) { public DeviceEntity getDeviceByDeviceNo(String deviceNo) {
if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceNo))) { if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceNo))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceNo)), DeviceEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceNo)), DeviceEntity.class);
} }
DeviceEntity device = deviceMapper.getByDeviceNo(deviceNo); DeviceEntity device = deviceMapper.getByDeviceNo(deviceNo);
if (null == device) { if (null == device) {
device = deviceMapper.getByDeviceNo2(deviceNo); device = deviceMapper.getByDeviceNo2(deviceNo);
} }
if (null != device) { if (null != device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device), 3, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device), 3, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
} else { } else {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS);
} }
@@ -55,7 +55,7 @@ public class DeviceRepository {
public DeviceConfigEntity getDeviceConfig(Long deviceId) { public DeviceConfigEntity getDeviceConfig(Long deviceId) {
if (redisTemplate.hasKey(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId))) { if (redisTemplate.hasKey(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId)), DeviceConfigEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId)), DeviceConfigEntity.class);
} }
DeviceConfigEntity deviceConfig = deviceMapper.getConfigByDeviceId(deviceId); DeviceConfigEntity deviceConfig = deviceMapper.getConfigByDeviceId(deviceId);
if (null == deviceConfig) { if (null == deviceConfig) {
@@ -64,7 +64,7 @@ public class DeviceRepository {
deviceConfig.setDeviceId(deviceId); deviceConfig.setDeviceId(deviceId);
deviceMapper.addConfig(deviceConfig); deviceMapper.addConfig(deviceConfig);
} }
redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JSONObject.toJSONString(deviceConfig), 3, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JacksonUtil.toJSONString(deviceConfig), 3, TimeUnit.DAYS);
return deviceConfig; return deviceConfig;
} }
@@ -111,22 +111,22 @@ public class DeviceRepository {
device.setOnline(online); device.setOnline(online);
device.setKeepaliveAt(keepaliveAt); device.setKeepaliveAt(keepaliveAt);
device.setIpAddr(ipAddr); device.setIpAddr(ipAddr);
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 3, TimeUnit.DAYS); redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
// deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt); // deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
updateDeviceCache(device); updateDeviceCache(device);
} }
public DeviceEntity getOnlineStatus(Long deviceId) { public DeviceEntity getOnlineStatus(Long deviceId) {
if (redisTemplate.hasKey(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId))) { if (redisTemplate.hasKey(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class);
} else { } else {
return null; return null;
} }
} }
private void updateDeviceCache(DeviceEntity device) { private void updateDeviceCache(DeviceEntity device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device)); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JacksonUtil.toJSONString(device));
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JSONObject.toJSONString(device)); redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JacksonUtil.toJSONString(device));
} }
public List<DeviceEntity> getAllDeviceByScenicId(Long scenicId) { public List<DeviceEntity> getAllDeviceByScenicId(Long scenicId) {

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.FaceMapper; import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper; import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.model.pc.face.entity.FaceEntity; import com.ycwl.basic.model.pc.face.entity.FaceEntity;
@@ -30,11 +30,11 @@ public class FaceRepository {
public FaceEntity getFace(Long id) { public FaceEntity getFace(Long id) {
if (redisTemplate.hasKey(String.format(FACE_CACHE_KEY, id))) { if (redisTemplate.hasKey(String.format(FACE_CACHE_KEY, id))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(FACE_CACHE_KEY, id)), FaceEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(FACE_CACHE_KEY, id)), FaceEntity.class);
} }
FaceEntity face = faceMapper.get(id); FaceEntity face = faceMapper.get(id);
if (face != null) { if (face != null) {
redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JSONObject.toJSONString(face), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JacksonUtil.toJSONString(face), 12, TimeUnit.HOURS);
} }
return face; return face;
} }

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONArray; import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.mapper.OrderMapper; import com.ycwl.basic.mapper.OrderMapper;
import com.ycwl.basic.model.pc.order.entity.OrderEntity; import com.ycwl.basic.model.pc.order.entity.OrderEntity;
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity; import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
@@ -27,25 +27,25 @@ public class OrderRepository {
public OrderEntity getOrder(Long orderId) { public OrderEntity getOrder(Long orderId) {
if (redisTemplate.hasKey(String.format(ORDER_CACHE_KEY, orderId))) { if (redisTemplate.hasKey(String.format(ORDER_CACHE_KEY, orderId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_CACHE_KEY, orderId)), OrderEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_CACHE_KEY, orderId)), OrderEntity.class);
} }
OrderEntity orderEntity = orderMapper.get(orderId); OrderEntity orderEntity = orderMapper.get(orderId);
if (orderEntity != null) { if (orderEntity != null) {
redisTemplate.opsForValue().set(String.format(ORDER_CACHE_KEY, orderId), JSON.toJSONString(orderEntity), 60, TimeUnit.SECONDS); redisTemplate.opsForValue().set(String.format(ORDER_CACHE_KEY, orderId), JacksonUtil.toJSONString(orderEntity), 60, TimeUnit.SECONDS);
} }
return orderEntity; return orderEntity;
} }
public List<OrderItemEntity> getOrderItems(Long orderId) { public List<OrderItemEntity> getOrderItems(Long orderId) {
if (redisTemplate.hasKey(String.format(ORDER_ITEMS_CACHE_KEY, orderId))) { if (redisTemplate.hasKey(String.format(ORDER_ITEMS_CACHE_KEY, orderId))) {
return JSON.parseArray(redisTemplate.opsForValue().get(String.format(ORDER_ITEMS_CACHE_KEY, orderId)), Long.class) return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEMS_CACHE_KEY, orderId)), new TypeReference<List<Long>>() {})
.stream().map(this::getOrderItemByOrderItemId).collect(Collectors.toList()); .stream().map(this::getOrderItemByOrderItemId).collect(Collectors.toList());
} }
List<OrderItemEntity> orderItemEntities = orderMapper.listOrderItemByOrderId(orderId); List<OrderItemEntity> orderItemEntities = orderMapper.listOrderItemByOrderId(orderId);
if (orderItemEntities != null) { if (orderItemEntities != null) {
redisTemplate.opsForValue().set( redisTemplate.opsForValue().set(
String.format(ORDER_ITEMS_CACHE_KEY, orderId), String.format(ORDER_ITEMS_CACHE_KEY, orderId),
JSONArray.toJSONString(orderItemEntities.stream().map(OrderItemEntity::getId).collect(Collectors.toList())) JacksonUtil.toJSONString(orderItemEntities.stream().map(OrderItemEntity::getId).collect(Collectors.toList()))
); );
} }
return orderItemEntities; return orderItemEntities;
@@ -53,11 +53,11 @@ public class OrderRepository {
public OrderItemEntity getOrderItemByOrderItemId(Long orderItemId) { public OrderItemEntity getOrderItemByOrderItemId(Long orderItemId) {
if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, orderItemId))) { if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, orderItemId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, orderItemId)), OrderItemEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, orderItemId)), OrderItemEntity.class);
} }
OrderItemEntity orderItemEntity = orderMapper.getOrderItem(orderItemId); OrderItemEntity orderItemEntity = orderMapper.getOrderItem(orderItemId);
if (orderItemEntity != null) { if (orderItemEntity != null) {
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, orderItemId), JSON.toJSONString(orderItemEntity)); redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, orderItemId), JacksonUtil.toJSONString(orderItemEntity));
} }
return orderItemEntity; return orderItemEntity;
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.PriceConfigMapper; import com.ycwl.basic.mapper.PriceConfigMapper;
import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity; import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -23,13 +23,13 @@ public class PriceRepository {
String cacheKey = String.format(PRICE_SCENIC_TYPE_GOODS_CACHE, scenicId, type, goodsId); String cacheKey = String.format(PRICE_SCENIC_TYPE_GOODS_CACHE, scenicId, type, goodsId);
PriceConfigEntity priceConfigEntity = null; PriceConfigEntity priceConfigEntity = null;
if (redisTemplate.hasKey(cacheKey)) { if (redisTemplate.hasKey(cacheKey)) {
priceConfigEntity = JSON.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class); priceConfigEntity = JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
} }
if (priceConfigEntity == null) { if (priceConfigEntity == null) {
priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId); priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId);
if (priceConfigEntity != null) { if (priceConfigEntity != null) {
redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(cacheKey, JacksonUtil.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JacksonUtil.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
} }
} }
return priceConfigEntity; return priceConfigEntity;
@@ -39,7 +39,7 @@ public class PriceRepository {
String cacheKey = String.format(PRICE_ID_CACHE, id); String cacheKey = String.format(PRICE_ID_CACHE, id);
PriceConfigEntity priceConfigEntity = null; PriceConfigEntity priceConfigEntity = null;
if (redisTemplate.hasKey(cacheKey)) { if (redisTemplate.hasKey(cacheKey)) {
priceConfigEntity = JSON.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class); priceConfigEntity = JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
} }
return priceConfigEntity; return priceConfigEntity;
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.RenderWorkerMapper; import com.ycwl.basic.mapper.RenderWorkerMapper;
import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity; import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity;
import com.ycwl.basic.model.task.req.ClientStatusReqVo; import com.ycwl.basic.model.task.req.ClientStatusReqVo;
@@ -25,12 +25,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) { public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey); String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey);
if (redisTemplate.hasKey(key)) { if (redisTemplate.hasKey(key)) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
} }
RenderWorkerEntity renderWorker = mapper.findByAccessKey(accessKey); RenderWorkerEntity renderWorker = mapper.findByAccessKey(accessKey);
if (renderWorker != null) { if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS); redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
} }
return renderWorker; return renderWorker;
} }
@@ -38,12 +38,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorker(Long id) { public RenderWorkerEntity getWorker(Long id) {
String key = String.format(RENDER_WORKER_CACHE_KEY, id); String key = String.format(RENDER_WORKER_CACHE_KEY, id);
if (redisTemplate.hasKey(key)) { if (redisTemplate.hasKey(key)) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
} }
RenderWorkerEntity renderWorker = mapper.getById(id); RenderWorkerEntity renderWorker = mapper.getById(id);
if (renderWorker != null) { if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS); redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
} }
return renderWorker; return renderWorker;
} }
@@ -69,14 +69,14 @@ public class RenderWorkerRepository {
if (!redisTemplate.hasKey(key)) { if (!redisTemplate.hasKey(key)) {
mapper.updateHost(id, worker); mapper.updateHost(id, worker);
} }
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(status), 1, TimeUnit.HOURS); redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(status), 1, TimeUnit.HOURS);
} }
public ClientStatusReqVo getWorkerHostStatus(Long id) { public ClientStatusReqVo getWorkerHostStatus(Long id) {
String key = String.format(RENDER_WORKER_STATUS_CACHE_KEY, id); String key = String.format(RENDER_WORKER_STATUS_CACHE_KEY, id);
if (redisTemplate.hasKey(key)) { if (redisTemplate.hasKey(key)) {
String status = redisTemplate.opsForValue().get(key); String status = redisTemplate.opsForValue().get(key);
return JSONObject.parseObject(status, ClientStatusReqVo.class); return JacksonUtil.parseObject(status, ClientStatusReqVo.class);
} }
return null; return null;
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.MpConfigMapper; import com.ycwl.basic.mapper.MpConfigMapper;
import com.ycwl.basic.mapper.MpNotifyConfigMapper; import com.ycwl.basic.mapper.MpNotifyConfigMapper;
import com.ycwl.basic.mapper.ScenicMapper; import com.ycwl.basic.mapper.ScenicMapper;
@@ -34,41 +34,41 @@ public class ScenicRepository {
public ScenicEntity getScenic(Long id) { public ScenicEntity getScenic(Long id) {
if (redisTemplate.hasKey(String.format(SCENIC_CACHE_KEY, id))) { if (redisTemplate.hasKey(String.format(SCENIC_CACHE_KEY, id))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CACHE_KEY, id)), ScenicEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CACHE_KEY, id)), ScenicEntity.class);
} }
ScenicEntity scenic = scenicMapper.get(id); ScenicEntity scenic = scenicMapper.get(id);
if (scenic != null) { if (scenic != null) {
redisTemplate.opsForValue().set(String.format(SCENIC_CACHE_KEY, id), JSONObject.toJSONString(scenic)); redisTemplate.opsForValue().set(String.format(SCENIC_CACHE_KEY, id), JacksonUtil.toJSONString(scenic));
} }
return scenic; return scenic;
} }
public ScenicConfigEntity getScenicConfig(Long scenicId) { public ScenicConfigEntity getScenicConfig(Long scenicId) {
if (redisTemplate.hasKey(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId))) { if (redisTemplate.hasKey(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId)), ScenicConfigEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId)), ScenicConfigEntity.class);
} }
ScenicConfigEntity scenicConfig = scenicMapper.getConfig(scenicId); ScenicConfigEntity scenicConfig = scenicMapper.getConfig(scenicId);
if (scenicConfig != null) { if (scenicConfig != null) {
redisTemplate.opsForValue().set(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId), JSONObject.toJSONString(scenicConfig)); redisTemplate.opsForValue().set(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId), JacksonUtil.toJSONString(scenicConfig));
} }
return scenicConfig; return scenicConfig;
} }
public MpConfigEntity getScenicMpConfig(Long scenicId) { public MpConfigEntity getScenicMpConfig(Long scenicId) {
if (redisTemplate.hasKey(String.format(SCENIC_MP_CACHE_KEY, scenicId))) { if (redisTemplate.hasKey(String.format(SCENIC_MP_CACHE_KEY, scenicId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_CACHE_KEY, scenicId)), MpConfigEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_CACHE_KEY, scenicId)), MpConfigEntity.class);
} }
ScenicEntity scenic = getScenic(scenicId); ScenicEntity scenic = getScenic(scenicId);
MpConfigEntity mpConfigEntity = mpConfigMapper.selectById(scenic.getMpId()); MpConfigEntity mpConfigEntity = mpConfigMapper.selectById(scenic.getMpId());
if (mpConfigEntity != null) { if (mpConfigEntity != null) {
redisTemplate.opsForValue().set(String.format(SCENIC_MP_CACHE_KEY, scenicId), JSONObject.toJSONString(mpConfigEntity)); redisTemplate.opsForValue().set(String.format(SCENIC_MP_CACHE_KEY, scenicId), JacksonUtil.toJSONString(mpConfigEntity));
} }
return mpConfigEntity; return mpConfigEntity;
} }
public ScenicMpNotifyVO getScenicMpNotifyConfig(Long scenicId) { public ScenicMpNotifyVO getScenicMpNotifyConfig(Long scenicId) {
if (redisTemplate.hasKey(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId))) { if (redisTemplate.hasKey(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId)), ScenicMpNotifyVO.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId)), ScenicMpNotifyVO.class);
} }
MpConfigEntity mpConfig = getScenicMpConfig(scenicId); MpConfigEntity mpConfig = getScenicMpConfig(scenicId);
if (mpConfig == null) { if (mpConfig == null) {
@@ -93,7 +93,7 @@ public class ScenicRepository {
break; break;
} }
}); });
redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JSONObject.toJSONString(mpNotifyConfig)); redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JacksonUtil.toJSONString(mpNotifyConfig));
return mpNotifyConfig; return mpNotifyConfig;
} }

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.mapper.FaceMapper; import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper; import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.TemplateMapper; import com.ycwl.basic.mapper.TemplateMapper;
@@ -56,10 +57,10 @@ public class TemplateRepository {
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) { public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
List<Long> idList; List<Long> idList;
if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) { if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) {
idList = JSONObject.parseArray(redisTemplate.opsForValue().get(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId)), Long.class); idList = JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId)), new TypeReference<List<Long>>() {});
} else { } else {
idList = templateMapper.listEnabledTemplateIdByScenicId(scenicId); idList = templateMapper.listEnabledTemplateIdByScenicId(scenicId);
redisTemplate.opsForValue().set(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId), JSONObject.toJSONString(idList)); redisTemplate.opsForValue().set(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId), JacksonUtil.toJSONString(idList));
} }
if (idList == null || idList.isEmpty()) { if (idList == null || idList.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
@@ -78,7 +79,7 @@ public class TemplateRepository {
public TemplateRespVO getTemplate(Long templateId) { public TemplateRespVO getTemplate(Long templateId) {
if (redisTemplate.hasKey(String.format(TEMPLATE_CACHE_KEY, templateId))) { if (redisTemplate.hasKey(String.format(TEMPLATE_CACHE_KEY, templateId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CACHE_KEY, templateId)), TemplateRespVO.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CACHE_KEY, templateId)), TemplateRespVO.class);
} }
TemplateRespVO template = templateMapper.getById(templateId); TemplateRespVO template = templateMapper.getById(templateId);
if (template == null) { if (template == null) {
@@ -86,7 +87,7 @@ public class TemplateRepository {
} }
if (null == template.getPid() || template.getPid() == 0) { if (null == template.getPid() || template.getPid() == 0) {
template.setChildren(templateMapper.getByPid(templateId)); template.setChildren(templateMapper.getByPid(templateId));
redisTemplate.opsForValue().set(String.format(TEMPLATE_CACHE_KEY, templateId), JSONObject.toJSONString(template)); redisTemplate.opsForValue().set(String.format(TEMPLATE_CACHE_KEY, templateId), JacksonUtil.toJSONString(template));
return template; return template;
} else { } else {
clearTemplateCache(templateId); clearTemplateCache(templateId);
@@ -99,7 +100,7 @@ public class TemplateRepository {
return new TemplateConfigEntity(); return new TemplateConfigEntity();
} }
if (redisTemplate.hasKey(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId))) { if (redisTemplate.hasKey(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId)), TemplateConfigEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId)), TemplateConfigEntity.class);
} }
TemplateConfigEntity templateConfig = templateMapper.getConfig(templateId); TemplateConfigEntity templateConfig = templateMapper.getConfig(templateId);
if (templateConfig == null) { if (templateConfig == null) {
@@ -108,7 +109,7 @@ public class TemplateRepository {
templateConfig.setTemplateId(templateId); templateConfig.setTemplateId(templateId);
templateMapper.addConfig(templateConfig); templateMapper.addConfig(templateConfig);
} }
redisTemplate.opsForValue().set(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId), JSONObject.toJSONString(templateConfig)); redisTemplate.opsForValue().set(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId), JacksonUtil.toJSONString(templateConfig));
return templateConfig; return templateConfig;
} }

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.VideoMapper; import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity; import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity;
import com.ycwl.basic.model.pc.video.entity.VideoEntity; import com.ycwl.basic.model.pc.video.entity.VideoEntity;
@@ -25,24 +25,24 @@ public class VideoRepository {
public VideoEntity getVideo(Long videoId) { public VideoEntity getVideo(Long videoId) {
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) { if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_CACHE_KEY, videoId)), VideoEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_CACHE_KEY, videoId)), VideoEntity.class);
} }
VideoEntity video = videoMapper.getEntity(videoId); VideoEntity video = videoMapper.getEntity(videoId);
if (video != null) { if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.toJSONString(video), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JSON.toJSONString(video), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
} }
return video; return video;
} }
public VideoEntity getVideoByTaskId(Long taskId) { public VideoEntity getVideoByTaskId(Long taskId) {
if (redisTemplate.hasKey(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId))) { if (redisTemplate.hasKey(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId)), VideoEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId)), VideoEntity.class);
} }
VideoEntity video = videoMapper.findByTaskId(taskId); VideoEntity video = videoMapper.findByTaskId(taskId);
if (video != null) { if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JSON.toJSONString(video), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JSON.toJSONString(video), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
} }
return video; return video;
} }

View File

@@ -1,8 +1,6 @@
package com.ycwl.basic.repository; package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.mapper.TaskMapper; import com.ycwl.basic.mapper.TaskMapper;
import com.ycwl.basic.mapper.VideoMapper; import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.task.entity.TaskEntity; import com.ycwl.basic.model.pc.task.entity.TaskEntity;
@@ -27,11 +25,11 @@ public class VideoTaskRepository {
public TaskEntity getTaskById(Long taskId) { public TaskEntity getTaskById(Long taskId) {
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) { if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class); return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class);
} else { } else {
TaskEntity task = taskMapper.get(taskId); TaskEntity task = taskMapper.get(taskId);
if (task != null && 1 == task.getStatus()) { if (task != null && 1 == task.getStatus()) {
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task), 12, TimeUnit.HOURS); redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JacksonUtil.toJSONString(task), 12, TimeUnit.HOURS);
} }
return task; return task;
} }
@@ -48,14 +46,14 @@ public class VideoTaskRepository {
return null; return null;
} }
Date shotTime = taskRespVO.getCreateTime(); Date shotTime = taskRespVO.getCreateTime();
JSONObject paramJson = JSON.parseObject(taskRespVO.getTaskParams()); JacksonUtil.JSONObjectCompat paramJson = JacksonUtil.JSONObjectCompat.parseObject(taskRespVO.getTaskParams());
if (paramJson != null) { if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny(); Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) { if (any.isPresent()) {
JSONArray jsonArray = paramJson.getJSONArray(any.get()); var jsonArray = paramJson.getJSONArray(any.get());
if (!jsonArray.isEmpty()) { if (jsonArray != null && !jsonArray.isEmpty()) {
JSONObject jsonObject = jsonArray.getJSONObject(0); JacksonUtil.JSONObjectCompat jsonObject = jsonArray.get(0);
if (jsonObject.containsKey("createTime")) { if (jsonObject.getLong("createTime") != null) {
shotTime = new Date(jsonObject.getLong("createTime")); shotTime = new Date(jsonObject.getLong("createTime"));
} }
} }

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.service.mobile.impl; package com.ycwl.basic.service.mobile.impl;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.constant.BaseContextHandler; import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.constant.NumberConstant; import com.ycwl.basic.constant.NumberConstant;
import com.ycwl.basic.enums.BizCodeEnum; import com.ycwl.basic.enums.BizCodeEnum;
@@ -61,7 +61,7 @@ public class AppMemberServiceImpl implements AppMemberService {
if (StringUtils.isBlank(response)) { if (StringUtils.isBlank(response)) {
return null; return null;
} }
return JSONObject.parseObject(response); return JacksonUtil.parseObject(response, Map.class);
} catch (Exception e) { } catch (Exception e) {
log.error("getOpenId", e); log.error("getOpenId", e);
throw new AppException(BizCodeEnum.SERVER_INTERNAL_ERROR); throw new AppException(BizCodeEnum.SERVER_INTERNAL_ERROR);

View File

@@ -3,8 +3,7 @@ package com.ycwl.basic.service.mobile.impl;
import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.enums.StatisticEnum; import com.ycwl.basic.enums.StatisticEnum;
import com.ycwl.basic.mapper.StatisticsMapper; import com.ycwl.basic.mapper.StatisticsMapper;
import com.ycwl.basic.model.jwt.JwtInfo; import com.ycwl.basic.model.jwt.JwtInfo;
@@ -188,8 +187,8 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
// 缓存 // 缓存
if (redisTemplate.hasKey(redisKey)) { if (redisTemplate.hasKey(redisKey)) {
String s = redisTemplate.opsForValue().get(redisKey); String s = redisTemplate.opsForValue().get(redisKey);
JSONObject cacheObj = JSON.parseObject(s); Map<String, Object> cacheObj = JacksonUtil.parseObject(s, Map.class);
return ApiResponse.success(cacheObj.toJavaObject(AppStatisticsFunnelVO.class)); return ApiResponse.success(JacksonUtil.toJavaObject(cacheObj, AppStatisticsFunnelVO.class));
} }
} }
} }
@@ -202,8 +201,8 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
// 缓存 // 缓存
if (redisTemplate.hasKey(redisKey)) { if (redisTemplate.hasKey(redisKey)) {
String s = redisTemplate.opsForValue().get(redisKey); String s = redisTemplate.opsForValue().get(redisKey);
JSONObject cacheObj = JSON.parseObject(s); Map<String, Object> cacheObj = JacksonUtil.parseObject(s, Map.class);
return ApiResponse.success(cacheObj.toJavaObject(AppStatisticsFunnelVO.class)); return ApiResponse.success(JacksonUtil.toJavaObject(cacheObj, AppStatisticsFunnelVO.class));
} }
} }
} }
@@ -266,7 +265,7 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
vo.setRefundOfOrderNum(refundOfOrderNum); vo.setRefundOfOrderNum(refundOfOrderNum);
vo.setRefundOfOrderAmount(refundOfOrderAmount.setScale(2, RoundingMode.HALF_UP)); vo.setRefundOfOrderAmount(refundOfOrderAmount.setScale(2, RoundingMode.HALF_UP));
statisticsMapper.insertStat(query.getScenicId(), new Date(), vo); statisticsMapper.insertStat(query.getScenicId(), new Date(), vo);
redisTemplate.opsForValue().set(redisKey, JSON.toJSONString(vo), 60, TimeUnit.SECONDS); redisTemplate.opsForValue().set(redisKey, JacksonUtil.toJSONString(vo), 60, TimeUnit.SECONDS);
return ApiResponse.success(vo); return ApiResponse.success(vo);
} finally { } finally {
lock.unlock(); lock.unlock();

View File

@@ -3,9 +3,7 @@ package com.ycwl.basic.service.mobile.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.biz.CouponBiz; import com.ycwl.basic.biz.CouponBiz;
import com.ycwl.basic.biz.OrderBiz; import com.ycwl.basic.biz.OrderBiz;
import com.ycwl.basic.biz.TaskStatusBiz; import com.ycwl.basic.biz.TaskStatusBiz;
@@ -287,7 +285,7 @@ public class GoodsServiceImpl implements GoodsService {
if (task == null) { if (task == null) {
return ApiResponse.fail("该vlog不存在或已失效"); return ApiResponse.fail("该vlog不存在或已失效");
} }
JSONObject paramJson = JSON.parseObject(task.getTaskParams()); Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
AtomicInteger deviceCount = new AtomicInteger(); AtomicInteger deviceCount = new AtomicInteger();
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId())); goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId()));
if (paramJson == null) { if (paramJson == null) {
@@ -297,7 +295,7 @@ public class GoodsServiceImpl implements GoodsService {
paramJson.entrySet().stream() paramJson.entrySet().stream()
.filter(entry -> StringUtils.isNumeric(entry.getKey())) .filter(entry -> StringUtils.isNumeric(entry.getKey()))
.forEach(entry -> { .forEach(entry -> {
JSONArray jsonArray = paramJson.getJSONArray(entry.getKey()); List<Object> jsonArray = JacksonUtil.parseArray(JacksonUtil.toJSONString(entry.getValue()), Object.class);
if (jsonArray != null && !jsonArray.isEmpty()) { if (jsonArray != null && !jsonArray.isEmpty()) {
for (Object ignored : jsonArray) { for (Object ignored : jsonArray) {
if (templatePlaceholder.contains(entry.getKey())) { if (templatePlaceholder.contains(entry.getKey())) {
@@ -565,7 +563,7 @@ public class GoodsServiceImpl implements GoodsService {
IStorageAdapter adapter; IStorageAdapter adapter;
if (scenicConfig != null && scenicConfig.getStoreType() != null) { if (scenicConfig != null && scenicConfig.getStoreType() != null) {
adapter = StorageFactory.get(scenicConfig.getStoreType()); adapter = StorageFactory.get(scenicConfig.getStoreType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getStoreConfigJson(), Map.class));
} else { } else {
adapter = StorageFactory.use("assets-ext"); adapter = StorageFactory.use("assets-ext");
} }
@@ -674,7 +672,7 @@ public class GoodsServiceImpl implements GoodsService {
IStorageAdapter adapter; IStorageAdapter adapter;
if (scenicConfig.getStoreType() != null) { if (scenicConfig.getStoreType() != null) {
adapter = StorageFactory.get(scenicConfig.getStoreType()); adapter = StorageFactory.get(scenicConfig.getStoreType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getStoreConfigJson(), Map.class));
} else { } else {
adapter = StorageFactory.use("assets-ext"); adapter = StorageFactory.use("assets-ext");
} }

View File

@@ -1,7 +1,6 @@
package com.ycwl.basic.service.pc.impl; package com.ycwl.basic.service.pc.impl;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.ycwl.basic.biz.CouponBiz; import com.ycwl.basic.biz.CouponBiz;
@@ -252,7 +251,7 @@ public class OrderServiceImpl implements OrderService {
if (task.getTaskParams() == null) { if (task.getTaskParams() == null) {
deviceCount = 1; deviceCount = 1;
} else { } else {
JSONObject paramJson = JSON.parseObject(task.getTaskParams()); Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId()); List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
deviceCount = paramJson.keySet().stream() deviceCount = paramJson.keySet().stream()
.filter(StringUtils::isNumeric) .filter(StringUtils::isNumeric)

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.service.pc.impl; package com.ycwl.basic.service.pc.impl;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.ycwl.basic.facebody.FaceBodyFactory; import com.ycwl.basic.facebody.FaceBodyFactory;
@@ -233,7 +233,7 @@ public class ScenicServiceImpl implements ScenicService {
if (scenicConfig != null && scenicConfig.getStoreType() != null) { if (scenicConfig != null && scenicConfig.getStoreType() != null) {
try { try {
adapter = StorageFactory.get(scenicConfig.getStoreType()); adapter = StorageFactory.get(scenicConfig.getStoreType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getStoreConfigJson(), Map.class));
} catch (StorageUnsupportedException ignored) { } catch (StorageUnsupportedException ignored) {
return StorageFactory.use("video"); return StorageFactory.use("video");
} }
@@ -252,7 +252,7 @@ public class ScenicServiceImpl implements ScenicService {
if (scenicConfig != null && scenicConfig.getTmpStoreType() != null) { if (scenicConfig != null && scenicConfig.getTmpStoreType() != null) {
try { try {
adapter = StorageFactory.get(scenicConfig.getTmpStoreType()); adapter = StorageFactory.get(scenicConfig.getTmpStoreType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getTmpStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getTmpStoreConfigJson(), Map.class));
} catch (StorageUnsupportedException ignored) { } catch (StorageUnsupportedException ignored) {
return getScenicStorageAdapter(scenicId); return getScenicStorageAdapter(scenicId);
} }
@@ -271,7 +271,7 @@ public class ScenicServiceImpl implements ScenicService {
if (scenicConfig != null && scenicConfig.getLocalStoreType() != null) { if (scenicConfig != null && scenicConfig.getLocalStoreType() != null) {
try { try {
adapter = StorageFactory.get(scenicConfig.getLocalStoreType()); adapter = StorageFactory.get(scenicConfig.getLocalStoreType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getLocalStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getLocalStoreConfigJson(), Map.class));
} catch (StorageUnsupportedException ignored) { } catch (StorageUnsupportedException ignored) {
return getScenicStorageAdapter(scenicId); return getScenicStorageAdapter(scenicId);
} }
@@ -290,7 +290,7 @@ public class ScenicServiceImpl implements ScenicService {
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId); ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
if (scenicConfig != null && scenicConfig.getFaceType() != null) { if (scenicConfig != null && scenicConfig.getFaceType() != null) {
adapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType()); adapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
} else { } else {
adapter = FaceBodyFactory.use(); adapter = FaceBodyFactory.use();
} }
@@ -306,7 +306,7 @@ public class ScenicServiceImpl implements ScenicService {
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId); ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
if (scenicConfig != null && scenicConfig.getPayType() != null) { if (scenicConfig != null && scenicConfig.getPayType() != null) {
adapter = PayFactory.getAdapter(scenicConfig.getPayType()); adapter = PayFactory.getAdapter(scenicConfig.getPayType());
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getPayConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getPayConfigJson(), Map.class));
} else { } else {
adapter = PayFactory.use(); adapter = PayFactory.use();
} }

View File

@@ -1,8 +1,7 @@
package com.ycwl.basic.service.task.impl; package com.ycwl.basic.service.task.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.facebody.model.v20191230.SearchFaceRequest; import com.aliyuncs.facebody.model.v20191230.SearchFaceRequest;
import com.ycwl.basic.biz.OrderBiz; import com.ycwl.basic.biz.OrderBiz;
import com.ycwl.basic.constant.FaceConstant; import com.ycwl.basic.constant.FaceConstant;
@@ -98,7 +97,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
IFaceBodyAdapter faceBodyAdapter; IFaceBodyAdapter faceBodyAdapter;
if (scenicConfig != null && scenicConfig.getFaceType() != null) { if (scenicConfig != null && scenicConfig.getFaceType() != null) {
faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType()); faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
faceBodyAdapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class)); faceBodyAdapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
} else { } else {
faceBodyAdapter = FaceBodyFactory.use(); faceBodyAdapter = FaceBodyFactory.use();
} }
@@ -202,7 +201,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
SearchFaceRespVo respVo = new SearchFaceRespVo(); SearchFaceRespVo respVo = new SearchFaceRespVo();
List<SearchFaceResultItem> records = response.getResult(); List<SearchFaceResultItem> records = response.getResult();
respVo.setScore(response.getOriginalFaceScore()); respVo.setScore(response.getOriginalFaceScore());
respVo.setSearchResultJson(JSON.toJSONString(records)); respVo.setSearchResultJson(JacksonUtil.toJSONString(records));
logEntity.setMatchRawRecord(records); logEntity.setMatchRawRecord(records);
if (records.isEmpty()) { if (records.isEmpty()) {
return respVo; return respVo;
@@ -265,7 +264,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
record.setMatched(item.getScore() > _threshold); record.setMatched(item.getScore() > _threshold);
collect.add(record); collect.add(record);
} }
logEntity.setMatchLocalRecord(JSONObject.toJSONString(collect)); logEntity.setMatchLocalRecord(JacksonUtil.toJSONString(collect));
if (acceptFaceSampleIds.isEmpty()) { if (acceptFaceSampleIds.isEmpty()) {
respVo.setFirstMatchRate(0f); respVo.setFirstMatchRate(0f);
respVo.setSampleListIds(Collections.emptyList()); respVo.setSampleListIds(Collections.emptyList());

View File

@@ -1,9 +1,7 @@
package com.ycwl.basic.service.task.impl; package com.ycwl.basic.service.task.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.biz.OrderBiz; import com.ycwl.basic.biz.OrderBiz;
import com.ycwl.basic.biz.TaskStatusBiz; import com.ycwl.basic.biz.TaskStatusBiz;
import com.ycwl.basic.biz.TemplateBiz; import com.ycwl.basic.biz.TemplateBiz;
@@ -259,7 +257,7 @@ public class TaskTaskServiceImpl implements TaskService {
TaskReqQuery taskReqQuery = new TaskReqQuery(); TaskReqQuery taskReqQuery = new TaskReqQuery();
taskReqQuery.setFaceId(faceId); taskReqQuery.setFaceId(faceId);
taskReqQuery.setTemplateId(templateId); taskReqQuery.setTemplateId(templateId);
taskReqQuery.setTaskParams(JSON.toJSONString(sourcesMap)); taskReqQuery.setTaskParams(JacksonUtil.toJSONString(sourcesMap));
List<TaskRespVO> list = taskMapper.list(taskReqQuery); List<TaskRespVO> list = taskMapper.list(taskReqQuery);
MemberVideoEntity memberVideoEntity = new MemberVideoEntity(); MemberVideoEntity memberVideoEntity = new MemberVideoEntity();
@@ -298,7 +296,7 @@ public class TaskTaskServiceImpl implements TaskService {
} }
taskEntity.setWorkerId(null); taskEntity.setWorkerId(null);
taskEntity.setStatus(0); taskEntity.setStatus(0);
taskEntity.setTaskParams(JSON.toJSONString(sourcesMap)); taskEntity.setTaskParams(JacksonUtil.toJSONString(sourcesMap));
taskMapper.add(taskEntity); taskMapper.add(taskEntity);
memberVideoEntity.setTaskId(taskEntity.getId()); memberVideoEntity.setTaskId(taskEntity.getId());
} else { } else {
@@ -471,7 +469,7 @@ public class TaskTaskServiceImpl implements TaskService {
TaskReqQuery taskReqQuery = new TaskReqQuery(); TaskReqQuery taskReqQuery = new TaskReqQuery();
taskReqQuery.setFaceId(faceId); taskReqQuery.setFaceId(faceId);
taskReqQuery.setTemplateId(templateId); taskReqQuery.setTemplateId(templateId);
taskReqQuery.setTaskParams(JSON.toJSONString(sourcesMap)); taskReqQuery.setTaskParams(JacksonUtil.toJSONString(sourcesMap));
List<TaskRespVO> list = taskMapper.list(taskReqQuery); List<TaskRespVO> list = taskMapper.list(taskReqQuery);
MemberVideoEntity memberVideoEntity = new MemberVideoEntity(); MemberVideoEntity memberVideoEntity = new MemberVideoEntity();
@@ -510,7 +508,7 @@ public class TaskTaskServiceImpl implements TaskService {
} }
taskEntity.setWorkerId(null); taskEntity.setWorkerId(null);
taskEntity.setStatus(0); taskEntity.setStatus(0);
taskEntity.setTaskParams(JSON.toJSONString(sourcesMap)); taskEntity.setTaskParams(JacksonUtil.toJSONString(sourcesMap));
taskMapper.add(taskEntity); taskMapper.add(taskEntity);
memberVideoEntity.setTaskId(taskEntity.getId()); memberVideoEntity.setTaskId(taskEntity.getId());
} else { } else {
@@ -650,7 +648,7 @@ public class TaskTaskServiceImpl implements TaskService {
IStorageAdapter adapter; IStorageAdapter adapter;
try { try {
adapter = StorageFactory.get(worker.getStoreType()); adapter = StorageFactory.get(worker.getStoreType());
adapter.loadConfig(JSONObject.parseObject(worker.getStoreConfigJson(), Map.class)); adapter.loadConfig(JacksonUtil.parseObject(worker.getStoreConfigJson(), Map.class));
} catch (Exception e) { } catch (Exception e) {
adapter = scenicService.getScenicStorageAdapter(task.getScenicId()); adapter = scenicService.getScenicStorageAdapter(task.getScenicId());
} }
@@ -677,15 +675,19 @@ public class TaskTaskServiceImpl implements TaskService {
return null; return null;
} }
Date shotTime = taskRespVO.getCreateTime(); Date shotTime = taskRespVO.getCreateTime();
JSONObject paramJson = JSON.parseObject(taskRespVO.getTaskParams()); Map<String, Object> paramJson = JacksonUtil.parseObject(taskRespVO.getTaskParams(), Map.class);
if (paramJson != null) { if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny(); Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) { if (any.isPresent()) {
JSONArray jsonArray = paramJson.getJSONArray(any.get()); @SuppressWarnings("unchecked")
if (!jsonArray.isEmpty()) { List<Map<String, Object>> jsonArray = (List<Map<String, Object>>) paramJson.get(any.get());
JSONObject jsonObject = jsonArray.getJSONObject(0); if (jsonArray != null && !jsonArray.isEmpty()) {
Map<String, Object> jsonObject = jsonArray.get(0);
if (jsonObject.containsKey("createTime")) { if (jsonObject.containsKey("createTime")) {
shotTime = new Date(jsonObject.getLong("createTime")); Object createTimeObj = jsonObject.get("createTime");
if (createTimeObj instanceof Number) {
shotTime = new Date(((Number) createTimeObj).longValue());
}
} }
} }
} }

View File

@@ -138,8 +138,9 @@ public class DownloadNotificationTasker {
CouponQueryReq query = new CouponQueryReq(); CouponQueryReq query = new CouponQueryReq();
query.setScenicId(item.getScenicId()); query.setScenicId(item.getScenicId());
query.setType(3); query.setType(3);
query.setStatus(1);
List<CouponRespVO> coupons = couponMapper.selectByQuery(query); List<CouponRespVO> coupons = couponMapper.selectByQuery(query);
if (coupons.isEmpty()) { if (coupons.isEmpty() || StringUtils.isBlank(coupons.getFirst().getBroadcast())) {
remarkMap.put("value", "视频即将删除,花点小钱买下回忆"); remarkMap.put("value", "视频即将删除,花点小钱买下回忆");
} else { } else {
remarkMap.put("value", coupons.getFirst().getBroadcast()); remarkMap.put("value", coupons.getFirst().getBroadcast());

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.task; package com.ycwl.basic.task;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.biz.TemplateBiz; import com.ycwl.basic.biz.TemplateBiz;
import com.ycwl.basic.facebody.FaceBodyFactory; import com.ycwl.basic.facebody.FaceBodyFactory;
import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter; import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter;
@@ -116,7 +116,7 @@ public class DynamicTaskGenerator {
IFaceBodyAdapter faceBodyAdapter; IFaceBodyAdapter faceBodyAdapter;
if (scenicConfig.getFaceType() != null) { if (scenicConfig.getFaceType() != null) {
faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType()); faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
faceBodyAdapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class)); faceBodyAdapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
} else { } else {
faceBodyAdapter = FaceBodyFactory.use(); faceBodyAdapter = FaceBodyFactory.use();
} }

View File

@@ -3,9 +3,7 @@ package com.ycwl.basic.task;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.ycwl.basic.utils.JacksonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import java.util.Date; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -32,12 +30,12 @@ public class N9eSyncTask {
String auth = "Basic " + Base64.encode("user001:ccc26da7b9aba533cbb263a36c07dcc4"); String auth = "Basic " + Base64.encode("user001:ccc26da7b9aba533cbb263a36c07dcc4");
// 构建请求体 // 构建请求体
JSONObject requestBody = new JSONObject(); Map<String, Object> requestBody = new HashMap<>();
JSONArray queries = new JSONArray(); List<Map<String, Object>> queries = new ArrayList<>();
JSONObject query = new JSONObject(); Map<String, Object> query = new HashMap<>();
query.put("key", "group_ids"); query.put("key", "group_ids");
query.put("op", "=="); query.put("op", "==");
JSONArray values = new JSONArray(); List<Integer> values = new ArrayList<>();
values.add(4); values.add(4);
query.put("values", values); query.put("values", values);
queries.add(query); queries.add(query);
@@ -47,23 +45,27 @@ public class N9eSyncTask {
HttpResponse response = HttpUtil.createPost("https://n9e.jerryyan.top/v1/n9e/target/list") HttpResponse response = HttpUtil.createPost("https://n9e.jerryyan.top/v1/n9e/target/list")
.header("Authorization", auth) .header("Authorization", auth)
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(requestBody.toJSONString()) .body(JacksonUtil.toJSONString(requestBody))
.execute(); .execute();
JSONObject respData = JSON.parseObject(response.body()); Map<String, Object> respData = JacksonUtil.parseObject(response.body(), Map.class);
if (StringUtils.isNotBlank(respData.getString("err"))) { String err = (String) respData.get("err");
if (StringUtils.isNotBlank(err)) {
log.warn("N9E信息获取失败"); log.warn("N9E信息获取失败");
return; return;
} }
JSONObject data = respData.getJSONObject("dat"); @SuppressWarnings("unchecked")
if (data.getInteger("total") <= 0) { Map<String, Object> data = (Map<String, Object>) respData.get("dat");
Integer total = (Integer) data.get("total");
if (total == null || total <= 0) {
log.warn("N9E信息为空"); log.warn("N9E信息为空");
return; return;
} }
JSONArray list = data.getJSONArray("list"); @SuppressWarnings("unchecked")
List<Map<String, Object>> list = (List<Map<String, Object>>) data.get("list");
list.forEach(item -> { list.forEach(item -> {
JSONObject itemObj = (JSONObject) item; String ident = (String) item.get("ident");
String ident = itemObj.getString("ident"); Number updateAtNum = (Number) item.get("update_at");
Long updateAt = itemObj.getLong("update_at"); Long updateAt = updateAtNum != null ? updateAtNum.longValue() : 0L;
redisTemplate.opsForValue().set("ext_device:online:" + ident, updateAt.toString(), 1, TimeUnit.DAYS); redisTemplate.opsForValue().set("ext_device:online:" + ident, updateAt.toString(), 1, TimeUnit.DAYS);
}); });
} }

View File

@@ -0,0 +1,511 @@
package com.ycwl.basic.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Jackson JSON工具类
* 提供简单易用的JSON序列化和反序列化功能
*/
public class JacksonUtil {
private static final ObjectMapper objectMapper = new ObjectMapper();
/**
* 对象转JSON字符串
* @param obj 要转换的对象
* @return JSON字符串
*/
public static String toJson(Object obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException("对象转JSON失败", e);
}
}
/**
* JSON字符串转对象
* @param json JSON字符串
* @param clazz 目标类型
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T fromJson(String json, Class<T> clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
throw new RuntimeException("JSON转对象失败", e);
}
}
/**
* JSON字符串转对象(支持复杂类型)
* @param json JSON字符串
* @param typeReference 类型引用
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T fromJson(String json, TypeReference<T> typeReference) {
try {
return objectMapper.readValue(json, typeReference);
} catch (IOException e) {
throw new RuntimeException("JSON转对象失败", e);
}
}
/**
* JSON字符串转List
* @param json JSON字符串
* @param elementClass 列表元素类型
* @param <T> 泛型类型
* @return List对象
*/
public static <T> List<T> fromJsonToList(String json, Class<T> elementClass) {
try {
TypeFactory typeFactory = objectMapper.getTypeFactory();
CollectionType listType = typeFactory.constructCollectionType(List.class, elementClass);
return objectMapper.readValue(json, listType);
} catch (IOException e) {
throw new RuntimeException("JSON转List失败", e);
}
}
/**
* JSON字符串转Map
* @param json JSON字符串
* @return Map对象
*/
public static Map<String, Object> fromJsonToMap(String json) {
try {
return objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
} catch (IOException e) {
throw new RuntimeException("JSON转Map失败", e);
}
}
/**
* 获取JSON节点
* @param json JSON字符串
* @return JsonNode对象
*/
public static JsonNode getJsonNode(String json) {
try {
return objectMapper.readTree(json);
} catch (IOException e) {
throw new RuntimeException("解析JSON失败", e);
}
}
/**
* 从JSON中获取字符串值
* @param json JSON字符串
* @param path 路径(支持嵌套,如:"user.name")
* @return 字符串值
*/
public static String getString(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isNull() ? node.asText() : null;
}
/**
* 从JSON中获取整数值
* @param json JSON字符串
* @param path 路径
* @return 整数值
*/
public static Integer getInt(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isNull() ? node.asInt() : null;
}
/**
* 从JSON中获取长整数值
* @param json JSON字符串
* @param path 路径
* @return 长整数值
*/
public static Long getLong(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isNull() ? node.asLong() : null;
}
/**
* 从JSON中获取双精度浮点数值
* @param json JSON字符串
* @param path 路径
* @return 双精度浮点数值
*/
public static Double getDouble(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isNull() ? node.asDouble() : null;
}
/**
* 从JSON中获取布尔值
* @param json JSON字符串
* @param path 路径
* @return 布尔值
*/
public static Boolean getBoolean(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isNull() ? node.asBoolean() : null;
}
/**
* 从JSON中获取对象
* @param json JSON字符串
* @param path 路径
* @param clazz 目标类型
* @param <T> 泛型类型
* @return 对象
*/
public static <T> T getObject(String json, String path, Class<T> clazz) {
JsonNode node = getValueByPath(json, path);
if (node != null && !node.isNull()) {
try {
return objectMapper.treeToValue(node, clazz);
} catch (JsonProcessingException e) {
throw new RuntimeException("JSON节点转对象失败", e);
}
}
return null;
}
/**
* 从JSON中获取数组
* @param json JSON字符串
* @param path 路径
* @param elementClass 数组元素类型
* @param <T> 泛型类型
* @return List对象
*/
public static <T> List<T> getArray(String json, String path, Class<T> elementClass) {
JsonNode node = getValueByPath(json, path);
if (node != null && node.isArray()) {
try {
TypeFactory typeFactory = objectMapper.getTypeFactory();
CollectionType listType = typeFactory.constructCollectionType(List.class, elementClass);
return objectMapper.treeToValue(node, listType);
} catch (JsonProcessingException e) {
throw new RuntimeException("JSON节点转数组失败", e);
}
}
return null;
}
/**
* 检查JSON中是否存在指定路径
* @param json JSON字符串
* @param path 路径
* @return 是否存在
*/
public static boolean hasPath(String json, String path) {
JsonNode node = getValueByPath(json, path);
return node != null && !node.isMissingNode();
}
/**
* 根据路径获取JSON节点值
* @param json JSON字符串
* @param path 路径(支持嵌套,如:"user.name"或"users[0].name")
* @return JsonNode对象
*/
private static JsonNode getValueByPath(String json, String path) {
try {
JsonNode rootNode = objectMapper.readTree(json);
String[] pathParts = path.split("\\.");
JsonNode currentNode = rootNode;
for (String part : pathParts) {
if (currentNode == null || currentNode.isMissingNode()) {
return null;
}
// 处理数组索引,如:users[0]
if (part.contains("[") && part.contains("]")) {
String fieldName = part.substring(0, part.indexOf("["));
String indexStr = part.substring(part.indexOf("[") + 1, part.indexOf("]"));
int index = Integer.parseInt(indexStr);
currentNode = currentNode.get(fieldName);
if (currentNode != null && currentNode.isArray() && index < currentNode.size()) {
currentNode = currentNode.get(index);
} else {
return null;
}
} else {
currentNode = currentNode.get(part);
}
}
return currentNode;
} catch (Exception e) {
throw new RuntimeException("获取JSON路径值失败", e);
}
}
/**
* 美化JSON字符串(格式化输出)
* @param json JSON字符串
* @return 格式化后的JSON字符串
*/
public static String prettyPrint(String json) {
try {
JsonNode node = objectMapper.readTree(json);
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(node);
} catch (IOException e) {
throw new RuntimeException("JSON格式化失败", e);
}
}
/**
* 获取ObjectMapper实例(用于高级用法)
* @return ObjectMapper实例
*/
public static ObjectMapper getObjectMapper() {
return objectMapper;
}
// ==== FastJSON 兼容性方法 ====
/**
* 兼容 FastJSON 的 JSON.toJSONString() 方法
* @param obj 要转换的对象
* @return JSON字符串
*/
public static String toJSONString(Object obj) {
return toJson(obj);
}
/**
* 兼容 FastJSON 的 JSON.parseObject() 方法
* @param json JSON字符串
* @param clazz 目标类型
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T parseObject(String json, Class<T> clazz) {
return fromJson(json, clazz);
}
/**
* 兼容 FastJSON 的 JSON.parseArray() 方法
* @param json JSON字符串
* @param clazz 数组元素类型
* @param <T> 泛型类型
* @return List对象
*/
public static <T> List<T> parseArray(String json, Class<T> clazz) {
return fromJsonToList(json, clazz);
}
/**
* 带TypeReference的parseObject方法,支持复杂泛型
* @param json JSON字符串
* @param typeReference 类型引用
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T parseObject(String json, TypeReference<T> typeReference) {
return fromJson(json, typeReference);
}
/**
* 将Map或其他对象转换为指定类型,兼容fastjson的toJavaObject方法
* @param obj 源对象
* @param clazz 目标类型
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T toJavaObject(Object obj, Class<T> clazz) {
if (obj == null) {
return null;
}
try {
// 如果对象已经是目标类型,直接返回
if (clazz.isInstance(obj)) {
return clazz.cast(obj);
}
// 先转为JSON字符串,再转为目标对象
String json = toJson(obj);
return fromJson(json, clazz);
} catch (Exception e) {
throw new RuntimeException("对象转换失败", e);
}
}
/**
* 兼容 FastJSON 的 JSONObject.parseObject() 方法
* @param json JSON字符串
* @param clazz 目标类型
* @param <T> 泛型类型
* @return 转换后的对象
*/
public static <T> T parseObjectCompat(String json, Class<T> clazz) {
return fromJson(json, clazz);
}
/**
* 兼容 FastJSON 的 JSONObject.toJSONString() 方法
* @param obj 要转换的对象
* @return JSON字符串
*/
public static String toJSONStringCompat(Object obj) {
return toJson(obj);
}
/**
* 兼容 FastJSON 的 JSONObject.parseArray() 方法
* @param json JSON字符串
* @param clazz 数组元素类型
* @param <T> 泛型类型
* @return List对象
*/
public static <T> List<T> parseArrayCompat(String json, Class<T> clazz) {
return fromJsonToList(json, clazz);
}
/**
* 简单的JSON对象包装类,兼容部分JSONObject的用法
*/
public static class JSONObjectCompat {
private final JsonNode node;
private JSONObjectCompat(JsonNode node) {
this.node = node;
}
/**
* 解析JSON字符串为JSONObjectCompat
* @param json JSON字符串
* @return JSONObjectCompat对象
*/
public static JSONObjectCompat parseObject(String json) {
return new JSONObjectCompat(getJsonNode(json));
}
/**
* 获取JSON数组
* @param key 键名
* @return JSON数组的List表示
*/
public List<JSONObjectCompat> getJSONArray(String key) {
JsonNode arrayNode = node.get(key);
if (arrayNode != null && arrayNode.isArray()) {
List<JSONObjectCompat> result = new java.util.ArrayList<>();
for (JsonNode item : arrayNode) {
result.add(new JSONObjectCompat(item));
}
return result;
}
return null;
}
/**
* 获取JSON对象
* @param index 索引
* @return JSONObjectCompat对象
*/
public JSONObjectCompat getJSONObject(int index) {
if (node.isArray() && index < node.size()) {
return new JSONObjectCompat(node.get(index));
}
return null;
}
/**
* 获取字符串值
* @param key 键名
* @return 字符串值
*/
public String getString(String key) {
JsonNode valueNode = node.get(key);
return valueNode != null && !valueNode.isNull() ? valueNode.asText() : null;
}
/**
* 获取整数值
* @param key 键名
* @return 整数值
*/
public Integer getInteger(String key) {
JsonNode valueNode = node.get(key);
return valueNode != null && !valueNode.isNull() ? valueNode.asInt() : null;
}
/**
* 获取长整数值
* @param key 键名
* @return 长整数值
*/
public Long getLong(String key) {
JsonNode valueNode = node.get(key);
return valueNode != null && !valueNode.isNull() ? valueNode.asLong() : null;
}
/**
* 获取双精度浮点数值
* @param key 键名
* @return 双精度浮点数值
*/
public Double getDouble(String key) {
JsonNode valueNode = node.get(key);
return valueNode != null && !valueNode.isNull() ? valueNode.asDouble() : null;
}
/**
* 获取布尔值
* @param key 键名
* @return 布尔值
*/
public Boolean getBoolean(String key) {
JsonNode valueNode = node.get(key);
return valueNode != null && !valueNode.isNull() ? valueNode.asBoolean() : null;
}
/**
* 获取键集合
* @return 键的Set集合
*/
public java.util.Set<String> keySet() {
if (node.isObject()) {
java.util.Set<String> keys = new java.util.HashSet<>();
node.fieldNames().forEachRemaining(keys::add);
return keys;
}
return java.util.Collections.emptySet();
}
/**
* 检查是否包含指定键
* @param key 键名
* @return 是否包含
*/
public boolean containsKey(String key) {
return node.has(key);
}
/**
* 转换为Java对象
* @param clazz 目标类型
* @param <T> 泛型类型
* @return Java对象
*/
public <T> T toJavaObject(Class<T> clazz) {
try {
return objectMapper.treeToValue(node, clazz);
} catch (JsonProcessingException e) {
throw new RuntimeException("JSON节点转对象失败", e);
}
}
}
}

View File

@@ -2,7 +2,8 @@ package com.ycwl.basic.utils;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.ycwl.basic.utils.JacksonUtil;
import java.util.HashMap;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@@ -37,22 +38,22 @@ public class WxMpUtil {
String token; String token;
if (!System.getProperty("os.name").toLowerCase().startsWith("win")) { if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
String url = String.format(STABLE_ACCESS_TOKEN_URL, appId, appSecret); String url = String.format(STABLE_ACCESS_TOKEN_URL, appId, appSecret);
JSONObject params = new JSONObject(); Map<String, Object> params = new HashMap<>();
params.put("grant_type", "client_credential"); params.put("grant_type", "client_credential");
params.put("appid", appId); params.put("appid", appId);
params.put("secret", appSecret); params.put("secret", appSecret);
params.put("force_refresh", false); params.put("force_refresh", false);
String response = HttpUtil.post(url, params.toJSONString()); String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
JSONObject jsonObject = JSONObject.parseObject(response); Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
token = jsonObject.getString("access_token"); token = (String) jsonObject.get("access_token");
Date expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000 / 2); Date expireTime = new Date(System.currentTimeMillis() + ((Integer) jsonObject.get("expires_in")) * 1000 / 2);
expireTimes.put(appId, expireTime); expireTimes.put(appId, expireTime);
} else { } else {
String url = String.format(ACCESS_TOKEN_URL, appId, appSecret); String url = String.format(ACCESS_TOKEN_URL, appId, appSecret);
String response = HttpUtil.get(url); String response = HttpUtil.get(url);
JSONObject jsonObject = JSONObject.parseObject(response); Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
token = jsonObject.getString("access_token"); token = (String) jsonObject.get("access_token");
Date expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000 / 2); Date expireTime = new Date(System.currentTimeMillis() + ((Integer) jsonObject.get("expires_in")) * 1000 / 2);
expireTimes.put(appId, expireTime); expireTimes.put(appId, expireTime);
} }
return token; return token;
@@ -64,12 +65,12 @@ public class WxMpUtil {
public static void generateWXAQRCode(String appId, String appSecret, String envVersion, String path, String filePath) throws Exception { public static void generateWXAQRCode(String appId, String appSecret, String envVersion, String path, String filePath) throws Exception {
String url = String.format(GET_WXA_CODE_URL, getAccessToken(appId, appSecret)); String url = String.format(GET_WXA_CODE_URL, getAccessToken(appId, appSecret));
JSONObject json = new JSONObject(); Map<String, Object> json = new HashMap<>();
json.put("env_version", envVersion); json.put("env_version", envVersion);
json.put("path", path); json.put("path", path);
json.put("width", 1000); json.put("width", 1000);
try (HttpResponse response = HttpUtil.createPost(url).body(json.toJSONString()).header("Content-Type", "application/json").execute()) { try (HttpResponse response = HttpUtil.createPost(url).body(JacksonUtil.toJSONString(json)).header("Content-Type", "application/json").execute()) {
if (response.getStatus() != 200) { if (response.getStatus() != 200) {
throw new Exception("获取小程序二维码失败,原因为:" + response.body()); throw new Exception("获取小程序二维码失败,原因为:" + response.body());
} }
@@ -86,12 +87,12 @@ public class WxMpUtil {
public static void generateUnlimitedWXAQRCode(String appId, String appSecret, String path, String scene, File targetFile) throws Exception { public static void generateUnlimitedWXAQRCode(String appId, String appSecret, String path, String scene, File targetFile) throws Exception {
String url = String.format(GET_WXA_CODE_UNLIMITED_URL, getAccessToken(appId, appSecret)); String url = String.format(GET_WXA_CODE_UNLIMITED_URL, getAccessToken(appId, appSecret));
JSONObject json = new JSONObject(); Map<String, Object> json = new HashMap<>();
json.put("page", path); json.put("page", path);
json.put("scene", scene); json.put("scene", scene);
json.put("check_path", false); json.put("check_path", false);
try (HttpResponse response = HttpUtil.createPost(url).body(json.toJSONString()).header("Content-Type", "application/json").execute()) { try (HttpResponse response = HttpUtil.createPost(url).body(JacksonUtil.toJSONString(json)).header("Content-Type", "application/json").execute()) {
if (response.getStatus() != 200) { if (response.getStatus() != 200) {
throw new Exception("获取小程序二维码失败,原因为:" + response.body()); throw new Exception("获取小程序二维码失败,原因为:" + response.body());
} }
@@ -108,34 +109,34 @@ public class WxMpUtil {
public static String generateUrlLink(String appId, String appSecret, String path, String query) throws Exception { public static String generateUrlLink(String appId, String appSecret, String path, String query) throws Exception {
String url = String.format(GET_URL_LICK_URL, getAccessToken(appId, appSecret)); String url = String.format(GET_URL_LICK_URL, getAccessToken(appId, appSecret));
JSONObject json = new JSONObject(); Map<String, Object> json = new HashMap<>();
json.put("path", path); json.put("path", path);
json.put("query", query); json.put("query", query);
try (HttpResponse response = HttpUtil.createPost(url).body(json.toJSONString()).header("Content-Type", "application/json").execute()) { try (HttpResponse response = HttpUtil.createPost(url).body(JacksonUtil.toJSONString(json)).header("Content-Type", "application/json").execute()) {
String responseStr = response.body(); String responseStr = response.body();
JSONObject jsonObject = JSONObject.parseObject(responseStr); Map<String, Object> jsonObject = JacksonUtil.parseObject(responseStr, Map.class);
if (jsonObject.getInteger("errcode") != 0) { if ((Integer) jsonObject.get("errcode") != 0) {
throw new Exception("获取url_link失败,原因为:" + jsonObject.getString("errmsg")); throw new Exception("获取url_link失败,原因为:" + (String) jsonObject.get("errmsg"));
} }
return jsonObject.getString("url_link"); return (String) jsonObject.get("url_link");
} }
} }
public static String getUserPhone(String appId, String appSecret, String code) throws Exception { public static String getUserPhone(String appId, String appSecret, String code) throws Exception {
String url = String.format(GET_USER_PHONE_URL, getAccessToken(appId, appSecret)); String url = String.format(GET_USER_PHONE_URL, getAccessToken(appId, appSecret));
JSONObject json = new JSONObject(); Map<String, Object> json = new HashMap<>();
json.put("code", code); json.put("code", code);
try (HttpResponse response = HttpUtil.createPost(url).body(json.toJSONString()).header("Content-Type", "application/json").execute()) { try (HttpResponse response = HttpUtil.createPost(url).body(JacksonUtil.toJSONString(json)).header("Content-Type", "application/json").execute()) {
String responseStr = response.body(); String responseStr = response.body();
JSONObject jsonObject = JSONObject.parseObject(responseStr); Map<String, Object> jsonObject = JacksonUtil.parseObject(responseStr, Map.class);
if (jsonObject.getInteger("errcode") != 0) { if ((Integer) jsonObject.get("errcode") != 0) {
throw new Exception("获取用户手机号失败,原因为:" + jsonObject.getString("errmsg")); throw new Exception("获取用户手机号失败,原因为:" + (String) jsonObject.get("errmsg"));
} }
return jsonObject.getJSONObject("phone_info").getString("phoneNumber"); return (String) ((Map<String, Object>) jsonObject.get("phone_info")).get("phoneNumber");
} }
} }