diff --git a/src/main/java/com/glxp/udidl/admin/config/CustomerSqlInjector.java b/src/main/java/com/glxp/udidl/admin/config/CustomerSqlInjector.java new file mode 100644 index 0000000..d53ec87 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/CustomerSqlInjector.java @@ -0,0 +1,27 @@ +package com.glxp.udidl.admin.config; + +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; +import com.baomidou.mybatisplus.core.metadata.TableInfo; + +import java.util.List; + +/** + * 自定义sql注入器,增加通用方法 + */ +public class CustomerSqlInjector extends DefaultSqlInjector { + + @Override + public List getMethodList(Class mapperClass, TableInfo tableInfo) { + List methodList = super.getMethodList(mapperClass, tableInfo); + // 插入数据,如果中已经存在相同的记录,则忽略当前新数据 + methodList.add(new com.glxp.udidl.admin.config.InsertIgnore()); + // 批量插入数据,如果中已经存在相同的记录,则忽略当前新数据 + methodList.add(new com.glxp.udidl.admin.config.InsertIgnoreBatch()); + // 替换数据,如果中已经存在相同的记录,则覆盖旧数据 + methodList.add(new com.glxp.udidl.admin.config.Replace()); + // 批量替换数据,如果中已经存在相同的记录,则覆盖旧数据 + methodList.add(new com.glxp.udidl.admin.config.ReplaceBatch()); + return methodList; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/CustomerSqlMethod.java b/src/main/java/com/glxp/udidl/admin/config/CustomerSqlMethod.java new file mode 100644 index 0000000..622c559 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/CustomerSqlMethod.java @@ -0,0 +1,28 @@ +package com.glxp.udidl.admin.config; + +import lombok.Getter; + +/** + * MybatisPlus自定义SQL方法枚举 + */ +@Getter +public enum CustomerSqlMethod { + /** + * 插入 + */ + INSERT_IGNORE_ONE("insertIgnore", "插入一条数据(选择字段插入),如果中已经存在相同的记录,则忽略当前新数据", ""), + /** + * 替换 + */ + REPLACE_ONE("replace", "替换一条数据(选择字段插入),存在则替换,不存在则插入", ""); + + private final String method; + private final String desc; + private final String sql; + + CustomerSqlMethod(String method, String desc, String sql) { + this.method = method; + this.desc = desc; + this.sql = sql; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/HdSchemaExecutor.java b/src/main/java/com/glxp/udidl/admin/config/HdSchemaExecutor.java new file mode 100644 index 0000000..1659b80 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/HdSchemaExecutor.java @@ -0,0 +1,81 @@ +package com.glxp.udidl.admin.config; + +import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.lang.UUID; +import com.glxp.udidl.admin.dao.sys.DbVersionDao; +import com.glxp.udidl.admin.entity.sys.DbVersionEntity; +import com.glxp.udidl.admin.entity.sys.SchemaData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Order(1) +@Component +@Slf4j +public class HdSchemaExecutor implements ApplicationRunner { + + @Resource + DbVersionDao hdCommonDao; + + private List schema = new ArrayList<>(); + + @Override + public void run(ApplicationArguments args) throws Exception { + //初始版本列表 + buildSchemas(); + //定义sql文件路径 + String basePath = "schemas/"; + //非版本控制,初始化脚本 + ClassLoader loader = this.getClass().getClassLoader(); + //通过流的方式获取项目路径下的文件 + InputStream inputStream = loader.getResourceAsStream(basePath + "init.sql"); + //获取文件内容 + String sql = IoUtil.readUtf8(inputStream); + try { + //判断版本表是否存在 + int count = hdCommonDao.selectTableExist("hd_version"); + if (count == 0) { + hdCommonDao.updateSql(sql); + } + for (SchemaData schemaData : schema) { + //查询版本记录是否存在 + count = hdCommonDao.selectVersion(schemaData.getVersion()); + if (count == 0) { + log.info("--------------执行数据脚本,版本:" + schemaData.getVersion()); + //获取对应sql脚本 + inputStream = loader.getResourceAsStream(basePath + schemaData.getFileName()); + sql = IoUtil.readUtf8(inputStream); + hdCommonDao.updateSql(sql); + DbVersionEntity entity = new DbVersionEntity(); + entity.setId(UUID.randomUUID().toString()); + entity.setVersion(schemaData.getVersion()); + entity.setCreated(new Date()); + entity.setRemark(schemaData.getFileName()); + //写入版本记录 + hdCommonDao.insertVersion(entity); + } + } + + } catch (IORuntimeException e) { + e.printStackTrace(); + } finally { + //关闭流 + inputStream.close(); + } + } + + public void buildSchemas() { + schema.add(new SchemaData("v2.1", "schema_v2.1.sql")); +// schema.add(new SchemaData("v2.2", "schema_v2.2.sql")); +// schema.add(new SchemaData("v2.3", "schema_v2.3.sql")); + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/InsertIgnore.java b/src/main/java/com/glxp/udidl/admin/config/InsertIgnore.java new file mode 100644 index 0000000..3396ea3 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/InsertIgnore.java @@ -0,0 +1,49 @@ +package com.glxp.udidl.admin.config; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; +import org.apache.ibatis.executor.keygen.KeyGenerator; +import org.apache.ibatis.executor.keygen.NoKeyGenerator; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlSource; + +/** + * 插入一条数据(选择字段插入) + * INSERT IGNORE 表示,如果中已经存在相同的记录,则忽略当前新数据; + */ +public class InsertIgnore extends AbstractMethod { + @Override + public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { + KeyGenerator keyGenerator = new NoKeyGenerator(); + com.glxp.udidl.admin.config.CustomerSqlMethod sqlMethod = com.glxp.udidl.admin.config.CustomerSqlMethod.INSERT_IGNORE_ONE; + String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf(null), + LEFT_BRACKET, RIGHT_BRACKET, null, COMMA); + String valuesScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlPropertyMaybeIf(null), + LEFT_BRACKET, RIGHT_BRACKET, null, COMMA); + String keyProperty = null; + String keyColumn = null; + // 表包含主键处理逻辑,如果不包含主键当普通字段处理 + if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { + if (tableInfo.getIdType() == IdType.AUTO) { + /* 自增主键 */ + keyGenerator = new Jdbc3KeyGenerator(); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } else { + if (null != tableInfo.getKeySequence()) { + keyGenerator = TableInfoHelper.genKeyGenerator(sqlMethod.getMethod(), tableInfo, builderAssistant); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } + } + } + String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript); + SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); + return this.addInsertMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource, keyGenerator, keyProperty, keyColumn); + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/InsertIgnoreBatch.java b/src/main/java/com/glxp/udidl/admin/config/InsertIgnoreBatch.java new file mode 100644 index 0000000..bd7b2fd --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/InsertIgnoreBatch.java @@ -0,0 +1,76 @@ +package com.glxp.udidl.admin.config; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.enums.SqlMethod; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; +import org.apache.ibatis.executor.keygen.KeyGenerator; +import org.apache.ibatis.executor.keygen.NoKeyGenerator; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlSource; + +import java.util.List; +import java.util.function.Predicate; + +/** + * 批量新增数据,自选字段 insert ignore + */ +public class InsertIgnoreBatch extends AbstractMethod { + /** + * mapper 对应的方法名 + */ + private static final String MAPPER_METHOD = "insertIgnoreBatch"; + + /** + * 字段筛选条件 + */ + @Setter + @Accessors(chain = true) + private Predicate predicate; + + @Override + public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { + KeyGenerator keyGenerator = new NoKeyGenerator(); + com.glxp.udidl.admin.config.CustomerSqlMethod sqlMethod = com.glxp.udidl.admin.config.CustomerSqlMethod.INSERT_IGNORE_ONE; + List fieldList = tableInfo.getFieldList(); + String insertSqlColumn = tableInfo.getKeyInsertSqlColumn(false, true) + + this.filterTableFieldInfo(fieldList, predicate, TableFieldInfo::getInsertSqlColumn, EMPTY); + String columnScript = LEFT_BRACKET + insertSqlColumn.substring(0, insertSqlColumn.length() - 1) + RIGHT_BRACKET; + String insertSqlProperty = tableInfo.getKeyInsertSqlProperty(false, ENTITY_DOT, true) + + this.filterTableFieldInfo(fieldList, predicate, i -> i.getInsertSqlProperty(ENTITY_DOT), EMPTY); + insertSqlProperty = LEFT_BRACKET + insertSqlProperty.substring(0, insertSqlProperty.length() - 1) + RIGHT_BRACKET; + String valuesScript = SqlScriptUtils.convertForeach(insertSqlProperty, "list", null, ENTITY, COMMA); + String keyProperty = null; + String keyColumn = null; + // 表包含主键处理逻辑,如果不包含主键当普通字段处理 + if (tableInfo.havePK()) { + if (tableInfo.getIdType() == IdType.AUTO) { + /* 自增主键 */ + keyGenerator = new Jdbc3KeyGenerator(); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } else { + if (null != tableInfo.getKeySequence()) { + keyGenerator = TableInfoHelper.genKeyGenerator(MAPPER_METHOD, tableInfo, builderAssistant); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } + } + } + String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript); + SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); + return this.addInsertMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource, keyGenerator, keyProperty, keyColumn); + } + + @Override + public String getMethod(SqlMethod sqlMethod) { + // 自定义 mapper 方法名 + return MAPPER_METHOD; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/Replace.java b/src/main/java/com/glxp/udidl/admin/config/Replace.java new file mode 100644 index 0000000..8877e21 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/Replace.java @@ -0,0 +1,40 @@ +package com.glxp.udidl.admin.config; + +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import org.apache.ibatis.executor.keygen.KeyGenerator; +import org.apache.ibatis.executor.keygen.NoKeyGenerator; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlSource; + +/** + * 替换数据实现类 + * 替换数据,如果中已经存在相同的记录,则覆盖旧数据 + */ +public class Replace extends AbstractMethod { + @Override + public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { + KeyGenerator keyGenerator = new NoKeyGenerator(); + com.glxp.udidl.admin.config.CustomerSqlMethod sqlMethod = com.glxp.udidl.admin.config.CustomerSqlMethod.REPLACE_ONE; + String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf(null), + LEFT_BRACKET, RIGHT_BRACKET, null, COMMA); + String valuesScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlPropertyMaybeIf(null), + LEFT_BRACKET, RIGHT_BRACKET, null, COMMA); + String keyProperty = null; + String keyColumn = null; + // 表包含主键处理逻辑,如果不包含主键当普通字段处理 + if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { + if (null != tableInfo.getKeySequence()) { + keyGenerator = TableInfoHelper.genKeyGenerator(sqlMethod.getMethod(), tableInfo, builderAssistant); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } + } + String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript); + SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); + return this.addInsertMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource, keyGenerator, keyProperty, keyColumn); + } +} diff --git a/src/main/java/com/glxp/udidl/admin/config/ReplaceBatch.java b/src/main/java/com/glxp/udidl/admin/config/ReplaceBatch.java new file mode 100644 index 0000000..5ebf9eb --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/config/ReplaceBatch.java @@ -0,0 +1,72 @@ +package com.glxp.udidl.admin.config; + +import com.baomidou.mybatisplus.core.enums.SqlMethod; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.apache.ibatis.executor.keygen.KeyGenerator; +import org.apache.ibatis.executor.keygen.NoKeyGenerator; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlSource; + +import java.util.List; +import java.util.function.Predicate; + +/** + * 替换数据实现类 + * 替换数据,如果中已经存在相同的记录,则覆盖旧数据 + */ +public class ReplaceBatch extends AbstractMethod { + /** + * mapper 对应的方法名 + */ + private static final String MAPPER_METHOD = "replaceBatch"; + + /** + * 字段筛选条件 + */ + @Setter + @Accessors(chain = true) + private Predicate predicate; + + @Override + public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { + KeyGenerator keyGenerator = new NoKeyGenerator(); + com.glxp.udidl.admin.config.CustomerSqlMethod sqlMethod = com.glxp.udidl.admin.config.CustomerSqlMethod.REPLACE_ONE; + List fieldList = tableInfo.getFieldList(); + +// String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf(null), +// LEFT_BRACKET, RIGHT_BRACKET, null, COMMA); + String insertSqlColumn = tableInfo.getKeyInsertSqlColumn(true, true) + + this.filterTableFieldInfo(fieldList, predicate, TableFieldInfo::getInsertSqlColumn, EMPTY); + String columnScript = LEFT_BRACKET + insertSqlColumn.substring(0, insertSqlColumn.length() - 1) + RIGHT_BRACKET; + String insertSqlProperty = tableInfo.getKeyInsertSqlProperty(true, ENTITY_DOT, true) + + this.filterTableFieldInfo(fieldList, predicate, i -> i.getInsertSqlProperty(ENTITY_DOT), EMPTY); + insertSqlProperty = LEFT_BRACKET + insertSqlProperty.substring(0, insertSqlProperty.length() - 1) + RIGHT_BRACKET; + String valuesScript = SqlScriptUtils.convertForeach(insertSqlProperty, "list", null, ENTITY, COMMA); + String keyProperty = null; + String keyColumn = null; + // 表包含主键处理逻辑,如果不包含主键当普通字段处理 + if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { + if (null != tableInfo.getKeySequence()) { + keyGenerator = TableInfoHelper.genKeyGenerator(sqlMethod.getMethod(), tableInfo, builderAssistant); + keyProperty = tableInfo.getKeyProperty(); + keyColumn = tableInfo.getKeyColumn(); + } + } + String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript); + SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); + return this.addInsertMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource, keyGenerator, keyProperty, keyColumn); + } + + @Override + public String getMethod(SqlMethod sqlMethod) { + // 自定义 mapper 方法名 + return MAPPER_METHOD; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/dao/BaseMapperPlus.java b/src/main/java/com/glxp/udidl/admin/dao/BaseMapperPlus.java new file mode 100644 index 0000000..9233b15 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/dao/BaseMapperPlus.java @@ -0,0 +1,325 @@ +package com.glxp.udidl.admin.dao; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.enums.SqlMethod; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.*; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.glxp.udidl.admin.util.BeanCopyUtils; +import org.apache.ibatis.binding.MapperMethod; +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.logging.LogFactory; + +import java.io.Serializable; +import java.util.*; + +/** + * 自定义 Mapper 接口, 实现 自定义扩展 + * + * @param mapper 泛型 + * @param table 泛型 + * @param vo 泛型 + * @author Lion Li + * @since 2021-05-13 + */ +@SuppressWarnings("unchecked") +public interface BaseMapperPlus extends BaseMapper { + + Log log = LogFactory.getLog(BaseMapperPlus.class); + + int DEFAULT_BATCH_SIZE = 1000; + + default Class currentVoClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 2); + } + + default Class currentModelClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 1); + } + + default Class currentMapperClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 0); + } + + default List selectList() { + return this.selectList(new QueryWrapper<>()); + } + + /** + * 批量插入 + */ + default boolean insertBatch(Collection entityList) { + return insertBatch(entityList, DEFAULT_BATCH_SIZE); + } + + /** + * 批量更新 + */ + default boolean updateBatchById(Collection entityList) { + return updateBatchById(entityList, DEFAULT_BATCH_SIZE); + } + + /** + * 批量插入或更新 + */ + default boolean insertOrUpdateBatch(Collection entityList) { + return insertOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE); + } + + /** + * 批量插入(包含限制条数) + */ + default boolean insertBatch(Collection entityList, int batchSize) { + String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.INSERT_ONE); + return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize, + (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); + } + + /** + * 批量更新(包含限制条数) + */ + default boolean updateBatchById(Collection entityList, int batchSize) { + String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID); + return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize, + (sqlSession, entity) -> { + MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); + param.put(Constants.ENTITY, entity); + sqlSession.update(sqlStatement, param); + }); + } + + /** + * 批量插入或更新(包含限制条数) + */ + default boolean insertOrUpdateBatch(Collection entityList, int batchSize) { + TableInfo tableInfo = TableInfoHelper.getTableInfo(this.currentModelClass()); + Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); + String keyProperty = tableInfo.getKeyProperty(); + Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); + return SqlHelper.saveOrUpdateBatch(this.currentModelClass(), this.currentMapperClass(), log, entityList, batchSize, (sqlSession, entity) -> { + Object idVal = tableInfo.getPropertyValue(entity, keyProperty); + String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.SELECT_BY_ID); + return StringUtils.checkValNull(idVal) + || CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity)); + }, (sqlSession, entity) -> { + MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); + param.put(Constants.ENTITY, entity); + String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID); + sqlSession.update(sqlStatement, param); + }); + } + + /** + * 插入或更新(包含限制条数) + */ + default boolean insertOrUpdate(T entity) { + if (null != entity) { + TableInfo tableInfo = TableInfoHelper.getTableInfo(this.currentModelClass()); + Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); + String keyProperty = tableInfo.getKeyProperty(); + Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); + Object idVal = tableInfo.getPropertyValue(entity, tableInfo.getKeyProperty()); + return StringUtils.checkValNull(idVal) || Objects.isNull(selectById((Serializable) idVal)) ? insert(entity) > 0 : updateById(entity) > 0; + } + return false; + } + + default V selectVoById(Serializable id) { + return selectVoById(id, this.currentVoClass()); + } + + /** + * 根据 ID 查询 + */ + default C selectVoById(Serializable id, Class voClass) { + T obj = this.selectById(id); + if (ObjectUtil.isNull(obj)) { + return null; + } + return BeanCopyUtils.copy(obj, voClass); + } + + default List selectVoBatchIds(Collection idList) { + return selectVoBatchIds(idList, this.currentVoClass()); + } + + /** + * 查询(根据ID 批量查询) + */ + default List selectVoBatchIds(Collection idList, Class voClass) { + List list = this.selectBatchIds(idList); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return BeanCopyUtils.copyList(list, voClass); + } + + default List selectVoByMap(Map map) { + return selectVoByMap(map, this.currentVoClass()); + } + + /** + * 查询(根据 columnMap 条件) + */ + default List selectVoByMap(Map map, Class voClass) { + List list = this.selectByMap(map); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return BeanCopyUtils.copyList(list, voClass); + } + + default V selectVoOne(Wrapper wrapper) { + return selectVoOne(wrapper, this.currentVoClass()); + } + + /** + * 根据 entity 条件,查询一条记录 + */ + default C selectVoOne(Wrapper wrapper, Class voClass) { + T obj = this.selectOne(wrapper); + if (ObjectUtil.isNull(obj)) { + return null; + } + return BeanCopyUtils.copy(obj, voClass); + } + + default List selectVoList(Wrapper wrapper) { + return selectVoList(wrapper, this.currentVoClass()); + } + + /** + * 根据 entity 条件,查询全部记录 + */ + default List selectVoList(Wrapper wrapper, Class voClass) { + List list = this.selectList(wrapper); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return BeanCopyUtils.copyList(list, voClass); + } + + default

> P selectVoPage(IPage page, Wrapper wrapper) { + return selectVoPage(page, wrapper, this.currentVoClass()); + } + + /** + * 分页查询VO + */ + default > P selectVoPage(IPage page, Wrapper wrapper, Class voClass) { + IPage pageData = this.selectPage(page, wrapper); + IPage voPage = new Page<>(pageData.getCurrent(), pageData.getSize(), pageData.getTotal()); + if (CollUtil.isEmpty(pageData.getRecords())) { + return (P) voPage; + } + voPage.setRecords(BeanCopyUtils.copyList(pageData.getRecords(), voClass)); + return (P) voPage; + } + + /** + * 插入数据,如果中已经存在相同的记录,则忽略当前新数据 + * {@link com.glxp.udidl.admin.config.InsertIgnore} + * + * @param entity 实体类 + * @return 影响条数 + */ + int insertIgnore(T entity); + + /** + * 批量插入数据,如果中已经存在相同的记录,则忽略当前新数据 + * {@link com.glxp.udidl.admin.config.InsertIgnoreBatch} + * + * @param entityList 实体类列表 + * @return 影响条数 + */ + default boolean insertIgnoreBatchs(List entityList) { + return insertIgnoreBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean insertIgnoreBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator var7 = entityList.iterator(); var7.hasNext(); ++i) { + T element = var7.next(); + oneBatchList.add(element); + if (i == idxLimit) { + + this.insertIgnoreBatch(oneBatchList); + //每次提交后需要清空集合数据 + oneBatchList.clear(); + idxLimit = Math.min(idxLimit + batchSize, size); + } + } + } catch (Exception e) { + log.error("insertIgnoreBatch fail", e); + return false; + } + return true; + } + + int insertIgnoreBatch(List entityList); + + + /** + * 替换数据 + * replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样; + * {@link com.glxp.udidl.admin.config.Replace} + * + * @param entity 实体类 + * @return 影响条数 + */ + int replace(T entity); + + /** + * 批量替换数据 + * replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样; + * {@link com.glxp.udidl.admin.config.ReplaceBatch} + * + * @param entityList 实体类列表 + * @return 影响条数 + */ + default boolean replaceBatchs(List entityList) { + return this.replaceBatchs(entityList, DEFAULT_BATCH_SIZE); + } + + default boolean replaceBatchs(List entityList, int batchSize) { + + try { + int size = entityList.size(); + int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size); + int i = 1; + //保存单批提交的数据集合 + List oneBatchList = new ArrayList<>(); + for (Iterator var7 = entityList.iterator(); var7.hasNext(); ++i) { + T element = var7.next(); + oneBatchList.add(element); + if (i == idxLimit) { + + this.replaceBatch(oneBatchList); + //每次提交后需要清空集合数据 + oneBatchList.clear(); + idxLimit = Math.min(idxLimit + batchSize, size); + } + } + } catch (Exception e) { + log.error("insertIgnoreBatch fail", e); + return false; + } + return true; + } + + int replaceBatch(List entityList); + +} diff --git a/src/main/java/com/glxp/udidl/admin/dao/sys/DbVersionDao.java b/src/main/java/com/glxp/udidl/admin/dao/sys/DbVersionDao.java new file mode 100644 index 0000000..1a6df97 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/dao/sys/DbVersionDao.java @@ -0,0 +1,24 @@ +package com.glxp.udidl.admin.dao.sys; + +import com.glxp.udidl.admin.entity.sys.DbVersionEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; + +@Mapper +public interface DbVersionDao { + + int selectVersion(@Param("version") String version); + + //查询版本表是否存在 + int selectTableExist(@Param("tableName") String tableName); + + //新增版本 + int insertVersion(DbVersionEntity entity); + + //执行sql + @Update("${sql}") + void updateSql(@Param("sql") String sql); + + +} diff --git a/src/main/java/com/glxp/udidl/admin/dao/tyapi/TySupplierMapper.java b/src/main/java/com/glxp/udidl/admin/dao/tyapi/TySupplierMapper.java index 8c4a9ad..1927a25 100644 --- a/src/main/java/com/glxp/udidl/admin/dao/tyapi/TySupplierMapper.java +++ b/src/main/java/com/glxp/udidl/admin/dao/tyapi/TySupplierMapper.java @@ -1,9 +1,10 @@ package com.glxp.udidl.admin.dao.tyapi; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.glxp.udidl.admin.dao.BaseMapperPlus; import com.glxp.udidl.admin.entity.tyapi.TySupplierEntity; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface TySupplierMapper extends BaseMapper { +public interface TySupplierMapper extends BaseMapperPlus { } diff --git a/src/main/java/com/glxp/udidl/admin/entity/sys/DbVersionEntity.java b/src/main/java/com/glxp/udidl/admin/entity/sys/DbVersionEntity.java new file mode 100644 index 0000000..fb8901b --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/entity/sys/DbVersionEntity.java @@ -0,0 +1,15 @@ +package com.glxp.udidl.admin.entity.sys; + +import lombok.Data; + +import java.util.Date; + +@Data +public class DbVersionEntity { + + private String id; + private String version; + private String remark; + private Date created; + +} diff --git a/src/main/java/com/glxp/udidl/admin/entity/sys/SchemaData.java b/src/main/java/com/glxp/udidl/admin/entity/sys/SchemaData.java new file mode 100644 index 0000000..158342d --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/entity/sys/SchemaData.java @@ -0,0 +1,22 @@ +package com.glxp.udidl.admin.entity.sys; + +import lombok.Data; + + +@Data +public class SchemaData { + /** + * 版本号 + */ + public String version; + + /** + * 文件名 + */ + public String fileName; + + public SchemaData(String version, String fileName) { + this.version = version; + this.fileName = fileName; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/entity/tyapi/TySupplierEntity.java b/src/main/java/com/glxp/udidl/admin/entity/tyapi/TySupplierEntity.java index d96cffd..7734fdd 100644 --- a/src/main/java/com/glxp/udidl/admin/entity/tyapi/TySupplierEntity.java +++ b/src/main/java/com/glxp/udidl/admin/entity/tyapi/TySupplierEntity.java @@ -6,96 +6,104 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +import java.util.Date; + import lombok.Data; /** - * 供应商企业列表 - */ -@ApiModel(value="com-glxp-udidl-admin-entity-tyapi-TySupplier") + * 供应商企业列表 + */ +@ApiModel(value = "com-glxp-udidl-admin-entity-tyapi-TySupplier") @Data @TableName(value = "ty_supplier") public class TySupplierEntity implements Serializable { @TableId(value = "id", type = IdType.INPUT) - @ApiModelProperty(value="") + @ApiModelProperty(value = "") private Integer id; /** * 供应商id */ @TableField(value = "supplier_graphId") - @ApiModelProperty(value="供应商id") + @ApiModelProperty(value = "供应商id") private String supplier_graphId; /** * 报告期 */ @TableField(value = "announcement_date") - @ApiModelProperty(value="报告期") + @ApiModelProperty(value = "报告期") private String announcement_date; /** * 采购金额(万元) */ @TableField(value = "amt") - @ApiModelProperty(value="采购金额(万元)") + @ApiModelProperty(value = "采购金额(万元)") private String amt; /** * logo */ @TableField(value = "logo") - @ApiModelProperty(value="logo") + @ApiModelProperty(value = "logo") private String logo; /** * 简称 */ @TableField(value = "`alias`") - @ApiModelProperty(value="简称") + @ApiModelProperty(value = "简称") private String alias; /** * 供应商名称 */ @TableField(value = "supplier_name") - @ApiModelProperty(value="供应商名称") + @ApiModelProperty(value = "供应商名称") private String supplier_name; /** * 关联关系 */ @TableField(value = "relationship") - @ApiModelProperty(value="关联关系") + @ApiModelProperty(value = "关联关系") private String relationship; /** * 数据来源 */ @TableField(value = "dataSource") - @ApiModelProperty(value="数据来源") + @ApiModelProperty(value = "数据来源") private String dataSource; /** * 采购占比 */ @TableField(value = "ratio") - @ApiModelProperty(value="采购占比") + @ApiModelProperty(value = "采购占比") private String ratio; /** * 所属医院统一社会信用号外键 */ @TableField(value = "creditCodeFk") - @ApiModelProperty(value="所属医院统一社会信用号外键") + @ApiModelProperty(value = "所属医院统一社会信用号外键") private String creditCodeFk; /** * 所属医院名称 */ @TableField(value = "hospName") - @ApiModelProperty(value="所属医院名称") + @ApiModelProperty(value = "所属医院名称") private String hospName; + + @TableField(value = "updateTime") + @ApiModelProperty(value = "更新时间") + private Date updateTime; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/glxp/udidl/admin/res/tyapi/CompanyBaseResponse.java b/src/main/java/com/glxp/udidl/admin/res/tyapi/CompanyBaseResponse.java new file mode 100644 index 0000000..fbd3777 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/tyapi/CompanyBaseResponse.java @@ -0,0 +1,131 @@ +package com.glxp.udidl.admin.res.tyapi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class CompanyBaseResponse { + + @JsonProperty("result") + private ResultDTO result; + @JsonProperty("reason") + private String reason; + @JsonProperty("error_code") + private Integer errorCode; + + @NoArgsConstructor + @Data + public static class ResultDTO { + @JsonProperty("historyNames") + private String historyNames; + @JsonProperty("cancelDate") + private Object cancelDate; + @JsonProperty("regStatus") + private String regStatus; + @JsonProperty("regCapital") + private String regCapital; + @JsonProperty("city") + private String city; + @JsonProperty("staffNumRange") + private String staffNumRange; + @JsonProperty("bondNum") + private String bondNum; + @JsonProperty("historyNameList") + private List historyNameList; + @JsonProperty("industry") + private String industry; + @JsonProperty("bondName") + private String bondName; + @JsonProperty("revokeDate") + private Object revokeDate; + @JsonProperty("type") + private Integer type; + @JsonProperty("updateTimes") + private Long updateTimes; + @JsonProperty("legalPersonName") + private String legalPersonName; + @JsonProperty("revokeReason") + private String revokeReason; + @JsonProperty("regNumber") + private String regNumber; + @JsonProperty("creditCode") + private String creditCode; + @JsonProperty("property3") + private String property3; + @JsonProperty("usedBondName") + private String usedBondName; + @JsonProperty("approvedTime") + private Long approvedTime; + @JsonProperty("fromTime") + private Long fromTime; + @JsonProperty("socialStaffNum") + private Integer socialStaffNum; + @JsonProperty("actualCapitalCurrency") + private String actualCapitalCurrency; + @JsonProperty("alias") + private String alias; + @JsonProperty("companyOrgType") + private String companyOrgType; + @JsonProperty("id") + private Integer id; + @JsonProperty("cancelReason") + private String cancelReason; + @JsonProperty("orgNumber") + private String orgNumber; + @JsonProperty("email") + private String email; + @JsonProperty("toTime") + private Object toTime; + @JsonProperty("actualCapital") + private String actualCapital; + @JsonProperty("estiblishTime") + private Long estiblishTime; + @JsonProperty("regInstitute") + private String regInstitute; + @JsonProperty("businessScope") + private String businessScope; + @JsonProperty("taxNumber") + private String taxNumber; + @JsonProperty("regLocation") + private String regLocation; + @JsonProperty("regCapitalCurrency") + private String regCapitalCurrency; + @JsonProperty("tags") + private String tags; + @JsonProperty("websiteList") + private String websiteList; + @JsonProperty("phoneNumber") + private String phoneNumber; + @JsonProperty("district") + private String district; + @JsonProperty("bondType") + private String bondType; + @JsonProperty("name") + private String name; + @JsonProperty("percentileScore") + private Integer percentileScore; + @JsonProperty("industryAll") + private IndustryAllDTO industryAll; + @JsonProperty("isMicroEnt") + private Integer isMicroEnt; + @JsonProperty("base") + private String base; + + @NoArgsConstructor + @Data + public static class IndustryAllDTO { + @JsonProperty("categoryMiddle") + private String categoryMiddle; + @JsonProperty("categoryBig") + private String categoryBig; + @JsonProperty("category") + private String category; + @JsonProperty("categorySmall") + private String categorySmall; + } + } +} diff --git a/src/main/java/com/glxp/udidl/admin/res/tyapi/ContactResponse.java b/src/main/java/com/glxp/udidl/admin/res/tyapi/ContactResponse.java new file mode 100644 index 0000000..310f3a7 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/tyapi/ContactResponse.java @@ -0,0 +1,47 @@ +package com.glxp.udidl.admin.res.tyapi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class ContactResponse { + + @JsonProperty("result") + private ResultDTO result; + @JsonProperty("reason") + private String reason; + @JsonProperty("error_code") + private Integer errorCode; + + @NoArgsConstructor + @Data + public static class ResultDTO { + @JsonProperty("phoneNumber") + private String phoneNumber; + @JsonProperty("allCalls") + private List allCalls; + @JsonProperty("regLocation") + private String regLocation; + @JsonProperty("id") + private Integer id; + @JsonProperty("email") + private String email; + @JsonProperty("websiteList") + private String websiteList; + + @NoArgsConstructor + @Data + public static class AllCallsDTO { + @JsonProperty("phoneNumber") + private String phoneNumber; + @JsonProperty("source") + private String source; + @JsonProperty("tag") + private String tag; + } + } +} diff --git a/src/main/java/com/glxp/udidl/admin/res/tyapi/OpenSearchResponse.java b/src/main/java/com/glxp/udidl/admin/res/tyapi/OpenSearchResponse.java new file mode 100644 index 0000000..2e67267 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/tyapi/OpenSearchResponse.java @@ -0,0 +1,58 @@ +package com.glxp.udidl.admin.res.tyapi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class OpenSearchResponse { + @JsonProperty("result") + private ResultDTO result; + @JsonProperty("reason") + private String reason; + @JsonProperty("error_code") + private Integer errorCode; + + @NoArgsConstructor + @Data + public static class ResultDTO { + @JsonProperty("total") + private Integer total; + @JsonProperty("items") + private List items; + + @NoArgsConstructor + @Data + public static class ItemsDTO { + @JsonProperty("regStatus") + private String regStatus; + @JsonProperty("estiblishTime") + private String estiblishTime; + @JsonProperty("regCapital") + private String regCapital; + @JsonProperty("companyType") + private Integer companyType; + @JsonProperty("matchType") + private String matchType; + @JsonProperty("type") + private Integer type; + @JsonProperty("legalPersonName") + private String legalPersonName; + @JsonProperty("regNumber") + private String regNumber; + @JsonProperty("creditCode") + private String creditCode; + @JsonProperty("name") + private String name; + @JsonProperty("id") + private Integer id; + @JsonProperty("orgNumber") + private String orgNumber; + @JsonProperty("base") + private String base; + } + } +} diff --git a/src/main/java/com/glxp/udidl/admin/res/tyapi/SupplierResponse.java b/src/main/java/com/glxp/udidl/admin/res/tyapi/SupplierResponse.java new file mode 100644 index 0000000..ffc9465 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/tyapi/SupplierResponse.java @@ -0,0 +1,68 @@ +package com.glxp.udidl.admin.res.tyapi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + + +@Data +public class SupplierResponse { + + @JsonProperty("result") + private ResultDTO result; + @JsonProperty("reason") + private String reason; + @JsonProperty("error_code") + private Integer errorCode; + + + @Data + public static class ResultDTO { + @JsonProperty("suppliesYear") + private List suppliesYear; + @JsonProperty("pageBean") + private PageBeanDTO pageBean; + + + @Data + public static class PageBeanDTO { + @JsonProperty("result") + private List result; + @JsonProperty("total") + private Integer total; + + + @Data + public static class SupplierDTO { + @JsonProperty("supplier_graphId") + private Long supplier_graphId; + @JsonProperty("announcement_date") + private Long announcement_date; + @JsonProperty("amt") + private String amt; + @JsonProperty("logo") + private String logo; + @JsonProperty("alias") + private String alias; + @JsonProperty("supplier_name") + private String supplier_name; + @JsonProperty("relationship") + private String relationship; + @JsonProperty("dataSource") + private String dataSource; + @JsonProperty("ratio") + private String ratio; + } + } + + + @Data + public static class SuppliesYearDTO { + @JsonProperty("title") + private String title; + @JsonProperty("value") + private String value; + } + } +} diff --git a/src/main/java/com/glxp/udidl/admin/service/CustomService.java b/src/main/java/com/glxp/udidl/admin/service/CustomService.java new file mode 100644 index 0000000..ab40d63 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/service/CustomService.java @@ -0,0 +1,12 @@ +package com.glxp.udidl.admin.service; + +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +public interface CustomService extends IService { + int insertIgnore(T entity); + boolean insertIgnoreBatch(List entityList); + int replace(T entity); + boolean replaceBatch(List entityList); +} diff --git a/src/main/java/com/glxp/udidl/admin/service/CustomServiceImpl.java b/src/main/java/com/glxp/udidl/admin/service/CustomServiceImpl.java new file mode 100644 index 0000000..3decbb1 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/service/CustomServiceImpl.java @@ -0,0 +1,29 @@ +package com.glxp.udidl.admin.service; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.glxp.udidl.admin.dao.BaseMapperPlus; + +import java.util.List; + +public class CustomServiceImpl, T> extends ServiceImpl, T> implements CustomService { + @Override + public int insertIgnore(T entity) { + return baseMapper.insertIgnore(entity); + } + + @Override + public boolean insertIgnoreBatch(List entityList) { + return baseMapper.insertIgnoreBatchs(entityList); + } + + @Override + public int replace(T entity) { + return baseMapper.replace(entity); + } + + @Override + public boolean replaceBatch(List entityList) { + return baseMapper.replaceBatchs(entityList); + } +} diff --git a/src/main/java/com/glxp/udidl/admin/service/tyapi/TyDlHttpClient.java b/src/main/java/com/glxp/udidl/admin/service/tyapi/TyDlHttpClient.java index 83c59d5..fa37590 100644 --- a/src/main/java/com/glxp/udidl/admin/service/tyapi/TyDlHttpClient.java +++ b/src/main/java/com/glxp/udidl/admin/service/tyapi/TyDlHttpClient.java @@ -2,7 +2,10 @@ package com.glxp.udidl.admin.service.tyapi; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; -import com.glxp.udidl.admin.res.BaseResponse; +import com.glxp.udidl.admin.res.tyapi.CompanyBaseResponse; +import com.glxp.udidl.admin.res.tyapi.ContactResponse; +import com.glxp.udidl.admin.res.tyapi.OpenSearchResponse; +import com.glxp.udidl.admin.res.tyapi.SupplierResponse; import com.glxp.udidl.admin.util.OkHttpCli; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -19,23 +22,54 @@ public class TyDlHttpClient { @Value("${TY_AUTHORIZATION}") String suthorization; - String supplyUrl = "http://open.api.tianyancha.com/services/open/m/supply/2.0"; - String baseInfo = "http://open.api.tianyancha.com/services/open/ic/baseinfoV2/2.0"; - String contactUrl = "http://open.api.tianyancha.com/services/open/ic/contact"; - String openSearchUrl = "http://open.api.tianyancha.com/services/open/search/2.0"; - + String supplyUrl = "http://open.api.tianyancha.com/services/open/m/supply/2.0"; //946 + String baseInfoUrl = "http://open.api.tianyancha.com/services/open/ic/baseinfoV2/2.0"; //818 + String contactUrl = "http://open.api.tianyancha.com/services/open/ic/contact"; //1046 + String openSearchUrl = "http://open.api.tianyancha.com/services/open/search/2.0"; //816 String[] headers = {"Authorization", suthorization}; //获取供应商列表 - public void getSupplier() { + public SupplierResponse getSupplier(String hospital, Integer pageNum, Integer pageSize) { Map params = new HashMap<>(); + params.put("keyword", hospital); + params.put("pageNum", pageNum + ""); + params.put("pageSize", pageSize + ""); String response = okHttpCli.doGet(supplyUrl, params, headers); - BaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference>() { + SupplierResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + //获取企业相信信息 + public CompanyBaseResponse getBaseInfo(String company) { + Map params = new HashMap<>(); + params.put("keyword", company); + String response = okHttpCli.doGet(baseInfoUrl, params, headers); + CompanyBaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + //获取企业相信信息 + public ContactResponse getContact(String company) { + Map params = new HashMap<>(); + params.put("keyword", company); + String response = okHttpCli.doGet(contactUrl, params, headers); + ContactResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + + //获取企业相信信息 + public OpenSearchResponse getOpenSearch(String company) { + Map params = new HashMap<>(); + params.put("keyword", company); + String response = okHttpCli.doGet(openSearchUrl, params, headers); + OpenSearchResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { }); - if (baseResponse.getCode() == 20000) { - } else { - } + return baseResponse; } } diff --git a/src/main/java/com/glxp/udidl/admin/service/tyapi/TySupplierService.java b/src/main/java/com/glxp/udidl/admin/service/tyapi/TySupplierService.java index 5120605..82409f4 100644 --- a/src/main/java/com/glxp/udidl/admin/service/tyapi/TySupplierService.java +++ b/src/main/java/com/glxp/udidl/admin/service/tyapi/TySupplierService.java @@ -1,10 +1,48 @@ package com.glxp.udidl.admin.service.tyapi; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import com.glxp.udidl.admin.res.tyapi.SupplierResponse; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.glxp.udidl.admin.entity.tyapi.TySupplierEntity; import com.glxp.udidl.admin.dao.tyapi.TySupplierMapper; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + @Service public class TySupplierService extends ServiceImpl { + @Resource + TyDlHttpClient tyDlHttpClient; + @Resource + TySupplierMapper tySupplierMapper; + + public void download(String hospital) { + + Integer pageNum = 1; + Integer pageSize = 20; + while (true) { + SupplierResponse supplierResponse = tyDlHttpClient.getSupplier(hospital, pageNum, pageSize); + if (supplierResponse.getErrorCode() == 0) { + List supplierDTOS = supplierResponse.getResult().getPageBean().getResult(); + List tySupplierEntities = BeanUtil.copyToList(supplierDTOS, TySupplierEntity.class); + if (CollUtil.isNotEmpty(supplierDTOS)) { + for (TySupplierEntity tySupplierEntity : tySupplierEntities) { + tySupplierEntity.setHospName(hospital); + tySupplierEntity.setUpdateTime(new Date()); + } + } + tySupplierMapper.insertBatch(tySupplierEntities); + if (CollUtil.isNotEmpty(supplierDTOS) && supplierDTOS.size() == 20) { + pageNum = pageNum + 1; + } else { + return; + } + } + } + } + } diff --git a/src/main/java/com/glxp/udidl/admin/util/BeanCopyUtils.java b/src/main/java/com/glxp/udidl/admin/util/BeanCopyUtils.java new file mode 100644 index 0000000..043dda3 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/util/BeanCopyUtils.java @@ -0,0 +1,184 @@ +package com.glxp.udidl.admin.util; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.SimpleCache; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.cglib.beans.BeanCopier; +import org.springframework.cglib.beans.BeanMap; +import org.springframework.cglib.core.Converter; + +import java.util.List; +import java.util.Map; + +/** + * bean深拷贝工具(基于 cglib 性能优异) + *

+ * 重点 cglib 不支持 拷贝到链式对象 + * 例如: 源对象 拷贝到 目标(链式对象) + * 请区分好`浅拷贝`和`深拷贝`再做使用 + * + * @author Lion Li + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BeanCopyUtils { + + /** + * 单对象基于class创建拷贝 + * + * @param source 数据来源实体 + * @param desc 描述对象 转换后的对象 + * @return desc + */ + public static V copy(T source, Class desc) { + if (ObjectUtil.isNull(source)) { + return null; + } + if (ObjectUtil.isNull(desc)) { + return null; + } + final V target = ReflectUtil.newInstanceIfPossible(desc); + return copy(source, target); + } + + /** + * 单对象基于对象创建拷贝 + * + * @param source 数据来源实体 + * @param desc 转换后的对象 + * @return desc + */ + public static V copy(T source, V desc) { + if (ObjectUtil.isNull(source)) { + return null; + } + if (ObjectUtil.isNull(desc)) { + return null; + } + BeanCopier beanCopier = BeanCopierCache.INSTANCE.get(source.getClass(), desc.getClass(), null); + beanCopier.copy(source, desc, null); + return desc; + } + + /** + * 列表对象基于class创建拷贝 + * + * @param sourceList 数据来源实体列表 + * @param desc 描述对象 转换后的对象 + * @return desc + */ + public static List copyList(List sourceList, Class desc) { + if (ObjectUtil.isNull(sourceList)) { + return null; + } + if (CollUtil.isEmpty(sourceList)) { + return CollUtil.newArrayList(); + } + return StreamUtils.toList(sourceList, source -> { + V target = ReflectUtil.newInstanceIfPossible(desc); + copy(source, target); + return target; + }); + } + + /** + * bean拷贝到map + * + * @param bean 数据来源实体 + * @return map对象 + */ + @SuppressWarnings("unchecked") + public static Map copyToMap(T bean) { + if (ObjectUtil.isNull(bean)) { + return null; + } + return BeanMap.create(bean); + } + + /** + * map拷贝到bean + * + * @param map 数据来源 + * @param beanClass bean类 + * @return bean对象 + */ + public static T mapToBean(Map map, Class beanClass) { + if (MapUtil.isEmpty(map)) { + return null; + } + if (ObjectUtil.isNull(beanClass)) { + return null; + } + T bean = ReflectUtil.newInstanceIfPossible(beanClass); + return mapToBean(map, bean); + } + + /** + * map拷贝到bean + * + * @param map 数据来源 + * @param bean bean对象 + * @return bean对象 + */ + public static T mapToBean(Map map, T bean) { + if (MapUtil.isEmpty(map)) { + return null; + } + if (ObjectUtil.isNull(bean)) { + return null; + } + BeanMap.create(bean).putAll(map); + return bean; + } + + /** + * BeanCopier属性缓存
+ * 缓存用于防止多次反射造成的性能问题 + * + * @author Looly + * @since 5.4.1 + */ + public enum BeanCopierCache { + /** + * BeanCopier属性缓存单例 + */ + INSTANCE; + + private final SimpleCache cache = new SimpleCache<>(); + + /** + * 获得类与转换器生成的key在{@link BeanCopier}的Map中对应的元素 + * + * @param srcClass 源Bean的类 + * @param targetClass 目标Bean的类 + * @param converter 转换器 + * @return Map中对应的BeanCopier + */ + public BeanCopier get(Class srcClass, Class targetClass, Converter converter) { + final String key = genKey(srcClass, targetClass, converter); + return cache.get(key, () -> BeanCopier.create(srcClass, targetClass, converter != null)); + } + + /** + * 获得类与转换器生成的key + * + * @param srcClass 源Bean的类 + * @param targetClass 目标Bean的类 + * @param converter 转换器 + * @return 属性名和Map映射的key + */ + private String genKey(Class srcClass, Class targetClass, Converter converter) { + final StringBuilder key = StrUtil.builder() + .append(srcClass.getName()).append('#').append(targetClass.getName()); + if(null != converter){ + key.append('#').append(converter.getClass().getName()); + } + return key.toString(); + } + } + +} diff --git a/src/main/java/com/glxp/udidl/admin/util/StreamUtils.java b/src/main/java/com/glxp/udidl/admin/util/StreamUtils.java new file mode 100644 index 0000000..983f103 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/util/StreamUtils.java @@ -0,0 +1,247 @@ +package com.glxp.udidl.admin.util; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StreamUtils { + + /** + * 将collection过滤 + * + * @param collection 需要转化的集合 + * @param function 过滤方法 + * @return 过滤后的list + */ + public static List filter(Collection collection, Predicate function) { + if (CollUtil.isEmpty(collection)) { + return CollUtil.newArrayList(); + } + return collection.stream().filter(function).collect(Collectors.toList()); + } + + /** + * 将collection拼接 + * + * @param collection 需要转化的集合 + * @param function 拼接方法 + * @return 拼接后的list + */ + public static String join(Collection collection, Function function) { + return join(collection, function, ","); + } + + /** + * 将collection拼接 + * + * @param collection 需要转化的集合 + * @param function 拼接方法 + * @param delimiter 拼接符 + * @return 拼接后的list + */ + public static String join(Collection collection, Function function, CharSequence delimiter) { + if (CollUtil.isEmpty(collection)) { + return StringUtils.EMPTY; + } + return collection.stream().map(function).filter(Objects::nonNull).collect(Collectors.joining(delimiter)); + } + + /** + * 将collection排序 + * + * @param collection 需要转化的集合 + * @param comparing 排序方法 + * @return 排序后的list + */ + public static List sorted(Collection collection, Comparator comparing) { + if (CollUtil.isEmpty(collection)) { + return CollUtil.newArrayList(); + } + return collection.stream().sorted(comparing).collect(Collectors.toList()); + } + + /** + * 将collection转化为类型不变的map
+ * {@code Collection ----> Map} + * + * @param collection 需要转化的集合 + * @param key V类型转化为K类型的lambda方法 + * @param collection中的泛型 + * @param map中的key类型 + * @return 转化后的map + */ + public static Map toIdentityMap(Collection collection, Function key) { + if (CollUtil.isEmpty(collection)) { + return MapUtil.newHashMap(); + } + return collection.stream().collect(Collectors.toMap(key, Function.identity(), (l, r) -> l)); + } + + /** + * 将Collection转化为map(value类型与collection的泛型不同)
+ * {@code Collection -----> Map } + * + * @param collection 需要转化的集合 + * @param key E类型转化为K类型的lambda方法 + * @param value E类型转化为V类型的lambda方法 + * @param collection中的泛型 + * @param map中的key类型 + * @param map中的value类型 + * @return 转化后的map + */ + public static Map toMap(Collection collection, Function key, Function value) { + if (CollUtil.isEmpty(collection)) { + return MapUtil.newHashMap(); + } + return collection.stream().collect(Collectors.toMap(key, value, (l, r) -> l)); + } + + /** + * 将collection按照规则(比如有相同的班级id)分类成map
+ * {@code Collection -------> Map> } + * + * @param collection 需要分类的集合 + * @param key 分类的规则 + * @param collection中的泛型 + * @param map中的key类型 + * @return 分类后的map + */ + public static Map> groupByKey(Collection collection, Function key) { + if (CollUtil.isEmpty(collection)) { + return MapUtil.newHashMap(); + } + return collection + .stream() + .collect(Collectors.groupingBy(key, LinkedHashMap::new, Collectors.toList())); + } + + /** + * 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map
+ * {@code Collection ---> Map>> } + * + * @param collection 需要分类的集合 + * @param key1 第一个分类的规则 + * @param key2 第二个分类的规则 + * @param 集合元素类型 + * @param 第一个map中的key类型 + * @param 第二个map中的key类型 + * @return 分类后的map + */ + public static Map>> groupBy2Key(Collection collection, Function key1, Function key2) { + if (CollUtil.isEmpty(collection)) { + return MapUtil.newHashMap(); + } + return collection + .stream() + .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.groupingBy(key2, LinkedHashMap::new, Collectors.toList()))); + } + + /** + * 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map
+ * {@code Collection ---> Map> } + * + * @param collection 需要分类的集合 + * @param key1 第一个分类的规则 + * @param key2 第二个分类的规则 + * @param 第一个map中的key类型 + * @param 第二个map中的key类型 + * @param collection中的泛型 + * @return 分类后的map + */ + public static Map> group2Map(Collection collection, Function key1, Function key2) { + if (CollUtil.isEmpty(collection) || key1 == null || key2 == null) { + return MapUtil.newHashMap(); + } + return collection + .stream() + .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.toMap(key2, Function.identity(), (l, r) -> l))); + } + + /** + * 将collection转化为List集合,但是两者的泛型不同
+ * {@code Collection ------> List } + * + * @param collection 需要转化的集合 + * @param function collection中的泛型转化为list泛型的lambda表达式 + * @param collection中的泛型 + * @param List中的泛型 + * @return 转化后的list + */ + public static List toList(Collection collection, Function function) { + if (CollUtil.isEmpty(collection)) { + return CollUtil.newArrayList(); + } + return collection + .stream() + .map(function) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + /** + * 将collection转化为Set集合,但是两者的泛型不同
+ * {@code Collection ------> Set } + * + * @param collection 需要转化的集合 + * @param function collection中的泛型转化为set泛型的lambda表达式 + * @param collection中的泛型 + * @param Set中的泛型 + * @return 转化后的Set + */ + public static Set toSet(Collection collection, Function function) { + if (CollUtil.isEmpty(collection) || function == null) { + return CollUtil.newHashSet(); + } + return collection + .stream() + .map(function) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + } + + + /** + * 合并两个相同key类型的map + * + * @param map1 第一个需要合并的 map + * @param map2 第二个需要合并的 map + * @param merge 合并的lambda,将key value1 value2合并成最终的类型,注意value可能为空的情况 + * @param map中的key类型 + * @param 第一个 map的value类型 + * @param 第二个 map的value类型 + * @param 最终map的value类型 + * @return 合并后的map + */ + public static Map merge(Map map1, Map map2, BiFunction merge) { + if (MapUtil.isEmpty(map1) && MapUtil.isEmpty(map2)) { + return MapUtil.newHashMap(); + } else if (MapUtil.isEmpty(map1)) { + map1 = MapUtil.newHashMap(); + } else if (MapUtil.isEmpty(map2)) { + map2 = MapUtil.newHashMap(); + } + Set key = new HashSet<>(); + key.addAll(map1.keySet()); + key.addAll(map2.keySet()); + Map map = new HashMap<>(); + for (K t : key) { + X x = map1.get(t); + Y y = map2.get(t); + V z = merge.apply(x, y); + if (z != null) { + map.put(t, z); + } + } + return map; + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 15803a3..235f750 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -4,7 +4,7 @@ spring: matching-strategy: ant_path_matcher datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/udidl_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + url: jdbc:mysql://127.0.0.1:3306/udidl_test?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root password: 123456 hikari: diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index f273f0b..cbe0ba6 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -4,19 +4,33 @@ spring: matching-strategy: ant_path_matcher datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/udidl_test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://127.0.0.1:3306/udidl_test?allowMultiQueries=true&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false username: root - password: 123456 + password: mysql@2020 hikari: pool-name: udidl connection-timeout: 100000 #设置等待超时时间为10秒 maximum-pool-size: 60 minimum-idle: 10 + redis: + database: 6 + host: 127.0.0.1 + port: 6379 + password: + connect-timeout: 5000ms + lettuce: + pool: + max-active: 60 + max-idle: 10 + min-idle: 5 + max-wait: 5000ms servlet: multipart: max-file-size: 100MB max-request-size: 1000MB + + ok: http: connect-timeout: 3000 @@ -24,7 +38,6 @@ ok: write-timeout: 3000 max-idle-connections: 200 keep-alive-duration: 300 - logging: level: com.glxp: debug @@ -35,7 +48,7 @@ UDIC_MIPSDOWNLOAD_URL: http://127.0.0.1:8080/UDIC_MIPSDL_Server config: downloadPath: E:/temp openAuth: false - +TY_AUTHORIZATION: ac9d111c-3abd-4d8c-bf57-2df44952ab2e # 阳光采购平台 udplat: host: http://pre-mcs.udplat.org/mcs-api diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 122d21b..cc534e0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ knife4j: mybatis-plus: mapperPackage: com.glxp.udidl.admin.dao.* - mapper-locations: classpath*:mybatis/mapper/**/*Mapper.xml + mapper-locations: classpath*:mybatis/mapper/**/*.xml type-aliases-package: com.glxp.udidl.admin.entity check-config-location: false configuration: diff --git a/src/main/resources/mybatis/mapper/sys/DbVersionDao.xml b/src/main/resources/mybatis/mapper/sys/DbVersionDao.xml new file mode 100644 index 0000000..693c9ea --- /dev/null +++ b/src/main/resources/mybatis/mapper/sys/DbVersionDao.xml @@ -0,0 +1,21 @@ + + + + + + + + + insert into sys_db_version(id, version, remark, created) + values (uuid(), #{version}, #{remark}, #{created}) + + diff --git a/src/main/resources/schemas/init.sql b/src/main/resources/schemas/init.sql new file mode 100644 index 0000000..b3e0119 --- /dev/null +++ b/src/main/resources/schemas/init.sql @@ -0,0 +1,105 @@ +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; +DROP TABLE IF EXISTS `sys_db_version`; +CREATE TABLE `sys_db_version` +( + `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, + `version` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '版本号', + `created` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', + `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + CHARACTER SET = utf8mb4 + COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据版本' + ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; + + +/* 创建函数Pro_Temp_ColumnWork操作表字段 */ +DROP PROCEDURE IF EXISTS Pro_Temp_ColumnWork; +CREATE PROCEDURE `Pro_Temp_ColumnWork`(TableName VARCHAR(50), ColumnName VARCHAR(50), SqlStr VARCHAR(4000), CType INT) +BEGIN + DECLARE + Rows1 INT; + + SET Rows1 = 0; + SELECT COUNT(*) + INTO Rows1 + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_schema = DATABASE() + AND upper(table_name) = TableName + AND upper(column_name) = ColumnName; + IF + (CType = 1 AND Rows1 <= 0) THEN + + SET SqlStr := CONCAT('ALTER TABLE ', TableName, ' ADD COLUMN ', ColumnName, ' ', SqlStr); + + ELSEIF (CType = 2 AND Rows1 > 0) THEN + + SET SqlStr := CONCAT('ALTER TABLE ', TableName, ' MODIFY ', ColumnName, ' ', SqlStr); + + ELSEIF (CType = 3 AND Rows1 > 0) THEN + + SET SqlStr := CONCAT('ALTER TABLE ', TableName, ' DROP COLUMN ', ColumnName); + ELSE + SET SqlStr := ''; + + END IF; + IF + (SqlStr <> '') THEN + + SET @SQL1 = SqlStr; + PREPARE stmt1 + FROM + @SQL1; + EXECUTE stmt1; + + END IF; + +END; +/** 函数创建结束 **/ + +/*创建定义普通索引函数*/ +DROP PROCEDURE IF EXISTS Modify_index; + +CREATE PROCEDURE Modify_index( + TableName VARCHAR(50), + ColumnNames VARCHAR(500), + idx_name VARCHAR(50), + idx_type VARCHAR(50)) +BEGIN + DECLARE + Rows1 int; + DECLARE + SqlStr VARCHAR(4000); + DECLARE + target_database VARCHAR(100); + SELECT DATABASE + () + INTO target_database; + + SET Rows1 = 0; + SELECT COUNT(*) + INTO Rows1 + FROM information_schema.statistics + WHERE table_schema = DATABASE() + AND upper(table_name) = upper(TableName) + AND upper(index_name) = upper(idx_name); + IF Rows1 <= 0 THEN + SET SqlStr := + CONCAT('alter table ', TableName, ' ADD INDEX ', idx_name, '(', ColumnNames, ') USING ', idx_type); + END IF; + IF + (SqlStr <> '') THEN + + SET @SQL1 = SqlStr; + PREPARE stmt1 + FROM + @SQL1; + EXECUTE stmt1; + + END IF; + +END; +/*创建定义普通索引函数结束*/ diff --git a/src/main/resources/schemas/schema_v2.1.sql b/src/main/resources/schemas/schema_v2.1.sql new file mode 100644 index 0000000..4e7845a --- /dev/null +++ b/src/main/resources/schemas/schema_v2.1.sql @@ -0,0 +1,13 @@ +# 字段新增 (表名,字段名,字段类型,修改方式(1:新增,2:修改,3:删除) + +CALL Pro_Temp_ColumnWork('ty_supplier', 'updateTime', 'date', 1); + + + + + + + + + +