| | |
| | | public String username; |
| | | public String password; |
| | | public String table; |
| | | public String tableName; |
| | | public String packagePath; |
| | | public boolean controller = true; |
| | | public boolean service = true; |
| | |
| | | private String systemPackage; |
| | | private String itemName; |
| | | private String tableColumns; |
| | | private String formEditColumns; |
| | | |
| | | public void build() throws Exception { |
| | | init(); |
| | |
| | | } |
| | | itemName = packagePathSplit[packagePathSplit.length - 1]; |
| | | tableColumns = createTableColumns(); |
| | | formEditColumns = createFormEditColumns(); |
| | | } |
| | | |
| | | private String readFile(String template){ |
| | |
| | | if(!writerFile.exists()){ |
| | | content=content. |
| | | replaceAll("@\\{TABLENAME}", table) |
| | | .replaceAll("@\\{TABLEDESC}", tableName) |
| | | .replaceAll("@\\{ENTITYIMPORT}", entityImport) |
| | | .replaceAll("@\\{ENTITYCONTENT}", entityContent) |
| | | .replaceAll("@\\{ENTITYNAME}", fullEntityName) |
| | |
| | | .replaceAll("@\\{UPCASEMARJORCOLUMN}", GeneratorUtils.firstCharConvert(primaryKeyColumn, false)) |
| | | .replaceAll("@\\{SYSTEMPACKAGE}",systemPackage) |
| | | .replaceAll("@\\{TABLECOLUMNS}", tableColumns) |
| | | .replaceAll("@\\{FORMEDITCOLUMNS}", formEditColumns) |
| | | ; |
| | | writerFile.createNewFile(); |
| | | BufferedWriter writer=new BufferedWriter(new FileWriter(writerFile)); |
| | |
| | | private void gainDbInfo() throws Exception { |
| | | Connection conn; |
| | | if (null == this.sqlOsType) { |
| | | throw new RuntimeException("请指定数据库类型!"); |
| | | throw new RuntimeException("请选择sqlOsType!"); |
| | | } |
| | | if (null == this.table) { |
| | | throw new RuntimeException("请输入table!"); |
| | | } |
| | | if (null == this.tableName) { |
| | | throw new RuntimeException("请输入tableName!"); |
| | | } |
| | | switch (this.sqlOsType) { |
| | | case MYSQL: |
| | |
| | | sb.append(column.getHumpName()); |
| | | } |
| | | sb.append("',\n") |
| | | .append(" valueType: 'text',\n"); |
| | | .append(" valueType: 'text',\n") |
| | | .append(" hidden: false,\n") |
| | | .append(" width: 140,\n"); |
| | | if (column.isMajor()) { |
| | | sb.append(" copyable: true,\n"); |
| | | } |
| | | sb.append(" filterDropdown: (props) => <").append(getAntProFilterType(column)).append("\n") |
| | | .append(" name='").append(column.getHumpName()).append("'\n") |
| | | .append(" {...props}\n") |
| | | .append(" name='").append(column.getHumpName()).append("'\n"); |
| | | |
| | | if (!Cools.isEmpty(column.getForeignKey())) { |
| | | sb.append(" major='").append(GeneratorUtils.firstCharConvert(column.getForeignKey())).append("'\n"); |
| | | } |
| | | |
| | | sb.append(" {...props}\n") |
| | | .append(" actionRef={actionRef}\n") |
| | | .append(" setSearchParam={setSearchParam}\n"); |
| | | if (!Cools.isEmpty(column.getEnums())) { |
| | |
| | | /************************************** Edit动态字段 ********************************************/ |
| | | /**********************************************************************************************/ |
| | | |
| | | private String createFormEditColumns() { |
| | | StringBuilder sb = new StringBuilder(); |
| | | int times = 0; |
| | | boolean has = false;boolean init = false; |
| | | for (Column column : columns) { |
| | | if (column.isPrimaryKey() |
| | | || column.getHumpName().equals("deleted") |
| | | || column.getHumpName().equals("hostId") |
| | | ) { |
| | | continue; |
| | | } |
| | | if (times%2 == 0) { |
| | | sb.append(" <ProForm.Group>\n"); |
| | | has = true;init=true; |
| | | } |
| | | |
| | | String itemType = "ProFormText"; |
| | | String precision = ""; |
| | | switch (column.getType()) { |
| | | case "Boolean": |
| | | itemType = "ProFormText"; |
| | | break; |
| | | case "Short": |
| | | itemType = "ProFormDigit"; |
| | | precision = "0"; |
| | | break; |
| | | case "Integer": |
| | | itemType = "ProFormDigit"; |
| | | precision = "0"; |
| | | break; |
| | | case "Long": |
| | | itemType = "ProFormDigit"; |
| | | precision = "0"; |
| | | break; |
| | | case "Double": |
| | | itemType = "ProFormDigit"; |
| | | precision = "2"; |
| | | break; |
| | | case "String": |
| | | itemType = "ProFormText"; |
| | | break; |
| | | case "Date": |
| | | itemType = "ProFormDateTimePicker"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (!Cools.isEmpty(column.getEnums())) { |
| | | itemType = "ProFormSelect"; |
| | | } |
| | | if (!Cools.isEmpty(column.getForeignKey())) { |
| | | itemType = "ProFormSelect"; |
| | | } |
| | | |
| | | sb.append(" <").append(itemType).append("\n") |
| | | .append(" name=\"").append(column.getHumpName()).append("\"\n") |
| | | .append(" label=\"").append(column.getComment()).append("\"\n") |
| | | .append(" colProps={{ md: 12, xl: 12 }}\n"); |
| | | // 数字小数点 |
| | | if (!Cools.isEmpty(precision) && Cools.isEmpty(column.getEnums())) { |
| | | sb.append(" fieldProps={{ precision: ").append(precision).append(" }}\n"); |
| | | } |
| | | |
| | | // 非空 |
| | | if (column.isNotNull()) { |
| | | sb.append(" rules={[{ required: true }]}\n"); |
| | | } |
| | | |
| | | // 枚举 |
| | | if (!Cools.isEmpty(column.getEnums())) { |
| | | sb.append(" options={[\n"); |
| | | for (Map<String, Object> map : column.getEnums()) { |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | sb.append(" { label: '").append(entry.getValue()).append("', value: ").append(entry.getKey()).append(" },\n"); |
| | | } |
| | | } |
| | | sb.append(" ]}\n"); |
| | | } |
| | | |
| | | // 时间 |
| | | if ("Date".equals(column.getType())) { |
| | | sb.append(" transform={(value) => moment(value).toISOString()}\n"); |
| | | } |
| | | |
| | | // 关联表 |
| | | if (!Cools.isEmpty(column.getForeignKey())) { |
| | | sb.append(" showSearch\n") |
| | | .append(" debounceTime={300}\n") |
| | | .append(" request={async ({ keyWords }) => {\n") |
| | | .append(" const resp = await Http.doPostForm('api/").append(GeneratorUtils.firstCharConvert(column.getForeignKey())).append("/query', { condition: keyWords });\n") |
| | | .append(" return resp.data;\n") |
| | | .append(" }}\n"); |
| | | } |
| | | |
| | | sb.append(" />\n"); |
| | | |
| | | if (times%2 != 0) { |
| | | sb.append(" </ProForm.Group>\n"); |
| | | has = false; |
| | | } |
| | | times++; |
| | | } |
| | | if (init && has) { |
| | | sb.append(" </ProForm.Group>\n"); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | } |