3281 lines
121 KiB
C#
3281 lines
121 KiB
C#
using Newtonsoft.Json.Linq;
|
||
using System.Data;
|
||
using System.Net;
|
||
using System.Text.RegularExpressions;
|
||
using KART_API.Dto;
|
||
using KART_API.Utils;
|
||
using System.Linq;
|
||
using System.Text.Json.Nodes;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||
|
||
namespace KART_API.Services
|
||
{
|
||
public class ProjectService
|
||
{
|
||
static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(ProjectService));
|
||
|
||
/// <summary>
|
||
/// KON 프로젝트 리스트 반환
|
||
/// </summary>
|
||
/// <param name="gkey">KRI 팀</param>
|
||
/// <param name="mkey">USER</param>
|
||
/// <param name="isKRI">1:KRI사람, 2:외부인</param>
|
||
/// <returns>KON 프로젝트 리스트</returns>
|
||
public DataTable getProjectList(string gkey, string mkey, string isAdmin)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
MSDAL msdal = new MSDAL();
|
||
string[] verArray = { "KON", "KIWI" };
|
||
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
DataTable mustViewProject = getMustViewProject(i);
|
||
|
||
string konSqlString = "select '" + verArray[i]+ "' as [ver], '' AS ROWN,";
|
||
if (i == 1)
|
||
{
|
||
konSqlString += " '|K|W|' +";
|
||
}
|
||
konSqlString += " PKEY as PKEY,";
|
||
konSqlString += " cast('' as nvarchar(max)) as security,";
|
||
konSqlString += " ";
|
||
if (i == 1)
|
||
{
|
||
konSqlString += " 'KIWI - ' +";
|
||
}
|
||
konSqlString += " JSON_VALUE(PROJECTJSON, '$.title_inner') as title,"; ///타이틀 여기
|
||
konSqlString += " JSON_VALUE(PROJECTJSON, '$.surveytype') as [surveytype],";
|
||
konSqlString += " JSON_VALUE(PROJECTJSON, '$.status') as [status],";
|
||
konSqlString += " GKEY,";
|
||
konSqlString += " MKEY,";
|
||
konSqlString += " create_date";
|
||
konSqlString += " from" + Environment.NewLine;
|
||
konSqlString += " (" + Environment.NewLine;
|
||
konSqlString += " SELECT PKEY, GKEY, MKEY, JSON_QUERY(PROJECTJSON, '$.must') as PROJECTJSON, create_date" + Environment.NewLine;
|
||
konSqlString += " FROM PROJECT with(nolock) where PKEY <> ''" + Environment.NewLine;
|
||
|
||
konSqlString += " and (create_date >= CONVERT(CHAR(10), DATEADD(YEAR, -1, GETDATE()), 23)";
|
||
if (i == 1)
|
||
{
|
||
konSqlString += " or JSON_VALUE(PROJECTJSON, '$.must.surveyclass') = '1'";
|
||
}
|
||
if (mustViewProject.Rows.Count > 0)
|
||
{
|
||
string mustViewPkeys = string.Join(",", mustViewProject.Rows.OfType<DataRow>().Select(r => "'" + r["pkey"].ToString() + "'"));
|
||
konSqlString += " or PKEY in (" + mustViewPkeys + ")";
|
||
}
|
||
konSqlString += ")";
|
||
|
||
konSqlString += " and JSON_VALUE(PROJECTJSON, '$.must.title_inner') not like '%사례비%'" + Environment.NewLine;
|
||
konSqlString += " and JSON_VALUE(PROJECTJSON, '$.must.companytype') not in ('4', '5')" + Environment.NewLine;
|
||
|
||
if (gkey != "M101" && isAdmin != "0")
|
||
{
|
||
konSqlString += " AND GKEY <> 'M101'" + Environment.NewLine;
|
||
|
||
}
|
||
else if (isAdmin == "4")//BC팀(M101이면서 JOB이 제작)은 KIWI 퀵서베이는 보이게
|
||
{
|
||
//sqlString += " and JSON_VALUE(PROJECTJSON, '$.must.title_inner') like '%kiwisurvey%' ";
|
||
}
|
||
else if (gkey.StartsWith("R") || gkey == "M101")//AI 빅데이터 제외
|
||
{
|
||
konSqlString += " and GKEY = '" + gkey + "'" + Environment.NewLine;
|
||
}
|
||
//if (gkey.StartsWith("R") || gkey == "M101" || gkey.StartsWith("A"))//AI 빅데이터 포함
|
||
if (Convert.ToInt32(isAdmin) > 5)
|
||
{
|
||
konSqlString += " and pkey in (" + getAssignPkeys(mkey) + ")" + Environment.NewLine;
|
||
}
|
||
|
||
konSqlString += " ) a" + Environment.NewLine;
|
||
konSqlString += " where JSON_VALUE(PROJECTJSON, '$.status') in (2, 3)" + Environment.NewLine;
|
||
konSqlString += " and MKEY not in (" + UserService.getDinIDs() + ")" + Environment.NewLine;
|
||
konSqlString += " order by create_date desc" + Environment.NewLine;
|
||
|
||
var msConnection = msdal.ConnectKonKiwi(i);
|
||
try
|
||
{
|
||
if (returnTable.Rows.Count.Equals(0)) returnTable = msdal.GetDataTable(konSqlString, msConnection);
|
||
else returnTable.Merge(msdal.GetDataTable(konSqlString, msConnection));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(msConnection);
|
||
}
|
||
}
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT 'NEWSSAK' AS ver, '' AS ROWN, " +Environment.NewLine;
|
||
sqlString += " concat('|N|S|', CD) as PKEY, " + Environment.NewLine;
|
||
sqlString += " '' as 'security', " +Environment.NewLine;
|
||
sqlString += " IN_TT as title, " +Environment.NewLine;
|
||
sqlString += " 'NEWSSAK' as 'surveytype', " +Environment.NewLine;
|
||
sqlString += " CAST(ST as NCHAR) as 'status', " + Environment.NewLine;
|
||
sqlString += " OWN_TM_CD AS GKEY, " +Environment.NewLine;
|
||
sqlString += " CAST(REG_MBR as NCHAR) AS MKEY, " + Environment.NewLine;
|
||
sqlString += " REG_DT AS create_date " +Environment.NewLine;
|
||
sqlString += " FROM project " +Environment.NewLine;
|
||
sqlString += " WHERE REG_DT >= DATE_ADD(NOW(), INTERVAL - 1 YEAR) AND ST IN(1, 9) and IS_DEL = 0 " + Environment.NewLine;
|
||
|
||
if (gkey != "M101" && isAdmin != "0")
|
||
{
|
||
sqlString += " AND OWN_TM_CD <> 'M101'" + Environment.NewLine;
|
||
|
||
}
|
||
else if (gkey.StartsWith("R") || gkey == "M101")//AI 빅데이터 제외
|
||
{
|
||
sqlString += " and OWN_TM_CD = '" + gkey + "'" + Environment.NewLine;
|
||
}
|
||
|
||
if (Convert.ToInt32(isAdmin) > 5)
|
||
{
|
||
sqlString += " and CD in (" + getAssignProjectCodes(mkey) + ")" + Environment.NewLine;
|
||
}
|
||
|
||
sqlString += " and REG_MBR not in (" + UserService.getDinIDs() + ")" + Environment.NewLine;
|
||
sqlString += " order by REG_DT desc" + Environment.NewLine;
|
||
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
DataTable myTable = mydal.GetDataTable(sqlString, connection);
|
||
if (returnTable.Rows.Count.Equals(0)) returnTable = myTable;
|
||
else returnTable.Merge(myTable);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
if (returnTable.Rows.Count > 0)
|
||
{
|
||
Security security = new Security();
|
||
returnTable = returnTable.Select("", "create_date DESC").CopyToDataTable<DataRow>();
|
||
//키위를 이어 붙였기 때문에 다시 오더바이
|
||
|
||
for (int i = 0; i < returnTable.Rows.Count; i++)
|
||
{
|
||
returnTable.Rows[i]["ROWN"] = (i + 1).ToString();
|
||
string encprojectCode = security.encryptString(returnTable.Rows[i]["PKEY"].ToString());
|
||
returnTable.Rows[i]["security"] = WebUtility.UrlEncode(encprojectCode);
|
||
}
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
public DataTable getMustViewProject(int iskiwi)
|
||
{
|
||
|
||
DataTable returnTable = new DataTable();
|
||
MSDAL dal = new MSDAL();
|
||
var connection = dal.ConnectReport();
|
||
|
||
try
|
||
{
|
||
returnTable = dal.GetDataTable($"SELECT pkey FROM REPORT_MUST_VIEW_PROJECT WHERE is_kiwi = {iskiwi}", connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
dal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// User에게 배정된 프로젝트 Key들 반환
|
||
/// </summary>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>User에게 배정된 프로젝트 Key들</returns>
|
||
public string getAssignPkeys(string mkey)
|
||
{
|
||
string returnValue = string.Empty;
|
||
|
||
MSDAL dal = new MSDAL();
|
||
var connection = dal.ConnectReport();
|
||
try
|
||
{
|
||
//var assignTable = dal.GetDataTable("SELECT [pkey] FROM [REPORT_ASSIGN] where member_mail = '" + mkey + "' and is_use = 1", connection);
|
||
var assignTable = dal.GetDataTable("SELECT [pkey] FROM [REPORT_ASSIGN] where member_mail = '" + mkey + "'", connection);
|
||
if (assignTable.Rows.Count > 0)
|
||
{
|
||
returnValue = string.Join(",", assignTable.Rows.OfType<DataRow>().Select(r => "'" + r["pkey"].ToString() + "'"));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
dal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 새싹 프로젝트 상세 정보 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns>새싹 프로젝트 상세 정보</returns>
|
||
public DataTable getProjectInfo(string projectCode)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " select CD, OWN_TM_CD, REG_MBR, IN_TT, OUT_TT, ST" + Environment.NewLine;
|
||
sqlString += " from project p" + Environment.NewLine;
|
||
sqlString += " where p.CD = '" + projectCode + "' and p.IS_DEL != 1" + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 팀 코드로 팀명 반환
|
||
/// </summary>
|
||
/// <param name="gkey">팀 코드</param>
|
||
/// <returns>팀명</returns>
|
||
public string getProjectTeamName(string gkey)
|
||
{
|
||
string returnValue = string.Empty;
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectIntra();
|
||
try
|
||
{
|
||
returnValue = msdal.GetDataTable("SELECT T_Name FROM project2.dbo.v_Department with(nolock) where Code='" + gkey + "'", connection).Rows[0]["T_Name"].ToString();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 진행중 이거나 완료인 상위 6개 프로젝트 반환
|
||
/// </summary>
|
||
/// <param name="team">팀코드</param>
|
||
/// <param name="mkey">USER</param>
|
||
/// <param name="isAdmin">0:admin, 1:DCO, 5:다른 팀, 7:client, 9:외부 링크</param>
|
||
/// <param name="getCount">가져올 프로젝트 개수</param>
|
||
/// <returns>진행중 이거나 완료인 상위 6개 프로젝트</returns>
|
||
public DataTable lastProjectCount(string team, string mkey, string isAdmin, int getCount)
|
||
{
|
||
DataTable tempTable = new DataTable();
|
||
string[] verArray = { "KON", "KIWI" };
|
||
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
string konSqlString = "";
|
||
konSqlString += " select" + Environment.NewLine;
|
||
konSqlString += " top(" + getCount + ") *" + Environment.NewLine;
|
||
konSqlString += " from(" + Environment.NewLine;
|
||
konSqlString += " select" + Environment.NewLine;
|
||
|
||
if (i == 1) konSqlString += " '|K|W|' +";
|
||
|
||
konSqlString += " b.PKEY as PKEY" + Environment.NewLine;
|
||
konSqlString += " ,'" + verArray[i]+ "' as [ver]" + Environment.NewLine;
|
||
konSqlString += " ,cast('' as nvarchar(max)) as security" + Environment.NewLine;
|
||
konSqlString += " , CAST(sum(isnull(allCount, 0)) as bigint) as allCount" + Environment.NewLine;
|
||
konSqlString += " , CAST(sum(isnull(ongoingCount, 0)) as bigint) as ongoingCount" + Environment.NewLine;
|
||
konSqlString += " , CAST(sum(isnull(screenCount, 0)) as bigint) as screenCount" + Environment.NewLine;
|
||
konSqlString += " , CAST(sum(isnull(quotaCount, 0)) as bigint) as quotaCount" + Environment.NewLine;
|
||
konSqlString += " , CAST(sum(isnull(completeCount, 0)) as bigint) as completeCount" + Environment.NewLine;
|
||
konSqlString += " , JSON_value(PROJECTJSON, '$.must.title_inner') as [title]" + Environment.NewLine; ///타이틀 여기
|
||
konSqlString += " , JSON_value(PROJECTJSON, '$.must.surveytype') as [surveytype]" + Environment.NewLine;
|
||
konSqlString += " , JSON_value(PROJECTJSON, '$.must.status') as [status]" + Environment.NewLine;
|
||
konSqlString += " , b.create_date" + Environment.NewLine;
|
||
konSqlString += " from(" + Environment.NewLine;
|
||
konSqlString += " SELECT PKEY" + Environment.NewLine;
|
||
konSqlString += " , count(*) as allCount" + Environment.NewLine;
|
||
konSqlString += " ,case when[Status] = 1 then count(*) end as ongoingCount" + Environment.NewLine;
|
||
konSqlString += " ,case when[Status] = 99 then count(*) end as screenCount" + Environment.NewLine;
|
||
konSqlString += " ,case when[Status] = 98 then count(*) end as quotaCount" + Environment.NewLine;
|
||
konSqlString += " ,case when[Status] = 10 then count(*) end as completeCount" + Environment.NewLine;
|
||
konSqlString += " FROM [DATA] with(nolock)" + Environment.NewLine;
|
||
konSqlString += " where SURVEY_TYPE != 'TEST' and [Status] != 999" + Environment.NewLine;
|
||
konSqlString += " group by PKEY, [Status]" + Environment.NewLine;
|
||
konSqlString += " ) a" + Environment.NewLine;
|
||
konSqlString += " inner join (select top(50) * from PROJECT with(nolock)" + Environment.NewLine;
|
||
konSqlString += " where JSON_value(JSON_QUERY(PROJECTJSON, '$.must'), '$.status') != 1" + Environment.NewLine;
|
||
konSqlString += " and JSON_VALUE(PROJECTJSON, '$.must.companytype') not in ('4', '5')" + Environment.NewLine;
|
||
konSqlString += " and MKEY not in (" + UserService.getDinIDs() + ")" + Environment.NewLine;
|
||
|
||
if (team != "M101" && isAdmin != "0")
|
||
{
|
||
konSqlString += " AND GKEY <> 'M101' " + Environment.NewLine;
|
||
|
||
}
|
||
else if (isAdmin == "4")//BC팀(M101이면서 JOB이 제작)은 KIWI 퀵서베이는 보이게
|
||
{
|
||
konSqlString += " and JSON_value(PROJECTJSON, '$.must.title_inner') like '%kiwisurvey%' ";
|
||
}
|
||
else if (team.StartsWith("R") || team == "M101")//AI 빅데이터 제외
|
||
{
|
||
konSqlString += " and GKEY = '" + team + "'" + Environment.NewLine;
|
||
}
|
||
//if (team.StartsWith("R") || team.StartsWith("A"))//AI 빅데이터 포함
|
||
if (Convert.ToInt32(isAdmin) > 5)
|
||
{
|
||
konSqlString += " and pkey in (" + getAssignPkeys(mkey) + ")" + Environment.NewLine;
|
||
}
|
||
konSqlString += " order by create_date desc" + Environment.NewLine;
|
||
konSqlString += " ) b on a.PKEY = b.PKEY" + Environment.NewLine;
|
||
konSqlString += " group by b.PKEY, b.create_date, b.PROJECTJSON" + Environment.NewLine;
|
||
konSqlString += " )out_a" + Environment.NewLine;
|
||
konSqlString += " where [status] != 1" + Environment.NewLine;
|
||
konSqlString += " order by [status], create_date desc" + Environment.NewLine;
|
||
|
||
MSDAL msdal = new MSDAL();
|
||
var msConnection = msdal.ConnectKonKiwi(i);
|
||
try
|
||
{
|
||
if (tempTable.Rows.Count.Equals(0)) tempTable = msdal.GetDataTable(konSqlString, msConnection);
|
||
else tempTable.Merge(msdal.GetDataTable(konSqlString, msConnection));
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(msConnection);
|
||
}
|
||
}
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT* " + Environment.NewLine;
|
||
sqlString += " FROM( " + Environment.NewLine;
|
||
sqlString += " SELECT concat('|N|S|', CD) as PKEY " + Environment.NewLine;
|
||
sqlString += " , 'NEWSSAK' AS ver " + Environment.NewLine;
|
||
sqlString += " , '' as 'security' " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(IFNULL(allCount, 0)) AS SIGNED) as allCount " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(IFNULL(ongoingCount, 0)) AS SIGNED) as ongoingCount " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(IFNULL(screenCount, 0)) AS SIGNED) as screenCount " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(IFNULL(quotaCount, 0)) AS SIGNED) as quotaCount " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(IFNULL(completeCount, 0)) AS SIGNED) as completeCount " + Environment.NewLine;
|
||
sqlString += " , pj.IN_TT as 'title' " + Environment.NewLine;
|
||
sqlString += " , 'NEWSSAK' as 'surveytype' " + Environment.NewLine;
|
||
sqlString += " , cast(pj.ST as NCHAR) as 'status' " + Environment.NewLine;
|
||
sqlString += " , pj.REG_DT AS 'create_date' " + Environment.NewLine;
|
||
sqlString += " FROM project pj " + Environment.NewLine;
|
||
sqlString += " inner join( " + Environment.NewLine;
|
||
sqlString += " SELECT PRJ_CD " + Environment.NewLine;
|
||
sqlString += " , count(*) as allCount " + Environment.NewLine;
|
||
sqlString += " ,case when ANS_ST = 1 then count(*) end as ongoingCount " + Environment.NewLine;
|
||
sqlString += " ,case when ANS_ST = 99 then count(*) end as screenCount " + Environment.NewLine;
|
||
sqlString += " ,case when ANS_ST = 98 then count(*) end as quotaCount " + Environment.NewLine;
|
||
sqlString += " ,case when ANS_ST = 10 then count(*) end as completeCount " + Environment.NewLine;
|
||
sqlString += " FROM survey_respondent " + Environment.NewLine;
|
||
sqlString += " WHERE SV_TY_CD != 99 and ANS_ST != 999 " + Environment.NewLine;
|
||
sqlString += " group by PRJ_CD, ANS_ST " + Environment.NewLine;
|
||
sqlString += " ) sr on pj.CD = sr.PRJ_CD " + Environment.NewLine;
|
||
sqlString += " WHERE ST IN(1, 9) and IS_DEL = 0 " + Environment.NewLine;
|
||
if (team != "M101" && isAdmin != "0")
|
||
{
|
||
sqlString += " AND OWN_TM_CD <> 'M101'" + Environment.NewLine;
|
||
|
||
}
|
||
else if (team.StartsWith("R") || team == "M101")//AI 빅데이터 제외
|
||
{
|
||
sqlString += " and OWN_TM_CD = '" + team + "'" + Environment.NewLine;
|
||
}
|
||
|
||
if (Convert.ToInt32(isAdmin) > 5)
|
||
{
|
||
sqlString += " and CD in (" + getAssignProjectCodes(mkey) + ")" + Environment.NewLine;
|
||
}
|
||
|
||
sqlString += " and REG_MBR not in (" + UserService.getDinIDs() + ")" + Environment.NewLine;
|
||
sqlString += " group by pj.CD, pj.IN_TT, pj.ST, pj.REG_DT " + Environment.NewLine;
|
||
sqlString += " order by pj.REG_DT desc " + Environment.NewLine;
|
||
sqlString += " ) OUT_A " + Environment.NewLine;
|
||
sqlString += " LIMIT 6 " + Environment.NewLine;
|
||
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
DataTable myTable = mydal.GetDataTable(sqlString, connection);
|
||
|
||
if (tempTable.Rows.Count.Equals(0)) tempTable = myTable;
|
||
else tempTable.Merge(myTable);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
DataTable returnTable = new DataTable();
|
||
|
||
if (tempTable.Rows.Count > 0)
|
||
{
|
||
tempTable = tempTable.Select("", "create_date DESC").CopyToDataTable<DataRow>();
|
||
|
||
returnTable = tempTable.Clone();
|
||
Security security = new Security();
|
||
int loopCount = tempTable.Rows.Count > getCount ? getCount : tempTable.Rows.Count;
|
||
for (int i = 0; i < loopCount; i++)
|
||
{
|
||
string encprojectCode = security.encryptString(tempTable.Rows[i]["PKEY"].ToString());
|
||
tempTable.Rows[i]["security"] = WebUtility.UrlEncode(encprojectCode);
|
||
|
||
tempTable.Rows[i]["surveytype"] = setProjectTypeStatus(0, tempTable.Rows[i]["surveytype"].ToString());
|
||
tempTable.Rows[i]["status"] = setProjectTypeStatus(1, tempTable.Rows[i]["status"].ToString());
|
||
|
||
returnTable.Rows.Add(tempTable.Rows[i].ItemArray);
|
||
}
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// User에게 배정된 프로젝트 개수 반환
|
||
/// </summary>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>User에게 배정된 프로젝트 개수</returns>
|
||
public short getAssignCount(string mkey)
|
||
{
|
||
short returnValue = 0;
|
||
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
var assignCountTable = msdal.GetDataTable("SELECT count(*) as p_cnt FROM [REPORT_ASSIGN] where member_mail = '" + mkey + "'", connection);
|
||
|
||
if (assignCountTable.Rows.Count > 0)
|
||
{
|
||
returnValue = Convert.ToInt16(assignCountTable.Rows[0][0]);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// User에게 배정된 프로젝트 Key들 반환
|
||
/// </summary>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>User에게 배정된 프로젝트 Key들</returns>
|
||
public string getAssignProjectCodes(string mkey)
|
||
{
|
||
string returnValue = string.Empty;
|
||
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
//var assignTable = msdal.GetDataTable("SELECT [projectCode] FROM [REPORT_ASSIGN] where member_mail = '" + mkey + "' and is_use = 1", connection);
|
||
var assignTable = msdal.GetDataTable("SELECT [pkey] FROM [REPORT_ASSIGN] where member_mail = '" + mkey + "'", connection);
|
||
if (assignTable.Rows.Count > 0)
|
||
{
|
||
returnValue = string.Join(",", assignTable.Rows.OfType<DataRow>().Select(r => "'" + r["pkey"].ToString() + "'"));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트의 일자별 상태별 개수 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="selectDate">일자 범위 JSON</param>
|
||
/// <returns>프로젝트의 상태별 개수</returns>
|
||
public DataTable getTypeByState(string projectCode, string selectDate)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT ";
|
||
sqlString += " count(1) as allCount ";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 1 then 1 else 0 end),0) as ongoingCount ";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 99 then 1 else 0 end),0) as screenCount ";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 98 then 1 else 0 end),0) as quotaCount ";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 10 then 1 else 0 end),0) as completeCount ";
|
||
sqlString += " FROM survey_respondent ";
|
||
sqlString += " WHERE PRJ_CD = '" + projectCode + "' and SV_TY_CD != 99 and ANS_ST in (10, 99, 98, 1) ";
|
||
if (Common.IsJson(selectDate))
|
||
{
|
||
JObject sqlDate = Common.GetJObjectFromString(selectDate);
|
||
if (sqlDate.Count > 0)
|
||
{
|
||
sqlString += " and ANS_E_DT >= CAST('" + sqlDate["sDate"].ToString() + "' as DATE)";
|
||
sqlString += " and ANS_E_DT <= CAST('" + sqlDate["eDate"].ToString() + "' as DATE)";
|
||
}
|
||
}
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// LOI 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="selectDate">일자 범위 JSON</param>
|
||
/// <returns>LOI</returns>
|
||
public DataTable getLOI(string projectCode, string selectDate)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
string sqlString = "";
|
||
sqlString += " SELECT "+Environment.NewLine;
|
||
sqlString += " SUM(CNT) AS CNT "+Environment.NewLine;
|
||
sqlString += " , CAST(ROUND(SUM(AVG_LOI)) AS NCHAR) AS AVG_LOI " + Environment.NewLine;
|
||
sqlString += " , CAST(ROUND(SUM(AVG_LOI_MODIFY)) AS NCHAR) AS AVG_LOI_MODIFY "+Environment.NewLine;
|
||
sqlString += " , CAST(SUM(MIN_LOI) AS NCHAR) AS MIN_LOI " + Environment.NewLine;
|
||
sqlString += " , CAST(SUM(MAX_LOI) AS NCHAR) AS MAX_LOI "+Environment.NewLine;
|
||
sqlString += " FROM ( "+Environment.NewLine;
|
||
sqlString += " SELECT CNT "+Environment.NewLine;
|
||
sqlString += " , AVG(LOI) AS AVG_LOI "+Environment.NewLine;
|
||
sqlString += " , AVG(CASE WHEN ROWNUM < (CNT - CNT * 0.025) AND ROWNUM > CNT * 0.025 THEN LOI ELSE NULL END) AS AVG_LOI_MODIFY "+Environment.NewLine;
|
||
sqlString += " , MIN(LOI) AS MIN_LOI "+Environment.NewLine;
|
||
sqlString += " , MAX(LOI) AS MAX_LOI "+Environment.NewLine;
|
||
sqlString += " FROM ( "+Environment.NewLine;
|
||
sqlString += " SELECT ROW_NUMBER() OVER(ORDER BY LOI) AS ROWNUM "+Environment.NewLine;
|
||
sqlString += " , LOI "+Environment.NewLine;
|
||
sqlString += " , CNT "+Environment.NewLine;
|
||
sqlString += " FROM ( "+Environment.NewLine;
|
||
sqlString += " SELECT TIMESTAMPDIFF(SECOND,ANS_S_DT, ANS_E_DT) as LOI "+Environment.NewLine;
|
||
sqlString += " , count(1) as CNT "+Environment.NewLine;
|
||
sqlString += " FROM survey_respondent "+Environment.NewLine;
|
||
sqlString += " WHERE PRJ_CD = '" + projectCode + "' and SV_TY_CD != 99 and ANS_ST = 10 " + Environment.NewLine;
|
||
|
||
if (Common.IsJson(selectDate))
|
||
{
|
||
JObject sqlDate = Common.GetJObjectFromString(selectDate);
|
||
if (sqlDate.Count > 0)
|
||
{
|
||
sqlString += " and ANS_E_DT >= CAST('" + sqlDate["sDate"].ToString() + "' as DATE)";
|
||
sqlString += " and ANS_E_DT <= CAST('" + sqlDate["eDate"].ToString() + "' as DATE)";
|
||
}
|
||
}
|
||
|
||
sqlString += " GROUP BY TIMESTAMPDIFF(SECOND,ANS_S_DT, ANS_E_DT) "+Environment.NewLine;
|
||
sqlString += " )IN_A "+Environment.NewLine;
|
||
sqlString += " )OUT_A "+Environment.NewLine;
|
||
sqlString += " GROUP BY CNT "+Environment.NewLine;
|
||
sqlString += " UNION ALL " + Environment.NewLine;
|
||
sqlString += " SELECT 0,0,0,0,0 " + Environment.NewLine;
|
||
sqlString += " ) LOI " + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
|
||
if (returnTable.Rows.Count > 0)
|
||
{
|
||
for (int column = 1; column < 5; column++)
|
||
{
|
||
returnTable.Rows[0][column] = Common.SecondToTime(returnTable.Rows[0][column].ToString());
|
||
}
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트의 일자별 상태별 개수 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns>프로젝트의 상태별 개수</returns>
|
||
public DataTable getDayByState(string projectCode)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT";
|
||
sqlString += " DATE_FORMAT(CAST(ANS_E_DT as DATE),'%Y-%m-%d') as survey_date";
|
||
sqlString += " ,count(1) as allCount";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 1 then 1 else 0 end),0) as ongoingCount";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 99 then 1 else 0 end),0) as screenCount";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 98 then 1 else 0 end),0) as quotaCount";
|
||
sqlString += " ,IFNULL(SUM(case when ANS_ST = 10 then 1 else 0 end),0) as completeCount";
|
||
sqlString += " FROM survey_respondent";
|
||
sqlString += " WHERE PRJ_CD = '" + projectCode + "' and SV_TY_CD != 99 and ANS_ST in (10, 99, 98, 1)";
|
||
sqlString += " group by CAST(ANS_E_DT as DATE)";
|
||
sqlString += " order by CAST(ANS_E_DT as DATE)";
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트의 문항별 스크린 아웃 개수 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="selectDate">일자 범위 JSON</param>
|
||
/// <returns>프로젝트의 문항별 스크린 아웃 개수</returns>
|
||
public DataTable getQidByScreen(string projectCode, string selectDate)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT " + Environment.NewLine;
|
||
sqlString += " q.Q_ODR as Qorder " + Environment.NewLine;
|
||
sqlString += " , CONCAT(q.NM, '. ', CASE WHEN q.EXP_TXT = '' THEN q.TT ELSE q.EXP_TXT END) as VIEWTITLE " + Environment.NewLine;
|
||
sqlString += " , q.NM as PAGENAME " + Environment.NewLine;
|
||
sqlString += " ,count(1) as CNT " + Environment.NewLine;
|
||
sqlString += " FROM survey_respondent sr " + Environment.NewLine;
|
||
sqlString += " inner join question q on sr.PRJ_CD = q.PRJ_CD and sr.ANS_E_Q_UK = q.Q_UK " + Environment.NewLine;
|
||
sqlString += " WHERE sr.PRJ_CD = '" + projectCode + "' and q.Q_ODR > 0 and SV_TY_CD != 99 and ANS_ST in (99) " + Environment.NewLine;
|
||
if (Common.IsJson(selectDate))
|
||
{
|
||
JObject sqlDate = Common.GetJObjectFromString(selectDate);
|
||
if (sqlDate.Count > 0)
|
||
{
|
||
sqlString += " and ANS_E_DT >= CAST('" + sqlDate["sDate"].ToString() + "' as DATE)";
|
||
sqlString += " and ANS_E_DT <= CAST('" + sqlDate["eDate"].ToString() + "' as DATE)";
|
||
}
|
||
}
|
||
sqlString += " group by q.Q_ODR, q.NM, q.TT, q.EXP_TXT " + Environment.NewLine;
|
||
sqlString += " order by q.Q_ODR " + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 문항 List 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="qID">특정 QID의 내용만 가져오기 위해 사용</param>
|
||
/// <param name="isAdmin">계정 등급에 따라 상이하게 사용되는 내용</param>
|
||
/// <returns>문항 List</returns>
|
||
public DataTable getQuestionList(string projectCode, string qID, int isGuid = 0)
|
||
{
|
||
DataTable qlistTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " select " + Environment.NewLine;
|
||
sqlString += " CAST(q.Q_UK as NCHAR) as 'QID', " + Environment.NewLine;
|
||
sqlString += " q.Q_ODR as 'Qorder', " + Environment.NewLine;
|
||
sqlString += " q.NM as 'VARIABLE', " + Environment.NewLine;
|
||
sqlString += " q.TT as 'TITLE', " + Environment.NewLine;
|
||
sqlString += " q.EXP_TXT as 'EXPLAIN', " + Environment.NewLine;
|
||
sqlString += " q.DIM as 'VTYPE', " + Environment.NewLine;
|
||
sqlString += " CASE RIGHT(q.TY,2) " + Environment.NewLine;
|
||
sqlString += " WHEN 11 THEN 'info' " + Environment.NewLine;
|
||
sqlString += " WHEN 21 THEN 'single' " + Environment.NewLine;
|
||
sqlString += " WHEN 22 THEN 'scale' " + Environment.NewLine;
|
||
sqlString += " WHEN 31 THEN 'multi' " + Environment.NewLine;
|
||
sqlString += " WHEN 32 THEN 'rank' " + Environment.NewLine;
|
||
sqlString += " WHEN 41 THEN 'num' " + Environment.NewLine;
|
||
sqlString += " WHEN 42 THEN 'text' " + Environment.NewLine;
|
||
sqlString += " WHEN 91 THEN 'file' " + Environment.NewLine;
|
||
sqlString += " ELSE q.TY " + Environment.NewLine;
|
||
sqlString += " END as 'QTYPE', " + Environment.NewLine;
|
||
//산출 옵션 용
|
||
sqlString += " '0' as 'IS_NPS', " + Environment.NewLine;
|
||
sqlString += " '0' as 'IS_REVERSE', " + Environment.NewLine;
|
||
sqlString += " '' as 'MISSING_VALUE', " + Environment.NewLine;
|
||
//산출 옵션 용
|
||
sqlString += " '' as 'MAX_RANK', " + Environment.NewLine;
|
||
//파생 변수 용
|
||
sqlString += " IS_DERIVED, " + Environment.NewLine;
|
||
sqlString += " '' as 'GKEY', " + Environment.NewLine;
|
||
sqlString += " q.REG_MBR as 'MKEY', " + Environment.NewLine;
|
||
//파생 변수 용
|
||
sqlString += " q.Q_ID, " + Environment.NewLine;
|
||
sqlString += " ifnull(b.Q_ID, '') as L_Q_ID, " + Environment.NewLine;
|
||
sqlString += " l.L_VALUE, ifnull(l.L_LABEL,'') as L_LABEL, " + Environment.NewLine;
|
||
sqlString += " t.T_VALUE, ifnull(t.T_LABEL,'') as T_LABEL, " + Environment.NewLine;
|
||
sqlString += " m.M_VALUE, ifnull(m.M_LABEL,'') as M_LABEL, " + Environment.NewLine;
|
||
sqlString += " ifnull(qt.L_INFO, '') as T_LABEL_INFO, " + Environment.NewLine;
|
||
sqlString += " ifnull(qm.L_INFO, '') as M_LABEL_INFO, " + Environment.NewLine;
|
||
sqlString += " ifnull(qs.L_INFO, '') as LABEL_INFO " + Environment.NewLine;
|
||
sqlString += " from (" + Environment.NewLine;
|
||
sqlString += " select '0' as IS_DERIVED, PRJ_CD, Q_UK, Q_ID, Q_ODR, NM, TT, EXP_TXT, DIM, TY, REG_MBR, IS_DEL from question where PRJ_CD = '" + projectCode + "' and IS_DEL = 0" + Environment.NewLine;
|
||
sqlString += " UNION ALL" + Environment.NewLine;
|
||
sqlString += " select '1' as IS_DERIVED, PRJ_CD, Q_UK, Q_ID, Q_ODR as Q_ODR , NM, TT, TT as EXP_TXT, DIM, TY, REG_MBR, IS_DEL from `derived` where PRJ_CD = '" + projectCode + "' and IS_DEL = 0" + Environment.NewLine;
|
||
sqlString += " ) q" + Environment.NewLine;
|
||
sqlString += " left join ( " + Environment.NewLine;
|
||
sqlString += " select qi.Q_ID, ql.L_INFO, qbc.Q_UK " + Environment.NewLine;
|
||
sqlString += " from question_block qb " + Environment.NewLine;
|
||
sqlString += " inner join question_block_collection qbc on qb.PRJ_CD = qbc.PRJ_CD and qb.CD = qbc.BK_CD " + Environment.NewLine;
|
||
sqlString += " inner join question_block_option qbo on qb.PRJ_CD = qbo.PRJ_CD and qb.CD = qbo.BK_CD " + Environment.NewLine;
|
||
sqlString += " inner join question_label ql" + Environment.NewLine;
|
||
sqlString += " on qb.PRJ_CD = ql.PRJ_CD " + Environment.NewLine;
|
||
sqlString += " and ql.Q_UK = cast(replace(qbo.OPT_VAL -> '$[0].value','\"','') as unsigned ) " + Environment.NewLine;
|
||
sqlString += " and ql.DIM = 1 " + Environment.NewLine;
|
||
sqlString += " and ql.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " inner join question qi on qi.PRJ_CD = ql.PRJ_CD and qi.Q_UK = ql.Q_UK " + Environment.NewLine;
|
||
sqlString += " where qb.PRJ_CD = '" + projectCode + "' and qb.TY = 3 " + Environment.NewLine;
|
||
sqlString += " ) b on q.Q_UK = b.Q_UK " + Environment.NewLine;
|
||
sqlString += " left join question_label qt on q.PRJ_CD = qt.PRJ_CD and q.Q_UK = qt.Q_UK and qt.DIM = 3 and qt.DIM <= q.DIM and qt.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " left join question_label qm on q.PRJ_CD = qm.PRJ_CD and q.Q_UK = qm.Q_UK and qm.DIM = 2 and qm.DIM <= q.DIM and qm.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " left join (" + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, Q_UK, DIM, L_INFO from question_label " + Environment.NewLine;
|
||
sqlString += " union all " + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, Q_UK, DIM, L_INFO from derived_label " + Environment.NewLine;
|
||
sqlString += ") qs on q.PRJ_CD = qs.PRJ_CD and q.Q_UK = qs.Q_UK and qs.DIM = 1 and qs.DIM <= q.DIM and qs.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(b.L_INFO,'[{\"order\":\"0\",\"value\":\"\",\"label\":\"\"}]'), '$[*]' COLUMNS(L_ORDER int PATH '$.order',L_VALUE varchar(32) PATH '$.value',L_LABEL varchar(32) PATH '$.label') " + Environment.NewLine;
|
||
sqlString += " ) AS l " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(qt.L_INFO,'[{\"order\":\"0\",\"value\":\"\",\"label\":\"\"}]'), '$[*]' COLUMNS(T_ORDER int PATH '$.order',T_VALUE varchar(32) PATH '$.value',T_LABEL varchar(32) PATH '$.label') " + Environment.NewLine;
|
||
sqlString += " ) AS t " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(qm.L_INFO,'[{\"order\":\"0\",\"value\":\"\",\"label\":\"\"}]'), '$[*]' COLUMNS(M_ORDER int PATH '$.order',M_VALUE varchar(32) PATH '$.value',M_LABEL varchar(32) PATH '$.label') " + Environment.NewLine;
|
||
sqlString += " ) AS m " + Environment.NewLine;
|
||
sqlString += " where q.DIM > 0 " + Environment.NewLine;
|
||
|
||
if(String.IsNullOrEmpty(qID) == false)
|
||
{
|
||
sqlString += " and q.Q_UK = " + qID + " " + Environment.NewLine;
|
||
}
|
||
|
||
sqlString += " order by q.Q_ODR, l.L_ORDER, t.T_ORDER, m.M_ORDER " + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
qlistTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
DataTable returnTable = new DataTable();
|
||
if (isGuid == 1)
|
||
{
|
||
returnTable = qlistTable;
|
||
}
|
||
else
|
||
{
|
||
returnTable = organizeQuestionList(qlistTable, projectCode, qID);
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
public JArray getQuestionOption(string projectCode, string questionUniqueKey)
|
||
{
|
||
JArray jArray = new JArray();
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
DataTable qOptionTable = mydal.GetDataTable("select OPT_VAL from question_option where PRJ_CD ='" + projectCode + "' and Q_UK = " + questionUniqueKey, connection);
|
||
if (qOptionTable.Rows.Count > 0)
|
||
{
|
||
jArray = Common.GetJArrayFromString(qOptionTable.Rows[0]["OPT_VAL"].ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return jArray;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 문항 List 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="team">소속 팀</param>
|
||
/// <param name="isAdmin">0:admin, 1:DCO, 5:다른 팀, 7:client, 9:외부 링크</param>
|
||
/// <returns>문항 List</returns>
|
||
public DataTable getOnlyDerivedList(string projectCode, string team, string isAdmin)
|
||
{
|
||
DataTable qlistTable = getQuestionList(projectCode, "");
|
||
DataTable dlistTable = qlistTable.AsEnumerable().Where(dr => dr.Field<string>("IS_DERIVED") == "1").CopyToDataTable();
|
||
|
||
if(isAdmin != "0" && isAdmin != "1")
|
||
{
|
||
//해당 팀 것만 가져와야 하는데 정보가 없네... 그냥 다 가져오게 하지 뭐
|
||
}
|
||
|
||
DataTable returnTable = organizeQuestionList(dlistTable, projectCode, "");
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Question/Derived List 정리
|
||
/// </summary>
|
||
/// <param name="qlistTable">Question/Derived List</param>
|
||
/// <param name="qID">QID</param>
|
||
/// <returns>정규화된 Question/Derived List</returns>
|
||
public DataTable organizeQuestionList(DataTable qlistTable, string projectCode, string qID)
|
||
{
|
||
DataTable returnTable = qlistTable.Clone();
|
||
returnTable.Columns["QID"].MaxLength = 32;
|
||
returnTable.Columns["VARIABLE"].MaxLength = 64;
|
||
returnTable.Columns["Q_ID"].MaxLength = 64;
|
||
returnTable.Columns["MAX_RANK"].MaxLength = 4;
|
||
|
||
Common.SetEnableDataTableForEdit(ref qlistTable, 0);
|
||
|
||
string oldQID = "";
|
||
for (int i = 0; i < qlistTable.Rows.Count; i++)
|
||
{
|
||
string questionUK = qlistTable.Rows[i]["QID"].ToString();
|
||
string qtype = qlistTable.Rows[i]["QTYPE"].ToString();
|
||
|
||
string qidAdd = "";
|
||
string vnameAdd = "";
|
||
string titleAdd = "";
|
||
string lValue = qlistTable.Rows[i]["L_VALUE"].ToString();
|
||
string lLabel = qlistTable.Rows[i]["L_LABEL"].ToString();
|
||
string tValue = qlistTable.Rows[i]["T_VALUE"].ToString();
|
||
string tLabel = qlistTable.Rows[i]["T_LABEL"].ToString();
|
||
string mValue = qlistTable.Rows[i]["M_VALUE"].ToString();
|
||
string mLabel = qlistTable.Rows[i]["M_LABEL"].ToString();
|
||
|
||
qlistTable.Rows[i]["T_LABEL_INFO"] = summarizeLabelInfo(qlistTable.Rows[i]["T_LABEL_INFO"].ToString());
|
||
qlistTable.Rows[i]["M_LABEL_INFO"] = summarizeLabelInfo(qlistTable.Rows[i]["M_LABEL_INFO"].ToString());
|
||
if (qlistTable.Rows[i]["LABEL_INFO"].ToString().Contains("realCondition") == false)
|
||
{
|
||
qlistTable.Rows[i]["LABEL_INFO"] = summarizeLabelInfo(qlistTable.Rows[i]["LABEL_INFO"].ToString());
|
||
}
|
||
|
||
//17[l1][t1][m1][r1]
|
||
if (String.IsNullOrEmpty(lValue) == false)
|
||
{
|
||
qidAdd += "[L" + lValue + "]";
|
||
vnameAdd += "_" + lValue;
|
||
titleAdd += " - " + lLabel;
|
||
}
|
||
|
||
if ((qlistTable.Rows[i]["VTYPE"].ToString() == "3" || qlistTable.Rows[i]["VTYPE"].ToString() == "2") && oldQID.Equals(questionUK + qidAdd) == false)
|
||
{
|
||
oldQID = questionUK + qidAdd;
|
||
//서머리 변수 추가
|
||
object[] aQinfo = qlistTable.Rows[i].ItemArray;
|
||
aQinfo[0] = aQinfo[0] + qidAdd;
|
||
aQinfo[2] = aQinfo[2] + vnameAdd;
|
||
aQinfo[3] = aQinfo[3].ToString() + titleAdd;
|
||
aQinfo[4] = aQinfo[4].ToString() + titleAdd;
|
||
aQinfo[15] = aQinfo[15] + vnameAdd;
|
||
//label 정보를 만들어서 붙여줘야 하는데
|
||
returnTable.Rows.Add(aQinfo);
|
||
|
||
if (qlistTable.Rows[i]["VTYPE"].ToString() == "3")
|
||
{
|
||
|
||
// 매트릭스 서머리 변수 추가
|
||
Dictionary<string, string> tensorTable = qlistTable.AsEnumerable()
|
||
.Where(dr => dr.Field<string>("QID") == questionUK)
|
||
.Select(dr => new {value = dr.Field<string>("T_VALUE") , lable = dr.Field<string>("T_LABEL") })
|
||
.Distinct()
|
||
.ToDictionary(dr => dr.value, dr => dr.lable);
|
||
|
||
foreach (var tinfo in tensorTable)
|
||
{
|
||
//label 정보를 만들어서 붙여줘야 하는데
|
||
|
||
object[] tQinfo = qlistTable.Rows[i].ItemArray;
|
||
tQinfo[0] = tQinfo[0] + "[T"+ tinfo.Key + "]";
|
||
tQinfo[2] = tQinfo[2] + "_" + tinfo.Key;
|
||
tQinfo[3] = tQinfo[3].ToString() + " - " + tinfo.Value;
|
||
tQinfo[4] = tQinfo[4].ToString() + " - " + tinfo.Value;
|
||
tQinfo[5] = 2;
|
||
tQinfo[15] = tQinfo[15] + "_" + tinfo.Key;
|
||
returnTable.Rows.Add(tQinfo);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (String.IsNullOrEmpty(tValue) == false)
|
||
{
|
||
qidAdd += "[T" + tValue + "]";
|
||
vnameAdd += "_" + tValue;
|
||
titleAdd += " - " + tLabel;
|
||
}
|
||
if (String.IsNullOrEmpty(mValue) == false)
|
||
{
|
||
qidAdd += "[M" + mValue + "]";
|
||
vnameAdd += "_" + mValue;
|
||
titleAdd += " - " + mLabel;
|
||
}
|
||
|
||
///////L T M에 대한 첨자가 붙어야 한다
|
||
object[] originQinfo = qlistTable.Rows[i].ItemArray;
|
||
originQinfo[0] = originQinfo[0] + qidAdd;
|
||
originQinfo[2] = originQinfo[2] + vnameAdd;
|
||
originQinfo[3] = originQinfo[3].ToString() + titleAdd;
|
||
originQinfo[4] = originQinfo[4].ToString() + titleAdd;
|
||
originQinfo[5] = 1;
|
||
originQinfo[15] = originQinfo[15] + vnameAdd;
|
||
|
||
if (qtype == "rank")
|
||
{
|
||
int rankCount = getMaxRank(projectCode, questionUK);
|
||
for (int j = 1; j <= rankCount; j++)
|
||
{
|
||
List<string> rankTitle = new List<string>();
|
||
for (int k = 1; k <= j; k++)
|
||
{
|
||
rankTitle.Add(k.ToString());
|
||
}
|
||
|
||
object[] qinfo = new object[originQinfo.Length];
|
||
Array.Copy(originQinfo, qinfo, originQinfo.Length);
|
||
qinfo[0] = qinfo[0] + qidAdd + "[R"+j+"]";
|
||
qinfo[2] = qinfo[2] + vnameAdd + "_"+j;
|
||
qinfo[3] = qinfo[3].ToString() + titleAdd + " - " + String.Join("+", rankTitle) + "순위 까지";
|
||
qinfo[4] = qinfo[4].ToString() + titleAdd + " - " + String.Join("+", rankTitle) + "순위 까지";
|
||
qinfo[10] = j.ToString(); // rank count aka MAX_RANK
|
||
qinfo[15] = qinfo[15] + vnameAdd + "_" + j;
|
||
returnTable.Rows.Add(qinfo);//순위 만큼 부풀리기
|
||
}
|
||
}
|
||
else
|
||
{
|
||
returnTable.Rows.Add(originQinfo);
|
||
}
|
||
}
|
||
|
||
if (String.IsNullOrEmpty(qID) == false)
|
||
{
|
||
var selectVariable = returnTable.Copy().AsEnumerable().Where(dr => dr.Field<string>("QID") == qID).ToList();
|
||
returnTable.Clear();
|
||
|
||
if (selectVariable.Count > 0)
|
||
{
|
||
object[] variableInfo = selectVariable[0].ItemArray;
|
||
returnTable.Rows.Add(variableInfo);
|
||
}
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// LABEL_INFO에서 order, value, label 만 뽑아서 다시 만들기
|
||
/// </summary>
|
||
/// <param name="labelInfo">Label 정보</param>
|
||
/// <returns>order, value, label 만 있는 json 배열 문자열</returns>
|
||
public string summarizeLabelInfo(string labelInfo)
|
||
{
|
||
if (String.IsNullOrEmpty(labelInfo))
|
||
{
|
||
return string.Empty;
|
||
}
|
||
|
||
JArray labelJArray = Common.GetJArrayFromString(labelInfo);
|
||
JArray summarizeJArray = new JArray(labelJArray.Select(x => new JObject(
|
||
new JProperty("order", x.Value<string>("order")),
|
||
new JProperty("value", x.Value<string>("value")),
|
||
new JProperty("label", Common.StripHTML(x.Value<string>("label")))
|
||
)));
|
||
|
||
return Common.GetStringFromJArray(summarizeJArray);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// KON에서 설정한 Quota List 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns>KON에서 설정한 Quota List</returns>
|
||
public DataTable getQuotaList(string projectCode)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT CD as 'ID' " + Environment.NewLine;
|
||
sqlString += " ,CD as 'QSORDER' " + Environment.NewLine;
|
||
sqlString += " ,case when TT != '' then TT else 'Quota ' + cast(CD as NCHAR) end as 'QSTITLE' " + Environment.NewLine;
|
||
sqlString += " ,CONCAT('{\"COL\":', COL_QUK,',\"ROW\":',ROW_QUK,'}') as 'QSJSON' " + Environment.NewLine;
|
||
sqlString += " FROM quota " + Environment.NewLine;
|
||
sqlString += " where PRJ_CD = '" + projectCode + "' " + Environment.NewLine;
|
||
sqlString += " order by CD " + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 쿼터 정보 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="qsOrder">설정한 쿼터 Order값</param>
|
||
/// <returns>쿼터 정보</returns>
|
||
public DataTable getQuota(string projectCode, string qsOrder)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
|
||
string sqlString = "";
|
||
sqlString += " SELECT idx as id, QT_CNT as cnt, VW_CNT as ori_cnt " + Environment.NewLine;
|
||
sqlString += " ,QT_INFO as QUOTAJSON,IS_USE " + Environment.NewLine;
|
||
sqlString += " FROM quota_cell " + Environment.NewLine;
|
||
sqlString += " where PRJ_CD = '" + projectCode + "' and QT_CD = " + qsOrder + " " + Environment.NewLine;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트 Data 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="filter">필터 쿼리문</param>
|
||
/// <param name="selectQID">특정 QID 없으면 모든 DATA</param>
|
||
/// <param name="startDate">시작 시간</param>
|
||
/// <param name="endDate">끝 시간</param>
|
||
/// <param name="isExport">1:다운로드 형식의 Data</param>
|
||
/// <param name="isTest">Test:Test DATA, ALL:ALL, 그 외 문자열:실제 DATA</param>
|
||
/// <param name="type">com:완료 DATA, not:완료 외 DATA</param>
|
||
/// <returns>프로젝트 Data</returns>
|
||
public DataTable getProjectData(string projectCode, string filter, string selectQID, string startDate, string endDate, int isExport, string isTest, string ansId, string type)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
DataTable pinfo = getProjectInfo(projectCode);
|
||
|
||
string comString = " and sr.ANS_ST = 10";
|
||
if (type.ToUpper() == "NOT")
|
||
{
|
||
comString = " and sr.ANS_ST <> 10";
|
||
}
|
||
|
||
string testString = " and sr.SV_TY_CD != 99";
|
||
if (isTest.ToUpper() == "TEST")
|
||
{
|
||
testString = " and sr.SV_TY_CD = 99";
|
||
}
|
||
else if (isTest.ToUpper() == "ALL")
|
||
{
|
||
testString = "";
|
||
}
|
||
|
||
string ansIdString = "";
|
||
if (String.IsNullOrEmpty(ansId) == false)
|
||
{
|
||
ansIdString = " and sr.ANS_ID in (" + ansId + ")";
|
||
}
|
||
|
||
string dateString = "";
|
||
if (String.IsNullOrEmpty(startDate) == false)
|
||
{
|
||
dateString = " and sr.ANS_S_DT >= '" + startDate + "'" + Environment.NewLine;
|
||
|
||
if (String.IsNullOrEmpty(endDate) == false)
|
||
{
|
||
dateString += " and sr.ANS_E_DT <= '" + endDate + "'" + Environment.NewLine;
|
||
}
|
||
}
|
||
|
||
string selectQidString = "";
|
||
if (selectQID != "''" && String.IsNullOrEmpty(selectQID) == false)
|
||
{
|
||
selectQidString += " and q.Q_UK in (" + selectQID + ")" + Environment.NewLine;
|
||
}
|
||
|
||
//if (pinfo.Rows[0]["surveytype"].ToString() == "2") ; //<-- CAPI
|
||
//if (isExport == 1) //<-- Export 일때만
|
||
|
||
string sqlString = "";
|
||
sqlString += " select ANS_ID, ANS_ST, ANS_S_DT, ANS_E_DT, INTERVAL_MIN, INTERVIEWER_INFO, INTERVIEWER_CODE, ANS_DATA " + Environment.NewLine;
|
||
sqlString += " from( " + Environment.NewLine;
|
||
sqlString += " select ANS_ID, ANS_ST, ANS_S_DT, ANS_E_DT, TIMESTAMPDIFF(MINUTE, ANS_S_DT, ANS_E_DT) as INTERVAL_MIN, '' as INTERVIEWER_INFO, '' as INTERVIEWER_CODE " + Environment.NewLine;
|
||
|
||
if(isExport == 1)
|
||
{
|
||
sqlString += " , JSON_OBJECTAGG(JS.Q_ID, ifnull(JS.ANS_DATA, cast('[]' as json))) as ANS_DATA " + Environment.NewLine;
|
||
}
|
||
else
|
||
{
|
||
sqlString += " , JSON_OBJECTAGG(JS.Q_UK, ifnull(JS.ANS_DATA, cast('[]' as json))) as ANS_DATA " + Environment.NewLine;
|
||
}
|
||
|
||
sqlString += " from( " + Environment.NewLine;
|
||
sqlString += " select sr.ANS_ID, sr.ANS_ST, sr.ANS_S_DT, sr.ANS_E_DT, q.Q_UK, q.Q_ID, JSON_ARRAYAGG(JSON_INSERT(CASE WHEN q.TY=41 then json_replace(j.myvalue,'$.s',CAST(j.myvalue -> '$.o' as SIGNED)) else j.myvalue end,'$.l',sd.LOOP_ID)) as ANS_DATA " + Environment.NewLine;
|
||
sqlString += " from survey_respondent sr " + Environment.NewLine;
|
||
sqlString += " inner join ( " + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, ANS_ID, Q_UK, LOOP_ID, ANS_DATA from survey_data where PRJ_CD = '" + projectCode + "' and json_valid(ANS_DATA) " + Environment.NewLine;
|
||
sqlString += " union all " + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, ANS_ID, Q_UK, LOOP_ID, ANS_DATA from derived_data where PRJ_CD = '" + projectCode + "' and json_valid(ANS_DATA) " + Environment.NewLine;
|
||
sqlString += " ) sd on sr.PRJ_CD = sd.PRJ_CD and sr.ANS_ID = sd.ANS_ID " + Environment.NewLine;
|
||
sqlString += " inner join ( " + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, Q_UK, Q_ID, TY, DIM, IS_DEL from question where PRJ_CD = '" + projectCode + "' " + Environment.NewLine;
|
||
sqlString += " union all " + Environment.NewLine;
|
||
sqlString += " select PRJ_CD, Q_UK, Q_ID, TY, DIM, IS_DEL from `derived` where PRJ_CD = '" + projectCode + "' " + Environment.NewLine;
|
||
sqlString += " ) q on sd.PRJ_CD = q.PRJ_CD and sd.Q_UK = q.Q_UK " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " CASE WHEN q.Q_UK = 1 THEN '[{\"t\":0,\"m\":0,\"s\":0,\"r\":0,\"o\":\"\"}]' ELSE sd.ANS_DATA END, '$[*]' COLUMNS(myvalue JSON PATH '$') " + Environment.NewLine;
|
||
sqlString += " ) AS j " + Environment.NewLine;
|
||
sqlString += " where (q.DIM > 0 or q.Q_UK = 1) and q.IS_DEL = 0 and q.TY not in (91) " + Environment.NewLine;
|
||
|
||
sqlString += " " + comString + testString + ansIdString + dateString + selectQidString + Environment.NewLine;
|
||
|
||
sqlString += " group by sd.ANS_ID, sr.ANS_ST, sr.ANS_S_DT, sr.ANS_E_DT, q.Q_UK, q.Q_ID " + Environment.NewLine;
|
||
sqlString += " ) JS " + Environment.NewLine;
|
||
sqlString += " group by ANS_ID, ANS_ST, ANS_S_DT, ANS_E_DT " + Environment.NewLine;
|
||
sqlString += " ) DT " + Environment.NewLine;
|
||
sqlString += " where 1 = 1 " + Environment.NewLine;
|
||
|
||
if (String.IsNullOrEmpty(filter) == false)
|
||
{
|
||
RegexFilterService regexFilterService = new RegexFilterService();
|
||
sqlString += regexFilterService.makeFilterString(projectCode, filter);
|
||
}
|
||
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
returnTable = mydal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트 DATA를 Json형식으로 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="filter">필터 쿼리문</param>
|
||
/// <param name="selectQID">특정 QID 없으면 모든 DATA</param>
|
||
/// <param name="startDate">시작 시간</param>
|
||
/// <param name="endDate">끝 시간</param>
|
||
/// <param name="isTest">Test:Test DATA, ALL:ALL, 그 외 문자열:실제 DATA</param>
|
||
/// <returns>Json형식의 DATA</returns>
|
||
public string getProjectDataJson(string projectCode, string filter, string selectQID, string startDate, string endDate, string isTest, string idkeys)
|
||
{
|
||
string returnValue = string.Empty;
|
||
|
||
DataTable resultTable = getProjectData(projectCode, filter, selectQID, startDate, endDate, 0, isTest, idkeys, "COM");
|
||
try
|
||
{
|
||
returnValue = "[" + string.Join(",", resultTable.AsEnumerable().Where(x => x.Field<string>("ANS_DATA") != null).Select(x => x.Field<string>("ANS_DATA").ToString()).ToArray()) + "]";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 실제로 저장된 QID 문자열 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="indexString">Index QID들</param>
|
||
/// <param name="bannerString">Banner QID들</param>
|
||
/// <returns>'QID1','QID2'...</returns>
|
||
public string makeSelectQID(string projectCode, string indexString, string bannerString, string filterString)
|
||
{
|
||
string returnString = string.Empty;
|
||
|
||
List<string> qidList = new List<string>();
|
||
qidList.Add(Regex.Replace(indexString, @"(\[[LlTtMmRr]\d\])", ""));
|
||
|
||
if (String.IsNullOrEmpty(bannerString) == false)
|
||
{
|
||
string splitString = bannerString.Replace("|", ",");
|
||
string[] bannerArray = splitString.Split(',').Distinct().ToArray();
|
||
|
||
for (int i = 0; i < bannerArray.Length; i++)
|
||
{
|
||
qidList.Add(Regex.Replace(bannerArray[i], @"(\[[LlTtMmRr]\d\])", ""));
|
||
}
|
||
}
|
||
|
||
if (String.IsNullOrEmpty(filterString) == false)
|
||
{
|
||
foreach(Match quk in Regex.Matches(filterString, @"\[(UK|uk)\:\d+\]"))
|
||
{
|
||
qidList.Add(Regex.Replace(quk.Value, @"\D", ""));
|
||
}
|
||
}
|
||
|
||
qidList = qidList.Distinct().ToList<string>();
|
||
returnString = "'" + String.Join("','", qidList) + "'";
|
||
|
||
return returnString;
|
||
}
|
||
|
||
public DataTable getExportExplain(string projectCode)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
string selectString = string.Empty;
|
||
selectString += " select Q_ID, TT, EXP_TXT " + Environment.NewLine;
|
||
selectString += " from question " + Environment.NewLine;
|
||
selectString += " where PRJ_CD = 'REFACTORING_TEST' and DIM > 0 and IS_DEL = 0 and TY != 91 " + Environment.NewLine;
|
||
selectString += " order by Q_ODR " + Environment.NewLine;
|
||
|
||
returnTable = mydal.GetDataTable(selectString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// DATA 다운로드용 Header정보 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="isAdmin">0:admin, 1:DCO, 5:다른 팀, 7:client, 9:외부 링크</param>
|
||
/// <returns>Header정보</returns>
|
||
public DataTable getExportHeader(string projectCode, string isAdmin)
|
||
{
|
||
DataTable qheadTable = getHeaderBaseTable(projectCode, isAdmin);
|
||
|
||
DataTable returnTable = new DataTable();
|
||
|
||
Common.tableAddColumn(returnTable, new string[] { "detail_qid", "qid", "raw_qid", "l", "t", "m", "s", "r", "e" });
|
||
string[] header = new string[] { "ANS_ID", "ANS_ST", "ANS_S_DT", "ANS_E_DT", "INTERVAL_MIN", "INTERVIEWER_INFO", "INTERVIEWER_CODE" };
|
||
|
||
for (int i = 0; i < header.Length; i++)
|
||
{
|
||
returnTable.Rows.Add(new object[] { header[i], header[i], header[i], "", "", "", "", "", "" });
|
||
}
|
||
|
||
try
|
||
{
|
||
string[] qidLoopArray = new string[] { "L_VALUE", "T_VALUE", "M_VALUE", "S_VALUE" };
|
||
foreach (DataRow qhead in qheadTable.Rows)
|
||
{
|
||
List<string> detailQidArray = new List<string>();
|
||
List<string> qidArray = new List<string>();
|
||
|
||
detailQidArray.Add(qhead["Q_ID"].ToString());
|
||
qidArray.Add(qhead["Q_ID"].ToString());
|
||
|
||
foreach (string qidLoop in qidLoopArray)
|
||
{
|
||
if (String.IsNullOrEmpty(qhead[qidLoop].ToString()) == false)
|
||
{
|
||
detailQidArray.Add(qhead[qidLoop].ToString() + "#" + qidLoop.Substring(0, 1));
|
||
qidArray.Add(qhead[qidLoop].ToString());
|
||
}
|
||
}
|
||
|
||
string mValue = qhead["M_VALUE"].ToString();
|
||
if (qhead["TY"].ToString() == "32" && String.IsNullOrEmpty(qhead["E_VALUE"].ToString()))
|
||
{
|
||
//Rank처리 순위만큼 돌면서 찍기
|
||
int maxRank = getMaxRank(projectCode, qhead["Q_UK"].ToString());
|
||
for (int i = 1; i <= maxRank; i++)
|
||
{
|
||
string detailRankQid = String.Join("_", detailQidArray) + "_" + i + "#R";
|
||
string rankQid = String.Join("_", qidArray) + "_" + i;
|
||
returnTable.Rows.Add(new object[] { detailRankQid, rankQid, qhead["Q_ID"], qhead["L_VALUE"], qhead["T_VALUE"], qhead["M_VALUE"], qhead["S_VALUE"], i.ToString(), qhead["E_VALUE"] });
|
||
}
|
||
//Rank 기타는 따로 처리
|
||
continue;
|
||
}
|
||
|
||
|
||
string detailQid = String.Join("_", detailQidArray);
|
||
string qid = String.Join("_", qidArray);
|
||
//멀티가 아니면서 기타인 경우는 TQID_~_기타로 찍어주기
|
||
if (String.IsNullOrEmpty(qhead["E_VALUE"].ToString()) == false && qhead["TY"].ToString() != "31")
|
||
{
|
||
detailQid = detailQid + "_" + qhead["E_VALUE"] + "#S_ETC";
|
||
qid = qid + "_" + qhead["E_VALUE"] + "_ETC";
|
||
}
|
||
|
||
returnTable.Rows.Add(new object[] { detailQid, qid, qhead["Q_ID"], qhead["L_VALUE"], qhead["T_VALUE"], qhead["M_VALUE"], qhead["S_VALUE"], "", qhead["E_VALUE"] });
|
||
|
||
//멀티면서 기타가 있는 경우는 한번 더 찍어주기
|
||
if (String.IsNullOrEmpty(qhead["E_VALUE"].ToString()) == false && qhead["TY"].ToString() == "31")
|
||
{
|
||
returnTable.Rows.Add(new object[] { detailQid + "_ETC", qid + "_ETC", qhead["Q_ID"], qhead["L_VALUE"], qhead["T_VALUE"], qhead["M_VALUE"], qhead["S_VALUE"], "", qhead["E_VALUE"] });
|
||
}
|
||
}
|
||
|
||
//QID_{loop}_{tensor}_{matrix}_{rank or multi}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 데이터 헤더 Base 테이블 만들기
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 코드</param>
|
||
/// <param name="isAdmin">0:admin, 1:DCO, 5:다른 팀, 7:client, 9:외부 링크</param>
|
||
/// <returns>데이터 헤더 Base 테이블</returns>
|
||
public DataTable getHeaderBaseTable(string projectCode, string isAdmin)
|
||
{
|
||
DataTable headBaseTable = new DataTable();
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
//파생 변수 관련
|
||
if (isAdmin == "0" || isAdmin == "1")
|
||
{
|
||
|
||
}
|
||
|
||
string sqlString = string.Empty;
|
||
sqlString += " select q.Q_UK, q.Q_ID, q.DIM, q.TY, l.L_VALUE, t.T_VALUE, m.M_VALUE " + Environment.NewLine;
|
||
sqlString += " , case when q.TY = 31 then s.S_VALUE else '' end as S_VALUE " + Environment.NewLine;
|
||
sqlString += " , case when s.IS_ETC != 0 then s.S_VALUE else '' end as E_VALUE " + Environment.NewLine;
|
||
sqlString += " from question q " + Environment.NewLine;
|
||
sqlString += " left join( " + Environment.NewLine;
|
||
|
||
sqlString += " select ql.L_INFO, qbc.Q_UK " + Environment.NewLine;
|
||
sqlString += " from question_block qb " + Environment.NewLine;
|
||
sqlString += " inner join question_block_collection qbc on qb.PRJ_CD = qbc.PRJ_CD and qb.CD = qbc.BK_CD " + Environment.NewLine;
|
||
sqlString += " inner join question_block_option qbo on qb.PRJ_CD = qbo.PRJ_CD and qb.CD = qbo.BK_CD " + Environment.NewLine;
|
||
sqlString += " inner join question_label ql " + Environment.NewLine;
|
||
sqlString += " on qb.PRJ_CD = ql.PRJ_CD " + Environment.NewLine;
|
||
sqlString += " and ql.Q_UK = cast(replace(qbo.OPT_VAL -> '$[0].value','\"','') as unsigned ) " + Environment.NewLine;
|
||
sqlString += " and ql.DIM = 1 " + Environment.NewLine;
|
||
sqlString += " and ql.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " where qb.PRJ_CD = '" + projectCode + "' and TY = 3 " + Environment.NewLine;
|
||
|
||
sqlString += " ) b on q.Q_UK = b.Q_UK " + Environment.NewLine;
|
||
sqlString += " left join question_label qt on q.PRJ_CD = qt.PRJ_CD and q.Q_UK = qt.Q_UK and qt.DIM = 3 and qt.DIM <= q.DIM and qt.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " left join question_label qm on q.PRJ_CD = qm.PRJ_CD and q.Q_UK = qm.Q_UK and qm.DIM = 2 and qm.DIM <= q.DIM and qm.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " left join question_label qs on q.PRJ_CD = qs.PRJ_CD and q.Q_UK = qs.Q_UK and qs.DIM = 1 and qs.DIM <= q.DIM and qs.L_INFO != '[]' " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(b.L_INFO, '[{\"order\":\"0\",\"value\":\"\"}]'), '$[*]' COLUMNS(L_ORDER int PATH '$.order', L_VALUE varchar(32) PATH '$.value') " + Environment.NewLine;
|
||
sqlString += " ) AS l " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(qt.L_INFO, '[{\"order\":\"0\",\"value\":\"\"}]'), '$[*]' COLUMNS(T_ORDER int PATH '$.order', T_VALUE varchar(32) PATH '$.value') " + Environment.NewLine;
|
||
sqlString += " ) AS t " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(qm.L_INFO, '[{\"order\":\"0\",\"value\":\"\"}]'), '$[*]' COLUMNS(M_ORDER int PATH '$.order', M_VALUE varchar(32) PATH '$.value') " + Environment.NewLine;
|
||
sqlString += " ) AS m " + Environment.NewLine;
|
||
sqlString += " , JSON_TABLE( " + Environment.NewLine;
|
||
sqlString += " ifnull(qs.L_INFO, '[{\"order\":\"0\",\"value\":\"\",\"is_etc\":\"0\"}]'), '$[*]' COLUMNS(S_ORDER int PATH '$.order', S_VALUE varchar(32) PATH '$.value', IS_ETC varchar(32) PATH '$.is_etc') " + Environment.NewLine;
|
||
sqlString += " ) AS s " + Environment.NewLine;
|
||
sqlString += " where q.PRJ_CD = '" + projectCode + "' " + Environment.NewLine;
|
||
sqlString += " and q.IS_DEL = 0 and q.DIM > 0 and q.TY not in (91)" + Environment.NewLine;
|
||
sqlString += " order by q.Q_ODR, l.L_ORDER, t.T_ORDER, m.M_ORDER, s.S_ORDER " + Environment.NewLine;
|
||
|
||
DataTable rawTable = mydal.GetDataTable(sqlString, connection);
|
||
headBaseTable = rawTable.DefaultView.ToTable(true, Common.getColumnNames(rawTable));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return headBaseTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 데이터 다운로드 용 DataTable 만들기
|
||
/// </summary>
|
||
/// <param name="headerTable">헤더 테이블</param>
|
||
/// <param name="bodyTable">응답 데이터 테이블</param>
|
||
/// <returns>헤더에 맞게 들어간 테이블</returns>
|
||
public DataTable makeExportTable(DataTable headerTable, DataTable bodyTable = null)
|
||
{
|
||
JArray excelJson = new JArray();
|
||
JObject headerJson = new JObject();
|
||
string[] fixHeader = new string[] { "ANS_ID", "ANS_ST", "ANS_S_DT", "ANS_E_DT", "INTERVAL_MIN", "INTERVIEWER_INFO", "INTERVIEWER_CODE" };
|
||
|
||
foreach (DataRow headerRow in headerTable.Rows)
|
||
{
|
||
string detailQid = headerRow["detail_qid"].ToString();
|
||
string qid = headerRow["qid"].ToString();
|
||
headerJson[detailQid] = qid;
|
||
}
|
||
|
||
excelJson.Add(headerJson);
|
||
|
||
if (bodyTable != null)
|
||
{
|
||
for (int i = 0; i < bodyTable.Rows.Count; i++)
|
||
{
|
||
string datString = Common.ReplaceUnicodeEmpty(bodyTable.Rows[i]["ANS_DATA"].ToString());
|
||
if (String.IsNullOrEmpty(datString) == false)
|
||
{
|
||
JObject bodyJson = new JObject();
|
||
JObject dataJson = Common.GetJObjectFromString(datString);
|
||
|
||
foreach (var item in headerJson)
|
||
{
|
||
var keyString = item.Key.ToString();
|
||
DataStructure dataStructure = new DataStructure(fixHeader, keyString);
|
||
|
||
//l, t, m, r or s
|
||
string dataValue = string.Empty;
|
||
|
||
if (Array.IndexOf(fixHeader, keyString) > -1 && bodyTable.Columns.Contains(keyString))
|
||
{
|
||
dataValue = bodyTable.Rows[i][keyString].ToString();
|
||
}
|
||
else if (dataJson[dataStructure.questionId.ToUpper()] != null)
|
||
{
|
||
var dataJArray = Common.GetJArrayFromString(dataJson[dataStructure.questionId.ToUpper()].ToString());
|
||
var targetData = dataJArray.Where(item =>
|
||
item.Value<string>("l") == dataStructure.l
|
||
&& item.Value<string>("t") == dataStructure.t
|
||
&& item.Value<string>("m") == dataStructure.m
|
||
&& item.Value<string>("r") == dataStructure.r
|
||
);
|
||
if (dataStructure.s != "0")
|
||
{
|
||
targetData = targetData.Where(item => item.Value<string>("s") == dataStructure.s);
|
||
}
|
||
|
||
if (targetData.Count() > 0)
|
||
{
|
||
if (dataStructure.isEtc || (targetData.Any(item => String.IsNullOrEmpty(item.Value<string>("o")) == false) && dataStructure.s == "0"))
|
||
{
|
||
dataValue = targetData.Select(item => item.Value<string>("o")).First();
|
||
}
|
||
else
|
||
{
|
||
dataValue = targetData.Select(item => item.Value<string>("s")).First();
|
||
}
|
||
}
|
||
}
|
||
|
||
bodyJson[keyString] = dataValue;
|
||
}
|
||
excelJson.Add(bodyJson);
|
||
}
|
||
}
|
||
}
|
||
|
||
DataTable returnTable = Common.GetDataTableFromJArray(excelJson);
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 변수 가이드 Table 생성
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns></returns>
|
||
public DataTable makeGuideTable(string projectCode, string isAdmin)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
Common.tableAddColumn(returnTable, new string[] { "반복 문항", "문항 차원", "문항 타입", "문항 / 보기번호", "내용", "VALUE LABEL", "VARIABLE LABEL" });
|
||
|
||
DataTable qsTable = getQuestionList(projectCode, "", 1);
|
||
foreach (DataRow qsRow in qsTable.Rows)
|
||
{
|
||
string typeCode = qsRow["QTYPE"].ToString();
|
||
int rankMax = 0;
|
||
|
||
string loopQid = Common.JoinStringWithOutEmpty("_", [qsRow["L_Q_ID"].ToString(), qsRow["L_VALUE"].ToString()]);
|
||
string dimensionString = getDimension(Convert.ToInt32(qsRow["VTYPE"]));
|
||
|
||
string title = clearReserveString(qsRow["TITLE"].ToString() + " " + Common.JoinStringWithOutEmpty(" ", [qsRow["L_LABEL"].ToString(), qsRow["T_LABEL"].ToString(), qsRow["M_LABEL"].ToString()], "[", "]"));
|
||
string startQid = Common.JoinStringWithOutEmpty("_", [qsRow["Q_ID"].ToString(), qsRow["L_VALUE"].ToString(), qsRow["T_VALUE"].ToString(), qsRow["M_VALUE"].ToString()]);
|
||
string endQid = string.Empty;
|
||
|
||
string variableLabel = string.Empty;
|
||
string labelString = qsRow["LABEL_INFO"].ToString();
|
||
|
||
JArray labelArray = Common.GetJArrayFromString(labelString);
|
||
|
||
DataTable labelTable = returnTable.Clone();
|
||
if (labelArray.Count > 0 && Array.IndexOf(["single", "scale", "multi", "rank"], typeCode) > -1)
|
||
{
|
||
int maxRank = 0;
|
||
string tempQid = startQid;
|
||
labelArray = new JArray(labelArray.OrderBy(x => Convert.ToInt32(x["order"])));
|
||
|
||
if (typeCode == "multi")
|
||
{
|
||
endQid = startQid + "_" + labelArray[labelArray.Count - 1]["value"].ToString();
|
||
startQid = startQid + "_" + labelArray[0]["value"].ToString();
|
||
}
|
||
else if (typeCode == "rank")
|
||
{
|
||
List<string> maxRankList = getQuestionOption(projectCode, qsRow["QID"].ToString())
|
||
.Where(x =>
|
||
x["option_code"].ToString() == "30"
|
||
&& x["type_code"].ToString() == "02"
|
||
&& x["detail_code"].ToString() == "01"
|
||
)
|
||
.Select(x => x["value"].ToString()).ToList<string>();
|
||
if (maxRankList.Count > 0)
|
||
{
|
||
maxRank = Convert.ToInt32(maxRankList[0]);
|
||
endQid = startQid + "_" + maxRank;
|
||
startQid = startQid + "_1";
|
||
}
|
||
}
|
||
|
||
int i = 1;
|
||
foreach (JToken labelJson in labelArray)
|
||
{
|
||
string variableLabelSub = string.Empty;
|
||
string value = labelJson["value"].ToString();
|
||
string label = clearReserveString(labelJson["label"].ToString());
|
||
|
||
if (typeCode == "multi" || (typeCode == "rank" && i <= maxRank))
|
||
{
|
||
string suffix = typeCode == "multi" ? value : i.ToString();
|
||
variableLabelSub = "/" + tempQid + "_" + suffix + "'" + title;
|
||
|
||
if(typeCode == "rank")
|
||
{
|
||
variableLabelSub += "-"+i+"순위";
|
||
}
|
||
|
||
variableLabelSub += "'";
|
||
}
|
||
|
||
DataRow labelRow = labelTable.NewRow();
|
||
labelRow.ItemArray = new object[] { string.Empty, string.Empty, string.Empty, value, label, Convert.ToInt32(value).ToString("0000") + "'" + label + "'", variableLabelSub };
|
||
labelTable.Rows.Add(labelRow);
|
||
|
||
i++;
|
||
}
|
||
}
|
||
|
||
|
||
variableLabel = "/" + startQid + "'" + title + "'";
|
||
if (Array.IndexOf(["multi", "rank"], typeCode) > -1)
|
||
{
|
||
variableLabel = string.Empty;
|
||
|
||
if(Convert.ToInt32(qsRow["VTYPE"]) == 1)
|
||
{
|
||
if(qsTable.AsEnumerable().Where(dr => dr.Field<string>("L_Q_ID").ToUpper() == qsRow["Q_ID"].ToString().ToUpper()).Count() > 0)
|
||
{
|
||
loopQid = "[LOOP]";
|
||
}
|
||
}
|
||
}
|
||
|
||
string outQid = Common.JoinStringWithOutEmpty(" To ", [startQid, endQid]);
|
||
DataRow newRow = returnTable.NewRow();
|
||
newRow.ItemArray = new object[] { loopQid, dimensionString, typeCode, outQid, title, "/" + outQid, variableLabel };
|
||
returnTable.Rows.Add(newRow);
|
||
|
||
if (labelTable.Rows.Count > 0)
|
||
{
|
||
returnTable.Merge(labelTable);
|
||
}
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 랭크 문항 최대 순위 가져오기
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 코드</param>
|
||
/// <param name="questionUK">문항 고유키</param>
|
||
/// <returns>랭크문항 최대 순위</returns>
|
||
public int getMaxRank(string projectCode, string questionUK)
|
||
{
|
||
int maxRank = 0;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
|
||
try
|
||
{
|
||
string rankQuery = "";
|
||
rankQuery += " select OPT.VAL " + Environment.NewLine;
|
||
rankQuery += " from question_option qo " + Environment.NewLine;
|
||
rankQuery += " , JSON_TABLE( " + Environment.NewLine;
|
||
rankQuery += " qo.OPT_VAL, '$[*]' COLUMNS( " + Environment.NewLine;
|
||
rankQuery += " OPT_CD int path '$.option_code', " + Environment.NewLine;
|
||
rankQuery += " TY_CD int path '$.type_code', " + Environment.NewLine;
|
||
rankQuery += " DT_CD int path '$.detail_code', " + Environment.NewLine;
|
||
rankQuery += " VAL int path '$.value' " + Environment.NewLine;
|
||
rankQuery += " ) " + Environment.NewLine;
|
||
rankQuery += " ) as OPT " + Environment.NewLine;
|
||
rankQuery += " where PRJ_CD = '" + projectCode + "' and Q_UK = " + questionUK + " " + Environment.NewLine;
|
||
rankQuery += " and OPT.OPT_CD = 30 and TY_CD = 2 and DT_CD = 1 " + Environment.NewLine;
|
||
|
||
DataTable rankTable = mydal.GetDataTable(rankQuery, connection);
|
||
if (rankTable.Rows.Count > 0)
|
||
{
|
||
maxRank = Convert.ToInt32(rankTable.Rows[0][0]);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return maxRank;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 저장된 북마크 정보 반환
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="getPage">TABULATION, CROSSTAB</param>
|
||
/// <param name="gkey">팀코드</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>북마크 정보</returns>
|
||
public DataTable getBookmark(string projectCode, string getPage, string gkey, string mkey)
|
||
{
|
||
DataTable returnTable = new DataTable();
|
||
string sqlString = string.Empty;
|
||
sqlString += " SELECT BOOKMARK_ID, BOOKMARK_TITLE, BOOKMARK_INFO, BOOKMARK_JSON, GKEY, MKEY, IS_OPEN , CASE WHEN MKEY='" + mkey + "' THEN '1' ELSE '0' END as IS_MINE";
|
||
sqlString += " FROM REPORT_BOOKMARK ";
|
||
sqlString += " where PKEY = '" + projectCode + "' and BOOKMARK_PAGE = '" + getPage + "' and(IS_OPEN = 1 or(IS_OPEN = 0 and MKEY = '" + mkey + "')) ";
|
||
sqlString += " order by BOOKMARK_ORDER ";
|
||
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
returnTable = msdal.GetDataTable(sqlString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 북마크 정보 수정
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="bookmarkParam">북마크 정보</param>
|
||
/// <param name="gkey">팀코드</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>북마크 ID</returns>
|
||
public string updateBookmark(string projectCode, BookmarkParam bookmarkParam, string gkey, string mkey)
|
||
{
|
||
string returnValue = "";
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
string upsertString = string.Empty;
|
||
DataTable originInfo = msdal.GetDataTable("SELECT BOOKMARK_TITLE ,BOOKMARK_INFO ,BOOKMARK_JSON, IS_OPEN FROM REPORT_BOOKMARK WHERE BOOKMARK_ID= '" + bookmarkParam.BookmarkID + "'", connection);
|
||
|
||
upsertString += " update a set BOOKMARK_TITLE = '" + bookmarkParam.BookmarkTitle + "', BOOKMARK_INFO = '" + bookmarkParam.BookmarkInfo + "', BOOKMARK_JSON = '" + bookmarkParam.BookmarkJson + "', IS_OPEN = '" + bookmarkParam.IsOpen + "'";
|
||
upsertString += " from REPORT_BOOKMARK a";
|
||
upsertString += " where BOOKMARK_ID = '" + bookmarkParam.BookmarkID + "'";
|
||
|
||
msdal.ExecuteSQL(upsertString, connection);
|
||
returnValue = bookmarkParam.BookmarkID;
|
||
|
||
string logContent = "{\"ORIGIN\": { \"BOOKMARK_ID\": " + bookmarkParam.BookmarkID + ", \"BOOKMARK_TITLE\": " + originInfo.Rows[0]["BOOKMARK_TITLE"].ToString() + ", \"BOOKMARK_INFO\": " + originInfo.Rows[0]["BOOKMARK_INFO"].ToString() + ", \"BOOKMARK_JSON\": " + originInfo.Rows[0]["BOOKMARK_JSON"].ToString() + ", \"IS_OPEN\": " + originInfo.Rows[0]["IS_OPEN"].ToString() + "},";
|
||
logContent += "\"NEW\": { \"BOOKMARK_ID\": " + bookmarkParam.BookmarkID + ", \"BOOKMARK_TITLE\": " + bookmarkParam.BookmarkTitle + ", \"BOOKMARK_INFO\": " + bookmarkParam.BookmarkInfo + ", \"BOOKMARK_JSON\": " + bookmarkParam.BookmarkJson + ", \"IS_OPEN\": " + bookmarkParam.IsOpen + "}}";
|
||
LogService.InsertSiteLog(mkey, projectCode, "Update Bookmark", logContent);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 북마크 정보 등록
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="bookmarkParam">북마크 정보</param>
|
||
/// <param name="gkey">팀코드</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>북마크 ID</returns>
|
||
public string insertBookmark(string projectCode, BookmarkParam bookmarkParam, string gkey, string mkey)
|
||
{
|
||
string returnValue = "";
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
bookmarkParam.BookmarkID = projectCode + "_" + bookmarkParam.BookmarkPage.Substring(0, 1) + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss_ffff");
|
||
|
||
string upsertString = string.Empty;
|
||
upsertString += " insert into REPORT_BOOKMARK (PKEY, BOOKMARK_PAGE,BOOKMARK_ID,BOOKMARK_ORDER,BOOKMARK_TITLE,BOOKMARK_INFO,BOOKMARK_JSON,GKEY,MKEY,IS_OPEN)";
|
||
upsertString += " values ('" + projectCode + "','" + bookmarkParam.BookmarkPage + "','" + bookmarkParam.BookmarkID + "',(select isnull(max(BOOKMARK_ORDER),0)+1 as BOOKMARK_ORDER from REPORT_BOOKMARK where PKEY = '" + projectCode + "' and BOOKMARK_PAGE='" + bookmarkParam.BookmarkPage + "'),'" + bookmarkParam.BookmarkTitle + "','" + bookmarkParam.BookmarkInfo + "','" + bookmarkParam.BookmarkJson + "','" + gkey + "','" + mkey + "'," + bookmarkParam.IsOpen + ")";
|
||
|
||
msdal.ExecuteSQL(upsertString, connection);
|
||
returnValue = bookmarkParam.BookmarkID;
|
||
|
||
string logContent = "{\"NEW\": { \"BOOKMARK_ID\": " + bookmarkParam.BookmarkID + ", \"BOOKMARK_TITLE\": " + bookmarkParam.BookmarkTitle + ", \"BOOKMARK_INFO\": " + bookmarkParam.BookmarkInfo + ", \"BOOKMARK_JSON\": " + bookmarkParam.BookmarkJson + ", \"IS_OPEN\": " + bookmarkParam.IsOpen + "}}";
|
||
LogService.InsertSiteLog(mkey, projectCode, "Insert Bookmark", logContent);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 북마크 삭제
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="bookmarkID">북마크 ID</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>message</returns>
|
||
public string deleteBookmark(string projectCode, string bookmarkID, string mkey)
|
||
{
|
||
string returnValue = "삭제했습니다.";
|
||
MSDAL msdal = new MSDAL();
|
||
var connection = msdal.ConnectReport();
|
||
try
|
||
{
|
||
DataTable originInfo = msdal.GetDataTable("SELECT BOOKMARK_TITLE ,BOOKMARK_INFO ,BOOKMARK_JSON, IS_OPEN FROM REPORT_BOOKMARK WHERE BOOKMARK_ID= '" + bookmarkID + "'", connection);
|
||
|
||
string logContent = "{\"ORIGIN\": { \"BOOKMARK_ID\": " + bookmarkID + ", \"BOOKMARK_TITLE\": " + originInfo.Rows[0]["BOOKMARK_TITLE"].ToString() + ", \"BOOKMARK_INFO\": " + originInfo.Rows[0]["BOOKMARK_INFO"].ToString() + ", \"BOOKMARK_JSON\": " + originInfo.Rows[0]["BOOKMARK_JSON"].ToString() + ", \"IS_OPEN\": " + originInfo.Rows[0]["IS_OPEN"].ToString() + "}}";
|
||
LogService.InsertSiteLog(mkey, projectCode, "Delete Bookmark", logContent);
|
||
|
||
msdal.ExecuteSQL("update a set BOOKMARK_ORDER = (BOOKMARK_ORDER - 1) FROM REPORT_BOOKMARK a where PKEY = '" + projectCode + "' and BOOKMARK_ORDER > (select BOOKMARK_ORDER from REPORT_BOOKMARK b where PKEY = a.PKEY and BOOKMARK_ID = '" + bookmarkID + "')", connection);
|
||
msdal.ExecuteSQL("delete FROM REPORT_BOOKMARK where PKEY = '" + projectCode + "' and BOOKMARK_ID = '" + bookmarkID + "'", connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "삭제 중 오류가 발생했습니다.";
|
||
}
|
||
finally
|
||
{
|
||
msdal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 변수명 중복 체크
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="upsertMode">I:insert, U:update</param>
|
||
/// <param name="variableID">변수명</param>
|
||
/// <returns>true/false</returns>
|
||
public bool checkDuplicateVariable(string projectCode, string upsertMode, string variableID)
|
||
{
|
||
bool returnValue = true;
|
||
string sqlString = string.Empty;
|
||
|
||
sqlString += " select distinct QID ";
|
||
sqlString += " from ";
|
||
sqlString += " ( ";
|
||
sqlString += " select Q_ID from question where PRJ_CD = '" + projectCode + "' and IS_DEL = 0 ";
|
||
sqlString += " UNION ALL ";
|
||
sqlString += " select Q_ID from `derived` where PRJ_CD = '" + projectCode + "' and IS_DEL = 0 ";
|
||
sqlString += " ) a ";
|
||
sqlString += " where QID = '" + variableID + "' ";
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
var returnTable = mydal.GetDataTable(sqlString, connection);
|
||
if (upsertMode == "I" && returnTable.Rows.Count > 0 || upsertMode == "U" && returnTable.Rows.Count > 1)
|
||
{
|
||
returnValue = false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 모든 파생변수 Update
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>message</returns>
|
||
public string updateAllDerived(string projectCode, string mkey, string answeID = "")
|
||
{
|
||
string returnString = "";
|
||
|
||
var derivedList = getOnlyDerivedList(projectCode, "", "0").AsEnumerable().Select(dr => dr.Field<string>("QID")).ToList();
|
||
foreach (var derived in derivedList)
|
||
{
|
||
returnString = setDerivedData(projectCode, derived, answeID);
|
||
if (returnString.IndexOf("오류") > -1)
|
||
{
|
||
returnString += " / " + derived;
|
||
break;
|
||
}
|
||
}
|
||
|
||
string logContent = "{\"COUNT\": \"" + derivedList.Count + "\"}";
|
||
LogService.InsertSiteLog(mkey, projectCode, "Update All Derived Variable", logContent);
|
||
|
||
return returnString;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 파생변수 삭제
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="variableID">파생변수명</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>message</returns>
|
||
public string deleteDerivedVariable(string projectCode, string variableID, string mkey)
|
||
{
|
||
string returnValue = "삭제했습니다.";
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
|
||
LogService.InsertSiteLog(mkey, projectCode, "Delete Derived Variable", variableID);
|
||
|
||
mydal.ExecuteSQL("update `derived` set Q_ODR = (Q_ODR - 1) where PRJ_CD = '" + projectCode + "' and Q_ODR > (select Q_ODR from `derived` where PRJ_CD = '" + projectCode + "' and Q_UK = " + variableID + ")", connection);
|
||
mydal.ExecuteSQL("delete from `derived` where PRJ_CD = '" + projectCode + "' and Q_UK = " + variableID + " and IS_DEL = 0 ", connection);
|
||
mydal.ExecuteSQL("delete from `derived_label` where PRJ_CD = '" + projectCode + "' and Q_UK = " + variableID , connection);
|
||
mydal.ExecuteSQL("delete from derived_data where PRJ_CD ='" + projectCode + "' and Q_UK = "+ variableID, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "삭제 중 오류가 발생했습니다.";
|
||
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 파생변수 수정
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="derivedParam">파생변수 정보</param>
|
||
/// <param name="gkey">팀코드</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>message</returns>
|
||
|
||
public string updateDerivedVariable(string projectCode, DerivedParam derivedParam, string gkey, string mkey)
|
||
{
|
||
//여기 수정 해야해
|
||
|
||
|
||
string returnValue = "성공적으로 저장했습니다.";
|
||
|
||
if (checkDuplicateVariable(projectCode, "U", derivedParam.VariableID))
|
||
{
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
string quk = string.Empty;
|
||
string userNumber = UserService.userNumber(mkey);
|
||
string infoString = getDeriveInfoString(derivedParam);
|
||
string qjson = "";
|
||
|
||
DataTable originInfo = mydal.GetDataTable("select Q_UK, Q_ID, NM, TY, TT from `derived` where PRJ_CD = '" + projectCode + "' and Q_ID = '" + derivedParam.OriginID + "' AND IS_DEL = 0 ", connection);
|
||
if(originInfo.Rows.Count > 0)
|
||
{
|
||
quk = originInfo.Rows[0]["Q_UK"].ToString();
|
||
}
|
||
|
||
string upsertString = "";
|
||
upsertString += " update `derived` set " +
|
||
"Q_ID = '" + derivedParam.VariableID + "'" +
|
||
", NM = '" + derivedParam.VariableID + "'" +
|
||
", TY = '" + getType(derivedParam.VariableType) + "'" +
|
||
", TT = '" + derivedParam.VariableTitle + "'" +
|
||
", REG_MBR = " + userNumber + " ";
|
||
upsertString += " where PRJ_CD = '" + projectCode + "' and Q_UK = " + quk + " ";
|
||
mydal.ExecuteSQL(upsertString, connection);
|
||
|
||
string deleteString = "delete from `derived_label` where PRJ_CD='" + projectCode + "' and Q_UK = " + quk;
|
||
mydal.ExecuteSQL(deleteString, connection);
|
||
|
||
string labelString = "";
|
||
labelString += " insert into `derived_label`(PRJ_CD, Q_UK, DIM, L_INFO) ";
|
||
labelString += " values(" +
|
||
"'" + projectCode + "'" +
|
||
", " + quk +
|
||
",1" +
|
||
",'" + infoString.Replace(@"\", @"\\") + "') ";
|
||
mydal.ExecuteSQL(labelString, connection);
|
||
|
||
string logContent = "{\"NEW\": { \"QID\": " + derivedParam.VariableID + ", \"DERIVEDJSON\": " + infoString + "}}"; ;
|
||
LogService.InsertSiteLog(mkey, projectCode, "Update Derived Variable", logContent);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "저장 중 오류가 발생했습니다.";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
returnValue = setDerivedData(projectCode, derivedParam.VariableID, "");
|
||
}
|
||
else
|
||
{
|
||
returnValue = "ID가 중복됩니다.";
|
||
}
|
||
|
||
//값 만들기
|
||
return returnValue;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 파생변수 등록
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="derivedParam">파생변수 정보</param>
|
||
/// <param name="gkey">팀코드</param>
|
||
/// <param name="mkey">User</param>
|
||
/// <returns>message</returns>
|
||
|
||
public string insertDerivedVariable(string projectCode, DerivedParam derivedParam, string gkey, string mkey)
|
||
{
|
||
//여기 수정 해야해
|
||
|
||
string returnValue = "성공적으로 저장했습니다.";
|
||
|
||
if (checkDuplicateVariable(projectCode, "I", derivedParam.VariableID))
|
||
{
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
string userNumber = UserService.userNumber(mkey);
|
||
string infoString = getDeriveInfoString(derivedParam);
|
||
string quk = "0";
|
||
|
||
DataTable qukTable = mydal.GetDataTable("select count(1) + 9001 as quk from `derived` where PRJ_CD = '" + projectCode + "'", connection);
|
||
if(qukTable.Rows.Count > 0)
|
||
{
|
||
quk = qukTable.Rows[0][0].ToString();
|
||
}
|
||
|
||
string insertString = "";
|
||
insertString += " insert into `derived`(PRJ_CD, Q_UK, Q_ODR, Q_ID, NM, DIM, TY, TT, REG_MBR) ";
|
||
insertString += " values(" +
|
||
"'" + projectCode + "'" +
|
||
", " + quk +
|
||
", " + quk +
|
||
", '" + derivedParam.VariableID + "'" +
|
||
",'" + derivedParam.VariableID + "'" +
|
||
",1" +
|
||
"," + getType(derivedParam.VariableType) + "" +
|
||
",'" + derivedParam.VariableTitle + "'" +
|
||
"," + userNumber + ") ";
|
||
mydal.ExecuteSQL(insertString, connection);
|
||
|
||
string labelString = "";
|
||
labelString += " insert into `derived_label`(PRJ_CD, Q_UK, DIM, L_INFO) ";
|
||
labelString += " values(" +
|
||
"'" + projectCode + "'" +
|
||
", " + quk +
|
||
",1" +
|
||
",'" + infoString.Replace(@"\",@"\\") + "') ";
|
||
mydal.ExecuteSQL(labelString, connection);
|
||
|
||
string logContent = "{\"NEW\": { \"QID\": " + derivedParam.VariableID + ", \"DERIVEDJSON\": " + infoString + "}}";
|
||
LogService.InsertSiteLog(mkey, projectCode, "Insert Derived Variable", logContent);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "저장 중 오류가 발생했습니다.";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
returnValue = setDerivedData(projectCode, derivedParam.VariableID, "");
|
||
}
|
||
else
|
||
{
|
||
returnValue = "ID가 중복됩니다.";
|
||
}
|
||
|
||
//값 만들기
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// infoString 생성
|
||
/// </summary>
|
||
/// <param name="derivedParam">파생변수 정보</param>
|
||
/// <returns>infoString 반환</returns>
|
||
public string getDeriveInfoString(DerivedParam derivedParam)
|
||
{
|
||
string infoString = derivedParam.VariableInfo.Replace("\r", "").Replace("\n", "");
|
||
while (infoString.IndexOf(" ") > 0)
|
||
{
|
||
infoString = infoString.Replace(" ", " ");
|
||
}
|
||
|
||
var labelArray = new JArray();
|
||
var labelObject = Common.GetJObjectFromString(infoString);
|
||
|
||
foreach(var o in labelObject)
|
||
{
|
||
labelArray.Add(o.Value);
|
||
}
|
||
|
||
return Common.GetStringFromJArray(labelArray).Replace("\r","").Replace("\n","");
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 파생변수 DATA 생성/수정
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="variableID">파생변수명</param>
|
||
/// <returns>message</returns>
|
||
public string setDerivedData(string projectCode, string variableID, string answerID)
|
||
{
|
||
//여기 수정 해야해
|
||
|
||
string returnValue = "성공적으로 저장했습니다.";
|
||
JArray variableInfo = new JArray();
|
||
string quk = string.Empty;
|
||
string variableType = string.Empty;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
|
||
var tempTable = mydal.GetDataTable("select Q_UK, TY from `derived` where PRJ_CD ='" + projectCode + "' and Q_ID = '" + variableID + "' and IS_DEL = 0", connection);
|
||
if (tempTable.Rows.Count > 0)
|
||
{
|
||
quk = tempTable.Rows[0]["Q_UK"].ToString();
|
||
variableType = getTypeString(tempTable.Rows[0]["TY"].ToString());
|
||
}
|
||
|
||
DataTable derivedVariable = mydal.GetDataTable("select L_INFO from derived_label where PRJ_CD = '" + projectCode + "' and Q_UK=" + quk + " and DIM = 1", connection);
|
||
variableInfo = Common.GetJArrayFromString(derivedVariable.Rows[0]["L_INFO"].ToString());
|
||
|
||
string deleteString = "DELETE from derived_data where PRJ_CD='" + projectCode + "' and Q_UK = " + quk;
|
||
if(String.IsNullOrEmpty(answerID) == false)
|
||
{
|
||
deleteString += " and ANS_ID = '"+ answerID + "' ";
|
||
}
|
||
mydal.ExecuteSQL(deleteString, connection);
|
||
|
||
string insertString = " insert into derived_data (PRJ_CD, ANS_ID, Q_UK, LOOP_ID, ANS_DATA) " + Environment.NewLine;
|
||
insertString += " select PRJ_CD, ANS_ID, "+ quk + ", 0, '[]' " + Environment.NewLine;
|
||
insertString += " FROM survey_respondent sr " + Environment.NewLine;
|
||
insertString += " WHERE PRJ_CD = '"+ projectCode + "' and sr.ANS_ST = 10 and sr.SV_TY_CD != 99 " + Environment.NewLine;
|
||
if (String.IsNullOrEmpty(answerID) == false)
|
||
{
|
||
insertString += " and ANS_ID = '" + answerID + "' ";
|
||
}
|
||
mydal.ExecuteSQL(insertString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "저장 중 오류가 발생했습니다.";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
// 데이터 만들기
|
||
foreach (var labelInfo in variableInfo)
|
||
{
|
||
connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
string ansDataString = string.Empty;
|
||
string condition = labelInfo["realCondition"].ToString();
|
||
string value = labelInfo["value"].ToString();
|
||
|
||
if (condition == "ELSE")
|
||
{
|
||
condition = "( [UK:"+ quk + "] IS NULL ) ";
|
||
}
|
||
else
|
||
{
|
||
if (variableType != "multi")
|
||
{
|
||
condition += " AND ( [UK:" + quk + "] IS NULL )";
|
||
}
|
||
}
|
||
|
||
if (variableType == "num")
|
||
{
|
||
ansDataString = "{\"t\":0, \"m\":0, \"s\":\"\", \"r\":0, \"o\":"+value+"}";
|
||
}
|
||
else
|
||
{
|
||
ansDataString = "{\"t\":0, \"m\":0, \"s\":"+ value + ", \"r\":0, \"o\":\"\"}";
|
||
}
|
||
|
||
|
||
DataTable matchData = getProjectData(projectCode, condition, "", "", "", 0, "", answerID, "COM");
|
||
|
||
if(matchData.Rows.Count > 0)
|
||
{
|
||
string[] answerIDList = matchData.AsEnumerable().Select(x => "'" + x.Field<string>("ANS_ID") + "'").ToArray<string>();
|
||
|
||
string dataString = "update derived_data set ANS_DATA=JSON_ARRAY_APPEND(ANS_DATA, '$',CAST('" + ansDataString + "' as JSON)) where PRJ_CD='" + projectCode + "' and Q_UK = " + quk + " and ANS_ID in (" + String.Join(",", answerIDList) + ")";
|
||
mydal.ExecuteSQL(dataString, connection);
|
||
}
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "저장 중 오류가 발생했습니다.";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
}
|
||
|
||
connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
string deleteString = "DELETE FROM derived_data WHERE PRJ_CD ='" + projectCode + "' AND Q_UK = " + quk + " AND ANS_DATA ='[]'";
|
||
mydal.ExecuteSQL(deleteString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "저장 중 오류가 발생했습니다.";
|
||
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트 DATA File Upload
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="fileName">파일 Path</param>
|
||
/// <param name="extension">파일 확장자</param>
|
||
/// <returns>message</returns>
|
||
public string uploadProjectData(string projectCode, string fileName, string extension)
|
||
{
|
||
string returnValue = "업로드 성공";
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
//응답값 초기화
|
||
try
|
||
{
|
||
mydal.ExecuteSQL(" delete from [DATA] where projectCode = '" + projectCode + "' and SURVEY_TYPE = 'UPLOAD' ", connection);
|
||
mydal.ExecuteSQL(" update a set a.projectCode = 'DEL_'+projectCode FROM [DATA] a where projectCode = '" + projectCode + "' and SURVEY_TYPE != 'TEST' and status = '10' ", connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
return "응답 초기화 실패";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
// 파일 정리 후 넣기
|
||
try
|
||
{
|
||
DataTable excelData = new DataTable();
|
||
string[] headerArray;
|
||
string[] passArray = { "idkey", "status", "start_date", "end_date", "interval_min", "interviewer_info/interviewer_code" };///keyArray에서 _로 스플릿한 다음에 중복 제거를 하기 때문에
|
||
|
||
if (extension.ToLower() == ".xlsx")
|
||
{
|
||
excelData = Common.ExceltoDataTable(fileName);
|
||
}
|
||
else
|
||
{
|
||
excelData = Common.textToDataTable(fileName, extension);
|
||
}
|
||
|
||
if (excelData.Columns[0].ColumnName == "error")
|
||
{
|
||
return excelData.Rows[0][0].ToString();
|
||
}
|
||
else if (excelData.Rows.Count < 2)
|
||
{
|
||
return "파일을 확인해 주세요.";
|
||
}
|
||
else
|
||
{
|
||
excelData.Rows.Remove(excelData.Rows[0]); //KON DATA 파일은 header가 2줄 한줄 버리기
|
||
headerArray = Common.getColumnNames(excelData);
|
||
}
|
||
|
||
string[] keyArray = headerArray.Select(x => x.Split('_')[0].Replace("TQ", "Q")).Distinct().ToArray();
|
||
|
||
for (int i = 0; i < passArray.Length; i++)
|
||
{
|
||
keyArray = keyArray.Where((source, index) => index != 0).ToArray();
|
||
}
|
||
|
||
//여기서 multi인 QID 색출
|
||
/*
|
||
List<string> multiQlist = (from DataRow dr in getQuestionList(projectCode, "", iskiwi,"0").Rows
|
||
where dr.Field<string>("QTYPE").ToLower() == "multi"
|
||
select dr.Field<string>("QID").Split('_')[0]).Distinct().ToList<string>();
|
||
*/
|
||
List<string> multiQlist = getQuestionList(projectCode, "").AsEnumerable().Where(dr => dr.Field<string>("QTYPE").ToLower() == "multi").Select(dr => dr.Field<string>("QID").Split('_')[0]).Distinct().ToList<string>();
|
||
string insertPre = "insert into [DATA] ([IDKEY], [projectCode], [PAGENAME], [SURVEY_TYPE], [Status], [DATJSON], [survey_date])";
|
||
string pageName = string.Empty;
|
||
string surveyType = "UPLOAD";
|
||
for (int i = 0; i < excelData.Rows.Count; i++)
|
||
{
|
||
string[] dataArray = new string[keyArray.Length];
|
||
string[] timeArray = new string[keyArray.Length];
|
||
|
||
string idkey = excelData.Rows[i]["IDKEY"].ToString();
|
||
string status = excelData.Rows[i]["Status"].ToString();
|
||
string stime = excelData.Rows[i]["start_date"].ToString();
|
||
string etime = excelData.Rows[i]["end_date"].ToString();
|
||
|
||
if (String.IsNullOrEmpty(status))
|
||
{
|
||
status = "10";
|
||
}
|
||
if (String.IsNullOrEmpty(stime))
|
||
{
|
||
stime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
if (String.IsNullOrEmpty(etime))
|
||
{
|
||
etime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
|
||
string meanTime = new DateTime((Convert.ToDateTime(etime).Ticks + Convert.ToDateTime(stime).Ticks) / 2).ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
for (int j = 0; j < keyArray.Length; j++)
|
||
{
|
||
string[] dataKeyArray = headerArray.Where(x => x == keyArray[j] || x.StartsWith(keyArray[j] + "_") || x.StartsWith("T" + keyArray[j] + "_")).ToArray();
|
||
string[] dataJsonArray = new string[dataKeyArray.Length];
|
||
|
||
for (int k = 0; k < dataKeyArray.Length; k++)
|
||
{
|
||
string cellValue = excelData.Rows[i][dataKeyArray[k]].ToString().Trim().Replace(".00", "");
|
||
if (String.IsNullOrEmpty(cellValue) == false)
|
||
{
|
||
string dataKey = dataKeyArray[k];
|
||
//모든 multi는 QID_Value_Attr(당겨쳐진 multi처리)
|
||
if (multiQlist.Contains(keyArray[j]) && Common.IsNumeric(cellValue))
|
||
{
|
||
string[] dataKeyDetail = dataKey.Split('_');
|
||
dataKeyDetail[1] = cellValue;
|
||
dataKey = String.Join("_", dataKeyDetail);
|
||
}
|
||
|
||
dataJsonArray[k] = "\"" + dataKey + "\":\"" + cellValue.Replace("\n", " ").Replace("\"", """).Replace("'", "‘") + "\"";
|
||
}
|
||
}
|
||
|
||
dataJsonArray = dataJsonArray.Where(x => x != null).ToArray();
|
||
string dataJson = string.Join(",", dataJsonArray);
|
||
if (String.IsNullOrEmpty(dataJson) == false)
|
||
{
|
||
pageName = keyArray[j];
|
||
dataArray[j] = "\"" + keyArray[j] + "\":{" + dataJson + "}";
|
||
timeArray[j] = "\"" + keyArray[j] + "\":\"" + meanTime + "\"";
|
||
}
|
||
}
|
||
|
||
dataArray = dataArray.Where(x => x != null).ToArray();
|
||
timeArray = timeArray.Where(x => x != null).ToArray();
|
||
|
||
var lastTime = timeArray[timeArray.Length - 1].Split("\":\"");
|
||
timeArray[timeArray.Length - 1] = lastTime[0] + "\":\"" + etime + "\"";
|
||
string dataString = "{ \"INDEX\":{\"USERAGENT\":\"\",\"USERIP\":\"\",\"TK\":\"\"}," + string.Join(",", dataArray) + "}";
|
||
string timeString = "{ \"INDEX\":\"" + stime + "\"," + string.Join(",", timeArray) + "}";
|
||
|
||
string insertString = insertPre + " values ('" + idkey + "','" + projectCode + "','" + pageName + "','" + surveyType + "','" + status + "',N'" + dataString + "','" + timeString + "')";
|
||
|
||
connection = mydal.ConnectNewssak();
|
||
mydal.ExecuteSQL(insertString, connection);
|
||
mydal.Disconnect(connection);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "실패";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 파일로 문항 등록
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="fileName">파일 Path</param>
|
||
/// <param name="extension">파일 확장자</param>
|
||
/// <returns>message</returns>
|
||
public string uploadQuestion(string projectCode, string fileName, string extension)
|
||
{
|
||
string returnValue = "업로드 성공";
|
||
/*
|
||
try
|
||
{
|
||
#region 파일 정리
|
||
DataTable excelData = new DataTable();
|
||
string[] headerArray = new string[] { "variable", "explain", "qtype", "attr_value", "max_value", "title" };
|
||
|
||
if (extension.ToLower() == ".xlsx")
|
||
{
|
||
excelData = Common.ExceltoDataTable(fileName, "", headerArray);
|
||
}
|
||
else
|
||
{
|
||
excelData = Common.textToDataTable(fileName, extension, headerArray);
|
||
}
|
||
|
||
if (excelData.Columns[0].ColumnName == "error")
|
||
{
|
||
return excelData.Rows[0][0].ToString();
|
||
}
|
||
else if (excelData.Rows.Count < 1)
|
||
{
|
||
return "파일을 확인해 주세요.";
|
||
}
|
||
else
|
||
{
|
||
Regex qidRegex = new Regex(@"((?<!')[a-zA-Z][a-zA-Z0-9]*)");//알파벳으로 시작하고 숫자 또는 언더바
|
||
while (qidRegex.Match(excelData.Rows[0][0].ToString()).ToString() != excelData.Rows[0][0].ToString() || String.IsNullOrEmpty(excelData.Rows[0][0].ToString()))
|
||
{
|
||
excelData.Rows.Remove(excelData.Rows[0]); //KON DATA 파일은 header가 2줄 한줄 버리기
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
//한번 훑어 보면서 양식이 제대로 들어 왔는지 확인?
|
||
|
||
|
||
#region 문항 등록
|
||
QuestionInfo qinfo = new QuestionInfo();
|
||
int attrOrder = 1;
|
||
int itemOrder = 1;
|
||
for (int i = 0; i < excelData.Rows.Count; i++)
|
||
{
|
||
if (String.IsNullOrEmpty(excelData.Rows[i]["variable"].ToString()) == false)
|
||
{
|
||
#region 문항 정리
|
||
qinfo.variableName = excelData.Rows[i]["variable"].ToString();
|
||
qinfo.explain = excelData.Rows[i]["explain"].ToString();
|
||
|
||
setQTYPE(qinfo, excelData.Rows[i]["qtype"].ToString());
|
||
|
||
string maxCount = "";
|
||
if (String.IsNullOrEmpty(excelData.Rows[i]["variable"].ToString()) == false && (excelData.Rows[i]["qtype"].ToString() == "R" || excelData.Rows[i]["qtype"].ToString() == "M"))
|
||
{
|
||
maxCount = excelData.Rows[i]["max_value"].ToString();
|
||
}
|
||
qinfo.maxCount = maxCount;
|
||
qinfo.questionTitle = excelData.Rows[i]["title"].ToString();
|
||
#endregion
|
||
}
|
||
else if (qinfo.variableType != "i")
|
||
{
|
||
#region label 정리
|
||
var labelJSON = new JObject();
|
||
if (String.IsNullOrEmpty(excelData.Rows[i]["attr_value"].ToString()) == false)
|
||
{
|
||
if (qinfo.attrJson.HasValues == false)
|
||
{
|
||
attrOrder = 1;
|
||
qinfo.questionType = "attr";
|
||
qinfo.structureType = "AM1";
|
||
qinfo.attrJson.Add("attr", new JObject());
|
||
}
|
||
|
||
if (excelData.Rows[i]["title"].ToString().ToLower().IndexOf("{t}") > -1)
|
||
{
|
||
excelData.Rows[i]["title"] = excelData.Rows[i]["title"].ToString().Replace("{t}", "").Replace("{T}", "");
|
||
labelJSON.Add("etc", "1");
|
||
}
|
||
else
|
||
{
|
||
labelJSON.Add("etc", "0");
|
||
}
|
||
|
||
labelJSON.Add("except", "0");
|
||
labelJSON.Add("label", excelData.Rows[i]["title"].ToString());
|
||
labelJSON.Add("value", excelData.Rows[i]["attr_value"].ToString());
|
||
|
||
JObject attrObject = qinfo.attrJson["attr"] as JObject;
|
||
attrObject.Add(attrOrder.ToString(), labelJSON);
|
||
attrOrder++;
|
||
}
|
||
else if (String.IsNullOrEmpty(excelData.Rows[i]["title"].ToString()) == false)
|
||
{
|
||
if (qinfo.itemJson.HasValues == false)
|
||
{
|
||
itemOrder = 1;
|
||
qinfo.itemJson.Add(qinfo.itemType, new JObject());
|
||
}
|
||
|
||
labelJSON.Add("label", excelData.Rows[i]["title"].ToString().Replace("{t}", "").Replace("{T}", ""));
|
||
if (qinfo.itemType == "open")
|
||
{
|
||
if (qinfo.variableType == "n")
|
||
{
|
||
labelJSON.Add("option", "num");
|
||
}
|
||
else
|
||
{
|
||
labelJSON.Add("option", "all");
|
||
}
|
||
labelJSON.Add("must", "1");
|
||
}
|
||
else
|
||
{
|
||
labelJSON.Add("value", excelData.Rows[i]["max_value"].ToString());
|
||
|
||
if (qinfo.itemType != "scale") // single, multi
|
||
{
|
||
if (excelData.Rows[i]["title"].ToString().ToLower().IndexOf("{t}") > -1)
|
||
{
|
||
excelData.Rows[i]["title"] = excelData.Rows[i]["title"].ToString();
|
||
labelJSON.Add("etc", "1");
|
||
}
|
||
else
|
||
{
|
||
labelJSON.Add("etc", "0");
|
||
}
|
||
labelJSON.Add("except", "0");
|
||
}
|
||
}
|
||
|
||
JObject itemObject = qinfo.itemJson[qinfo.itemType] as JObject;
|
||
itemObject.Add(itemOrder.ToString(), labelJSON);
|
||
itemOrder++;
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
|
||
if (excelData.Rows.Count - 1 == i || String.IsNullOrEmpty(excelData.Rows[i + 1]["variable"].ToString()) == false)
|
||
{
|
||
JObject optionObject = new JObject();
|
||
|
||
if (qinfo.variableType == "r")
|
||
{
|
||
qinfo.itemJson.Add("rank", JObject.Parse("{\"val\":\"" + qinfo.maxCount + "\",\"max\":\"" + qinfo.maxCount + "\"}"));
|
||
}
|
||
else if (qinfo.variableType == "m" || qinfo.variableType == "o" || qinfo.variableType == "n")
|
||
{
|
||
if (qinfo.variableType == "m" && qinfo.maxCount != "")
|
||
{
|
||
optionObject.Add("max", qinfo.maxCount);
|
||
}
|
||
}
|
||
else if (qinfo.variableType == "nps")
|
||
{
|
||
optionObject.Add("arrow", "");
|
||
optionObject.Add("under_label", "");
|
||
optionObject.Add("reverse", "");
|
||
optionObject.Add("break", "");
|
||
optionObject.Add("npsFlag", "1");
|
||
}
|
||
|
||
if (optionObject.Count > 0)
|
||
{
|
||
qinfo.optionJson.Add("option", optionObject);
|
||
}
|
||
|
||
|
||
// 문항 업로드
|
||
string qid = saveQuestion(projectCode, qinfo);
|
||
|
||
if (qid == "FAIL")
|
||
{
|
||
return "초기화 완료 / 저장 실패";
|
||
}
|
||
|
||
List<string> qinfoList = new List<string>();
|
||
JObject linfoJson = new JObject();
|
||
if (String.IsNullOrEmpty(qinfo.itemType) == false)
|
||
{
|
||
string linfoString = "";
|
||
int attrCount = 1;
|
||
int itemLoop = 1;
|
||
|
||
if (qinfo.attrJson["attr"] != null)
|
||
{
|
||
attrCount = qinfo.attrJson["attr"].Count();
|
||
}
|
||
|
||
if (qinfo.itemType == "scale" || qinfo.itemType == "single" || qinfo.itemType == "rank")
|
||
{
|
||
List<string> linfoList = new List<string>();
|
||
if (qinfo.itemType == "rank")
|
||
{
|
||
itemLoop = Convert.ToInt32(qinfo.maxCount);
|
||
}
|
||
|
||
for (int li = 0; li < qinfo.itemJson[qinfo.itemType].Count(); li++)
|
||
{
|
||
linfoList.Add("\"" + qinfo.itemJson[qinfo.itemType][(li + 1).ToString()]["value"] + "\":\"" + qinfo.itemJson[qinfo.itemType][(li + 1).ToString()]["label"].ToString().Replace("\"", "\\\"") + "\"");
|
||
}
|
||
|
||
linfoString = "{" + string.Join(",", linfoList) + "}";
|
||
}
|
||
else if (qinfo.itemType == "open")
|
||
{
|
||
itemLoop = Convert.ToInt32(qinfo.itemJson[qinfo.itemType].Count());
|
||
//open은 Label상관없이 open
|
||
linfoString = "open";
|
||
}
|
||
else if (qinfo.itemType == "multi")
|
||
{
|
||
itemLoop = Convert.ToInt32(qinfo.itemJson[qinfo.itemType].Count());
|
||
}
|
||
|
||
for (int ai = 0; ai < attrCount; ai++)
|
||
{
|
||
string attrString = string.Empty;
|
||
|
||
if (qinfo.attrJson["attr"] != null)
|
||
{
|
||
attrString = "_" + qinfo.attrJson["attr"][(ai + 1).ToString()]["value"].ToString();
|
||
}
|
||
|
||
for (int ii = 0; ii < itemLoop; ii++)
|
||
{
|
||
string multiString = string.Empty;
|
||
string itemValue = string.Empty;
|
||
string itemLabel = string.Empty;
|
||
|
||
if (qinfo.itemType == "multi")
|
||
{
|
||
multiString = "_" + qinfo.itemJson[qinfo.itemType][(ii + 1).ToString()]["value"].ToString();
|
||
linfoString = "{\"" + qinfo.itemJson[qinfo.itemType][(ii + 1).ToString()]["value"] + "\":\"" + qinfo.itemJson[qinfo.itemType][(ii + 1).ToString()]["label"].ToString().Replace("\"", "\\\"") + "\"}";
|
||
}
|
||
else if (qinfo.itemType == "open")
|
||
{
|
||
multiString = "_" + (ii + 1);
|
||
}
|
||
else if (qinfo.itemType == "rank")
|
||
{
|
||
multiString = "_" + (ii + 1);
|
||
}
|
||
|
||
string sqid = qid + multiString + attrString;
|
||
qinfoList.Add(sqid);
|
||
linfoJson.Add(sqid, Common.GetJObjectFromString(linfoString));
|
||
|
||
if (qinfo.itemType == "multi" && Common.GetNullString(qinfo.itemJson[qinfo.itemType][(ii + 1).ToString()]["etc"]) == "1")//멀티만 기타가 있으면
|
||
{
|
||
string tqid = "T" + qid + multiString + attrString; ;
|
||
qinfoList.Add(tqid);
|
||
linfoJson.Add(tqid, qinfo.itemJson[qinfo.itemType][(ii + 1).ToString()]["label"].ToString() + "(기타)");
|
||
}
|
||
}
|
||
|
||
if (qinfo.itemType == "single" || qinfo.itemType == "rank")
|
||
{
|
||
// 기타 개수대로
|
||
List<string> etcValues = qinfo.itemJson[qinfo.itemType].Where(x => x.Children()["etc"].ToList()[0].ToString() == "1").Select(x => x.Children()["value"].ToList()[0].ToString()).ToList<string>();
|
||
for (int ei = 0; ei < etcValues.Count; ei++)
|
||
{
|
||
string tqid = "T" + qid + "_" + etcValues[ei] + attrString; ;
|
||
qinfoList.Add(tqid);
|
||
linfoJson.Add(tqid, qinfo.itemJson[qinfo.itemType][etcValues[ei]]["label"].ToString() + "(기타)");
|
||
}
|
||
}
|
||
|
||
if (qinfo.attrJson["attr"] != null && Common.GetNullString(qinfo.attrJson["attr"][(ai + 1).ToString()]["etc"]) == "1")//기타가 있으면
|
||
{
|
||
string tqid = qid + attrString + "_AT";
|
||
qinfoList.Add(tqid);
|
||
linfoJson.Add(tqid, qinfo.attrJson["attr"][(ai + 1).ToString()]["label"] + "_기타");
|
||
}
|
||
}
|
||
}
|
||
|
||
// QINFO {"qid":["변수 목록"], ...} QID_multi_attr // info 문항은 "qid":[]
|
||
string sturctureMessage = saveStructure(projectCode, qid, qinfoList, linfoJson);
|
||
|
||
if (String.IsNullOrEmpty(sturctureMessage) == false)
|
||
{
|
||
return "초기화 완료 / STRUCTUIRE 저장 실패";
|
||
}
|
||
|
||
qinfo = new QuestionInfo();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "실패";
|
||
}
|
||
*/
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트의 문항과 관련된 모든 정보 초기화
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns>message</returns>
|
||
public string resetQuestion(string projectCode)
|
||
{
|
||
string returnValue = string.Empty;
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
|
||
#region 문항 초기화
|
||
try
|
||
{
|
||
//QOPTION, QUOTASET, QUOTA은 엉킬수 있으므로 같이 제거
|
||
//어떻게 할까? 테이블에 콘에서 만들어진 건지 리포트에서 만들어 진건지 구별하는 칼럼을 추가할까?
|
||
|
||
mydal.ExecuteSQL(" delete from [QUESTION] where projectCode = '" + projectCode + "' ", connection);
|
||
mydal.ExecuteSQL(" delete from [QOPTION] where projectCode = '" + projectCode + "' ", connection);
|
||
mydal.ExecuteSQL(" delete from [QUOTASET] where projectCode = '" + projectCode + "' ", connection);
|
||
mydal.ExecuteSQL(" delete from [QUOTA] where projectCode = '" + projectCode + "' and (QSORDER is not null or QSORDER <> '') ", connection);
|
||
mydal.ExecuteSQL(" update a set QINFO = N'{}', LINFO = N'{}' from [STRUCTURE] a where projectCode = '" + projectCode + "' ", connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "응답 초기화 실패";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
#endregion
|
||
}
|
||
|
||
/// <summary>
|
||
/// 파일로 Explain 등록
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="fileName">파일 Path</param>
|
||
/// <param name="extension">파일 확장자</param>
|
||
/// <returns>message</returns>
|
||
public string uploadExplain(string projectCode, string fileName, string extension)
|
||
{
|
||
string returnValue = "업로드 성공";
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
try
|
||
{
|
||
#region 파일 정리
|
||
DataTable excelData = new DataTable();
|
||
string[] headerArray = new string[] { "qid", "variable", "title", "explain" };
|
||
|
||
if (extension.ToLower() == ".xlsx")
|
||
{
|
||
excelData = Common.ExceltoDataTable(fileName, "", headerArray);
|
||
}
|
||
else
|
||
{
|
||
excelData = Common.textToDataTable(fileName, extension, headerArray);
|
||
}
|
||
|
||
if (excelData.Columns[0].ColumnName == "error")
|
||
{
|
||
return excelData.Rows[0][0].ToString();
|
||
}
|
||
else if (excelData.Rows.Count < 1)
|
||
{
|
||
return "파일을 확인해 주세요.";
|
||
}
|
||
#endregion
|
||
|
||
#region explain 등록
|
||
foreach (DataRow row in excelData.Rows)
|
||
{
|
||
string updateString = string.Empty;
|
||
updateString += " UPDATE a SET [QUESTIONJSON] = JSON_MODIFY([QUESTIONJSON],'$.explain','" + row["explain"].ToString() + "')" + Environment.NewLine;
|
||
updateString += " from [QUESTION] a" + Environment.NewLine;
|
||
updateString += " where projectCode = '" + projectCode + "' and qid='" + row["qid"].ToString() + "'" + Environment.NewLine;
|
||
|
||
mydal.ExecuteSQL(updateString, connection);
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "실패";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트 문항의 Explain 공백으로 변경
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <returns>message</returns>
|
||
public string resetExplain(string projectCode)
|
||
{
|
||
string returnValue = string.Empty;
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
|
||
#region 문항 초기화
|
||
try
|
||
{
|
||
string updateString = string.Empty;
|
||
updateString += " UPDATE a SET [QUESTIONJSON] = JSON_MODIFY([QUESTIONJSON],'$.explain','')" + Environment.NewLine;
|
||
updateString += " from [QUESTION] a" + Environment.NewLine;
|
||
updateString += " where projectCode = '" + projectCode + "' and JSON_VALUE([QUESTIONJSON], '$.qtype') <> 'description' and JSON_VALUE([QUESTIONJSON],'$.stype') <> 'MM_FILE'";
|
||
|
||
mydal.ExecuteSQL(updateString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "Title 초기화 실패";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
|
||
return returnValue;
|
||
#endregion
|
||
}
|
||
|
||
/// <summary>
|
||
/// 문항 저장
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="qinfo">문항 정보</param>
|
||
|
||
/// <returns>QID</returns>
|
||
public string saveQuestion(string projectCode, QuestionInfo qinfo)
|
||
{
|
||
string returnValue = string.Empty;
|
||
/*
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
|
||
#region 문항 저장
|
||
try
|
||
{
|
||
JObject dataSet = new JObject();
|
||
JObject question = new JObject();
|
||
question.Add("qgroup", "");
|
||
question.Add("rota", "");
|
||
question.Add("variable", qinfo.variableName);
|
||
question.Add("explain", qinfo.explain);
|
||
question.Add("title", qinfo.questionTitle);
|
||
question.Add("stype", qinfo.structureType);
|
||
question.Add("description", "");
|
||
|
||
if (qinfo.itemJson.Count > 0)
|
||
{
|
||
dataSet.Merge(qinfo.itemJson);
|
||
}
|
||
if (qinfo.attrJson.Count > 0)
|
||
{
|
||
dataSet.Merge(qinfo.attrJson);
|
||
}
|
||
|
||
if (dataSet.Count > 0)
|
||
{
|
||
question.Add("dataset", dataSet);
|
||
}
|
||
else
|
||
{
|
||
question.Add("dataset", new JObject());
|
||
}
|
||
|
||
question.Add("datagroup", "");
|
||
question.Add("qtype", qinfo.questionType);
|
||
|
||
if (qinfo.optionJson.Count > 0)
|
||
{
|
||
question.Add("option", qinfo.optionJson);
|
||
}
|
||
else
|
||
{
|
||
question.Add("option", "");
|
||
}
|
||
|
||
string newQID = "Q1";
|
||
string newQorder = "1";
|
||
DataTable newQIDTable = mydal.GetDataTable("select 'Q'+cast(max(cast(replace(QID,'Q','') as int))+1 as nvarchar(max)) as QID, (max(Qorder) + 1) as Qorder FROM [QUESTION] where projectCode = '" + projectCode + "'", connection);
|
||
if (newQIDTable.Rows.Count > 0 && String.IsNullOrEmpty(newQIDTable.Rows[0]["QID"].ToString()) == false)
|
||
{
|
||
newQID = newQIDTable.Rows[0]["QID"].ToString();
|
||
newQorder = newQIDTable.Rows[0]["Qorder"].ToString();
|
||
}
|
||
|
||
string insertString = " insert into [QUESTION]([projectCode], [QID], [Qorder], [QUESTIONJSON], [LOGICJSON])" + Environment.NewLine;
|
||
insertString += " values('" + projectCode + "', '" + newQID + "', " + newQorder + ", json_query(N'" + Common.GetStringFromJson(question) + "'), '')";
|
||
|
||
mydal.ExecuteSQL(insertString, connection);
|
||
returnValue = newQID;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "FAIL";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
#endregion
|
||
*/
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Structure Table 수정
|
||
/// </summary>
|
||
/// <param name="projectCode">프로젝트 Key</param>
|
||
/// <param name="qid">Kon QID</param>
|
||
/// <param name="qinfoList">QINFO 내용</param>
|
||
/// <param name="linfoJson">LINFO 내용</param>
|
||
/// <returns>message</returns>
|
||
public string saveStructure(string projectCode, string qid, List<string> qinfoList, JObject linfoJson)
|
||
{
|
||
string returnValue = string.Empty;
|
||
|
||
MYDAL mydal = new MYDAL();
|
||
var connection = mydal.ConnectNewssak();
|
||
#region structure저장
|
||
try
|
||
{
|
||
string updateString = string.Empty;
|
||
|
||
string qinfoString = string.Empty;
|
||
string linfoString = string.Empty;
|
||
|
||
if (qinfoList.Count > 0)
|
||
{
|
||
qinfoString = "\"" + string.Join("\",\"", qinfoList) + "\"";
|
||
}
|
||
qinfoString = "[" + qinfoString + "]";
|
||
linfoString = Common.GetStringFromJson(linfoJson);
|
||
|
||
updateString += " update a set" + Environment.NewLine;
|
||
updateString += " QINFO = JSON_MODIFY(QINFO,'$." + qid + "',N'" + qinfoString + "')" + Environment.NewLine;
|
||
updateString += " , LINFO = JSON_MODIFY(LINFO,'$." + qid + "',N'" + linfoString + "')" + Environment.NewLine;
|
||
updateString += " from [STRUCTURE] a" + Environment.NewLine;
|
||
updateString += " where projectCode = '" + projectCode + "'";
|
||
|
||
mydal.ExecuteSQL(updateString, connection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Fatal(this.GetType().Name + " > " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message);
|
||
returnValue = "FAIL";
|
||
}
|
||
finally
|
||
{
|
||
mydal.Disconnect(connection);
|
||
}
|
||
#endregion
|
||
return returnValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 문항 타입별 QTYPE 세팅
|
||
/// </summary>
|
||
/// <param name="qinfo">QuestionInfo</param>
|
||
/// <param name="typeString">문항 타입</param>
|
||
/// <returns>QuestionInfo</returns>
|
||
public QuestionInfo setQTYPE(QuestionInfo qinfo, string typeString)
|
||
{
|
||
/*
|
||
qinfo.variableType = typeString.ToLower();
|
||
|
||
switch (typeString.ToLower())
|
||
{
|
||
case "i":
|
||
qinfo.structureType = "DM1";
|
||
qinfo.questionType = "description";
|
||
qinfo.itemType = string.Empty;
|
||
break;
|
||
case "s":
|
||
qinfo.structureType = "SM2";
|
||
qinfo.questionType = "single";
|
||
qinfo.itemType = "single";
|
||
break;
|
||
case "m":
|
||
qinfo.structureType = "MM2";
|
||
qinfo.questionType = "multi";
|
||
qinfo.itemType = "multi";
|
||
break;
|
||
case "r":
|
||
qinfo.structureType = "RM1";
|
||
qinfo.questionType = "rank";
|
||
qinfo.itemType = "multi";
|
||
break;
|
||
case "c":
|
||
qinfo.structureType = "SCM1";
|
||
qinfo.questionType = "scale";
|
||
qinfo.itemType = "scale";
|
||
break;
|
||
case "nps":
|
||
qinfo.structureType = "SCM1";
|
||
qinfo.questionType = "scale";
|
||
qinfo.itemType = "scale";
|
||
break;
|
||
case "n":
|
||
qinfo.structureType = "OM1";
|
||
qinfo.questionType = "open";
|
||
qinfo.itemType = "open";
|
||
break;
|
||
case "o":
|
||
qinfo.structureType = "OM1";
|
||
qinfo.questionType = "open";
|
||
qinfo.itemType = "open";
|
||
break;
|
||
}
|
||
*/
|
||
return qinfo;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 프로젝트 타입 or Status 반환
|
||
/// </summary>
|
||
/// <param name="type">0:타입, 그외:Status</param>
|
||
/// <param name="value">index 값</param>
|
||
/// <returns>프로젝트 타입 or Status</returns>
|
||
public string setProjectTypeStatus(int type, string value)
|
||
{
|
||
string returnValue = value;
|
||
|
||
if (Common.IsNumeric(value))
|
||
{
|
||
int index = Convert.ToInt32(value);
|
||
if (index > 0 && index < 4)
|
||
{
|
||
string[] labelArray = new string[3];
|
||
|
||
if (type == 0)
|
||
{
|
||
labelArray = new string[] { "온라인", "CAPI", "GANG" };
|
||
}
|
||
else
|
||
{
|
||
labelArray = new string[] { "준비", "진행", "완료" };
|
||
}
|
||
|
||
returnValue = labelArray[(index - 1)];
|
||
}
|
||
else if (type == 1 && index == 9)
|
||
{
|
||
returnValue = "완료";
|
||
}
|
||
}
|
||
return returnValue;
|
||
}
|
||
|
||
|
||
/*************************나중에 별도의 클래스로 뺄수도 있음*********************************/
|
||
public string getDimension(int dimensionValue)
|
||
{
|
||
string dimensionString = "";
|
||
switch (dimensionValue)
|
||
{
|
||
case 0:
|
||
dimensionString = "info";
|
||
break;
|
||
case 1:
|
||
dimensionString = "scalar";
|
||
break;
|
||
case 2:
|
||
dimensionString = "matrix";
|
||
break;
|
||
case 3:
|
||
dimensionString = "tensor";
|
||
break;
|
||
case 9:
|
||
dimensionString = "auto";
|
||
break;
|
||
|
||
}
|
||
|
||
return dimensionString;
|
||
}
|
||
|
||
public string getType(string typeString)
|
||
{
|
||
string type = "";
|
||
|
||
switch (typeString.ToLower())
|
||
{
|
||
case "single":
|
||
type = "21";
|
||
break;
|
||
case "scale":
|
||
type = "22";
|
||
break;
|
||
case "multi":
|
||
type = "31";
|
||
break;
|
||
case "numeric":
|
||
type = "41";
|
||
break;
|
||
|
||
}
|
||
|
||
return type;
|
||
}
|
||
|
||
public string getTypeString(string type)
|
||
{
|
||
string typeString = "";
|
||
|
||
switch (type.ToLower())
|
||
{
|
||
case "21":
|
||
typeString = "single";
|
||
break;
|
||
case "22":
|
||
typeString = "scale";
|
||
break;
|
||
case "31":
|
||
typeString = "multi";
|
||
break;
|
||
case "41":
|
||
typeString = "numeric";
|
||
break;
|
||
|
||
}
|
||
|
||
return typeString;
|
||
}
|
||
|
||
public string clearReserveString(string inputString)
|
||
{
|
||
string returnString = inputString;
|
||
returnString = Regex.Replace(returnString, @"<", "<");
|
||
returnString = Regex.Replace(returnString, @">", ">");
|
||
returnString = Common.StripHTML(returnString).Replace("\r", string.Empty).Replace("\n", " ");
|
||
returnString = Regex.Replace(returnString, @"{[T|t](?!N)(\|?.)*}|{[TN|tn](\|?.)*}|{[N|n]}", string.Empty);
|
||
returnString = Regex.Replace(returnString, @"{([^}]+)}", string.Empty);
|
||
|
||
return returnString;
|
||
}
|
||
}
|
||
}
|