| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService { |
| | | public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTable, GenTable> implements IGenTableService { |
| | | |
| | | @Autowired |
| | | private GenTableColumnMapper genTableColumnMapper; |
| | |
| | | for (GenTableColumn cenTableColumn : genTable.getColumns()) { |
| | | genTableColumnMapper.update(cenTableColumn, |
| | | new LambdaUpdateWrapper<GenTableColumn>() |
| | | .set(cenTableColumn.getIsPk() == null, GenTableColumn::getIsPk, null) |
| | | .set(cenTableColumn.getIsIncrement() == null, GenTableColumn::getIsIncrement, null) |
| | | .set(cenTableColumn.getIsInsert() == null, GenTableColumn::getIsInsert, null) |
| | | .set(cenTableColumn.getIsEdit() == null, GenTableColumn::getIsEdit, null) |
| | | .set(cenTableColumn.getIsList() == null, GenTableColumn::getIsList, null) |
| | | .set(cenTableColumn.getIsQuery() == null, GenTableColumn::getIsQuery, null) |
| | | .set(cenTableColumn.getIsRequired() == null, GenTableColumn::getIsRequired, null) |
| | | .eq(GenTableColumn::getColumnId,cenTableColumn.getColumnId())); |
| | | .set(StringUtils.isBlank(cenTableColumn.getColumnComment()), GenTableColumn::getColumnComment, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsPk()), GenTableColumn::getIsPk, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsIncrement()), GenTableColumn::getIsIncrement, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsInsert()), GenTableColumn::getIsInsert, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsEdit()), GenTableColumn::getIsEdit, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsList()), GenTableColumn::getIsList, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsQuery()), GenTableColumn::getIsQuery, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getIsRequired()), GenTableColumn::getIsRequired, null) |
| | | .set(StringUtils.isBlank(cenTableColumn.getDictType()), GenTableColumn::getDictType, "") |
| | | .eq(GenTableColumn::getColumnId,cenTableColumn.getColumnId())); |
| | | } |
| | | } |
| | | } |
| | |
| | | List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | for (GenTableColumn column : genTableColumns) { |
| | | GenUtils.initColumnField(column, table); |
| | | genTableColumnMapper.insert(column); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new CustomException("导入失败:" + e.getMessage()); |
| | |
| | | // 获取模板列表 |
| | | List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); |
| | | for (String template : templates) { |
| | | if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { |
| | | if (!StringUtils.containsAny("sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm", template)) { |
| | | // 渲染模板 |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | |
| | | dbTableColumns.forEach(column -> { |
| | | if (!tableColumnNames.contains(column.getColumnName())) { |
| | | GenUtils.initColumnField(column, table); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | }); |
| | | genTableColumnMapper.insert(column); |
| | | } |
| | | }); |
| | | |
| | | List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(delColumns)) { |
| | |
| | | */ |
| | | public static String getGenPath(GenTable table, String template) { |
| | | String genPath = table.getGenPath(); |
| | | if (StrUtil.equals(genPath, "/")) { |
| | | if (StringUtils.equals(genPath, "/")) { |
| | | return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); |
| | | } |
| | | return genPath + File.separator + VelocityUtils.getFileName(template, table); |