优化缓存查询异常抛出
This commit is contained in:
@@ -9,6 +9,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode ERP_NOT_EXISTS = new ErrorCode(1_000_000_001, "获取ERP数据为空");
|
ErrorCode ERP_NOT_EXISTS = new ErrorCode(1_000_000_001, "获取ERP数据为空");
|
||||||
ErrorCode ERP_NOT_JSON_EXISTS = new ErrorCode(1_000_000_002, "ERP接口响应无法解析为JSON");
|
ErrorCode ERP_NOT_JSON_EXISTS = new ErrorCode(1_000_000_002, "ERP接口响应无法解析为JSON");
|
||||||
ErrorCode ERP_ERROR_EXISTS = new ErrorCode(1_000_000_003, "调用ERP RFC接口失败");
|
ErrorCode ERP_ERROR_EXISTS = new ErrorCode(1_000_000_003, "调用ERP RFC接口失败");
|
||||||
|
ErrorCode ERP_REDIS_EXISTS = new ErrorCode(1_000_000_004, "公司调用缓存失败");
|
||||||
|
|
||||||
ErrorCode ERP_CUSTOMER_NOT_EXISTS = new ErrorCode(1_001_000_001, "ERP客商主数据不存在");
|
ErrorCode ERP_CUSTOMER_NOT_EXISTS = new ErrorCode(1_001_000_001, "ERP客商主数据不存在");
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,12 @@ public class ErpCompanyController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/test")
|
||||||
|
@Operation(summary = "定时获得erp更新公司")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-company:create')")
|
||||||
|
public CommonResult<Boolean> test() {
|
||||||
|
erpCompanyService.test();
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -70,4 +70,6 @@ public interface ErpCompanyService {
|
|||||||
* @return ERP公司
|
* @return ERP公司
|
||||||
*/
|
*/
|
||||||
ErpCompanyDO getErpCompanyByNumber(String number);
|
ErpCompanyDO getErpCompanyByNumber(String number);
|
||||||
|
|
||||||
|
void test();
|
||||||
}
|
}
|
||||||
@@ -131,8 +131,9 @@ public class ErpCompanyServiceImpl implements ErpCompanyService {
|
|||||||
saveData(result);
|
saveData(result);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用ERP RFC接口失败: {}", e);
|
// log.error("调用ERP RFC接口失败: {}", e);
|
||||||
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
throw e;
|
||||||
|
// throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,4 +236,18 @@ public class ErpCompanyServiceImpl implements ErpCompanyService {
|
|||||||
myRedisConfig.addRedisCacheMap(key, existingNumbers);
|
myRedisConfig.addRedisCacheMap(key, existingNumbers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void test() {
|
||||||
|
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.公司代码;
|
||||||
|
String funcnr = funcnrEnum.getFuncnr();
|
||||||
|
//防止缓存数据丢失
|
||||||
|
String key = "erpMap" + funcnrEnum.getFuncnr();
|
||||||
|
myRedisConfig.getRedisCacheMap(key);
|
||||||
|
// 1. 调用ERP接口获取数据
|
||||||
|
HashMap<String, Object> dataFromERP = erpConfig.fetchDataFromERP(funcnr, null);
|
||||||
|
JSONArray dataArray = (JSONArray) dataFromERP.get("E_RESP");
|
||||||
|
if (CollUtil.isEmpty(dataArray)) {
|
||||||
|
throw exception(ERP_COMPANY_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.*;
|
||||||
import static dm.jdbc.util.DriverUtil.log;
|
import static dm.jdbc.util.DriverUtil.log;
|
||||||
|
|
||||||
|
|
||||||
@@ -72,8 +74,6 @@ public class MyRedisConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//list
|
//list
|
||||||
public Map<String, List<String>> numbers(JSONArray dataArray, String key, String dataKey) {
|
public Map<String, List<String>> numbers(JSONArray dataArray, String key, String dataKey) {
|
||||||
// 使用 Redis 获取缓存数据
|
// 使用 Redis 获取缓存数据
|
||||||
@@ -152,9 +152,13 @@ public class MyRedisConfig {
|
|||||||
|
|
||||||
//map
|
//map
|
||||||
public Map<String, Long> getRedisCacheMap(String key) {
|
public Map<String, Long> getRedisCacheMap(String key) {
|
||||||
// 使用 Redis 获取缓存数据
|
try {
|
||||||
Map<String, Long> result = (Map<String, Long>) redisTemplate.opsForHash().entries(key);
|
// 使用 Redis 获取缓存数据
|
||||||
return result;
|
Map<String, Long> result = (Map<String, Long>) redisTemplate.opsForHash().entries(key);
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw exception(ERP_REDIS_EXISTS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRedisCacheMap(String key, Map<String, Long> allnumbers) {
|
public void addRedisCacheMap(String key, Map<String, Long> allnumbers) {
|
||||||
@@ -179,13 +183,4 @@ public class MyRedisConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user