钉钉通讯录同步基本完成

DS7_JingHan
ddlucky 2 years ago
parent d5c16bffa0
commit 059e5997d3

@ -2116,7 +2116,32 @@ namespace DSWeb.Common.DB
}
[Table("code_employee")]
public partial class code_employee_md
{
[Key]
public string GID { get; set; }
public string USERNAME { get; set; }
public string SEX { get; set; }
public DateTime? ENROLLTIME { get; set; }
public DateTime? BIRTHDAY { get; set; }
public string OFFICEPHONE { get; set; }
public string HOMEPHONE { get; set; }
public string MOBILE { get; set; }
public string EMAIL1 { get; set; }
public string EMAIL2 { get; set; }
public string HOMEADDRESS { get; set; }
public string DEPTNAME { get; set; }
public string STATUS { get; set; }
public DateTime? LEAVEOFFICETIME { get; set; }
public string CREATEUSER { get; set; }
public DateTime? CREATETIME { get; set; }
public string MODIFIEDUSER { get; set; }
public DateTime? MODIFIEDTIME { get; set; }
public string REMARK { get; set; }
public string CORPID { get; set; }
public string USERCODE { get; set; }
public string OFFICEADDR { get; set; }
}
}

@ -96,8 +96,8 @@ namespace DSWeb.Common.DB
public DbSet<op_task_md> op_task { get; set; }
public DbSet<op_task_fieldvalue_md> op_task_fieldvalue { get; set; }
public DbSet<code_employee_md> code_employee { get; set; }
}

@ -36,6 +36,8 @@
<add key="FeePayMyshippingCustomer" value="大简云" />
<add key="FeePayMyshippingPrice" value="1" />
<add key="DS7URL" value="http://127.0.0.1:10200/" />
</appSettings>
<connectionStrings>
<!--本地开发 -->

