@ -30,6 +30,7 @@ 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 ;
namespace DSWeb.Areas.MvcShipping.Helper
{
@ -139,7 +140,7 @@ namespace DSWeb.Areas.MvcShipping.Helper
{
var result = new DBResult ( ) ;
DingTalk_ SendAuditWork dh = new DingTalk_SendAuditWork ( uid ) ;
DingTalk_ WmsInAudit dh = new DingTalk_WmsInAudit ( uid ) ;
if ( dh . cansend ( wmsno ) )
{
@ -166,6 +167,36 @@ namespace DSWeb.Areas.MvcShipping.Helper
return result ;
}
public static DBResult Send_WMSOUT ( string uid , string BSNO )
{
var result = new DBResult ( ) ;
DingTalk_WmsOutAudit dh = new DingTalk_WmsOutAudit ( uid ) ;
if ( dh . cansend ( BSNO ) )
{
result = dh . MakeSendMessage ( BSNO ) ;
if ( ! result . Success )
{
return result ;
}
result = dh . DoSend ( ) ;
if ( result . Success )
{
}
}
else
{
result . SetErrorInfo ( "该业务已发送" ) ;
}
return result ;
}
}
@ -238,7 +269,9 @@ namespace DSWeb.Areas.MvcShipping.Helper
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 ) ;
@ -313,9 +346,11 @@ namespace DSWeb.Areas.MvcShipping.Helper
public class DingTalk_SendAuditWork : DingTalkSendHelper
{
public string BSNO { get ; set ; }
public DingTalk_SendAuditWork ( )
{
}
public DingTalk_SendAuditWork ( string uid )
{
this . uid = uid ;
getUser ( ) ;
}
@ -366,7 +401,63 @@ namespace DSWeb.Areas.MvcShipping.Helper
return true ;
}
public DBResult MakeSendMessage ( string wmsno )
public virtual DBResult MakeSendMessage ( string wmsno )
{
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 > ( ) ;
dic . Add ( "instanceId" , jo . instanceId ) ;
BasicDataRefDAL . SaveLogicInfo ( BSNO , "钉钉审批" , dic ) ;
} catch ( Exception ex )
{
}
}
return result ;
}
}
public class DingTalk_WmsInAudit : DingTalk_SendAuditWork
{
public DingTalk_WmsInAudit ( string uid )
{
this . uid = uid ;
getUser ( ) ;
}
//public bool cansend(string GID)
//{
// //看是否已发过
// var logiclog = BasicDataRefDAL.GetLogicInfo(GID, "钉钉审批");
// if (logiclog.Count > 0)
// {
// return false;
// }
// return true;
//}
public override DBResult MakeSendMessage ( string wmsno )
{
var result = new DBResult ( ) ;
@ -394,8 +485,8 @@ namespace DSWeb.Areas.MvcShipping.Helper
//获取用户的钉钉id
var dtc = new DingTalkContext ( ) ;
body . approvers . Add ( new DingTalkForm_approvers ( "OR" , new List < string > { user . DingTalkAccount } ) ) ;
//20230116 改为不指定审核人 完全依照审核流程自身的安排
//body.approvers.Add(new DingTalkForm_approvers("OR", new List<string> { "5620105362687730" })) ;
body . microappAgentId = dp . agentid ; / /
@ -427,18 +518,28 @@ namespace DSWeb.Areas.MvcShipping.Helper
入 库 信 息 list . Add ( newrk ) ;
if ( 车 队 list ! = null & & 车 队 list . Exists ( x = > x . GID = = item . CHEDUIID ) )
{
//if (车队list != null && 车队list.Exists(x => x.GID == item.CHEDUIID) )
// {
var 车 队 = 车 队 list . First ( x = > x . GID = = item . CHEDUIID ) ;
var newcl = new List < DingTalkFormField > {
new DingTalkFormField ( "车队" , 车 队 . SHORTNAME ) ,
new DingTalkFormField ( "车牌号" , item . TRUCKNO )
} ;
车 队 信 息 list . Add ( newcl ) ;
}
// var 车队 = 车队list.First(x => x.GID == item.CHEDUIID);
// var newcl = new List<DingTalkFormField>{
// new DingTalkFormField("车队", 车队.SHORTNAME),
// new DingTalkFormField("车牌号", item.TRUCKNO)
// };
// 车队信息list.Add(newcl);
// }
}
//var newcl = new List<DingTalkFormField>{
// new DingTalkFormField("车队", "青岛众盈"),
// new DingTalkFormField("车牌号", "车牌号")
// };
//车队信息list.Add(newcl);
var 入 库 信 息 = new DingTalkFormField ( "入库信息" , JsonConvert . SerializeObject ( 入 库 信 息 list ) ) ;
var 车 队 信 息 = new DingTalkFormField ( "车队信息" , JsonConvert . SerializeObject ( 车 队 信 息 list ) ) ;
@ -464,19 +565,209 @@ namespace DSWeb.Areas.MvcShipping.Helper
result . OK ( ) ;
return result ;
}
catch ( Exception e ) {
return result . SetErrorInfo ( e . Message ) ;
catch ( Exception e )
{
return result . SetErrorInfo ( e . Message ) ;
}
}
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 > ( ) ;
dic . Add ( "instanceId" , jo . instanceId ) ;
BasicDataRefDAL . SaveLogicInfo ( BSNO , "钉钉审批" , dic ) ;
}
catch ( Exception ex )
{
public DBResult DoSend ( ) {
}
}
return result ;
}
}
public class DingTalk_WmsOutAudit : DingTalk_SendAuditWork
{
public DingTalk_WmsOutAudit ( string uid )
{
this . uid = uid ;
getUser ( ) ;
}
public override DBResult MakeSendMessage ( string bsno )
{
var result = new DBResult ( ) ;
bsno = bsno . Replace ( "'" , "" ) ;
try
{
if ( string . IsNullOrWhiteSpace ( user . DingTalkAccount ) )
{
return result . SetErrorInfo ( "请配置用户的钉钉id" ) ;
}
BSNO = bsno ;
DingTalk_OAAuditBody body = new DingTalk_OAAuditBody ( ) ;
var 诚 锐 app = DingTalkApp . GetDingTalkApp ( "诚锐东胜对接" ) ;
var dp = 诚 锐 app . GetProcess ( "诚锐出货通知" ) ;
body . deptId = dp . deptid ; / /
//获取用户的钉钉id
var dtc = new DingTalkContext ( ) ;
//body.approvers.Add(new DingTalkForm_approvers("OR", new List<string> { user.DingTalkAccount }));
body . microappAgentId = dp . agentid ; / /
body . originatorUserId = user . DingTalkAccount ;
body . processCode = dp . processCode ;
var cdc = new CommonDataContext ( ) ;
var wmsout = cdc . wms_out . First ( p = > p . BSNO = = BSNO ) ;
var wmsoutdetailList = cdc . wms_out_detail . Where ( x = > x . OUTBSNO = = BSNO ) . ToList ( ) ;
var 出 库 信 息 list = new List < List < DingTalkFormField > > ( ) ;
var 车 辆 信 息 list = new List < List < DingTalkFormField > > ( ) ;
var 待 添 加 车 辆 信 息 = new List < wms_out_detail_md > ( ) ;
var ingidlist = wmsoutdetailList . Select ( s = > s . ASSOCIATEDNO ) . ToList ( ) ;
var 对 应 入 库 wmsList = cdc . wms . Where ( x = > ingidlist . Contains ( x . GID ) ) . ToList ( ) ;
var 对 应 入 库 wmsinList = cdc . wms_in . Where ( x = > ingidlist . Contains ( x . ASSOCIATEDNO ) ) . ToList ( ) ;
foreach ( var item in wmsoutdetailList )
{
var 对 应 入 库 wms = 对 应 入 库 wmsList . First ( x = > x . GID = = item . ASSOCIATEDNO ) ;
var 对 应 入 库 wmsin = new wms_in_md ( ) ;
if ( item . ASSOCIATEDNO = = item . INBSNO )
{
//整体出库 明细取第一条即可
对 应 入 库 wmsin = 对 应 入 库 wmsinList . First ( x = > x . ASSOCIATEDNO = = item . ASSOCIATEDNO ) ;
}
else {
//明细出库 取具体条目
对 应 入 库 wmsin = 对 应 入 库 wmsinList . First ( x = > x . GID = = item . INBSNO ) ;
}
//重量和尺码 都来自出库量字段GOODSPFSL 填充重量还是尺码 决定于chargeunit
var 重 量 = 0 M ;
var 尺 码 = 0 M ;
if ( 对 应 入 库 wms . CHARGEUNIT = = "吨" | | 对 应 入 库 wms . CHARGEUNIT = = "千克" ) {
重 量 = item . GOODSPFSL = = null ? 0 M : ( decimal ) item . GOODSPFSL ;
}
if ( 对 应 入 库 wms . CHARGEUNIT = = "CBM" )
{
尺 码 = item . GOODSPFSL = = null ? 0 M : ( decimal ) item . GOODSPFSL ;
}
var newrk = new List < DingTalkFormField >
{
new DingTalkFormField ( "提单号" , 对 应 入 库 wms . BLNO ) ,
//new DingTalkFormField("箱号", 对应入库wmsin.CNTRNO),
new DingTalkFormField ( "品名" , item . GOODSNAME ) ,
new DingTalkFormField ( "重量" , 重 量 . ToString ( ) ) ,
new DingTalkFormField ( "件数" , item . GOODSPACKPFSL . ToString ( ) ) ,
new DingTalkFormField ( "尺码" , 尺 码 . ToString ( ) ) ,
new DingTalkFormField ( "库位" , string . IsNullOrWhiteSpace ( 对 应 入 库 wmsin . AREANAME . ToString ( ) ) ? "无" : 对 应 入 库 wmsin . AREANAME . ToString ( ) )
} ;
出 库 信 息 list . Add ( newrk ) ;
if ( 待 添 加 车 辆 信 息 . Exists ( x = > x . TRUCKNO = = item . TRUCKNO ) ) {
if ( 待 添 加 车 辆 信 息 . Exists ( x = > x . TRUCKNO = = item . TRUCKNO & & ( x . DRIVERIDCARD ! = null & & x . DRIVERIDCARD ! = "" ) ) )
{
}
else {
待 添 加 车 辆 信 息 . First ( x = > x . TRUCKNO = = item . TRUCKNO ) . DRIVERIDCARD = item . DRIVERIDCARD ;
}
}
else {
待 添 加 车 辆 信 息 . Add ( item ) ;
}
}
if ( 待 添 加 车 辆 信 息 ! = null & & 待 添 加 车 辆 信 息 . Count > 0 )
{
foreach ( var item in 待 添 加 车 辆 信 息 ) {
var newcl = new List < DingTalkFormField > {
new DingTalkFormField ( "车牌号" , item . TRUCKNO ) ,
new DingTalkFormField ( "司机姓名" , item . DRIVERIDCARD )
} ;
车 辆 信 息 list . Add ( newcl ) ;
}
}
var 出 库 信 息 = new DingTalkFormField ( "出库信息" , JsonConvert . SerializeObject ( 出 库 信 息 list ) ) ;
var 车 辆 信 息 = new DingTalkFormField ( "车辆信息" , JsonConvert . SerializeObject ( 车 辆 信 息 list ) ) ;
body . formComponentValues = new List < DingTalkFormField >
{
//new DingTalkFormField("提单号", "123123")
//增加字段内容
new DingTalkFormField ( "客户名称" , wmsout . CUSTOMERNAME ) ,
new DingTalkFormField ( "出库日期" , ( ( DateTime ) wmsout . DODATE ) . ToString ( "yyyy-MM-dd" ) ) ,
出 库 信 息 ,
车 辆 信 息
} ;
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 DBResult DoSend ( )
{
var result = base . DoSend_Header ( ) ;
if ( result . Success ) {
if ( result . Success )
{
try
{
var jo = new DingTalk_SendAuditResult ( ) ;
@ -487,7 +778,8 @@ namespace DSWeb.Areas.MvcShipping.Helper
dic . Add ( "instanceId" , jo . instanceId ) ;
BasicDataRefDAL . SaveLogicInfo ( BSNO , "钉钉审批" , dic ) ;
} catch ( Exception ex )
}
catch ( Exception ex )
{
}
@ -1011,6 +1303,14 @@ namespace DSWeb.Areas.MvcShipping.Helper
{
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 ;
}
}
@ -1024,20 +1324,21 @@ namespace DSWeb.Areas.MvcShipping.Helper
deptid = 809181118 ;
}
public static DingTalkProcess GetDingTalk Process( string processname )
public override DingTalkProcess Get Process( string processname )
{
var result = new DingTalkProcess ( ) ;
if ( processname = = "测试入货通知" )
{
result = new DingTalkProcess_ 测 试 入 货 通 知 ( processname ) ;
Getappinfo ( ref result ) ;
return result ;
}
return result ;
}
public static DingTalkProcess GetDingTalkProcessByProcessCode ( string processCode )
public override DingTalkProcess GetDingTalkProcessByProcessCode ( string processCode )
{
var processdic = new Dictionary < string , string > {
{ "PROC-0DC40EA2-E9D2-4917-A597-AD77EC055C49" , "测试入货通知" }
@ -1045,7 +1346,7 @@ namespace DSWeb.Areas.MvcShipping.Helper
if ( processdic . ContainsKey ( processCode ) )
{
return Get DingTalk Process( processdic [ processCode ] ) ;
return Get Process( processdic [ processCode ] ) ;
}
else { return new DingTalkProcess ( ) ; }
}
@ -1062,27 +1363,35 @@ namespace DSWeb.Areas.MvcShipping.Helper
deptid = 432400353 ;
}
public static DingTalkProcess GetDingTalk Process( string processname )
public override DingTalkProcess Get Process( string processname )
{
var result = new DingTalkProcess ( ) ;
if ( processname = = "诚锐入货通知" )
{
result = new DingTalkProcess_ 诚 锐 入 库 ( processname ) ;
Getappinfo ( ref result ) ;
return result ;
}
if ( processname = = "诚锐出货通知" )
{
result = new DingTalkProcess_ 诚 锐 出 库 ( processname ) ;
Getappinfo ( ref result ) ;
return result ;
}
return result ;
}
new public static DingTalkProcess GetDingTalkProcessByProcessCode ( string processCode )
new public DingTalkProcess GetDingTalkProcessByProcessCode ( string processCode )
{
var processdic = new Dictionary < string , string > {
{ "PROC-0888A19C-0562-42AC-A9C6-24E4C4398410" , "诚锐入货通知" }
{ "PROC-0888A19C-0562-42AC-A9C6-24E4C4398410" , "诚锐入货通知" } ,
{ "PROC-7F3CA810-FB06-4E59-867F-49C42BFC25FB" , "诚锐出货通知" }
} ;
if ( processdic . ContainsKey ( processCode ) )
{
return Get DingTalk Process( processdic [ processCode ] ) ;
return Get Process( processdic [ processCode ] ) ;
}
else { return new DingTalkProcess ( ) ; }
}
@ -1163,6 +1472,27 @@ namespace DSWeb.Areas.MvcShipping.Helper
return callbackinfo . ReadDingtalkInstanceinfo ( ) ;
}
}
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();
// //return callbackinfo.ReadDingtalkInstanceinfo();
//}
}
# endregion
}