Commit 72630f59 by chongli

资源同步更新最小价格和最小赞助价格时改为只更新价格变动过的球场的最小价格,提升性能

parent a7ddc5f3
......@@ -153,7 +153,7 @@ public class AsmCourseResourceDao extends GenericHibernateDao<AsmCourseresource,
this.updateSponsorInfo();
logger.error("xingnengjiance4-7:"+DateUtil.getDateTimeStr(new Date()));
// 必须在SponsorInfo更新完之后执行
this.updatePriceField();
this.updatePriceField(date, now);
logger.error("xingnengjiance4-8:"+DateUtil.getDateTimeStr(new Date()));
}
......@@ -1657,31 +1657,40 @@ public class AsmCourseResourceDao extends GenericHibernateDao<AsmCourseresource,
return null;
}
private void updatePriceField() {
private void updatePriceField(Date date, Date now) {
// String sql1 = "delete from asm_courseresource WHERE PriceDate < CURDATE()";
// String sql2 = "update asm_courseresource t SET t.MinPrice = false, t.MinPrice2 = false WHERE t.PriceDate >= CURDATE()";
//modify by caosy for delay 2 day to delete resource
String sql1 = "delete from asm_courseresource WHERE PriceDate < DATE_SUB(CURDATE(),INTERVAL 3 day)";
String sql2 = "update asm_courseresource t SET t.MinPrice = false, t.MinPrice2 = false WHERE t.PriceDate >= DATE_SUB(CURDATE(),INTERVAL 3 day)";
String sql2 = "update asm_courseresource t SET t.MinPrice = false, t.MinPrice2 = false WHERE t.courseid in (SELECT courseid FROM (SELECT DISTINCT courseid from asm_courseresource where Update_LastTime=:Update_LastTime) temp) and t.PriceDate >= DATE_SUB(CURDATE(),INTERVAL 3 day)";
logger.error("xingnengjiance4-7-1:"+DateUtil.getDateTimeStr(new Date()));
this.getSession().createSQLQuery(sql1).executeUpdate();
this.getSession().createSQLQuery(sql2).executeUpdate();
String ids = this.getIds();
logger.error("xingnengjiance4-7-2:"+DateUtil.getDateTimeStr(new Date()));
Query query = this.getSession().createSQLQuery(sql2);
query.setParameter("Update_LastTime", now);
query.executeUpdate();
logger.error("xingnengjiance4-7-3:"+DateUtil.getDateTimeStr(new Date()));
String ids = this.getIds(now);
logger.error("xingnengjiance4-7-4:"+DateUtil.getDateTimeStr(new Date()));
if (!"".equals(ids)) {
String sql3 = "update asm_courseresource set MinPrice = true where id in (" + ids + ")";
this.getSession().createSQLQuery(sql3).executeUpdate();
}
logger.error("xingnengjiance4-7-5:"+DateUtil.getDateTimeStr(new Date()));
// v2 支持赞助
String ids2 = this.getSponsorMinIds();
String ids2 = this.getSponsorMinIds(now);
if (!ids.equals("")) {
String sql4 = "update asm_courseresource set MinPrice2 = true where id in (" + ids2 + ")";
this.getSession().createSQLQuery(sql4).executeUpdate();
}
logger.error("xingnengjiance4-7-6:"+DateUtil.getDateTimeStr(new Date()));
}
private String getIds() {
private String getIds(Date now) {
// String sql =
// "select id from (SELECT SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY salePrice,teeTime ASC),',',1) AS id FROM asm_courseresource t where t.PriceDate >= CURDATE() "
// + " and t.courseStatus!="
......@@ -1712,8 +1721,11 @@ public class AsmCourseResourceDao extends GenericHibernateDao<AsmCourseresource,
+ " and productType in("
+ ProductTypeEnum.NORMAL.getValue()+","+ProductTypeEnum.OFFLINE.getValue()+","+ProductTypeEnum.CALLLINE.getValue()+")"
+ " and "
+ ResourcePriceStatusEnum.getSql(null) + " and publishDate<=PriceDate and PriceDate<=offlineDate" + " GROUP BY t.CourseID,t.PriceDate) as tmp";
List<String> ids = this.getSession().createSQLQuery(sql).list();
+ ResourcePriceStatusEnum.getSql(null) + " and publishDate<=PriceDate and PriceDate<=offlineDate AND t.courseid in (SELECT DISTINCT courseid from asm_courseresource where Update_LastTime=:Update_LastTime)" + " GROUP BY t.CourseID,t.PriceDate) as tmp";
Query query = this.getSession().createSQLQuery(sql);
query.setParameter("Update_LastTime", now);
List<String> ids = query.list();
String idStrs = "";
if (ids != null) {
int index = 0;
......@@ -1733,7 +1745,7 @@ public class AsmCourseResourceDao extends GenericHibernateDao<AsmCourseresource,
*
* @return
*/
private String getSponsorMinIds() {
private String getSponsorMinIds(Date now) {
String sql = "SELECT CASE WHEN LOCATE(CONCAT('=540p=', minPrice2),datas) THEN SUBSTRING_INDEX(SUBSTRING(datas from 1 for LOCATE(CONCAT('=540p=', minPrice2),datas)-1),',',-1) ELSE minId END as id"
+ " FROM (SELECT SUBSTRING_INDEX(GROUP_CONCAT(sponsorPrice ORDER BY sponsorPrice,teeTime ASC),',',1) minPrice2,GROUP_CONCAT(id,'=',teeTime,'p=',sponsorPrice) datas,SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY sponsorPrice,teeTime ASC),',',1) minId"
......@@ -1751,9 +1763,12 @@ public class AsmCourseResourceDao extends GenericHibernateDao<AsmCourseresource,
+ " and productType in("
+ ProductTypeEnum.NORMAL.getValue()+","+ProductTypeEnum.OFFLINE.getValue()+","+ProductTypeEnum.CALLLINE.getValue()+")"
+ " and "
+ ResourcePriceStatusEnum.getSql(null) + " and publishDate<=PriceDate and PriceDate<=offlineDate" + " GROUP BY t.CourseID,t.PriceDate) as tmp";
+ ResourcePriceStatusEnum.getSql(null) + " and publishDate<=PriceDate and PriceDate<=offlineDate and t.courseid in (SELECT DISTINCT courseid from asm_courseresource where Update_LastTime=:Update_LastTime)" + " GROUP BY t.CourseID,t.PriceDate) as tmp";
List<String> ids = this.getSession().createSQLQuery(sql).list();
Query query = this.getSession().createSQLQuery(sql);
query.setParameter("Update_LastTime", now);
List<String> ids = query.list();
String idStrs = "";
if (ids != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment