|
@@ -5,9 +5,14 @@ import java.util.List;
|
|
|
import java.util.concurrent.locks.Condition;
|
|
|
|
|
|
import com.boman.common.core.constant.UserConstants;
|
|
|
+import com.boman.common.core.utils.DateUtils;
|
|
|
+import com.boman.common.core.utils.SecurityUtils;
|
|
|
import com.boman.common.core.utils.StringUtils;
|
|
|
+import com.boman.common.log.enums.BusinessType;
|
|
|
import com.boman.gen.domain.GenTable;
|
|
|
+import com.boman.gen.domain.TableSql;
|
|
|
import com.boman.gen.mapper.GenTableMapper;
|
|
|
+import com.boman.gen.mapper.TableSqlMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.boman.common.core.text.Convert;
|
|
@@ -25,6 +30,8 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
private GenTableColumnMapper genTableColumnMapper;
|
|
|
@Autowired
|
|
|
private GenTableMapper genTableMapper;
|
|
|
+ @Autowired
|
|
|
+ private TableSqlMapper tableSqlMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询业务字段列表
|
|
@@ -39,12 +46,13 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
|
|
|
/**
|
|
|
* 根据gen_table_column的id查询字段对象
|
|
|
+ *
|
|
|
* @param columnId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public GenTableColumn selectGenTableColumnListByColumnId(Long columnId) {
|
|
|
- return genTableColumnMapper.selectGenTableColumnListByColumnId(columnId);
|
|
|
+ return genTableColumnMapper.selectGenTableColumnByColumnId(columnId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -70,8 +78,10 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
*/
|
|
|
@Override
|
|
|
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
|
|
+ int i = genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
|
|
isAk(genTableColumn);
|
|
|
- return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
|
|
+ insertCreateLog(genTableColumn, BusinessType.INSERT);
|
|
|
+ return i;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,11 +93,37 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
@Override
|
|
|
public int updateGenTableColumn(GenTableColumn genTableColumn) {
|
|
|
isAk(genTableColumn);
|
|
|
+ insertCreateLog(genTableColumn, BusinessType.UPDATE);
|
|
|
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 插入表sql日志
|
|
|
+ */
|
|
|
+ public void insertCreateLog(GenTableColumn genTableColumn, BusinessType type) {
|
|
|
+ GenTable genTable = genTableMapper.selectGenTableById(genTableColumn.getTableId());
|
|
|
+ //新增业务字段的同时新增一条建表sql修改日志
|
|
|
+ TableSql tableSql = tableSqlMapper.selectTableSqlByTableId(genTableColumn.getTableId());
|
|
|
+ String createLog = tableSql.getCreateLog();
|
|
|
+ StringBuffer sb = new StringBuffer(createLog);
|
|
|
+ //ALTER TABLE table_name ADD COLUMN column_name VARCHAR(100) DEFAULT NULL COMMENT '新加字段';
|
|
|
+ sb.append("\r\n").append(DateUtils.getTime()).append(" ").append(SecurityUtils.getUsername()).append(" ALTER TABLE ").append(genTable.getTableName());
|
|
|
+ if (BusinessType.INSERT.equals(type)){
|
|
|
+ sb.append(" ADD COLUMN ").append(genTableColumn.getColumnName()).append(" ").append(genTableColumn.getColumnType());
|
|
|
+ sb = genTableColumn.getDefaultValue() == null ? sb.append(" DEFAULT NULL COMMENT ") : sb.append(" DEFAULT '").append(genTableColumn.getDefaultValue()).append("' COMMENT '");
|
|
|
+ sb.append(genTableColumn.getColumnComment()).append("';");
|
|
|
+ }else if(BusinessType.UPDATE.equals(type)){
|
|
|
+ sb.append(" MODIFY ").append(genTableColumn.getColumnName()).append(" ").append(genTableColumn.getColumnType()).append(";");
|
|
|
+ }else if(BusinessType.DELETE.equals(type)){
|
|
|
+ sb.append(" DROP ").append(genTableColumn.getColumnName()).append(";");
|
|
|
+ }
|
|
|
+ tableSql.setCreateLog(sb.toString());
|
|
|
+ tableSqlMapper.updateTableSql(tableSql);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断对象是否设置显示和输入字段
|
|
|
+ *
|
|
|
* @param genTableColumn
|
|
|
*/
|
|
|
public void isAk(GenTableColumn genTableColumn) {
|
|
@@ -95,16 +131,33 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
String isIn = genTableColumn.getIsIn();
|
|
|
//是否是显示
|
|
|
String isOut = genTableColumn.getIsOut();
|
|
|
+ List<GenTableColumn> genTableColumns = genTableColumnMapper.selectGenTableColumnListByTableId(genTableColumn.getTableId());
|
|
|
GenTable genTable = new GenTable();
|
|
|
- if (UserConstants.YES.equals(isIn)){
|
|
|
+ if (UserConstants.YES.equals(isIn)) {
|
|
|
+ //判断是否已经存在输入字段且不是同一个字段
|
|
|
+ for (GenTableColumn tableColumn : genTableColumns) {
|
|
|
+ if (UserConstants.YES.equals(tableColumn.getIsIn()) && !tableColumn.getColumnId().equals(genTableColumn.getColumnId())){
|
|
|
+ tableColumn.setIsIn("N");
|
|
|
+ genTableColumnMapper.updateGenTableColumn(tableColumn);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
genTable.setTableId(genTableColumn.getTableId());
|
|
|
genTable.setAkColumn(genTableColumn.getColumnId());
|
|
|
}
|
|
|
- if (UserConstants.YES.equals(isOut)){
|
|
|
+ if (UserConstants.YES.equals(isOut)) {
|
|
|
+ //判断是否已经存在显示字段且不是同一个字段
|
|
|
+ for (GenTableColumn tableColumn : genTableColumns) {
|
|
|
+ if (UserConstants.YES.equals(tableColumn.getIsOut()) && !tableColumn.getColumnId().equals(genTableColumn.getColumnId())){
|
|
|
+ tableColumn.setIsOut("N");
|
|
|
+ genTableColumnMapper.updateGenTableColumn(tableColumn);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
genTable.setTableId(genTableColumn.getTableId());
|
|
|
genTable.setDkColumn(genTableColumn.getColumnId());
|
|
|
}
|
|
|
- if (genTable.getTableId() != null){
|
|
|
+ if (genTable.getTableId() != null) {
|
|
|
genTableMapper.updateGenTable(genTable);
|
|
|
}
|
|
|
}
|
|
@@ -113,7 +166,7 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
/**
|
|
|
* 删除业务字段对象
|
|
|
*
|
|
|
- * @param ids 需要删除的数据ID
|
|
|
+ * @param ids 表id
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
@@ -123,11 +176,17 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
|
|
|
/**
|
|
|
* 删除业务字段对象
|
|
|
+ *
|
|
|
* @param ids 字段id
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public int deleteGenTableColumnByColumnIds(String ids) {
|
|
|
+ Long[] longs = Convert.toLongArray(ids);
|
|
|
+ for (Long aLong : longs) {
|
|
|
+ GenTableColumn genTableColumn = genTableColumnMapper.selectGenTableColumnByColumnId(aLong);
|
|
|
+ insertCreateLog(genTableColumn,BusinessType.DELETE);
|
|
|
+ }
|
|
|
return genTableColumnMapper.deleteGenTableColumnByColumnIds(Convert.toLongArray(ids));
|
|
|
}
|
|
|
|
|
@@ -140,7 +199,7 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
|
@Override
|
|
|
public String checkColumnNameUnique(GenTableColumn genTableColumn) {
|
|
|
Long columnId = StringUtils.isNull(genTableColumn.getColumnId()) ? -1L : genTableColumn.getColumnId();
|
|
|
- GenTableColumn column = genTableColumnMapper.checkColumnNameUnique(genTableColumn.getColumnName());
|
|
|
+ GenTableColumn column = genTableColumnMapper.checkColumnNameUnique(genTableColumn);
|
|
|
if (StringUtils.isNotNull(column) && !column.getColumnId().equals(columnId)) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|