commit
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
package com.budwk.app.base.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:DataCenterProperties
|
||||
* @Date 2025/9/15 15:34
|
||||
* @注释 数据中心配置文件,存放接口地址和参数配置
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@IocBean(create = "init")
|
||||
public class DataCenterProperties {
|
||||
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
private String appId;
|
||||
private String tokenUrl;
|
||||
private Map<String, String> codes = new HashMap<>();
|
||||
private Map<String, String> urls = new HashMap<>();
|
||||
|
||||
public void init() {
|
||||
Map<String, String> all = conf.toMap();
|
||||
appId = all.get("data-center.app-id");
|
||||
tokenUrl = all.get("data-center.token-url");
|
||||
extract(all, "data-center.codes.", codes);
|
||||
extract(all, "data-center.urls.", urls);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描配置 把 prefix 开头的 key 变成 Map
|
||||
* @param prefix 配置前缀
|
||||
* @param target 目标值
|
||||
*/
|
||||
private void extract(Map<String, String> all, String prefix, Map<String, String> target) {
|
||||
all.forEach((k, v) -> {
|
||||
if (k.startsWith(prefix)) {
|
||||
target.put(k.substring(prefix.length()), v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置
|
||||
* @param key 接口类型枚举
|
||||
* @return 相关配置
|
||||
*/
|
||||
public Credential credential(String key) {
|
||||
String code = codes.get(key);
|
||||
String url = urls.get(key);
|
||||
if (code == null || url == null) {
|
||||
throw new BaseException("未知业务: " + key);
|
||||
}
|
||||
String token = getToken(Integer.parseInt(code), key);
|
||||
return new Credential(url, token);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class Credential {
|
||||
private String url;
|
||||
private String token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* @param code
|
||||
* @param keyPrefix
|
||||
* @return token
|
||||
*/
|
||||
private String getToken(Integer code, String keyPrefix) {
|
||||
String dateCenterPrefix = RedisConstant.DATE_CENTER_PREFIX + keyPrefix;
|
||||
String token = redisService.get(dateCenterPrefix);
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
return token;
|
||||
} else {
|
||||
HttpRequest httpRequest = HttpUtil.createPost(tokenUrl);
|
||||
Map<String, Object> reqBody = Map.of(
|
||||
"appId", appId,
|
||||
"code", code
|
||||
);
|
||||
httpRequest.body(JSONUtil.toJsonStr(reqBody));
|
||||
JSONObject resp = JSONUtil.parseObj(httpRequest.execute().body());
|
||||
|
||||
if (resp.getInt("code") != 200) {
|
||||
throw new BaseException("获取token失败: " + resp.getStr("msg"));
|
||||
} else {
|
||||
JSONObject data = resp.getJSONObject("data");
|
||||
String tokenStr = data.getStr("token");
|
||||
Integer expire = data.getInt("expire");
|
||||
redisService.setex(dateCenterPrefix, expire, tokenStr);
|
||||
return tokenStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,4 +62,9 @@ public class RedisConstant {
|
||||
* 用户登录锁前缀
|
||||
*/
|
||||
public static final String USER_LOGIN_LOCK_PREFIX = PLATFORM_REDIS_PREFIX + "user:login:lock:";
|
||||
|
||||
/**
|
||||
* 数据接口锁前缀
|
||||
*/
|
||||
public static final String DATE_CENTER_PREFIX = PLATFORM_REDIS_PREFIX + "datacenter:token:";
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Sys_unit extends BaseModel implements Serializable {
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
// @PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@@ -110,4 +110,24 @@ public class Sys_unit extends BaseModel implements Serializable {
|
||||
@Comment("小组id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String unionGroupId;
|
||||
|
||||
@Column
|
||||
@Comment("处级_院系单位号")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String divisionCollegeCode;
|
||||
|
||||
@Column
|
||||
@Comment("机构类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String institutionType;
|
||||
|
||||
@Column
|
||||
@Comment("部门类别")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String unitType;
|
||||
|
||||
@Column
|
||||
@Comment("部门类别区分(部门类设置 1, 其他设置 0)")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer unitTypeCode;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:SysDataDictPullService
|
||||
* @Date 2025/9/22 11:35
|
||||
* @注释
|
||||
*/
|
||||
public interface SysDataDictPullService extends BaseService<Sys_dict> {
|
||||
|
||||
void pullDataDict();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:SysDataUnitPullService
|
||||
* @Date 2025/9/15 17:54
|
||||
* @注释
|
||||
*/
|
||||
public interface SysDataUnitPullService extends BaseService<Sys_unit> {
|
||||
|
||||
void updateUnits();
|
||||
|
||||
void updateUnits(List<String> unitIds);
|
||||
}
|
||||
@@ -31,4 +31,11 @@ public interface SysDataUserPullService extends BaseService<Sys_user_source> {
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> pullTimeOptions();
|
||||
|
||||
|
||||
/**
|
||||
* 获取财务数据
|
||||
* @return
|
||||
*/
|
||||
Map<String, NutMap> pullFinance();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.budwk.app.sys.utils;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:DataCenterUtil
|
||||
* @Date 2025/9/16 9:34
|
||||
* @注释
|
||||
*/
|
||||
public class DataCenterUtil {
|
||||
|
||||
/**
|
||||
* 映射字段
|
||||
* @param obj
|
||||
* @param clazz
|
||||
* @param api2db
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> T mapJsonToBean(JSONObject obj, Class<T> clazz, Map<String, String> api2db) {
|
||||
T bean = ReflectUtil.newInstance(clazz);
|
||||
api2db.forEach((apiField, dbColumn) -> {
|
||||
Object val = obj.getByPath(apiField);
|
||||
if (val == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Field field = ClassUtil.getDeclaredField(clazz, dbColumn);
|
||||
if (field != null) {
|
||||
Object castVal = Convert.convert(field.getType(), val);
|
||||
ReflectUtil.setFieldValue(bean, field, castVal);
|
||||
}
|
||||
});
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user