|
@@ -1,14 +1,15 @@
|
|
package entity
|
|
package entity
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "config"
|
|
"db"
|
|
"db"
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
- "log"
|
|
|
|
"mongodb"
|
|
"mongodb"
|
|
qutil "qfw/util"
|
|
qutil "qfw/util"
|
|
"qfw/util/elastic"
|
|
"qfw/util/elastic"
|
|
"qfw/util/jy"
|
|
"qfw/util/jy"
|
|
|
|
+ "qfw/util/redis"
|
|
"sort"
|
|
"sort"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -16,6 +17,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
type EntFollow struct {
|
|
type EntFollow struct {
|
|
|
|
+ HasPower bool
|
|
UserId string //用户id
|
|
UserId string //用户id
|
|
MaxNum int //最大关注数量
|
|
MaxNum int //最大关注数量
|
|
SaveTable string //关注企业数量
|
|
SaveTable string //关注企业数量
|
|
@@ -32,13 +34,11 @@ func CreateEntFollowManager(userid string, pageFlag ...string) (*EntFollow, erro
|
|
if len(pageFlag) > 0 {
|
|
if len(pageFlag) > 0 {
|
|
defaultPageFlag = pageFlag[0]
|
|
defaultPageFlag = pageFlag[0]
|
|
}
|
|
}
|
|
- isBuy := bigMsg.CheckBigVipBackPower(defaultPageFlag)
|
|
|
|
- if !isBuy {
|
|
|
|
- return nil, errors.New("非法请求")
|
|
|
|
|
|
+ if isBuy := bigMsg.CheckBigVipBackPower(defaultPageFlag); isBuy {
|
|
|
|
+ uid := qutil.If(bigMsg.Pid == "", userid, bigMsg.Pid).(string) //若为子账号则存储为主账号userid
|
|
|
|
+ return &EntFollow{true, uid, bigMsg.EntNum, "follow_entinfo_bigvip"}, nil
|
|
}
|
|
}
|
|
-
|
|
|
|
- uid := qutil.If(bigMsg.Pid == "", userid, bigMsg.Pid).(string) //若为子账号则存储为主账号userid
|
|
|
|
- return &EntFollow{uid, bigMsg.EntNum, "follow_entinfo_bigvip"}, nil
|
|
|
|
|
|
+ return &EntFollow{false, userid, config.Config.FollowProject.Normal, "jylab_followent"}, nil
|
|
}
|
|
}
|
|
|
|
|
|
//关注企业联想
|
|
//关注企业联想
|
|
@@ -58,7 +58,7 @@ func (this *EntFollow) GetAssociationEnt(entName string) ([]map[string]interface
|
|
})
|
|
})
|
|
}
|
|
}
|
|
//查询是否关注
|
|
//查询是否关注
|
|
- followed, _ := db.Mgo.Find(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}, nil, `{"s_entname":1,"s_entId"}`, false, -1, -1)
|
|
|
|
|
|
+ followed, _ := db.Mgo.Find(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}, nil, `{"s_entname":1,"s_entId":1}`, false, -1, -1)
|
|
if followed != nil && len(*followed) > 0 { //有关注的项目
|
|
if followed != nil && len(*followed) > 0 { //有关注的项目
|
|
for _, follow := range *followed {
|
|
for _, follow := range *followed {
|
|
s_entId := qutil.ObjToString(follow["s_entId"])
|
|
s_entId := qutil.ObjToString(follow["s_entId"])
|
|
@@ -79,74 +79,173 @@ func (this *EntFollow) GetAssociationEnt(entName string) ([]map[string]interface
|
|
return accMap, nil
|
|
return accMap, nil
|
|
}
|
|
}
|
|
|
|
|
|
-//详情页查询是否关注企业
|
|
|
|
|
|
+//EntFollowedShow 详情页查询是否关注企业
|
|
|
|
+//followed 是否已关注
|
|
|
|
+//showFollow 是否展示关注(检索库存在相关企业信息时展示)
|
|
func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool, err error) {
|
|
func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool, err error) {
|
|
if entId == "" {
|
|
if entId == "" {
|
|
err = errors.New("未查询到企业")
|
|
err = errors.New("未查询到企业")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- query := map[string]interface{}{"s_entId": entId, "s_userid": this.UserId}
|
|
|
|
- fRes, _ := db.Mgo.FindOneByField(this.SaveTable, query, `{"i_apppushunread":1}`)
|
|
|
|
- followed = false
|
|
|
|
- if fRes != nil && len(*fRes) > 0 {
|
|
|
|
- followed = true
|
|
|
|
- //已关注,并且有未读标示
|
|
|
|
- if qutil.IntAll((*fRes)["i_apppushunread"]) > 0 {
|
|
|
|
- go db.Mgo.Update(this.SaveTable, query, map[string]interface{}{
|
|
|
|
- "$set": map[string]interface{}{
|
|
|
|
- "i_apppushunread": 0,
|
|
|
|
- },
|
|
|
|
- }, false, false)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if followed {
|
|
|
|
- //查询是否可以关注
|
|
|
|
- showFollow = true
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- //展示是否关注(部分企业不在企业库中 不展示关注按钮)
|
|
|
|
- r := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"term": {"_id": "%s"}},"_source": ["name"],"size": %d}`, entId, 1))
|
|
|
|
- if r != nil && len(*r) > 0 {
|
|
|
|
|
|
+ if this.HasPower { //大会员付费用户
|
|
|
|
+ query := map[string]interface{}{"s_entId": entId, "s_userid": this.UserId}
|
|
|
|
+ fRes, _ := db.Mgo.FindOneByField(this.SaveTable, query, `{"i_apppushunread":1}`)
|
|
|
|
+ followed = false
|
|
|
|
+ if fRes != nil && len(*fRes) > 0 {
|
|
|
|
+ followed = true
|
|
|
|
+ //已关注,并且有未读标示
|
|
|
|
+ if qutil.IntAll((*fRes)["i_apppushunread"]) > 0 {
|
|
|
|
+ go db.Mgo.Update(this.SaveTable, query, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{
|
|
|
|
+ "i_apppushunread": 0,
|
|
|
|
+ },
|
|
|
|
+ }, false, false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if followed {
|
|
|
|
+ //查询是否可以关注
|
|
|
|
+ showFollow = true
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //展示是否关注(部分企业不在企业库中 不展示关注按钮)
|
|
|
|
+ r := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"term": {"_id": "%s"}},"_source": ["name"],"size": %d}`, entId, 1))
|
|
|
|
+ if r != nil && len(*r) > 0 {
|
|
|
|
+ showFollow = true
|
|
|
|
+ }
|
|
|
|
+ } else { //免费用户
|
|
|
|
+ //获取关注企业名字
|
|
|
|
+ entName := getEntNameById(entId)
|
|
|
|
+ if entName == "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
showFollow = true
|
|
showFollow = true
|
|
|
|
+ query := map[string]interface{}{"s_entname": entName, "s_userid": this.UserId}
|
|
|
|
+ fRes, _ := db.Mgo.FindOneByField(this.SaveTable, query, `{"i_apppushunread":1}`)
|
|
|
|
+ if fRes != nil && len(*fRes) > 0 {
|
|
|
|
+ followed = true
|
|
|
|
+ //已关注,并且有未读标示
|
|
|
|
+ if qutil.IntAll((*fRes)["i_apppushunread"]) > 0 {
|
|
|
|
+ go db.Mgo.Update(this.SaveTable, query, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{
|
|
|
|
+ "i_apppushunread": 0,
|
|
|
|
+ },
|
|
|
|
+ }, false, false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//我关注的企业列表
|
|
|
|
-func (this *EntFollow) GetEntFollowList(pNum, pSize int) (followData []map[string]interface{}, hasNext bool, count int, err error) {
|
|
|
|
- count = db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId})
|
|
|
|
|
|
+//GetEntFollowList 我关注的企业列表
|
|
|
|
+// param A默认分组 B竞争对手 C合作伙伴 逗号分隔
|
|
|
|
+// db 0||nil 默认分组、1 竞争对手、2 合作伙伴、3 竞争对手和合作伙伴
|
|
|
|
+func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (followData []map[string]interface{}, hasNext bool, count, total int, err error) {
|
|
|
|
+ var groupSearchArr []map[string]interface{}
|
|
|
|
+ if group != "" {
|
|
|
|
+ groupSearchArr = func() (searchArr []map[string]interface{}) {
|
|
|
|
+ if strings.Index(group, "A") > -1 {
|
|
|
|
+ searchArr = append(searchArr, []map[string]interface{}{map[string]interface{}{"i_group": map[string]interface{}{"$exists": 0}}, map[string]interface{}{"i_group": 0}}...)
|
|
|
|
+ }
|
|
|
|
+ if strings.Index(group, "B") > -1 && strings.Index(group, "C") > -1 {
|
|
|
|
+ searchArr = append(searchArr, []map[string]interface{}{map[string]interface{}{"i_group": 1},
|
|
|
|
+ map[string]interface{}{"i_group": 2}, map[string]interface{}{"i_group": 3}}...)
|
|
|
|
+ } else {
|
|
|
|
+ if strings.Index(group, "B") > -1 {
|
|
|
|
+ searchArr = append(searchArr, []map[string]interface{}{map[string]interface{}{"i_group": 1}, map[string]interface{}{"i_group": 3}}...)
|
|
|
|
+ } else if strings.Index(group, "C") > -1 {
|
|
|
|
+ searchArr = append(searchArr, []map[string]interface{}{map[string]interface{}{"i_group": 2}, map[string]interface{}{"i_group": 3}}...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }()
|
|
|
|
+ }
|
|
|
|
+ query := map[string]interface{}{"s_userid": this.UserId}
|
|
|
|
+ //已关注数量查询
|
|
|
|
+ count = db.Mgo.Count(this.SaveTable, query)
|
|
if count == 0 {
|
|
if count == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if pNum*pSize > count {
|
|
|
|
- err = errors.New("非法查询")
|
|
|
|
- return
|
|
|
|
|
|
+ if match = strings.TrimSpace(match); match != "" {
|
|
|
|
+ query["s_entname"] = map[string]interface{}{"$regex": match}
|
|
}
|
|
}
|
|
- hasNext = (pNum+1)*pSize < count
|
|
|
|
- res, _ := db.Mgo.Find(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}, `{"l_lastpushtime":-1}`, `{"s_entname":1,"s_area":1,"s_city":1,"s_phone":1,"f_capital":1,"s_employeeno":1,"l_establishdate":1,"i_apppushunread":1,"s_entId":1}`, false, pNum*pSize, pSize)
|
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
|
- err = errors.New("查询异常")
|
|
|
|
- return
|
|
|
|
|
|
+ //当前筛选条件数量
|
|
|
|
+ if len(groupSearchArr) > 0 {
|
|
|
|
+ query["$or"] = groupSearchArr
|
|
|
|
+ total = db.Mgo.Count(this.SaveTable, query)
|
|
|
|
+ if total == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ total = count
|
|
}
|
|
}
|
|
- //followData = *res
|
|
|
|
- //加密entId
|
|
|
|
- for _, item := range *res {
|
|
|
|
- entId := qutil.ObjToString(item["s_entId"])
|
|
|
|
- if entId == "" { //dev3.6.2 前关注企业未存入企业id
|
|
|
|
- //查询企业entid
|
|
|
|
- entId = this.updateFollowed(item)
|
|
|
|
|
|
+
|
|
|
|
+ hasNext = (pNum+1)*pSize < total
|
|
|
|
+
|
|
|
|
+ if this.HasPower { //购买企业情报的用户直接查询
|
|
|
|
+ res, _ := db.Mgo.Find(this.SaveTable, query, `{"l_lastpushtime":-1}`, `{"_id":1,"s_entname":1,"s_area":1,"s_city":1,"s_phone":1,"f_capital":1,"s_employeeno":1,"l_establishdate":1,"i_apppushunread":1,"s_entId":1,"l_lastpushtime":1,"i_group":1}`, false, pNum*pSize, pSize)
|
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
|
+ err = errors.New("查询异常")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //followData = *res
|
|
|
|
+ //加密entId
|
|
|
|
+ for _, item := range *res {
|
|
|
|
+ entId := qutil.ObjToString(item["s_entId"])
|
|
|
|
+ if entId == "" { //dev3.6.2 前关注企业未存入企业id
|
|
|
|
+ //查询企业entid
|
|
|
|
+ entId = this.updateFollowed(item)
|
|
|
|
+ }
|
|
|
|
+ followData = append(followData, map[string]interface{}{
|
|
|
|
+ "fid": util.EncodeId(mongodb.BsonIdToSId(item["_id"])),
|
|
|
|
+ "s_entId": util.EncodeId(entId),
|
|
|
|
+ "f_capital": item["f_capital"],
|
|
|
|
+ "l_establishdate": item["l_establishdate"],
|
|
|
|
+ "s_area": item["s_area"],
|
|
|
|
+ "s_city": item["s_city"],
|
|
|
|
+ "s_employeeno": item["s_employeeno"],
|
|
|
|
+ "s_entname": item["s_entname"],
|
|
|
|
+ "s_phone": item["s_phone"],
|
|
|
|
+ "i_apppushunread": item["i_apppushunread"],
|
|
|
|
+ "l_lastpushtime": item["l_lastpushtime"],
|
|
|
|
+ "s_group": parseGroupStr(qutil.IntAll(item["i_group"])),
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ } else { //免费用户根据企业名称 二次查询企业id、成立时间等数据
|
|
|
|
+ res, _ := db.Mgo.Find(this.SaveTable, query, `{"l_lastpushtime":-1}`, `{"_id":1,"s_entname":1,"i_apppushunread":1,"l_lastpushtime":1,"i_group":1}`, false, pNum*pSize, pSize)
|
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
|
+ err = errors.New("查询异常")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //根据企业名字查询企业信息
|
|
|
|
+ var names []string
|
|
|
|
+ for _, data := range *res {
|
|
|
|
+ names = append(names, qutil.ObjToString(data["s_entname"]))
|
|
|
|
+ }
|
|
|
|
+ fullData := getEntMsgByNames(names)
|
|
|
|
+
|
|
|
|
+ for _, item := range *res {
|
|
|
|
+ entName, _ := item["s_entname"].(string)
|
|
|
|
+ rowMap := map[string]interface{}{
|
|
|
|
+ "fid": util.EncodeId(mongodb.BsonIdToSId(item["_id"])),
|
|
|
|
+ "s_entname": entName,
|
|
|
|
+ "i_apppushunread": item["i_apppushunread"],
|
|
|
|
+ "l_lastpushtime": item["l_lastpushtime"],
|
|
|
|
+ "s_group": parseGroupStr(qutil.IntAll(item["i_group"])),
|
|
|
|
+ }
|
|
|
|
+ if supplement, ok := fullData[entName]; ok {
|
|
|
|
+ //企业id
|
|
|
|
+ if entId, _ := supplement["_id"].(string); entId != "" {
|
|
|
|
+ rowMap["s_entId"] = util.EncodeId(entId)
|
|
|
|
+ }
|
|
|
|
+ rowMap["l_establishdate"] = supplement["establish_date"] //成立时间
|
|
|
|
+ rowMap["f_capital"] = supplement["capital"] //注册资本
|
|
|
|
+ rowMap["s_area"] = supplement["company_area"] //企业省份
|
|
|
|
+ rowMap["s_city"] = supplement["company_city"] //城市
|
|
|
|
+ rowMap["s_phone"] = supplement["company_phone"] //企业电话
|
|
|
|
+ }
|
|
|
|
+ followData = append(followData, rowMap)
|
|
}
|
|
}
|
|
- followData = append(followData, map[string]interface{}{
|
|
|
|
- "s_entId": util.EncodeId(entId), //此处id需要加密
|
|
|
|
- "f_capital": item["f_capital"],
|
|
|
|
- "l_establishdate": item["l_establishdate"],
|
|
|
|
- "s_area": item["s_area"],
|
|
|
|
- "s_city": item["s_city"],
|
|
|
|
- "s_employeeno": item["s_employeeno"],
|
|
|
|
- "s_entname": item["s_entname"],
|
|
|
|
- "s_phone": item["s_phone"],
|
|
|
|
- "i_apppushunread": item["i_apppushunread"],
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -154,7 +253,6 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int) (followData []map[strin
|
|
func (this *EntFollow) GetEntFollowAndChangeList(num int) (followData []map[string]interface{}, err error) {
|
|
func (this *EntFollow) GetEntFollowAndChangeList(num int) (followData []map[string]interface{}, err error) {
|
|
res, _ := db.Mgo.Find(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}, `{"l_lastpushtime":-1}`, `{"s_entname":1,"i_apppushunread":1,"s_entId":1,"l_lastpushtime":1}`, false, 0, num)
|
|
res, _ := db.Mgo.Find(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}, `{"l_lastpushtime":-1}`, `{"s_entname":1,"i_apppushunread":1,"s_entId":1,"l_lastpushtime":1}`, false, 0, num)
|
|
if res == nil || len(*res) == 0 {
|
|
if res == nil || len(*res) == 0 {
|
|
- err = errors.New("查询异常")
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
//加密entId,查询变更条数
|
|
//加密entId,查询变更条数
|
|
@@ -201,7 +299,6 @@ func (this *EntFollow) updateFollowed(follow map[string]interface{}) string {
|
|
if entName == "" {
|
|
if entName == "" {
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
- log.Println(fmt.Sprintf(`{"query":{"bool":{"should":[{"term":{"company_name":"%s"}},{"term":{"hname":"%s"}}],"minimum_should_match":1}},"_source":["name","_id","capital","company_phone"],"size":1}`, entName, entName))
|
|
|
|
rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"should":[{"term":{"company_name":"%s"}},{"term":{"hname":"%s"}}],"minimum_should_match":1}},"_source":["name","_id","capital","company_phone"],"size":1}`, entName, entName))
|
|
rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"should":[{"term":{"company_name":"%s"}},{"term":{"hname":"%s"}}],"minimum_should_match":1}},"_source":["name","_id","capital","company_phone"],"size":1}`, entName, entName))
|
|
if rData == nil || len(*rData) == 0 {
|
|
if rData == nil || len(*rData) == 0 {
|
|
return ""
|
|
return ""
|
|
@@ -234,58 +331,186 @@ func (this *EntFollow) updateFollowed(follow map[string]interface{}) string {
|
|
return entId
|
|
return entId
|
|
}
|
|
}
|
|
|
|
|
|
-//添加关注企业
|
|
|
|
-func (this *EntFollow) AddFollowEnt(entId string, getOldData ...bool) error {
|
|
|
|
- if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId, "s_entId": entId}) > 0 {
|
|
|
|
- return errors.New("已关注此企业")
|
|
|
|
- }
|
|
|
|
- if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}) >= this.MaxNum {
|
|
|
|
- return errors.New(fmt.Sprintf("您关注的企业已达%d个,无法关注更多", this.MaxNum))
|
|
|
|
- }
|
|
|
|
- res, _ := db.Mgo_Ent.FindOneByField("qyxy_std", map[string]interface{}{"_id": entId}, `{"company_name":1,"company_area":1,"company_city":1,"establish_date":1,"capital":1,"employee_no":1,"company_phone":1}`)
|
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
|
- return errors.New("查找企业异常")
|
|
|
|
- }
|
|
|
|
- followData := map[string]interface{}{
|
|
|
|
- "s_entId": mongodb.BsonIdToSId((*res)["_id"]), //dev3.6.2 企业画像根据entId查询
|
|
|
|
- "s_entname": (*res)["company_name"],
|
|
|
|
- "s_area": qutil.If((*res)["company_area"] == nil, "", (*res)["company_area"]),
|
|
|
|
- "s_city": qutil.If((*res)["company_city"] == nil, "", (*res)["company_city"]),
|
|
|
|
- "s_phone": qutil.If((*res)["company_phone"] == nil, "", (*res)["company_phone"]),
|
|
|
|
- "f_capital": qutil.If((*res)["capital"] == nil, 0.0, (*res)["capital"]),
|
|
|
|
- "s_employeeno": qutil.If((*res)["employee_no"] == nil, 0, (*res)["employee_no"]),
|
|
|
|
- "l_createdate": time.Now().Unix(),
|
|
|
|
- "s_userid": this.UserId,
|
|
|
|
- "l_lastpushtime": time.Now().Unix(),
|
|
|
|
- }
|
|
|
|
- if len(getOldData) > 0 && getOldData[0] {
|
|
|
|
- followent, ok := db.Mgo.FindOne("jylab_followent", map[string]interface{}{"s_userid": this.UserId, "s_entname": (*res)["company_name"]})
|
|
|
|
- if followent != nil && ok && len(*followent) > 0 {
|
|
|
|
- followData["s_id"] = qutil.If((*followent)["s_id"] == nil, "", (*followent)["s_id"])
|
|
|
|
- followData["l_lastpushtime"] = qutil.If((*followent)["s_id"] == nil, 0, (*followent)["l_lastpushtime"])
|
|
|
|
|
|
+//AddFollowEnt 添加关注企业
|
|
|
|
+
|
|
|
|
+func (this *EntFollow) AddFollowEnt(entId, group string, getOldData ...bool) error {
|
|
|
|
+ groupFlag := getGroup(group)
|
|
|
|
+ if this.HasPower {
|
|
|
|
+ if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId, "s_entId": entId}) > 0 {
|
|
|
|
+ return errors.New("已关注此企业")
|
|
|
|
+ }
|
|
|
|
+ if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}) >= this.MaxNum {
|
|
|
|
+ return errors.New(fmt.Sprintf("您关注的企业已达%d个,无法关注更多", this.MaxNum))
|
|
|
|
+ }
|
|
|
|
+ res, _ := db.Mgo_Ent.FindOneByField("qyxy_std", map[string]interface{}{"_id": entId}, `{"company_name":1,"company_area":1,"company_city":1,"establish_date":1,"capital":1,"employee_no":1,"company_phone":1}`)
|
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
|
+ return errors.New("查找企业异常")
|
|
|
|
+ }
|
|
|
|
+ followData := map[string]interface{}{
|
|
|
|
+ "s_entId": mongodb.BsonIdToSId((*res)["_id"]), //dev3.6.2 企业画像根据entId查询
|
|
|
|
+ "s_entname": (*res)["company_name"],
|
|
|
|
+ "s_area": qutil.If((*res)["company_area"] == nil, "", (*res)["company_area"]),
|
|
|
|
+ "s_city": qutil.If((*res)["company_city"] == nil, "", (*res)["company_city"]),
|
|
|
|
+ "s_phone": qutil.If((*res)["company_phone"] == nil, "", (*res)["company_phone"]),
|
|
|
|
+ "f_capital": qutil.If((*res)["capital"] == nil, 0.0, (*res)["capital"]),
|
|
|
|
+ "s_employeeno": qutil.If((*res)["employee_no"] == nil, 0, (*res)["employee_no"]),
|
|
|
|
+ "l_createdate": time.Now().Unix(),
|
|
|
|
+ "s_userid": this.UserId,
|
|
|
|
+ "l_lastpushtime": time.Now().Unix(),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(getOldData) > 0 && getOldData[0] {
|
|
|
|
+ followent, ok := db.Mgo.FindOne("jylab_followent", map[string]interface{}{"s_userid": this.UserId, "s_entname": (*res)["company_name"]})
|
|
|
|
+ if followent != nil && ok && len(*followent) > 0 {
|
|
|
|
+ followData["s_id"] = qutil.If((*followent)["s_id"] == nil, "", (*followent)["s_id"])
|
|
|
|
+ followData["l_lastpushtime"] = qutil.If((*followent)["s_id"] == nil, 0, (*followent)["l_lastpushtime"])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ establishdate := qutil.ObjToString((*res)["establish_date"])
|
|
|
|
+ if establishdate != "" {
|
|
|
|
+ t, err := time.Parse(qutil.Date_Short_Layout, establishdate)
|
|
|
|
+ if err == nil {
|
|
|
|
+ followData["l_establishdate"] = t.Unix()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //设置分组
|
|
|
|
+ if groupFlag > -1 {
|
|
|
|
+ followData["i_group"] = groupFlag
|
|
|
|
+ }
|
|
|
|
+ followId := db.Mgo.Save(this.SaveTable, followData)
|
|
|
|
+ if followId == "" || len(followId) == 0 {
|
|
|
|
+ return errors.New("保存关注企业异常")
|
|
|
|
+ }
|
|
|
|
+ } else { //免费用户关注企业
|
|
|
|
+ entName := getEntNameById(entId)
|
|
|
|
+ if entName == "" {
|
|
|
|
+ return errors.New("企业信息异常")
|
|
|
|
+ }
|
|
|
|
+ if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId, "s_entname": entName}) > 0 {
|
|
|
|
+ return errors.New("已关注此企业")
|
|
|
|
+ }
|
|
|
|
+ if db.Mgo.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId}) >= this.MaxNum {
|
|
|
|
+ return errors.New(fmt.Sprintf("您关注的企业已达%d个,无法关注更多", this.MaxNum))
|
|
|
|
+ }
|
|
|
|
+ followData := map[string]interface{}{
|
|
|
|
+ "s_entname": entName,
|
|
|
|
+ "s_userid": this.UserId,
|
|
|
|
+ "l_createtime": time.Now().Unix(),
|
|
|
|
+ "l_lastpushtime": time.Now().Unix(),
|
|
|
|
+ "i_apppushunread": 0,
|
|
|
|
+ }
|
|
|
|
+ //设置分组
|
|
|
|
+ if groupFlag > -1 {
|
|
|
|
+ followData["i_group"] = groupFlag
|
|
|
|
+ }
|
|
|
|
+ followId := db.Mgo.Save(this.SaveTable, followData)
|
|
|
|
+ if followId == "" || len(followId) == 0 {
|
|
|
|
+ return errors.New("保存关注企业异常")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ go func(userId string) {
|
|
|
|
+ //首页潜在竞争对手缓存
|
|
|
|
+ redis.Del("other", fmt.Sprintf("CRIndex_R_%s", userId))
|
|
|
|
+ }(this.UserId)
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
|
|
- establishdate := qutil.ObjToString((*res)["establish_date"])
|
|
|
|
- if establishdate != "" {
|
|
|
|
- t, err := time.Parse(qutil.Date_Short_Layout, establishdate)
|
|
|
|
- if err == nil {
|
|
|
|
- followData["l_establishdate"] = t.Unix()
|
|
|
|
|
|
+// getGroup 获取分组
|
|
|
|
+// param A默认分组 B竞争对手 C合作伙伴 逗号分隔
|
|
|
|
+// db 0||nil 默认分组、1 竞争对手、2 合作伙伴、3 竞争对手和合作伙伴
|
|
|
|
+func getGroup(groupStr string) (s int) {
|
|
|
|
+ for _, sign := range strings.Split(groupStr, ",") {
|
|
|
|
+ switch sign {
|
|
|
|
+ case "A": //默认分组
|
|
|
|
+ return -1
|
|
|
|
+ case "B": //竞争对手
|
|
|
|
+ if s == 0 {
|
|
|
|
+ s = 1
|
|
|
|
+ } else {
|
|
|
|
+ return 3
|
|
|
|
+ }
|
|
|
|
+ case "C": //合作伙伴
|
|
|
|
+ if s == 0 {
|
|
|
|
+ s = 2
|
|
|
|
+ } else {
|
|
|
|
+ return 3
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if s == 0 {
|
|
|
|
+ return -1
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//格式化分组字段
|
|
|
|
+func parseGroupStr(gFlag int) string {
|
|
|
|
+ switch gFlag {
|
|
|
|
+ case 1:
|
|
|
|
+ return "B"
|
|
|
|
+ case 2:
|
|
|
|
+ return "C"
|
|
|
|
+ case 3:
|
|
|
|
+ return "B,C"
|
|
|
|
+ default:
|
|
|
|
+ return "A"
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- followId := db.Mgo.Save(this.SaveTable, followData)
|
|
|
|
- if followId == "" || len(followId) == 0 {
|
|
|
|
- return errors.New("保存关注企业异常")
|
|
|
|
|
|
+//ChangeFollowGroup 更换关注企业分组
|
|
|
|
+func (this *EntFollow) ChangeFollowGroup(fid, group string) error {
|
|
|
|
+ groupValue := getGroup(group)
|
|
|
|
+ if groupValue == -1 {
|
|
|
|
+ groupValue = 0
|
|
|
|
+ }
|
|
|
|
+ if !db.Mgo.UpdateById(this.SaveTable, fid, map[string]interface{}{"$set": map[string]interface{}{"i_group": groupValue}}) {
|
|
|
|
+ return fmt.Errorf("设置分组失败")
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
//删除关注企业
|
|
//删除关注企业
|
|
-func (this *EntFollow) DelFollowEnt(entId string) error {
|
|
|
|
- if db.Mgo.Delete(this.SaveTable, map[string]interface{}{"s_userid": this.UserId, "s_entId": entId}) < 0 {
|
|
|
|
- return errors.New("取关企业失败")
|
|
|
|
|
|
+func (this *EntFollow) DelFollowEnt(entId, fid string) error {
|
|
|
|
+ if entId == "" && fid == "" {
|
|
|
|
+ return fmt.Errorf("筛选条件异常")
|
|
}
|
|
}
|
|
|
|
+ query := map[string]interface{}{
|
|
|
|
+ "s_userid": this.UserId,
|
|
|
|
+ }
|
|
|
|
+ if this.HasPower {
|
|
|
|
+ if entId != "" {
|
|
|
|
+ query["s_entId"] = entId
|
|
|
|
+ }
|
|
|
|
+ if fid != "" {
|
|
|
|
+ query["_id"] = mongodb.StringTOBsonId(fid)
|
|
|
|
+ }
|
|
|
|
+ if db.Mgo.Delete(this.SaveTable, query) < 0 {
|
|
|
|
+ return errors.New("取关企业失败")
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if fid != "" {
|
|
|
|
+ query["_id"] = mongodb.StringTOBsonId(fid)
|
|
|
|
+ } else if entId != "" {
|
|
|
|
+ if entName := getEntNameById(entId); entName != "" {
|
|
|
|
+ query["s_entname"] = entName
|
|
|
|
+ } else {
|
|
|
|
+ return fmt.Errorf("未获取到企业信息")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ data, ok := db.Mgo.FindOne("jylab_followent", query)
|
|
|
|
+ if ok && data != nil && len(*data) > 0 && db.Mgo.Del("jylab_followent", map[string]interface{}{"_id": (*data)["_id"]}) {
|
|
|
|
+ (*data)["s_followid"] = mongodb.BsonIdToSId((*data)["_id"])
|
|
|
|
+ db.Mgo.Save("jylab_followent_back", data)
|
|
|
|
+ } else {
|
|
|
|
+ return fmt.Errorf("操作失败")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ go func(userId string) {
|
|
|
|
+ //首页潜在竞争对手缓存
|
|
|
|
+ redis.Del("other", fmt.Sprintf("CRIndex_R_%s", userId))
|
|
|
|
+ }(this.UserId)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -374,3 +599,27 @@ func InitializeSort(data []map[string]interface{}) []map[string][]EntChangeSort
|
|
}
|
|
}
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func getEntNameById(entId string) (entName string) {
|
|
|
|
+ r := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"term": {"_id": "%s"}},"_source": ["name"],"size": %d}`, entId, 1))
|
|
|
|
+ if r == nil || len(*r) == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ entName, _ = (*r)[0]["name"].(string)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getEntMsgByNames(names []string) (detail map[string]map[string]interface{}) {
|
|
|
|
+ detail = make(map[string]map[string]interface{})
|
|
|
|
+ names_str := `"` + strings.Join(names, `","`) + `"`
|
|
|
|
+ rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"company_name":[%s]}}]}},"_source":["company_name","_id","company_area","company_city","company_phone","capital","establish_date"],"size":%d}`, names_str, len(names)))
|
|
|
|
+ if rData == nil || len(*rData) == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, data := range *rData {
|
|
|
|
+ if name, ok := data["company_name"].(string); ok && name != "" {
|
|
|
|
+ detail[name] = data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|