@ -29,13 +29,15 @@ namespace DSWeb.Service.Output.DingtalkUserList
private IConnection mqConn;
public bool Start(HostControl hostControl)
{
// 开始具体的业务逻辑
logger.Debug("开始运行");
//只调用一下ds7的公开接口
var dsurl = ConfigurationManager.AppSettings["DS7URL"] + "CommMng/PublicAPI/DingTalkUserList";
var rtn = JobReqWebData.WebRequestHelper.DoGet(dsurl);
return true;
}
@ -51,960 +53,5 @@ namespace DSWeb.Service.Output.DingtalkUserList
}
#region 舱单数据解析实体类
public class Ctnlist
{
/// <summary>
///
/// </summary>
public string ctn_id { get; set; }
/// <summary>
///
/// </summary>
public string MFNO { get; set; }
/// <summary>
///
/// </summary>
public string CTNCODE { get; set; }
/// <summary>
///
/// </summary>
public int? SIZE { get; set; }
/// <summary>
///
/// </summary>
public string CTN { get; set; }
/// <summary>
///
/// </summary>
public int? CTNNUM { get; set; }
/// <summary>
///
/// </summary>
public int? TEU { get; set; }
/// <summary>
///
/// </summary>
public string CTNALL { get; set; }
/// <summary>
///
/// </summary>
public string CNTRNO { get; set; }
/// <summary>
///
/// </summary>
public string SEALNO { get; set; }
/// <summary>
///
/// </summary>
public int? PKGS { get; set; }
/// <summary>
///
/// </summary>
public decimal? KGS { get; set; }
/// <summary>
///
/// </summary>
public decimal? CBM { get; set; }
/// <summary>
///
/// </summary>
public string KINDPKGS { get; set; }
/// <summary>
///
/// </summary>
public string DESCRIPTION { get; set; }
/// <summary>
///
/// </summary>
public string MARKS { get; set; }
/// <summary>
///
/// </summary>
public string PO { get; set; }
/// <summary>
///
/// </summary>
public string SKU { get; set; }
/// <summary>
///
/// </summary>
public string SKUDESCRIP { get; set; }
/// <summary>
///
/// </summary>
public string DUNNO { get; set; }
/// <summary>
///
/// </summary>
public string HTS { get; set; }
/// <summary>
///
/// </summary>
public string CTOFORIGIN { get; set; }
/// <summary>
///
/// </summary>
public decimal? GOODVALUE { get; set; }
/// <summary>
///
/// </summary>
public string CTNOWNER { get; set; }
/// <summary>
///
/// </summary>
public string ShiFengRen { get; set; }
/// <summary>
///
/// </summary>
public string LeiXingFa { get; set; }
/// <summary>
///
/// </summary>
public string LeiXingShou { get; set; }
/// <summary>
///
/// </summary>
public string LeiXingTong { get; set; }
/// <summary>
///
/// </summary>
public int ZhongKongBiaoShi { get; set; }
/// <summary>
///
/// </summary>
public string ChengZhongZhongLiang { get; set; }
/// <summary>
///
/// </summary>
public string ChengZhongFangShi { get; set; }
/// <summary>
///
/// </summary>
public string ChengZhongShiJian { get; set; }
/// <summary>
///
/// </summary>
public decimal? PIZHONG { get; set; }
/// <summary>
///
/// </summary>
public string APICTNID { get; set; }
/// <summary>
///
/// </summary>
public DateTime? VGMCLOSETIME { get; set; }
}
public class OpSeaeEdi
{
/// <summary>
///
/// </summary>
public string MBLNO { get; set; }
/// <summary>
///
/// </summary>
public string HBLNO { get; set; }
/// <summary>
///
/// </summary>
public string CARRIERID { get; set; }
/// <summary>
///
/// </summary>
public string CARRIER { get; set; }
/// <summary>
///
/// </summary>
public string WeiTuoFaSongFang { get; set; }
/// <summary>
///
/// </summary>
public string DESTINATION { get; set; }
/// <summary>
///
/// </summary>
public string DESTINATIONID { get; set; }
/// <summary>
///
/// </summary>
public string PORTDISCHARGE { get; set; }
/// <summary>
///
/// </summary>
public string PORTDISCHARGEID { get; set; }
/// <summary>
///
/// </summary>
public DateTime? ETD { get; set; }
/// <summary>
///
/// </summary>
public string CompId { get; set; }
/// <summary>
/// 东方海外物流(中国)有限公司青岛分公司
/// </summary>
public string CompName { get; set; }
/// <summary>
///
/// </summary>
public string MFNO { get; set; }
/// <summary>
///
/// </summary>
public string BSNO { get; set; }
/// <summary>
///
/// </summary>
public string MASTERNO { get; set; }
/// <summary>
///
/// </summary>
public string SHIPPERNAME { get; set; }
/// <summary>
///
/// </summary>
public string SHIPPERADDR1 { get; set; }
/// <summary>
///
/// </summary>
public string SHIPPERCOUNTRY { get; set; }
/// <summary>
///
/// </summary>
public string SHIPPERTEL { get; set; }
/// <summary>
///
/// </summary>
public string CONSIGNEENAME { get; set; }
/// <summary>
///
/// </summary>
public string CONSIGNEEADDR1 { get; set; }
/// <summary>
///
/// </summary>
public string CONSIGNEECOUNTRY { get; set; }
public string CONSIGNEETEL { get; set; }
public string NOTIFYPARTYNAME { get; set; }
public string NOTIFYPARTYADDR1 { get; set; }
/// <summary>
///
/// </summary>
public string NOTIFYPARTYCOUNTRY { get; set; }
/// <summary>
///
/// </summary>
public string NOTIFYPARTYTEL { get; set; }
/// <summary>
///
/// </summary>
public string SHIPPER { get; set; }
/// <summary>
///
/// </summary>
public string CONSIGNEE { get; set; }
/// <summary>
///
/// </summary>
public string NOTIFYPARTY { get; set; }
/// <summary>
///
/// </summary>
public string VESSEL { get; set; }
/// <summary>
///
/// </summary>
public string VOYNO { get; set; }
/// <summary>
///
/// </summary>
public string PORTLOADID { get; set; }
/// <summary>
///
/// </summary>
public string PORTLOAD { get; set; }
/// <summary>
///
/// </summary>
public string PLACEDELIVERYID { get; set; }
/// <summary>
///
/// </summary>
public string PLACEDELIVERY { get; set; }
/// <summary>
///
/// </summary>
public string SERVICE { get; set; }
/// <summary>
///
/// </summary>
public string MARKS { get; set; }
/// <summary>
///
/// </summary>
public string DESCRIPTION { get; set; }
/// <summary>
///
/// </summary>
public int? PKGS { get; set; }
/// <summary>
///
/// </summary>
public string KINDPKGS { get; set; }
/// <summary>
///
/// </summary>
public decimal? KGS { get; set; }
/// <summary>
///
/// </summary>
public decimal? CBM { get; set; }
/// <summary>
///
/// </summary>
public string CARGOID { get; set; }
/// <summary>
///
/// </summary>
public string DCLASS { get; set; }
/// <summary>
///
/// </summary>
public string DUNNO { get; set; }
/// <summary>
///
/// </summary>
public string REEFERF { get; set; }
/// <summary>
///
/// </summary>
public string TEMPID { get; set; }
/// <summary>
///
/// </summary>
public string TEMPSET { get; set; }
/// <summary>
///
/// </summary>
public string TEMPMAX { get; set; }
/// <summary>
///
/// </summary>
public string TEMPMIN { get; set; }
/// <summary>
///
/// </summary>
public string FREIGHTAGMNO { get; set; }
/// <summary>
///
/// </summary>
public string HUMIDITY { get; set; }
/// <summary>
///
/// </summary>
public string SHIPIMO { get; set; }
/// <summary>
///
/// </summary>
public DateTime? ETA { get; set; }
/// <summary>
///
/// </summary>
public string BLFRT { get; set; }
/// <summary>
///
/// </summary>
public DateTime? SENDTIME { get; set; }
/// <summary>
///
/// </summary>
public string YARD { get; set; }
/// <summary>
/// 外代
/// </summary>
public string FORWARDER { get; set; }
/// <summary>
///
/// </summary>
public List<Ctnlist> ctnlist { get; set; }
}
#endregion
/// <summary>
/// 舱单数据生成到OPOther版本的舱单业务中 经汉专用
/// </summary>
/// <param name="jarr"></param>
public void CangdanDataToDS7_OPOther(JArray jarr)
{
try
{
var opUser = dS7Data.User.AsNoTracking().First(u => u.GID == FeeInputUserId);
foreach (var item in jarr)
{
var obj = item as JObject;
var itemstr = item.ToString();
var _edi = JsonConvert.DeserializeObject<OpSeaeEdi>(itemstr);
var MBLNO = obj.GetValue("MBLNO").ToString();
var HBLNO = obj.GetValue("HBLNO").ToString();
var CARRIERID = obj.GetValue("CARRIERID").ToString();
var CARRIER = obj.GetValue("CARRIER").ToString();
var WeiTuoFaSongFang = obj.GetValue("WeiTuoFaSongFang").ToString();
var DESTINATION = obj.GetValue("DESTINATION").ToString();
var DESTINATIONID = obj.GetValue("DESTINATIONID").ToString();
var PORTDISCHARGE = obj.GetValue("PORTDISCHARGE").ToString();
var PORTDISCHARGEID = obj.GetValue("PORTDISCHARGEID").ToString();
var strETD = obj.GetValue("ETD").ToString();
var ETD = Convert.ToDateTime(strETD);
var CompId = obj.GetValue("CompId").ToString();
//看op_other当中有没有该业务主单 如无则增加
var mfno = "topother" + _edi.MFNO;
if (!string.IsNullOrWhiteSpace(_edi.BSNO)) mfno = "topother" + _edi.BSNO;
op_other_md op_other = dS7Data.op_other.FirstOrDefault(x => x.BSNO == mfno);
var BSNO = "";
var CUSTNOHEAD = "";
var CUSTOMERNAME = "";
var custEdi = dS7Data.CodeCustEdi.AsNoTracking().FirstOrDefault(x => x.EDINAME == "DJY_OUTPUT" && x.EDICODE == WeiTuoFaSongFang);
if (custEdi != null)
{
CUSTOMERNAME = custEdi.CUST;
}
if (op_other == null || op_other.BSNO == null || op_other.BSNO == "")
{
logger.Debug($"未找到委托数据:{MBLNO}");
BSNO = mfno;
//件数 毛重 净重 尺码 sum
var PKGS = 0;
var KGS = 0M;
var CBM = 0M;
foreach (var ja in jarr)
{
var _edi2= JsonConvert.DeserializeObject<OpSeaeEdi>(ja.ToString());
PKGS += _edi2.PKGS==null?0:(int)_edi2.PKGS;
KGS += _edi2.KGS == null ? 0M : (decimal)_edi2.KGS;
CBM += _edi2.CBM == null ? 0M : (decimal)_edi2.CBM;
}
var newrec = new op_other_md
{
BSNO = BSNO,
OPLB = "op_other",
OPLBNAME = "舱单申报",
BSSTATUS = false,
FEESTATUS = false,
MBLNO = MBLNO,
HBLNO = "",
CUSTOMERNAME = CUSTOMERNAME,
//CARRIER
BSDATE = DateTime.Today,
ACCDATE = DateTime.Now.ToString("yyyy-MM"),
BSSOURCE = "",
OP = opUser.SHOWNAME,
CUSTSERVICE = opUser.SHOWNAME,
SALE = opUser.SHOWNAME,
CORPID = Corpid,
ETD = ETD,//业务日期
//SR2023011000005
PORTLOAD = _edi.PORTLOAD,//装货港
PORTDISCHARGE = _edi.PORTDISCHARGE,//卸货港
PKGS= PKGS,
KGS= KGS,
NETWEIGHT=0,
CBM= CBM
};
var billnoset = dS7Data.SysBillNoSet.AsNoTracking().FirstOrDefault(x => x.COMPANYID == Corpid && x.OPLBNAME == "舱单申报" && x.RULEBLNO == "委托编号");
if (billnoset != null)
newrec.CUSTNO = GetBillNo(billnoset, newrec.ETD.ToString(), newrec.ACCDATE, opname: opUser.SHOWNAME, corpid: Corpid);
else
{
logger.Debug($"SysBillNoSet数据未找到无法生成编号{MBLNO}");
}
dS7Data.op_other.Add(newrec);
dS7Data.SaveChanges();
op_other= dS7Data.op_other.FirstOrDefault(x => x.BSNO == mfno);
}
else
{
logger.Debug($"委托数据已存在:{MBLNO}");
BSNO = op_other.BSNO;
CUSTNOHEAD = op_other.CUSTNO;
}
//看op_seae_edi当中有没有该业务 如无则增加
var ediList = dS7Data.op_seae_edi.Where(x => x.BSNO == BSNO).ToList();
if (!ediList.Exists(x => x.MBLNO == MBLNO && x.HBLNO == HBLNO))
{
var newedi = new op_seae_edi_md {
MFNO = _edi.MFNO,
BSNO = mfno,
MASTERNO = mfno,
CUSTNO = CUSTNOHEAD + (ediList.Count + 1).ToString(),
MBLNO =_edi.MBLNO,
HBLNO = _edi.HBLNO,
CARRIERID = _edi.CARRIERID,
CARRIER = _edi.CARRIER,
//WeiTuoFaSongFang = _edi.WeiTuoFaSongFang,
DESTINATION = _edi.DESTINATION,
DESTINATIONID = _edi.DESTINATIONID,
PORTDISCHARGE = _edi.PORTDISCHARGE,
PORTDISCHARGEID = _edi.PORTDISCHARGEID,
ETD = _edi.ETD,
SHIPPERNAME = _edi.SHIPPERNAME,
SHIPPERADDR1 = _edi.SHIPPERADDR1,
SHIPPERCOUNTRY = _edi.SHIPPERCOUNTRY,
SHIPPERTEL = _edi.SHIPPERTEL,
CONSIGNEENAME = _edi.CONSIGNEENAME,
CONSIGNEEADDR1 = _edi.CONSIGNEEADDR1,
CONSIGNEECOUNTRY = _edi.CONSIGNEECOUNTRY,
CONSIGNEETEL = _edi.CONSIGNEETEL,
NOTIFYPARTYNAME = _edi.NOTIFYPARTYNAME,
NOTIFYPARTYADDR1 = _edi.NOTIFYPARTYADDR1,
NOTIFYPARTYCOUNTRY = _edi.NOTIFYPARTYCOUNTRY,
NOTIFYPARTYTEL = _edi.NOTIFYPARTYTEL,
SHIPPER = _edi.SHIPPER,
CONSIGNEE = _edi.CONSIGNEE,
NOTIFYPARTY = _edi.NOTIFYPARTY,
VESSEL = _edi.VESSEL,
VOYNO = _edi.VOYNO,
PORTLOADID = _edi.PORTLOADID,
PORTLOAD = _edi.PORTLOAD,
PLACEDELIVERYID = _edi.PLACEDELIVERYID,
PLACEDELIVERY = _edi.PLACEDELIVERY,
SERVICE = _edi.SERVICE,
MARKS = _edi.MARKS,
DESCRIPTION = _edi.DESCRIPTION,
PKGS = _edi.PKGS,
KINDPKGS = _edi.KINDPKGS,
KGS = _edi.KGS,
CBM = _edi.CBM,
CARGOID = _edi.CARGOID,
DCLASS = _edi.DCLASS,
DUNNO = _edi.DUNNO,
REEFERF = _edi.REEFERF,
TEMPID = _edi.TEMPID,
TEMPSET = _edi.TEMPSET,
TEMPMAX = _edi.TEMPMAX,
TEMPMIN = _edi.TEMPMIN,
FREIGHTAGMNO = _edi.FREIGHTAGMNO,
HUMIDITY = _edi.HUMIDITY,
SHIPIMO = _edi.SHIPIMO,
ETA = _edi.ETA,
BLFRT = _edi.BLFRT,
SENDTIME = _edi.SENDTIME,
YARD = _edi.YARD,
FORWARDER = _edi.FORWARDER
};
dS7Data.op_seae_edi.Add(newedi);
if (_edi.ctnlist != null && _edi.ctnlist.Count > 0) {
foreach (var ctn in _edi.ctnlist) {
var newctn = new op_seae_edi_ctn_md
{
ctn_id = Guid.NewGuid().ToString(),//ctn.ctn_id,
MFNO = _edi.MFNO,
CTNCODE = ctn.CTNCODE,
CNTRNO= ctn.CNTRNO,
SEALNO = ctn.SEALNO,
SIZE = ctn.SIZE.ToString(),
CTN = ctn.CTN,
CTNNUM = ctn.CTNNUM,
TEU = ctn.TEU,
CTNALL = ctn.CTNALL,
PKGS = ctn.PKGS,
KGS = ctn.KGS,
CBM = ctn.CBM,
KINDPKGS = ctn.KINDPKGS,
DESCRIPTION = ctn.DESCRIPTION,
MARKS = ctn.MARKS,
PO = ctn.PO,
SKU = ctn.SKU,
SKUDESCRIP = ctn.SKUDESCRIP,
DUNNO = ctn.DUNNO,
HTS = ctn.HTS,
CTOFORIGIN = ctn.CTOFORIGIN,
GOODVALUE = ctn.GOODVALUE,
CTNOWNER = ctn.CTNOWNER
};
dS7Data.op_seae_edi_ctn.Add(newctn);
}
}
dS7Data.SaveChanges();
}
//只要有对应的往来单位=委托发送方 主分单都产生相应的应收
InfoClient infoClient = null;
if (!string.IsNullOrEmpty(CUSTOMERNAME))
{
infoClient = dS7Data.InfoClient.AsNoTracking().FirstOrDefault(x => x.SHORTNAME == CUSTOMERNAME);
if (infoClient != null)
{
op_other.SALE = infoClient.SALE; //揽货人赋值
//查询配置,生成应收
var fee = dS7Data.CustFeeTemplateDetail.AsNoTracking().FirstOrDefault(x => x.CUSTOMERNAME == infoClient.SHORTNAME && x.FEENAME == FeeShouName);
if (fee != null )
{
var feeShou = new ChFee();
feeShou.GID = Guid.NewGuid().ToString().Replace("-", "");
feeShou.BSNO = op_other.BSNO;
feeShou.FEETYPE = 1;
feeShou.FEENAME = FeeShouName;
feeShou.CUSTOMERTYPE = "其他";
feeShou.CUSTOMERNAME = infoClient.SHORTNAME;
feeShou.UNIT = fee.UNIT;
feeShou.UNITPRICE = fee.UNITPRICE;
feeShou.QUANTITY = 1;
feeShou.AMOUNT = fee.UNITPRICE;
feeShou.EXCHANGERATE = 1;
feeShou.CURRENCY = "RMB";
feeShou.ENTEROPERATOR = FeeInputUserId;
feeShou.ENTERDATE = DateTime.Now;
feeShou.MODIFIEDUSER = FeeInputUserId;
feeShou.MODIFIEDTIME = DateTime.Now;
feeShou.LOCALCURR = feeShou.CURRENCY;
feeShou.FEEDESCRIPTION = feeShou.FEENAME;
feeShou.FEESTATUS = 0;//费用插入时状态为提交审核2021-12-8要求插入时状态改为录入状态12021-12-9要求状态为审核通过状态0
//2021-12-8下列字段不能为空写入默认值
feeShou.SETTLEMENT = 0;
feeShou.ORDERAMOUNT = 0;
feeShou.ORDERINVOICE = 0;
feeShou.ORDERINVSETTLEMENT = 0;
feeShou.ORDERSETTLEMENT = 0;
feeShou.INVOICE = 0;
feeShou.TAXRATE = 0;
feeShou.ISADVANCEDPAY = false;
feeShou.ISINVOICE = false;
feeShou.ISCRMORDERFEE = false;
feeShou.TAXUNITPRICE = fee.UNITPRICE;//2021-12-29于菲同样赋值单价和金额
feeShou.NOTAXAMOUNT = fee.UNITPRICE;//2021-12-29于菲同样赋值单价和金额
//2021-12-9要求下列字段不能为空填写0或false
feeShou.COMMISSIONRATE = 0;
feeShou.AUDITSTATUS = 0;
feeShou.LINENUM = 0;
feeShou.ISDEBIT = false;
feeShou.ISOPEN = false;
feeShou.ACCTAXRATE = 0;
feeShou.ISVOU = false;
feeShou.TAX = 0;
feeShou.PREAMOUNT = 0;
feeShou.ISACC = false;
feeShou.CUSTDUI = false;
feeShou.BXGID = HBLNO;
//2021-12-23分单号写入备注
//if (!string.IsNullOrEmpty(HBLNO))
//{
// feeShou.REMARK += $" {HBLNO} ";
//}
dS7Data.ChFee.Add(feeShou);
}
}
}
//应付
if (string.IsNullOrEmpty(HBLNO) && FeePayPrice>0) //主单才插入船代费用
{
var feeFu = new ChFee();
feeFu.GID = Guid.NewGuid().ToString().Replace("-", "");
feeFu.BSNO = op_other.BSNO;
feeFu.FEETYPE = 2;
feeFu.FEENAME = FeePayName;
feeFu.CUSTOMERTYPE = FeePayCustomerType;
feeFu.CUSTOMERNAME = FeePayCustomer;
feeFu.UNIT = "票";
feeFu.UNITPRICE = FeePayPrice;
feeFu.QUANTITY = 1;
feeFu.AMOUNT = FeePayPrice;
feeFu.EXCHANGERATE = 1;
feeFu.CURRENCY = "RMB";
feeFu.ENTEROPERATOR = FeeInputUserId;
feeFu.ENTERDATE = DateTime.Now;
feeFu.MODIFIEDUSER = FeeInputUserId;
feeFu.MODIFIEDTIME = DateTime.Now;
feeFu.LOCALCURR = feeFu.CURRENCY;
feeFu.FEEDESCRIPTION = feeFu.FEENAME;
feeFu.FEESTATUS = 0;//费用插入时状态为提交审核2021-12-8要求插入时状态改为录入状态12021-12-9要求状态为审核通过状态0
//2021-12-8下列字段不能为空写入默认值
feeFu.SETTLEMENT = 0;
feeFu.ORDERAMOUNT = 0;
feeFu.ORDERINVOICE = 0;
feeFu.ORDERINVSETTLEMENT = 0;
feeFu.ORDERSETTLEMENT = 0;
feeFu.INVOICE = 0;
feeFu.TAXRATE = 0;
feeFu.ISADVANCEDPAY = false;
feeFu.ISINVOICE = false;
feeFu.ISCRMORDERFEE = false;
feeFu.TAXUNITPRICE = FeePayPrice;
feeFu.NOTAXAMOUNT = 0;
//2021-12-9要求下列字段不能为空填写0或false
feeFu.COMMISSIONRATE = 0;
feeFu.AUDITSTATUS = 0;
feeFu.LINENUM = 0;
feeFu.ISDEBIT = false;
feeFu.ISOPEN = false;
feeFu.ACCTAXRATE = 0;
feeFu.ISVOU = false;
feeFu.TAX = 0;
feeFu.PREAMOUNT = 0;
feeFu.ISACC = false;
feeFu.CUSTDUI = false;
feeFu.BXGID = HBLNO;
dS7Data.ChFee.Add(feeFu);
dS7Data.SaveChanges();
}
if (FeePayMyshippingPrice > 0) {
//不管主单分单都要付费给大简云
var feeFuDJY = new ChFee();
feeFuDJY.GID = Guid.NewGuid().ToString().Replace("-", "");
feeFuDJY.BSNO = op_other.BSNO;
feeFuDJY.FEETYPE = 2;
feeFuDJY.FEENAME = FeePayMyshippingName;
feeFuDJY.CUSTOMERTYPE = "其他";
feeFuDJY.CUSTOMERNAME = FeePayMyshippingCustomer;
feeFuDJY.UNIT = "票";
feeFuDJY.UNITPRICE = FeePayMyshippingPrice;
feeFuDJY.QUANTITY = 1;
feeFuDJY.AMOUNT = FeePayMyshippingPrice;
feeFuDJY.EXCHANGERATE = 1;
feeFuDJY.CURRENCY = "RMB";
feeFuDJY.ENTEROPERATOR = FeeInputUserId;
feeFuDJY.ENTERDATE = DateTime.Now;
feeFuDJY.MODIFIEDUSER = FeeInputUserId;
feeFuDJY.MODIFIEDTIME = DateTime.Now;
feeFuDJY.LOCALCURR = feeFuDJY.CURRENCY;
feeFuDJY.FEEDESCRIPTION = feeFuDJY.FEENAME;
feeFuDJY.FEESTATUS = 0;//费用插入时状态为提交审核2021-12-8要求插入时状态改为录入状态12021-12-9要求状态为审核通过状态0
//2021-12-8下列字段不能为空写入默认值
feeFuDJY.SETTLEMENT = 0;
feeFuDJY.ORDERAMOUNT = 0;
feeFuDJY.ORDERINVOICE = 0;
feeFuDJY.ORDERINVSETTLEMENT = 0;
feeFuDJY.ORDERSETTLEMENT = 0;
feeFuDJY.INVOICE = 0;
feeFuDJY.TAXRATE = 0;
feeFuDJY.ISADVANCEDPAY = false;
feeFuDJY.ISINVOICE = false;
feeFuDJY.ISCRMORDERFEE = false;
feeFuDJY.TAXUNITPRICE = FeePayMyshippingPrice;
feeFuDJY.NOTAXAMOUNT = 0;
//2021-12-9要求下列字段不能为空填写0或false
feeFuDJY.COMMISSIONRATE = 0;
feeFuDJY.AUDITSTATUS = 0;
feeFuDJY.LINENUM = 0;
feeFuDJY.ISDEBIT = false;
feeFuDJY.ISOPEN = false;
feeFuDJY.ACCTAXRATE = 0;
feeFuDJY.ISVOU = false;
feeFuDJY.TAX = 0;
feeFuDJY.PREAMOUNT = 0;
feeFuDJY.ISACC = false;
feeFuDJY.CUSTDUI = false;
feeFuDJY.BXGID = HBLNO;
dS7Data.ChFee.Add(feeFuDJY);
//dS7Data.Database.Log = (x => { logger.Debug(x); });
dS7Data.SaveChanges();
}
}
}
catch (Exception e) {
logger.Error($"导入舱单出错:{e}");
}
}
/// <summary>
/// 生成编号从东胜7移植并修改
/// </summary>
/// <param name="billType"></param>
/// <param name="bsdate"></param>
/// <param name="accdate"></param>
/// <param name="dbname"></param>
/// <param name="opname"></param>
/// <param name="corpid"></param>
/// <param name="bshead"></param>
/// <returns></returns>
private string GetBillNo(SysBillNoSet billType, string bsdate, string accdate, string dbname = "", string opname = "", string corpid = "", string bshead = "")
{
var orgCode = "";
var UserCode = "";
UserCode = GetUserCode(opname, dbname);
orgCode = GetCorpCode(corpid, dbname);
//List<SqlParameter> paramArray = new List<SqlParameter>();
//paramArray.Add(new SqlParameter("@ps_BillType", billType.BILLTYPE));
//paramArray.Add(new SqlParameter("@ps_OrgCode", orgCode));
//paramArray.Add(new SqlParameter("@ps_EmpCode", UserCode));
//paramArray.Add(new SqlParameter("@ps_bshead", bshead));
//if (billType.RULEDATETYPE == "业务日期")
// paramArray.Add(new SqlParameter("@ps_Date", bsdate));
//else if (billType.RULEDATETYPE == "会计期间" && accdate.Length == 7)
// paramArray.Add(new SqlParameter("@ps_Date", accdate + "-01"));
//else
// paramArray.Add(new SqlParameter("@ps_Date", accdate + ""));
//paramArray.Add(new SqlParameter("@ps_BillNo", 20));
//SqlParameter sqlParaOut = new SqlParameter("@ps_RefBillNo", SqlDbType.VarChar, 50);
//sqlParaOut.Direction = ParameterDirection.Output;
//paramArray.Add(sqlParaOut);
//dS7Data.Database.ExecuteSqlCommand("EXEC [sSysGetBillNo_new] @ps_BillType,@ps_OrgCode,@ps_EmpCode,@ps_bshead,@ps_Date,@ps_BillNo,@ps_RefBillNo output", paramArray.ToArray());
//ExecStoredProcedure("sSysGetBillNo_new", paramArray.ToArray());
var bsDate = string.Empty;
if (!string.IsNullOrWhiteSpace(bsdate))
bsdate = Convert.ToDateTime(bsdate).ToString("yyyy-MM-dd");
if (billType.RULEDATETYPE == "业务日期")
bsDate = bsdate;
else if (billType.RULEDATETYPE == "会计期间" && accdate.Length == 7)
bsDate = accdate + "-01";
else
bsDate = accdate;
var cmd = $@"DECLARE @ps_BillNo varchar(20)
EXEC [sSysGetBillNo_new]
@ps_BillType = N'{billType.BILLTYPE}',
@ps_OrgCode = N'{orgCode}',
@ps_EmpCode = N'{UserCode}',
@ps_Date = N'{bsDate}',
@ps_bshead = N'{bshead}',
@ps_BillNo = @ps_BillNo OUTPUT,
@ps_RefBillNo = N''
SELECT @ps_BillNo as N'billno'";
return dS7Data.Database.SqlQuery<string>(cmd).First();
}
/// <summary>
/// 获取用户code参考东胜7修改
/// </summary>
/// <param name="username"></param>
/// <param name="dbname"></param>
/// <returns></returns>
private string GetUserCode(string username, string dbname = "")
{
//string EDICODE = "";
//var strSql = new StringBuilder();
//strSql.Append("select CODENAME from [user] where SHOWNAME='" + username + "'");
//Database db = string.IsNullOrWhiteSpace(dbname) ? DatabaseFactory.CreateDatabase() : DatabaseFactory.CreateDatabase(dbname);
//using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
//{
// while (reader.Read())
// {
// EDICODE = Convert.ToString(reader["CODENAME"]);
// }
// reader.Close();
//}
//return EDICODE;
return dS7Data.Database.SqlQuery<string>("select CODENAME from [user] where SHOWNAME='" + username + "'").FirstOrDefault();
}
/// <summary>
/// 获取公司code参考东胜7修改
/// </summary>
/// <param name="Corpid"></param>
/// <param name="dbname"></param>
/// <returns></returns>
private string GetCorpCode(string Corpid, string dbname = "")
{
//string EDICODE = "";
//var strSql = new StringBuilder();
//strSql.Append("select CODENAME from [company] where GID='" + Corpid + "'");
//Database db = string.IsNullOrWhiteSpace(dbname) ? DatabaseFactory.CreateDatabase() : DatabaseFactory.CreateDatabase(dbname);
//using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
//{
// while (reader.Read())
// {
// EDICODE = Convert.ToString(reader["CODENAME"]);
// }
// reader.Close();
//}
//return EDICODE;
return dS7Data.Database.SqlQuery<string>("select CODENAME from [company] where GID='" + Corpid + "'").FirstOrDefault();
}
public static int ExecStoredProcedure(string procName, params SqlParameter[] parameters)
{
int rtn = 0;
using (SqlConnection conn = new SqlConnection(DS7ConnStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
SqlTransaction st = conn.BeginTransaction();
cmd.Transaction = st;
try
{
cmd.CommandText = procName;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(parameters);
var rr = cmd.ExecuteScalar();
st.Commit();
return rtn;
}
catch (SqlException sqlex)
{
st.Rollback();
throw sqlex;
}
}
}
}
}
}

@ -27,5 +27,36 @@
</simple>
</trigger>
<job>
<name>JobDingTalkUserList</name>
<group>System</group>
<description>定时同步钉钉通讯录服务</description>
<job-type>DSWeb.BillCenter.Service.DingtalkUserList.JobDS7BillOutput,DSWeb.BillCenter.Service.DingtalkUserList</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<!--<trigger>
<simple>
<name>TriggerDingTalkUserList</name>
<group>System</group>
<description>定时同步钉钉通讯录服务触发器</description>
<job-name>JobDingTalkUserList</job-name>
<job-group>System</job-group>
<repeat-count>-1</repeat-count>
<repeat-interval>60000</repeat-interval>
</simple>
</trigger>-->
<trigger>
<cron>
<name>TriggerDingTalkUserList</name>
<group>System</group>
<description>定时同步钉钉通讯录服务触发器</description>
<job-name>JobDingTalkUserList</job-name>
<job-group>System</job-group>
<cron-expression>0 0 0/1 * * ? </cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>

@ -16,6 +16,7 @@ using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.MvcShipping.DAL;
using HcUtility.Comm;
using DSWeb.MvcShipping.DAL.MsCodeEmployee;
namespace DSWeb.Areas.CommMng.Controllers
{
@ -101,10 +102,11 @@ namespace DSWeb.Areas.CommMng.Controllers
/// 获取钉钉的通讯录
/// </summary>
/// <returns></returns>
[HttpPost]
public ContentResult DingTalkUserList() {
var result = new DBResult();
result = MsCodeEmployeeDAL.GetDingTalkUserList();
return BasicDataRefDAL.GetContentResult(result);
}

@ -6,7 +6,11 @@ using DSWeb.MvcShipping.Models.MsCodeEmployee;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.Areas.MvcShipping.Helper;
using DSWeb.Common.DB;
using System.Linq;
using DSWeb.SoftMng.Model;
using System.Data.Entity.Migrations;
namespace DSWeb.MvcShipping.DAL.MsCodeEmployee
{
@ -292,6 +296,83 @@ namespace DSWeb.MvcShipping.DAL.MsCodeEmployee
return result;
}
public static DBResult GetDingTalkUserList()
{
var result = new DBResult();
try
{
var userlist = DingTalkHelper.GetUserList();
DingTalk_.deptlist = DingTalkHelper.GetDeptList();
var cdc = new CommonDataContext();
var codeemployeeList = cdc.code_employee.ToList();
var updList = new List<DingTalk_>();
var insertList = new List<DingTalk_>();
var _updList = new List<code_employee_md>();
var _insertList = new List<code_employee_md>();
foreach (var item in userlist)
{
if (codeemployeeList.Exists(x => x.GID == item.userid))
{
//var curruser = codeemployeeList.First(x => x.GID == item.userid);
//curruser.USERNAME = item.name;
//curruser.MOBILE = item.mobile;
//curruser.MODIFIEDTIME = DateTime.Now;
//curruser.OFFICEPHONE = item.telephone;
updList.Add(item);
_updList.Add(codeemployeeList.First(x => x.GID == item.userid));
}
else
{
insertList.Add(item);
}
}
if (updList.Count > 0)
{
foreach (var item in updList)
{
var newupdrec = item.getCodeEmployee();
var updrec = _updList.First(x => x.GID == item.userid);
updrec.USERNAME = newupdrec.USERNAME;
updrec.MOBILE = newupdrec.MOBILE;
updrec.MODIFIEDTIME = newupdrec.MODIFIEDTIME;
updrec.OFFICEPHONE = newupdrec.OFFICEPHONE;
updrec.CORPID= newupdrec.CORPID;
updrec.DEPTNAME=newupdrec.DEPTNAME;
updrec.OFFICEADDR=newupdrec.OFFICEADDR;
cdc.code_employee.AddOrUpdate(updrec);
}
}
if (insertList.Count > 0)
{
foreach (var item in insertList)
{
var newinsertrec = item.getCodeEmployee();
cdc.code_employee.AddOrUpdate(newinsertrec);
}
}
cdc.SaveChanges();
result.OK("同步完成");
}
catch(Exception e){
result.SetErrorInfo(e.Message);
}
return result;
}
}
}

@ -1,4 +1,5 @@
using System;
using HcUtility.Comm;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
@ -16,5 +17,21 @@ namespace DSWeb.Areas.MvcShipping.DB
public DbSet<User> Users { get; set; }
public DbSet<SysParamSet> ParamSets { get; set; }
public SysParamSet pAgentid { get; set; }
public DBResult CanUse() {
var result = new DBResult();
pAgentid = ParamSets.FirstOrDefault(p => p.PARAMNAME == "DingTalkAgentid");
if (pAgentid == null || string.IsNullOrWhiteSpace(pAgentid.PARAMVALUE))
{
//throw new Exception("钉钉Agentid参数配置错误");
result.SetErrorInfo("钉钉Agentid参数配置错误");
}
else {
result.OK();
}
return result;
}
}
}

@ -1,14 +1,21 @@
using DSWeb.Areas.Dispatch.Helper;
using DSWeb.Areas.CommMng.Controllers;
using DSWeb.Areas.Dispatch.Helper;
using DSWeb.Areas.MvcShipping.DB;
using DSWeb.Areas.MvcShipping.Job;
using DSWeb.Common.DB;
using DSWeb.MvcShipping.Models.MsCodeEmployee;
using HcUtility.Comm;
using java.rmi.server;
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.EnterpriseServices.Internal;
using System.Linq;
using System.Runtime.Caching;
using System.Web;
using static sun.awt.CausedFocusEvent;
namespace DSWeb.Areas.MvcShipping.Helper
{
@ -18,6 +25,7 @@ namespace DSWeb.Areas.MvcShipping.Helper
private static ILog logger = LogManager.GetLogger("DingTalkHelper");
public static bool SendMessage(string uid, string msg)
{
DingTalkContext dingTalkContext = new DingTalkContext();
@ -63,5 +71,239 @@ namespace DSWeb.Areas.MvcShipping.Helper
return false;
}
public static List<DingTalk_> GetUserList(int dept_id = 1,int? cursor=0)
{
var result = new List<DingTalk_>();
DingTalkContext dingTalkContext = new DingTalkContext();
//if (!dingTalkContext.CanUse().Success)
//{
// throw new Exception(dingTalkContext.CanUse().Message);
//}
var token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
var json = new
{
dept_id = dept_id,
cursor = cursor,
size=1
};
string resp = WebRequestHelper.DoPost($"https://oapi.dingtalk.com/topapi/v2/user/list?access_token={token}", JsonConvert.SerializeObject(json));
logger.Debug(resp);
var userlistresult = JsonConvert.DeserializeObject<DingTalk_info>(resp);
result.AddRange(userlistresult.result.list);
if (userlistresult.result.has_more) {
var newresult = GetUserList(dept_id, userlistresult.result.next_cursor);
result.AddRange(newresult);
}
return result;
}
public static List<DingTalk_> GetDeptList(int dept_id = 1)
{
DingTalkContext dingTalkContext = new DingTalkContext();
//if (!dingTalkContext.CanUse().Success) {
// throw new Exception(dingTalkContext.CanUse().Message);
//}
var result=new List<DingTalk_>();
var token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
var json = new
{
dept_id = dept_id
};
string resp = "";
resp=WebRequestHelper.DoPost($"https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token={token}", JsonConvert.SerializeObject(json));
logger.Debug(resp);
/*{
"errcode":0,
"result":[
{
"auto_add_user":true,
"parent_id":1,
"name":"经汉测试",
"dept_id":831067016,
"create_dept_group":true
},
{
"auto_add_user":true,
"parent_id":1,
"name":"仓储部",
"dept_id":809181118,
"create_dept_group":true
}
],
"errmsg":"ok",
"request_id":"16kmqqovk737j"
}*/
var jsonObj = JsonConvert.DeserializeObject<DingTalk_Result>(resp);
if (jsonObj.errcode == 0)
{
//return true;
if (jsonObj.result != null && jsonObj.result.Count > 0) {
result.AddRange(jsonObj.result);
foreach(var item in jsonObj.result )
{
var _r = GetDeptList(item.dept_id);
if (_r != null && _r.Count > 0)
{
result.AddRange(_r);
}
}
}
}
return result;
}
}
public class DingTalkResult {
public int errcode { get; set; }
public string errmsg { get; set; }
public string request_id { get; set; }
//public virtual object result { get; set; }
}
public class DingTalk_info : DingTalkResult
{
//"has_more":false,
//"next_cursor":1,
public DingTalk_result result { get; set; }
}
public class DingTalk_result
{
//"has_more":false,
//"next_cursor":1,
public bool has_more { get; set; }
public int? next_cursor { get; set; }
public List<DingTalk_> list { get; set; }
}
public class DingTalk_
{
//使用company.TRADE_CODE 存放所属分公司的部门ID
//{
// "dept_order":176240477069450512,
// "leader":false,
// "boss":false,
// "unionid":"cW8AXMajbyktliPjonBnTiSgiEiE",
// "exclusive_account":false,
// "mobile":"15192712750",
// "active":true,
// "admin":false,
// "remark":"",
// "telephone":"",
// "avatar":"https://static-legacy.dingtalk.com/media/lADPBbCc1UgQulLNAx_NA8A_960_799.jpg",
// "hide_mobile":false,
// "userid":"0905390251649410",
// "work_place":"",
// "name":"于斐",
// "dept_id_list":[
// 1,
// 831067016
// ],
// "state_code":"86",
// "email":""
// }
public long dept_order { get; set; }
public bool? leader { get; set; }
public bool? boss { get; set; }
public string unionid { get; set; }
public bool? exclusive_account { get; set; }
public string mobile { get; set; }
public bool? active { get; set; }
public bool? admin { get; set; }
public string remark { get; set; }
public string telephone { get; set; }
public string avatar { get; set; }
public bool? hide_mobile { get; set; }
public string userid { get; set; }
public string work_place { get; set; }
public string name { get; set; }
public string email { get; set; }
public List<int> dept_id_list { get; set; }
public List<string> deptidlist() {
var result = new List<string>();
foreach (var item in dept_id_list) {
result.Add(item.ToString());
}
return result;
}
public static List<DingTalk_> deptlist{ get; set; }
public code_employee_md getCodeEmployee() {
var result = new code_employee_md();
result.GID = userid;
result.USERNAME = name;
result.MOBILE= mobile;
result.OFFICEPHONE= telephone;
result.OFFICEADDR = work_place;
result.STATUS = "在职";
//根据部门信息dept_id_list 查找company.trade_code=其中一个部门id的公司
//companyid是这个公司的id
var cdc = new CommonDataContext();
var _deptidlist = deptidlist();
var companydeptid = 0;
var company = cdc.company.Where(x => _deptidlist.Contains(x.TRADE_CODE)).ToList();
if (company != null && company.Count > 0)
{
result.CORPID = company[0].GID;
companydeptid = Convert.ToInt32(company[0].TRADE_CODE);
}
//根据companydeptid 读取部门信息
//如果这个部门的下属部门deptid 和 dept_id_list有交集
//则选取其中一个交集作为部门信信息的来源
var companydeptList = deptlist.Where(x => x.parent_id == companydeptid).ToList();
foreach (var dept in deptlist.Where(x => x.dept_id != 1 && x.dept_id != companydeptid))
{
if (companydeptList.Exists(x => x.dept_id == dept.dept_id))
{
result.DEPTNAME = companydeptList.FirstOrDefault(x => x.dept_id == dept.dept_id).name;
}
}
return result;
}
}
public class DingTalk_Result : DingTalkResult
{
public List<DingTalk_> result { get; set; }
}
public class DingTalk_
{
public bool auto_add_user { get; set; }
public int parent_id { get; set; }
public string name { get; set; }
public int dept_id { get; set; }
public bool create_dept_group { get; set; }
}
}

@ -367,6 +367,14 @@ Ext.extend(Shipping.MsCodeEmployeeIndex, Ext.Panel, {
handler: function (button, event) {
},
scope: this
}, '-',
{
text: "获取钉钉通讯录",
iconCls: "btnrefresh",
handler: function (button, event) {
this.onGetDingTalkClick(button, event);
},
scope: this
}
]
});
@ -547,7 +555,40 @@ Ext.extend(Shipping.MsCodeEmployeeIndex, Ext.Panel, {
ret[2] = this.SelectedRecord;
return ret;
}
},
onGetDingTalkClick: function (button, event) {
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/CommMng/PublicAPI/DingTalkUserList',
scope: this,
params: {
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
this.onRefreshClick();
} else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({
title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
}, //end save
});

Loading…
Cancel
Save