delete from zz_ryjbxx where RYBM = #{userCode} delete from zz_djxx where RYBM = #{userCode} delete from gg_zgjbxx where RYBM = #{userCode} delete from rs_ryjbxxfb where RYBM = #{userCode} delete from cf_userroles where USERID = #{userCode} delete from cf_users where USERID = #{userCode} delete from us_party_month where yearMonth = #{yearMonth}; insert ignore into us_party_month (yearMonth, userCode, partyCode ) select #{yearMonth},um.userCode,um.partyCode_by_yearMonth from ( select us.RYBM as userCode, case when pc.oldPartyCode is not null then pc.oldPartyCode else us.SZDZBDM end as partyCode_by_yearMonth from zz_ryjbxx us inner join zz_djxx zd on us.RYBM = zd.RYBM left join (select chg.RYBM, min(chg.newDzzdm) as newPartyCode, min(chg.SZDZB) as oldPartyCode from zz_zzgxxx chg inner join (select RYBM, min(cast(chg.ZLZBRQ as signed)) as maxChangeDate from zz_zzgxxx chg where chg.newDzzdm is not null and chg.userPartyChangeStatus = 2 and cast(substr(chg.ZLZBRQ, 1, 6) as signed) > #{yearMonth} group by RYBM) m on chg.RYBM = m.RYBM and chg.ZLZBRQ = m.maxChangeDate group by chg.RYBM) pc on us.RYBM = pc.RYBM inner join rs_ryjbxxfb fb on us.RYBM = fb.RYBM where us.RYZT in ('2', '3') and cast(substr(zd.JRZGZZRQ, 1, 6) as signed) #{yearMonth} and (fb.ISARCHIVE is null or fb.ISARCHIVE = 0 or (fb.ISARCHIVE = 1 and cast(substr(DATE_FORMAT(fb.archiveDate, '%Y%m%d'), 1, 6) as signed) = ]]> #{yearMonth})) ) um left join us_party_month upm on um.userCode=upm.userCode and upm.yearMonth=#{yearMonth} where upm.userCode is null update us_party_month upm inner join ( select us.RYBM as userCode, case when cast(substr(zd.JRZGZZRQ, 1, 6) as signed) ]]> #{yearMonth} then '' when pc.oldPartyCode is not null then pc.oldPartyCode else us.SZDZBDM end as partyCode_by_yearMonth from zz_ryjbxx us inner join zz_djxx zd on us.RYBM = zd.RYBM left join (select chg.RYBM, min(chg.newDzzdm) as newPartyCode, min(chg.SZDZB) as oldPartyCode from zz_zzgxxx chg inner join (select RYBM, min(cast(chg.ZLZBRQ as signed)) as maxChangeDate from zz_zzgxxx chg where chg.newDzzdm is not null and chg.userPartyChangeStatus = 2 and cast(substr(chg.ZLZBRQ, 1, 6) as signed) > #{yearMonth} group by RYBM) m on chg.RYBM = m.RYBM and chg.ZLZBRQ = m.maxChangeDate group by chg.RYBM) pc on us.RYBM = pc.RYBM inner join rs_ryjbxxfb fb on us.RYBM = fb.RYBM where us.RYZT in ('2', '3') and zd.JRZGZZRQ is not null ) um on upm.userCode = um.userCode and upm.yearMonth=#{yearMonth} set upm.partyCode=um.partyCode_by_yearMonth where 1=1;