/// <summary> /// 檢核預審名單 /// </summary> /// <param name="campaignId">行銷活動代號</param> /// <returns>檢核結果</returns> public ValidatePreAdjustResultDTO ValidatePreAdjust(string campaignId) { ValidatePreAdjustResultDTO result = null; string validateMsg = null; int? campaignListCount = null; if (String.IsNullOrEmpty(campaignId)) { throw new ArgumentNullException("campaignId"); } CampaignDO campaignInfo = CampaignService.GetCampaign(campaignId); if (campaignInfo == null) { validateMsg = "ILRC行銷活動編碼,輸入錯誤。"; } else if (!DateTime.TryParseExact(campaignInfo.ExpectedCloseDate, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out DateTime tempCloseDate)) { throw new InvalidOperationException("Convert ExpectedCloseDate Fail"); } else if (tempCloseDate < DateTime.Now.Date) { validateMsg = "此行銷活動已結案,無法進入匯入作業。"; } else { CampaignImportLogDO importLogInfo = CampaignService.GetImportLog(campaignInfo.CampaignId); if (importLogInfo != null) { validateMsg = $"此行銷活動已於{importLogInfo.ImportDate}匯入過,無法再進行匯入。"; } } if (String.IsNullOrEmpty(validateMsg)) { campaignListCount = CampaignService.GetCampaignListCount(campaignInfo.CampaignId, campaignInfo.ExecutionPathway); } result = new ValidatePreAdjustResultDTO() { ErrorMessage = validateMsg, CampaignListCount = campaignListCount, }; return(result); }
/// <summary> /// 取得行銷活動資訊 /// </summary> /// <param name="campaignId">行銷活動代號</param> /// <returns></returns> public CampaignDO GetCampaign(string campaignId) { CampaignDO campaign = null; if (String.IsNullOrEmpty(campaignId)) { throw new ArgumentNullException("campaignId"); } campaign = new CampaignDAO().Get(campaignId); return(campaign); }
/// <summary> /// 取得行銷活動資訊 /// </summary> /// <param name="campaignId">行銷活動編號</param> /// <returns>行銷活動資訊</returns> public CampaignDO Get(string campaignId) { CampaignDO result = null; if (String.IsNullOrEmpty(campaignId)) { throw new ArgumentNullException("campaignId"); } string query = @" SELECT [CMPN_ID],[CMPN_NM],[CMPN_DSC],[CMPN_TP_ID],[INL_OU_ID],[INL_EMPE_NO],[CMPN_PROM_PRD_ID], [CMPN_FILTER_TYPID],[CMPN_EXPC_STRT_DT],[CMPN_EXPC_END_DT],[CMPN_EXPC_CLOSE_DT],[CMPN_DETAIL_DSC], [CMPN_EXPC_CNL_ID],[CMPN_FRQ_TP_ID],[CMPN_BASE_DSC],[CMPN_APPROVE_STS],[CMPN_ASSIGN_MIS], [CREATED_DT],[LST_MTN_DT],[CRSS_FLG] FROM [CMPN] WHERE CMPN_ID = @CampaignId;"; using (SqlConnection connection = DbConnection(Connection.CMPN)) { SqlCommand command = new SqlCommand(query, connection); command.Parameters.Add(new SqlParameter("@CampaignId", SqlDbType.NVarChar) { Value = campaignId }); connection.Open(); DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dt); if (dt.Rows.Count == 1) { result = ConvertCampaignDO(dt.Rows[0]); } adapter = null; dt = null; command = null; } return(result); }
/// <summary> /// 匯入預審名單 /// </summary> /// <param name="campaignId">行銷活動代號</param> /// <param name="userId">登入帳號</param> /// <param name="userName">登入姓名</param> /// <returns>處理結果</returns> public ImportPreAdjustResultDTO ImportPreAdjust(string campaignId, string userId, string userName) { ImportPreAdjustResultDTO result = null; if (String.IsNullOrEmpty(campaignId)) { throw new ArgumentNullException("campaignId"); } ValidatePreAdjustResultDTO validateResult = ValidatePreAdjust(campaignId); if (validateResult == null) { var e = new InvalidOperationException("ValidateResult not found"); e.Data["campaignId"] = campaignId; throw e; } else if (!String.IsNullOrEmpty(validateResult.ErrorMessage)) { result = new ImportPreAdjustResultDTO() { ValidateMessage = validateResult.ErrorMessage, }; return(result); } CampaignDO campaignInfo = CampaignService.GetCampaign(campaignId); if (campaignInfo == null) { var e = new InvalidOperationException("CampaignInfo not found"); e.Data["campaignId"] = campaignId; throw e; } IEnumerable <CampaignListDO> campaignList = CampaignService.GetCampaignList( campaignInfo.CampaignId, campaignInfo.ExecutionPathway); if ((campaignList == null) || (campaignList.Count() == 0)) { var e = new InvalidOperationException("CampaignList not found"); e.Data["CampaignId"] = campaignInfo.CampaignId; e.Data["ExecutionPathway"] = campaignInfo.ExecutionPathway; throw e; } DateTime currentTime = DateTime.Now; CampaignImportLogDO importLog = new CampaignImportLogDO() { CampaignId = campaignInfo.CampaignId, ExpectedStartDate = campaignInfo.ExpectedStartDateTime, ExpectedEndDate = campaignInfo.ExpectedEndDateTime, Count = campaignList.Count(), ImportUserId = userId, ImportUserName = userName, ImportDate = currentTime.ToString("yyyy/MM/dd"), }; List <PreAdjustDO> preAdjustList = new List <PreAdjustDO>(); PreAdjustDO preAdjust = null; foreach (CampaignListDO item in campaignList) { preAdjust = null; preAdjust = new PreAdjustDO() { CampaignId = campaignInfo.CampaignId, Id = item.CustomerId, ProjectName = item.Col1, ProjectAmount = Convert.ToDecimal(item.Col2), CloseDate = item.Col3, ImportDate = currentTime.ToString("yyyy/MM/dd"), Kind = item.Col4, Status = "待生效", }; preAdjustList.Add(preAdjust); } if (preAdjustList.Count == 0) { throw new InvalidOperationException("preAdjustList not found"); } CustomerDAO aboutDataDAO = new CustomerDAO(); CustomerShortDO aboutData = null; PreAdjustDO tempPreAdjust = null; foreach (CampaignListDO item in campaignList) { aboutData = aboutDataDAO.GetShortData(item.CustomerId); if (aboutData == null) { var e = new InvalidOperationException("AboutData not found"); e.Data["CustomerId"] = item.CustomerId; throw e; } tempPreAdjust = preAdjustList.FirstOrDefault(x => x.Id == item.CustomerId); if (tempPreAdjust == null) { var e = new InvalidOperationException("tempPreAdjust not found"); e.Data["CustomerId"] = item.CustomerId; throw e; } tempPreAdjust.ChineseName = aboutData.ChineseName; tempPreAdjust.ClosingDay = aboutData.ClosingDay; tempPreAdjust.PayDeadline = aboutData.PayDeadline; tempPreAdjust.MobileTel = aboutData.MobileTel; } SaveCampaignData(importLog, preAdjustList); result = new ImportPreAdjustResultDTO(); return(result); }