diff --git a/REPORT_API_ver6/Controllers/ProjectAPI.cs b/REPORT_API_ver6/Controllers/ProjectAPI.cs index 3646a0a..1c85868 100644 --- a/REPORT_API_ver6/Controllers/ProjectAPI.cs +++ b/REPORT_API_ver6/Controllers/ProjectAPI.cs @@ -37,6 +37,38 @@ namespace REPORT_API_ver6.Controllers return Content(null); } + [Route("list/{intranetCd}/{gkey}/{isKiwi}")] + [HttpGet] + public IActionResult GetProjectList + ( + [FromHeader(Name = "token")] string? token, + [FromHeader(Name = "X-API-Key")] string? xApiKey, + [FromRoute] string intranetCd, + [FromRoute] string gkey, + [FromRoute] int isKiwi, + [FromQuery(Name = "keyword")] string keyword = "" + ) + { + var configuration = Common.GetConfiguration(); + var value = configuration.GetSection("X-API-Key")[xApiKey ?? ""]; + UserInfo? userInfo = String.IsNullOrEmpty(token)? null : Security.ValidateToken(token); + + if (userInfo != null || !String.IsNullOrEmpty(value)) + { + intranetCd = intranetCd.Split("_")[0]; + Project project = new Project(); + DataTable resultTable = project.getProjectList(intranetCd, gkey, isKiwi, keyword); + string returnString = Common.GetJsonFromObject(resultTable); + + hcAccessor.HttpContext.Response.ContentType = "application/json"; + Response.StatusCode = (int)HttpStatusCode.OK; + return Content(returnString); + } + + Response.StatusCode = (int)HttpStatusCode.Unauthorized; + return Content(null); + } + [Route("assign")] [HttpGet] public IActionResult GetAssignList([FromHeader] string token) diff --git a/REPORT_API_ver6/REPORT_API_ver6.csproj b/REPORT_API_ver6/REPORT_API_ver6.csproj index 1312105..2a6b89e 100644 --- a/REPORT_API_ver6/REPORT_API_ver6.csproj +++ b/REPORT_API_ver6/REPORT_API_ver6.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/REPORT_API_ver6/Services/Common.cs b/REPORT_API_ver6/Services/Common.cs index b399372..38b1369 100644 --- a/REPORT_API_ver6/Services/Common.cs +++ b/REPORT_API_ver6/Services/Common.cs @@ -18,6 +18,12 @@ namespace REPORT_API_ver6.Services { static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Common)); + public static IConfiguration GetConfiguration() + { + var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + return builder.Build(); + } + /// /// Request 변수값 반환 /// diff --git a/REPORT_API_ver6/Services/DAL.cs b/REPORT_API_ver6/Services/DAL.cs index efbae63..2bb92b2 100644 --- a/REPORT_API_ver6/Services/DAL.cs +++ b/REPORT_API_ver6/Services/DAL.cs @@ -11,16 +11,6 @@ namespace REPORT_API_ver6.Services { static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DAL)); - /// - /// Config 파일 로드 - /// - /// - public IConfiguration GetConfiguration() - { - var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); - return builder.Build(); - } - /// /// Report DB 연결 /// @@ -30,7 +20,7 @@ namespace REPORT_API_ver6.Services SqlConnection connection = new SqlConnection(); try { - var configuration = GetConfiguration(); + var configuration = Common.GetConfiguration(); connection.ConnectionString = configuration.GetSection("ConnectionStrings").GetSection("ReportString").Value; connection.Open(); } @@ -52,7 +42,7 @@ namespace REPORT_API_ver6.Services string connectionString = string.Empty; try { - var configuration = GetConfiguration(); + var configuration = Common.GetConfiguration(); if (isKiwi == 0) { @@ -82,7 +72,7 @@ namespace REPORT_API_ver6.Services SqlConnection connection = new SqlConnection(); try { - var configuration = GetConfiguration(); + var configuration = Common.GetConfiguration(); connection.ConnectionString = configuration.GetSection("ConnectionStrings").GetSection("IntraString").Value; connection.Open(); } diff --git a/REPORT_API_ver6/Services/Project.cs b/REPORT_API_ver6/Services/Project.cs index ada82ae..1a38073 100644 --- a/REPORT_API_ver6/Services/Project.cs +++ b/REPORT_API_ver6/Services/Project.cs @@ -117,6 +117,59 @@ namespace REPORT_API_ver6.Services return returnTable; } + public DataTable getProjectList(string intranetCd, string gkey, int iskiwi, string keyword) + { + DataTable returnTable = new DataTable(); + + DAL dal = new DAL(); + var connection = dal.ConnectKonKiwi(iskiwi); + try + { + string sqlString = ""; + sqlString += $" SELECT pkey," + Environment.NewLine; + sqlString += $" JSON_VALUE(PROJECTJSON, '$.must.title_inner') as title," + Environment.NewLine; + sqlString += $" JSON_VALUE(PROJECTJSON, '$.must.surveytype') as [surveyType]," + Environment.NewLine; + sqlString += $" JSON_VALUE(PROJECTJSON, '$.must.status') as [status]," + Environment.NewLine; + sqlString += $" gkey, mkey, create_date as createDate " + Environment.NewLine; + sqlString += $" FROM PROJECT with(nolock) " + Environment.NewLine; + sqlString += $" WHERE PKEY <> '' " + Environment.NewLine; + + if (gkey.StartsWith("R")) + { + sqlString += $" AND GKEY = '{gkey}' " + Environment.NewLine; + } + else + { + sqlString += $" AND GKEY <> 'M101'" + Environment.NewLine; + } + + if (String.IsNullOrEmpty(keyword)) + { + sqlString += $" AND PKEY like '%{intranetCd}%' " + Environment.NewLine; + } + else + { + sqlString += $" AND ( " + Environment.NewLine; + sqlString += $" PKEY like '%{keyword}%'" + Environment.NewLine; + sqlString += $" OR JSON_VALUE(PROJECTJSON, '$.must.title_inner') like '%{keyword}%'" + Environment.NewLine; + sqlString += $" )" + Environment.NewLine; + } + sqlString += " ORDER BY create_date DESC" + Environment.NewLine; + + returnTable = dal.GetDataTable(sqlString, connection); + } + catch (Exception ex) + { + logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message); + } + finally + { + dal.Disconnect(connection); + } + + return returnTable; + } + /// /// KON 프로젝트 상세 정보 반환 /// diff --git a/REPORT_API_ver6/appsettings.json b/REPORT_API_ver6/appsettings.json index 440068c..33dd92c 100644 --- a/REPORT_API_ver6/appsettings.json +++ b/REPORT_API_ver6/appsettings.json @@ -12,5 +12,9 @@ "KonString": "Persist Security Info=True;Data Source=1.235.195.8,20022;Initial Catalog=KON;User Id=kon;Password=kon#51304;", "KiwiString": "Persist Security Info=True;Data Source=mssql-7sq2n-kr.vpc-pub-cdb.ntruss.com;Initial Catalog=konkiwi;User Id=kadmin;Password=it#51304;" }, + "X-API-Key": { + "4B726963-436F6E74616374-53657276696365-402531213230" : "Contact Service", + "4B726963-436F6E74616374-46726F6E74-402531213230" : "Contact Front" + }, "AllowedHosts": "*" }