This commit is contained in:
2025-07-27 08:59:08 +08:00
parent e9f44dd851
commit 563d83f849
35 changed files with 482 additions and 255 deletions

View File

@@ -20,7 +20,6 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<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>
<pagehelper.version>5.3.1</pagehelper.version>
<!--跳过单元测试-->
@@ -122,12 +121,6 @@
<artifactId>core</artifactId>
<version>3.3.3</version>
</dependency>
<!-- json处理工具 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- Jackson JSON处理库 -->
<dependency>

View File

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

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.controller.extern;
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.mapper.FaceMapper;
import com.ycwl.basic.mapper.MemberMapper;
@@ -184,7 +184,7 @@ public class LyCompatibleController {
}
String openId = headersMap.get("client");
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);
if (member == null) {
@@ -248,7 +248,7 @@ public class LyCompatibleController {
.put("face_id", faceVO.getId().toString())
.put("newvideo", videoList)
.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);
return response;
}

View File

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

View File

@@ -1,6 +1,6 @@
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.DeviceEntity;
import lombok.Setter;
@@ -13,7 +13,7 @@ public abstract class CommonDeviceChecker<C> {
protected DeviceConfigEntity deviceConfig;
public CommonDeviceChecker(String configJson) {
config = JSON.parseObject(configJson, getConfigClass());
config = JacksonUtil.parseObject(configJson, getConfigClass());
}
@SuppressWarnings("unchecked")

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.device.operator;
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.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter;
@@ -28,7 +28,7 @@ public class AliOssStorageOperator extends ADeviceStorageOperator {
@Override
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);
}

View File

@@ -1,7 +1,6 @@
package com.ycwl.basic.device.operator;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.vpt_passive.VptPassiveStorageConfig;
@@ -29,10 +28,8 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
public Long scenicId;
public Long deviceId;
public String deviceNo;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date startTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date endTime;
}
@@ -75,7 +72,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
@Override
public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, VptPassiveStorageConfig.class);
this.config = JacksonUtil.parseObject(configJson, VptPassiveStorageConfig.class);
}
@Override
@@ -94,7 +91,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
if (redisTemplate == null) {
taskList.add(task);
} 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());
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.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.wvp_active.WvpActiveStorageConfig;
import com.ycwl.basic.storage.exceptions.StorageConfigException;
@@ -30,7 +30,7 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
@Override
public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, WvpActiveStorageConfig.class);
this.config = JacksonUtil.parseObject(configJson, WvpActiveStorageConfig.class);
}
@Override
@@ -55,13 +55,14 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
String password = MD5.create().digestHex(this.config.getLoginPassword());
params.put("password", password);
String jsonResult = HttpUtil.get(url, params);
JSONObject result = JSON.parseObject(jsonResult);
if (result.getInteger("code") == 0) {
JSONObject data = result.getJSONObject("data");
this.token = data.getString("accessToken");
Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
Integer code = (Integer) result.get("code");
if (code != null && code == 0) {
Map<String, Object> data = (Map<String, Object>) result.get("data");
this.token = (String) data.get("accessToken");
return this.token;
} else {
throw new StorageConfigException("获取token失败,原因为:" + result.getString("msg"));
throw new StorageConfigException("获取token失败,原因为:" + result.get("msg"));
}
}
public List<FileObject> listDirByDtRange(Date startDate, Date endDate) {
@@ -75,19 +76,23 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
params.put("page", 1);
params.put("count", 100);
String jsonResult = HttpRequest.get(url).form(params).header("Access-Token", getToken()).execute().body();
JSONObject result = JSON.parseObject(jsonResult);
if (result.getInteger("code") == 0) {
JSONObject data = result.getJSONObject("data");
List<JSONObject> recordList = data.getJSONArray("list").toJavaList(JSONObject.class);
Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
Integer code = (Integer) result.get("code");
if (code != null && code == 0) {
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()
.map(record -> {
FileObject object = new FileObject();
object.setName(record.getString("id"));
object.setPath(record.getString("folder"));
object.setUrl(getUrlForDownload(record.getInteger("id")));
object.setName((String) record.get("id"));
object.setPath((String) record.get("folder"));
Integer recordId = (Integer) record.get("id");
object.setUrl(getUrlForDownload(recordId != null ? recordId : 0));
object.setNeedDownload(true);
object.setCreateTime(new Date(record.getLongValue("startTime")));
object.setEndTime(new Date(record.getLongValue("endTime")));
Number startTime = (Number) record.get("startTime");
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;
})
.sorted(Comparator.comparing(FileObject::getCreateTime))
@@ -100,10 +105,11 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
// assume path is recordId
String url = this.config.getHost() + "/api/cloud/record/play/path?recordId=" + id;
String jsonResult = HttpRequest.get(url).header("Access-Token", getToken()).execute().body();
JSONObject result = JSON.parseObject(jsonResult);
if (result.getInteger("code") == 0) {
JSONObject data = result.getJSONObject("data");
String httpPath = data.getString("httpPath");
Map<String, Object> result = JacksonUtil.parseObject(jsonResult, Map.class);
Integer code = (Integer) result.get("code");
if (code != null && code == 0) {
Map<String, Object> data = (Map<String, Object>) result.get("data");
String httpPath = (String) data.get("httpPath");
if (StringUtils.isBlank(this.config.getZlmHost())) {
return httpPath;
}
@@ -114,7 +120,7 @@ public class WvpActiveStorageOperator extends ADeviceStorageOperator {
}
return this.config.getZlmHost() + uri.getPath() + "?" + uri.getQuery();
} 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;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.entity.wvp_passive.WvpPassiveStorageConfig;
@@ -28,10 +27,8 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
public Long scenicId;
public Long deviceId;
public String deviceNo;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date startTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date endTime;
}
@@ -72,7 +69,7 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
@Override
public void loadConfig(String configJson) {
this.config = JSON.parseObject(configJson, WvpPassiveStorageConfig.class);
this.config = JacksonUtil.parseObject(configJson, WvpPassiveStorageConfig.class);
}
@Override
@@ -91,7 +88,7 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
if (redisTemplate == null) {
taskList.add(task);
} 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();
while (true) {

View File

@@ -1,6 +1,7 @@
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.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
@@ -73,10 +74,10 @@ public class DeviceConfigEntity {
return Collections.singletonList(new DeviceCropConfig());
}
if (StringUtils.startsWith(cropConfig, "{")) {
return Collections.singletonList(JSON.parseObject(cropConfig, DeviceCropConfig.class));
return Collections.singletonList(JacksonUtil.parseObject(cropConfig, DeviceCropConfig.class));
}
if (StringUtils.startsWith(cropConfig, "[")) {
return JSON.parseArray(cropConfig, DeviceCropConfig.class);
return JacksonUtil.parseObject(cropConfig, new TypeReference<List<DeviceCropConfig>>() {});
}
return Collections.singletonList(new DeviceCropConfig());
}

View File

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

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.notify.adapters;
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.WxMpSrvConfig;
@@ -45,15 +45,16 @@ public class WxMpSrvNotifyAdapter implements INotifyAdapter{
}
String url = String.format(ACCESS_TOKEN_URL, config.getAppId(), config.getAppSecret());
String response = HttpUtil.get(url);
JSONObject jsonObject = JSONObject.parseObject(response);
ACCESS_TOKEN = jsonObject.getString("access_token");
expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000);
Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
ACCESS_TOKEN = (String) jsonObject.get("access_token");
Integer expiresIn = (Integer) jsonObject.get("expires_in");
expireTime = new Date(System.currentTimeMillis() + (expiresIn != null ? expiresIn : 7200) * 1000);
return ACCESS_TOKEN;
}
public void sendServiceNotification(Map<String, Object> params) {
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);
}
}

