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.
81 lines
3.1 KiB
Transact-SQL
81 lines
3.1 KiB
Transact-SQL
|
|
/****** Object: StoredProcedure [dbo].[p_gen_sea_Origi_warntask] Script Date: 12/13/2017 17:33:59 ******/
|
|
SET ANSI_NULLS OFF
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
ALTER PROCEDURE [dbo].[p_gen_sea_Origi_warntask]
|
|
@tskCount int output
|
|
AS
|
|
begin
|
|
---清理临时表
|
|
---------必须是两个..
|
|
if object_id('tempdb..#tempWarnlist') is not null Begin
|
|
drop table #tempWarnlist
|
|
END
|
|
---创建临时表
|
|
CREATE TABLE [dbo].#tempWarnlist(
|
|
[ID] [int] IDENTITY(1,1) NOT NULL,
|
|
[MblNo] [varchar](20) NOT NULL,
|
|
[WarnDate] [datetime] NOT NULL,
|
|
[WarnType] [varchar](20) NOT NULL,
|
|
[createdate] [datetime] NOT NULL default getdate()
|
|
)
|
|
|
|
---将相关数据插入到临时表
|
|
insert into #tempWarnlist (mblno,warndate,warntype)
|
|
select tdh, 邮件发送日期 ,'预警提醒'
|
|
from
|
|
(
|
|
select
|
|
ltrim(
|
|
rtrim(SUBSTRING(
|
|
substring( 邮件主题,charindex('number',v.邮件主题,1)+6,LEN(v.邮件主题)-charindex('number',v.邮件主题,1)),1
|
|
,LEN(substring( 邮件主题,charindex('number',v.邮件主题,1)+6,LEN(v.邮件主题)-charindex('number',v.邮件主题,1)))-
|
|
LEN(' is now available'))
|
|
)
|
|
) as tdh, cast(邮件发送日期 as DATETIME) as 邮件发送日期,
|
|
邮件主题
|
|
from
|
|
(select m.邮件id,m.邮件主题,m.邮件发送日期,m.处理时间,DATEDIFF(mi,m.邮件发送日期,m.处理时间)as minYsh
|
|
from t_op_seae_edi_mail m where 邮件主题 like '%origin%'and 邮件发送日期>=cast(GETDATE()-3 as DATE)and 邮件发送日期<cast(GETDATE()+1 as DATE)
|
|
and m.处理时间 < DATEADD(MI,-30,GETDATE())
|
|
)v
|
|
)
|
|
vv
|
|
where tdh not in
|
|
(
|
|
select t.提单号 -- , t.任务类型
|
|
from t_op_task t where t.任务开始时间>=cast(GETDATE()-3 as DATE)and 任务开始时间< DATEADD(MI,-30,GETDATE())
|
|
|
|
and t.任务类型='ORIGINAL'
|
|
)
|
|
and not exists ( select Mblno from t_op_seae_task_warn_mblno w where w.MblNo= vv.tdh and w.Warndate=vv.邮件发送日期)
|
|
---将临时表的数据插入到预警任务列表
|
|
set @tskCount=( select COUNT('MblNo') from #tempWarnlist);
|
|
----------------
|
|
insert into t_op_seae_task_warn_mblno (mblno,warndate,warntype)
|
|
select [MblNo], [WarnDate] , [WarnType]
|
|
from #tempWarnlist
|
|
|
|
----形成任务(注意这里有问题)
|
|
insert into t_op_task
|
|
([任务编号] , [任务类型],[任务来源],[任务状态],[任务说明]
|
|
,[发起人] ,[录入日期] ,[任务开始时间] ,[完成方式]
|
|
,[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号])
|
|
select [任务编号] , [任务类型],[任务来源],[任务状态],[任务说明]
|
|
,[发起人] ,[录入日期] ,[任务开始时间] ,[完成方式]
|
|
,[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号] from
|
|
(
|
|
select NEWID() as 任务编号 ,wn.WarnType as [任务类型] ,'邮件分析' as 任务来源 ,'待确认' as 任务状态,'有Original Bill邮件无正本' as 任务说明 ,
|
|
'DEMO-SA' as 发起人 ,GETDATE() as 录入日期 ,wn.WarnDate as [任务开始时间],'手动' as 完成方式 ,
|
|
wn.MblNo as 提单号 ,null as 文件编号 ,null as 邮件编号 ,null as 电子档案路径 ,case when LEN(isnull(s.客服员,''))<1 then 1 else 0 end as 是否公共 ,s.客服员 as 任务相关人员 ,s.编号 as SEA编号
|
|
,s.装运方式
|
|
from #tempWarnlist wn left join t_op_seae s on wn.MblNo= s.主提单号 and s.业务类型='普通货' )
|
|
v where v.装运方式 is null or v.装运方式='整箱'
|
|
|
|
return @tskCount
|
|
end;
|
|
|
|
|