You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
15 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using djy.Model;
using System.Text.Json;
using DotNetCore.CAP;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
using djy.IService.Djy;
using Common.DJYModel;
using Common.Extensions;
using Common.Entity;
using Common.Tools;
using Common;
using djy.Service.Report;
namespace djy.Service.DjyService
{
public class ToolsService : ServBase, IToolsService
{
#region 数据字典配置
public ReturnPagedResult<tb_sys_Dictionary> GetDictionaryList(tb_sys_Dictionary Dto, PageEntity pageEntity)
{
var rs = new ReturnPagedResult<tb_sys_Dictionary>();
//var sql = DbBus.Get(DbList.djypublicedb).Select<tb_sys_Dictionary>().WhereIf(Dto.GroupName.IsNotNull(), w => w.GroupName == Dto.GroupName)
// .WhereIf(Dto.Key.IsNotNull(), w => w.Key == Dto.Key);
//var list = sql.Count(out var totalcount).Page(pageEntity.Page, pageEntity.Limit).ToList();
//rs.Pageset(pageEntity, totalcount);
//rs.Data = list;
//rs.OK();
var getlist = YsRedisHelp.RedisGet<List<tb_sys_Dictionary>>("dictlist");
if (getlist == null)
{
var sql = DbBus.Get(DbList.djydb).Select<tb_sys_Dictionary>().WhereIf(Dto.GroupName.IsNotNull(), w => w.GroupName == Dto.GroupName)
.WhereIf(Dto.Key.IsNotNull(), w => w.Key == Dto.Key);
rs.Data = sql.ToList();
}
else
{
if (Dto.GroupName.IsNotNull() && Dto.Key.IsNull())
{
rs.Data = getlist.Where(w => w.GroupName == Dto.GroupName).ToList();
}
else if (Dto.GroupName.IsNotNull() && Dto.Key.IsNotNull())
{
rs.Data = getlist.Where(w => w.GroupName == Dto.GroupName && w.Key == Dto.Key).ToList();
}
else
{
rs.Data = getlist;
}
}
rs.Count = rs.Data.Count();
rs.PageIndex = 1;
rs.Limit = rs.Data.Count;
rs.OK();
return rs;
}
public ReturnResult<int> UpDictionary(tb_sys_Dictionary Dto)
{
var rs = new ReturnResult<int>();
rs.Data = DbBus.Get(DbList.djydb).Update<tb_sys_Dictionary>().Set(w => w.Value, Dto.Value).WhereIf(Dto.Key.IsNotNull(), w => w.Key == Dto.Key)
.WhereIf(Dto.Id > 0, w => w.Id == Dto.Id).ExecuteAffrows();
rs.OK();
bindConfigDict();
return rs;
}
/// <summary>
/// 初始化绑定数据字典到 sysOptionConfig.ConfigDcit配置
/// </summary>
/// <param name="Isjob">间隔自动刷新</param>
/// <param name="jobtime">间隔时间 分钟 默认一分钟</param>
/// <returns></returns>
public bool bindConfigDict(bool Isjob = false, int jobtime = 1)
{
var GetDcitList = DbBus.Get(DbList.djydb).Select<tb_sys_Dictionary>().OrderBy(w => w.GroupName).OrderBy(w => w.Indexint).ToList();
var grouplist = GetDcitList.GroupBy(w => w.GroupName).Select(g => new { GroupName = g.Key }).ToList();
YsRedisHelp.RedisSet("dictlist", GetDcitList.Where(w => w.GroupName != "sys").ToList());
//grouplist.ForEach(item => {
// //写入redis缓存
// YsRedisHelp.RedisSet("dict_"+item.GroupName, GetDcitList.Where(w=>w.GroupName==item.GroupName).ToList());
//});
var dlist = GetDcitList.Where(w => w.DictType == "config").ToList();
if (dlist.Count == 0)
{ //没有字典数据则初始化数据库字典
sysOptionConfig.Webconfig.ConfigInitcount++;
if (sysOptionConfig.Webconfig.ConfigInitStatus == false)
{
sysOptionConfig.Webconfig.ConfigInitStatus = true;
_DictInit();
dlist = DbBus.Get(DbList.djydb).Select<tb_sys_Dictionary>().Where(w => w.DictType == "config").OrderBy(w => w.GroupName).ToList();
}
}
var dictlist = dlist.ToDictionary(item => string.Format("{0}.{1}", item.GroupName, item.Key), item => item.Value);
sysOptionConfig.Webconfig.ConfigList = dictlist;
if (Isjob)
{
int _dict_refreshtime = jobtime;
try
{
if (sysOptionConfig.Webconfig.ConfigList.GetValueOrDefault("sys.dict_refreshtime").IsNotNull())
{
_dict_refreshtime = int.Parse(sysOptionConfig.Webconfig.ConfigList.GetValueOrDefault("sys.dict_refreshtime"));
}
}
catch { }
Hangfire.RecurringJob.AddOrUpdate(() => bindConfigDict(false, 1), Hangfire.Cron.MinuteInterval(_dict_refreshtime), TimeZoneInfo.Local);
}
_LogsAdd($"刷新缓存{DateTime.Now}Isjob{Isjob}", "bindConfigDict", null);
return true;
}
/// <summary>
/// 获取数据字典分组列表
/// </summary>
/// <returns></returns>
public Dictionary<string, string> GetConfigList(string GroupName = null)
{
if (sysOptionConfig.Webconfig.ConfigList == null)
{
bindConfigDict();
}
if (GroupName.IsNotNull())
return sysOptionConfig.Webconfig.ConfigList.Where(w => w.Key.StartsWith(GroupName + ".")).ToDictionary(x => x.Key, x => x.Value);
else
return sysOptionConfig.Webconfig.ConfigList;
}
/// <summary>
/// 获取配置参数
/// </summary>
/// <param name="key"></param>
/// <param name="GroupName">默认sys</param>
public string GetConfigKey(string key, string GroupName = "sys")
{
if (sysOptionConfig.Webconfig.ConfigList == null)
{
bindConfigDict();
}
var dictkey = string.Format("{0}.{1}", GroupName, key);
return sysOptionConfig.Webconfig.ConfigList.GetValueOrDefault(dictkey);
}
/// <summary>
/// 获取配置参数转djy标准dict类型对象列表
/// </summary>
/// <param name="Key"></param>
/// <param name="GroupName"></param>
/// <returns></returns>
public List<DjyDictDto> GetConfigKeyToDictList(string Key, string GroupName = "sys")
{
var list = new List<DjyDictDto>();
try
{
list = Json.JsonToObject<List<DjyDictDto>>(GetConfigKey(Key));
}
catch { }
return list;
}
/// <summary>
/// 初始化配置数据库字典
/// </summary>
private static void _DictInit()
{//
sysOptionConfig.Webconfig.ConfigInitStatus = true;
var dictlist = new List<tb_sys_Dictionary>();
dictlist.AddRange(
new List<tb_sys_Dictionary>() {
new tb_sys_Dictionary{Indexint=1, GroupName="sys", Key="txxp_pyhost", Value="http://47.104.90.170:9000", Title="提箱小票爬虫服务器", Memo="" },
new tb_sys_Dictionary{Indexint=3, GroupName="sys", Key="Email_SmtpHost", Value="smtpcom.263xmail.com", Title="email smtm服务器地址", Memo="" },
new tb_sys_Dictionary{Indexint=4, GroupName="sys", Key="Email_SmtpPort", Value="465", Title="email发动端口", Memo="" },
new tb_sys_Dictionary{Indexint=5, GroupName="sys", Key="Email_LoginName", Value="admin@dongshengsoft.com", Title="email发送者账户", Memo="" },
new tb_sys_Dictionary{Indexint=6, GroupName="sys", Key="Email_Password", Value="ds!@#)(*", Title="发送账户密码", Memo="" },
new tb_sys_Dictionary{Indexint=7, GroupName="sys", Key="Email_SendAccess", Value="dongshengsoft@dongshengsoft.com", Title="发送者", Memo="" },
new tb_sys_Dictionary{Indexint=12, GroupName="sys", Key="host_djypublice", Value="http://txxp.myshipping.net", Title="大简云公用应用url地址", Memo="" },
new tb_sys_Dictionary{Indexint=14, GroupName="sys", Title="船务公司数据 json格式",Key="carrierlist", Value="[{\"Code\":\"BSL\",\"Name\":\"巴拉基船务\"},{\"Code\":\"MEL\",\"Name\":\"玛利亚那\"},{\"Code\":\"JIJIANG\",\"Name\":\"锦江航运\"},{\"Code\":\"SCIL\",\"Name\":\"印度国航\"},{\"Code\":\"PCL\",\"Name\":\"泛舟海运\"},{\"Code\":\"SITC\",\"Name\":\"海丰船务\"},{\"Code\":\"SLS\",\"Name\":\"新加坡海领\"},{\"Code\":\"CCL\",\"Name\":\"中通\"},{\"Code\":\"STX\",\"Name\":\"世腾船务\"},{\"Code\":\"UASC\",\"Name\":\"阿拉伯航运\"},{\"Code\":\"NILEDUTCH\",\"Name\":\"尼罗河航运\"},{\"Code\":\"MCC\",\"Name\":\"新航\"},{\"Code\":\"SML\",\"Name\":\"森罗商船\"},{\"Code\":\"YML\",\"Name\":\"阳明\"},{\"Code\":\"OUASCA\",\"Name\":\"怡和\"},{\"Code\":\"KKC\",\"Name\":\"神原汽船\"},{\"Code\":\"CNC\",\"Name\":\"正利航运\",\"Config\":\"OrderHead=AA\"},{\"Code\":\"ANL\",\"Name\":\"澳航\",\"Config\":\"OrderHead=WD\"},{\"Code\":\"VSI\",\"Name\":\"维萨航运\"},{\"Code\":\"SMH\",\"Name\":\"上海德生达人\"},{\"Code\":\"SWIRE\",\"Name\":\"太古\"},{\"Code\":\"CMA\",\"Name\":\"法国达飞\",\"Config\":\"OrderHead=QD\"},{\"Code\":\"ZIM\",\"Name\":\"以星轮船\"},{\"Code\":\"HLC\",\"Name\":\"赫伯罗特\"},{\"Code\":\"ASL\",\"Name\":\"亚海\"},{\"Code\":\"CKL\",\"Name\":\"天敬海运\"},{\"Code\":\"MSC\",\"Name\":\"地中海航运\"},{\"Code\":\"GSL\",\"Name\":\"金星轮船\"},{\"Code\":\"CCNI\",\"Name\":\"智利航运\"},{\"Code\":\"IAL\",\"Name\":\"运达\"},{\"Code\":\"HMM\",\"Name\":\"现代\"},{\"Code\":\"OOCL\",\"Name\":\"东方海外\"},{\"Code\":\"WHL\",\"Name\":\"万海\"},{\"Code\":\"DSL\",\"Name\":\"斗宇\"},{\"Code\":\"TYS\",\"Name\":\"太荣\"},{\"Code\":\"DYL\",\"Name\":\"东映\"},{\"Code\":\"FESCO\",\"Name\":\"FESCO\"},{\"Code\":\"GFS\",\"Name\":\"格飞驰\"},{\"Code\":\"WINFAST\",\"Name\":\"永发航运\"},{\"Code\":\"ONE\",\"Name\":\"网联船务\"},{\"Code\":\"EAS\",\"Name\":\"达通\"},{\"Code\":\"ACI\",\"Name\":\"亚利安莎\"},{\"Code\":\"APL\",\"Name\":\"美国总统\"},{\"Code\":\"TSL\",\"Name\":\"德祥\"},{\"Code\":\"MARI\",\"Name\":\"玛丽亚娜\"},{\"Code\":\"ESL\",\"Name\":\"阿联酋航运\"},{\"Code\":\"KMTC\",\"Name\":\"高丽\"},{\"Code\":\"HSD\",\"Name\":\"汉堡南美\"},{\"Code\":\"AAL\",\"Name\":\"澳亚航运\"},{\"Code\":\"CUL\",\"Name\":\"中联航运\"},{\"Code\":\"SINOLINE\",\"Name\":\"中外运集装箱\"},{\"Code\":\"MSK\",\"Name\":\"马士基\"},{\"Code\":\"PHL\",\"Name\":\"浦海\"},{\"Code\":\"SAF\",\"Name\":\"南非航运\"},{\"Code\":\"EMC\",\"Name\":\"长荣\"},{\"Code\":\"SNKO\",\"Name\":\"长锦\"},{\"Code\":\"COHE\",\"Name\":\"京汉\"},{\"Code\":\"NAM\",\"Name\":\"南星\"},{\"Code\":\"SOF\",\"Name\":\"顺发\"},{\"Code\":\"PIL\",\"Name\":\"太平\"},{\"Code\":\"IRL\",\"Name\":\"伊朗航运\"},{\"Code\":\"POS\",\"Name\":\"泛奥升\"},{\"Code\":\"GQF\",\"Name\":\"安通\"},{\"Code\":\"HAT\",\"Name\":\"兴亚船务\"},{\"Code\":\"RCL\",\"Name\":\"宏海\"},{\"Code\":\"COSCO\",\"Name\":\"中远海运\"}]", Memo="" },
new tb_sys_Dictionary{Indexint=15, GroupName="sys", Key="boxstationlist", Title="场站 json列表数据",Value="[{\"Code\":\"JIEFENG\",\"Name\":\"捷丰国际\",\"Config\":\"\"},{\"Code\":\"STXKEYUN\",\"Name\":\"世腾客运\",\"Config\":\"\"},{\"Code\":\"ZHONGCHUANG\",\"Name\":\"中创物流\",\"Config\":\"\"},{\"Code\":\"GangLianXin\",\"Name\":\"港联欣物流\",\"Config\":\"\"},{\"Code\":\"GLCZ\",\"Name\":\"青岛港路\",\"Config\":\"\"},{\"Code\":\"SSCZ\",\"Name\":\"胜狮物流\",\"Config\":\"\"},{\"Code\":\"SZX\",\"Name\":\"青岛神州行\",\"Config\":\"\"},{\"Code\":\"GANGWAN\",\"Name\":\"青岛港联海物流\",\"Config\":\"\"},{\"Code\":\"ZHENGHUA\",\"Name\":\"青岛振华\",\"Config\":\"\"},{\"Code\":\"WYCZ\",\"Name\":\"中国外运\",\"Config\":\"\"},{\"Code\":\"LUHAI\",\"Name\":\"青岛陆海国际\",\"Config\":\"\"},{\"Code\":\"JINHENG\",\"Name\":\"青岛锦恒\",\"Config\":\"\"},{\"Code\":\"GLJ\",\"Name\":\"港联捷,怡航\",\"Config\":\"\"},{\"Code\":\"DAYA\",\"Name\":\"大亚场站\",\"Config\":\"\"},{\"Code\":\"WLXX\",\"Name\":\"物流信息\",\"Config\":\"\"},{\"Code\":\"FLCZ\",\"Name\":\"泛联场站\",\"Config\":\"\"},{\"Code\":\"QDKY\",\"Name\":\"青岛客运\",\"Config\":\"\"},{\"Code\":\"SDITDS\",\"Name\":\"通关与物流状态\",\"Config\":\"\"},{\"Code\":\"MJCZ\",\"Name\":\"青岛珉钧\",\"Config\":\"\"},{\"Code\":\"MGDG\",\"Name\":\"青岛东港,明港东港\",\"Config\":\"\"},{\"Code\":\"QDGLH\",\"Name\":\"青岛港联华\",\"Config\":\"\"},{\"Code\":\"CHANGRONG\",\"Name\":\"长荣\",\"Config\":\"vgmislogin=1\"},{\"Code\":\"GLR\",\"Name\":\"港联荣\",\"Config\":\"vgmislogin=1\"},{\"Code\":\"YGT\",\"Name\":\"云港通\",\"Config\":\"\"},{\"Code\":\"XINBADA\",\"Name\":\"新霸达场站\",\"Config\":\"vgmislogin=1\"}]", Memo="" },
new tb_sys_Dictionary{Indexint=16, GroupName="sys", Key="boxweigthbetween", Title="箱子重量区间",Value="2600,36000", Memo="" }
// new tb_tb_sys_Dictionary{Indexint=9, GroupName="sys", Key="", Title="",Value="", Memo="" }
}
);
dictlist.ForEach(x => { x.Init(); });
DbBus.Get(DbList.djydb).Insert(dictlist).ExecuteAffrows();
}
#endregion
#region 统一任务调用
/// <summary>
/// 统一任务调用
/// </summary>
public void AutoJob()
{
if (!sysOptionConfig.Webconfig.IsDev)
{
Hangfire.RecurringJob.AddOrUpdate(() => _LogsClear(), "0 0 0 * * ? ", TimeZoneInfo.Local);
}
if (sysOptionConfig.Webconfig.IsReport)
{
Hangfire.RecurringJob.AddOrUpdate(() => new ReportService().TemplateTask(), "0 0 0 * * ? ", TimeZoneInfo.Local);
}
}
#endregion
public void LogsAdd(string Message, string GroupName = null, object DataJson = null, string ObjGid = null, object ResultJson = null)
{
_LogsAdd(Message, GroupName, DataJson, ObjGid, ResultJson);
}
/// <summary>
/// 日志数据库定期清理
/// </summary>
public void _LogsClear()
{ //删除10天前的并收缩logs日志数据库文件
//var delcount = DbBus.Get(DbList.Logsdb).Delete<tb_sys_Logs>().Where(w => w.AddTime < DateTime.Now.AddDays(-7).ToTimeStamp()).ExecuteAffrows();
//var dbcc = DbBus.Get(DbList.Logsdb).Ado.ExecuteNonQuery("DBCC SHRINKFILE (N'djy_logs_log' , 1, TRUNCATEONLY)");
//_LogsAdd("del Logs :" + delcount + "行", "logs", new { delcount, dbcc }, null);
}
}
}