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.
DS7/DSWeb/Areas/Dispatch/Helper/DingTalkHelper.cs

1837 lines
69 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 AlibabaCloud.SDK.Dingtalkh5package_1_0.Models;
using AlibabaCloud.SDK.Dingtalkvillage_1_0.Models;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Dispatch.Helper;
using DSWeb.Areas.MvcShipping.DB;
using DSWeb.Areas.MvcShipping.Job;
using DSWeb.Areas.MvcShipping.Models.MsOpSeaeBaoXian;
using DSWeb.Common.DB;
using HcUtility.Comm;
using java.rmi.server;
using java.util;
using log4net;
using Microsoft.Office.Interop.Excel;
using Newtonsoft.Json;
using NPOI.OpenXmlFormats.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using Tea;
using static DSWeb.Areas.CommMng.Controllers.WorkFlowController;
using static DSWeb.Areas.MvcShipping.Helper.DingTalk_SendAuditWork;
using Newtonsoft.Json.Linq;
using sun.tools.jar.resources;
using System.Data.Entity.Migrations;
using AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models;
using NPOI.SS.Formula.Functions;
using System.Text.RegularExpressions;
using DSWeb.MvcShipping.Models.DingTalkSet;
using HcUtility.Core;
using DSWeb.MvcShipping.DAL.MsCodeDingTalkSet;
using DSWeb.Areas.Account.DAL.Chfee_Payapplication;
namespace DSWeb.Areas.Dispatch.Helper
{
public static class DingTalkHelper
{
public static readonly string DingTalkAccessTokenStoreKey = "DingTalkToken";
private static ILog logger = LogManager.GetLogger("DingTalkHelper");
/// <summary>
/// 发送工作通知
/// https://open-dev.dingtalk.com/apiExplorer#/?devType=org&api=dingtalk.oapi.message.corpconversation.asyncsend_v2
/// </summary>
/// <param name="uid"></param>
/// <param name="msg"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static bool SendMessage(string uid, string msg)
{
DingTalkContext dingTalkContext = new DingTalkContext();
var pAgentid = dingTalkContext.ParamSets.FirstOrDefault(p => p.PARAMNAME == "DingTalkAgentid");
if (pAgentid == null || string.IsNullOrWhiteSpace(pAgentid.PARAMVALUE))
{
throw new Exception("钉钉Agentid参数配置错误");
}
var user = dingTalkContext.Users.FirstOrDefault(u => u.GID == uid);
if (user != null && !string.IsNullOrWhiteSpace(user.DingTalkAccount))
{
var token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
var json = new
{
agent_id = pAgentid.PARAMVALUE,
userid_list = user.DingTalkAccount,
msg = new
{
msgtype = "text",
text = new
{
content = msg
}
}
};
string resp = WebRequestHelper.DoPost($"https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token={token}", JsonConvert.SerializeObject(json));
logger.Debug(resp);
var jsonObj = JsonConvert.DeserializeAnonymousType(resp, new
{
errcode = 0,
errmsg = "",
task_id = ""
});
if (jsonObj.errcode == 0)
{
return true;
}
}
return false;
}
/// <summary>
/// 读取实例当前值 data内容是json文本
/// </summary>
/// <param name="instanceId"></param>
/// <returns></returns>
public static DBResult DingTalk_Instanceinfo(string instanceId) {
//https://open.dingtalk.com/document/isvapp-server/queries-a-process-instance-based-on-its-id
var result = new DBResult();
DingTalk_Instanceinfo dh = new DingTalk_Instanceinfo();
dh.MakeSendMessage(instanceId);//i0P82FAHT_G9TWJmavxGdg03131673000830
result = dh.DoSend();
return result;
}
//public static DBResult DingTalk_ReadWMSINInstance(string instanceId)
//{
// var result = new DBResult();
// var instanceiddic = BasicDataRefDAL.GetLogicInfo(wmsno, "钉钉审批");
// if (instanceiddic == null || !instanceiddic.ContainsKey("instanceId"))
// {
// return result.SetErrorInfo(wmsno + "没有进行钉钉审批");
// }
// else
// {
// }
// var _r = DingTalk_Instanceinfo(instanceId);
// if (!_r.Success)
// {
// return _r;
// }
// 如果成功 用数据对象解析结果 并做相应处理
//}
public static DBResult Send_Audit(CodeDingTalkSet TalkSet, List<CodeDingTalkSetDetail> TalkSetDetail,string BILLNO, ModelObjectBillHead MasterDB, List<ModelObjectBase> FenDb1, string uid,long deptid)
{
var result = new DBResult();
DingTalk_Send_Audit dh = new DingTalk_Send_Audit(TalkSet, uid);
result = dh.MakeSendMessage(TalkSet,TalkSetDetail, BILLNO, MasterDB, FenDb1, deptid);
if (!result.Success)
{
return result;
}
result = dh.DoSend();
return result;
}
public static DBResult SubmitAuditBack(CodeDingTalkSet TalkSet,string BILLNO, string uid)
{
var result = new DBResult();
DingTalk_Send_Audit dh = new DingTalk_Send_Audit(TalkSet, uid);
result = dh.MakeSubmitAuditBackMessage(TalkSet, BILLNO);
if (!result.Success)
{
return result;
}
result = dh.DoSendSubmitAuditBack();
return result;
}
public static DBResult CallBack(DingCallBackInfo DingCallBackInfo)
{
var result = new DBResult();
var DingTalkSet = MsCodeDingTalkSetDAL.GetData("PROCID='"+ DingCallBackInfo.processCode+ "' AND ISENABLE=1", "");
if (DingTalkSet == null || !DingTalkSet.ISENABLE)
{
return result;
}
if (DingTalkSet.MODULENAME == "付款申请") {
var lv = BasicDataRefDAL.GetLogicHaveValue("钉钉审批", "instanceId", DingCallBackInfo.processInstanceId);
if (lv != null && lv.ContainsKey("instanceId"))
{
var BILLNO = lv["BSNO"];
if (DingCallBackInfo.EventType == "bpms_instance_change" && DingCallBackInfo.result == "agree"&&DingCallBackInfo.type=="finish")
{
BasicDataRefDAL.SaveLog("AuditList" + BILLNO, "admin", "钉钉回调", "bpms_instance_change");
var Payapplist = ChpayapplicationDAL.GetAuditAllDataList("i.BILLNO='"+BILLNO+"'");
var WorkFlowID = WorkFlowDAL.GetBSNOWorkFlowID("FeeSettleAudit", BILLNO)[0].GID;
var RECEIVER = WorkFlowDAL.GetAuditor(WorkFlowID, "1");
if (RECEIVER != null && RECEIVER.Count != 0) {
result = ChpayapplicationDAL.AuditList(Payapplist, RECEIVER[0].GID);
}
}
else if (DingCallBackInfo.type == "finish"&&DingCallBackInfo.result == "refuse")
{
BasicDataRefDAL.SaveLog("AuditBackList"+BILLNO, "admin", "钉钉回调", "bpms_instance_change");
var Payapplist = ChpayapplicationDAL.GetAuditAllDataList("i.BILLNO='" + BILLNO + "'");
var WorkFlowID = WorkFlowDAL.GetBSNOWorkFlowID("FeeSettleAudit", BILLNO)[0].GID;
var RECEIVER = WorkFlowDAL.GetAuditor(WorkFlowID, "1");
if (RECEIVER != null && RECEIVER.Count != 0)
{
result = ChpayapplicationDAL.AuditBackList(Payapplist, RECEIVER[0].GID,"");
}
}
}
}
return result;
}
}
public class DingTalkSendHelper {
public DingTalkSendHelper() { }
public string url { get; set; }
public string uid { get; set; }
public object SendObject { get; set; }
public SysParamSet pAgentid { get; set; }
public DSWeb.Areas.MvcShipping.DB.User user { get; set; } = null;
public object jsonObj { get; set; }
public Dictionary<string, string> dicObj { get; set; } = new Dictionary<string, string>();
public string json { get; set; }
public string token { get; set; }
public Dictionary<string, string> HeaderDic { get; set; }
private static ILog logger = LogManager.GetLogger("DingTalkHelper");
public DingTalkContext dingTalkContext { get; set; } = new DingTalkContext();
DBResult result { get; set; } = new DBResult();
public DBResult getUser()
{
user = dingTalkContext.Users.FirstOrDefault(u => u.GID == uid);
if (user == null || string.IsNullOrWhiteSpace(user.DingTalkAccount))
{
result.SetErrorInfo("用户没有维护钉钉userid");
return result;
}
result.OK();
return result;
}
public DBResult GetAgentid() {
result = new DBResult();
pAgentid = dingTalkContext.ParamSets.FirstOrDefault(p => p.PARAMNAME == "DingTalkAgentid");
if (pAgentid == null || string.IsNullOrWhiteSpace(pAgentid.PARAMVALUE))
{
result.SetErrorInfo("钉钉Agentid参数配置错误");
return result;
}
result.OK();
return result;
}
public DBResult DoSend() {
var result = new DBResult();
string resp = WebRequestHelper.DoPost(url, JsonConvert.SerializeObject(jsonObj));
logger.Debug(resp);
result.setMessage(true,"发送成功", jsonObj);
return result;
}
public DBResult DoSend_Header()
{
var result = new DBResult();
string resp = "";
if (jsonObj != null)
{
BasicDataRefDAL.SaveLog("url:" + url+ "header:" +JsonConvert.SerializeObject(HeaderDic)+" body:"+ JsonConvert.SerializeObject(jsonObj),"","钉钉审核","发出");
resp=WebRequestHelper.DoPost_Header(url, HeaderDic, jsonObj);
BasicDataRefDAL.SaveLog(resp, "", "钉钉审核", "返回");
}
else {
resp=WebRequestHelper.DoPost_Header(url, HeaderDic);
}
logger.Debug(resp);
result.setMessage(true, "发送成功", resp);
return result;
}
public DBResult DoGet_Header_Param()
{
var result = new DBResult();
string resp = WebRequestHelper.DoGet_Header_Param(url, HeaderDic, dicObj);
//logger.Debug(resp);
result.setMessage(true, "发送成功", resp);
return result;
}
public static object JsonToObject(string jsonString, object obj)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
return serializer.ReadObject(mStream);
}
}
public class DingTalk_SendWorkMessage : DingTalkSendHelper {
public DingTalk_SendWorkMessage(string uid) {
this.uid = uid;
}
public DBResult MakeSendMessage(string msg) {
var result = new DBResult();
result = GetAgentid();
if (!result.Success) return result;
result = getUser();
if (!result.Success) return result;
jsonObj = new
{
agent_id = pAgentid.PARAMVALUE,
userid_list = user.DingTalkAccount,
msg = new
{
msgtype = "text",
text = new
{
content = msg
}
}
};
token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
url = $"https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token={token}";
result.OK();
return result;
}
}
public class DingTalk_SendAuditWork : DingTalkSendHelper
{
public string BSNO { get; set; }
public DingTalk_SendAuditWork()
{
}
public DingTalk_SendAuditWork(string uid)
{
this.uid = uid;
getUser();
}
public class DingTalkFormField {
public string name { get; set; }
public string value { get; set; }
public DingTalkFormField(string name, string value)
{
this.name = name;
this.value = value;
}
}
public class DingTalkForm_approvers
{
public string actionType { get; set; }
public List<string> userIds { get; set; }
public DingTalkForm_approvers(string actionType, List<string> userIds)
{
this.actionType = actionType;
this.userIds = userIds;
}
}
public class DingTalk_OAAuditBody {
public long deptId { get; set; }
public List<DingTalkForm_approvers> approvers { get; set; } = new List<DingTalkForm_approvers>();
public long microappAgentId { get; set; }
public string originatorUserId { get; set; }
public string processCode { get; set; }
public List<DingTalkFormField> formComponentValues { get; set; } = new List<DingTalkFormField>();
}
public class User
{
public string userId { get; set; }
}
public class updateProcessInstanceRequests
{
public string processInstanceId { get; set; }
public bool isSystem { get; set; }
public string remark { get; set; }
public string operatingUserId { get; set; }
}
public class DingTalk_OAAuditStatus
{
public updateProcessInstanceRequests updateProcessInstanceRequests { get; set; }
// public List<updateProcessInstanceRequests> updateProcessInstanceRequests { get; set; } = new List<updateProcessInstanceRequests>();
}
public DBResult cansend_in(string wmsno)
{
var result = new DBResult();
result.OK();
return result;
}
public bool cansend_out(string BSNO) {
return true;
}
public virtual DBResult MakeSendMessage(CodeDingTalkSet TalkSet, List<CodeDingTalkSetDetail> TalkSetDetail,string BILLNO, ModelObjectBillHead MasterDB, List<ModelObjectBase> FenDb1,long deptid)
{
var result = new DBResult();
return result;
}
public virtual DBResult MakeSubmitAuditBackMessage(CodeDingTalkSet TalkSet, string billnos)
{
var result = new DBResult();
return result;
}
public class DingTalk_SendAuditResult {
public string instanceId { get; set; }
}
public DBResult DoSend() {
var result = base.DoSend_Header();
if (result.Success) {
try
{
var jo = new DingTalk_SendAuditResult();
jo = (DingTalk_SendAuditResult)JsonToObject(result.Data.ToString(), jo);
var dic = new Dictionary<string, string>
{
{ "instanceId", jo.instanceId }
};
BasicDataRefDAL.SaveLogicInfo(BSNO, "钉钉审批", dic);
}catch(Exception ex)
{
}
}
return result;
}
}
public class DingTalk_Send_Audit : DingTalk_SendAuditWork
{
public DingTalk_Send_Audit(CodeDingTalkSet TalkSet, string uid)
{
this.uid = uid;
getUser();
}
public override DBResult MakeSendMessage(CodeDingTalkSet TalkSet, List<CodeDingTalkSetDetail> TalkSetDetailList,string BILLNO, ModelObjectBillHead MasterDB, List<ModelObjectBase> FenDb1,long deptid)
{
var result = new DBResult();
try
{
if (string.IsNullOrWhiteSpace(user.DingTalkAccount))
{
return result.SetErrorInfo("请配置用户的钉钉id");
}
BSNO = BILLNO;
DingTalk_OAAuditBody body = new DingTalk_OAAuditBody();
var app = DingTalkApp.GetDingTalkApp(TalkSet);
//var dp = app.GetProcess(TalkSet);
body.deptId = deptid;//
//获取用户的钉钉id
var dtc = new DingTalkContext();
body.microappAgentId =Convert.ToInt64(TalkSet.AGENTID);//
body.originatorUserId = user.DingTalkAccount;
body.processCode = TalkSet.PROCID;
var bodylist = new List<List<DingTalkFormField>>();
var DDFIELDNAME = "";
foreach (var item in FenDb1)
{
var newrk = new List<DingTalkFormField>();
foreach (var TalkSetDetail in TalkSetDetailList) {
if (TalkSetDetail.TABLETYPE == "明细数据1") {
var fieldname = TalkSetDetail.DFIELDNAME;
var fieldvalue = "";
if (!string.IsNullOrEmpty(TalkSetDetail.DEFAULTVALUE)) fieldvalue = TalkSetDetail.DEFAULTVALUE;
else {
var propArr = item.GetType().GetProperties();
var prop = propArr.FirstOrDefault(p => p.Name.ToLower() == TalkSetDetail.FIELDNAME.ToLower());
if (prop != null) {
if (prop.PropertyType.Name =="Decimal")
{
fieldvalue = Convert.ToDecimal(prop.GetValue(item)).ToString("0.00").Trim();
}
else
fieldvalue = prop.GetValue(item).ToString();
}
}
var FormField = new DingTalkFormField(fieldname, fieldvalue);
newrk.Add(FormField);
DDFIELDNAME = TalkSetDetail.DDFIELDNAME;
}
}
bodylist.Add(newrk);
}
body.formComponentValues = new List<DingTalkFormField>();
foreach (var TalkSetDetail in TalkSetDetailList)
{
if (TalkSetDetail.TABLETYPE == "主数据")
{
var fieldname = TalkSetDetail.DFIELDNAME;
var fieldvalue = "";
if (!string.IsNullOrEmpty(TalkSetDetail.DEFAULTVALUE)) fieldvalue = TalkSetDetail.DEFAULTVALUE;
else
{
var propArr = MasterDB.GetType().GetProperties();
var prop = propArr.FirstOrDefault(p => p.Name.ToLower() == TalkSetDetail.FIELDNAME.ToLower());
if (prop != null)
{
if (prop.PropertyType.Name == "Decimal")
{
fieldvalue = Convert.ToDecimal(prop.GetValue(MasterDB)).ToString("0.00").Trim();
}
else
fieldvalue = prop.GetValue(MasterDB).ToString();
}
}
var FormField = new DingTalkFormField(fieldname, fieldvalue);
body.formComponentValues.Add(FormField);
}
if (bodylist != null && bodylist.Count != 0) {
body.formComponentValues.Add(new DingTalkFormField(DDFIELDNAME, JsonConvert.SerializeObject(bodylist)));
}
}
jsonObj = body;
token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
url = $"https://api.dingtalk.com/v1.0/workflow/processInstances";
HeaderDic = new Dictionary<string, string>
{
{ "x-acs-dingtalk-access-token", token }
};
result.OK();
return result;
}
catch (Exception e)
{
return result.SetErrorInfo(e.Message);
}
}
public override DBResult MakeSubmitAuditBackMessage(CodeDingTalkSet TalkSet,string billno)
{
var result = new DBResult();
try
{
if (string.IsNullOrWhiteSpace(user.DingTalkAccount))
{
return result.SetErrorInfo("请配置用户的钉钉id");
}
var app = DingTalkApp.GetDingTalkApp(TalkSet);
DingTalk_OAAuditStatus body = new DingTalk_OAAuditStatus();
var updateProcessInstanceRequestsList = new List<updateProcessInstanceRequests>();
//var billList = billnos.Split(',');
//foreach (var bill in billList)
//{
var updateProcessInstanceRequests = new updateProcessInstanceRequests();
var instanceId = BasicDataRefDAL.GetLogicValue("钉钉审批", "instanceId", billno);
if (!string.IsNullOrEmpty(instanceId))
{
updateProcessInstanceRequests.processInstanceId = instanceId;
updateProcessInstanceRequests.isSystem =true;
updateProcessInstanceRequests.operatingUserId = user.DingTalkAccount;
//updateProcessInstanceRequestsList.Add(updateProcessInstanceRequests);
}
//}
body.updateProcessInstanceRequests = updateProcessInstanceRequests;
jsonObj = updateProcessInstanceRequests;
token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
url = $"https://api.dingtalk.com/v1.0/workflow/processInstances/terminate";
HeaderDic = new Dictionary<string, string>
{
{ "x-acs-dingtalk-access-token", token }
};
result.OK();
return result;
}
catch (Exception e)
{
return result.SetErrorInfo(e.Message);
}
}
public class CallbackResult
{
public bool success { get; set; }
}
public DBResult DoSendSubmitAuditBack()
{
var result = base.DoSend_Header();
if (result.Success)
{
try
{
var objRtn = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(result.Data.ToString(),new CallbackResult());
result.Success = objRtn.success;
//BasicDataRefDAL.SaveLogicInfo(BSNO, "钉钉审批", dic);
}
catch (Exception ex)
{
}
}
return result;
}
public DBResult DoSend()
{
var result = base.DoSend_Header();
if (result.Success)
{
try
{
var jo = new DingTalk_SendAuditResult();
jo = (DingTalk_SendAuditResult)JsonToObject(result.Data.ToString(), jo);
var dic = new Dictionary<string, string>();
dic.Add("instanceId", jo.instanceId);
BasicDataRefDAL.SaveLogicInfo(BSNO, "钉钉审批", dic);
}
catch (Exception ex)
{
}
}
return result;
}
}
public class DingTalk_Instanceinfo : DingTalkSendHelper {
public string instanceId { get; set; }
public DingTalk_Instanceinfo()
{
//this.uid = uid;
}
public DBResult MakeSendMessage(string instanceId )
{
this.instanceId = instanceId;
var result = new DBResult();
jsonObj = null;
token = MemoryCache.Default[DingTalkTokenJob.DingTalkAccessTokenStoreKey].ToString();
url = $"https://api.dingtalk.com/v1.0/workflow/processInstances" ;
dicObj= new Dictionary<string, string> {
{"processInstanceId",instanceId }
};
HeaderDic = new Dictionary<string, string>
{
{ "x-acs-dingtalk-access-token", token }
};
result.OK();
return result;
}
public DBResult DoSend()
{
var result = base.DoGet_Header_Param();
if (result.Success)
{
try
{
BasicDataRefDAL.SaveLog(result.Data.ToString(), uid, "读取业务信息","返回");
//jo = (DingTalk_Instanceinfo)JsonToObject(result.Data.ToString(), jo);
}
catch (Exception ex)
{
}
}
return result;
}
}
#region 处理钉钉回调返回值
public class DingTalkCallbackDealHelper
{
public string processInstanceId { get; set; }
public string processCode { get; set; }
public string type { get; set; }
public DingTalkCallbackDealHelper() { }
public DingTalkCallbackDealHelper(string instanceId) {
processInstanceId = instanceId;
}
public DingTalkCallbackDealHelper(CallBackInfo callbackinfo)
{
processInstanceId = callbackinfo.processInstanceId;
processCode = callbackinfo.processCode;
type = callbackinfo.type;
}
/// <summary>
/// 已不使用 改为在子类内各自实现
/// </summary>
/// <returns></returns>
public DBResult ReadDingtalkInstanceinfo()
{
var result = new DBResult();
//var userid=
try
{
//如果是费用入账动作 且配置了钉钉审批入库 则调用
result = DingTalkHelper.DingTalk_Instanceinfo(processInstanceId);
DingTalkInstanceinfo di = DSWeb.MvcShipping.Helper.JsonConvert.Deserialize<DingTalkInstanceinfo>(result.Data.ToString());
//根据内容修改wms和wmsin值
var cdc = new CommonDataContext();
var lv = BasicDataRefDAL.GetLogicHaveValue("钉钉审批", "instanceId", processInstanceId);
if (lv != null && lv.ContainsKey("instanceId"))
{
var wmsno = lv["BSNO"];
var wmsold = new DSWeb.MvcShipping.Models.WMS.WMS_IN_OLD(wmsno);
var wms = wmsold.wms;
var wmslist = wmsold.wms_in;
//var wms = cdc.wms.FirstOrDefault(x => x.WMSNO == wmsno);
//var wmslist = new List<wms_in_md>();
//if (wms != null) {
// wmslist = cdc.wms_in.Where(x => x.ASSOCIATEDNO == wms.GID).ToList();
//}
var updwmsinlist = new List<wms_in_md>();
var newwmsinlist = new List<wms_in_md>();
var = new wms_in_md();
foreach (var item in di.result.formComponentValues)
{
//从其中查找货物信息 并更新至当前
if (item.name == "客户名称")
{
//var cust=cdc.info_client.Where(x=>x.SHORTNAME==item.value || x.DESCRIPTION==item.value)
}
if (item.name == "入库日期")
{
wms.WMSDATE = Convert.ToDateTime(item.value);
}
if (item.name == "入库信息")
{
var list = FormComponentValues.GetRowValues(item.value);
if (list != null)
{
foreach (var DingWmsin in list)
{
var = DingWmsin.getValue("提单号");
var = DingWmsin.getValue("箱号");
if (wmslist.Exists(x => x.BLNO == && x.CNTRNO == ))
{
var updrec = wmslist.First(x => x.BLNO == && x.CNTRNO == );
//new DingTalkFormField("提单号", item.BLNO),
//new DingTalkFormField("箱号", item.CNTRNO),
//new DingTalkFormField("品名", item.GOODSNAME),
//new DingTalkFormField("重量", item.GOODSRKSL.ToString()),
//new DingTalkFormField("件数", item.GOODSPACK.ToString()),
//new DingTalkFormField("尺码", item.CHIMA1.ToString()),
//new DingTalkFormField("库位", item.CHIMA1.ToString())
updrec.GOODSNAME = DingWmsin.getValue("品名");
if (wms.CHARGEUNIT == "吨" || wms.CHARGEUNIT == "千克")
{
updrec.GOODSRKSL = DingWmsin.getValue_decimal("重量");
updrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
//updrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
updrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
updrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
updrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
if (wms.CHARGEUNIT == "CBM")
{
updrec.GOODSRKSL = DingWmsin.getValue_decimal("尺码");
updrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
//updrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
updrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
updrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
updrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
updrec.GOODSPACK = DingWmsin.getValue_decimal("件数");
updrec.AREANAME = DingWmsin.getValue("库位");
updrec.DODATE = wms.WMSDATE;
updwmsinlist.Add(updrec);
}
else
{
var newrec = new wms_in_md();
newrec.ASSOCIATEDNO = wms.GID;
newrec.GID = Guid.NewGuid().ToString();
newrec.BLNO = DingWmsin.getValue("提单号");
newrec.CNTRNO = DingWmsin.getValue("箱号");
newrec.CLIENTNAME = wms.CUSTOMERNAME;
newrec.DODATE = wms.WMSDATE;
newrec.GOODSNAME = DingWmsin.getValue("品名");
if (wms.CHARGEUNIT == "吨" || wms.CHARGEUNIT == "千克")
{
newrec.GOODSRKSL = DingWmsin.getValue_decimal("重量");
newrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
//newrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
newrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
newrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
newrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
if (wms.CHARGEUNIT == "CBM")
{
newrec.GOODSRKSL = DingWmsin.getValue_decimal("尺码");
newrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
//newrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
newrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
newrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
newrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
newrec.GOODSPACK = DingWmsin.getValue_decimal("件数");
newrec.AREANAME = DingWmsin.getValue("库位");
newrec.CREATETIME = DateTime.Now;
newrec.CHARGEUNIT = wms.CHARGEUNIT;
newrec.CORPID = wms.CORPID;
newwmsinlist.Add(newrec);
}
}
}
}
if (item.name == "车队信息")
{
var list = FormComponentValues.GetRowValues(item.value);
if (list != null && list.Count > 0)
{
var name = list[0].getValue("车队");
var = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == name);
if ( != null && .SHORTNAME != null && .SHORTNAME != "")
{
.CHEDUIID = .GID;
.TRUCKNO = list[0].getValue("车牌号");
}
}
}
}
cdc.wms.AddOrUpdate(wms);
if (updwmsinlist != null && updwmsinlist.Count > 0)
{
foreach (var item in updwmsinlist)
{
item.CHEDUIID = .CHEDUIID;
item.TRUCKNO = .TRUCKNO;
cdc.wms_in.AddOrUpdate(item);
}
}
if (newwmsinlist != null && newwmsinlist.Count > 0)
{
foreach (var item in newwmsinlist)
{
item.CHEDUIID = .CHEDUIID;
item.TRUCKNO = .TRUCKNO;
cdc.wms_in.AddOrUpdate(item);
}
}
wms.ISLOCK2 = false;
cdc.wms.AddOrUpdate(wms);
cdc.SaveChanges();
//然后执行入库的费用入账原逻辑
DSWeb.MvcShipping.DAL.WMSNewDAL.WMSNewDAL.DoWMSLOCK("'"+wmsno+"'");
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
public class OperationRecords
{
/// <summary>
///
/// </summary>
public string date { get; set; }
/// <summary>
///
/// </summary>
public string result { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public string userId { get; set; }
}
public class FormComponentValues
{
/// <summary>
///
/// </summary>
public string componentType { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public string bizAlias { get; set; }
/// <summary>
///
/// </summary>
public string id { get; set; }
/// <summary>
/// 众盈
/// </summary>
public string value { get; set; }
public static List<row> GetRowValues(string value)
{
//用value值文本来解析成 行信息
var result = new List<row>();
if (value.Contains("\"rowValue\""))
{
try
{
var jarr = JArray.Parse(value);
foreach (var item in jarr)
{
var obj = item as JObject;
var row =JsonConvert.DeserializeObject<row>(obj.ToString());
result.Add(row);
}
}
catch (Exception ex)
{ }
}
return result;
}
}
public class Tasks
{
/// <summary>
///
/// </summary>
public string result { get; set; }
/// <summary>
///
/// </summary>
public string activityId { get; set; }
/// <summary>
///
/// </summary>
public string finishTime { get; set; }
/// <summary>
///
/// </summary>
public string pcUrl { get; set; }
/// <summary>
///
/// </summary>
public string createTime { get; set; }
/// <summary>
///
/// </summary>
public string mobileUrl { get; set; }
/// <summary>
///
/// </summary>
public string userId { get; set; }
/// <summary>
///
/// </summary>
public long? taskId { get; set; }
/// <summary>
///
/// </summary>
public string status { get; set; }
}
public class Result
{
/// <summary>
///
/// </summary>
public string finishTime { get; set; }
/// <summary>
///
/// </summary>
public List<string> attachedProcessInstanceIds { get; set; }
/// <summary>
///
/// </summary>
public string businessId { get; set; }
/// <summary>
/// 邓羽提交的入库统计
/// </summary>
public string title { get; set; }
/// <summary>
///
/// </summary>
public string originatorDeptId { get; set; }
/// <summary>
///
/// </summary>
public List<OperationRecords> operationRecords { get; set; }
/// <summary>
///
/// </summary>
public List<FormComponentValues> formComponentValues { get; set; }
/// <summary>
///
/// </summary>
public string result { get; set; }
/// <summary>
///
/// </summary>
public string bizAction { get; set; }
/// <summary>
///
/// </summary>
public string createTime { get; set; }
/// <summary>
///
/// </summary>
public string originatorUserId { get; set; }
/// <summary>
///
/// </summary>
public List<Tasks> tasks { get; set; }
/// <summary>
/// 青岛诚锐众盈货运代理有限公司
/// </summary>
public string originatorDeptName { get; set; }
/// <summary>
///
/// </summary>
public string status { get; set; }
}
public class DingTalkInstanceinfo
{
/// <summary>
///
/// </summary>
public Result result { get; set; }
/// <summary>
///
/// </summary>
public bool success { get; set; }
}
public class
{
public List<row> row { get; set; }
}
public class row
{
public List<rowValue> rowValue { get; set; }
public string rowNumber { get; set; }
public string getValue(string fieldname)
{
var result = "";
if (rowValue.Exists(x => x.label == fieldname))
{
result = rowValue.First(x => x.label == fieldname).value;
}
return result;
}
public decimal getValue_decimal(string fieldname)
{
var resultstr = "";
var result = 0M;
if (rowValue.Exists(x => x.label == fieldname))
{
resultstr = rowValue.First(x => x.label == fieldname).value;
}
//return result;
//提取带有小数点的数字,该方式会将所有带有小数的数字拼接在一起,如:"ABC#123.56@AS8.9测试"提取出来就是123.568.9
var result2 = Regex.Replace(resultstr, @"[^\d.\d]", "");
//如果是数字则转换为decimal类型
if (Regex.IsMatch(result2, @"^[+-]?\d*[.]?\d*$"))
{
result = decimal.Parse(result2);
}
return result;
}
}
public class rowValue
{
public string bizAlias { get; set; }
public string label { get; set; }
public string value { get; set; }
public string key { get; set; }
}
public class DingCallBackInfo
{
/// <summary>
///
/// </summary>
public string processInstanceId { get; set; }
/// <summary>
///
/// </summary>
public string corpId { get; set; }
/// <summary>
///
/// </summary>
public string EventType { get; set; }
/// <summary>
///
/// </summary>
public string businessId { get; set; }
/// <summary>
/// 邓羽提交的入货通知
/// </summary>
public string title { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public long? createTime { get; set; }
/// <summary>
///
/// </summary>
public string processCode { get; set; }
/// <summary>
///
/// </summary>
public string bizCategoryId { get; set; }
/// <summary>
///
/// </summary>
public string businessType { get; set; }
/// <summary>
///
/// </summary>
public string staffId { get; set; }
public string result { get; set; }
/// <summary>
///
/// </summary>
public long? taskId { get; set; }
}
#endregion
#region 钉钉业务类
public class DingTalkApp {
public string token { get; set; }
public string aes_key { get; set; }
public string appkey { get; set; }
public long agentid { get; set; }
public long deptid { get; set; }
public static DingTalkApp GetDingTalkApp(CodeDingTalkSet TalkSet)
{
var result = new DingTalkApp();
result.token = TalkSet.APITOKEN;
result.aes_key = TalkSet.APPSECRET;
result.appkey = TalkSet.APPKEY;
result.agentid =Convert.ToInt64(TalkSet.AGENTID);
return result;
}
public static DingTalkProcess GetProcess(CodeDingTalkSet TalkSet) {
var result = new DingTalkProcess();
result.processname = TalkSet.PROCNAME;
result.processCode = TalkSet.PROCID;
return result;
}
public DingTalkProcess GetDingTalkProcessByProcessCode(CodeDingTalkSet TalkSet)
{
var processdic = new Dictionary<string, string> {
{ TalkSet.PROCID,TalkSet.PROCNAME}
};
if (processdic.ContainsKey(TalkSet.PROCID))
{
return GetProcess(TalkSet);
}
else { return new DingTalkProcess(); }
}
public void Getappinfo(ref DingTalkProcess process) {
process.token = token;
process.aes_key = aes_key;
process.appkey = appkey;
process.agentid = agentid;
process.deptid = deptid;
}
}
public class DingTalkProcess: DingTalkApp
{
public string processname { get; set; }
public string processCode { get; set; }
//public string callbackstr { get; set; }
public DingTalkCallbackDealHelper callbackinfo { get; set; }
public void SaveCallBack(CallBackInfo _callbackinfo) {
callbackinfo = new DingTalkCallbackDealHelper(_callbackinfo);
}
public DingTalkProcess() { }
public DingTalkProcess(string processname) { this.processname = processname; }
/// <summary>
/// 这些数值来自于钉钉中某个组织的某个应用。一个应用可以监听多个实际业务的返回值
/// </summary>
/// <param name="processname"></param>
/// <returns></returns>
public virtual DBResult DoDeal() { return new DBResult(); }
}
public class DingTalkProcess_ : DingTalkProcess
{
public DingTalkProcess_(string processname)
{
this.processname = processname;
//token = "zbGFOwrH6zCvq3VE3izLmWRTNUC1YcX";
//aes_key = "sb6GkCKsUwNQo3RKbX1MzHKea1ZsE221n3xQ9hwJBMK";
//appkey = "dingsaofiohmsrcbxyef";
//agentid = 2298782307;
processCode = "PROC-0DC40EA2-E9D2-4917-A597-AD77EC055C49";
}
public override DBResult DoDeal() {
var result = new DBResult();
//根据processinstancid 读取审批实例信息
var Str = DingTalkHelper.DingTalk_Instanceinfo(callbackinfo.processInstanceId);
//解析返回结果
return result;
}
}
public class DingTalkProcess_ : DingTalkProcess
{
public DingTalkProcess_(string processname) {
this.processname = processname;
//token = "CWhvNvfyuNf9D8halMs5PyHV70CrFx3E";
//aes_key = "O5u6L8YnUaucnC8FyFNMeMeGE5uoYSAGFGdg3rOHftt";
//appkey = "dingkt5caipnn4fbuqsf";
//agentid = 2365401074;
processCode = "PROC-0888A19C-0562-42AC-A9C6-24E4C4398410";
}
public override DBResult DoDeal()
{
//return new DBResult();
if (callbackinfo.type == "finish")
{
return ReadDingtalkInstanceinfo(callbackinfo.processInstanceId);
}
else {
return new DBResult();
}
}
public DBResult ReadDingtalkInstanceinfo(string processInstanceId)
{
var result = new DBResult();
//var userid=
try
{
//如果是费用入账动作 且配置了钉钉审批入库 则调用
result = DingTalkHelper.DingTalk_Instanceinfo(processInstanceId);
DingTalkInstanceinfo di = DSWeb.MvcShipping.Helper.JsonConvert.Deserialize<DingTalkInstanceinfo>(result.Data.ToString());
//根据内容修改wms和wmsin值
var cdc = new CommonDataContext();
var lv = BasicDataRefDAL.GetLogicHaveValue("钉钉审批", "instanceId", processInstanceId);
if (lv != null && lv.ContainsKey("instanceId"))
{
var wmsno = lv["BSNO"];
var wmsold = new DSWeb.MvcShipping.Models.WMS.WMS_IN_OLD(wmsno);
var wms = wmsold.wms;
var wmslist = wmsold.wms_in;
//var wms = cdc.wms.FirstOrDefault(x => x.WMSNO == wmsno);
//var wmslist = new List<wms_in_md>();
//if (wms != null) {
// wmslist = cdc.wms_in.Where(x => x.ASSOCIATEDNO == wms.GID).ToList();
//}
var updwmsinlist = new List<wms_in_md>();
var newwmsinlist = new List<wms_in_md>();
var = new wms_in_md();
foreach (var item in di.result.formComponentValues)
{
//从其中查找货物信息 并更新至当前
if (item.name == "客户名称")
{
//var cust=cdc.info_client.Where(x=>x.SHORTNAME==item.value || x.DESCRIPTION==item.value)
}
if (item.name == "入库日期")
{
wms.WMSDATE = Convert.ToDateTime(item.value);
wms.STARTBILLINGDATE= Convert.ToDateTime(item.value);
wms.STARTBILLINGDATEAP = Convert.ToDateTime(item.value);
}
if (item.name == "入库信息")
{
var list = FormComponentValues.GetRowValues(item.value);
if (list != null)
{
foreach (var DingWmsin in list)
{
//var 提单号 = DingWmsin.getValue("提单号");
//var 箱号 = DingWmsin.getValue("箱号");
var wmsingid= DingWmsin.getValue("唯一标识");
if (wmslist.Exists(x => x.GID== wmsingid))
{
var updrec = wmslist.First(x => x.GID == wmsingid);
//new DingTalkFormField("提单号", item.BLNO),
//new DingTalkFormField("箱号", item.CNTRNO),
//new DingTalkFormField("品名", item.GOODSNAME),
//new DingTalkFormField("重量", item.GOODSRKSL.ToString()),
//new DingTalkFormField("件数", item.GOODSPACK.ToString()),
//new DingTalkFormField("尺码", item.CHIMA1.ToString()),
//new DingTalkFormField("库位", item.CHIMA1.ToString())
updrec.BLNO = DingWmsin.getValue("提单号");
updrec.CNTRNO = DingWmsin.getValue("箱号");
updrec.GOODSNAME = DingWmsin.getValue("品名");
if (wms.CHARGEUNIT == "吨" || wms.CHARGEUNIT == "千克")
{
updrec.GOODSRKSL = DingWmsin.getValue_decimal("重量");
updrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
updrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
updrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue_decimal("重量"));
updrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue_decimal("尺码"));
updrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue_decimal("尺码"));
}
if (wms.CHARGEUNIT == "CBM")
{
updrec.GOODSRKSL = DingWmsin.getValue_decimal("尺码");
updrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
updrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
updrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
updrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
updrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
updrec.GOODSPACK = DingWmsin.getValue_decimal("件数");
updrec.AREANAME = DingWmsin.getValue("库位");
updrec.DODATE = wms.WMSDATE;
//if(string.IsNullOrWhiteSpace(DingWmsin.getValue("车牌号")))
updrec.TRUCKNO = DingWmsin.getValue("车牌号");
var name= DingWmsin.getValue("车队");
var infoclient = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == name);
if(infoclient!=null && !string.IsNullOrWhiteSpace( infoclient.SHORTNAME))
updrec.CHEDUIID = infoclient.GID;
updrec.DODATE = wms.WMSDATE;
updwmsinlist.Add(updrec);
}
else
{
var newrec = new wms_in_md();
newrec.ASSOCIATEDNO = wms.GID;
newrec.GID = Guid.NewGuid().ToString();
newrec.BLNO = DingWmsin.getValue("提单号");
newrec.CNTRNO = DingWmsin.getValue("箱号");
newrec.CLIENTNAME = wms.CUSTOMERNAME;
newrec.DODATE = wms.WMSDATE;
newrec.GOODSNAME = DingWmsin.getValue("品名");
if (wms.CHARGEUNIT == "吨" || wms.CHARGEUNIT == "千克")
{
newrec.GOODSRKSL = DingWmsin.getValue_decimal("重量");
newrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
newrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
newrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
newrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
newrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
if (wms.CHARGEUNIT == "CBM")
{
newrec.GOODSRKSL = DingWmsin.getValue_decimal("尺码");
newrec.GOODSSTOCK = DingWmsin.getValue_decimal("重量");
newrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
newrec.SHIJIZHONGLIANG = Convert.ToDouble(DingWmsin.getValue("重量"));
newrec.CHIMA1 = Convert.ToDouble(DingWmsin.getValue("尺码"));
newrec.SHIJICHIMA = Convert.ToDouble(DingWmsin.getValue("尺码"));
}
newrec.GOODSPACK = DingWmsin.getValue_decimal("件数");
newrec.AREANAME = DingWmsin.getValue("库位");
newrec.CREATETIME = DateTime.Now;
newrec.CHARGEUNIT = wms.CHARGEUNIT;
newrec.CORPID = wms.CORPID;
newrec.TRUCKNO = DingWmsin.getValue("车牌号");
var name = DingWmsin.getValue("车队");
var infoclient = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == name);
if (infoclient != null && string.IsNullOrWhiteSpace(infoclient.SHORTNAME))
newrec.CHEDUIID = infoclient.SHORTNAME;
newwmsinlist.Add(newrec);
}
}
}
}
//if (item.name == "车队信息")
//{
// var 车队信息list = FormComponentValues.GetRowValues(item.value);
// if (车队信息list != null && 车队信息list.Count > 0)
// {
// var 车队name = 车队信息list[0].getValue("车队");
// var 车队 = cdc.info_client.FirstOrDefault(x => x.SHORTNAME == 车队name);
// if (车队 != null && 车队.SHORTNAME != null && 车队.SHORTNAME != "")
// {
// 车辆信息.CHEDUIID = 车队.GID;
// 车辆信息.TRUCKNO = 车队信息list[0].getValue("车牌号");
// }
// }
//}
}
cdc.wms.AddOrUpdate(wms);
if (updwmsinlist != null && updwmsinlist.Count > 0)
{
foreach (var item in updwmsinlist)
{
cdc.wms_in.AddOrUpdate(item);
}
//20230209 根据明细数据重新计算头表数据
var = updwmsinlist.Sum(s => s.GOODSPACK);
var = updwmsinlist.Sum(s => s.GOODSKGS);
var = updwmsinlist.Sum(s => s.GOODSRKSL);
var = updwmsinlist.Sum(s => s.CHIMA1);
wms.GOODSPACK = ;
wms.GOODSPACKSTOCK = ;
wms.GOODSPACKACTUAL = ;
wms.GOODSRKSL = ;
wms.GOODSRKSLACTUAL = ;
wms.GOODSSTOCK = ;
wms.GOODSKGS = ;
cdc.wms.AddOrUpdate(wms);
}
if (newwmsinlist != null && newwmsinlist.Count > 0)
{
foreach (var item in newwmsinlist)
{
item.CHEDUIID = .CHEDUIID;
item.TRUCKNO = .TRUCKNO;
cdc.wms_in.AddOrUpdate(item);
}
}
wms.ISLOCK2 = false;
cdc.wms.AddOrUpdate(wms);
cdc.SaveChanges();
//然后执行入库的费用入账原逻辑
DSWeb.MvcShipping.DAL.WMSNewDAL.WMSNewDAL.DoWMSLOCK("'" + wmsno + "'");
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
public class DingTalkProcess_ : DingTalkProcess
{
public DingTalkProcess_(string processname)
{
this.processname = processname;
//token = "CWhvNvfyuNf9D8halMs5PyHV70CrFx3E";
//aes_key = "O5u6L8YnUaucnC8FyFNMeMeGE5uoYSAGFGdg3rOHftt";
//appkey = "dingkt5caipnn4fbuqsf";
//agentid = 2365401074;
processCode = "PROC-7F3CA810-FB06-4E59-867F-49C42BFC25FB";
}
public override DBResult DoDeal()
{
//return new DBResult();
if (callbackinfo.type == "finish")
{
return ReadDingtalkInstanceinfo(callbackinfo.processInstanceId);
}
else
{
return new DBResult();
}
}
public DBResult ReadDingtalkInstanceinfo(string processInstanceId)
{
var result = new DBResult();
//var userid=
try
{
result = DingTalkHelper.DingTalk_Instanceinfo(processInstanceId);
DingTalkInstanceinfo di = DSWeb.MvcShipping.Helper.JsonConvert.Deserialize<DingTalkInstanceinfo>(result.Data.ToString());
//根据内容修改wms_out_detail的值
var cdc = new CommonDataContext();
var lv = BasicDataRefDAL.GetLogicHaveValue("钉钉审批", "instanceId", processInstanceId);
if (lv != null && lv.ContainsKey("instanceId"))
{
var BSNO = lv["BSNO"];
var wmsold = new DSWeb.MvcShipping.Models.WMS.WMS_OUT_OLD(BSNO);
var wms_out = wmsold.wms_out;
var wms_out_detaillist = wmsold.wms_out_detail;
List<wms_out_detail_md> updwmslist = new List<wms_out_detail_md>();
var = new wms_in_md();
foreach (var item in di.result.formComponentValues)
{
//从其中查找货物信息 并更新至当前
//if (item.name == "客户名称")
//{
// //var cust=cdc.info_client.Where(x=>x.SHORTNAME==item.value || x.DESCRIPTION==item.value)
//}
if (item.name == "出库日期")
{
wms_out.DODATE = Convert.ToDateTime(item.value);
cdc.wms_out.AddOrUpdate(wms_out);
}
if (item.name == "出库信息")
{
var list = FormComponentValues.GetRowValues(item.value);
if (list != null)
{
foreach (var DingWmsin in list)
{
//var 提单号 = DingWmsin.getValue("提单号");
//var 箱号 = DingWmsin.getValue("箱号");
//var 品名 = DingWmsin.getValue("品名");
var gid= DingWmsin.getValue("唯一标识");
if (wmsold.VW_WMS_OUT_DETAIL.Exists(x => x.GID_OUT == gid))
{
//var _outrec= wmsold.VW_WMS_OUT_DETAIL.First(x => x.GID_OUT == gid);
var updrec = wms_out_detaillist.First(x => x.GID== gid);
//new DingTalkFormField("提单号", item.BLNO),
//new DingTalkFormField("箱号", item.CNTRNO),
//new DingTalkFormField("品名", item.GOODSNAME),
//new DingTalkFormField("重量", item.GOODSRKSL.ToString()),
//new DingTalkFormField("件数", item.GOODSPACK.ToString()),
//new DingTalkFormField("尺码", item.CHIMA1.ToString()),
//new DingTalkFormField("库位", item.CHIMA1.ToString())
updrec.GOODSNAME = DingWmsin.getValue("品名");
if (wms_out.CHARGEUNIT == "吨" || wms_out.CHARGEUNIT == "千克")
{
updrec.GOODSPFSL = DingWmsin.getValue_decimal("重量");
updrec.GOODSKGS = DingWmsin.getValue_decimal("重量");
}
if (wms_out.CHARGEUNIT == "CBM")
{
updrec.GOODSPFSL = DingWmsin.getValue_decimal("尺码");
updrec.GOODSKGS =0;
}
updrec.GOODSPACK = DingWmsin.getValue("件数");
//updrec.AREANAME = DingWmsin.getValue("库位");
//updrec.DODATE = wms_out.DODATE;
updwmslist.Add(updrec);
}
else
{
}
}
}
}
if (item.name == "车辆信息")
{
var list = FormComponentValues.GetRowValues(item.value);
if (list != null && list.Count > 0)
{
.TRUCKNO = list[0].getValue("车牌号");
}
}
}
//cdc.wms.AddOrUpdate(wms);
if (updwmslist != null && updwmslist.Count > 0)
{
foreach (var item in updwmslist)
{
//item.CHEDUIID = 车辆信息.CHEDUIID;
item.TRUCKNO = .TRUCKNO;
cdc.wms_out_detail.AddOrUpdate(item);
}
}
cdc.SaveChanges();
//20230221 根据明细总数合计一下原业务的合计数
wms_out.SetSum(updwmslist);
cdc.SaveChanges();
//然后执行出库的费用入账原逻辑
var outtype = wms_out.IsDetail == "1" ? "StockOutDetail" : "StockOut";
DSWeb.MvcShipping.DAL.WMSOUT_GuiGeDAL.WMSOUT_GuiGeDAL.DoSetislock(wms_out.GID, (bool)wms_out.EIP, outtype,wms_out.CREATEUSER);
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
#endregion
}