471 lines
24 KiB

using EasyBL.WebApi.Message;
using EasyNet;
using Entity;
using Entity.Sugar;
using Entity.ViewModels;
using JumpKick.HttpLib;
using Newtonsoft.Json;
using SqlSugar;
using SqlSugar.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace EasyBL.WEBAPP.ShowEasy
{
public class ServiceQSMaintain_UpdService : ServiceBase
{
public static string LANGUAGEID = "zh-TW";
#region 展館服務報價表管理編輯(單筆查詢)
/// <summary>
/// 展館服務報價表管理編輯(單筆查詢)
/// </summary>
/// <param name="i_crm"></param>
/// <returns></returns>
public ResponseMessage QueryOne(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
var db = SugarBase.GetIntance();
try
{
do
{
var sQSID = _fetchString(i_crm, @"QSID");
var sLangID = _fetchString(i_crm, @"LangID");
if (string.IsNullOrEmpty(sLangID))
{
sLangID = LANGUAGEID;
}
var oEntity = db.Queryable<SETB_PDT_ServiceQS, OTB_SYS_Members, OTB_SYS_Members>
((t1, t2, t3) =>
new object[] {
JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
}
)
.Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.QSID == sQSID && t1.LangID == sLangID)
.Select((t1, t2, t3) => new SETB_PDT_ServiceQS
{
QSID = SqlFunc.GetSelfAndAutoFill(t1.QSID),
CreateUserName = t2.MemberName,
ModifyUserName = t3.MemberName
})
.Single();
if (oEntity.QuotationType == WebAppGlobalConstWord.STACKER) {
//堆高機
var lstServiceCostRules = db.Queryable<SETB_PDT_ServiceCostRules>()
.WhereIF(!string.IsNullOrEmpty(sQSID), x => x.QSID == sQSID)
.OrderBy(x => x.CreateDate)
.Select(x => new View_PDT_ServiceCostRules { Guid = x.Guid, QSID = x.QSID, Weight_Min = x.Weight_Min, Weight_Max = x.Weight_Max, Price = x.Price, PricingMode = x.PricingMode, Memo = x.Memo, CreateDate = x.CreateDate })
.ToList();
int i = 1;
foreach (var ServiceCostRules in lstServiceCostRules)
{
ServiceCostRules.Index = i;
i++;
}
oEntity.CostRules = lstServiceCostRules.Count > 0 ? JsonConvert.SerializeObject(lstServiceCostRules) : "[]";
oEntity.TruckCostRules = "[]";
oEntity.TruckHolidayPay = "[]";
oEntity.TruckMarkupByModel = "[]";
}
else if (oEntity.QuotationType == WebAppGlobalConstWord.TRUCK)
{
oEntity.CostRules = "[]";
//卡車費用表
var lstServiceTruckCostRules = db.Queryable<SETB_PDT_ServiceTruckCostRules>()
.WhereIF(!string.IsNullOrEmpty(sQSID), x => x.QSID == sQSID)
.ToList();
oEntity.TruckCostRules = lstServiceTruckCostRules.Count > 0 ? JsonConvert.SerializeObject(lstServiceTruckCostRules) : "[]";
//假日加班費
var lstTruckHolidayPay = db.Queryable<SETB_PDT_ServiceTruckOtherCost>()
.WhereIF(!string.IsNullOrEmpty(sQSID), x => x.QSID == sQSID && x.Type=="1")
.ToList();
oEntity.TruckHolidayPay = lstTruckHolidayPay.Count > 0 ? JsonConvert.SerializeObject(lstTruckHolidayPay) : "[]";
//車型加價
var lstTruckMarkupByModel = db.Queryable<SETB_PDT_ServiceTruckOtherCost>()
.WhereIF(!string.IsNullOrEmpty(sQSID), x => x.QSID == sQSID && x.Type == "2")
.ToList();
oEntity.TruckMarkupByModel = lstTruckMarkupByModel.Count > 0 ? JsonConvert.SerializeObject(lstTruckMarkupByModel) : "[]";
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, oEntity);
} while (false);
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ServiceQSMaintain_UpdService), "", "QueryOne(展館服務報價表管理編輯(單筆查詢))", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展館服務報價表管理編輯(單筆查詢)
#region 展館服務報價表管理編輯(新增)
/// <summary>
/// 展館服務報價表管理編輯(新增)
/// </summary>
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
/// <returns></returns>
public ResponseMessage Insert(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
string sQSID = Guid.NewGuid().ToString();
var iRel = 0;
var lstCostRules = _fetchCusEntity<SETB_PDT_ServiceCostRules>(i_crm, "CostRules");
var lstTruckCostRules = _fetchCusEntity<SETB_PDT_ServiceTruckCostRules>(i_crm, "TruckCostRules");
var lstTruckHolidayPay = _fetchCusEntity<SETB_PDT_ServiceTruckOtherCost>(i_crm, "TruckHolidayPay");
var lstTruckMarkupByModel = _fetchCusEntity<SETB_PDT_ServiceTruckOtherCost>(i_crm, "TruckMarkupByModel");
var oEntity = _fetchEntity<SETB_PDT_ServiceQS>(i_crm);
_setEntityBase(oEntity, i_crm);
oEntity.QSID = sQSID;
oEntity.CostRules = null;
oEntity.TruckCostRules = null;
oEntity.TruckHolidayPay = null;
oEntity.TruckMarkupByModel = null;
var saArgument = db.Queryable<OTB_SYS_Arguments>()
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N" && x.ArgumentClassID == "LanCountry" && x.LevelOfArgument == 0)
.OrderBy(x => x.OrderByValue)
.ToList();
foreach (var Argument in saArgument)
{
oEntity.LangID = Argument.ArgumentID;
iRel = db.Insertable(oEntity).ExecuteCommand();
}
if (lstCostRules != null && oEntity.QuotationType== WebAppGlobalConstWord.STACKER)//堆高機費用
{
List<SETB_PDT_ServiceCostRules> lstServiceCostRules = new List<SETB_PDT_ServiceCostRules>();
SETB_PDT_ServiceCostRules model = new SETB_PDT_ServiceCostRules();
foreach (var SETB_PDT_ServiceCostRulesModel in lstCostRules)
{
model = new SETB_PDT_ServiceCostRules();
model.Guid = SETB_PDT_ServiceCostRulesModel.Guid;
model.QSID = oEntity.QSID;
model.Weight_Min = SETB_PDT_ServiceCostRulesModel.Weight_Min;
model.Weight_Max = SETB_PDT_ServiceCostRulesModel.Weight_Max;
model.Price = SETB_PDT_ServiceCostRulesModel.Price;
model.PricingMode = SETB_PDT_ServiceCostRulesModel.PricingMode;
model.Memo = SETB_PDT_ServiceCostRulesModel.Memo;
model.CreateDate = DateTime.Now;
lstServiceCostRules.Add(model);
}
if (lstServiceCostRules.Count() > 0)
{
iRel = db.Insertable(lstServiceCostRules).ExecuteCommand();
}
}
if (lstTruckCostRules != null && oEntity.QuotationType == WebAppGlobalConstWord.TRUCK)//卡車費用
{
List<SETB_PDT_ServiceTruckCostRules> lstServiceTruckCostRules = new List<SETB_PDT_ServiceTruckCostRules>();
SETB_PDT_ServiceTruckCostRules model = new SETB_PDT_ServiceTruckCostRules();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckCostRules)
{
model = new SETB_PDT_ServiceTruckCostRules();
model.QSID = oEntity.QSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.CityID = SETB_PDT_ServiceTruckCostRulesModel.CityID;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstServiceTruckCostRules.Add(model);
}
if (lstServiceTruckCostRules.Count() > 0)
{
iRel = db.Insertable(lstServiceTruckCostRules).ExecuteCommand();
}
}
if (lstTruckHolidayPay != null && oEntity.QuotationType == WebAppGlobalConstWord.TRUCK)//假日加班費
{
List<SETB_PDT_ServiceTruckOtherCost> lstTruckHolidayPays = new List<SETB_PDT_ServiceTruckOtherCost>();
SETB_PDT_ServiceTruckOtherCost model = new SETB_PDT_ServiceTruckOtherCost();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckHolidayPay)
{
model = new SETB_PDT_ServiceTruckOtherCost();
model.QSID = oEntity.QSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.Type = SETB_PDT_ServiceTruckCostRulesModel.Type;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstTruckHolidayPays.Add(model);
}
if (lstTruckHolidayPays.Count() > 0)
{
iRel = db.Insertable(lstTruckHolidayPays).ExecuteCommand();
}
}
if (lstTruckMarkupByModel != null && oEntity.QuotationType == WebAppGlobalConstWord.TRUCK)//車型加價
{
List<SETB_PDT_ServiceTruckOtherCost> lstTruckHolidayPays = new List<SETB_PDT_ServiceTruckOtherCost>();
SETB_PDT_ServiceTruckOtherCost model = new SETB_PDT_ServiceTruckOtherCost();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckMarkupByModel)
{
model = new SETB_PDT_ServiceTruckOtherCost();
model.QSID = oEntity.QSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.Type = SETB_PDT_ServiceTruckCostRulesModel.Type;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstTruckHolidayPays.Add(model);
}
if (lstTruckHolidayPays.Count() > 0)
{
iRel = db.Insertable(lstTruckHolidayPays).ExecuteCommand();
}
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ServiceQSMaintain_UpdService), @"展館服務報價表管理編輯", @"Add(展館服務報價表管理編輯(新增))", @"", @"", @"");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展館服務報價表管理編輯(新增)
#region 展館服務報價表管理編輯(修改)
/// <summary>
/// 展館服務報價表管理編輯(修改)
/// </summary>
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
/// <returns></returns>
public ResponseMessage Update(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var lstCostRules = _fetchCusEntity<SETB_PDT_ServiceCostRules>(i_crm, "CostRules");
var lstTruckCostRules = _fetchCusEntity<SETB_PDT_ServiceTruckCostRules>(i_crm, "TruckCostRules");
var lstTruckHolidayPay = _fetchCusEntity<SETB_PDT_ServiceTruckOtherCost>(i_crm, "TruckHolidayPay");
var lstTruckMarkupByModel = _fetchCusEntity<SETB_PDT_ServiceTruckOtherCost>(i_crm, "TruckMarkupByModel");
var sQSID = _fetchString(i_crm, @"QSID");
var sQuotationType = _fetchString(i_crm, @"QuotationType");
var oNewEntity = _fetchEntity<SETB_PDT_ServiceQS>(i_crm);
_setEntityBase(oNewEntity, i_crm);
oNewEntity.CostRules = null;
var iRel = db.Updateable(oNewEntity)
.IgnoreColumns(x => new
{
x.CreateUser,
x.CreateDate
}).ExecuteCommand();
iRel = db.Deleteable<SETB_PDT_ServiceCostRules>().Where(x => x.QSID == sQSID).ExecuteCommand();
if (lstCostRules != null && sQuotationType == WebAppGlobalConstWord.STACKER)//堆高機費用
{
List<SETB_PDT_ServiceCostRules> lstServiceCostRules = new List<SETB_PDT_ServiceCostRules>();
SETB_PDT_ServiceCostRules model = new SETB_PDT_ServiceCostRules();
foreach (var SETB_PDT_ServiceCostRulesModel in lstCostRules)
{
model = new SETB_PDT_ServiceCostRules();
model.Guid = SETB_PDT_ServiceCostRulesModel.Guid;
model.QSID = sQSID;
model.Weight_Min = SETB_PDT_ServiceCostRulesModel.Weight_Min;
model.Weight_Max = SETB_PDT_ServiceCostRulesModel.Weight_Max;
model.Price = SETB_PDT_ServiceCostRulesModel.Price;
model.PricingMode = SETB_PDT_ServiceCostRulesModel.PricingMode;
model.Memo = SETB_PDT_ServiceCostRulesModel.Memo;
model.CreateDate = DateTime.Now;
lstServiceCostRules.Add(model);
}
if (lstServiceCostRules.Count() > 0)
{
iRel = db.Insertable(lstServiceCostRules).ExecuteCommand();
}
}
iRel = db.Deleteable<SETB_PDT_ServiceTruckCostRules>().Where(x => x.QSID == sQSID).ExecuteCommand();
if (lstTruckCostRules != null && sQuotationType == WebAppGlobalConstWord.TRUCK)//卡車費用
{
List<SETB_PDT_ServiceTruckCostRules> lstServiceTruckCostRules = new List<SETB_PDT_ServiceTruckCostRules>();
SETB_PDT_ServiceTruckCostRules model = new SETB_PDT_ServiceTruckCostRules();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckCostRules)
{
model = new SETB_PDT_ServiceTruckCostRules();
model.QSID = sQSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.CityID = SETB_PDT_ServiceTruckCostRulesModel.CityID;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstServiceTruckCostRules.Add(model);
}
if (lstServiceTruckCostRules.Count() > 0)
{
iRel = db.Insertable(lstServiceTruckCostRules).ExecuteCommand();
}
}
iRel = db.Deleteable<SETB_PDT_ServiceTruckOtherCost>().Where(x => x.QSID == sQSID).ExecuteCommand();
if (lstTruckHolidayPay != null && sQuotationType == WebAppGlobalConstWord.TRUCK)//假日加班費
{
List<SETB_PDT_ServiceTruckOtherCost> lstTruckHolidayPays = new List<SETB_PDT_ServiceTruckOtherCost>();
SETB_PDT_ServiceTruckOtherCost model = new SETB_PDT_ServiceTruckOtherCost();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckHolidayPay)
{
model = new SETB_PDT_ServiceTruckOtherCost();
model.QSID = sQSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.Type = SETB_PDT_ServiceTruckCostRulesModel.Type;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstTruckHolidayPays.Add(model);
}
if (lstTruckHolidayPays.Count() > 0)
{
iRel = db.Insertable(lstTruckHolidayPays).ExecuteCommand();
}
}
if (lstTruckMarkupByModel != null && sQuotationType == WebAppGlobalConstWord.TRUCK)//車型加價
{
List<SETB_PDT_ServiceTruckOtherCost> lstTruckHolidayPays = new List<SETB_PDT_ServiceTruckOtherCost>();
SETB_PDT_ServiceTruckOtherCost model = new SETB_PDT_ServiceTruckOtherCost();
foreach (var SETB_PDT_ServiceTruckCostRulesModel in lstTruckMarkupByModel)
{
model = new SETB_PDT_ServiceTruckOtherCost();
model.QSID = sQSID;
model.TruckID = SETB_PDT_ServiceTruckCostRulesModel.TruckID;
model.Type = SETB_PDT_ServiceTruckCostRulesModel.Type;
model.Price = SETB_PDT_ServiceTruckCostRulesModel.Price;
lstTruckHolidayPays.Add(model);
}
if (lstTruckHolidayPays.Count() > 0)
{
iRel = db.Insertable(lstTruckHolidayPays).ExecuteCommand();
}
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ServiceQSMaintain_UpdService), @"展館服務報價表管理編輯", @"Update(展館服務報價表管理編輯(修改))", @"", @"", @"");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展館服務報價表管理編輯(修改)
#region 展館服務報價表管理編輯(刪除)
/// <summary>
/// 展館服務報價表管理編輯(刪除)
/// </summary>
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
/// <returns></returns>
public ResponseMessage Delete(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sQSID = _fetchString(i_crm, @"QSID");
var iRel = db.Deleteable<SETB_PDT_ServiceQS>().Where(x => x.QSID == sQSID).ExecuteCommand();
var iRel1 = db.Deleteable<SETB_PDT_ServiceCostRules>().Where(x => x.QSID == sQSID).ExecuteCommand();
iRel1 = db.Deleteable<SETB_PDT_ServiceTruckCostRules>().Where(x => x.QSID == sQSID).ExecuteCommand();
iRel1 = db.Deleteable<SETB_PDT_ServiceTruckOtherCost>().Where(x => x.QSID == sQSID).ExecuteCommand();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ServiceQSMaintain_UpdService), @"展館服務報價表管理編輯", @"Delete(展館服務報價表管理編輯(刪除))", @"", @"", @"");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 展館服務報價表管理編輯(刪除)
}
}