using System;
using System.Collections.Generic;
using System.Data;
using SuperMap.RealEstate.ServiceModel;
using Business = SuperMap.RealEstate.PlatForm.Dashboard.Business;
using HCC = HZQR.Common.Common;
using HZQR.Common;
namespace EShang.Common.GeneralMethod
{
///
/// 门店盈利贡献表相关方法
/// 2024/11/1 17:14:24自动生成
///
public class PROFITCONTRIBUTEHelper
{
#region 获取门店盈利贡献表列表
///
/// 获取门店盈利贡献表列表
///
/// 事务管理器
/// 查询结果总数
/// 查询条件对象
public static List GetPROFITCONTRIBUTEList(Transaction transaction,
ref int TotalCount, Model.SearchModel searchModel)
{
List PROFITCONTRIBUTEList = new List();
string WhereSQL = "", RowFilterSQL = "";
if (searchModel.SearchParameter != null)
{
WhereSQL = OperationDataHelper.GetWhereSQL(searchModel.SearchParameter, searchModel.QueryType, "",
"BUSINESSPROJECT_IDS", "EVALUATE_TYPES", "SERVERPART_IDS", "SERVERPARTSHOP_IDS", "STATISTICS_DATE_Start", "STATISTICS_DATE_End");
if (WhereSQL != "")
{
WhereSQL = " WHERE " + WhereSQL;
}
//查询经营项目内码
if (searchModel.SearchParameter.BUSINESSPROJECT_IDS.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "BUSINESSPROJECT_ID IN (" + searchModel.SearchParameter.BUSINESSPROJECT_IDS + ")";
}
//查询评判指标1: 贡献度(40%);2:盈利贡献评分(30%);3:车流弹性系数(20%);4: 商家风险指数(-10%);5:基础消费适配度(10%);6: 顾客吸引力指数(10%);7:消费体验与环境适应性(5-10%))
if (searchModel.SearchParameter.EVALUATE_TYPES.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "EVALUATE_TYPE IN (" + searchModel.SearchParameter.EVALUATE_TYPES + ")";
}
//查询服务区内码
if (searchModel.SearchParameter.SERVERPART_IDS.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "SERVERPART_ID IN (" + searchModel.SearchParameter.SERVERPART_IDS + ")";
}
//查询门店内码
if (searchModel.SearchParameter.SERVERPARTSHOP_IDS.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "SERVERPARTSHOP_ID IN ('" +
searchModel.SearchParameter.SERVERPARTSHOP_IDS.Replace(",", "','") + "')";
}
//查询统计日期
if (searchModel.SearchParameter.STATISTICS_DATE_Start.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "SUBSTR(STATISTICS_DATE,1,8) >= " +
DateTime.Parse(searchModel.SearchParameter.STATISTICS_DATE_Start).ToString("yyyyMMdd");
}
if (searchModel.SearchParameter.STATISTICS_DATE_End.TryParseToString() != "")
{
WhereSQL += (WhereSQL == "" ? " WHERE " : " AND ") + "SUBSTR(STATISTICS_DATE,1,8) <= " +
DateTime.Parse(searchModel.SearchParameter.STATISTICS_DATE_End).ToString("yyyyMMdd");
}
}
DataTable dtPROFITCONTRIBUTE = new Business.CATERINGGROSSMARGIN(transaction).ExecuteDataTable(
"SELECT * FROM PLATFORM_DASHBOARD.T_PROFITCONTRIBUTE" + WhereSQL);
//增加组合查询条件
if (searchModel.keyWord != null && !string.IsNullOrWhiteSpace(searchModel.keyWord.Key))
{
foreach (string KeyName in searchModel.keyWord.Key.Split(','))
{
RowFilterSQL += (RowFilterSQL == "" ? "" : " or ") +
KeyName + " like '%" + searchModel.keyWord.Value + "%'";
}
}
if (RowFilterSQL != "")
{
dtPROFITCONTRIBUTE.DefaultView.RowFilter = RowFilterSQL;
}
//排序:
dtPROFITCONTRIBUTE.DefaultView.Sort = searchModel.SortStr;
dtPROFITCONTRIBUTE = dtPROFITCONTRIBUTE.DefaultView.ToTable();
//获取查询结果总记录条数
TotalCount = dtPROFITCONTRIBUTE.Rows.Count;
//根据传入的页码和每页显示条数返回结果
dtPROFITCONTRIBUTE = CommonHelper.GetDataTableWithPageSize(dtPROFITCONTRIBUTE, searchModel.PageSize, searchModel.PageIndex);
foreach (DataRow drPROFITCONTRIBUTE in dtPROFITCONTRIBUTE.Rows)
{
Model.PROFITCONTRIBUTEModel profitcontributeModel = new Model.PROFITCONTRIBUTEModel();
//绑定门店盈利贡献表数据对象
BindDataRowToModel(drPROFITCONTRIBUTE, profitcontributeModel);
PROFITCONTRIBUTEList.Add(profitcontributeModel);
}
return PROFITCONTRIBUTEList;
}
#region 绑定model
///
/// 绑定model
///
/// datarow数据源
/// model对象
public static void BindDataRowToModel(DataRow drPROFITCONTRIBUTE, Model.PROFITCONTRIBUTEModel profitcontributeModel)
{
if (drPROFITCONTRIBUTE["PROFITCONTRIBUTE_ID"].ToString() != "")
{
profitcontributeModel.PROFITCONTRIBUTE_ID = drPROFITCONTRIBUTE["PROFITCONTRIBUTE_ID"].TryParseToInt(); //内码
}
if (drPROFITCONTRIBUTE["PROFITCONTRIBUTE_PID"].ToString() != "")
{
profitcontributeModel.PROFITCONTRIBUTE_PID = drPROFITCONTRIBUTE["PROFITCONTRIBUTE_PID"].TryParseToInt(); //父级内码
}
if (!string.IsNullOrWhiteSpace(drPROFITCONTRIBUTE["STATISTICS_DATE"].ToString()))
{
//统计日期
profitcontributeModel.STATISTICS_DATE = HCC.Common.TranslateDateTime(drPROFITCONTRIBUTE["STATISTICS_DATE"].ToString());
}
if (drPROFITCONTRIBUTE["SERVERPART_ID"].ToString() != "")
{
profitcontributeModel.SERVERPART_ID = drPROFITCONTRIBUTE["SERVERPART_ID"].TryParseToInt(); //服务区内码
}
profitcontributeModel.SERVERPART_NAME = drPROFITCONTRIBUTE["SERVERPART_NAME"].ToString(); //服务区名称
profitcontributeModel.SERVERPARTSHOP_ID = drPROFITCONTRIBUTE["SERVERPARTSHOP_ID"].ToString(); //门店内码
profitcontributeModel.SERVERPARTSHOP_NAME = drPROFITCONTRIBUTE["SERVERPARTSHOP_NAME"].ToString(); //门店名称
if (drPROFITCONTRIBUTE["BUSINESSPROJECT_ID"].ToString() != "")
{
profitcontributeModel.BUSINESSPROJECT_ID = drPROFITCONTRIBUTE["BUSINESSPROJECT_ID"].TryParseToInt(); //经营项目内码
}
profitcontributeModel.BUSINESSPROJECT_NAME = drPROFITCONTRIBUTE["BUSINESSPROJECT_NAME"].ToString(); //经营项目名称
if (drPROFITCONTRIBUTE["BUSINESSTRADETYPE"].ToString() != "")
{
profitcontributeModel.BUSINESSTRADETYPE = drPROFITCONTRIBUTE["BUSINESSTRADETYPE"].TryParseToShort(); //经营模式(1:自营便利店,2:自营餐饮,3:商铺租赁)
}
if (drPROFITCONTRIBUTE["EVALUATE_TYPE"].ToString() != "")
{
profitcontributeModel.EVALUATE_TYPE = drPROFITCONTRIBUTE["EVALUATE_TYPE"].TryParseToShort(); //评判指标1: 贡献度(40%);2:盈利贡献评分(30%);3:车流弹性系数(20%);4: 商家风险指数(-10%);5:基础消费适配度(10%);6: 顾客吸引力指数(10%);7:消费体验与环境适应性(5-10%))
}
if (drPROFITCONTRIBUTE["EVALUATE_SCORE"].ToString() != "")
{
profitcontributeModel.EVALUATE_SCORE = drPROFITCONTRIBUTE["EVALUATE_SCORE"].TryParseToDouble(); //指标评分
}
if (drPROFITCONTRIBUTE["SABFI_SCORE"].ToString() != "")
{
profitcontributeModel.SABFI_SCORE = drPROFITCONTRIBUTE["SABFI_SCORE"].TryParseToDouble(); //SABFI综合评分
}
if (drPROFITCONTRIBUTE["SABFI_TYPE"].ToString() != "")
{
profitcontributeModel.SABFI_TYPE = drPROFITCONTRIBUTE["SABFI_TYPE"].TryParseToShort(); //SABFI指数应用标准:
A类服务区(高流量):设定高基准,适合高盈利和高吸引力的门店。
B类服务区(中高流量):基准适当降低,注重刚需及盈利性门店。
C类服务区(中流量):适当降低吸引力和盈利标准,重点关注商家持续性。
D类服务区(低流量):低基准,优先满足基本消费需求。
优先保留(SABFI > 80):高盈利、高适配,适合拓展到其他服务区。
适当优化(SABFI 60-80):盈利表现良好,具有一定提升空间。
重点关注(SABFI 40-60):盈利不稳定,需定期关注,适时调整。
建议替换(SABFI < 40):长期亏损或风险较高,建议替换。
}
if (drPROFITCONTRIBUTE["STAFF_ID"].ToString() != "")
{
profitcontributeModel.STAFF_ID = drPROFITCONTRIBUTE["STAFF_ID"].TryParseToInt(); //操作人内码
}
profitcontributeModel.STAFF_NAME = drPROFITCONTRIBUTE["STAFF_NAME"].ToString(); //操作人员
if (drPROFITCONTRIBUTE["RECORD_DATE"].ToString() != "")
{
profitcontributeModel.RECORD_DATE = drPROFITCONTRIBUTE["RECORD_DATE"].TryParseToDateTime(); //记录时间
}
profitcontributeModel.PROFITCONTRIBUTE_DESC = drPROFITCONTRIBUTE["PROFITCONTRIBUTE_DESC"].ToString(); //备注说明
}
#endregion
#endregion
#region 获取门店盈利贡献表明细
///
/// 获取门店盈利贡献表明细
///
/// 事务管理器
/// 门店盈利贡献表内码
public static Model.PROFITCONTRIBUTEModel GetPROFITCONTRIBUTEDetail(Transaction transaction, int PROFITCONTRIBUTEId)
{
Model.PROFITCONTRIBUTEModel profitcontributeModel = new Model.PROFITCONTRIBUTEModel();
string WhereSQL = "WHERE PROFITCONTRIBUTE_ID = " + PROFITCONTRIBUTEId;
//查询明细数据
DataTable dtPROFITCONTRIBUTE = new Business.CATERINGGROSSMARGIN(transaction).ExecuteDataTable(
"SELECT * FROM PLATFORM_DASHBOARD.T_PROFITCONTRIBUTE " + WhereSQL);
if (dtPROFITCONTRIBUTE.Rows.Count > 0)
{
//绑定门店盈利贡献表数据对象
BindDataRowToModel(dtPROFITCONTRIBUTE.Rows[0], profitcontributeModel);
}
return profitcontributeModel;
}
#endregion
#region 同步门店盈利贡献表
///
/// 赋值门店盈利贡献表数据对象
///
/// 事务管理器
/// 门店盈利贡献表数据对象
public static bool SynchroPROFITCONTRIBUTE(Transaction transaction, Model.PROFITCONTRIBUTEModel profitcontributeModel)
{
bool SynchroFlag = true;
string SQLString;
List excludeField = new List();
Dictionary dateFieldList = new Dictionary();
string tableName = "PLATFORM_DASHBOARD.T_PROFITCONTRIBUTE", keyField = "PROFITCONTRIBUTE_ID", seqName = "SEQ_PROFITCONTRIBUTE";
Business.CATERINGGROSSMARGIN _CATERINGGROSSMARGIN = new Business.CATERINGGROSSMARGIN(transaction);
#region 添加SQL语句中需要排除在外的字段
excludeField.Add("STATISTICS_DATE_Start");
excludeField.Add("STATISTICS_DATE_End");
excludeField.Add("SERVERPART_IDS");
excludeField.Add("SERVERPARTSHOP_IDS");
excludeField.Add("BUSINESSPROJECT_IDS");
excludeField.Add("EVALUATE_TYPES");
#endregion
#region 添加SQL语句中日期相关字段的执行语句
//统计日期
if (!string.IsNullOrWhiteSpace(profitcontributeModel.STATISTICS_DATE))
{
dateFieldList.Add("STATISTICS_DATE", DateTime.Parse(
profitcontributeModel.STATISTICS_DATE).ToString("yyyyMMddHHmmss"));
}
else
{
dateFieldList.Add("STATISTICS_DATE", "NULL");
}
#endregion
if (profitcontributeModel.PROFITCONTRIBUTE_ID != null)
{
string WhereSQL = " WHERE PROFITCONTRIBUTE_ID = " + profitcontributeModel.PROFITCONTRIBUTE_ID;
DataTable dtPROFITCONTRIBUTE = _CATERINGGROSSMARGIN.ExecuteDataTable(
"SELECT * FROM PLATFORM_DASHBOARD.T_PROFITCONTRIBUTE" + WhereSQL);
if (dtPROFITCONTRIBUTE.Rows.Count > 0)
{
SQLString = OperationDataHelper.GetTableExcuteSQL(
profitcontributeModel, 1, tableName, keyField, seqName, dateFieldList, excludeField, WhereSQL);
}
else
{
return false;
}
}
else
{
DataTable dtPROFITCONTRIBUTE = _CATERINGGROSSMARGIN.ExecuteDataTable(
"SELECT " + seqName + ".NEXTVAL FROM DUAL");
profitcontributeModel.PROFITCONTRIBUTE_ID = dtPROFITCONTRIBUTE.Rows[0][0].TryParseToInt();
SQLString = OperationDataHelper.GetTableExcuteSQL(
profitcontributeModel, 0, tableName, keyField, seqName, dateFieldList, excludeField);
}
_CATERINGGROSSMARGIN.ExecuteNonQuery(SQLString, null);
return SynchroFlag;
}
#endregion
#region 删除门店盈利贡献表
///
/// 删除门店盈利贡献表
///
/// 事务管理器
/// 门店盈利贡献表内码
public static bool DeletePROFITCONTRIBUTE(Transaction transaction, int? PROFITCONTRIBUTEId)
{
bool DeleteFlag = false;
if (PROFITCONTRIBUTEId != null)
{
}
return DeleteFlag;
}
#endregion
#region 获取门店盈利贡献表嵌套列表
///
/// 获取门店盈利贡献表嵌套列表
///
/// 事务管理器
/// 父级内码
/// 模糊查询
///
public static List> GetNestingPROFITCONTRIBUTEList(Transaction transaction,
string PROFITCONTRIBUTE_PID, string SearchKey)
{
//申明嵌套列表集合
List> nestingModelList = new List>();
//赋值sql语句
string WhereSQL = "";
//查询门店盈利贡献表数据
DataTable dtPROFITCONTRIBUTE = new Business.CATERINGGROSSMARGIN(transaction).FillDataTable(WhereSQL);
if (PROFITCONTRIBUTE_PID == "-1")
{
//调用绑定数据的方法
BindNestingList(nestingModelList, "-1", dtPROFITCONTRIBUTE, SearchKey);
}
else
{
Model.PROFITCONTRIBUTEModel profitcontributeModel = GetPROFITCONTRIBUTEDetail(transaction, PROFITCONTRIBUTE_PID.TryParseToInt());
if (profitcontributeModel != null && profitcontributeModel.PROFITCONTRIBUTE_ID != null)
{
//申明嵌套对象
Model.NestingModel nestingModel = new Model.NestingModel();
//将门店盈利贡献表model添加到嵌套对象中去
nestingModel.node = profitcontributeModel;
List> nestingModelListChild = new List>();
//调用绑定嵌套列表的方法
BindNestingList(nestingModelListChild, profitcontributeModel.PROFITCONTRIBUTE_ID.ToString(), dtPROFITCONTRIBUTE, SearchKey);
//赋值子级
nestingModel.children = nestingModelListChild;
//过滤模糊查询条件
if (nestingModelListChild.Count > 0 || string.IsNullOrWhiteSpace(SearchKey))
{
nestingModelList.Add(nestingModel);
}
}
}
dtPROFITCONTRIBUTE.Clear();
dtPROFITCONTRIBUTE.Dispose();
return nestingModelList;
}
#region 绑定嵌套列表
///
/// 绑定嵌套列表
///
/// 上级分类
/// 嵌套列表
/// 门店盈利贡献表数据
/// 模糊查询内容
public static void BindNestingList(List> nestingModelList,
string PROFITCONTRIBUTE_PID, DataTable dtPROFITCONTRIBUTE, string SearchKey)
{
//遍历数据
foreach (DataRow drPROFITCONTRIBUTE in dtPROFITCONTRIBUTE.Select("PROFITCONTRIBUTE_PID = " +
PROFITCONTRIBUTE_PID, "PROFITCONTRIBUTE_ID,PROFITCONTRIBUTE_PID"))
{
//申明嵌套对象
Model.NestingModel nestingModelChild = new Model.NestingModel();
//申明门店盈利贡献表对象
Model.PROFITCONTRIBUTEModel profitcontributeModel = new Model.PROFITCONTRIBUTEModel();
//赋值门店盈利贡献表数据对象
BindDataRowToModel(drPROFITCONTRIBUTE, profitcontributeModel);
nestingModelChild.node = profitcontributeModel;
List> nestingModelListChild = new List>();
//判断下一关系级下面是否还存在数据,没有则跳出遍历
if (dtPROFITCONTRIBUTE.Select("PROFITCONTRIBUTE_PID = " + profitcontributeModel.PROFITCONTRIBUTE_ID).Length > 0)
{
//调用绑定嵌套列表的方法
BindNestingList(nestingModelListChild, profitcontributeModel.PROFITCONTRIBUTE_ID.ToString(), dtPROFITCONTRIBUTE, SearchKey);
//赋值子级
nestingModelChild.children = nestingModelListChild;
}
//过滤模糊查询条件
if (nestingModelListChild.Count > 0 || string.IsNullOrWhiteSpace(SearchKey))
{
nestingModelList.Add(nestingModelChild);
}
}
}
#endregion
#endregion
#region 获取门店盈利贡献表嵌套树
///
/// 获取门店盈利贡献表嵌套树
///
/// 事务管理器
/// 父级内码
/// 模糊查询
///
public static List> GetNestingPROFITCONTRIBUTETree(Transaction transaction,
string PROFITCONTRIBUTE_PID, string SearchKey)
{
//申明嵌套树集合
List> nestingModelList = new List>();
//赋值sql语句
string WhereSQL = "";
//查询门店盈利贡献表数据
DataTable dtPROFITCONTRIBUTE = new Business.CATERINGGROSSMARGIN(transaction).FillDataTable(WhereSQL);
if (PROFITCONTRIBUTE_PID == "-1")
{
//调用绑定数据的方法
BindNestingTree(nestingModelList, "-1", dtPROFITCONTRIBUTE, SearchKey);
}
else
{
Model.PROFITCONTRIBUTEModel profitcontributeModel = GetPROFITCONTRIBUTEDetail(transaction, PROFITCONTRIBUTE_PID.TryParseToInt());
if (profitcontributeModel != null && profitcontributeModel.PROFITCONTRIBUTE_ID != null)
{
//申明嵌套对象
Model.NestingModel nestingModel = new Model.NestingModel();
//申明门店盈利贡献表对象
Model.CommonTypeModel commonTypeModel = new Model.CommonTypeModel
{
//将门店盈利贡献表赋值给CommonTypeModel
//绑定门店名称
label = profitcontributeModel.SERVERPARTSHOP_NAME,
//绑定内码
value = profitcontributeModel.PROFITCONTRIBUTE_ID.TryParseToInt(),
type = 1,//标识为子级节点
};
commonTypeModel.key = commonTypeModel.type + "-" + commonTypeModel.value;
//将commonTypeModel添加到嵌套对象中去
nestingModel.node = commonTypeModel;
List> nestingModelListChild = new List>();
//调用绑定数据的方法
BindNestingTree(nestingModelListChild, profitcontributeModel.PROFITCONTRIBUTE_ID.ToString(), dtPROFITCONTRIBUTE, SearchKey);
//赋值子级
nestingModel.children = nestingModelListChild;
//过滤模糊查询条件
if (nestingModelListChild.Count > 0 || string.IsNullOrWhiteSpace(SearchKey))
{
nestingModelList.Add(nestingModel);
}
}
}
dtPROFITCONTRIBUTE.Clear();
dtPROFITCONTRIBUTE.Dispose();
return nestingModelList;
}
#region 绑定嵌套树
///
/// 绑定嵌套树
///
/// 上级分类
/// 嵌套列表
/// 门店盈利贡献表数据
/// 模糊查询内容
public static void BindNestingTree(List> nestingModelList,
string PROFITCONTRIBUTE_PID, DataTable dtPROFITCONTRIBUTE, string SearchKey)
{
//遍历数据
foreach (DataRow drPROFITCONTRIBUTE in dtPROFITCONTRIBUTE.Select("PROFITCONTRIBUTE_PID = " +
PROFITCONTRIBUTE_PID, "PROFITCONTRIBUTE_ID,PROFITCONTRIBUTE_PID"))
{
//申明嵌套对象
Model.NestingModel nestingModelChild = new Model.NestingModel();
//申明门店盈利贡献表对象
Model.CommonTypeModel commonTypeModel = new Model.CommonTypeModel();
//将门店盈利贡献表赋值给CommonTypeModel
//绑定门店名称
commonTypeModel.label = drPROFITCONTRIBUTE["SERVERPARTSHOP_NAME"].ToString();
//绑定内码
commonTypeModel.value = drPROFITCONTRIBUTE["PROFITCONTRIBUTE_ID"].TryParseToInt();
commonTypeModel.type = 1;//标识为子级节点
commonTypeModel.key = commonTypeModel.type + "-" + commonTypeModel.value;
nestingModelChild.node = commonTypeModel;
List> nestingModelListChild = new List>();
//判断下一关系级下面是否还存在数据,没有则跳出遍历
if (dtPROFITCONTRIBUTE.Select("PROFITCONTRIBUTE_PID = " + drPROFITCONTRIBUTE["PROFITCONTRIBUTE_ID"]).Length > 0)
{
//调用绑定嵌套列表的方法
BindNestingTree(nestingModelListChild, drPROFITCONTRIBUTE["PROFITCONTRIBUTE_ID"].ToString(), dtPROFITCONTRIBUTE, SearchKey);
//赋值子级
nestingModelChild.children = nestingModelListChild;
}
//过滤模糊查询条件
if (nestingModelListChild.Count > 0 || string.IsNullOrWhiteSpace(SearchKey))
{
nestingModelList.Add(nestingModelChild);
}
}
}
#endregion
#endregion
}
}