View File

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

View File

@@ -1,6 +1,6 @@
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 lombok.Data;
@@ -29,10 +29,10 @@ public class ProfitSharingUser {
private BigDecimal realRate;
public void setWxPayConfig(String wxPayConfig) {
this.wxPayConfig = JSON.parseObject(wxPayConfig, Map.class);
this.wxPayConfig = JacksonUtil.parseObject(wxPayConfig, Map.class);
}
public String getWxPayConfig() {
return JSON.toJSONString(wxPayConfig);
return JacksonUtil.toJSONString(wxPayConfig);
}
}

View File

@@ -1,6 +1,6 @@
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.mapper.ProfitSharingConfigMapper;
import com.ycwl.basic.profitsharing.mapper.ProfitSharingUserMapper;
@@ -20,12 +20,12 @@ public class ProfitSharingRepository {
public ProfitSharingConfig getScenicConfig(Long 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);
if (scenicConfig != null) {
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;
}

View File

@@ -1,6 +1,6 @@
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.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
@@ -27,26 +27,26 @@ public class DeviceRepository {
public DeviceEntity getDevice(Long 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);
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;
}
public DeviceEntity getDeviceByDeviceNo(String 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);
if (null == device) {
device = deviceMapper.getByDeviceNo2(deviceNo);
}
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, device.getId()), 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()), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
} else {
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) {
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);
if (null == deviceConfig) {
@@ -64,7 +64,7 @@ public class DeviceRepository {
deviceConfig.setDeviceId(deviceId);
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;
}
@@ -111,22 +111,22 @@ public class DeviceRepository {
device.setOnline(online);
device.setKeepaliveAt(keepaliveAt);
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);
updateDeviceCache(device);
}
public DeviceEntity getOnlineStatus(Long 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 {
return null;
}
}
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.getNo()), 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()), JacksonUtil.toJSONString(device));
}
public List<DeviceEntity> getAllDeviceByScenicId(Long scenicId) {

View File

@@ -1,6 +1,6 @@
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.FaceSampleMapper;
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
@@ -30,11 +30,11 @@ public class FaceRepository {
public FaceEntity getFace(Long 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);
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;
}

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.mapper.OrderMapper;
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
@@ -27,25 +27,25 @@ public class OrderRepository {
public OrderEntity getOrder(Long 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);
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;
}
public List<OrderItemEntity> getOrderItems(Long 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());
}
List<OrderItemEntity> orderItemEntities = orderMapper.listOrderItemByOrderId(orderId);
if (orderItemEntities != null) {
redisTemplate.opsForValue().set(
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;
@@ -53,11 +53,11 @@ public class OrderRepository {
public OrderItemEntity getOrderItemByOrderItemId(Long 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);
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;
}

View File

@@ -1,6 +1,6 @@
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.model.pc.price.entity.PriceConfigEntity;
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);
PriceConfigEntity priceConfigEntity = null;
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) {
priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId);
if (priceConfigEntity != null) {
redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), 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()), JacksonUtil.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
}
}
return priceConfigEntity;
@@ -39,7 +39,7 @@ public class PriceRepository {
String cacheKey = String.format(PRICE_ID_CACHE, id);
PriceConfigEntity priceConfigEntity = null;
if (redisTemplate.hasKey(cacheKey)) {
priceConfigEntity = JSON.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
priceConfigEntity = JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
}
return priceConfigEntity;
}

