Commit d56575fe by yuwei

2.0.0项目初始化

parent bb5b9c28
...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory; ...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -58,18 +57,6 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB ...@@ -58,18 +57,6 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
} }
/** /**
* 发布事件
*
* @param event
*/
public static void publishEvent(ApplicationEvent event) {
if (applicationContext == null) {
return;
}
applicationContext.publishEvent(event);
}
/**
* 实现DisposableBean接口, 在Context关闭时清理静态变量. * 实现DisposableBean接口, 在Context关闭时清理静态变量.
*/ */
@Override @Override
......
...@@ -13,7 +13,7 @@ public class DbQueryProperty implements Serializable { ...@@ -13,7 +13,7 @@ public class DbQueryProperty implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String dbType; private Integer dbType;
private String host; private String host;
private String username; private String username;
private String password; private String password;
...@@ -24,12 +24,12 @@ public class DbQueryProperty implements Serializable { ...@@ -24,12 +24,12 @@ public class DbQueryProperty implements Serializable {
* 参数合法性校验 * 参数合法性校验
*/ */
public void viald() { public void viald() {
if (StringUtils.isEmpty(dbType) || StringUtils.isEmpty(host) || if (null == dbType || StringUtils.isEmpty(host) ||
StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password) ||
StringUtils.isEmpty(port) || StringUtils.isEmpty(dbName)) { StringUtils.isEmpty(port) || StringUtils.isEmpty(dbName)) {
throw new DataQueryException("参数不完整"); throw new DataQueryException("参数不完整");
} }
if (DbType.OTHER.getDb().equals(dbType)) { if (DbType.OTHER.getDb() == dbType) {
throw new DataQueryException("不支持的数据库类型"); throw new DataQueryException("不支持的数据库类型");
} }
} }
......
...@@ -11,40 +11,40 @@ public enum DbType { ...@@ -11,40 +11,40 @@ public enum DbType {
/** /**
* MYSQL * MYSQL
*/ */
MYSQL("mysql", "MySql数据库", "jdbc:mysql://${host}:${port}/${dbName}?serverTimezone=GMT%2B8&characterEncoding=UTF-8&useUnicode=true&useSSL=false"), MYSQL(1, "MySql数据库", "jdbc:mysql://${host}:${port}/${dbName}?serverTimezone=GMT%2B8&characterEncoding=UTF-8&useUnicode=true&useSSL=false"),
/** /**
* MARIADB * MARIADB
*/ */
MARIADB("mariadb", "MariaDB数据库", "jdbc:mariadb://${host}:${port}/${dbName}"), MARIADB(2, "MariaDB数据库", "jdbc:mariadb://${host}:${port}/${dbName}"),
/** /**
* ORACLE * ORACLE
*/ */
ORACLE("oracle", "Oracle11g及以下数据库", "jdbc:oracle:thin:@${host}:${port}:${dbName}"), ORACLE(3, "Oracle11g及以下数据库", "jdbc:oracle:thin:@${host}:${port}:${dbName}"),
/** /**
* oracle12c new pagination * oracle12c new pagination
*/ */
ORACLE_12C("oracle12c", "Oracle12c+数据库", "jdbc:oracle:thin:@${host}:${port}:${dbName}"), ORACLE_12C(4, "Oracle12c+数据库", "jdbc:oracle:thin:@${host}:${port}:${dbName}"),
/** /**
* POSTGRE * POSTGRESQL
*/ */
POSTGRE_SQL("postgresql", "Postgre数据库", "jdbc:postgresql://${host}:${port}/${dbName}"), POSTGRE_SQL(5, "PostgreSql数据库", "jdbc:postgresql://${host}:${port}/${dbName}"),
/** /**
* SQLSERVER2005 * SQLSERVER2005
*/ */
SQL_SERVER2008("sqlserver2008", "SQLServer2008及以下数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"), SQL_SERVER2008(6, "SQLServer2008及以下数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"),
/** /**
* SQLSERVER * SQLSERVER
*/ */
SQL_SERVER("sqlserver", "SQLServer2012+数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"), SQL_SERVER(7, "SQLServer2012+数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}"),
/** /**
* UNKONWN DB * UNKONWN DB
*/ */
OTHER("other", "其他数据库", ""); OTHER(8, "其他数据库", "");
/** /**
* 数据库名称 * 数据库名称
*/ */
private final String db; private final Integer db;
/** /**
* 描述 * 描述
...@@ -56,7 +56,7 @@ public enum DbType { ...@@ -56,7 +56,7 @@ public enum DbType {
*/ */
private final String url; private final String url;
public String getDb() { public Integer getDb() {
return this.db; return this.db;
} }
...@@ -68,7 +68,7 @@ public enum DbType { ...@@ -68,7 +68,7 @@ public enum DbType {
return this.url; return this.url;
} }
DbType(String db, String desc, String url) { DbType(Integer db, String desc, String url) {
this.db = db; this.db = db;
this.desc = desc; this.desc = desc;
this.url = url; this.url = url;
...@@ -79,9 +79,9 @@ public enum DbType { ...@@ -79,9 +79,9 @@ public enum DbType {
* *
* @param dbType 数据库类型字符串 * @param dbType 数据库类型字符串
*/ */
public static DbType getDbType(String dbType) { public static DbType getDbType(Integer dbType) {
for (DbType type : DbType.values()) { for (DbType type : DbType.values()) {
if (type.db.equalsIgnoreCase(dbType)) { if (type.db == dbType) {
return type; return type;
} }
} }
......
...@@ -45,12 +45,14 @@ public class DictAnalysis implements ResponseBodyAdvice { ...@@ -45,12 +45,14 @@ public class DictAnalysis implements ResponseBodyAdvice {
if (null != dictAop) { if (null != dictAop) {
String code = dictAop.code(); String code = dictAop.code();
String text = field.getName(); String text = field.getName();
System.out.println("code:" + code); Object object = item.get(field.getName());
System.out.println("field:" + text); if (null != object) {
System.out.println("value:" + item.get(field.getName())); // 字典翻译
// 字典翻译 Object dictValue = DictUtil.getInstance().getDictItemValue(code, object.toString());
String dictValue = DictUtil.getInstance().getDictItemValue(code, text); if (null != dictValue) {
item.put(field.getName() + "_dictText", dictValue); item.put(field.getName() + "_dictText", dictValue);
}
}
} }
} }
items.add(item); items.add(item);
......
package cn.datax.common.dictionary.utils; package cn.datax.common.dictionary.utils;
import cn.datax.common.redis.service.RedisService; import cn.datax.common.redis.service.RedisService;
import cn.datax.common.utils.SpringContextHolder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j @Slf4j
public class DictUtil { public class DictUtil {
...@@ -22,24 +28,22 @@ public class DictUtil { ...@@ -22,24 +28,22 @@ public class DictUtil {
return instance; return instance;
} }
@Autowired private RedisService redisService = SpringContextHolder.getBean(RedisService.class);
private RedisService redisService;
static {
initDictionary();
}
// 初始化字典数据
private static void initDictionary() {
log.info("DictUtil初始化中...");
}
/** /**
* 获取字典项 * 获取字典项
* @param code * @param code
*/ */
public void getDictItemList(String code) { public Object getDictItemList(String code) {
String key = "data:system:dicts";
Object object = redisService.get(key);
if (null == object) {
return null;
}
JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(object));
List<Object> list = jsonArray.stream().filter(obj -> ((JSONObject) obj).get("dictCode").equals(code))
.flatMap(obj -> ((JSONObject) obj).getJSONArray("items").stream()).collect(Collectors.toList());
return list;
} }
/** /**
...@@ -48,7 +52,17 @@ public class DictUtil { ...@@ -48,7 +52,17 @@ public class DictUtil {
* @param text * @param text
* @return * @return
*/ */
public String getDictItemValue(String code, String text) { public Object getDictItemValue(String code, String text) {
return "test"; String key = "data:system:dicts";
Object object = redisService.get(key);
if (null == object) {
return null;
}
JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(object));
Object o = jsonArray.stream().filter(obj -> ((JSONObject) obj).get("dictCode").equals(code))
.flatMap(obj -> ((JSONObject) obj).getJSONArray("items").stream())
.filter(obj -> ((JSONObject) obj).get("itemText").equals(text))
.map(obj -> ((JSONObject) obj).get("itemValue")).findFirst().orElse(null);
return o;
} }
} }
...@@ -403,7 +403,7 @@ public class RedisService { ...@@ -403,7 +403,7 @@ public class RedisService {
* @param end 结束 0 到 -1代表所有值 * @param end 结束 0 到 -1代表所有值
* @return List * @return List
*/ */
public List<Object> lGet(String key, Long start, Long end) { public List<Object> lGet(String key, int start, int end) {
try { try {
return redisTemplate.opsForList().range(key, start, end); return redisTemplate.opsForList().range(key, start, end);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -27,7 +27,7 @@ public class DataSourceDto implements Serializable { ...@@ -27,7 +27,7 @@ public class DataSourceDto implements Serializable {
private String id; private String id;
@ApiModelProperty(value = "数据源类型") @ApiModelProperty(value = "数据源类型")
@NotBlank(message = "数据源类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotBlank(message = "数据源类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
private String dbType; private Integer dbType;
@ApiModelProperty(value = "数据源名称") @ApiModelProperty(value = "数据源名称")
@NotBlank(message = "数据源名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class}) @NotBlank(message = "数据源名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
private String sourceName; private String sourceName;
......
...@@ -28,7 +28,7 @@ public class DataSourceEntity extends DataScopeBaseEntity { ...@@ -28,7 +28,7 @@ public class DataSourceEntity extends DataScopeBaseEntity {
/** /**
* 数据源类型 * 数据源类型
*/ */
private String dbType; private Integer dbType;
/** /**
* 数据源名称 * 数据源名称
......
...@@ -24,7 +24,7 @@ public class DataSourceVo implements Serializable { ...@@ -24,7 +24,7 @@ public class DataSourceVo implements Serializable {
private Integer status; private Integer status;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime; private LocalDateTime createTime;
private String dbType; private Integer dbType;
private String sourceName; private String sourceName;
private String remark; private String remark;
private DbSchema dbSchema; private DbSchema dbSchema;
......
...@@ -20,6 +20,7 @@ public class RoleVo implements Serializable { ...@@ -20,6 +20,7 @@ public class RoleVo implements Serializable {
private LocalDateTime createTime; private LocalDateTime createTime;
private String roleName; private String roleName;
private String roleCode; private String roleCode;
@DictAop(code = "dataScope")
private Integer dataScope; private Integer dataScope;
private List<MenuVo> menus; private List<MenuVo> menus;
private List<DeptVo> depts; private List<DeptVo> depts;
......
...@@ -2,6 +2,7 @@ package cn.datax.service.system.controller; ...@@ -2,6 +2,7 @@ package cn.datax.service.system.controller;
import cn.datax.common.core.JsonPage; import cn.datax.common.core.JsonPage;
import cn.datax.common.core.R; import cn.datax.common.core.R;
import cn.datax.common.dictionary.utils.DictUtil;
import cn.datax.common.validate.ValidationGroups; import cn.datax.common.validate.ValidationGroups;
import cn.datax.service.system.api.dto.DictDto; import cn.datax.service.system.api.dto.DictDto;
import cn.datax.service.system.api.entity.DictEntity; import cn.datax.service.system.api.entity.DictEntity;
...@@ -120,6 +121,17 @@ public class DictController extends BaseController { ...@@ -120,6 +121,17 @@ public class DictController extends BaseController {
} }
/** /**
* 获取字典项
*
* @return
*/
@GetMapping("/code/{code}")
public R getDictItems(@PathVariable String code) {
Object list = DictUtil.getInstance().getDictItemList(code);
return R.ok().setData(list);
}
/**
* 刷新字典 * 刷新字典
* *
* @return * @return
......
package cn.datax.service.system.service.impl; package cn.datax.service.system.service.impl;
import cn.datax.common.core.DataConstant; import cn.datax.common.core.DataConstant;
import cn.datax.common.exception.DataException;
import cn.datax.common.redis.service.RedisService; import cn.datax.common.redis.service.RedisService;
import cn.datax.service.system.api.entity.DictEntity; import cn.datax.service.system.api.entity.DictEntity;
import cn.datax.service.system.api.dto.DictDto; import cn.datax.service.system.api.dto.DictDto;
...@@ -8,6 +9,7 @@ import cn.datax.service.system.service.DictService; ...@@ -8,6 +9,7 @@ import cn.datax.service.system.service.DictService;
import cn.datax.service.system.mapstruct.DictMapper; import cn.datax.service.system.mapstruct.DictMapper;
import cn.datax.service.system.dao.DictDao; import cn.datax.service.system.dao.DictDao;
import cn.datax.common.base.BaseServiceImpl; import cn.datax.common.base.BaseServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
...@@ -40,6 +42,10 @@ public class DictServiceImpl extends BaseServiceImpl<DictDao, DictEntity> implem ...@@ -40,6 +42,10 @@ public class DictServiceImpl extends BaseServiceImpl<DictDao, DictEntity> implem
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDict(DictDto dictDto) { public void saveDict(DictDto dictDto) {
DictEntity dict = dictMapper.toEntity(dictDto); DictEntity dict = dictMapper.toEntity(dictDto);
int n = dictDao.selectCount(Wrappers.<DictEntity>lambdaQuery().eq(DictEntity::getDictCode, dict.getDictCode()));
if(n > 0){
throw new DataException("该字典编码已存在");
}
dictDao.insert(dict); dictDao.insert(dict);
} }
...@@ -64,6 +70,6 @@ public class DictServiceImpl extends BaseServiceImpl<DictDao, DictEntity> implem ...@@ -64,6 +70,6 @@ public class DictServiceImpl extends BaseServiceImpl<DictDao, DictEntity> implem
if (hasKey) { if (hasKey) {
redisService.del(key); redisService.del(key);
} }
redisService.lSet(key, dictEntityList); redisService.set(key, dictEntityList);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment