ComplianceServer/oldcode/Core.BLL/EventBus/EventHandlers/RejectContractEventHandler.cs

281 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CRM.Core.BLL.Base;
using CRM.Core.BLL.EventBus.Events;
using CRM.Core.BLL.Util;
using CRM.Core.BLL.Wx;
using CRM.Core.Common.EventBus;
using CRM.Core.Common.WebHelper;
using CRM.Core.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WX.CRM.Common;
namespace CRM.Core.BLL.EventBus.EventHandlers
{
public class RejectContractEventHandler : IEventHandler<RejectContractEvent>
{
private readonly SecurityHelper sHelper = new SecurityHelper();
private readonly WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL();
private readonly Bas_ActLog_BL _actLog = new Bas_ActLog_BL();
private CACHE_BL _cache = new CACHE_BL();
public void Handle(RejectContractEvent @event)
{
try
{
LogHelper.Info("合同审核事件推送执行:" + @event.ToJson());
var env = Utility.GetSettingOrNullByKey("env");
var order = _order.Get(p => p.ORDERID == @event.OrderId);
if (order != null)
{
try
{
var status = "0";
if (!string.IsNullOrWhiteSpace(@event.RejectRemark))
{
var rejectArr = @event.RejectRemark.Split(new char[3] { '#', '#', '#' }, StringSplitOptions.RemoveEmptyEntries);
status = rejectArr[0].Replace("[", "").Replace("]", "");
}
var orderId = Convert.ToInt64(order.SZZYORDERID.Value);
var content = new { orderId, status };
var paraYP = JsonHelper.ObjDivertToJson(sHelper.createAjaxSignEncodingStr(JsonHelper.ObjDivertToJson(content), SecurityHelper.OrderClientIdKey));
//LogHelper.Info("paraYP:" + paraYP.ToString());
var ypurl = "https://r2.soft.dn8188.com/contract_sign_crm/updatecompliancestatus";
if (!string.IsNullOrEmpty(env))
{
ypurl = "http://192.168.11.141:10004/contract_sign_crm/updatecompliancestatus";
}
var retmsg = Utility.PostAjaxData(ypurl, paraYP, Encoding.UTF8);//返回信息
LogHelper.Info("优品接口调用返回数据json=>:" + retmsg);
}
catch (Exception ee)
{
LogHelper.Error("优品接口调用错误:" + ee.ToString());
}
try
{
if (string.IsNullOrEmpty(env))
{
var status = "0";
if (!string.IsNullOrWhiteSpace(@event.RejectRemark))
{
var rejectArr = @event.RejectRemark.Split(new char[3] { '#', '#', '#' }, StringSplitOptions.RemoveEmptyEntries);
status = rejectArr[0].Replace("[", "").Replace("]", "");
}
var orderId = Convert.ToInt64(order.SZZYORDERID.Value);
var username = order.SOFTUSERNAME;
var productcode = order.PRODUCTCODE;
var content = new { username, orderId, productcode, status };
var paraYP = JsonHelper.ObjDivertToJson(sHelper.createAjaxSignEncodingStr(JsonHelper.ObjDivertToJson(content), SecurityHelper.OrderClientIdKey));
//LogHelper.Info("paraYP2:" + paraYP.ToString());
var retmsg = Utility.PostAjaxData("http://post.hc.dn8188.com/Rights/signback.html", paraYP, Encoding.UTF8);//返回信息
LogHelper.Info("企微接口调用返回数据json=>:" + retmsg);
}
}
catch (Exception exx)
{
LogHelper.Error("企微接口调用错误:" + exx.ToString());
}
try
{
//http://post.hc.dn8188.com/Rights/orderback.html
var noticeUrl = Utility.GetSettingByKey("noticeUrl");
if (!string.IsNullOrEmpty(noticeUrl))
{
Utility.GetData(noticeUrl, "orderid=" + @event.OrderId.ToString() + "&type=3&values=" + @event.Status, Encoding.UTF8);
}
}
catch (Exception exx)
{
LogHelper.Error("通知前端错误:" + exx.ToString());
}
var pt1Channel = _cache.GetValue_Parameter("pt1Channel");
if (!string.IsNullOrEmpty(pt1Channel))
{
try
{
var arrChannel = pt1Channel.Split('|');
foreach (var channel in arrChannel)
{
var itemChannel = channel.Split(',');
var min = Convert.ToInt32(itemChannel[0]);
var max = Convert.ToInt32(itemChannel[1]);
if (order.CHANNEL >= min && order.CHANNEL <= max)
{
var Username = "donggao";
var Password = "clyuQwhLcUgQfV1r";
var Authorization = "Basic " + Utility.StrToBase64(Username + ":" + Password);
//LogHelper.Info("Authorization:" + Authorization);
var orderNo = order.outorderno;
var thirdOrderNo = Convert.ToInt64(order.SZZYORDERID.Value);
var status = "1";
var dics = new Dictionary<string, string>
{
{ "orderNo", orderNo },
{ "thirdOrderNo", thirdOrderNo.ToString() },
//{ "reasonIdList", reasonIdList.ToJson() }
};
var reasonIdList = new List<int>();
if (@event.Status == -1)
{
var rejectArr = @event.RejectRemark.Split(new char[3] { '#', '#', '#' }, StringSplitOptions.RemoveEmptyEntries);
var rejectStr = rejectArr[0].Replace("[", "").Replace("]", "");
if (!rejectStr.StartsWith("7"))
{
reasonIdList = (new List<string>(rejectStr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)).Select<string, int>(x => Convert.ToInt32(x))).ToList();
status = "2";
}
}
dics.Add("status", status);
dics.Add("reasonIdList", reasonIdList.ToJson());
var param = Utility.GetParamSrc(dics);
//LogHelper.Info("param:" + param);
var sign = Utility.EncryptMD5(param).ToUpper();
//LogHelper.Info("sign:" + sign);
var tnbPara = new { orderNo, thirdOrderNo, reasonIdList, status, sign };
LogHelper.Info("tnbPara:" + tnbPara.ToJson());
if (string.IsNullOrEmpty(env))
{
var res = Utility.PostAjaxData("http://tnbapi.dn8188.com/orders/ruleAudit", tnbPara.ToJson(), Authorization, true);
//var res = Utility.PostAjaxData("http://test-tnbapi.dn8188.com/orders/ruleAudit", tnbPara.ToJson(), Authorization, true);
LogHelper.Info("res" + res);
}
}
}
}
catch (Exception exx)
{
LogHelper.Error("淘牛帮接口调用错误:" + exx.ToString());
}
}
else
{
if ((order.CHANNEL >= 25000 && order.CHANNEL <= 26199) || (order.CHANNEL >= 3900 && order.CHANNEL <= 3999))
{
try
{
var Username = "donggao";
var Password = "clyuQwhLcUgQfV1r";
var Authorization = "Basic " + Utility.StrToBase64(Username + ":" + Password);
//LogHelper.Info("Authorization:" + Authorization);
var orderNo = order.outorderno;
var thirdOrderNo = Convert.ToInt64(order.SZZYORDERID.Value);
var status = "1";
var dics = new Dictionary<string, string>
{
{ "orderNo", orderNo },
{ "thirdOrderNo", thirdOrderNo.ToString() },
//{ "reasonIdList", reasonIdList.ToJson() }
};
var reasonIdList = new List<int>();
if (@event.Status == -1)
{
var rejectArr = @event.RejectRemark.Split(new char[3] { '#', '#', '#' }, StringSplitOptions.RemoveEmptyEntries);
var rejectStr = rejectArr[0].Replace("[", "").Replace("]", "");
if (!rejectStr.StartsWith("7"))
{
reasonIdList = (new List<string>(rejectStr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)).Select<string, int>(x => Convert.ToInt32(x))).ToList();
status = "2";
}
}
dics.Add("status", status);
dics.Add("reasonIdList", reasonIdList.ToJson());
var param = Utility.GetParamSrc(dics);
//LogHelper.Info("param:" + param);
var sign = Utility.EncryptMD5(param).ToUpper();
//LogHelper.Info("sign:" + sign);
var tnbPara = new { orderNo, thirdOrderNo, reasonIdList, status, sign };
LogHelper.Info("tnbPara:" + tnbPara.ToJson() + ",channel:" + order.CHANNEL);
if (string.IsNullOrEmpty(env))
{
var res = Utility.PostAjaxData("http://tnbapi.dn8188.com/orders/ruleAudit", tnbPara.ToJson(), Authorization, true);
//var res = Utility.PostAjaxData("http://test-tnbapi.dn8188.com/orders/ruleAudit", tnbPara.ToJson(), Authorization, true);
LogHelper.Info("res" + res);
}
}
catch (Exception exx)
{
LogHelper.Error("淘牛帮接口调用错误:" + exx.ToString());
}
}
}
}
var host = Utility.GetSettingOrNullByKey("DataSyncApiUrl");
var url = host + "/api/DataSync";
var para = new SYNC_PUSH_DTO()
{
bidatatype = "Client_RejectContract",
deptcode = @event.DeptCode,
jsontext = new { @event.OrderId, @event.Status, @event.RejectRemark, @event.IdCard, @event.Name }.ToJson()
};
var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8);
var ret = Utility.JSONToObject<retMsg>(rep);
if (!ret.result)
LogHelper.Error("接口 SignContractEventHandler 写入失败!");
if (@event.OperaId.HasValue)
{
var info = new Model.Entity.Bas_ActLog() { ActType = 2, ActTypeName = "合同审核", Operaor = @event.OperaId.Value, OperatorName = @event.OperaName, Status = @event.Status, OperationTime = DateTime.Now, OrderId = @event.OrderId };
if (@event.Status == 2)
{
info.Remark = "合同审核通过";
}
else if (@event.Status == -1)
{
info.Remark = "合同审核驳回";
}
else
{
info.Remark = "未知";
}
_actLog.Add(info);
}
}
catch (Exception ex)
{
LogHelper.Error("签约事件推送错误:" + ex.ToString());
}
}
}
}