|
@@ -8,6 +8,14 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.boman.common.core.constant.Constants;
|
|
|
+import com.boman.common.core.utils.DateUtils;
|
|
|
+import com.boman.common.core.web.domain.AjaxResult;
|
|
|
+import com.boman.gen.domain.GenTable;
|
|
|
+import com.boman.gen.domain.GenTableColumn;
|
|
|
+import com.boman.gen.mapper.GenTableColumnMapper;
|
|
|
+import com.boman.gen.mapper.GenTableMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.boman.common.core.constant.UserConstants;
|
|
@@ -43,6 +51,12 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
@Autowired
|
|
|
private SysRoleMenuMapper roleMenuMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GenTableColumnMapper genTableColumnMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GenTableMapper genTableMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 根据用户查询系统菜单列表
|
|
|
*
|
|
@@ -462,4 +476,86 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
{
|
|
|
return getChildList(list, t).size() > 0 ? true : false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代码生成业务表新增
|
|
|
+ * 注意解决事务问题
|
|
|
+ *
|
|
|
+ * @param genTable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult insertGenTable(GenTable genTable) {
|
|
|
+ //判断是否是菜单
|
|
|
+ isMenu(genTable);
|
|
|
+ //新增表成功的时候,新增字段公共字段
|
|
|
+ int i = genTableMapper.insertGenTable(genTable);
|
|
|
+ if (i > 0) {
|
|
|
+ insertCommonColumn(genTable.getTableId());
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+ return AjaxResult.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新建表时新增对应公共字段
|
|
|
+ *
|
|
|
+ * @param tableId
|
|
|
+ */
|
|
|
+ public void insertCommonColumn(Long tableId) {
|
|
|
+
|
|
|
+ String[] columnName = new String[]{"create_by", "create_time", "update_by", "update_time", "is_del"};
|
|
|
+ String[] columnComment = new String[]{"创建者", "创建时间", "更新者", "更新时间", "是否删除"};
|
|
|
+ String[] columnType = new String[]{"varchar(64)", "datetime", "varchar(64)", "datetime", "char(1)"};
|
|
|
+ String[] htmlType = new String[]{"input", "datetime", "input", "datetime", "input"};
|
|
|
+ for (int i = 0; i < columnName.length; i++) {
|
|
|
+ GenTableColumn genTableColumn = new GenTableColumn();
|
|
|
+ genTableColumn.setTableId(tableId);
|
|
|
+ genTableColumn.setColumnName(columnName[i]);
|
|
|
+ genTableColumn.setColumnComment(columnComment[i]);
|
|
|
+ genTableColumn.setColumnType(columnType[i]);
|
|
|
+ genTableColumn.setIsPk("0");
|
|
|
+ genTableColumn.setIsIncrement("0");
|
|
|
+ genTableColumn.setIsInsert("1");
|
|
|
+ genTableColumn.setQueryType("EQ");
|
|
|
+ genTableColumn.setHtmlType(htmlType[i]);
|
|
|
+ genTableColumn.setSort(i + 1);
|
|
|
+ genTableColumn.setCreateBy("admin");
|
|
|
+ genTableColumn.setCreateTime(DateUtils.getNowDate());
|
|
|
+ genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否是菜单
|
|
|
+ public void isMenu(GenTable genTable) {
|
|
|
+ String isMenu = genTable.getIsMenu();
|
|
|
+ if (StringUtils.isNotBlank(isMenu) && isMenu.equals(UserConstants.NOT_UNIQUE)) {
|
|
|
+ //先生成主菜单
|
|
|
+ SysMenu sysMenu = new SysMenu();
|
|
|
+ //表描述当菜单名称
|
|
|
+ sysMenu.setMenuName(genTable.getTableComment());
|
|
|
+ sysMenu.setParentId(0L);
|
|
|
+ sysMenu.setOrderNum("1");
|
|
|
+ //路由地址
|
|
|
+ sysMenu.setPath(genTable.getBusinessName());
|
|
|
+ sysMenu.setComponent(genTable.getModuleName() + "/" + genTable.getTableComment() + "/index");
|
|
|
+ sysMenu.setMenuType("C");
|
|
|
+ sysMenu.setIcon("system");
|
|
|
+ sysMenu.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ menuMapper.insertMenu(sysMenu);
|
|
|
+ //是菜单,生成crud按钮
|
|
|
+ for (int i = 0; i < Constants.MENU_NAME.length; i++) {
|
|
|
+ String[] menuName = Constants.MENU_NAME;
|
|
|
+ SysMenu menu = new SysMenu();
|
|
|
+ menu.setParentId(sysMenu.getId());
|
|
|
+ menu.setMenuName(menuName[i]);
|
|
|
+ menu.setOrderNum(String.valueOf(i+1));
|
|
|
+ menu.setMenuType("F");
|
|
|
+ menu.setIcon("#");
|
|
|
+ sysMenu.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ menuMapper.insertMenu(menu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|