select udid, minScore, minRank, location, corrRank, version,planNum,enterLine,enterNum,maxScore,avgScore,maxRank,avgRank,collect,collectDesc from b_busi_wish_university_submit_marjors_update replace into b_busi_wish_university_submit_marjors_update(udid,minScore,minRank,version,planNum,enterLine,enterNum,maxScore,avgScore,maxRank,avgRank,collect,collectDesc) VALUES (#{o.udid}, #{o.minScore}, #{o.minRank}, #{o.version}, #{o.planNum}, #{o.enterLine}, #{o.enterNum}, #{o.maxScore}, #{o.avgScore}, #{o.maxRank}, #{o.avgRank}, #{o.collect}, #{o.collectDesc}) insert into b_busi_wish_university_submit_marjors_update(udid, version, location, corrRank) VALUES (#{o.udid}, #{o.version}, #{o.location}, #{o.corrRank}) on duplicate key update location = values(location), corrRank = values(corrRank) UPDATE `b_busi_wish_university_submit_marjors` sm, `b_busi_wish_university_submit_marjors_update` mu SET sm.`score` = mu.`minScore`, sm.`seat` = mu.`minRank`, sm.`corrScore` = mu.`minScore`, sm.`corrSeat` = mu.`corrRank`,sm.`num` = mu.`planNum`,sm.`numReal` = mu.`enterNum` ,sm.`scoreRealTop` = mu.`maxScore`,sm.`scoreRealAverage` = mu.`avgScore`,sm.`seatRealTop` = mu.`maxRank`,sm.`seatRealAverage` = mu.`avgRank` WHERE sm.`udid` = mu.`udid` AND mu.`version` = #{version} AND sm.`location` in #{o} REPLACE INTO `b_busi_wish_university_marjors_plan_submit`(`plan_id`,`submit_id`,last_submit_id, `plan_submit_id`,`group_id`,`year`,`universityId`,`location`,`collegeCode`,`level`,`liberalScience`,`course`, `course0`,`course1`,`course2`,`marjorName`, `marjorCollegeId`,`createTime`,`status`, `uCode`) SELECT rp.`id`, t.submit_id, t3.submit_id, t2.submit_id, pg.`group_id`, rp.`year`, rp.`universityId`, rp.`location`, rp.`collegeCode`, rp.`level`, rp.`liberalScience`, rp.`course`, IF(rp.`Course` IS NOT NULL AND rp.`Course` != '', SUBSTRING_INDEX(rp.`Course`, '+', 1), NULL) `course0`, IF(rp.`Course` IS NOT NULL AND rp.`Course` != '' AND rp.`Course` NOT LIKE '%不限%' AND rp.`Course` NOT LIKE '%和%', REPLACE(SUBSTRING_INDEX(REPLACE(rp.`Course`, '思想政治', '政治'), '+', -1), '或', ','), NULL) `course1`, IF(rp.`Course` IS NOT NULL AND rp.`Course` != '' AND rp.`Course` NOT LIKE '%不限%' AND rp.`Course` LIKE '%和%', REPLACE(SUBSTRING_INDEX(REPLACE(rp.`Course`, '思想政治', '政治'), '+', -1), '和', ','), NULL) `course2`, rp.`marjorName`, c.`id`, NOW(), 1, REPLACE(SUBSTRING_INDEX(rp.`universityName`, '(', -1), ')', '') FROM `b_busi_wish_university_submit_recruit_plan` rp LEFT JOIN `b_busi_wish_university_marjors_college` c ON rp.`universityId` = c.`universityId` AND rp.`location` = c.`location` AND rp.`year` = c.`year` AND rp.`level` = c.`level` AND rp.`liberalScience` = c.`liberalScience` AND rp.`collegeCode` = c.`collegeCode` AND REPLACE(SUBSTRING_INDEX(rp.`universityName`, '(', -1), ')', '') = c.uCode JOIN `b_busi_wish_university_match_plan_group` pg ON rp.`id` = pg.`plan_id` AND pg.`group_id` > 0 LEFT JOIN `b_busi_wish_university_match_submit` t ON t.group_id = pg.`group_id` AND t.year + 1 = rp.`year` -- 去年 LEFT JOIN `b_busi_wish_university_match_submit` t2 ON t2.group_id = pg.`group_id` AND t2.year = rp.`year` -- 本年 LEFT JOIN `b_busi_wish_university_match_submit` t3 ON t3.group_id = pg.`group_id` AND t3.year + 2 = rp.`year` -- 前年 WHERE rp.`id` IN #{o} truncate table `b_busi_wish_university_tmp_stat_college`; INSERT INTO b_busi_wish_university_tmp_stat_college SELECT T.marjorCollegeId, CONCAT('{"year":', T.year, ',"stats":[', GROUP_CONCAT(CONCAT('{"year":', T.submit_year, ',"score":', IF(score IS NULL, 0, score), ',"corrScore":', IF(corrScore IS NULL, 0, corrScore), ',"seat":', IF(seat IS NULL, 0, seat), ',"corrSeat":', IF(corrSeat IS NULL, 0, corrSeat), ',"numReal":',IF(numReal IS NULL, 0, numReal), ',"matchCount":',IF(matchCount IS NULL, 0, matchCount), ',"collect":',collect, ',"collectDesc":"',collectDesc, '","sinoForeign":',sinoForeign, ',"sinoForeignDesc":"',sinoForeignDesc, '"}') ORDER BY T.submit_year DESC), ']}') cnt FROM ( SELECT ps.`marjorCollegeId`, ps.`year` `year`, ps.`year` submit_year, MIN(IF(sm.`score` = 0, NULL, sm.`score`)) score, MIN(IF(sm.`corrScore` = 0, NULL, sm.`corrScore`)) corrScore, MAX(IF(sm.`score`>0,sm.`seat`,0)) seat, MAX(IF(sm.`corrScore`>0,sm.`corrSeat`,0)) corrSeat, MAX(IF(sm.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(sm.`collect` = '有征集', sm.`collectDesc`, '')) `collectDesc`, MIN(IF(s.`score` = 0, NULL, s.`score`)) score, MIN(IF(s.`curr_score` = 0, NULL, s.`curr_score`)) corrScore, MAX(IF(s.`score`>0,s.`seat`,0)) seat, MAX(IF(s.`curr_score`>0,s.`curr_seat`,0)) corrSeat, MAX(IF(s.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(s.`collect` = '有征集', s.`collectDesc`, '')) `collectDesc`, SUM(IF(sm.`numReal` IS NULL, 0, sm.`numReal`)) numReal, IF(SUM(IF(sm.`sinoForeign`, 0, 1)) > 0, 0, 1) sinoForeign, MAX(DISTINCT IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '')) `sinoForeignDesc`, COUNT(*) matchCount FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`plan_submit_id` = sm.`id` JOIN `b_busi_wish_university_submits` s ON sm.`location` = s.`location` AND sm.year = s.year AND sm.`universityId` = s.`universityId` AND sm.`level` = s.`level` AND sm.`liberalScience` = s.`liberalScience` AND sm.`collegeCode` = s.`collegeCode` AND sm.uCode = s.uCode WHERE ps.`marjorCollegeId` IS NOT NULL AND ps.`plan_submit_id` IS NOT NULL AND ps.year = #{currYear} AND ps.`location` in #{o} and ps.`marjorCollegeId` in #{o} GROUP BY ps.`marjorCollegeId`, ps.`year` UNION SELECT ps.`marjorCollegeId`, ps.`year` `year`, ps.`year` - 1 submit_year, MIN(IF(sm.`score` = 0, NULL, sm.`score`)) score, MIN(IF(sm.`corrScore` = 0, NULL, sm.`corrScore`)) corrScore, MAX(IF(sm.`score`>0,sm.`seat`,0)) seat, MAX(IF(sm.`corrScore`>0,sm.`corrSeat`,0)) corrSeat, MAX(IF(sm.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(sm.`collect` = '有征集', sm.`collectDesc`, '')) `collectDesc`, MIN(IF(s.`score` = 0, NULL, s.`score`)) score, MIN(IF(s.`curr_score` = 0, NULL, s.`curr_score`)) corrScore, MAX(IF(s.`score`>0,s.`seat`,0)) seat, MAX(IF(s.`curr_score`>0,s.`curr_seat`,0)) corrSeat, MAX(IF(s.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(s.`collect` = '有征集', s.`collectDesc`, '')) `collectDesc`, SUM(IF(sm.`numReal` IS NULL, 0, sm.`numReal`)) numReal, IF(SUM(IF(sm.`sinoForeign`, 0, 1)) > 0, 0, 1) sinoForeign, MAX(DISTINCT IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '')) `sinoForeignDesc`, COUNT(*) matchCount FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`submit_id` = sm.`id` JOIN `b_busi_wish_university_submits` s ON sm.`location` = s.`location` AND sm.year = s.year AND sm.`universityId` = s.`universityId` AND sm.`level` = s.`level` AND sm.`liberalScience` = s.`liberalScience` AND sm.`collegeCode` = s.`collegeCode` AND sm.uCode = s.uCode WHERE ps.`marjorCollegeId` IS NOT NULL AND ps.`submit_id` IS NOT NULL AND ps.year = #{currYear} AND ps.`location` in #{o} and ps.`marjorCollegeId` in #{o} GROUP BY ps.`marjorCollegeId`, ps.`year` UNION SELECT ps.`marjorCollegeId`, ps.`year` `year`, ps.`year` - 2 submit_year, MIN(IF(sm.`score` = 0, NULL, sm.`score`)) score, MIN(IF(sm.`corrScore` = 0, NULL, sm.`corrScore`)) corrScore, MAX(IF(sm.`score`>0,sm.`seat`,0)) seat, MAX(IF(sm.`corrScore`>0,sm.`corrSeat`,0)) corrSeat, MAX(IF(sm.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(sm.`collect` = '有征集', sm.`collectDesc`, '')) `collectDesc`, MIN(IF(s.`score` = 0, NULL, s.`score`)) score, MIN(IF(s.`curr_score` = 0, NULL, s.`curr_score`)) corrScore, MAX(IF(s.`score`>0,s.`seat`,0)) seat, MAX(IF(s.`curr_score`>0,s.`curr_seat`,0)) corrSeat, MAX(IF(s.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(s.`collect` = '有征集', s.`collectDesc`, '')) `collectDesc`, SUM(IF(sm.`numReal` IS NULL, 0, sm.`numReal`)) numReal, IF(SUM(IF(sm.`sinoForeign`, 0, 1)) > 0, 0, 1) sinoForeign, MAX(DISTINCT IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '')) `sinoForeignDesc`, COUNT(*) matchCount FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`last_submit_id` = sm.`id` JOIN `b_busi_wish_university_submits` s ON sm.`location` = s.`location` AND sm.year = s.year AND sm.`universityId` = s.`universityId` AND sm.`level` = s.`level` AND sm.`liberalScience` = s.`liberalScience` AND sm.`collegeCode` = s.`collegeCode` AND sm.uCode = s.uCode WHERE ps.`marjorCollegeId` IS NOT NULL AND ps.`last_submit_id` IS NOT NULL AND ps.year = #{currYear} AND ps.`location` in #{o} and ps.`marjorCollegeId` in #{o} GROUP BY ps.`marjorCollegeId`, ps.`year` UNION SELECT ps.`marjorCollegeId`, ps.`year` `year`, ps.`year` - 3 submit_year, MIN(IF(sm.`score` = 0, NULL, sm.`score`)) score, MIN(IF(sm.`corrScore` = 0, NULL, sm.`corrScore`)) corrScore, MAX(IF(sm.`score`>0,sm.`seat`,0)) seat, MAX(IF(sm.`corrScore`>0,sm.`corrSeat`,0)) corrSeat, MAX(IF(sm.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(sm.`collect` = '有征集', sm.`collectDesc`, '')) `collectDesc`, MIN(IF(s.`score` = 0, NULL, s.`score`)) score, MIN(IF(s.`curr_score` = 0, NULL, s.`curr_score`)) corrScore, MAX(IF(s.`score`>0,s.`seat`,0)) seat, MAX(IF(s.`curr_score`>0,s.`curr_seat`,0)) corrSeat, MAX(IF(s.`collect` = '有征集', 1, 0)) `collect`, MAX(IF(s.`collect` = '有征集', s.`collectDesc`, '')) `collectDesc`, SUM(IF(sm.`numReal` IS NULL, 0, sm.`numReal`)) numReal, IF(SUM(IF(sm.`sinoForeign`, 0, 1)) > 0, 0, 1) sinoForeign, MAX(DISTINCT IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '')) `sinoForeignDesc`, COUNT(*) matchCount FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`old_submit_id` = sm.`id` JOIN `b_busi_wish_university_submits` s ON sm.`location` = s.`location` AND sm.year = s.year AND sm.`universityId` = s.`universityId` AND sm.`level` = s.`level` AND sm.`liberalScience` = s.`liberalScience` AND sm.`collegeCode` = s.`collegeCode` AND sm.uCode = s.uCode WHERE ps.`marjorCollegeId` IS NOT NULL AND ps.`old_submit_id` IS NOT NULL AND ps.year = #{currYear} AND ps.`location` in #{o} and ps.`marjorCollegeId` in #{o} GROUP BY ps.`marjorCollegeId`, ps.`year` ) T GROUP BY T.marjorCollegeId; UPDATE `b_busi_wish_university_marjors_college` c, b_busi_wish_university_tmp_stat_college t SET c.`stats` = t.`stats`, c.`score` = 0, c.`seat` = 0, c.`matchCount`=0 WHERE c.`id` = t.`marjorCollegeId` AND c.year = #{currYear} AND c.`location` in #{o}; UPDATE `b_busi_wish_university_marjors_college` c SET c.`score` = IF(c.`stats` LIKE CONCAT('%', c.`year`, ',"score"%') OR c.`stats` LIKE CONCAT('%', c.`year` - 1, ',"score"%'), json_extract(c.`stats`, '$.stats[0].corrScore'), NULL), c.`seat` = IF(c.`stats` LIKE CONCAT('%', c.`year`, ',"score"%') OR c.`stats` LIKE CONCAT('%', c.`year` - 1, ',"score"%'), json_extract(c.`stats`, '$.stats[0].corrSeat'), NULL), c.`matchCount` = IF(c.`stats` LIKE CONCAT('%', c.`year`, ',"score"%') OR c.`stats` LIKE CONCAT('%', c.`year` - 1, ',"score"%'), json_extract(c.`stats`, '$.stats[0].matchCount'), NULL) -- c.`score` = IF(c.`stats` LIKE CONCAT('%', c.`year`, ',"score"%') OR c.`stats` LIKE CONCAT('%', c.`year` - 1, ',"score"%'), json_extract(c.`stats`, '$.stats[0].score'), NULL), -- c.`seat` = IF(c.`stats` LIKE CONCAT('%', c.`year`, ',"score"%') OR c.`stats` LIKE CONCAT('%', c.`year` - 1, ',"score"%'), json_extract(c.`stats`, '$.stats[0].seat'), NULL) WHERE c.`stats` IS NOT NULL AND c.year = #{currYear} AND c.`location` in #{o} and c.`id` in #{o} truncate table `b_busi_wish_university_tmp_stat`; SET SESSION group_concat_max_len = 1024000; INSERT INTO b_busi_wish_university_tmp_stat SELECT T.`plan_id`, CONCAT('{"year":', T.`year`, ',"stats":[', GROUP_CONCAT(CONCAT('{"year":', T.submit_year, ',"submit_id":', T.`submit_id`, ',"score":', T.`score`, ',"corrScore":', T.`corrScore`, ',"seat":', T.`seat`, ',"corrSeat":', T.`corrSeat`, ',"numReal":', T.`numReal`, ',"collect":', T.`collect`, ',"collectDesc":"', T.`collectDesc`, '","sinoForeign":', T.`sinoForeign`, ',"sinoForeignDesc":"', T.`sinoForeignDesc`, '"}') ORDER BY T.submit_year DESC), ']}') FROM ( SELECT ps.`plan_id`, ps.`year`, ps.`year` submit_year, ps.`plan_submit_id` submit_id, IF(sm.`score`>0,sm.`score`,0) score, IF(sm.`corrScore`>0,sm.`corrScore`,0) corrScore, IF(sm.`score`>0,sm.`seat`,0) seat, IF(sm.`corrScore`>0,sm.`corrSeat`,0) corrSeat, IF(sm.`numReal` IS NULL, 0, sm.`numReal`) numReal, IF(sm.`collect` = '有征集', 1, 0) `collect`, IF(sm.`collect` = '有征集', sm.`collectDesc`, '') `collectDesc`, IF(sm.`sinoForeign`, 1, 0) sinoForeign, IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '') `sinoForeignDesc` FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`plan_submit_id` = sm.`id` WHERE ps.year = #{currYear} AND ps.`location` in #{o} and ps.`plan_id` in #{o} UNION SELECT ps.`plan_id`, ps.`year`, ps.`year` - 1 submit_year, ps.`submit_id` submit_id, IF(sm.`score`>0,sm.`score`,0) score, IF(sm.`corrScore`>0,sm.`corrScore`,0) corrScore, IF(sm.`score`>0,sm.`seat`,0) seat, IF(sm.`corrScore`>0,sm.`corrSeat`,0) corrSeat, IF(sm.`numReal` IS NULL, 0, sm.`numReal`), IF(sm.`collect` = '有征集', 1, 0) `collect`, IF(sm.`collect` = '有征集', sm.`collectDesc`, '') `collectDesc`, IF(sm.`sinoForeign`, 1, 0) sinoForeign, IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '') `sinoForeignDesc` FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`submit_id` = sm.`id` WHERE ps.year = #{currYear} AND ps.`location` in #{o} and ps.`plan_id` in #{o} UNION SELECT ps.`plan_id`, ps.`year`, ps.`year` - 2 submit_year, ps.`last_submit_id` submit_id, IF(sm.`score`>0,sm.`score`,0) score, IF(sm.`corrScore`>0,sm.`corrScore`,0) corrScore, IF(sm.`score`>0,sm.`seat`,0) seat, IF(sm.`corrScore`>0,sm.`corrSeat`,0) corrSeat, IF(sm.`numReal` IS NULL, 0, sm.`numReal`), IF(sm.`collect` = '有征集', 1, 0) `collect`, IF(sm.`collect` = '有征集', sm.`collectDesc`, '') `collectDesc`, IF(sm.`sinoForeign`, 1, 0) sinoForeign, IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '') `sinoForeignDesc` FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`last_submit_id` = sm.`id` WHERE ps.year = #{currYear} AND ps.`location` in #{o} and ps.`plan_id` in #{o} UNION SELECT ps.`plan_id`, ps.`year`, ps.`year` - 3 submit_year, ps.`old_submit_id` submit_id, IF(sm.`score`>0,sm.`score`,0) score, IF(sm.`corrScore`>0,sm.`corrScore`,0) corrScore, IF(sm.`score`>0,sm.`seat`,0) seat, IF(sm.`corrScore`>0,sm.`corrSeat`,0) corrSeat, IF(sm.`numReal` IS NULL, 0, sm.`numReal`), IF(sm.`collect` = '有征集', 1, 0) `collect`, IF(sm.`collect` = '有征集', sm.`collectDesc`, '') `collectDesc`, IF(sm.`sinoForeign`, 1, 0) sinoForeign, IF(sm.`sinoForeign`, sm.`sinoForeignDesc`, '') `sinoForeignDesc` FROM `b_busi_wish_university_marjors_plan_submit` ps JOIN `b_busi_wish_university_submit_marjors` sm ON ps.`old_submit_id` = sm.`id` WHERE ps.year = #{currYear} AND ps.`location` in #{o} and ps.`plan_id` in #{o} ) T GROUP BY T.`plan_id`; UPDATE `b_busi_wish_university_marjors_plan_submit` ps, b_busi_wish_university_tmp_stat t SET ps.`stats` = t.`stats` WHERE ps.`plan_id` = t.`planId` AND ps.year = #{currYear} AND ps.`location` in #{o} and ps.`plan_id` in #{o} DELETE mu FROM `b_busi_wish_university_submit_marjors_update` mu WHERE mu.`version` = #{version} and mu.location is not null and mu.location = #{location}