|
@@ -373,18 +373,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if starttime == 0 && endtime > 0 {
|
|
|
userStr += fmt.Sprintf(" and a.date<=%d", endtime)
|
|
|
}
|
|
|
- // 是否已读
|
|
|
- if spqp.IsRead != "" {
|
|
|
- if spqp.IsRead == "0" {
|
|
|
- userStr += " and a.isvisit IS NULL"
|
|
|
- } else if spqp.IsRead == "1" {
|
|
|
- userStr += " and a.isvisit=1"
|
|
|
- }
|
|
|
- }
|
|
|
- // 信息来源
|
|
|
- if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
|
|
|
- userStr += " and a.source=" + spqp.Source
|
|
|
- }
|
|
|
|
|
|
if spqp.Area != "" || spqp.City != "" {
|
|
|
var sqlAreaCity = ""
|
|
@@ -510,8 +498,8 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
}
|
|
|
|
|
|
if spqp.IsEnt {
|
|
|
-
|
|
|
isNew := 1
|
|
|
+ var staffs []string
|
|
|
//商机管理判断
|
|
|
newCount := IC.MainMysql.CountBySql("select count(id) from entniche_info where id =? and isNew != 1 and status=1", spqp.EntId)
|
|
|
if newCount > 0 {
|
|
@@ -522,7 +510,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
//企业主体是企业的企业查询
|
|
|
userStr += fmt.Sprintf(" and a.entid='%s' and (a.source > 1) ", spqp.EntId)
|
|
|
} else {
|
|
|
- userStr += fmt.Sprintf(" and a.entid='%s' ", spqp.EntId)
|
|
|
+ userStr += fmt.Sprintf(" and a.entid='%s' and a.source = 2 ", spqp.EntId)
|
|
|
}
|
|
|
//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
|
|
|
userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
|
|
@@ -530,35 +518,65 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
result = []*bxsubscribe.SubscribeInfo{}
|
|
|
return
|
|
|
}
|
|
|
- if userEnt.Role_admin_department && len(spqp.Staffs) == 0 { //部门管理员 获取所有部门和子部门员工
|
|
|
+ if len(spqp.Staffs) == 0 && userEnt.Role_admin_department { //部门管理员 获取所有部门和子部门员工
|
|
|
users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
|
|
|
- var userIds []string
|
|
|
if users != nil && len(*users) > 0 {
|
|
|
for _, v := range *users {
|
|
|
- userIds = append(userIds, common.InterfaceToStr(v.Id))
|
|
|
+ staffs = append(staffs, common.InterfaceToStr(v.Id))
|
|
|
}
|
|
|
- userStr += fmt.Sprintf(" and a.userid in (%s) ", strings.Join(userIds, ","))
|
|
|
} else {
|
|
|
log.Printf("部门管理员为获取到部门员工:%s", spqp.EntUserId)
|
|
|
result = []*bxsubscribe.SubscribeInfo{}
|
|
|
return
|
|
|
}
|
|
|
- } else if len(spqp.Staffs) != 0 {
|
|
|
- userStr += fmt.Sprintf(" and a.userid in (%s) ", strings.Join(spqp.Staffs, ","))
|
|
|
}
|
|
|
|
|
|
- //查询数量(需要去重)
|
|
|
- if len(querys) > 1 {
|
|
|
- //countSql = fmt.Sprintf("select count(1) as count from %s a STRAIGHT_JOIN %s b ON %s and a.infoid = b.infoid %s where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
|
|
|
- countSql = fmt.Sprintf("SELECT count(1) AS count FROM (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE source=2 %s ) a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, Baseinfo, leftJoinStr, strings.Join(querys, " and "))
|
|
|
+ // 无查询分配人员、是否已读
|
|
|
+ if (spqp.IsRead == "" && len(spqp.Staffs) == 0) || isNew == 0 {
|
|
|
+ //查询数量(需要去重)
|
|
|
+ //if len(querys) > 1 {
|
|
|
+ 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)
|
|
|
+ //} else {
|
|
|
+ // countSql = fmt.Sprintf("select count(1) from %s a WHERE 1=1 %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
+ //}
|
|
|
+ //列表查询
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count 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 {
|
|
|
- //countSql = fmt.Sprintf("select count(1) as count from %s a where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
- countSql = fmt.Sprintf("SELECT count(1) AS count FROM ( SELECT DISTINCT matchkeys,infoid FROM %s a WHERE source=2 %s ) AS data", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
+ //查询分配人员或是否已读
|
|
|
+ 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 len(querys) > 1 {
|
|
|
+ countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where source=2 %s and %s and ((%s) or EXISTS (SELECT 1 from %s c STRAIGHT_JOIN %s b ON c.infoid = b.infoid %s WHERE c.source=3 %s and %s and a.id=c.pid and (%s))) ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr, strings.Join(querys, " and "), staffQuery, aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.ReplaceAll(userStr, "a.", "c."), strings.Join(querys, " and "), strings.ReplaceAll(staffQuery, "a.", "c."))
|
|
|
+ //} else {
|
|
|
+ // countSql = fmt.Sprintf("select count(1) from %s a WHERE a.source=2 %s and ((%s) or EXISTS (SELECT 1 from %s c WHERE c.source=3 %s and a.id=pid and (%s))) ", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, staffQuery, aboutDbMsg[s.ModuleFlag].MysqlTable, strings.ReplaceAll(userStr, "a.", "c."), strings.ReplaceAll(staffQuery, "a.", "c."))
|
|
|
+ //}
|
|
|
+ //列表查询
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where a.source=2 %s and %s and ((%s) or EXISTS (SELECT 1 from %s c STRAIGHT_JOIN %s b ON c.infoid = b.infoid %s WHERE c.source=3 %s and %s and a.id=c.pid and (%s))) order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr, strings.Join(querys, " and "), staffQuery, aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.ReplaceAll(userStr, "a.", "c."), strings.Join(querys, " and "), strings.ReplaceAll(staffQuery, "a.", "c."))
|
|
|
}
|
|
|
- //列表查询
|
|
|
- findSql = fmt.Sprintf("select a.infoid,a.matchkeys,b.isvalidfile as attachment_count from (SELECT DISTINCT matchkeys,infoid FROM %s a WHERE source=2 %s ) a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s"+
|
|
|
- " order by b.publishtime desc", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, Baseinfo, leftJoinStr, strings.Join(querys, " and "))
|
|
|
} else {
|
|
|
+ // 是否已读
|
|
|
+ if spqp.IsRead != "" {
|
|
|
+ if spqp.IsRead == "0" {
|
|
|
+ userStr += " and a.isvisit IS NULL"
|
|
|
+ } else if spqp.IsRead == "1" {
|
|
|
+ userStr += " and a.isvisit=1"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 信息来源
|
|
|
+ if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
|
|
|
+ userStr += " and a.source=" + spqp.Source
|
|
|
+ }
|
|
|
+
|
|
|
if spqp.BuySubject == 1 {
|
|
|
//企业主体是企业的个人查询
|
|
|
if spqp.UserType == SubVipFlag {
|
|
@@ -579,11 +597,11 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
}
|
|
|
|
|
|
//查询数量
|
|
|
- if len(querys) > 1 {
|
|
|
- countSql = fmt.Sprintf("select count(1) as count from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where 1=1 %s and %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr, strings.Join(querys, " and "))
|
|
|
- } else {
|
|
|
- countSql = fmt.Sprintf("select count(1) as count from %s a where 1=1 %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
- }
|
|
|
+ //if len(querys) > 1 {
|
|
|
+ countSql = fmt.Sprintf("select count(1) as count from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where 1=1 %s and %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr, strings.Join(querys, " and "))
|
|
|
+ //} else {
|
|
|
+ // countSql = fmt.Sprintf("select count(1) as count from %s a where 1=1 %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
+ //}
|
|
|
//列表查询语句
|
|
|
findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
if s.ModuleFlag == EntnicheFlag {
|