| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | import java.io.StringWriter; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | |
| | | Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); |
| | | |
| | | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | if (StringUtils.isEmpty(dbTableColumns)) { |
| | | if (CollUtil.isEmpty(dbTableColumns)) { |
| | | throw new ServiceException("同步数据失败,原表结构不存在"); |
| | | } |
| | | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | |
| | | GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); |
| | | column.setColumnId(prevColumn.getColumnId()); |
| | | if (column.isList()) { |
| | | // 如果是列表,继续保留字典类型 |
| | | // 如果是列表,继续保留查询方式/字典类型选项 |
| | | column.setDictType(prevColumn.getDictType()); |
| | | column.setQueryType(prevColumn.getQueryType()); |
| | | } |
| | | genTableColumnMapper.updateGenTableColumn(column); |
| | | if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() |
| | | && (column.isInsert() || column.isEdit()) |
| | | && ((column.isUsableColumn()) || (!column.isSuperColumn()))) |
| | | { |
| | | // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 |
| | | column.setIsRequired(prevColumn.getIsRequired()); |
| | | column.setHtmlType(prevColumn.getHtmlType()); |
| | | } |
| | | genTableColumnMapper.updateById(column); |
| | | } else { |
| | | genTableColumnMapper.insertGenTableColumn(column); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | }); |
| | | if (CollUtil.isNotEmpty(saveColumns)) { |
| | |
| | | public void validateEdit(GenTable genTable) { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { |
| | | Map<String, Object> paramsObj = genTable.getParams(); |
| | | if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { |
| | | if (ObjectUtil.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { |
| | | throw new ServiceException("树编码字段不能为空"); |
| | | } else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) { |
| | | } else if (ObjectUtil.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) { |
| | | throw new ServiceException("树父编码字段不能为空"); |
| | | } else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) { |
| | | } else if (ObjectUtil.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) { |
| | | throw new ServiceException("树名称字段不能为空"); |
| | | } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { |
| | | if (StringUtils.isEmpty(genTable.getSubTableName())) { |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getPkColumn())) { |
| | | if (ObjectUtil.isNull(table.getPkColumn())) { |
| | | table.setPkColumn(table.getColumns().get(0)); |
| | | } |
| | | if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { |
| | |
| | | break; |
| | | } |
| | | } |
| | | if (StringUtils.isNull(table.getSubTable().getPkColumn())) { |
| | | if (ObjectUtil.isNull(table.getSubTable().getPkColumn())) { |
| | | table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); |
| | | } |
| | | } |
| | |
| | | */ |
| | | public void setTableFromOptions(GenTable genTable) { |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions()); |
| | | if (StringUtils.isNotNull(paramsObj)) { |
| | | if (ObjectUtil.isNotNull(paramsObj)) { |
| | | String treeCode = Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)); |
| | | String treeParentCode = Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)); |
| | | String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); |