private static string GetContent(HotchnerTable table) { var entityName = Backend_Devices.GetEntityName(table); var serviceClassName = Backend_Devices.GetServiceInterfaceClassName(table); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("package " + Backend_Devices.DeviceServiceInterfacePackagePrefix + ";"); stringBuilder.AppendLine(); stringBuilder.AppendLine($"import {Backend_Code.GetPagingParameterEntity()};"); stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.{entityName};"); stringBuilder.AppendLine(); stringBuilder.AppendLine("import java.util.List;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("public interface " + serviceClassName + " {"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetCreateMethodName(table)}(List<{entityName}> infoList);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetDeleteByIdMethodName(table)}(long id);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetUpdateMethodName(table)}({entityName} info);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" {entityName} {Backend_Devices.GetByIdMethodName(table)}(long id);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" List<{entityName}> {Backend_Devices.GetAllMethodName(table)}(PagingParameter parameter);"); stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }
private static string GetContent(HotchnerTable table) { var daoClassName = Backend_Devices.GetDaoClassName(table); var entityName = Backend_Devices.GetEntityName(table); var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("package " + Backend_Devices.DaoPackagePrefix + ";"); stringBuilder.AppendLine(); stringBuilder.AppendLine($"import {Backend_Code.GetPagingParameterEntity()};"); stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.{entityName};"); stringBuilder.AppendLine("import org.apache.ibatis.annotations.Param;"); stringBuilder.AppendLine("import org.springframework.stereotype.Repository;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("import java.util.List;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("@Repository"); stringBuilder.AppendLine("public interface " + daoClassName + " {"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetCreateMethodName(table)}(@Param(\"infoList\")List<{entityName}> infoList);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetDeleteByIdMethodName(table)}(@Param(\"id\") long id);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" int {Backend_Devices.GetUpdateMethodName(table)}(@Param(\"info\") {entityName} info);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" {entityName} {Backend_Devices.GetByIdMethodName(table)}(@Param(\"id\") long id);"); stringBuilder.AppendLine(); stringBuilder.AppendLine($" List<{entityName}> {Backend_Devices.GetAllMethodName(table)}(@Param(\"parameter\")PagingParameter parameter);"); stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }
internal static void Generate(string folderPath, List <HotchnerTable> tableList) { foreach (var table in tableList) { var content = GetContent(table); var filePath = folderPath + $"{Backend_Devices.GetServiceInterfaceClassName(table)}.java"; File.WriteAllText(filePath, content, new UTF8Encoding(false)); } }
private static void GenerateEntity(string entityFolderPath, HotchnerTable table) { var entityName = Backend_Devices.GetEntityName(table); StringBuilder entityBuilder = new StringBuilder(); entityBuilder.AppendLine("package " + Backend_Devices.EntityPackagePrefix + ";"); entityBuilder.AppendLine(""); entityBuilder.AppendLine("import java.sql.Timestamp;"); entityBuilder.AppendLine("import java.util.Date;"); entityBuilder.AppendLine(""); entityBuilder.AppendLine($"public class {entityName} " + "{"); foreach (var row in table.RowList) { entityBuilder.AppendLine($" // {row.Description}"); entityBuilder.AppendLine($" private {RowTypeJavaDict[row.RowType]} {row.Name.ToLower()};"); } entityBuilder.AppendLine(""); foreach (var row in table.RowList) { string javeType = RowTypeJavaDict[row.RowType]; string firstUpOtherLow = CommonMethod.GetFirstUpAndOtherLowString(row.Name); string nameLower = row.Name.ToLower(); entityBuilder.AppendLine($" public {javeType} get{firstUpOtherLow}() " + "{"); entityBuilder.AppendLine($" return {row.Name.ToLower()};"); entityBuilder.AppendLine(" }"); entityBuilder.AppendLine(""); entityBuilder.AppendLine($" public void set{firstUpOtherLow}({javeType} {nameLower}) " + "{"); entityBuilder.AppendLine($" this.{nameLower} = {nameLower};"); entityBuilder.AppendLine(" }"); entityBuilder.AppendLine(""); } entityBuilder.AppendLine("}"); var content = entityBuilder.ToString(); var filePath = entityFolderPath + $"\\{entityName}.java"; File.WriteAllText(filePath, content, new UTF8Encoding(false)); }
static void Main(string[] args) { PreproccessFolder(); var allTableList = ReadAllTables(); SqlScript.GenerateSqlScript("CreateDeviceSql", allTableList); ImportTemplate.GenerateTemplate(allTableList); Backend_Devices.GenerateCode(allTableList); Frontend_Devices.GenerateCode(allTableList); Backend_Retrieval.GenerateCode(allTableList); Frontend_Retrieval.GenerateCode(allTableList); Backend_Anchors.GenerateCode(allTableList); Frontend_Anchors.GenerateCode(allTableList); Backend_Statistic.GenerateCode(allTableList); Frontend_Statistic.GenerateCode(allTableList); Frontend_Api_Url.GenerateCode(allTableList); }
public static void GenerateCode(List <HotchnerTable> tableList) { var apiFolder = Frontend_Code.FrontendOutputPath; if (Program.IsOutputToProject) { apiFolder = @"C:\0_Workspace\ict\src\app\common\"; } StringBuilder stringBuilder = new StringBuilder(); #region Base URL stringBuilder.AppendLine("import {HTTP_REST_BASE_URL} from './ip-config';"); stringBuilder.AppendLine(""); stringBuilder.AppendLine("export class API {"); stringBuilder.AppendLine(" // 3D Base Url"); stringBuilder.AppendLine(" public static USBD_3D_BASE_URL = 'http://192.168.3.213:8090/iserver/services/';"); stringBuilder.AppendLine(" // 高程"); stringBuilder.AppendLine(" public static UAVS_3D_WORLD_CHINA_ZJDEM = API.USBD_3D_BASE_URL + '3D-worldscene/rest/realspace/datas/worldchinazjdem';"); stringBuilder.AppendLine(" // 地图影像"); stringBuilder.AppendLine(" public static UAVS_3D_YING_XIANG = API.USBD_3D_BASE_URL + 'map-worldscene/rest/maps/worldyingxiang0018web%40worldyingxiang0018web';"); stringBuilder.AppendLine(" // 三维场景"); stringBuilder.AppendLine(" public static UAVS_3D_SCENE = API.USBD_3D_BASE_URL + '3D-worldscene/rest/realspace';"); stringBuilder.AppendLine(" // 所有点坐标"); stringBuilder.AppendLine($" public static {Frontend_Anchors.Get_AnchorsByType_Url} = HTTP_REST_BASE_URL + " + $"'/device/{Backend_Anchors.GetAnchorsByDeviceType_MethodName}';"); stringBuilder.AppendLine(" // 检索设备信息"); stringBuilder.AppendLine($" public static {Frontend_Retrieval.Get_RetrievalAll_Url} = HTTP_REST_BASE_URL + " + $"'/device/{Backend_Retrieval.GetRetrievalAllMethodName}';"); stringBuilder.AppendLine(" // 检索设备详细信息"); stringBuilder.AppendLine($" public static {Frontend_Retrieval.Get_RetrievalDetail_Url} = HTTP_REST_BASE_URL + " + $"'/device/{Backend_Retrieval.GetRetrievalDetailMethodName}';"); stringBuilder.AppendLine(" // 获取设备统计信息"); stringBuilder.AppendLine($" public static STATISTICAL_DEVICE = HTTP_REST_BASE_URL + " + $"'/device/{Backend_Statistic.GetAllStatisticResult_MethodName}';"); stringBuilder.AppendLine(""); #endregion #region CURD URL foreach (var table in tableList) { stringBuilder.AppendLine(" /**"); stringBuilder.AppendLine(" * " + table.TableDescription + "API"); stringBuilder.AppendLine(" */"); stringBuilder.AppendLine(" // " + table.TableDescription + "导入"); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_Upload_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetImportMethodName(table)}';"); stringBuilder.AppendLine(" // " + table.TableDescription + "导入确认"); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_Upload_Confirm_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetImportConfirmMethodName(table)}';"); stringBuilder.AppendLine(" // 增加" + table.TableDescription); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_Add_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetCreateMethodName(table)}';"); stringBuilder.AppendLine(" // 修改" + table.TableDescription); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_Update_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetUpdateMethodName(table)}';"); stringBuilder.AppendLine(" // 修改" + table.TableDescription); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_Delete_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetDeleteByIdMethodName(table)}';"); stringBuilder.AppendLine(" // 查询全部" + table.TableDescription); stringBuilder.AppendLine($" public static {Frontend_Devices.Get_FIND_ALL_Url(table)} = HTTP_REST_BASE_URL + '/device/{Backend_Devices.GetAllMethodName(table)}';"); stringBuilder.AppendLine(""); } #endregion stringBuilder.AppendLine("}"); var apiTsFilePath = apiFolder + "api.ts"; var apiTsContent = stringBuilder.ToString(); File.WriteAllText(apiTsFilePath, apiTsContent, new UTF8Encoding(false)); }
private static string GetContent(List <HotchnerTable> tableList) { StringBuilder stringBuilder = new StringBuilder(); var filedName = $"{Backend_Retrieval.FieldPrefix}Service"; stringBuilder.AppendLine("package " + Backend_Retrieval.ControllerPackagePrefix + ";"); stringBuilder.AppendLine(); #region Impport stringBuilder.AppendLine("import com.alibaba.fastjson.JSON;"); stringBuilder.AppendLine("import com.alibaba.fastjson.JSONObject;"); stringBuilder.AppendLine("import com.infinite.common.base.BaseController;"); stringBuilder.AppendLine("import com.infinite.common.base.ResponseBase;"); stringBuilder.AppendLine($"import {Backend_Retrieval.EntityPackagePrefix}.{Entity.RetrievalParameterClass};"); stringBuilder.AppendLine($"import {Backend_Retrieval.EntityPackagePrefix}.{Entity.RetrievalResultClass};"); stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.*;"); stringBuilder.AppendLine($"import {Backend_Retrieval.ServiceInterfacePackagePrefix}.{Backend_Retrieval.ServicesName};"); stringBuilder.AppendLine($"import {Backend_Devices.DeviceServiceInterfacePackagePrefix}.*;"); stringBuilder.AppendLine("import org.springframework.beans.factory.annotation.Autowired;"); stringBuilder.AppendLine("import org.springframework.web.bind.annotation.RequestBody;"); stringBuilder.AppendLine("import org.springframework.web.bind.annotation.RequestMapping;"); stringBuilder.AppendLine("import org.springframework.web.bind.annotation.RequestMethod;"); stringBuilder.AppendLine("import org.springframework.web.bind.annotation.RestController;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("import java.util.List;"); #endregion stringBuilder.AppendLine(); stringBuilder.AppendLine("@RestController"); stringBuilder.AppendLine("@RequestMapping(\"/device\")"); stringBuilder.AppendLine($"public class {Backend_Retrieval.ControllerName} extends BaseController " + "{"); stringBuilder.AppendLine(); #region field stringBuilder.AppendLine(" @Autowired"); stringBuilder.AppendLine($" private {Backend_Retrieval.ServicesName} {filedName};"); stringBuilder.AppendLine(); foreach (var table in tableList) { var deviceServiceFieldName = GetDeviceServiceFieldName(table); var deviceServiceInterfaceClassName = Backend_Devices.GetServiceInterfaceClassName(table); stringBuilder.AppendLine(" @Autowired"); stringBuilder.AppendLine(" private " + deviceServiceInterfaceClassName + " " + deviceServiceFieldName + ";"); } stringBuilder.AppendLine(); #endregion #region GetListMethodName stringBuilder.AppendLine($" @RequestMapping(value = \"/{Backend_Retrieval.GetRetrievalAllMethodName}\", method = RequestMethod.POST)"); stringBuilder.AppendLine($" public ResponseBase {Backend_Retrieval.GetRetrievalAllMethodName}(@RequestBody String params) " + "{"); stringBuilder.AppendLine(" try {"); stringBuilder.AppendLine(" String keyword = JSON.parseObject(params).getString(\"keyword\");"); #warning 这里应该直接解析参数对象 stringBuilder.AppendLine($" {Entity.RetrievalParameterClass} parameter = new {Entity.RetrievalParameterClass}();"); stringBuilder.AppendLine(" parameter.setKeyword(keyword);"); stringBuilder.AppendLine($" List<{Entity.RetrievalResultClass}> infoList = {filedName}.{Backend_Retrieval.GetRetrievalAllMethodName}(parameter);"); stringBuilder.AppendLine(" if (infoList == null || infoList.size() <= 0) {"); stringBuilder.AppendLine(" return setResultError(\"查询无数据\");"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" return setResultSuccess(infoList);"); stringBuilder.AppendLine(" } catch (Exception e) {"); stringBuilder.AppendLine(" return setResultError(\"服务器错误\");"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" }"); #endregion #region GetDetail stringBuilder.AppendLine(""); stringBuilder.AppendLine($" @RequestMapping(value = \"/{Backend_Retrieval.GetRetrievalDetailMethodName}\", method = RequestMethod.POST)"); stringBuilder.AppendLine($" public ResponseBase {Backend_Retrieval.GetRetrievalDetailMethodName}(@RequestBody String params) " + "{"); stringBuilder.AppendLine(" try {"); #warning 这里应该直接解析参数对象 stringBuilder.AppendLine(" JSONObject parameter = JSON.parseObject(params);"); stringBuilder.AppendLine(" int id = parameter.getIntValue(\"id\");"); stringBuilder.AppendLine(" String deviceType = parameter.getString(\"deviceType\");"); var index = 0; foreach (var table in tableList) { var deviceType = table.PascalMethodName; var deviceEntityName = Backend_Devices.GetEntityName(table); var deviceServiceFieldName = GetDeviceServiceFieldName(table); var deviceGetByIdMethodName = Backend_Devices.GetByIdMethodName(table);; if (index == 0) { stringBuilder.AppendLine(" if (deviceType.equals(\"" + deviceType + "\")) {"); } else { stringBuilder.AppendLine(" } else if (deviceType.equals(\"" + deviceType + "\")) {"); } stringBuilder.AppendLine($" {deviceEntityName} info = {deviceServiceFieldName}.{deviceGetByIdMethodName}(id);"); stringBuilder.AppendLine(" return setResultSuccess(info);"); index = 1; } stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" return setResultSuccess(\"无匹配数据\");"); stringBuilder.AppendLine(" } catch (Exception e) {"); stringBuilder.AppendLine(" return setResultError(\"服务器错误\");"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine("}"); #endregion return(stringBuilder.ToString()); }
private static string GetContent(HotchnerTable table) { var daoFieldName = table.camelcaseMethodName + "Dao"; var entityName = Backend_Devices.GetEntityName(table); var daoClassName = Backend_Devices.GetDaoClassName(table); var serviceImplClassName = Backend_Devices.GetServiceImplClassName(table); var serviceInterfaceClassName = Backend_Devices.GetServiceInterfaceClassName(table); StringBuilder stringBuilder = new StringBuilder(); #region import stringBuilder.AppendLine("package " + Backend_Devices.ServiceImplPackagePrefix + ";"); stringBuilder.AppendLine(); stringBuilder.AppendLine($"import {Backend_Code.GetPagingParameterEntity()};"); stringBuilder.AppendLine($"import {Backend_Devices.DaoPackagePrefix}.{daoClassName};"); stringBuilder.AppendLine($"import {Backend_Devices.EntityPackagePrefix}.{entityName};"); stringBuilder.AppendLine($"import {Backend_Devices.DeviceServiceInterfacePackagePrefix}.{serviceInterfaceClassName};"); stringBuilder.AppendLine("import org.springframework.beans.factory.annotation.Autowired;"); stringBuilder.AppendLine("import org.springframework.stereotype.Service;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("import java.util.List;"); stringBuilder.AppendLine(); stringBuilder.AppendLine("@Service"); stringBuilder.AppendLine("public class " + serviceImplClassName + " implements " + serviceInterfaceClassName + " {"); stringBuilder.AppendLine(); stringBuilder.AppendLine(" @Autowired"); stringBuilder.AppendLine($" private {daoClassName} {daoFieldName};"); stringBuilder.AppendLine(); #endregion #region Implement stringBuilder.AppendLine(" @Override"); stringBuilder.AppendLine($" public int {Backend_Devices.GetCreateMethodName(table)}(List<{entityName}> infoList) " + "{"); stringBuilder.AppendLine($" return {daoFieldName}.{Backend_Devices.GetCreateMethodName(table)}(infoList);"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" @Override"); stringBuilder.AppendLine($" public int {Backend_Devices.GetDeleteByIdMethodName(table)}(long id)" + " {"); stringBuilder.AppendLine($" return {daoFieldName}.{Backend_Devices.GetDeleteByIdMethodName(table)}(id);"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" @Override"); stringBuilder.AppendLine($" public int {Backend_Devices.GetUpdateMethodName(table)}({entityName} info)" + " {"); stringBuilder.AppendLine($" return {daoFieldName}.{Backend_Devices.GetUpdateMethodName(table)}(info);"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" @Override"); stringBuilder.AppendLine($" public {entityName} {Backend_Devices.GetByIdMethodName(table)}(long id)" + " {"); stringBuilder.AppendLine($" return {daoFieldName}.{Backend_Devices.GetByIdMethodName(table)}(id);"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" @Override"); stringBuilder.AppendLine($" public List<{entityName}> {Backend_Devices.GetAllMethodName(table)}(PagingParameter parameter)" + " {"); stringBuilder.AppendLine($" return {daoFieldName}.{Backend_Devices.GetAllMethodName(table)}(parameter);"); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(""); #endregion stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }
private static string GetContent(HotchnerTable table) { var dbTableName = table.DbTableName; var entityName = Backend_Devices.GetEntityName(table); var daoClassName = Backend_Devices.GetDaoClassName(table); StringBuilder outterBuilder = new StringBuilder(); outterBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF" + "-" + "8\" ?>"); outterBuilder.AppendLine("<!DOCTYPE mapper PUBLIC \" -//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >"); outterBuilder.AppendLine(); outterBuilder.AppendLine("<mapper namespace=\"" + Backend_Devices.DaoPackagePrefix + "." + daoClassName + "\">"); var innerBuilder = new StringBuilder(); #region insert outterBuilder.AppendLine($" <insert id=\"{Backend_Devices.GetCreateMethodName(table)}\">"); outterBuilder.AppendLine($" INSERT INTO public.{dbTableName}("); innerBuilder.Append(" "); foreach (var row in table.RowList) { var fieldName = row.Name.ToLower(); if (fieldName == "id") { continue; } innerBuilder.Append($"{fieldName}, "); } innerBuilder.Remove(innerBuilder.Length - 2, 2); // 删除最后一个逗号 innerBuilder.Append(")"); outterBuilder.AppendLine(innerBuilder.ToString()); outterBuilder.AppendLine(" VALUES "); outterBuilder.AppendLine(" <foreach collection=\"infoList\" item=\"info\" index=\"currentIndex\" separator=\",\">"); innerBuilder.Clear(); innerBuilder.Append(" ("); foreach (var row in table.RowList) { var fieldName = row.Name.ToLower(); if (fieldName == "id") { continue; } innerBuilder.Append("#{info." + fieldName + "}, "); } innerBuilder.Remove(innerBuilder.Length - 2, 2); // 删除最后一个逗号 innerBuilder.Append(")"); outterBuilder.AppendLine(innerBuilder.ToString()); outterBuilder.AppendLine(" </foreach>"); outterBuilder.AppendLine(" </insert>"); #endregion #region delete 逻辑删除 outterBuilder.AppendLine($" <update id=\"{Backend_Devices.GetDeleteByIdMethodName(table)}\">"); outterBuilder.AppendLine($" UPDATE public.{dbTableName} set available = 0"); outterBuilder.AppendLine(" WHERE id=#{id}"); outterBuilder.AppendLine(" </update>"); #endregion #region update innerBuilder.Clear(); outterBuilder.AppendLine($" <update id=\"{Backend_Devices.GetUpdateMethodName(table)}\">"); outterBuilder.AppendLine($" UPDATE public.{dbTableName}"); innerBuilder.Append(" SET "); foreach (var row in table.RowList) { var fieldName = row.Name.ToLower(); if (fieldName == "id") { continue; } innerBuilder.Append(fieldName + "=#{info." + fieldName + "}, "); } innerBuilder.Remove(innerBuilder.Length - 2, 2); // 删除最后一个逗号 outterBuilder.AppendLine(innerBuilder.ToString()); outterBuilder.AppendLine(" WHERE id=#{info.id}"); outterBuilder.AppendLine(" </update>"); #endregion #region select outterBuilder.AppendLine($" <select id=\"{Backend_Devices.GetByIdMethodName(table)}\" resultType=\"{Backend_Devices.EntityPackagePrefix}.{entityName}\">"); outterBuilder.AppendLine($" SELECT * FROM public.{dbTableName}"); outterBuilder.AppendLine(" WHERE id=#{id} and available = 1"); outterBuilder.AppendLine(" </select>"); outterBuilder.AppendLine($" <select id=\"{Backend_Devices.GetAllMethodName(table)}\" resultType=\"{Backend_Devices.EntityPackagePrefix}.{entityName}\">"); outterBuilder.AppendLine($" SELECT * FROM public.{dbTableName} where available = 1"); outterBuilder.AppendLine(" </select>"); #endregion outterBuilder.AppendLine("</mapper>"); return(outterBuilder.ToString()); }