mirror of https://github.com/elunez/eladmin
parent
662345077e
commit
eba524e412
|
@ -17,17 +17,17 @@ public class RsaUtils {
|
|||
|
||||
private static final String SRC = "123456";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("\n");
|
||||
RsaKeyPair keyPair = generateKeyPair();
|
||||
System.out.println("公钥:" + keyPair.getPublicKey());
|
||||
System.out.println("私钥:" + keyPair.getPrivateKey());
|
||||
System.out.println("\n");
|
||||
test1(keyPair);
|
||||
System.out.println("\n");
|
||||
test2(keyPair);
|
||||
System.out.println("\n");
|
||||
}
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// System.out.println("\n");
|
||||
// RsaKeyPair keyPair = generateKeyPair();
|
||||
// System.out.println("公钥:" + keyPair.getPublicKey());
|
||||
// System.out.println("私钥:" + keyPair.getPrivateKey());
|
||||
// System.out.println("\n");
|
||||
// test1(keyPair);
|
||||
// System.out.println("\n");
|
||||
// test2(keyPair);
|
||||
// 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
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.repository;
|
||||
package me.zhengjie.repository.jpa;
|
||||
|
||||
import me.zhengjie.domain.ColumnInfo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.repository;
|
||||
package me.zhengjie.repository.jpa;
|
||||
|
||||
import me.zhengjie.domain.GenConfig;
|
||||
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 me.zhengjie.domain.GenConfig;
|
||||
import me.zhengjie.repository.GenConfigRepository;
|
||||
import me.zhengjie.repository.jpa.GenConfigRepository;
|
||||
import me.zhengjie.service.GenConfigService;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -23,7 +23,7 @@ import me.zhengjie.domain.GenConfig;
|
|||
import me.zhengjie.domain.ColumnInfo;
|
||||
import me.zhengjie.domain.vo.TableInfo;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.repository.ColumnInfoRepository;
|
||||
import me.zhengjie.repository.ColumnInfoDao;
|
||||
import me.zhengjie.service.GeneratorService;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.GenUtil;
|
||||
|
@ -58,7 +58,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
private final ColumnInfoRepository columnInfoRepository;
|
||||
private final ColumnInfoDao columnInfoDao;
|
||||
|
||||
@Override
|
||||
public Object getTables() {
|
||||
|
@ -93,12 +93,12 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||
|
||||
@Override
|
||||
public List<ColumnInfo> getColumns(String tableName) {
|
||||
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableNameOrderByIdAsc(tableName);
|
||||
List<ColumnInfo> columnInfos = columnInfoDao.findByTableNameOrderByIdAsc(tableName);
|
||||
if (CollectionUtil.isNotEmpty(columnInfos)) {
|
||||
return columnInfos;
|
||||
} else {
|
||||
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())) {
|
||||
column.setRemark(columnInfo.getRemark());
|
||||
}
|
||||
columnInfoRepository.save(column);
|
||||
columnInfoDao.update(column);
|
||||
} 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());
|
||||
// 如果找不到,就代表字段被删除了,则需要删除该字段
|
||||
if (CollectionUtil.isEmpty(columns)) {
|
||||
columnInfoRepository.delete(columnInfo);
|
||||
columnInfoDao.delete(columnInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(List<ColumnInfo> columnInfos) {
|
||||
columnInfoRepository.saveAll(columnInfos);
|
||||
columnInfoDao.saveAll(columnInfos);
|
||||
}
|
||||
|
||||
@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
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||
username: root
|
||||
password: 123456
|
||||
password: 59421
|
||||
# 初始连接数
|
||||
initial-size: 5
|
||||
# 最小连接数
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -206,6 +206,12 @@
|
|||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
<!-- MyBatisPlus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.3.3.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
Loading…
Reference in New Issue