|
@@ -1,986 +0,0 @@
|
|
|
-package marketAnalysis
|
|
|
-
|
|
|
-import (
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
- "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/bigmember/src/config"
|
|
|
- "jy/src/jfw/modules/bigmember/src/db"
|
|
|
- "jy/src/jfw/modules/bigmember/src/util"
|
|
|
- "log"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-const (
|
|
|
- marketQueryItem = iota //回显查询条件
|
|
|
- marketScaleMain //市场规模
|
|
|
- marketTopProject //项目规模TOP10
|
|
|
- marketProjectAllData //项目规模 地区分布 客户分布 地区客户top3
|
|
|
- marketScaleRefine //细化市场
|
|
|
- marketBuyerAndWinner //市场-采购单位&&中标企业
|
|
|
-
|
|
|
- ReportHistoryTable = "marketAnalysisReport"
|
|
|
- ReportCacheDB = "other"
|
|
|
- ReportCacheKey = "marketAnalysis_%s_%d"
|
|
|
- ReportCacheTime = 60 * 5
|
|
|
- ReportCanceledKey = "marketAnalysisCanceled_%s" // 取消的报告id
|
|
|
- ReportCanceledTime = 60 * 60 * 24
|
|
|
-
|
|
|
- ReportStateGenerating = 0 // 报告生成状态 生成中
|
|
|
- ReportStateGenerated = 1 // 生成 成功
|
|
|
- ReportStateCanceled = 2 // 已取消
|
|
|
- ReportStateFailed = -1 // 生成失败
|
|
|
- CollMarketScaleMain = "marketanalysisreport_scal" //市场规模 报告模块对应的mongo 集合名称
|
|
|
- CollMarketTopProject = "marketanalysisreport_top" //项目规模TOP10
|
|
|
- CollMarketProjectAllData = "marketanalysisreport_all" //项目规模 地区分布 客户分布 地区客户top3
|
|
|
- CollMarketScaleRefine = "marketanalysisreport_refine" //细化市场
|
|
|
- CollMarketBuyerAndWinner = "marketanalysisreport_bw" //市场-采购单位&&中标企业
|
|
|
- ValueOffline = 1 // 离线
|
|
|
- ValueRealTime = 2 // 实时
|
|
|
- Tablejianyu_mar_user_account = "jianyu.mar_user_account" // 离线市场报告分析关键词标准信息表
|
|
|
-)
|
|
|
-
|
|
|
-var (
|
|
|
- MarketAnalysisPool chan bool
|
|
|
-)
|
|
|
-
|
|
|
-func init() {
|
|
|
- MarketAnalysisPool = make(chan bool, config.Config.MarketAnalysisPool.Limit)
|
|
|
- for i := 0; i < config.Config.MarketAnalysisPool.Limit; i++ {
|
|
|
- MarketAnalysisPool <- true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// AnalysisRequestParam 接口原请求参数
|
|
|
-type AnalysisRequestParam struct {
|
|
|
- KeysItemsStr string //分析内容【字符串】结构和o_member_jy.a_items保持一致
|
|
|
- RangeTime string //时间【字符串】 时间戳开始-结束时间戳
|
|
|
- RangeTimeExtra string //时间【字符串】前段回显使用
|
|
|
- Area string //省份【对象字符串】
|
|
|
- Industry string //行业【对象字符串】
|
|
|
- BuyerClass string //采购单位类型【字符串】多个采购单位类型用逗号拼接
|
|
|
- Buyer string //采购单位
|
|
|
- Winner string //中标单位
|
|
|
- Sort int //排序:默认0:成交时间倒序;1:项目金额倒序
|
|
|
- PageSize int //默认每页10条
|
|
|
- PageNum int //默认当前第一页
|
|
|
- IsDetail bool //是否是项目明细请求
|
|
|
- MatchingMode string //匹配方式 title:标题 content:项目名称/标的物
|
|
|
-}
|
|
|
-
|
|
|
-type viewKeyWord struct {
|
|
|
- Keyword []string `json:"key"` //关键词
|
|
|
- Appended []string `json:"appendkey"` //附加词
|
|
|
- Exclude []string `json:"notkey"` //排除词
|
|
|
- MatchWay int `json:"matchway"` //匹配模式
|
|
|
-}
|
|
|
-
|
|
|
-// keyWordGroup 订阅词结构体
|
|
|
-type keyWordGroup struct {
|
|
|
- A_Key []viewKeyWord `json:"a_key"`
|
|
|
- ItemName string `json:"s_item"`
|
|
|
- UpdateTime int64 `json:"updatetime"`
|
|
|
-}
|
|
|
-
|
|
|
-// AnalysisRequestFormat 格式化后参数
|
|
|
-type AnalysisRequestFormat struct {
|
|
|
- KeysItems []keyWordGroup
|
|
|
- Area, City []string //省份城市
|
|
|
- STime, ETime int64 //开始结束时间
|
|
|
- Industry []string //行业
|
|
|
- BuyerClass []string //采购单位类型
|
|
|
- Buyer string //采购单位
|
|
|
- Winner string //中标单位
|
|
|
- Sort int //排序:默认0:成交时间倒序;1:项目金额倒序
|
|
|
- PageSize int //默认每页10条
|
|
|
- PageNum int //默认当前第一页
|
|
|
-}
|
|
|
-
|
|
|
-type MarketAnalysisEntity struct {
|
|
|
- MgoRecordId string
|
|
|
- BaseParam AnalysisRequestParam
|
|
|
- FormatParam AnalysisRequestFormat
|
|
|
- UId, Pid string
|
|
|
- ProjectInfo projectInfo
|
|
|
- Offline int // 1-离线 2-实时
|
|
|
- State int // 状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
|
|
|
- MgoUserId string
|
|
|
- Phone string // 手机号
|
|
|
- PositionId int
|
|
|
- OriginalTotal int64 // 数据总数
|
|
|
- PositionType int
|
|
|
- EntId int
|
|
|
- EntUserId int
|
|
|
- Source string
|
|
|
-}
|
|
|
-
|
|
|
-type projectInfo struct {
|
|
|
- Count int64
|
|
|
- List []ProjectList
|
|
|
-}
|
|
|
-
|
|
|
-type ProjectList struct {
|
|
|
- Name string `json:"name"` //项目名称
|
|
|
- Id string `json:"id"` //项目id
|
|
|
- Area string `json:"area"` //地区
|
|
|
- DealTime int64 `json:"dealTime"` //成交时间
|
|
|
- BidStatus string `json:"bidStatus"` //项目类型
|
|
|
- BuyerClass string `json:"buyerClass"` //采购单位类型
|
|
|
- Winner []string `json:"winner"` //中标单位
|
|
|
- WinnerId []string `json:"winnerId"` //中标单位id
|
|
|
- Buyer string `json:"buyer"` //采购单位
|
|
|
- BidAmount float64 `json:"bidAmount"` //中标金额
|
|
|
- Budget float64 `json:"budget"` //预算
|
|
|
-}
|
|
|
-
|
|
|
-// ForMatData 获取格式化请求参数
|
|
|
-func (mae *MarketAnalysisEntity) ForMatData() error {
|
|
|
- //格式化订阅词
|
|
|
- if err := json.Unmarshal([]byte(mae.BaseParam.KeysItemsStr), &mae.FormatParam.KeysItems); err != nil {
|
|
|
- return fmt.Errorf("关键词组格式异常")
|
|
|
- }
|
|
|
- if mae.FormatParam.KeysItems == nil || len(mae.FormatParam.KeysItems) == 0 {
|
|
|
- return fmt.Errorf("请选择关键词组")
|
|
|
- }
|
|
|
- var flag bool
|
|
|
- // 判断关键词是不是为空
|
|
|
- for i := 0; i < len(mae.FormatParam.KeysItems); i++ {
|
|
|
- items := mae.FormatParam.KeysItems[i]
|
|
|
- for j := 0; j < len(items.A_Key); j++ {
|
|
|
- AKey := items.A_Key[j]
|
|
|
- if len(AKey.Keyword) > 0 {
|
|
|
- flag = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if flag {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if !flag {
|
|
|
- return fmt.Errorf("请选择关键词组")
|
|
|
- }
|
|
|
- //格式化时间段
|
|
|
- if timeArr := strings.Split(mae.BaseParam.RangeTime, "-"); len(timeArr) == 2 {
|
|
|
- mae.FormatParam.STime = qutil.Int64All(timeArr[0])
|
|
|
- mae.FormatParam.ETime = qutil.Int64All(timeArr[1])
|
|
|
- if mae.FormatParam.STime == 0 || mae.FormatParam.ETime == 0 {
|
|
|
- return fmt.Errorf("开始时间和结束时间不能为空")
|
|
|
- }
|
|
|
- } else {
|
|
|
- return fmt.Errorf("时间戳格式异常")
|
|
|
- }
|
|
|
- //格式化省份、城市
|
|
|
- if areaStr := strings.TrimSpace(mae.BaseParam.Area); areaStr != "" {
|
|
|
- imap := map[string][]string{}
|
|
|
- if err := json.Unmarshal([]byte(mae.BaseParam.Area), &imap); err != nil {
|
|
|
- return fmt.Errorf("非法地区信息")
|
|
|
- }
|
|
|
- var city, area []string
|
|
|
- for name, v := range imap {
|
|
|
- if len(v) == 0 {
|
|
|
- area = append(area, name)
|
|
|
- } else {
|
|
|
- for _, vv := range v {
|
|
|
- city = append(city, vv)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- mae.FormatParam.Area = area
|
|
|
- mae.FormatParam.City = city
|
|
|
- }
|
|
|
- //格式化行业
|
|
|
- if industryStr := strings.TrimSpace(mae.BaseParam.Industry); industryStr != "" {
|
|
|
- imap := map[string][]string{}
|
|
|
- if err := json.Unmarshal([]byte(industryStr), &imap); err != nil {
|
|
|
- return fmt.Errorf("非法行业信息")
|
|
|
- }
|
|
|
- var farr []string
|
|
|
- for name, v := range imap {
|
|
|
- for _, vv := range v {
|
|
|
- farr = append(farr, fmt.Sprintf("%s_%s", name, vv))
|
|
|
- }
|
|
|
- }
|
|
|
- if len(farr) > 0 {
|
|
|
- //P510 行业:其它
|
|
|
- if qt := jy.IndustryHandle(strings.Join(farr, ",")); len(qt) > 0 {
|
|
|
- farr = append(farr, qt...)
|
|
|
- }
|
|
|
- }
|
|
|
- mae.FormatParam.Industry = farr
|
|
|
- }
|
|
|
- //格式化类型
|
|
|
- if buyerClassStr := strings.TrimSpace(mae.BaseParam.BuyerClass); buyerClassStr != "" {
|
|
|
- mae.FormatParam.BuyerClass = strings.Split(buyerClassStr, ",")
|
|
|
- }
|
|
|
- //中标企业
|
|
|
- mae.FormatParam.Winner = mae.BaseParam.Winner
|
|
|
- //采购单位
|
|
|
- mae.FormatParam.Buyer = mae.BaseParam.Buyer
|
|
|
- //排序
|
|
|
- mae.FormatParam.Sort = qutil.If(mae.BaseParam.Sort != 0 && mae.BaseParam.Sort != 1, 0, mae.BaseParam.Sort).(int)
|
|
|
- if mae.BaseParam.PageNum*mae.BaseParam.PageSize > config.Config.ProjectCount {
|
|
|
- mae.BaseParam.PageNum = config.Config.ProjectCount / mae.BaseParam.PageSize
|
|
|
- }
|
|
|
- //当前页码
|
|
|
- mae.FormatParam.PageNum = qutil.If(mae.BaseParam.PageNum < 1 || mae.BaseParam.PageNum > 1000, 1, mae.BaseParam.PageNum).(int)
|
|
|
- //默认每页10条
|
|
|
- mae.FormatParam.PageSize = qutil.If(mae.BaseParam.PageSize < 1 || mae.BaseParam.PageSize > 100, 50, mae.BaseParam.PageSize).(int)
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// ForMatData 获取格式化请求参数
|
|
|
-func (mae *MarketAnalysisEntity) ForMatDataPdf() (string, error) {
|
|
|
- //格式化订阅词
|
|
|
- if err := json.Unmarshal([]byte(mae.BaseParam.KeysItemsStr), &mae.FormatParam.KeysItems); err != nil {
|
|
|
- return "", fmt.Errorf("关键词组格式异常")
|
|
|
- }
|
|
|
-
|
|
|
- //格式化时间段
|
|
|
- if timeArr := strings.Split(mae.BaseParam.RangeTime, "-"); len(timeArr) == 2 {
|
|
|
- mae.FormatParam.STime = qutil.Int64All(timeArr[0])
|
|
|
- mae.FormatParam.ETime = qutil.Int64All(timeArr[1])
|
|
|
- if mae.FormatParam.STime == 0 || mae.FormatParam.ETime == 0 {
|
|
|
- return "", fmt.Errorf("开始时间和结束时间不能为空")
|
|
|
- }
|
|
|
- } else {
|
|
|
- return "", fmt.Errorf("时间戳格式异常")
|
|
|
- }
|
|
|
- //格式化省份、城市
|
|
|
- if areaStr := strings.TrimSpace(mae.BaseParam.Area); areaStr != "" {
|
|
|
- imap := map[string][]string{}
|
|
|
- if err := json.Unmarshal([]byte(mae.BaseParam.Area), &imap); err != nil {
|
|
|
- return "", fmt.Errorf("非法地区信息")
|
|
|
- }
|
|
|
- var city, area []string
|
|
|
- for name, v := range imap {
|
|
|
- if len(v) == 0 {
|
|
|
- area = append(area, name)
|
|
|
- } else {
|
|
|
- for _, vv := range v {
|
|
|
- city = append(city, vv)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- mae.FormatParam.Area = area
|
|
|
- mae.FormatParam.City = city
|
|
|
- }
|
|
|
- //格式化行业
|
|
|
- if industryStr := strings.TrimSpace(mae.BaseParam.Industry); industryStr != "" {
|
|
|
- imap := map[string][]string{}
|
|
|
- if err := json.Unmarshal([]byte(industryStr), &imap); err != nil {
|
|
|
- return "", fmt.Errorf("非法行业信息")
|
|
|
- }
|
|
|
- var farr []string
|
|
|
- for name, v := range imap {
|
|
|
- for _, vv := range v {
|
|
|
- farr = append(farr, fmt.Sprintf("%s_%s", name, vv))
|
|
|
- }
|
|
|
- }
|
|
|
- mae.FormatParam.Industry = farr
|
|
|
- }
|
|
|
- //格式化类型
|
|
|
- if buyerClassStr := strings.TrimSpace(mae.BaseParam.BuyerClass); buyerClassStr != "" {
|
|
|
- mae.FormatParam.BuyerClass = strings.Split(buyerClassStr, ",")
|
|
|
- }
|
|
|
- //中标企业
|
|
|
- mae.FormatParam.Winner = mae.BaseParam.Winner
|
|
|
- //采购单位
|
|
|
- mae.FormatParam.Buyer = mae.BaseParam.Buyer
|
|
|
- //排序
|
|
|
- mae.FormatParam.Sort = qutil.If(mae.BaseParam.Sort != 0 && mae.BaseParam.Sort != 1, 0, mae.BaseParam.Sort).(int)
|
|
|
- if mae.BaseParam.PageNum*mae.BaseParam.PageSize > config.Config.ProjectCount {
|
|
|
- mae.BaseParam.PageNum = config.Config.ProjectCount / mae.BaseParam.PageSize
|
|
|
- }
|
|
|
- //当前页码
|
|
|
- mae.FormatParam.PageNum = qutil.If(mae.BaseParam.PageNum < 1 || mae.BaseParam.PageNum > 1000, 1, mae.BaseParam.PageNum).(int)
|
|
|
- //默认每页10条
|
|
|
- mae.FormatParam.PageSize = qutil.If(mae.BaseParam.PageSize < 1 || mae.BaseParam.PageSize > 100, 50, mae.BaseParam.PageSize).(int)
|
|
|
- data := map[string]interface{}{
|
|
|
- "s_keysItems": mae.BaseParam.KeysItemsStr,
|
|
|
- "s_rangeTime": mae.BaseParam.RangeTime,
|
|
|
- "s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
|
|
|
- "s_area": mae.BaseParam.Area,
|
|
|
- "s_industry": mae.BaseParam.Industry,
|
|
|
- "s_buyerClass": mae.BaseParam.BuyerClass,
|
|
|
- "s_matchingMode": mae.BaseParam.MatchingMode,
|
|
|
- "s_userId": mae.UId,
|
|
|
- "s_parentId": mae.Pid,
|
|
|
- "s_mgoUserId": mae.MgoUserId,
|
|
|
- "i_positionId": mae.PositionId,
|
|
|
- "s_phone": mae.Phone,
|
|
|
- "audit": 1,
|
|
|
- }
|
|
|
- if mae.OriginalTotal > 0 {
|
|
|
- data["l_originalTotal"] = mae.OriginalTotal
|
|
|
- }
|
|
|
- if mae.Source != "" {
|
|
|
- data["source"] = mae.Source
|
|
|
- }
|
|
|
- rs, b := db.Mgo.FindOne(ReportHistoryTable, data)
|
|
|
- if b && rs != nil && len(*rs) > 0 {
|
|
|
- return qutil.InterfaceToStr((*rs)["_id"]), errors.New("当期分析已存在")
|
|
|
- }
|
|
|
- return "", nil
|
|
|
-}
|
|
|
-
|
|
|
-// GetProjectInfoList 项目明细
|
|
|
-func (mae *MarketAnalysisEntity) GetProjectInfoList() error {
|
|
|
- var (
|
|
|
- queryDefault = `,"sort": [{%s}],"from": %d,"size": %d`
|
|
|
- start = (mae.FormatParam.PageNum - 1) * mae.FormatParam.PageSize
|
|
|
- sort = `"jgtime": "desc"`
|
|
|
- )
|
|
|
- if mae.FormatParam.Sort > 0 {
|
|
|
- sort = `"bidamount": "desc","budget": "desc"`
|
|
|
- }
|
|
|
- countSql := fmt.Sprintf(mae.GetCommonQuerySql(), "")
|
|
|
- queryDefault = fmt.Sprintf(queryDefault, sort, start, mae.FormatParam.PageSize)
|
|
|
- finalSql := fmt.Sprintf(mae.GetCommonQuerySql(), queryDefault)
|
|
|
- log.Println("finalSql:", finalSql)
|
|
|
- count, hits := elastic.GetWithCount("projectset", "projectset", countSql, finalSql)
|
|
|
- //hits, count := elastic.GetOA("projectset", "projectset", finalSql)
|
|
|
- if count > 0 {
|
|
|
- mae.ProjectInfo.Count = count
|
|
|
- source := *hits
|
|
|
- for _, v := range source {
|
|
|
- var winnerIdArr []string
|
|
|
- if qutil.ObjToString(v["s_winner"]) != "" && v["entidlist"] != nil {
|
|
|
- idObjs, _ := v["entidlist"].([]interface{})
|
|
|
- for _, v := range qutil.ObjArrToStringArr(idObjs) {
|
|
|
- if v != "" && v != "-" {
|
|
|
- v = encrypt.EncodeArticleId2ByCheck(v)
|
|
|
- }
|
|
|
- winnerIdArr = append(winnerIdArr, v)
|
|
|
- }
|
|
|
- }
|
|
|
- mae.ProjectInfo.List = append(mae.ProjectInfo.List, ProjectList{
|
|
|
- Name: qutil.ObjToString(v["projectname"]),
|
|
|
- Id: encrypt.EncodeArticleId2ByCheck(qutil.ObjToString(v["id"])),
|
|
|
- Area: qutil.ObjToString(v["area"]),
|
|
|
- DealTime: qutil.Int64All(v["jgtime"]), //截止时间
|
|
|
- BidStatus: qutil.ObjToString(v["bidstatus"]),
|
|
|
- BuyerClass: qutil.ObjToString(v["buyerclass"]),
|
|
|
- Winner: strings.Split(qutil.ObjToString(v["s_winner"]), ","),
|
|
|
- WinnerId: winnerIdArr,
|
|
|
- Buyer: qutil.ObjToString(v["buyer"]),
|
|
|
- BidAmount: qutil.Float64All(v["bidamount"]), //中标金额
|
|
|
- Budget: qutil.Float64All(v["budget"]), //预算
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// SaveAnalysisRecord 保存分析记录
|
|
|
-func (mae *MarketAnalysisEntity) SaveAnalysisRecord() error {
|
|
|
- if mae.Offline == ValueRealTime {
|
|
|
- mae.State = ReportStateGenerated
|
|
|
- } else {
|
|
|
- mae.State = ReportStateGenerating
|
|
|
- }
|
|
|
- data := map[string]interface{}{
|
|
|
- "s_keysItems": mae.BaseParam.KeysItemsStr,
|
|
|
- "s_rangeTime": mae.BaseParam.RangeTime,
|
|
|
- "s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
|
|
|
- "s_area": mae.BaseParam.Area,
|
|
|
- "s_industry": mae.BaseParam.Industry,
|
|
|
- "s_buyerClass": mae.BaseParam.BuyerClass,
|
|
|
- "s_matchingMode": mae.BaseParam.MatchingMode,
|
|
|
- "s_userId": mae.UId,
|
|
|
- "s_parentId": mae.Pid,
|
|
|
- "i_state": qutil.If(mae.Source == "analysisPDF", 1, mae.State), //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
|
|
|
- "l_updateTime": time.Now().Unix(), //生成时间 or 取消时间
|
|
|
- "l_createTime": time.Now().Unix(),
|
|
|
- "i_offline": qutil.If(mae.Source == "analysisPDF", 2, mae.Offline),
|
|
|
- "s_mgoUserId": mae.MgoUserId,
|
|
|
- "i_positionId": mae.PositionId,
|
|
|
- "s_phone": mae.Phone,
|
|
|
- }
|
|
|
- if mae.OriginalTotal > 0 {
|
|
|
- data["l_originalTotal"] = mae.OriginalTotal
|
|
|
- }
|
|
|
- if mae.Source != "" {
|
|
|
- data["source"] = mae.Source
|
|
|
- }
|
|
|
- mae.MgoRecordId = db.Mgo.Save(ReportHistoryTable, data)
|
|
|
- if mae.MgoRecordId == "" {
|
|
|
- return fmt.Errorf("分析创建异常")
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// GetAnalysisFromMgoDb 从数据库中获取分析记录
|
|
|
-func (mae *MarketAnalysisEntity) GetAnalysisFromMgoDb() error {
|
|
|
- if mae.MgoRecordId == "" {
|
|
|
- return fmt.Errorf("缺少参数")
|
|
|
- }
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "_id": mongodb.StringTOBsonId(mae.MgoRecordId),
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- res, _ := db.Mgo.FindOne(ReportHistoryTable, queryMap)
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return fmt.Errorf("未查询到相关数据")
|
|
|
- }
|
|
|
- mae.Offline = qutil.IntAll((*res)["i_offline"])
|
|
|
- mae.State = qutil.IntAll((*res)["i_state"])
|
|
|
- mae.BaseParam.KeysItemsStr, _ = (*res)["s_keysItems"].(string)
|
|
|
- mae.BaseParam.RangeTime, _ = (*res)["s_rangeTime"].(string)
|
|
|
- mae.BaseParam.RangeTimeExtra, _ = (*res)["s_rangeTimeExtra"].(string)
|
|
|
- mae.BaseParam.Area, _ = (*res)["s_area"].(string)
|
|
|
- mae.BaseParam.Industry, _ = (*res)["s_industry"].(string)
|
|
|
- mae.BaseParam.BuyerClass, _ = (*res)["s_buyerClass"].(string)
|
|
|
- mae.BaseParam.MatchingMode, _ = (*res)["s_matchingMode"].(string)
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// removeEmptyRecord 删除空报告记录
|
|
|
-func (mae *MarketAnalysisEntity) removeEmptyRecord() {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "_id": mongodb.StringTOBsonId(mae.MgoRecordId),
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- db.Mgo.Update(ReportHistoryTable, queryMap, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{"i_del": 1},
|
|
|
- }, false, false)
|
|
|
- //log.Println("删除空报告", queryMap)
|
|
|
-}
|
|
|
-
|
|
|
-// GetRecordList 获取分析记录
|
|
|
-func (mae *MarketAnalysisEntity) GetRecordList(pageNum, PageSize int, positionType int, entId, entUserId int) (total int, list []map[string]interface{}) {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- if pageNum == 1 {
|
|
|
- total = db.Mgo.Count(ReportHistoryTable, queryMap)
|
|
|
- if total == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- total = -1
|
|
|
- }
|
|
|
- res, _ := db.Mgo.Find(ReportHistoryTable, queryMap, `{"l_createTime":-1}`, nil, false, (pageNum-1)*PageSize, PageSize)
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- var ids []string
|
|
|
- for _, m := range *res {
|
|
|
- ids = append(ids, qutil.InterfaceToStr(m["_id"]))
|
|
|
- }
|
|
|
- idMap := make(map[string]map[string]interface{})
|
|
|
- tName, _ := GetMongoColl(marketScaleMain)
|
|
|
- mids, _ := db.Mgo.Find(tName, map[string]interface{}{
|
|
|
- "s_m_id": map[string]interface{}{
|
|
|
- "$in": ids,
|
|
|
- },
|
|
|
- }, "", `{"market_profile":1,"s_m_id":1}`, false, -1, -1)
|
|
|
- if mids != nil && len(*mids) > 0 {
|
|
|
- for _, m := range *mids {
|
|
|
- marketProfile, _ := m["market_profile"].(map[string]interface{})
|
|
|
- if qutil.IntAll(marketProfile["project_count"]) > 0 {
|
|
|
- idMap[qutil.InterfaceToStr(m["s_m_id"])] = marketProfile
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //用户消息开关
|
|
|
- open := GetMsgOpen(mae.MgoUserId, positionType, entId, entUserId)
|
|
|
- for _, row := range *res {
|
|
|
- var status int
|
|
|
- if row["i_state"] != nil {
|
|
|
- status = qutil.IntAll(row["i_state"])
|
|
|
- if status == ReportStateFailed {
|
|
|
- status = ReportStateGenerating // 生成失败对外还是展示为生成中
|
|
|
- }
|
|
|
- }
|
|
|
- var (
|
|
|
- isDownload bool
|
|
|
- )
|
|
|
- marketProfile := make(map[string]interface{})
|
|
|
- if marketProfile = idMap[mongodb.BsonIdToSId(row["_id"])]; marketProfile != nil && qutil.IntAll(marketProfile["project_count"]) > 0 && status == 1 {
|
|
|
- isDownload = true
|
|
|
- }
|
|
|
- //P510 回显 移除 其它
|
|
|
- industry := qutil.ObjToString(row["s_industry"])
|
|
|
- if industry != "" {
|
|
|
- industry = strings.ReplaceAll(industry, "\"其它\"", "")
|
|
|
- }
|
|
|
- data := map[string]interface{}{
|
|
|
- "id": util.EncodeId(mongodb.BsonIdToSId(row["_id"])),
|
|
|
- "keysItems": qutil.ObjToString(row["s_keysItems"]),
|
|
|
- "area": qutil.ObjToString(row["s_area"]),
|
|
|
- "industry": industry,
|
|
|
- "buyerclass": qutil.ObjToString(row["s_buyerClass"]),
|
|
|
- "rangeTime": qutil.ObjToString(row["s_rangeTime"]),
|
|
|
- "s_rangeTimeExtra": qutil.ObjToString(row["s_rangeTimeExtra"]),
|
|
|
- "createTime": qutil.Int64All(row["l_createTime"]),
|
|
|
- "matchingMode": qutil.ObjToString(row["s_matchingMode"]), //项目匹配方式
|
|
|
- "state": qutil.If(row["i_state"] == nil, nil, status),
|
|
|
- "updateTime": qutil.Int64All(row["l_updateTime"]),
|
|
|
- "msgOpen": open,
|
|
|
- "isDownload": isDownload,
|
|
|
- "marketProfile": marketProfile,
|
|
|
- }
|
|
|
- list = append(list, data)
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func (mae *MarketAnalysisEntity) GetRecordPdfList(pageNum, PageSize int) (total int, list []map[string]interface{}) {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- "source": "analysisPDF",
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- if pageNum == 1 {
|
|
|
- total = db.Mgo.Count(ReportHistoryTable, queryMap)
|
|
|
- if total == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- total = -1
|
|
|
- }
|
|
|
- res, _ := db.Mgo.Find(ReportHistoryTable, queryMap, `{"l_createTime":-1}`, nil, false, (pageNum-1)*PageSize, PageSize)
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, row := range *res {
|
|
|
- data := map[string]interface{}{
|
|
|
- "id": util.EncodeId(mongodb.BsonIdToSId(row["_id"])),
|
|
|
- "keysItems": qutil.ObjToString(row["s_keysItems"]),
|
|
|
- "area": qutil.ObjToString(row["s_area"]),
|
|
|
- "industry": qutil.ObjToString(row["s_industry"]),
|
|
|
- "buyerclass": qutil.ObjToString(row["s_buyerClass"]),
|
|
|
- "rangeTime": qutil.ObjToString(row["s_rangeTime"]),
|
|
|
- "s_rangeTimeExtra": qutil.ObjToString(row["s_rangeTimeExtra"]),
|
|
|
- "createTime": qutil.Int64All(row["l_createTime"]),
|
|
|
- "matchingMode": qutil.ObjToString(row["s_matchingMode"]), //项目匹配方式
|
|
|
- "updateTime": qutil.Int64All(row["l_updateTime"]),
|
|
|
- "audit": qutil.Int64All(row["audit"]),
|
|
|
- }
|
|
|
- list = append(list, data)
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetQueryItem 获取查询条件,前端回显使用
|
|
|
-func (mae *MarketAnalysisEntity) getQueryItem() (map[string]interface{}, error) {
|
|
|
- return map[string]interface{}{
|
|
|
- "keysItems": mae.BaseParam.KeysItemsStr,
|
|
|
- "area": mae.BaseParam.Area,
|
|
|
- "industry": mae.BaseParam.Industry,
|
|
|
- "buyerclass": mae.BaseParam.BuyerClass,
|
|
|
- "rangeTime": mae.BaseParam.RangeTime,
|
|
|
- "s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
|
|
|
- "matchingMode": mae.BaseParam.MatchingMode,
|
|
|
- }, nil
|
|
|
-}
|
|
|
-
|
|
|
-// GetPartResult 分块儿获取报告内容
|
|
|
-func (mae *MarketAnalysisEntity) GetPartResult(flag int) (map[string]interface{}, error) {
|
|
|
- defer qutil.Catch()
|
|
|
- if flag == marketQueryItem { //返回查询内容
|
|
|
- return mae.getQueryItem()
|
|
|
- }
|
|
|
- thisCacheKey := fmt.Sprintf(ReportCacheKey, mae.MgoRecordId, flag)
|
|
|
- if cacheData := redis.Get(ReportCacheDB, thisCacheKey); cacheData != nil {
|
|
|
- if cacheMap, ok := cacheData.(map[string]interface{}); ok && len(cacheMap) > 0 {
|
|
|
- return cacheMap, nil
|
|
|
- }
|
|
|
- }
|
|
|
- rData, err := func() (map[string]interface{}, error) {
|
|
|
- //控制并发&&超时返回超时异常
|
|
|
- select {
|
|
|
- case <-time.After(time.Duration(config.Config.MarketAnalysisPool.TimeOut) * time.Second * 20):
|
|
|
- return nil, fmt.Errorf("查询超时,请稍后重试")
|
|
|
- case <-MarketAnalysisPool:
|
|
|
- }
|
|
|
- start := time.Now()
|
|
|
- defer func() {
|
|
|
- MarketAnalysisPool <- true
|
|
|
- log.Printf("report %s[%d] speed %d ms\n", mae.MgoRecordId, flag, time.Now().Sub(start).Milliseconds())
|
|
|
- }()
|
|
|
- //校验报告是否合法
|
|
|
- //if flag != marketScaleMain {
|
|
|
- // if exists, _ := redis.Exists(ReportCacheDB, fmt.Sprintf(ReportCacheKey, mae.MgoRecordId, 1)); !exists {
|
|
|
- // return nil, fmt.Errorf("报告异常请求,请刷新重试")
|
|
|
- // }
|
|
|
- //}
|
|
|
- // 1. 查mongo
|
|
|
- var rData map[string]interface{}
|
|
|
- var err error
|
|
|
- rData, err = mae.GetMongoData(flag)
|
|
|
- // 查到数据则直接返回
|
|
|
- if err == nil && rData != nil {
|
|
|
- return rData, nil
|
|
|
- }
|
|
|
- // 2.没有查询到数据 判断是不是离线的
|
|
|
- // 正常情况下正在离线生的不会走到这里
|
|
|
- // 离线的应该生成完报告之后才会调用获取结果接口 这里处理是防止直接调接口传正在离线生的报告
|
|
|
- if mae.Offline == ValueOffline || mae.Offline == 0 {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- // 3. 实时则查es
|
|
|
- rData, err = mae.realTimeQuery(flag)
|
|
|
- if err == nil && len(rData) > 0 {
|
|
|
- // 4.存库
|
|
|
- mae.SaveMongoReport(rData, flag)
|
|
|
- return rData, err
|
|
|
- }
|
|
|
- return nil, err
|
|
|
- }()
|
|
|
- if err == nil && rData != nil && len(rData) > 0 {
|
|
|
- delete(rData, "s_m_id")
|
|
|
- delete(rData, "_id")
|
|
|
- redis.Put(ReportCacheDB, thisCacheKey, rData, ReportCacheTime)
|
|
|
- }
|
|
|
- return rData, err
|
|
|
-}
|
|
|
-
|
|
|
-// 实时查询
|
|
|
-func (mae *MarketAnalysisEntity) realTimeQuery(flag int) (map[string]interface{}, error) {
|
|
|
- switch flag {
|
|
|
- case marketScaleMain:
|
|
|
- rData, err := mae.MarketTime()
|
|
|
- if err != nil { //若无报告内容,删除报告记录
|
|
|
- go mae.removeEmptyRecord()
|
|
|
- }
|
|
|
- return rData, err
|
|
|
- case marketTopProject:
|
|
|
- return mae.ProjectTop10()
|
|
|
- case marketProjectAllData:
|
|
|
- return mae.AllData()
|
|
|
- case marketScaleRefine:
|
|
|
- return mae.marketScaleRefineQuery()
|
|
|
- case marketBuyerAndWinner:
|
|
|
- return mae.BuyerWinnerAnalysis(), nil
|
|
|
- }
|
|
|
- return nil, fmt.Errorf("未知请求")
|
|
|
-}
|
|
|
-
|
|
|
-// GetMongoData 从mongo库查询数据
|
|
|
-func (mae *MarketAnalysisEntity) GetMongoData(flag int) (map[string]interface{}, error) {
|
|
|
- collName, err := GetMongoColl(flag)
|
|
|
- if err != nil || collName == "" {
|
|
|
- return nil, fmt.Errorf("未知请求")
|
|
|
- }
|
|
|
- // 查询
|
|
|
- query := map[string]interface{}{
|
|
|
- "s_m_id": mae.MgoRecordId,
|
|
|
- }
|
|
|
- data, b := db.Mgo.FindOne(collName, query)
|
|
|
- if !b || data == nil || len(*data) == 0 {
|
|
|
- log.Println("没有查询到数据", b, query, collName)
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
- delete(*data, "s_m_id")
|
|
|
- delete(*data, "_id")
|
|
|
- return *data, nil
|
|
|
-}
|
|
|
-
|
|
|
-// GetMongoColl 获取mgo库对应的Coll
|
|
|
-func GetMongoColl(flag int) (string, error) {
|
|
|
- switch flag {
|
|
|
- case marketScaleMain:
|
|
|
- return CollMarketScaleMain, nil
|
|
|
- case marketTopProject:
|
|
|
- return CollMarketTopProject, nil
|
|
|
- case marketProjectAllData:
|
|
|
- return CollMarketProjectAllData, nil
|
|
|
- case marketScaleRefine:
|
|
|
- return CollMarketScaleRefine, nil
|
|
|
- case marketBuyerAndWinner:
|
|
|
- return CollMarketBuyerAndWinner, nil
|
|
|
- }
|
|
|
- return "", fmt.Errorf("未知类型")
|
|
|
-}
|
|
|
-
|
|
|
-// SaveMongoReport 数据存mongo库
|
|
|
-func (mae *MarketAnalysisEntity) SaveMongoReport(rData map[string]interface{}, flag int) {
|
|
|
- collName, _ := GetMongoColl(flag)
|
|
|
- rData["s_m_id"] = mae.MgoRecordId
|
|
|
- b, err := json.Marshal(rData)
|
|
|
- if err != nil {
|
|
|
- log.Println("JSON marshal error:", err)
|
|
|
- } else {
|
|
|
- var saveMap map[string]interface{}
|
|
|
- err = json.Unmarshal(b, &saveMap)
|
|
|
- if err != nil {
|
|
|
- log.Println("JSON Unmarshal error:", err)
|
|
|
- db.Mgo.Save(collName, rData)
|
|
|
- } else {
|
|
|
- db.Mgo.Save(collName, saveMap)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// GetAnalyzingReport 是否有正在分析的离线报告
|
|
|
-func (mae *MarketAnalysisEntity) GetAnalyzingReport() string {
|
|
|
- query := map[string]interface{}{
|
|
|
- "s_userId": mae.UId,
|
|
|
- "i_state": map[string]interface{}{"$in": []int{ReportStateGenerating, ReportStateFailed}}, //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- }
|
|
|
- //log.Println("query:", query)
|
|
|
- rs, b := db.Mgo.FindOne(ReportHistoryTable, query)
|
|
|
- //log.Println("rs,b:", rs, b)
|
|
|
- if b && rs != nil {
|
|
|
- return mongodb.BsonIdToSId((*rs)["_id"])
|
|
|
- }
|
|
|
- return ""
|
|
|
-}
|
|
|
-
|
|
|
-// IsOffline 判断是否符合在线分析的条件
|
|
|
-func (mae *MarketAnalysisEntity) IsOffline() (offline bool) {
|
|
|
- //离线生成:订阅词(关键词+排除词)超过300个(数量支持配置),或单次分析数据超过60万条,则离线生成;
|
|
|
- keyCount := 0
|
|
|
- for i := 0; i < len(mae.FormatParam.KeysItems); i++ {
|
|
|
- items := mae.FormatParam.KeysItems[i]
|
|
|
- for j := 0; j < len(items.A_Key); j++ {
|
|
|
- AKey := items.A_Key[j]
|
|
|
- for k := 0; k < len(AKey.Keyword); k++ {
|
|
|
- keyCount++
|
|
|
- }
|
|
|
- for k := 0; k < len(AKey.Appended); k++ {
|
|
|
- keyCount++
|
|
|
- }
|
|
|
- for k := 0; k < len(AKey.Exclude); k++ {
|
|
|
- keyCount++
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if keyCount > config.Config.MarketAnalysisPool.KeyWordsCount {
|
|
|
- // 查询配置
|
|
|
- if mac := mae.getMarUserAccount(); mac != nil {
|
|
|
- if keyCount >= mac.Threshold {
|
|
|
- mae.Offline = ValueOffline
|
|
|
- return true
|
|
|
- }
|
|
|
- } else {
|
|
|
- mae.Offline = ValueOffline
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 查询数据量
|
|
|
- countSql := fmt.Sprintf(mae.GetCommonQuerySql(), "")
|
|
|
- log.Println("IsOffline count SQL:", countSql)
|
|
|
- a := time.Now()
|
|
|
- dataCount := elastic.Count("projectset", "projectset", countSql)
|
|
|
- b := time.Since(a)
|
|
|
- log.Println("IsOffline 统计数据量耗时:", b)
|
|
|
- log.Println("IsOffline 数据量:", dataCount)
|
|
|
- mae.OriginalTotal = dataCount
|
|
|
- if int(dataCount) > config.Config.MarketAnalysisPool.ProjectNumLimit {
|
|
|
- mae.Offline = ValueOffline
|
|
|
- return true
|
|
|
- }
|
|
|
- mae.Offline = ValueRealTime
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-type MarUserAccount struct {
|
|
|
- Threshold int // 关键词离线标准量
|
|
|
-}
|
|
|
-
|
|
|
-// 获取离线市场报告分析关键词标准信息
|
|
|
-func (mae *MarketAnalysisEntity) getMarUserAccount() *MarUserAccount {
|
|
|
- rs := db.Mysql.SelectBySql(fmt.Sprintf("SELECT threshold FROM %s where position_id=? and state = 0;", Tablejianyu_mar_user_account), mae.PositionId)
|
|
|
- if rs != nil && len(*rs) > 0 {
|
|
|
- return &MarUserAccount{Threshold: qutil.IntAll((*rs)[0]["threshold"])}
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-func (mae *MarketAnalysisEntity) GetReportState() (generated bool, needUpdate bool, err error) {
|
|
|
- // 查库
|
|
|
- err = mae.GetAnalysisFromMgoDb()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- // 已经生成的可以直接返回
|
|
|
- if mae.State == ReportStateGenerated {
|
|
|
- generated = true
|
|
|
- return
|
|
|
- }
|
|
|
- // 该字段没有值 说明是还没有被更新的历史数据 需要更新
|
|
|
- // 且判断之后后续需要更新i_state和i_offline字段
|
|
|
- if mae.Offline == 0 {
|
|
|
- needUpdate = true
|
|
|
- }
|
|
|
- // 如果没有值的话 说明这是历史数据 需要接着走下面的流程进行判断
|
|
|
- // 格式化数据 用于后面校验个数
|
|
|
- if err = mae.ForMatData(); err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- return
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// Cancel 取消正在分析中的报告
|
|
|
-func (mae *MarketAnalysisEntity) Cancel() (bool, error) {
|
|
|
- // 取消报告
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "_id": mae.MgoRecordId,
|
|
|
- "i_state": map[string]interface{}{"$in": []int{ReportStateGenerating, ReportStateFailed}}, //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- //验证
|
|
|
- rs, b := db.Mgo.FindOne(ReportHistoryTable, queryMap)
|
|
|
- //
|
|
|
- if !b || rs == nil {
|
|
|
- return false, fmt.Errorf("未查询到该记录")
|
|
|
- }
|
|
|
- update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "l_updateTime": time.Now().Unix(),
|
|
|
- "i_state": ReportStateCanceled,
|
|
|
- }})
|
|
|
- if !update {
|
|
|
- log.Println("分析报告取消失败:", mae.MgoRecordId)
|
|
|
- return false, fmt.Errorf("取消失败")
|
|
|
- }
|
|
|
- // redis里面放取消标识
|
|
|
- redis.Put(ReportCacheDB, fmt.Sprintf(ReportCanceledKey, mae.MgoRecordId), 1, ReportCanceledTime)
|
|
|
- return update, nil
|
|
|
-}
|
|
|
-
|
|
|
-// UpdateOffline 更新报告是否是离线报告
|
|
|
-func (mae *MarketAnalysisEntity) UpdateOffline(offline bool) bool {
|
|
|
- set := map[string]interface{}{
|
|
|
- "i_state": qutil.If(offline, ReportStateGenerating, ReportStateGenerated),
|
|
|
- "i_offline": qutil.If(offline, ValueOffline, ValueRealTime),
|
|
|
- "l_updateTime": time.Now().Unix(),
|
|
|
- "s_mgoUserId": mae.MgoUserId, // 这里更新这些字段是因为这几个字段是p437 版本新加上的 历史数据没有这些字段
|
|
|
- "s_positionId": mae.PositionId,
|
|
|
- "s_phone": mae.Phone,
|
|
|
- }
|
|
|
- if mae.OriginalTotal > 0 {
|
|
|
- set["l_originalTotal"] = mae.OriginalTotal
|
|
|
- }
|
|
|
- data := map[string]interface{}{
|
|
|
- "$set": set,
|
|
|
- }
|
|
|
- update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, data)
|
|
|
- if !update {
|
|
|
- log.Println("UpdateOffline 更新报告状态失败:", data, mae.MgoRecordId)
|
|
|
- }
|
|
|
- return update
|
|
|
-}
|
|
|
-
|
|
|
-// UpdateState 更新报告生成状态
|
|
|
-func (mae *MarketAnalysisEntity) UpdateState(state int) bool {
|
|
|
- data := map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_state": state,
|
|
|
- "l_updateTime": time.Now().Unix(),
|
|
|
- },
|
|
|
- }
|
|
|
- update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, data)
|
|
|
- if !update {
|
|
|
- log.Println("UpdateState 更新报告生成状态失败:", data, mae.MgoRecordId)
|
|
|
- }
|
|
|
- return update
|
|
|
-}
|
|
|
-
|
|
|
-// Delete 删除正在分析中的报告
|
|
|
-func (mae *MarketAnalysisEntity) Delete() (bool, error) {
|
|
|
- // 删除报告
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "_id": mae.MgoRecordId,
|
|
|
- "i_del": map[string]interface{}{"$ne": 1},
|
|
|
- }
|
|
|
- if mae.UId == mae.Pid { //主账号
|
|
|
- queryMap["s_parentId"] = mae.Pid
|
|
|
- } else {
|
|
|
- queryMap["s_userId"] = mae.UId
|
|
|
- }
|
|
|
- //验证
|
|
|
- rs, b := db.Mgo.FindOne(ReportHistoryTable, queryMap)
|
|
|
- //
|
|
|
- if !b || rs == nil {
|
|
|
- return false, fmt.Errorf("未查询到该记录")
|
|
|
- }
|
|
|
- update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "l_updateTime": time.Now().Unix(),
|
|
|
- "i_del": 1,
|
|
|
- }})
|
|
|
- if !update {
|
|
|
- log.Println("分析报告删除失败:", mae.MgoRecordId)
|
|
|
- return false, fmt.Errorf("删除失败")
|
|
|
- }
|
|
|
- // redis里面放取消标识
|
|
|
- redis.Put(ReportCacheDB, fmt.Sprintf(ReportCanceledKey, mae.MgoRecordId), 1, ReportCanceledTime)
|
|
|
- return update, nil
|
|
|
-}
|
|
|
-func GetEntNameByIds(ids []string) (returnMap map[string]string) {
|
|
|
- returnMap = map[string]string{}
|
|
|
- if len(ids) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- list := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"_source":["_id","company_name"],"size":%d}`, strings.Join(ids, `","`), len(ids)))
|
|
|
- if list == nil || len(*list) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, item := range *list {
|
|
|
- id, _ := item["_id"].(string)
|
|
|
- name, _ := item["company_name"].(string)
|
|
|
- if id != "" && name != "" {
|
|
|
- returnMap[id] = name
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetMsgOpen 获取用户服务通知开关是否开启
|
|
|
-func GetMsgOpen(mgoUserId string, positionType int, entId, entUserId int) bool {
|
|
|
- pushSetMap := &map[string]interface{}{}
|
|
|
- if positionType == 1 {
|
|
|
- pushSetMap, _ = db.Mgo.FindOne("ent_user", map[string]interface{}{"i_entid": entId, "i_userid": entUserId})
|
|
|
- } else {
|
|
|
- pushSetMap, _ = db.Mgo.FindById("user", mgoUserId, `{"o_pushset":1,"s_m_openid":1}`)
|
|
|
- }
|
|
|
- //log.Println(mgoUserId, pushSetMap)
|
|
|
- if pushSetMap != nil && len(*pushSetMap) > 0 {
|
|
|
- pushset := qutil.ObjToMap((*pushSetMap)["o_pushset"])
|
|
|
- if pushset == nil || len(*pushset) == 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- msgServicePushSet := qutil.ObjToMap((*pushset)["o_msg_service"])
|
|
|
- if msgServicePushSet != nil {
|
|
|
- if qutil.IntAll((*msgServicePushSet)["i_apppush"]) == 1 || qutil.IntAll((*msgServicePushSet)["i_wxpush"]) == 1 {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|