using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Http;
using System.Web.Http.Description;
using ESCG = CodeBuilderApi.GeneralMethod;
using ESCM = CodeBuilderApi.Model;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using HZQR.Common;
namespace CodeBuilderApi.Controllers
{
///
/// 代码生成表相关接口
/// 2022/10/18 11:36:31自动生成
///
public class CodeBuilderController : BaseController
{
#region 获取附件目录表列表
///
/// 获取附件目录表列表
///
/// 查询条件对象
///
[Route("CodeBuilder/GetCATALOGUEList")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg>))]
public IHttpActionResult GetCATALOGUEList(ESCM.SearchModel searchModel)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(searchModel);
try
{
int TotalCount = 0;
//获取附件目录表列表
List CATALOGUEList = ESCG.CATALOGUEHelper.GetCATALOGUEList(
transaction, ref TotalCount, searchModel);
//转化json形式
Models.JsonList jsonList = Models.JsonList.Success(
CATALOGUEList, TotalCount, searchModel.PageIndex, searchModel.PageSize);
return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetCATALOGUEList");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 获取附件目录表明细
///
/// 获取附件目录表明细
///
/// 附件目录表内码
///
[Route("CodeBuilder/GetCATALOGUEDetail")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult GetCATALOGUEDetail(int CATALOGUEId)
{
string Parameter = "入参信息:附件目录表内码【" + CATALOGUEId + "】";
try
{
//获取附件目录表明细
ESCM.CATALOGUEModel catalogueModel = ESCG.CATALOGUEHelper.GetCATALOGUEDetail(transaction, CATALOGUEId);
return Ok(Models.JsonMsg.Success(catalogueModel, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetCATALOGUEDetail");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 获取代码生成表列表
///
/// 获取代码生成表列表
///
/// 查询条件对象
///
[Route("Interface/GetCODEBUILDERList")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg>))]
public IHttpActionResult GetCODEBUILDERList(ESCM.SearchModel searchModel)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(searchModel);
try
{
int TotalCount = 0;
//获取代码生成表列表
List CODEBUILDERList = ESCG.CodeBuilderHelper.GetCODEBUILDERList(
transaction, ref TotalCount, searchModel);
//转化json形式
Models.JsonList jsonList = Models.JsonList.Success(
CODEBUILDERList, TotalCount, searchModel.PageIndex, searchModel.PageSize);
return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetCODEBUILDERList");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 获取代码生成表明细
///
/// 获取代码生成表明细
///
/// 代码生成表内码
///
[Route("Interface/GetCODEBUILDERDetail")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult GetCODEBUILDERDetail(int CODEBUILDERId)
{
string Parameter = "入参信息:代码生成表内码【" + CODEBUILDERId + "】";
try
{
//获取代码生成表明细
ESCM.CODEBUILDERModel codebuilderModel = ESCG.CodeBuilderHelper.GetCODEBUILDERDetail(transaction, CODEBUILDERId);
return Ok(Models.JsonMsg.Success(codebuilderModel, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetCODEBUILDERDetail");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 同步代码生成表
///
/// 同步代码生成表
///
///
///
[Route("Interface/SynchroCODEBUILDER")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult SynchroCODEBUILDER(ESCM.CODEBUILDERModel codebuilderModel)
{
try
{
//新增代码生成表
bool SynchroFlag = ESCG.CodeBuilderHelper.SynchroCODEBUILDER(transaction, codebuilderModel);
if (SynchroFlag)
{
return Ok(Method.Common.ReturnJson(100, "同步成功"));
}
else
{
return Ok(Method.Common.ReturnJson(200, "更新失败,数据不存在!"));
}
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "同步失败!失败原因:" + ex.Message,
DateTime.Now.ToString("yyyyMMdd") + "_SynchroCODEBUILDER");
return Ok(Method.Common.ReturnJson(999, "同步失败" + ex.Message));
}
}
#endregion
#region 删除代码生成表
///
/// 删除代码生成表
///
/// 代码生成表内码
///
[Route("Interface/DeleteCODEBUILDER")]
[AcceptVerbs("GET", "POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult DeleteCODEBUILDER(int CODEBUILDERId)
{
string Parameter = "入参信息:代码生成表内码【" + CODEBUILDERId + "】";
try
{
//删除代码生成表
bool DeleteFlag = ESCG.CodeBuilderHelper.DeleteCODEBUILDER(transaction, CODEBUILDERId);
if (DeleteFlag)
{
return Ok(Method.Common.ReturnJson(100, "删除成功"));
}
else
{
return Ok(Method.Common.ReturnJson(200, "删除失败,数据不存在!"));
}
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "删除失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_DeleteCODEBUILDER");
return Ok(Method.Common.ReturnJson(999, "删除失败" + ex.Message));
}
}
#endregion
#region 获取代码生成表嵌套列表
///
/// 获取代码生成表嵌套列表
///
/// 父级内码
/// 代码类型(1:接口;2:普通页面;3:小程序;4:报表页面)
/// 有效状态
/// 模糊查询内容
///
[Route("Interface/GetNestingCODEBUILDERList")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg>>))]
public IHttpActionResult GetNestingCODEBUILDERList(string CODEBUILDER_PID = "-1", string CODEBUILDER_FORMAT = null,
string CODEBUILDER_STATE = null, string SearchKey = null)
{
string Parameter = "入参信息:父级内码【" + CODEBUILDER_PID + "】, 代码类型【" + CODEBUILDER_FORMAT + "】," +
" 有效状态【" + CODEBUILDER_STATE + "】模糊查询内容【" + SearchKey + "】";
try
{
//获取代码生成表嵌套列表
List> CODEBUILDERList = ESCG.CodeBuilderHelper.GetNestingCODEBUILDERList(
transaction, CODEBUILDER_PID, CODEBUILDER_FORMAT, CODEBUILDER_STATE, SearchKey);
//转化json形式
Models.JsonList> jsonList =
Models.JsonList>.Success(CODEBUILDERList);
return Ok(Models.JsonMsg>>.Success(jsonList, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetNestingCODEBUILDERList");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 获取代码生成表嵌套树
///
/// 获取代码生成表嵌套树
///
/// 父级内码
/// 代码类型(1:接口;2:普通页面;3:小程序;4:报表页面)
/// 有效状态
/// 模糊查询内容
///
[Route("Interface/GetNestingCODEBUILDERTree")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg>>))]
public IHttpActionResult GetNestingCODEBUILDERTree(string CODEBUILDER_PID = "-1", string CODEBUILDER_FORMAT = null,
string CODEBUILDER_STATE = null, string SearchKey = null)
{
string Parameter = "入参信息:父级内码【" + CODEBUILDER_PID + "】, 代码类型【" + CODEBUILDER_FORMAT + "】," +
" 有效状态【" + CODEBUILDER_STATE + "】模糊查询内容【" + SearchKey + "】";
try
{
//获取代码生成表嵌套树
List> CODEBUILDERTree = ESCG.CodeBuilderHelper.GetNestingCODEBUILDERTree(
transaction, CODEBUILDER_PID, CODEBUILDER_FORMAT, CODEBUILDER_STATE, SearchKey);
//转化json形式
Models.JsonList> jsonList =
Models.JsonList>.Success(CODEBUILDERTree);
return Ok(Models.JsonMsg>>.Success(jsonList, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetNestingCODEBUILDERTree");
return Ok(Method.Common.ReturnJson(999, "查询失败" + ex.Message));
}
}
#endregion
#region 方法 -> 生成前端接口代码
///
/// 生成前端接口代码
///
///
[Route("CodeBuilder/BuildInterfaceCode")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult BuildInterfaceCode(ESCM.InterfaceCodeModel interfaceCodeModel)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(interfaceCodeModel);
try
{
//生成前端接口代码
ESCM.InterfaceCodeResModel interfaceCodeResModel = ESCG.CodeBuilderHelper.BuildInterfaceCode(interfaceCodeModel);
if (interfaceCodeResModel == null)
{
return Ok(Method.Common.ReturnJson(200, "生成失败,没有设置返参列表字段!"));
}
return Ok(Models.JsonMsg.Success(interfaceCodeResModel, 100, "生成成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "生成失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_BuildInterfaceCode");
return Ok(Method.Common.ReturnJson(999, "生成失败" + ex.Message));
}
}
#endregion
#region 方法 -> 生成前端页面代码
///
/// 生成前端页面代码
///
///
[Route("CodeBuilder/BuildWebPageCode")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult BuildWebPageCode(ESCM.WebPageCodeModel webPageCodeModel)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(webPageCodeModel);
try
{
//生成前端页面代码
ESCM.WebPageCodeResModel webPageCodeResModel = ESCG.CodeBuilderHelper.BuildWebPageCode(transaction, webPageCodeModel);
if (webPageCodeResModel == null)
{
return Ok(Method.Common.ReturnJson(200, "生成失败,没有设置列表字段!"));
}
return Ok(Models.JsonMsg.Success(webPageCodeResModel, 100, "生成成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "生成失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_BuildWebPageCode");
return Ok(Method.Common.ReturnJson(999, "生成失败" + ex.Message));
}
}
#endregion
#region 方法 -> 执行SQL语句,返回Datatable数据集
///
/// 执行SQL语句,返回Datatable数据集
///
///
/// 执行SQL语句入参对象:
/// HostInterfaceId:主表接口内码
/// SubInterfaceId:附表接口内码
/// txtSQLString:SQL语句内容
/// AdvancedConfig:额外的配置项
///
///
[Route("CodeBuilder/ExcuteSQLString")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult ExcuteSQLString(ESCM.ExSQLParam exSQLParam)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(exSQLParam);
try
{
//获取接口嵌套树
DataTable dtSQLResultClone = ESCG.CodeBuilderHelper.ExcuteSQLString(transaction, exSQLParam);
Models.dtJsonList dtJsonList = Models.dtJsonList.Success(dtSQLResultClone);
return Ok(Models.JsonMsg.Success(dtJsonList, 100, "查询成功"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "获取失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_GetNestingInterfaceTree");
return Ok(Method.Common.ReturnJson(999, "获取失败" + ex.Message));
}
}
#endregion
#region 方法 -> 发布接口代码文件
///
/// 发布接口代码文件
///
/// 入参对象
///
[Route("CodeBuilder/CreateInterfaceFile")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult CreateInterfaceFile(ESCM.CreateITFFileParam createFileParam)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(createFileParam);
try
{
//发布接口代码文件
string RebuildslnLogName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + createFileParam.UniqueCode;
bool Flag = ESCG.CodeBuilderHelper.CreateInterfaceFile(transaction, createFileParam, RebuildslnLogName);
if (Flag)
{
return Ok(Method.Common.ReturnJson(100, "发布成功", RebuildslnLogName));
}
return Ok(Method.Common.ReturnJson(200, "发布失败,没有设置返参列表字段!"));
}
catch (Exception ex)
{
transaction.Rollback();
LogUtil.WriteLog(null, "发布失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_CreateInterfaceFile");
return Ok(Method.Common.ReturnJson(999, "发布失败" + ex.Message));
}
}
#endregion
#region 方法 -> 监听接口代码生成结果
///
/// 监听接口代码生成结果
///
/// 监听日志文件名称
///
[Route("CodeBuilder/ListenRebuildRes")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult ListenRebuildRes(string RebuildslnLogName)
{
string Parameter = "入参信息:日志文件名称【" + RebuildslnLogName + "】";
try
{
string resMsg = "";
bool Flag = ESCG.CodeBuilderHelper.ListenRebuildRes(RebuildslnLogName, ref resMsg);
if (Flag)
{
if (resMsg != "")
{
return Ok(Method.Common.ReturnJson(100, "编译结束,出现异常错误!", resMsg));
}
return Ok(Method.Common.ReturnJson(100, "编译成功!"));
}
return Ok(Method.Common.ReturnJson(200, "正在编译中...!"));
}
catch (Exception ex)
{
transaction.Rollback();
LogUtil.WriteLog(null, "编译失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_ListenRebuildRes");
return Ok(Method.Common.ReturnJson(999, "编译失败" + ex.Message));
}
}
#endregion
#region 方法 -> 发布前端代码文件
///
/// 发布前端代码文件
///
/// 入参对象
///
[Route("CodeBuilder/CreateWebFile")]
[AcceptVerbs("POST")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult CreateWebFile(ESCM.CreateWebFileParam createWebFileParam)
{
string Parameter = "入参信息:" + JsonConvert.SerializeObject(createWebFileParam);
try
{
//发布接口代码文件
ESCG.CodeBuilderHelper.CreateWebFile(transaction, createWebFileParam);
return Ok(Method.Common.ReturnJson(100, "发布成功"));
}
catch (Exception ex)
{
transaction.Rollback();
LogUtil.WriteLog(null, "发布失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_CreateWebFile");
return Ok(Method.Common.ReturnJson(999, "发布失败" + ex.Message));
}
}
#endregion
#region 方法 -> 发布前端模块
///
/// 发布前端模块
///
/// 系统用户内码
/// 用户登录账号
/// 原文件所在目录
/// 模块名称
/// 模块唯一标识
/// 系统菜单内码
/// 系统角色内码
/// 文件发布地址
/// 原文件夹目录
///
[Route("CodeBuilder/PublishWebFile")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult PublishWebFile(string UserId, string UserPassport, string DirName, string ModuleName,
string ModuleGuid, int SystemMenuId, int? SystemRoleId = null, string SaveServer = "", string SolutionPath = "")
{
string Parameter = "入参信息:" + UserId;
try
{
//发布接口代码文件
ESCG.CodeBuilderHelper.PublishWebFile(UserId, UserPassport, DirName, ModuleName,
ModuleGuid, SystemMenuId, SystemRoleId, SaveServer, SolutionPath);
return Ok(Method.Common.ReturnJson(100, "发布成功"));
}
catch (Exception ex)
{
transaction.Rollback();
LogUtil.WriteLog(null, "发布失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_CreateWebFile");
return Ok(Method.Common.ReturnJson(999, "发布失败" + ex.Message));
}
}
#endregion
#region 方法 -> 生成本地文件
///
/// 生成本地文件代码
///
///
[Route("CodeBuilder/BuildCodeFiles")]
[AcceptVerbs("GET")]
[ResponseType(typeof(Models.JsonMsg))]
public IHttpActionResult BuildCodeFiles(int DataBaseTableId)
{
string Parameter = "入参信息:数据库Id【" + DataBaseTableId + "】";
try
{
//生成前端页面代码
ESCG.DATABASETABLEHelper.BuildDataBaseTableCode(transaction, DataBaseTableId);
return Ok(Method.Common.ReturnJson(100, "生成成功!"));
}
catch (Exception ex)
{
//事务回滚
transaction.Rollback();
LogUtil.WriteLog(null, "生成失败!失败原因:" + ex.Message + "\r\n" + Parameter,
DateTime.Now.ToString("yyyyMMdd") + "_BuildWebPageCode");
return Ok(Method.Common.ReturnJson(999, "生成失败" + ex.Message));
}
}
#endregion
}
}