|
|
|
|
@ -13,7 +13,7 @@
|
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
|
* the License.
|
|
|
|
|
*/
|
|
|
|
|
package org.opsli.modulars.creater.table.service.impl;
|
|
|
|
|
package org.opsli.modulars.generator.table.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
@ -23,19 +23,19 @@ import org.opsli.common.constants.MyBatisConstants;
|
|
|
|
|
import org.opsli.common.enums.DictType;
|
|
|
|
|
import org.opsli.common.utils.WrapperUtil;
|
|
|
|
|
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
|
|
|
|
import org.opsli.core.creater.exception.CreaterException;
|
|
|
|
|
import org.opsli.core.creater.msg.CreaterMsg;
|
|
|
|
|
import org.opsli.modulars.creater.column.service.ITableColumnService;
|
|
|
|
|
import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel;
|
|
|
|
|
import org.opsli.modulars.creater.createrlogs.service.ICreateLogsService;
|
|
|
|
|
import org.opsli.modulars.creater.importable.ImportTableUtil;
|
|
|
|
|
import org.opsli.modulars.creater.importable.entity.DatabaseColumn;
|
|
|
|
|
import org.opsli.modulars.creater.importable.entity.DatabaseTable;
|
|
|
|
|
import org.opsli.modulars.creater.table.entity.CreaterTable;
|
|
|
|
|
import org.opsli.modulars.creater.table.mapper.TableMapper;
|
|
|
|
|
import org.opsli.modulars.creater.table.service.ITableService;
|
|
|
|
|
import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel;
|
|
|
|
|
import org.opsli.modulars.creater.table.wrapper.CreaterTableModel;
|
|
|
|
|
import org.opsli.core.generator.exception.GeneratorException;
|
|
|
|
|
import org.opsli.core.generator.msg.GeneratorMsg;
|
|
|
|
|
import org.opsli.modulars.generator.column.service.IGenTableColumnService;
|
|
|
|
|
import org.opsli.modulars.generator.column.wrapper.GenTableColumnModel;
|
|
|
|
|
import org.opsli.modulars.generator.logs.service.IGenLogsService;
|
|
|
|
|
import org.opsli.modulars.generator.importable.ImportTableUtil;
|
|
|
|
|
import org.opsli.modulars.generator.importable.entity.DatabaseColumn;
|
|
|
|
|
import org.opsli.modulars.generator.importable.entity.DatabaseTable;
|
|
|
|
|
import org.opsli.modulars.generator.table.entity.GenTable;
|
|
|
|
|
import org.opsli.modulars.generator.table.mapper.GenTableMapper;
|
|
|
|
|
import org.opsli.modulars.generator.table.service.IGenTableService;
|
|
|
|
|
import org.opsli.modulars.generator.table.wrapper.GenTableAndColumnModel;
|
|
|
|
|
import org.opsli.modulars.generator.table.wrapper.GenTableModel;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -51,21 +51,21 @@ import java.util.List;
|
|
|
|
|
* @date 2020-09-16 17:34
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable, CreaterTableModel>
|
|
|
|
|
implements ITableService {
|
|
|
|
|
public class GenTableServiceImpl extends CrudServiceImpl<GenTableMapper, GenTable, GenTableModel>
|
|
|
|
|
implements IGenTableService {
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private TableMapper mapper;
|
|
|
|
|
private GenTableMapper mapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ITableColumnService iTableColumnService;
|
|
|
|
|
private IGenTableColumnService iGenTableColumnService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ICreateLogsService iCreateLogsService;
|
|
|
|
|
private IGenLogsService iGenLogsService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public CreaterTableModel insert(CreaterTableModel model) {
|
|
|
|
|
public GenTableModel insert(GenTableModel model) {
|
|
|
|
|
if(model == null){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@ -74,7 +74,7 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
Integer count = this.uniqueVerificationByTableName(model);
|
|
|
|
|
if(count != null && count > 0){
|
|
|
|
|
// 重复
|
|
|
|
|
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT);
|
|
|
|
|
throw new GeneratorException(GeneratorMsg.EXCEPTION_TABLE_NAME_REPEAT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!model.getIzApi()){
|
|
|
|
|
@ -91,7 +91,7 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public CreaterTableModel update(CreaterTableModel model) {
|
|
|
|
|
public GenTableModel update(GenTableModel model) {
|
|
|
|
|
if(model == null){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@ -100,10 +100,10 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
Integer count = this.uniqueVerificationByTableName(model);
|
|
|
|
|
if(count != null && count > 0){
|
|
|
|
|
// 重复
|
|
|
|
|
throw new CreaterException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT);
|
|
|
|
|
throw new GeneratorException(GeneratorMsg.EXCEPTION_TABLE_NAME_REPEAT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreaterTableModel oldModel = this.get(model.getId());
|
|
|
|
|
GenTableModel oldModel = this.get(model.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改后 默认未同步
|
|
|
|
|
@ -119,39 +119,39 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void insertAny(CreaterTableAndColumnModel model){
|
|
|
|
|
CreaterTableModel tableModel = WrapperUtil.transformInstance(model, CreaterTableModel.class);
|
|
|
|
|
public void insertAny(GenTableAndColumnModel model){
|
|
|
|
|
GenTableModel tableModel = WrapperUtil.transformInstance(model, GenTableModel.class);
|
|
|
|
|
// 保存表头数据
|
|
|
|
|
tableModel = this.insert(tableModel);
|
|
|
|
|
if(tableModel != null){
|
|
|
|
|
// 删除旧字段 全部新增
|
|
|
|
|
iTableColumnService.delByTableId(tableModel.getId());
|
|
|
|
|
iGenTableColumnService.delByTableId(tableModel.getId());
|
|
|
|
|
|
|
|
|
|
// 保存 表结构数据
|
|
|
|
|
List<CreaterTableColumnModel> columnList = model.getColumnList();
|
|
|
|
|
for (CreaterTableColumnModel tableColumnModel : columnList) {
|
|
|
|
|
List<GenTableColumnModel> columnList = model.getColumnList();
|
|
|
|
|
for (GenTableColumnModel tableColumnModel : columnList) {
|
|
|
|
|
tableColumnModel.setTableId(tableModel.getId());
|
|
|
|
|
}
|
|
|
|
|
iTableColumnService.insertBatch(columnList);
|
|
|
|
|
iGenTableColumnService.insertBatch(columnList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void updateAny(CreaterTableAndColumnModel model){
|
|
|
|
|
CreaterTableModel tableModel = WrapperUtil.transformInstance(model, CreaterTableModel.class);
|
|
|
|
|
public void updateAny(GenTableAndColumnModel model){
|
|
|
|
|
GenTableModel tableModel = WrapperUtil.transformInstance(model, GenTableModel.class);
|
|
|
|
|
// 保存表头数据
|
|
|
|
|
tableModel = this.update(tableModel);
|
|
|
|
|
if(tableModel != null){
|
|
|
|
|
// 删除旧字段 全部新增
|
|
|
|
|
iTableColumnService.delByTableId(tableModel.getId());
|
|
|
|
|
iGenTableColumnService.delByTableId(tableModel.getId());
|
|
|
|
|
|
|
|
|
|
// 保存 表结构数据
|
|
|
|
|
List<CreaterTableColumnModel> columnList = model.getColumnList();
|
|
|
|
|
for (CreaterTableColumnModel tableColumnModel : columnList) {
|
|
|
|
|
List<GenTableColumnModel> columnList = model.getColumnList();
|
|
|
|
|
for (GenTableColumnModel tableColumnModel : columnList) {
|
|
|
|
|
tableColumnModel.setTableId(tableModel.getId());
|
|
|
|
|
}
|
|
|
|
|
iTableColumnService.insertBatch(columnList);
|
|
|
|
|
iGenTableColumnService.insertBatch(columnList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -164,10 +164,10 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
// 删除字段
|
|
|
|
|
iTableColumnService.delByTableId(id);
|
|
|
|
|
iGenTableColumnService.delByTableId(id);
|
|
|
|
|
|
|
|
|
|
// 删除生成记录
|
|
|
|
|
iCreateLogsService.delByTableId(id);
|
|
|
|
|
iGenLogsService.delByTableId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -180,10 +180,10 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除字段
|
|
|
|
|
iTableColumnService.delByTableIds(ids);
|
|
|
|
|
iGenTableColumnService.delByTableIds(ids);
|
|
|
|
|
|
|
|
|
|
// 删除生成记录
|
|
|
|
|
iCreateLogsService.delByTableIds(ids);
|
|
|
|
|
iGenLogsService.delByTableIds(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -209,22 +209,22 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(table == null){
|
|
|
|
|
String msg = StrUtil.format(CreaterMsg.EXCEPTION_IMPORT_TABLE_NULL.getMessage(), tableName);
|
|
|
|
|
String msg = StrUtil.format(GeneratorMsg.EXCEPTION_IMPORT_TABLE_NULL.getMessage(), tableName);
|
|
|
|
|
// 暂无该表
|
|
|
|
|
throw new CreaterException(CreaterMsg.EXCEPTION_IMPORT_TABLE_NULL.getCode(), msg);
|
|
|
|
|
throw new GeneratorException(GeneratorMsg.EXCEPTION_IMPORT_TABLE_NULL.getCode(), msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获得表字段
|
|
|
|
|
List<DatabaseColumn> columns = ImportTableUtil.findColumns(tableName);
|
|
|
|
|
if(CollUtil.isEmpty(columns)){
|
|
|
|
|
// 暂未获得表字段
|
|
|
|
|
throw new CreaterException(CreaterMsg.EXCEPTION_IMPORT_FIELD_NULL);
|
|
|
|
|
throw new GeneratorException(GeneratorMsg.EXCEPTION_IMPORT_FIELD_NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CreaterTableColumnModel> columnModels = new ArrayList<>();
|
|
|
|
|
List<GenTableColumnModel> columnModels = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < columns.size(); i++) {
|
|
|
|
|
DatabaseColumn column = columns.get(i);
|
|
|
|
|
CreaterTableColumnModel columnModel = new CreaterTableColumnModel();
|
|
|
|
|
GenTableColumnModel columnModel = new GenTableColumnModel();
|
|
|
|
|
columnModel.setFieldName(column.getColumnName());
|
|
|
|
|
columnModel.setFieldType(column.getColumnType());
|
|
|
|
|
columnModel.setFieldLength(column.getColumnLength());
|
|
|
|
|
@ -239,16 +239,16 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成本地数据
|
|
|
|
|
CreaterTableAndColumnModel createrTableModel = new CreaterTableAndColumnModel();
|
|
|
|
|
createrTableModel.setComments(table.getTableComments());
|
|
|
|
|
createrTableModel.setTableName(table.getTableName());
|
|
|
|
|
createrTableModel.setOldTableName(table.getTableName());
|
|
|
|
|
createrTableModel.setIzSync("1");
|
|
|
|
|
createrTableModel.setJdbcType(ImportTableUtil.getDbType()!=null?ImportTableUtil.getDbType().getDb():null);
|
|
|
|
|
createrTableModel.setTableType("0");
|
|
|
|
|
createrTableModel.setColumnList(columnModels);
|
|
|
|
|
createrTableModel.setIzApi(true);
|
|
|
|
|
this.insertAny(createrTableModel);
|
|
|
|
|
GenTableAndColumnModel genTableModel = new GenTableAndColumnModel();
|
|
|
|
|
genTableModel.setComments(table.getTableComments());
|
|
|
|
|
genTableModel.setTableName(table.getTableName());
|
|
|
|
|
genTableModel.setOldTableName(table.getTableName());
|
|
|
|
|
genTableModel.setIzSync("1");
|
|
|
|
|
genTableModel.setJdbcType(ImportTableUtil.getDbType()!=null?ImportTableUtil.getDbType().getDb():null);
|
|
|
|
|
genTableModel.setTableType("0");
|
|
|
|
|
genTableModel.setColumnList(columnModels);
|
|
|
|
|
genTableModel.setIzApi(true);
|
|
|
|
|
this.insertAny(genTableModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -261,11 +261,11 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
|
|
|
|
|
* @return Integer
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
public Integer uniqueVerificationByTableName(CreaterTableModel model){
|
|
|
|
|
public Integer uniqueVerificationByTableName(GenTableModel model){
|
|
|
|
|
if(model == null){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<CreaterTable> wrapper = new QueryWrapper<>();
|
|
|
|
|
QueryWrapper<GenTable> wrapper = new QueryWrapper<>();
|
|
|
|
|
|
|
|
|
|
// code 唯一
|
|
|
|
|
wrapper.eq("table_name", model.getTableName());
|