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.

364 lines
21 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.Paas.IService;
using djy.Paas.Model;
using Ys.Core.Common;
using djy.Model;
using System.Text.Json;
using DotNetCore.CAP;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
namespace djy.Paas.Service
{
public class ToolsService : ServBase, IToolsService
{
/// <summary>
/// demo 订阅
/// </summary>
/// <param name="Data"></param>
[CapSubscribe("demo")]
public void Demo(string Data)
{
_LogsAdd("demo订阅接收" + DateTime.Now, "mq", Data);
}
#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.djypublicedb).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.djypublicedb).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.djypublicedb).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.YsWebconfig.ConfigInitcount++;
if (sysOptionConfig.YsWebconfig.ConfigInitStatus == false)
{
sysOptionConfig.YsWebconfig.ConfigInitStatus = true;
_DictInit();
dlist = DbBus.Get(DbList.djypublicedb).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.YsWebconfig.ConfigList = dictlist;
if (Isjob)
{
int _dict_refreshtime = jobtime;
try
{
if (sysOptionConfig.YsWebconfig.ConfigList.GetValueOrDefault("sys.dict_refreshtime").IsNotNull())
{
_dict_refreshtime = int.Parse(sysOptionConfig.YsWebconfig.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.YsWebconfig.ConfigList == null)
{
bindConfigDict();
}
if (GroupName.IsNotNull())
return sysOptionConfig.YsWebconfig.ConfigList.Where(w => w.Key.StartsWith(GroupName + ".")).ToDictionary(x => x.Key, x => x.Value);
else
return sysOptionConfig.YsWebconfig.ConfigList;
}
/// <summary>
/// 获取配置参数
/// </summary>
/// <param name="key"></param>
/// <param name="GroupName">默认sys</param>
public string GetConfigKey(string key, string GroupName = "sys")
{
if (sysOptionConfig.YsWebconfig.ConfigList == null)
{
bindConfigDict();
}
var dictkey = string.Format("{0}.{1}", GroupName, key);
return sysOptionConfig.YsWebconfig.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 = YsJson.JsonToObject<List<DjyDictDto>>(GetConfigKey(Key));
}
catch { }
return list;
}
/// <summary>
/// 初始化配置数据库字典
/// </summary>
private static void _DictInit()
{
//sysOptionConfig.YsWebconfig.ConfigInitStatus = true;
//var dictlist = new List<tb_sys_Dictionary>();
//dictlist.AddRange(
// new List<tb_sys_Dictionary>() {
// 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=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.djypublicedb).Insert(dictlist).ExecuteAffrows();
}
#endregion
#region 大简云字典
/// <summary>
///
/// </summary>
/// <param name="Key"></param>
/// <param name="Dto"></param>
/// <returns></returns>
public ReturnResult<object> GetDjyDict(string Key, ApiFromDto Dto)
{
var rs = new ReturnResult<object>();
try
{
switch (Key)
{
case "portlist"://全球港口列表
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodeDisport>().WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.CNAME.Contains(Dto.Name) || w.PORT.Contains(Dto.Name)).OrderBy(w => w.EDICODE).ToList();
rs.OK();
break;
case "sendportlist"://起运港
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodeLoadport>().WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.CNAME.Contains(Dto.Name) || w.PORT.Contains(Dto.Name)).OrderBy(w => w.EDICODE).ToList();
rs.OK();
break;
case "paytype"://付款方式
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodeFrt>().WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.FRT.Contains(Dto.Name)).OrderBy(w => w.FRT).ToList();
rs.OK();
break;
case "feightterm"://运输条款
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodeService>().WhereIf(Dto.Code.IsNotNull(), w => w.SERVICE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.SERVICE.Contains(Dto.Name)).OrderBy(w => w.SERVICE).ToList();
rs.OK();
break;
case "signingway"://签单方式
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodeIssutype>().WhereIf(Dto.Code.IsNotNull(), w => w.BLTYPE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.BLTYPE.Contains(Dto.Name)).OrderBy(w => w.BLTYPE).ToList();
rs.OK();
break;
case "boxstationlist"://场站
var _boxstationlist = DbBus.Get(DbList.djyolddb).Select<InfoClient>().Where(w => w.ISYARD == true).WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.DESCRIPTION.Contains(Dto.Name)).OrderBy(w => w.EDICODE).ToList();
var _blist = new List<DjyDictDto>();
var _bi = 0;
_boxstationlist.ForEach(item =>
{
_blist.Add(new DjyDictDto { Code = item.CODENAME, Name = item.DESCRIPTION, Index = _bi++ });
});
rs.Data = _blist;
rs.OK();
break;
case "shipagent"://船代
var getlist_shipagent = DbBus.Get(DbList.djyolddb).Select<InfoClient>().Where(w => w.ISSHIPAGENCY == true).WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.DESCRIPTION.Contains(Dto.Name)).OrderBy(w => w.EDICODE).ToList();
var _blist_shipagent = new List<DjyDictDto>();
_bi = 0;
getlist_shipagent.ForEach(item =>
{
_blist_shipagent.Add(new DjyDictDto { Select = item.SwitchCodeList, Code = item.CODENAME, Name = item.DESCRIPTION, Index = _bi++ });
});
rs.Data = _blist_shipagent;
rs.OK();
break;
case "carrierlist"://船公司
var _shshowlist = "";
if (Dto.Key.IsNotNull())
{
_shshowlist = DjyTools.GetConfigKey(Dto.Key);
}
var _sqlshiplist = DbBus.Get(DbList.djyolddb).Select<InfoClient>().Where(w => w.ISCARRIER == true).WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.DESCRIPTION.Contains(Dto.Name)).OrderBy(w => w.EDICODE).ToList();
var _shlist = new List<DjyDictDto>();
var _sbi = 0;
_sqlshiplist.ForEach(item =>
{
_shlist.Add(new DjyDictDto { Code = item.CODENAME, Name = item.DESCRIPTION, Index = _sbi++ });
});
if (_shshowlist.IsNotNull())
{
var _showl = _shshowlist.Split(',').ToList();
_shlist = _shlist.Where(w => _showl.Contains(w.Code)).ToList();
}
rs.Data = _shlist;
rs.OK();
break;
case "package"://包装
rs.Data = DbBus.Get(DbList.djyolddb).Select<CodePackage>().WhereIf(Dto.Code.IsNotNull(), w => w.EDICODE.Contains(Dto.Code))
.WhereIf(Dto.Name.IsNotNull(), w => w.PKGS.Contains(Dto.Name)).OrderBy(w => w.PKGS).ToList();
rs.OK();
break;
case "shiproute"://航线
var getlist_shiproute = DbBus.Get(DbList.djyolddb).Select<CodeLanes>().ToList();
var _blist_shiproute = new List<DjyDictDto>();
_bi = 0;
getlist_shiproute.ForEach(item =>
{
_blist_shiproute.Add(new DjyDictDto { Code = item.LANEID, Name = item.LANE, Index = _bi++ });
});
rs.Data = _blist_shiproute;
rs.OK();
break;
default:
rs.Not("没有找到此key");
break;
}
}
catch { }
return rs;
}
#endregion
#region 统一任务调用
/// <summary>
/// 统一任务调用
/// </summary>
public void AutoJob()
{
if (!sysOptionConfig.YsWebconfig.IsDev)
{
}
//胜云航通报关自动扣费
Hangfire.RecurringJob.AddOrUpdate(() => new BaoguanService(DbList.djypublicedb).ProcCustFee(), Hangfire.Cron.MinuteInterval(1), 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);
}
}
}