|
@@ -98,6 +98,9 @@ type SubPushQueryParam struct {
|
|
|
FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
|
|
|
EntUserId string //商机管理用户id
|
|
|
DeptId string //商机管理用户部门id
|
|
|
+ IsRead string //是否已读
|
|
|
+ Source string //信息来源
|
|
|
+ Staffs []string //分发人员
|
|
|
BaseServiceMysql *mysql.Mysql
|
|
|
NewUserId int64
|
|
|
IsEnt bool
|
|
@@ -122,7 +125,7 @@ type KeyParam struct {
|
|
|
}
|
|
|
|
|
|
func (spqp *SubPushQueryParam) IsEmpty() bool {
|
|
|
- return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
|
|
|
+ return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == ""
|
|
|
}
|
|
|
|
|
|
type subscribePush struct {
|
|
@@ -280,7 +283,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
start := (spqp.PageNum - 1) * spqp.PageSize
|
|
|
end := start + spqp.PageSize
|
|
|
//时间是今天,没有别的过滤条件--首先读取当前推送缓存数据 其次查询数据库
|
|
|
- if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" {
|
|
|
+ if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == "" {
|
|
|
subPush := &SubPush{}
|
|
|
var err error
|
|
|
if spqp.IsEnt == false {
|
|
@@ -363,7 +366,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
userStr := " "
|
|
|
leftJoinStr := " "
|
|
|
var (
|
|
|
- countSql, searchSql, findSql string
|
|
|
+ countSql, findSql string
|
|
|
)
|
|
|
codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
|
|
|
if codeMap.Data == nil || err != nil {
|
|
@@ -374,47 +377,11 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
|
|
|
countSql = fmt.Sprintf("select count(1) as count from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
|
logx.Info("countSql", countSql)
|
|
|
- searchSql = fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
|
//查询总数
|
|
|
count = spqp.BaseServiceMysql.CountBySql(countSql)
|
|
|
- findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
} else {
|
|
|
- if spqp.IsEnt {
|
|
|
- isNew := 1
|
|
|
- //商机管理判断
|
|
|
- newCount := IC.MainMysql.CountBySql("select count(id) from entniche_info where id =? and isNew != 1 and status=1", spqp.EntId)
|
|
|
- if newCount > 0 {
|
|
|
- //新商机管理
|
|
|
- isNew = 0
|
|
|
- }
|
|
|
- if isNew == 1 {
|
|
|
- //企业主体是企业的企业查询
|
|
|
- userStr = fmt.Sprintf(" a.entid='%s' and (a.source > 1) ", spqp.EntId)
|
|
|
- } else {
|
|
|
- userStr = fmt.Sprintf(" a.entid='%s' ", spqp.EntId)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if spqp.BuySubject == 1 {
|
|
|
- //企业主体是企业的个人查询
|
|
|
- if spqp.UserType == SubVipFlag {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product=1 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else if spqp.UserType == MemberFlag {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product=2 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product is null or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- }
|
|
|
- } else {
|
|
|
- if s.ModuleFlag == EntnicheFlag {
|
|
|
- //老商机管理个人订阅查询
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else {
|
|
|
- //个人订阅查询
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ //公共查询条件
|
|
|
//时间
|
|
|
if starttime > 0 && endtime > 0 {
|
|
|
userStr += fmt.Sprintf(" and a.date>=%d and a.date<=%d", starttime, endtime)
|
|
@@ -423,6 +390,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if starttime == 0 && endtime > 0 {
|
|
|
userStr += fmt.Sprintf(" and a.date<=%d", endtime)
|
|
|
}
|
|
|
+
|
|
|
if spqp.Area != "" || spqp.City != "" {
|
|
|
var sqlAreaCity = ""
|
|
|
//城市
|
|
@@ -545,25 +513,126 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
|
|
|
}
|
|
|
}
|
|
|
- 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 "))
|
|
|
+
|
|
|
+ if spqp.IsEnt {
|
|
|
+ var staffs []string
|
|
|
+ userStr += fmt.Sprintf(" and a.entid='%s' ", spqp.EntId)
|
|
|
+
|
|
|
+ //判断是企业管理员还是部门管理员 部门管理员获取所有子部门
|
|
|
+ userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
|
|
|
+ if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
|
|
|
+ result = []*bxsubscribe.SubscribeInfo{}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if userEnt.Role_admin_department { //部门管理员 获取所有部门和子部门员工
|
|
|
+ users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
|
|
|
+ if users != nil && len(*users) > 0 {
|
|
|
+ for _, v := range *users {
|
|
|
+ if len(spqp.Staffs) > 0 {
|
|
|
+ for _, vv := range spqp.Staffs {
|
|
|
+ if fmt.Sprintf("%d", v.Id) == vv {
|
|
|
+ staffs = append(staffs, common.InterfaceToStr(v.Id))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ staffs = append(staffs, common.InterfaceToStr(v.Id))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Printf("部门管理员为获取到部门员工:%s", spqp.EntUserId)
|
|
|
+ result = []*bxsubscribe.SubscribeInfo{}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if len(spqp.Staffs) > 0 {
|
|
|
+ staffs = spqp.Staffs
|
|
|
+ }
|
|
|
+
|
|
|
+ // 无查询分配人员、是否已读
|
|
|
+ if spqp.IsRead == "" && len(staffs) == 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 and a.source = 2", 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 and a.source = 2 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"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //if len(querys) > 1 {
|
|
|
+ countSql = fmt.Sprintf("select count(1) 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))) ", 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."))
|
|
|
+ }
|
|
|
} else {
|
|
|
- countSql = fmt.Sprintf("select count(1) as count from %s a where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
+ // 是否已读
|
|
|
+ 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 {
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=1 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ } else if spqp.UserType == MemberFlag {
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=2 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ } else {
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product is null or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if s.ModuleFlag == EntnicheFlag {
|
|
|
+ //老商机管理个人订阅查询
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ } else {
|
|
|
+ //个人订阅查询
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询数量
|
|
|
+ //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 {
|
|
|
+ findSql += ", IF(a.source is NULL,1,a.source) as source "
|
|
|
+ }
|
|
|
+ if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
|
|
|
+ findSql += ",a.isvip"
|
|
|
+ }
|
|
|
+ findSql = fmt.Sprintf("%s from %s a STRAIGHT_JOIN %s b ON 1=1 %s and a.infoid = b.infoid %s where %s"+
|
|
|
+ " order by a.date desc,a.id desc", findSql, aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
|
|
|
}
|
|
|
- logx.Info("countSql", countSql)
|
|
|
- searchSql = fmt.Sprintf(" from %s a STRAIGHT_JOIN %s b ON %s and a.infoid = b.infoid %s where %s"+
|
|
|
- " order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
|
|
|
//查询总数
|
|
|
+ logx.Info("countSql", countSql)
|
|
|
count = spqp.BaseServiceMysql.CountBySql(countSql)
|
|
|
- findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
- if s.ModuleFlag == EntnicheFlag {
|
|
|
- findSql += ", IF(a.source is NULL,1,a.source) as source "
|
|
|
- }
|
|
|
- }
|
|
|
- if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
|
|
|
- findSql += ",a.isvip"
|
|
|
}
|
|
|
- findSql += searchSql
|
|
|
if isLimit {
|
|
|
findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
|
|
|
}
|
|
@@ -1567,7 +1636,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-//关键词处理
|
|
|
+// 关键词处理
|
|
|
func KeyHandle(a_items map[string]interface{}) []interface{} {
|
|
|
keyArr := []interface{}{}
|
|
|
if a_items["a_key"] != nil {
|