|
@@ -579,29 +579,37 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if len(spqp.Staffs) > 0 {
|
|
|
staffs = spqp.Staffs
|
|
|
}
|
|
|
- // 无查询分配人员、是否已读
|
|
|
- if spqp.IsRead == "" && len(staffs) == 0 {
|
|
|
- //查询数量(需要去重)
|
|
|
- countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ // 空查询优化,不走关联表计算数量
|
|
|
+ if len(querys) == 1 {
|
|
|
+ countSql = fmt.Sprintf("select count(1) from %s a %s where 1=1 %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, leftJoinStr, userStr)
|
|
|
//列表查询
|
|
|
- findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count, IF(a.source is NULL,1,a.source) as source from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s order by a.date desc,a.id desc",
|
|
|
- aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count, IF(a.source is NULL,1,a.source) as source from %s a LEFT JOIN %s b ON a.infoid = b.infoid %s where 1=1 %s order by a.date desc,a.id desc",
|
|
|
+ aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr)
|
|
|
} else {
|
|
|
- //查询分配人员或是否已读
|
|
|
- staffQuery := " 1=1 "
|
|
|
- if len(staffs) > 0 {
|
|
|
- staffQuery += fmt.Sprintf(" and a.userid in ('%s') ", strings.Join(staffs, "','"))
|
|
|
- }
|
|
|
- if spqp.IsRead != "" {
|
|
|
- if spqp.IsRead == "0" {
|
|
|
- staffQuery += " and a.isvisit IS NULL"
|
|
|
- } else if spqp.IsRead == "1" {
|
|
|
- staffQuery += " and a.isvisit=1"
|
|
|
+ // 无查询分配人员、是否已读
|
|
|
+ if spqp.IsRead == "" && len(staffs) == 0 {
|
|
|
+ //查询数量(需要去重)
|
|
|
+ countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ //列表查询
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count, IF(a.source is NULL,1,a.source) as source from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s order by a.date desc,a.id desc",
|
|
|
+ aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ } else {
|
|
|
+ //查询分配人员或是否已读
|
|
|
+ staffQuery := " 1=1 "
|
|
|
+ if len(staffs) > 0 {
|
|
|
+ staffQuery += fmt.Sprintf(" and a.userid in ('%s') ", strings.Join(staffs, "','"))
|
|
|
}
|
|
|
+ if spqp.IsRead != "" {
|
|
|
+ if spqp.IsRead == "0" {
|
|
|
+ staffQuery += " and a.isvisit IS NULL"
|
|
|
+ } else if spqp.IsRead == "1" {
|
|
|
+ staffQuery += " and a.isvisit=1"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s and %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
|
|
|
+ //列表查询
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count,IF(a.source is NULL,1,a.source) as source from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s and %s order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
|
|
|
}
|
|
|
- countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s and %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
|
|
|
- //列表查询
|
|
|
- findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count,IF(a.source is NULL,1,a.source) as source from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s and %s order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
|
|
|
}
|
|
|
} else {
|
|
|
if spqp.PositionType == 1 {
|