ALTER PROCEDURE Proc_GetPreBuyResumeBase
@ResumeSourceSite varchar(100) = '51Job', --目标网站
@ContactState varchar(50) = '', --购买导入状态
@ResumeCodeType varchar(5), --查询简历ID类型:简历现ID[0]/简历源ID[1]
@ResumeCode varchar(20) = '', --简历ID
@CityID varchar(100), --分站
@OrderSet varchar(50), --排序设置
@BuyNum varchar(5) , --购买数量
@Size int, --页面显示最大数量
@Index varchar(10), --页面当前索引
@Count int output --带回当前条件查询数
AS
BEGIN
DECLARE @sql nvarchar(4000)
CREATE TABLE #ResumeBase (
ResumeID uniqueidentifier PRIMARY KEY
,JobSeekerID uniqueidentifier
,ResumeCode varchar(64)
,ResumeSourceSite varchar(20)
,ResumeSourceID varchar(64)
,UpdateDate datetime
,CreateDate datetime)
CREATE TABLE #BuyResume(ResumeID uniqueidentifier PRIMARY KEY, Quantity int, ValidQuantity int)
--
INSERT INTO #BuyResume(ResumeID, Quantity, ValidQuantity)
SELECT ResumeID, COUNT(ResumeID) Quantity, SUM(CASE WHEN DATEDIFF(day, BuyDate, GETDATE()) <= 7 THEN 1 ELSE 0 END) ValidQuantity
FROM BuyNoContactResume
GROUP BY ResumeID
IF (@ResumeCode = '')
INSERT INTO #ResumeBase(
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate)
SELECT
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate
FROM dbo.ResumeBase
WHERE ResumeSourceSite = @ResumeSourceSite
AND ResumeID IN (SELECT ResumeID FROM #BuyResume)
ELSE--简历编号不为空
BEGIN
IF (@ResumeCodeType = '0')--简历现ID
INSERT INTO #ResumeBase(
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate)
SELECT
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate
FROM dbo.ResumeBase
WHERE ResumeCode = @ResumeCode
AND ResumeID IN (SELECT ResumeID FROM #BuyResume)
ELSE --简历源ID
INSERT INTO #ResumeBase(
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate)
SELECT
ResumeID
,JobSeekerID
,ResumeCode
,ResumeSourceSite
,ResumeSourceID
,UpdateDate
,CreateDate
FROM dbo.ResumeBase
WHERE ResumeSourceSite = @ResumeSourceSite
AND ResumeSourceID = @ResumeCode
AND ResumeID IN (SELECT ResumeID FROM #BuyResume)
END
CREATE INDEX IX_ResumeBaseTemp_JobSeekerID ON #ResumeBase(JobSeekerID ASC);
CREATE TABLE #TempRecord (IndexID int
,ResumeID uniqueidentifier
,ResumeCode varchar(64)
,ResumeSourceSite varchar(20)
,ResumeSourceID varchar(64)
,Quantity int
,ValidQuantity int
,UpdateDate datetime
,CreateDate datetime
,CityID varchar(20)
,ContactState tinyint)
IF (@ContactState = '')
SET @ContactState = '0,1,2'
SET @sql = '
SELECT IndexID = ROW_NUMBER() OVER(ORDER BY ' + @orderSet + '), t.*
FROM (
SELECT
rb.ResumeID
,rb.ResumeCode
,rb.ResumeSourceSite
,rb.ResumeSourceID
,b.Quantity
,b.ValidQuantity
,rb.UpdateDate
,rb.CreateDate
,i.CityID
,i.ContactState
FROM
#ResumeBase rb
JOIN JobSeekerInfo i ON i.JobSeekerID = rb.JobSeekerID
JOIN #BuyResume b ON b.ResumeID = rb.ResumeID
WHERE
i.CityID IN (SELECT Rowvalue FROM dbo.f_split(''' + @CityID + ''', '',''))
and b.Quantity >= ' + @BuyNum + '
AND i.ContactState IN(SELECT Rowvalue FROM dbo.f_split(''' + @ContactState + ''', '',''))
) t'
--PRINT (@sql)
INSERT INTO #TempRecord
EXEC (@sql)
--返回统计数
SELECT @count = max(IndexID) from #TempRecord
--返回数据
SELECT * FROM #TempRecord tmp
WHERE IndexID > (@index*@Size) and IndexID<=((@index + 1) * @Size)
DROP TABLE #TempRecord
END