old_flsystem/应用/TBRebate/SessionExt.cs

130 lines
6.5 KiB
C#

using Api.Framework;
using Api.Framework.Enums;
using Api.Framework.Model;
using Api.Framework.Tools;
using CsharpHttpHelper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TBRebate.Entitys;
using TBRebate.Properties;
namespace TBRebate
{
public static class SessionExt
{
const string tbinfo_temp_list_tbrebate = "tbinfo_temp_list_tbrebates";
/// <summary>
/// 获取fl_fadzone_info表的数据集合缓存
/// </summary>
/// <param name="session"></param>
/// <param name="refresh">刷新</param>
/// <returns></returns>
public static List<tbinfo_temp> FindTbInfoTempGroups(this SqlSugarClient session, bool refresh = false)
{
//var stopWatch = new Stopwatch();
//stopWatch.Start();
var tbinfo_temp_groups = ApiClient.Cache.Get<List<tbinfo_temp>>(tbinfo_temp_list_tbrebate);//根据KEY、获得缓存
//stopWatch.Stop();
//EventClient.OnEvent("", "AAAA = " + stopWatch.Elapsed.TotalSeconds.ToString() + " ----------- " + (tbinfo_temp_groups == null ? "null" : tbinfo_temp_groups.Count.ToString()));
try
{
if (refresh || tbinfo_temp_groups == null)
{
tbinfo_temp_groups = new List<tbinfo_temp>();
var robots = session.FindRobots(true);
foreach (var item in robots)
{
tbinfo_temp_groups.Add(new tbinfo_temp()
{
ID = item.id,
chattype = item.type,
nick = item.nick,
name = item.name
});
}
foreach (var item in tbinfo_temp_groups)
{
//var adzones = session.Queryable<fl_adzone_info>().Where(f => f.robot_id == item.ID && f.custom_type == Resources.SoftwareType && f.alliance_id == (int)CpsType.阿里妈妈).ToList();
var adzones = session.Find<fl_adzone_info>("select * from fl_adzone_info where robot_id = @robot_id and custom_type = @custom_type and alliance_id = @alliance_id", new { robot_id = item.ID, custom_type = Resources.SoftwareType, alliance_id = (int)CpsType. });
foreach (var adzone in adzones)
{
if (adzone.extend == "chief")//主
{
item.onoff = adzone.onoff;
if (adzone.adzone_group != 0)//组
{
var _adzone = session.FindAdzoneGroups(CpsType., true).Where(f => string.IsNullOrWhiteSpace(f.remark)).FirstOrDefault(f => f.id == adzone.adzone_group);
if (_adzone != null)
{
item.is_chief_group = true;
item.pid_chief = _adzone.adzones;
item.pid_chief_name = _adzone.name;
}
}
else//单
{
item.is_chief_group = false;
item.pid_chief_cps_name = adzone.adzone_pid_cps_name;
item.pid_chief = adzone.adzone_pid;
item.pid_chief_name = adzone.adzone_name;
}
}
else//副
{
item.onoff = adzone.onoff;
if (adzone.adzone_group != 0)//组
{
var _adzone = session.FindAdzoneGroups(CpsType., true).Where(f => string.IsNullOrWhiteSpace(f.remark)).FirstOrDefault(f => f.id == adzone.adzone_group);
if (_adzone != null)
{
item.is_deputy_group = true;
item.pid_deputy = _adzone.adzones;
item.pid_deputy_name = _adzone.name;
}
}
else//单
{
item.is_deputy_group = false;
item.pid_deputy_cps_name = adzone.adzone_pid_cps_name;
item.pid_deputy = adzone.adzone_pid;
item.pid_deputy_name = adzone.adzone_name;
}
}
}
//var activity = session.Queryable<fl_adzone_info>().First(f => f.robot_id == item.ID && f.custom_type == Resources.TbActivitySoftwareType);
var activity = session.FindSingle<fl_adzone_info>("select * from fl_adzone_info where robot_id = @robot_id and custom_type = @custom_type", new { robot_id = item.ID, custom_type = Resources.TbActivitySoftwareType });
if (activity != null)
{
var _adzone = session.FindAdzoneGroups(CpsType., true).Where(f => f.remark == fl_alimama_activity_type..ToString()).FirstOrDefault(f => f.id == activity.adzone_group);
if (_adzone != null)
{
item.adzone_activity_name = _adzone.name;
item.adzone_activity_pid = _adzone.adzones;
}
}
}
ApiClient.Cache.Set(tbinfo_temp_list_tbrebate, tbinfo_temp_groups, 60);
}
}
catch (Exception ex)
{
EventClient.OnEvent(null, $"【淘宝返利】 => 获取推广位异常:{ex.Message} - {ex.StackTrace}");
}
return tbinfo_temp_groups;
}
public static void Clear()
{
ApiClient.Cache.Remove(tbinfo_temp_list_tbrebate);
}
}
}