View File

@@ -1,6 +1,6 @@
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.model.pc.renderWorker.entity.RenderWorkerEntity;
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
@@ -25,12 +25,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey);
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);
if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.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(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
}
return renderWorker;
}
@@ -38,12 +38,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorker(Long id) {
String key = String.format(RENDER_WORKER_CACHE_KEY, id);
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);
if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.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(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
}
return renderWorker;
}
@@ -69,14 +69,14 @@ public class RenderWorkerRepository {
if (!redisTemplate.hasKey(key)) {
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) {
String key = String.format(RENDER_WORKER_STATUS_CACHE_KEY, id);
if (redisTemplate.hasKey(key)) {
String status = redisTemplate.opsForValue().get(key);
return JSONObject.parseObject(status, ClientStatusReqVo.class);
return JacksonUtil.parseObject(status, ClientStatusReqVo.class);
}
return null;
}

View File

@@ -1,6 +1,6 @@
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.MpNotifyConfigMapper;
import com.ycwl.basic.mapper.ScenicMapper;
@@ -34,41 +34,41 @@ public class ScenicRepository {
public ScenicEntity getScenic(Long 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);
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;
}
public ScenicConfigEntity getScenicConfig(Long 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);
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;
}
public MpConfigEntity getScenicMpConfig(Long 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);
MpConfigEntity mpConfigEntity = mpConfigMapper.selectById(scenic.getMpId());
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;
}
public ScenicMpNotifyVO getScenicMpNotifyConfig(Long 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);
if (mpConfig == null) {
@@ -93,7 +93,7 @@ public class ScenicRepository {
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;
}

View File

@@ -1,6 +1,7 @@
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.FaceSampleMapper;
import com.ycwl.basic.mapper.TemplateMapper;
@@ -56,10 +57,10 @@ public class TemplateRepository {
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
List<Long> idList;
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 {
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()) {
return Collections.emptyList();
@@ -78,7 +79,7 @@ public class TemplateRepository {
public TemplateRespVO getTemplate(Long 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);
if (template == null) {
@@ -86,7 +87,7 @@ public class TemplateRepository {
}
if (null == template.getPid() || template.getPid() == 0) {
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;
} else {
clearTemplateCache(templateId);
@@ -99,7 +100,7 @@ public class TemplateRepository {
return new TemplateConfigEntity();
}
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);
if (templateConfig == null) {
@@ -108,7 +109,7 @@ public class TemplateRepository {
templateConfig.setTemplateId(templateId);
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;
}

View File

@@ -1,6 +1,6 @@
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.model.pc.video.entity.MemberVideoEntity;
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
@@ -25,24 +25,24 @@ public class VideoRepository {
public VideoEntity getVideo(Long 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);
if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.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_CACHE_KEY, videoId), JacksonUtil.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;
}
public VideoEntity getVideoByTaskId(Long 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);
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_CACHE_KEY, video.getId()), 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()), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
}
return video;
}

View File

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

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.service.mobile.impl;
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.NumberConstant;
import com.ycwl.basic.enums.BizCodeEnum;
@@ -61,7 +61,7 @@ public class AppMemberServiceImpl implements AppMemberService {
if (StringUtils.isBlank(response)) {
return null;
}
return JSONObject.parseObject(response);
return JacksonUtil.parseObject(response, Map.class);
} catch (Exception e) {
log.error("getOpenId", e);
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.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.enums.StatisticEnum;
import com.ycwl.basic.mapper.StatisticsMapper;
import com.ycwl.basic.model.jwt.JwtInfo;
@@ -188,8 +187,8 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
// 缓存
if (redisTemplate.hasKey(redisKey)) {
String s = redisTemplate.opsForValue().get(redisKey);
JSONObject cacheObj = JSON.parseObject(s);
return ApiResponse.success(cacheObj.toJavaObject(AppStatisticsFunnelVO.class));
Map<String, Object> cacheObj = JacksonUtil.parseObject(s, Map.class);
return ApiResponse.success(JacksonUtil.toJavaObject(cacheObj, AppStatisticsFunnelVO.class));
}
}
}
@@ -202,8 +201,8 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
// 缓存
if (redisTemplate.hasKey(redisKey)) {
String s = redisTemplate.opsForValue().get(redisKey);
JSONObject cacheObj = JSON.parseObject(s);
return ApiResponse.success(cacheObj.toJavaObject(AppStatisticsFunnelVO.class));
Map<String, Object> cacheObj = JacksonUtil.parseObject(s, Map.class);
return ApiResponse.success(JacksonUtil.toJavaObject(cacheObj, AppStatisticsFunnelVO.class));
}
}
}
@@ -266,7 +265,7 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
vo.setRefundOfOrderNum(refundOfOrderNum);
vo.setRefundOfOrderAmount(refundOfOrderAmount.setScale(2, RoundingMode.HALF_UP));
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);
} finally {
lock.unlock();

View File

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

View File

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

View File

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

View File

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

View File

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

@@ -1,6 +1,6 @@
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.facebody.FaceBodyFactory;
import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter;
@@ -116,7 +116,7 @@ public class DynamicTaskGenerator {
IFaceBodyAdapter faceBodyAdapter;
if (scenicConfig.getFaceType() != null) {
faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
faceBodyAdapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
faceBodyAdapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
} else {
faceBodyAdapter = FaceBodyFactory.use();
}

View File

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

View File

@@ -274,4 +274,238 @@ public class JacksonUtil {
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.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import java.util.HashMap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
@@ -37,22 +38,22 @@ public class WxMpUtil {
String token;
if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
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("appid", appId);
params.put("secret", appSecret);
params.put("force_refresh", false);
String response = HttpUtil.post(url, params.toJSONString());
JSONObject jsonObject = JSONObject.parseObject(response);
token = jsonObject.getString("access_token");
Date expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000 / 2);
String response = HttpUtil.post(url, JacksonUtil.toJSONString(params));
Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
token = (String) jsonObject.get("access_token");
Date expireTime = new Date(System.currentTimeMillis() + ((Integer) jsonObject.get("expires_in")) * 1000 / 2);
expireTimes.put(appId, expireTime);
} else {
String url = String.format(ACCESS_TOKEN_URL, appId, appSecret);
String response = HttpUtil.get(url);
JSONObject jsonObject = JSONObject.parseObject(response);
token = jsonObject.getString("access_token");
Date expireTime = new Date(System.currentTimeMillis() + jsonObject.getInteger("expires_in") * 1000 / 2);
Map<String, Object> jsonObject = JacksonUtil.parseObject(response, Map.class);
token = (String) jsonObject.get("access_token");
Date expireTime = new Date(System.currentTimeMillis() + ((Integer) jsonObject.get("expires_in")) * 1000 / 2);
expireTimes.put(appId, expireTime);
}
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 {
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("path", path);
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) {
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 {
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("scene", scene);
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) {
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 {
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("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();
JSONObject jsonObject = JSONObject.parseObject(responseStr);
if (jsonObject.getInteger("errcode") != 0) {
throw new Exception("获取url_link失败,原因为:" + jsonObject.getString("errmsg"));
Map<String, Object> jsonObject = JacksonUtil.parseObject(responseStr, Map.class);
if ((Integer) jsonObject.get("errcode") != 0) {
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 {
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);
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();
JSONObject jsonObject = JSONObject.parseObject(responseStr);
if (jsonObject.getInteger("errcode") != 0) {
throw new Exception("获取用户手机号失败,原因为:" + jsonObject.getString("errmsg"));
Map<String, Object> jsonObject = JacksonUtil.parseObject(responseStr, Map.class);
if ((Integer) jsonObject.get("errcode") != 0) {
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");
}
}