SetUsedSelectFields
if (rf.Mappers != null && dictionaryUrl.ContainsKey("_mapperType") && rf.Mappers.ContainsKey(dictionaryUrl["_mapperType"].ToString()) && !string.IsNullOrEmpty(rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias))
{
dictionaryUrl[_columnAliasKey] = rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias;
// 使用相同继承方式
if (rf.Mappers.ContainsKey(dictionaryUrl[_columnAliasKey].ToString()))
{
dictionaryUrl[_columnAliasKey] = rf.Mappers[dictionaryUrl[_columnAliasKey].ToString()].ColumnAlias;
}
}
_mapperType columnAlias need mappers
"manager": {
"showExtand": "{geography},null lng_lat",
"bridgeColumnExtand": "lng_lat,workshop,factory_user",
"originalExtand": "0.0 lng,0.0 lat",
// #region 开启扩展入库配置
"saveSqlExtand": true,
// #endregion 开启扩展入库配置
"guidMethod": "None",
"dataFromType": "Database",
"extend": "basis",
"original": "'' workshop,'' factory_user,is_enabled",
"auth": true,
"viewCountClosed": false,
"fieldChild": {},
"mapperType": {
// true 开启强制外部的
"replaces": false,
// key 对应角色id,如果包含,_mapperType=值,如果外部传递,使用外部的
// value 对应 op-eq值
"mappers": [
{
"key": "111",
"value": "",
"sortId": 1,
//关联对象类型, type 1=角色权限,2=用户增加特殊权限,3=用户减少的特殊权限,4=单位权限 5 职位
"type": null
}
]
},
// cpc_product_task status 0 待分配/待接收 1 进行中 2 已完工 3 已延期 4 已暂停 5 已关闭 6 已拒绝
// cpc_product_task_user status 0 待接收 6 已拒绝 7 已接收
// cpc_product_task_user user_type 0 未知 1 管理员 2 法人 3 员工 4 会计 5 财务 6 采购员 7 生产员 8 班组 9 厂长 10 仓管 11 供应商 12 客户 13 派单员 14 上报员 15 总部职员 16 总部领导 17 总部派单员 18 总部仓管
"wheres": [
"{where_sql} ",
//注意 and 前面必须有空格,否则where条件可能被过滤
"{s-if:_mapperType}",
// #region 添加不存在用户过滤
"{op-eq:1}",
" and ( ",
"create_user_id<>@_userId ",
"and fact_id not in (select factory_id from cpc_ws_factory_user where user_id=@_userId)",
") ",
"{op-eq:1}",
// #endregion
"{e-if:_mapperType}",
"{s-if:_mapperType}",
// #region 获取我的下达权限工厂 13 派单员,9 工厂 启用 审核通过
"{op-eq:2}",
" and (",
"fact_id in (select factory_id from cpc_ws_factory_user where user_id=@_userId and is_enabled=1 and audit_status=1 and user_type in (13,9,17,18))",
" or '4059455233548357632' in @_roleId",
")",
"{op-eq:2}",
"{e-if:_mapperType}",
// #endregion
"{s-if:_mapperType}",
// #region 工厂管理 (平台工厂管理员4059455233548357632\厂长9\管理员1)
"{op-eq:3}",
" and ((fact_id in (select factory_id from cpc_ws_factory_user where user_id=@_userId and user_type in (1,9,17)))",
" or ('4059455233548357632' in @_roleId))",
"{op-eq:3}",
"{e-if:_mapperType}",
// #endregion
// #region 我的申请待审核的 状态为未审核的
"{s-if:_mapperType}",
"{op-eq:10}",
" and fact_id in (select factory_id from cpc_ws_factory_user where user_id=@_userId and audit_status=0)",
"{op-eq:10}",
"{e-if:_mapperType}",
// #endregion 我的申请待审核的
// #region 我加入审核通过或自建的工厂
"{s-if:_mapperType}",
"{op-eq:11}",
" and (create_user_id=@_userId or fact_id in (select factory_id from cpc_ws_factory_user where user_id=@_userId and audit_status=1))",
"{op-eq:11}",
"{e-if:_mapperType}",
// #endregion 我加入审核通过或自建的工厂
// #region 被打回的工厂
"{s-if:_mapperType}",
"{op-eq:12}",
" and fact_id in (select factory_id from cpc_ws_factory_user where user_id=@_userId and audit_status=2)",
"{op-eq:12}",
"{e-if:_mapperType}"
// #endregion 被打回的工厂
],
"mappers": {
"default": {
"columnAlias": "create_user_id,fact_id,fact_name,user_count,audit_status,tags"
},
// 我的申请待审核的
"10": {
"need":"", // 必传参数
"columnAlias": "default"
},
// 我加入审核通过或自建的工厂
"11": {
"columnAlias": "default"
},
// 被打回的工厂
"12": {
"columnAlias": "default"
},
// 工厂管理
"3": {
"columnAlias": "default"
}
}
},
if (rf.Mappers != null && dictionaryUrl.ContainsKey("_mapperType") && rf.Mappers.ContainsKey(dictionaryUrl["_mapperType"].ToString()) && !string.IsNullOrEmpty(rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias))
{
dictionaryUrl["_columnAlias"] = rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias;
}
if (dictionaryUrl.ContainsKey("_columnAlias") && !ValidateUtil.IsNullOrEmptyOrDbNull(dictionaryUrl[_columnAliasKey]))
{
var _columns = $",{dictionaryUrl[_columnAliasKey].ToString()},";
sqlColumns = sqlColumns.Where(temp => _columns.Contains($",{temp.Alias},")).ToList();
}
public void SetUsedSelectFields(SqlConfig sqlConfig, RequestModuleType rmt, Dictionary<string, object> dictionaryUrl, out Dictionary<string, string> geographySql)
{
ResponseField rf = sqlConfig.ResponseFieldTemp;
List<SqlColumn> sqlColumns = sqlConfig.ColumnsLst;
// #region 添加使用外部要显示的列
var _columnAliasKey = "_columnAlias";
if (rf.Mappers != null && dictionaryUrl.ContainsKey("_mapperType") && rf.Mappers.ContainsKey(dictionaryUrl["_mapperType"].ToString()) && !string.IsNullOrEmpty(rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias))
{
dictionaryUrl[_columnAliasKey] = rf.Mappers[dictionaryUrl["_mapperType"].ToString()].ColumnAlias;
}
if (dictionaryUrl.ContainsKey(_columnAliasKey) && !ValidateUtil.IsNullOrEmptyOrDbNull(dictionaryUrl[_columnAliasKey]))
{
var _columns = $",{dictionaryUrl[_columnAliasKey].ToString()},";
sqlColumns = sqlColumns.Where(temp => _columns.Contains($",{temp.Alias},")).ToList();
}
// #endregion 添加使用外部要显示的列
if (rf != null && rf.Field?.Params != null)
{
//设置默认的查询条件
foreach (var key in rf.Field.Params.Keys)
{
if (!dictionaryUrl.ContainsKey(key) && !key.Contains("@"))
{
dictionaryUrl[key] = rf.Field.Params[key];
}
}
}
geographySql = new Dictionary<string, string>();
SetGeographySql(sqlConfig, rmt, dictionaryUrl, geographySql, rf);
//
#region 设置存在的关系表 ID ,用于下面判断列信息
IEnumerable<SqlRelation> relations = GetUseRelation(sqlConfig, rmt);
bool isRelation = !(relations == null || relations.Count() == 0);
Dictionary<int?, string> dicRelation = new Dictionary<int?, string>();
if (isRelation)
{
foreach (SqlRelation temp in relations)
{
dicRelation[Convert.ToInt32(temp.TableId1)] = temp.TableId1;
dicRelation[Convert.ToInt32(temp.TableId2)] = temp.TableId2;
}
}
#endregion
if (rmt == RequestModuleType.Page && sqlConfig.ResponseFieldTemp.OnlySqlPage != true && (string.IsNullOrEmpty(sqlConfig.SelectSql.PageField) || sqlConfig.SelectSql.PageField == "*") || dictionaryUrl.ContainsKey(_columnAliasKey))
{
if (sqlConfig.Tables == null)
{
throw new BizException(ErrorCodeConst.MAPPER_25001.ErrorCode, $"{sqlConfig.ModuleKey}未配置tables");
}
int? tableId = sqlConfig.Tables.FirstOrDefault(temp => { return temp.IsPrimary; }).Id;
StringBuilder sbField = new StringBuilder();
IEnumerable<SqlColumn> sqlColumnList = null;
if (!isRelation)
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsPage != false) && tableId == temp.TableId; });
}
else
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsPage != false) && dicRelation.ContainsKey(temp.TableId); });
}
SetSelectFields(sbField, sqlColumnList, sqlConfig, false);
if (sbField.Length == 0)
{
sbField.Append(",*");
}
sqlConfig.SelectSql.PageField = sbField.ToString();
}
//else if (rmt == RequestModuleType.List && !string.IsNullOrEmpty(sqlConfig.SelectSql.List))
//{
// //使用自定义的sql语句
//}
else if (rmt == RequestModuleType.List && sqlConfig.ResponseFieldTemp.OnlySqlList != true && (string.IsNullOrEmpty(sqlConfig.SelectSql.ListField) || sqlConfig.SelectSql.ListField == "*") || dictionaryUrl.ContainsKey(_columnAliasKey))
{
if (sqlConfig.Tables == null)
{
throw new BizException(ErrorCodeConst.MAPPER_25001.ErrorCode, $"{sqlConfig.ModuleKey}未配置tables");
}
SqlTable sqlTable = sqlConfig.Tables.FirstOrDefault(temp => { return temp.IsPrimary; });
if (sqlTable == null)
{
sqlTable = new SqlTable { IsPrimary = true };
sqlConfig.Tables.Add(sqlTable);
}
int? tableId = sqlConfig.Tables.FirstOrDefault(temp => { return temp.IsPrimary; }).Id;
StringBuilder sbField = new StringBuilder();
IEnumerable<SqlColumn> sqlColumnList = null;
if (!isRelation)
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsList != false) && tableId == temp.TableId; });
}
else
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsList != false) && dicRelation.ContainsKey(temp.TableId); });
}
SetSelectFields(sbField, sqlColumnList, sqlConfig, false);
sqlConfig.SelectSql.ListField = sbField.ToString().Trim(CommonConst.COMMA);
}
else if (rmt == RequestModuleType.Detail && sqlConfig.ResponseFieldTemp.OnlySqlDetail != true && (string.IsNullOrEmpty(sqlConfig.SelectSql.DetailField) || sqlConfig.SelectSql.DetailField == "*") || dictionaryUrl.ContainsKey(_columnAliasKey))
{
if (sqlConfig.Tables == null)
{
throw new BizException(ErrorCodeConst.MAPPER_25001.ErrorCode, $"{sqlConfig.ModuleKey}未配置tables");
}
int? tableId = sqlConfig.Tables.FirstOrDefault(temp => { return temp.IsPrimary; }).Id;
StringBuilder sbField = new StringBuilder();
IEnumerable<SqlColumn> sqlColumnList = null;
if (!isRelation)
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsDetail != false) && tableId == temp.TableId; });
}
else
{
sqlColumnList = sqlColumns.Where<SqlColumn>(temp => { return (temp.IsPrimary == true || temp.IsDetail != false) && dicRelation.ContainsKey(temp.TableId); });
}
SetSelectFields(sbField, sqlColumnList, sqlConfig, false);
sqlConfig.SelectSql.DetailField = sbField.ToString().Trim(CommonConst.COMMA);
}
}
文档更新时间: 2022-08-03 10:53 作者:admin