mirror of https://github.com/elunez/eladmin
parent
662345077e
commit
eba524e412
|
@ -17,17 +17,17 @@ public class RsaUtils {
|
||||||
|
|
||||||
private static final String SRC = "123456";
|
private static final String SRC = "123456";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
// public static void main(String[] args) throws Exception {
|
||||||
System.out.println("\n");
|
// System.out.println("\n");
|
||||||
RsaKeyPair keyPair = generateKeyPair();
|
// RsaKeyPair keyPair = generateKeyPair();
|
||||||
System.out.println("公钥:" + keyPair.getPublicKey());
|
// System.out.println("公钥:" + keyPair.getPublicKey());
|
||||||
System.out.println("私钥:" + keyPair.getPrivateKey());
|
// System.out.println("私钥:" + keyPair.getPrivateKey());
|
||||||
System.out.println("\n");
|
// System.out.println("\n");
|
||||||
test1(keyPair);
|
// test1(keyPair);
|
||||||
System.out.println("\n");
|
// System.out.println("\n");
|
||||||
test2(keyPair);
|
// test2(keyPair);
|
||||||
System.out.println("\n");
|
// System.out.println("\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公钥加密私钥解密
|
* 公钥加密私钥解密
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.AbstractChainWrapper;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public interface WhereFun {
|
||||||
|
WhereFun DEFAULT = new DefaultWhereFun();
|
||||||
|
|
||||||
|
<T> void whereFunc(Wrapper<T> wrapper, Field field, Object value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultWhereFun implements WhereFun {
|
||||||
|
@Override
|
||||||
|
public <T> void whereFunc(Wrapper<T> wrapper, Field field, Object value) {
|
||||||
|
if (wrapper instanceof AbstractWrapper) {
|
||||||
|
if (Objects.nonNull(value)) {
|
||||||
|
((AbstractWrapper) wrapper).eq(true, field.getName(), value);
|
||||||
|
}
|
||||||
|
} else if (wrapper instanceof AbstractChainWrapper) {
|
||||||
|
if (Objects.nonNull(value)) {
|
||||||
|
((AbstractChainWrapper) wrapper).eq(true, field.getName(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.AbstractChainWrapper;
|
||||||
|
import me.zhengjie.utils.enums.WhereTypeEnum;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class WrapperUtils {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WrapperUtils.class);
|
||||||
|
|
||||||
|
private static Map<WhereTypeEnum, WhereFun> typeFunc = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行
|
||||||
|
*
|
||||||
|
* @param obj obj
|
||||||
|
* @param wrapper
|
||||||
|
*/
|
||||||
|
public synchronized static <T> Wrapper<T> excute(Object obj, Wrapper<T> wrapper, WhereFun whereFun) {
|
||||||
|
//反射获取属性
|
||||||
|
Field[] fields = obj.getClass().getDeclaredFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
try {
|
||||||
|
final Object value = field.get(obj);
|
||||||
|
if (Objects.nonNull(whereFun)) {
|
||||||
|
whereFun.whereFunc(wrapper, field, value);
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package me.zhengjie.utils.enums;
|
||||||
|
|
||||||
|
public enum WhereTypeEnum {
|
||||||
|
EQ,NEQ,IN,LIKE,LT,GT,LE,GE;
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package me.zhengjie.repository;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import me.zhengjie.domain.ColumnInfo;
|
||||||
|
import me.zhengjie.repository.jpa.ColumnInfoRepository;
|
||||||
|
import me.zhengjie.repository.mp.ColumnInfoService;
|
||||||
|
import me.zhengjie.utils.WhereFun;
|
||||||
|
import me.zhengjie.utils.WrapperUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liaojinlong
|
||||||
|
* @since 2020/6/28 14:59
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ColumnInfoDao {
|
||||||
|
private Boolean dbType = false;
|
||||||
|
private ColumnInfoService columnInfoService;
|
||||||
|
private ColumnInfoRepository columnInfoRepository;
|
||||||
|
|
||||||
|
public ColumnInfoDao(ColumnInfoService columnInfoService, ColumnInfoRepository columnInfoRepository) {
|
||||||
|
this.columnInfoService = columnInfoService;
|
||||||
|
this.columnInfoRepository = columnInfoRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ColumnInfo> findByTableNameOrderByIdAsc(String tableName) {
|
||||||
|
if (false) {
|
||||||
|
return columnInfoRepository.findByTableNameOrderByIdAsc(tableName);
|
||||||
|
} else {
|
||||||
|
return columnInfoService
|
||||||
|
.selectList(Wrappers.<ColumnInfo>query().eq(true, "TABLE_NAME", tableName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ColumnInfo> saveAll(List<ColumnInfo> columnInfos) {
|
||||||
|
if (true) {
|
||||||
|
return columnInfoRepository.saveAll(columnInfos);
|
||||||
|
} else {
|
||||||
|
columnInfos.forEach(columnInfo -> {
|
||||||
|
columnInfoService.insert(columnInfo);
|
||||||
|
});
|
||||||
|
return columnInfos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(ColumnInfo columnInfo) {
|
||||||
|
if (dbType) {
|
||||||
|
columnInfoRepository.delete(columnInfo);
|
||||||
|
} else {
|
||||||
|
columnInfoService.delete(WrapperUtils.excute(columnInfo, Wrappers.query(), WhereFun.DEFAULT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(ColumnInfo columnInfo) {
|
||||||
|
if (dbType) {
|
||||||
|
columnInfoRepository.save(columnInfo);
|
||||||
|
} else {
|
||||||
|
columnInfoService.insert(columnInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(ColumnInfo columnInfo) {
|
||||||
|
if (dbType) {
|
||||||
|
columnInfoRepository.saveAndFlush(columnInfo);
|
||||||
|
} else {
|
||||||
|
columnInfoService.updateById(columnInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.repository;
|
package me.zhengjie.repository.jpa;
|
||||||
|
|
||||||
import me.zhengjie.domain.ColumnInfo;
|
import me.zhengjie.domain.ColumnInfo;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.repository;
|
package me.zhengjie.repository.jpa;
|
||||||
|
|
||||||
import me.zhengjie.domain.GenConfig;
|
import me.zhengjie.domain.GenConfig;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
@ -0,0 +1,11 @@
|
||||||
|
package me.zhengjie.repository.mp;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import me.zhengjie.domain.ColumnInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liaojinlong
|
||||||
|
* @since 2020/6/28 14:57
|
||||||
|
*/
|
||||||
|
public interface ColumnInfoService extends BaseMapper<ColumnInfo> {
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ package me.zhengjie.service.impl;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.zhengjie.domain.GenConfig;
|
import me.zhengjie.domain.GenConfig;
|
||||||
import me.zhengjie.repository.GenConfigRepository;
|
import me.zhengjie.repository.jpa.GenConfigRepository;
|
||||||
import me.zhengjie.service.GenConfigService;
|
import me.zhengjie.service.GenConfigService;
|
||||||
import me.zhengjie.utils.StringUtils;
|
import me.zhengjie.utils.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
|
@ -23,7 +23,7 @@ import me.zhengjie.domain.GenConfig;
|
||||||
import me.zhengjie.domain.ColumnInfo;
|
import me.zhengjie.domain.ColumnInfo;
|
||||||
import me.zhengjie.domain.vo.TableInfo;
|
import me.zhengjie.domain.vo.TableInfo;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.repository.ColumnInfoRepository;
|
import me.zhengjie.repository.ColumnInfoDao;
|
||||||
import me.zhengjie.service.GeneratorService;
|
import me.zhengjie.service.GeneratorService;
|
||||||
import me.zhengjie.utils.FileUtil;
|
import me.zhengjie.utils.FileUtil;
|
||||||
import me.zhengjie.utils.GenUtil;
|
import me.zhengjie.utils.GenUtil;
|
||||||
|
@ -58,7 +58,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
private final ColumnInfoRepository columnInfoRepository;
|
private final ColumnInfoDao columnInfoDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTables() {
|
public Object getTables() {
|
||||||
|
@ -93,12 +93,12 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ColumnInfo> getColumns(String tableName) {
|
public List<ColumnInfo> getColumns(String tableName) {
|
||||||
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableNameOrderByIdAsc(tableName);
|
List<ColumnInfo> columnInfos = columnInfoDao.findByTableNameOrderByIdAsc(tableName);
|
||||||
if (CollectionUtil.isNotEmpty(columnInfos)) {
|
if (CollectionUtil.isNotEmpty(columnInfos)) {
|
||||||
return columnInfos;
|
return columnInfos;
|
||||||
} else {
|
} else {
|
||||||
columnInfos = query(tableName);
|
columnInfos = query(tableName);
|
||||||
return columnInfoRepository.saveAll(columnInfos);
|
return columnInfoDao.saveAll(columnInfos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,10 +142,10 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
if (StringUtils.isBlank(column.getRemark())) {
|
if (StringUtils.isBlank(column.getRemark())) {
|
||||||
column.setRemark(columnInfo.getRemark());
|
column.setRemark(columnInfo.getRemark());
|
||||||
}
|
}
|
||||||
columnInfoRepository.save(column);
|
columnInfoDao.update(column);
|
||||||
} else {
|
} else {
|
||||||
// 如果找不到,则保存新字段信息
|
// 如果找不到,则保存新字段信息
|
||||||
columnInfoRepository.save(columnInfo);
|
columnInfoDao.save(columnInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 第二种情况,数据库字段删除了
|
// 第二种情况,数据库字段删除了
|
||||||
|
@ -154,14 +154,14 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
List<ColumnInfo> columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList());
|
List<ColumnInfo> columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList());
|
||||||
// 如果找不到,就代表字段被删除了,则需要删除该字段
|
// 如果找不到,就代表字段被删除了,则需要删除该字段
|
||||||
if (CollectionUtil.isEmpty(columns)) {
|
if (CollectionUtil.isEmpty(columns)) {
|
||||||
columnInfoRepository.delete(columnInfo);
|
columnInfoDao.delete(columnInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(List<ColumnInfo> columnInfos) {
|
public void save(List<ColumnInfo> columnInfos) {
|
||||||
columnInfoRepository.saveAll(columnInfos);
|
columnInfoDao.saveAll(columnInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package me.zhengjie.config;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@MapperScan("me.zhengjie.repository.mp")
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ spring:
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 59421
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
# 最小连接数
|
# 最小连接数
|
||||||
|
@ -106,4 +106,4 @@ file:
|
||||||
avatar: C:\eladmin\avatar\
|
avatar: C:\eladmin\avatar\
|
||||||
# 文件大小 /M
|
# 文件大小 /M
|
||||||
maxSize: 100
|
maxSize: 100
|
||||||
avatarMaxSize: 5
|
avatarMaxSize: 5
|
6
pom.xml
6
pom.xml
|
@ -206,6 +206,12 @@
|
||||||
<artifactId>UserAgentUtils</artifactId>
|
<artifactId>UserAgentUtils</artifactId>
|
||||||
<version>1.21</version>
|
<version>1.21</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- MyBatisPlus-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.3.3.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
Loading…
Reference in New Issue