|
@@ -8,26 +8,26 @@
|
|
|
package analysis
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- . "jy/src/jfw/modules/bigmember/src/config"
|
|
|
- "jy/src/jfw/modules/bigmember/src/db"
|
|
|
- "jy/src/jfw/modules/bigmember/src/entity"
|
|
|
- "jy/src/jfw/modules/bigmember/src/util"
|
|
|
- "log"
|
|
|
- "regexp"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "sync"
|
|
|
- "time"
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ . "jy/src/jfw/modules/bigmember/src/config"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/db"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/entity"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/util"
|
|
|
+ "log"
|
|
|
+ "regexp"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "sync"
|
|
|
+ "time"
|
|
|
|
|
|
- . "app.yhyue.com/moapp/jybase/api"
|
|
|
- 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/jybase/api"
|
|
|
+ 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"
|
|
|
)
|
|
|
|
|
|
var redis_forecast_status = "forecast_status_" //预测状态
|
|
@@ -36,526 +36,526 @@ var redis_forecast_date = "forecast_date_" //预测时间
|
|
|
var forecast_time = 300 //超过五分钟 预测失败 清记录
|
|
|
var reg = regexp.MustCompile("^[0-9]+.*$")
|
|
|
|
|
|
-//中标预测-项目信息当前是否已完成招标
|
|
|
+// 中标预测-项目信息当前是否已完成招标
|
|
|
func (this *Analysis) BdInfoStatus() {
|
|
|
- defer qutil.Catch()
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- rData, errMsg := func() (interface{}, error) {
|
|
|
- pid := this.GetString("pid") //项目信息id
|
|
|
- sid := this.GetString("sid") //招标信息id
|
|
|
- var pids, sids []string
|
|
|
- var isBool = false
|
|
|
- if pid != "" {
|
|
|
- pids = encrypt.DecodeArticleId2ByCheck(pid)
|
|
|
- isBool = true
|
|
|
- }
|
|
|
- if sid != "" {
|
|
|
- sids = encrypt.DecodeArticleId2ByCheck(sid)
|
|
|
- isBool = true
|
|
|
- }
|
|
|
- if !isBool {
|
|
|
- return nil, errors.New("项目信息id或招标信息id不能同时为空")
|
|
|
- }
|
|
|
- //log.Println("pids:", pids, "--sids:", sids)
|
|
|
- var res = entity.GetProInfoById(pids, sids)
|
|
|
- if res == nil || len(res) == 0 {
|
|
|
- return nil, errors.New("未查询到此项目")
|
|
|
- }
|
|
|
- bidstatus := qutil.ObjToString(res[0]["bidstatus"])
|
|
|
- if strings.Contains(bidstatus, "中标") || strings.Contains(bidstatus, "成交") || strings.Contains(bidstatus, "废标") || strings.Contains(bidstatus, "流标") {
|
|
|
- return 1, nil
|
|
|
- }
|
|
|
- return 0, nil
|
|
|
- }()
|
|
|
- if errMsg != nil {
|
|
|
- log.Printf("%s 获取此项目状态出错-%s", userId, errMsg)
|
|
|
- }
|
|
|
- this.ServeJson(NewResult(rData, errMsg))
|
|
|
+ defer qutil.Catch()
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
+ pid := this.GetString("pid") //项目信息id
|
|
|
+ sid := this.GetString("sid") //招标信息id
|
|
|
+ var pids, sids []string
|
|
|
+ var isBool = false
|
|
|
+ if pid != "" {
|
|
|
+ pids = encrypt.DecodeArticleId2ByCheck(pid)
|
|
|
+ isBool = true
|
|
|
+ }
|
|
|
+ if sid != "" {
|
|
|
+ sids = encrypt.DecodeArticleId2ByCheck(sid)
|
|
|
+ isBool = true
|
|
|
+ }
|
|
|
+ if !isBool {
|
|
|
+ return nil, errors.New("项目信息id或招标信息id不能同时为空")
|
|
|
+ }
|
|
|
+ //log.Println("pids:", pids, "--sids:", sids)
|
|
|
+ var res = entity.GetProInfoById(pids, sids)
|
|
|
+ if res == nil || len(res) == 0 {
|
|
|
+ return nil, errors.New("未查询到此项目")
|
|
|
+ }
|
|
|
+ bidstatus := qutil.ObjToString(res[0]["bidstatus"])
|
|
|
+ if strings.Contains(bidstatus, "中标") || strings.Contains(bidstatus, "成交") || strings.Contains(bidstatus, "废标") || strings.Contains(bidstatus, "流标") {
|
|
|
+ return 1, nil
|
|
|
+ }
|
|
|
+ return 0, nil
|
|
|
+ }()
|
|
|
+ if errMsg != nil {
|
|
|
+ log.Printf("%s 获取此项目状态出错-%s", userId, errMsg)
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult(rData, errMsg))
|
|
|
}
|
|
|
|
|
|
-//中标预测超时处理
|
|
|
+// 中标预测超时处理
|
|
|
func (this *Analysis) FWOvertime() {
|
|
|
- defer qutil.Catch()
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- //中标信息预测结束
|
|
|
- go ClearRedisInfo(userId)
|
|
|
+ defer qutil.Catch()
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ //中标信息预测结束
|
|
|
+ go ClearRedisInfo(userId)
|
|
|
}
|
|
|
|
|
|
-//预测数据
|
|
|
+// 预测数据
|
|
|
func (this *Analysis) FWData() {
|
|
|
- defer qutil.Catch()
|
|
|
- var regMap = Result{
|
|
|
- Data: []map[string]interface{}{},
|
|
|
- Error_code: Error_code,
|
|
|
- Error_msg: "",
|
|
|
- }
|
|
|
- if this.Method() == METHOD {
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- //有正在预测的数据或已预测未查看的数据
|
|
|
- success, id := isExistsFIng(userId)
|
|
|
- status := 0
|
|
|
- if success {
|
|
|
- if success && id != "" {
|
|
|
- status = 1 //success=true; id!="" ---未查看的预测数据
|
|
|
- } else if success && id == "" {
|
|
|
- status = 2 //success=true; id="" ---正在预测
|
|
|
- }
|
|
|
- var getRes map[string]interface{}
|
|
|
- if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
- log.Println("redis 1获取预测参数有误-", userId)
|
|
|
- }
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "status": status,
|
|
|
- "id": id,
|
|
|
- "pname": getRes["pname"],
|
|
|
- }
|
|
|
- } else {
|
|
|
- if string(this.Body()) != "" {
|
|
|
- //success=false; id="" ---没有正在预测 也没有未查看的预测数据
|
|
|
- //接受参数 调rpc 预测中标数据
|
|
|
- getRes := new(util.ForecastS)
|
|
|
- //接收参数
|
|
|
- json.Unmarshal(this.Body(), &getRes)
|
|
|
- if getRes.Type == "" && getRes.Id != "" {
|
|
|
- //是否是子账号
|
|
|
- var s_phone, _ = this.GetSession("s_phone").(string)
|
|
|
- if s_phone == "" {
|
|
|
- s_phone, _ = this.GetSession("s_m_phone").(string)
|
|
|
- }
|
|
|
- main_userId, phone, member_status := util.MainUserId(this.Session())
|
|
|
- entity.UIL.Lock()
|
|
|
- if entity.UIL.ForWLock[main_userId] == nil {
|
|
|
- entity.UIL.ForWLock[main_userId] = &sync.Mutex{}
|
|
|
- }
|
|
|
- entity.UIL.Unlock()
|
|
|
- entity.UIL.ForWLock[main_userId].Lock()
|
|
|
- defer entity.UIL.ForWLock[main_userId].Unlock()
|
|
|
- // log.Println(getRes.ServiceId, "----------", phone)
|
|
|
- //判断是否有中标预测权限
|
|
|
- var currentCount = 0
|
|
|
- getRes.ServiceId = 15
|
|
|
- ai, base64Key, currentCount := AnalysisPower("W", main_userId, getRes.Pname, getRes.Infoid, getRes.ServiceId)
|
|
|
- // log.Println("ai:", ai)
|
|
|
- if ai > 0 {
|
|
|
- log.Println(main_userId, "---ai:", ai)
|
|
|
- if ai == 2 {
|
|
|
- // 订阅及搜索优化版本dev4.3.4调整为预测成功后才扣次数
|
|
|
- // UpdatePower(main_userId, getRes.ServiceId) //更新sql库权限次数
|
|
|
- redis.Put("newother", "jyPredictedDeduction_"+main_userId, base64Key, 3*24*60*60) //是否需要扣除次数 默认存3天
|
|
|
- }
|
|
|
+ defer qutil.Catch()
|
|
|
+ var regMap = Result{
|
|
|
+ Data: []map[string]interface{}{},
|
|
|
+ Error_code: Error_code,
|
|
|
+ Error_msg: "",
|
|
|
+ }
|
|
|
+ if this.Method() == METHOD {
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ //有正在预测的数据或已预测未查看的数据
|
|
|
+ success, id := isExistsFIng(userId)
|
|
|
+ status := 0
|
|
|
+ if success {
|
|
|
+ if success && id != "" {
|
|
|
+ status = 1 //success=true; id!="" ---未查看的预测数据
|
|
|
+ } else if success && id == "" {
|
|
|
+ status = 2 //success=true; id="" ---正在预测
|
|
|
+ }
|
|
|
+ var getRes map[string]interface{}
|
|
|
+ if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
+ log.Println("redis 1获取预测参数有误-", userId)
|
|
|
+ }
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "status": status,
|
|
|
+ "id": id,
|
|
|
+ "pname": getRes["pname"],
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if string(this.Body()) != "" {
|
|
|
+ //success=false; id="" ---没有正在预测 也没有未查看的预测数据
|
|
|
+ //接受参数 调rpc 预测中标数据
|
|
|
+ getRes := new(util.ForecastS)
|
|
|
+ //接收参数
|
|
|
+ json.Unmarshal(this.Body(), &getRes)
|
|
|
+ if getRes.Type == "" && getRes.Id != "" {
|
|
|
+ //是否是子账号
|
|
|
+ var s_phone, _ = this.GetSession("s_phone").(string)
|
|
|
+ if s_phone == "" {
|
|
|
+ s_phone, _ = this.GetSession("s_m_phone").(string)
|
|
|
+ }
|
|
|
+ main_userId, phone, member_status := util.MainUserId(this.Session())
|
|
|
+ entity.UIL.Lock()
|
|
|
+ if entity.UIL.ForWLock[main_userId] == nil {
|
|
|
+ entity.UIL.ForWLock[main_userId] = &sync.Mutex{}
|
|
|
+ }
|
|
|
+ entity.UIL.Unlock()
|
|
|
+ entity.UIL.ForWLock[main_userId].Lock()
|
|
|
+ defer entity.UIL.ForWLock[main_userId].Unlock()
|
|
|
+ // log.Println(getRes.ServiceId, "----------", phone)
|
|
|
+ //判断是否有中标预测权限
|
|
|
+ var currentCount = 0
|
|
|
+ getRes.ServiceId = 15
|
|
|
+ ai, base64Key, currentCount := AnalysisPower("W", main_userId, getRes.Pname, getRes.Infoid, getRes.ServiceId)
|
|
|
+ // log.Println("ai:", ai)
|
|
|
+ if ai > 0 {
|
|
|
+ log.Println(main_userId, "---ai:", ai)
|
|
|
+ if ai == 2 {
|
|
|
+ // 订阅及搜索优化版本dev4.3.4调整为预测成功后才扣次数
|
|
|
+ // UpdatePower(main_userId, getRes.ServiceId) //更新sql库权限次数
|
|
|
+ redis.Put("newother", "jyPredictedDeduction_"+main_userId, base64Key, 3*24*60*60) //是否需要扣除次数 默认存3天
|
|
|
+ }
|
|
|
|
|
|
- //中标预测是否有缓存dev4.3.4-王山(项目名称+地区+城市+采购单位+标的物) 默认缓存保留一天
|
|
|
- redisKeys := GetRedisBase64Key(getRes.Pname, getRes.Area, getRes.City, getRes.Buyer, getRes.BuyerContent)
|
|
|
- if forecstId := redis.GetStr("newother", "jyPredicted_"+redisKeys); forecstId != "" {
|
|
|
- if f_id := db.Mgo.Save(C_ForecastData, map[string]interface{}{
|
|
|
- "userId": userId,
|
|
|
- "createtime": time.Now().Unix(),
|
|
|
- "status": 1, //预测完成待查看
|
|
|
- "requestData": getRes,
|
|
|
- "cacheId": forecstId,
|
|
|
- "upeatetime": time.Now().Unix(),
|
|
|
- }); f_id != "" {
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "status": 3, //缓存数据
|
|
|
- "id": util.EncodeId(forecstId),
|
|
|
- "pname": getRes.Pname,
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "status": -4, //缓存数据保存异常
|
|
|
- "pname": getRes.Pname,
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 项目信息加密key缓存5+分钟 - 预测成功后提供 项目加密key 把结果id存入redis缓存中时间默认一天
|
|
|
- redis.Put("newother", "jyPredicted_five_"+main_userId, redisKeys, forecast_time+20)
|
|
|
- getRes.RedisFKey = redis_forecast_res + userId
|
|
|
- getRes.Id = util.DecodeId(getRes.Id)
|
|
|
- if getRes.Infoid != "" {
|
|
|
- getRes.Infoid = util.DecodeId(getRes.Infoid)
|
|
|
- }
|
|
|
- //中标预测数据处理ing
|
|
|
- if util.JyForecastByRpc(getRes) {
|
|
|
- //redis 存正在预测标识
|
|
|
- redis.Put("other", redis_forecast_status+userId, getRes, -1)
|
|
|
- //预测参数--保存mongodb中
|
|
|
- f_id := db.Mgo.Save(C_ForecastData, map[string]interface{}{
|
|
|
- "userId": userId,
|
|
|
- "createtime": time.Now().Unix(),
|
|
|
- "status": -1, //预测完成待查看
|
|
|
- "requestData": getRes,
|
|
|
- "upeatetime": time.Now().Unix(),
|
|
|
- })
|
|
|
- if f_id != "" {
|
|
|
- redis.Put("other", redis_forecast_date+userId, f_id, forecast_time)
|
|
|
- }
|
|
|
- status = 2 //rpc 已接受参数 正在预测
|
|
|
- } else {
|
|
|
- status = -1
|
|
|
- s_nickname, _ := this.GetSession("s_nickname").(string)
|
|
|
- if s_nickname == "" {
|
|
|
- s_nickname, _ = this.GetSession("app_name").(string)
|
|
|
- }
|
|
|
- go SaveFalseLogAndSendMail(userId, "rpc 接口调用出错", "", s_nickname, *getRes)
|
|
|
- }
|
|
|
- //保存中标预测记录
|
|
|
- go SaveFWHistorys(status, userId, main_userId, base64Key, phone, currentCount, this.Request, getRes, ai)
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "status": status,
|
|
|
- "pname": getRes.Pname,
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if member_status == 4 {
|
|
|
- status = -3 //是否是试用用户
|
|
|
- } else {
|
|
|
- status = -2 //账号权限已经用完
|
|
|
- if main_userId != userId {
|
|
|
- status = -21 //子账号权限
|
|
|
- }
|
|
|
- }
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "status": status,
|
|
|
- "pname": getRes.Pname,
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1002
|
|
|
- regMap.Error_msg = Error_msg_1002
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1005
|
|
|
- regMap.Error_msg = Error_msg_1005
|
|
|
- }
|
|
|
- this.ServeJson(regMap)
|
|
|
+ //中标预测是否有缓存dev4.3.4-王山(项目名称+地区+城市+采购单位+标的物) 默认缓存保留一天
|
|
|
+ redisKeys := GetRedisBase64Key(getRes.Pname, getRes.Area, getRes.City, getRes.Buyer, getRes.BuyerContent)
|
|
|
+ if forecstId := redis.GetStr("newother", "jyPredicted_"+redisKeys); forecstId != "" {
|
|
|
+ if f_id := db.Mgo.Save(C_ForecastData, map[string]interface{}{
|
|
|
+ "userId": userId,
|
|
|
+ "createtime": time.Now().Unix(),
|
|
|
+ "status": 1, //预测完成待查看
|
|
|
+ "requestData": getRes,
|
|
|
+ "cacheId": forecstId,
|
|
|
+ "upeatetime": time.Now().Unix(),
|
|
|
+ }); f_id != "" {
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "status": 3, //缓存数据
|
|
|
+ "id": util.EncodeId(forecstId),
|
|
|
+ "pname": getRes.Pname,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "status": -4, //缓存数据保存异常
|
|
|
+ "pname": getRes.Pname,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 项目信息加密key缓存5+分钟 - 预测成功后提供 项目加密key 把结果id存入redis缓存中时间默认一天
|
|
|
+ redis.Put("newother", "jyPredicted_five_"+main_userId, redisKeys, forecast_time+20)
|
|
|
+ getRes.RedisFKey = redis_forecast_res + userId
|
|
|
+ getRes.Id = util.DecodeId(getRes.Id)
|
|
|
+ if getRes.Infoid != "" {
|
|
|
+ getRes.Infoid = util.DecodeId(getRes.Infoid)
|
|
|
+ }
|
|
|
+ //中标预测数据处理ing
|
|
|
+ if util.JyForecastByRpc(getRes) {
|
|
|
+ //redis 存正在预测标识
|
|
|
+ redis.Put("other", redis_forecast_status+userId, getRes, -1)
|
|
|
+ //预测参数--保存mongodb中
|
|
|
+ f_id := db.Mgo.Save(C_ForecastData, map[string]interface{}{
|
|
|
+ "userId": userId,
|
|
|
+ "createtime": time.Now().Unix(),
|
|
|
+ "status": -1, //预测完成待查看
|
|
|
+ "requestData": getRes,
|
|
|
+ "upeatetime": time.Now().Unix(),
|
|
|
+ })
|
|
|
+ if f_id != "" {
|
|
|
+ redis.Put("other", redis_forecast_date+userId, f_id, forecast_time)
|
|
|
+ }
|
|
|
+ status = 2 //rpc 已接受参数 正在预测
|
|
|
+ } else {
|
|
|
+ status = -1
|
|
|
+ s_nickname, _ := this.GetSession("s_nickname").(string)
|
|
|
+ if s_nickname == "" {
|
|
|
+ s_nickname, _ = this.GetSession("app_name").(string)
|
|
|
+ }
|
|
|
+ go SaveFalseLogAndSendMail(userId, "rpc 接口调用出错", "", s_nickname, *getRes)
|
|
|
+ }
|
|
|
+ //保存中标预测记录
|
|
|
+ go SaveFWHistorys(status, userId, main_userId, base64Key, phone, currentCount, this.Request, getRes, ai)
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "status": status,
|
|
|
+ "pname": getRes.Pname,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if member_status == 4 {
|
|
|
+ status = -3 //是否是试用用户
|
|
|
+ } else {
|
|
|
+ status = -2 //账号权限已经用完
|
|
|
+ if main_userId != userId {
|
|
|
+ status = -21 //子账号权限
|
|
|
+ }
|
|
|
+ }
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "status": status,
|
|
|
+ "pname": getRes.Pname,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1002
|
|
|
+ regMap.Error_msg = Error_msg_1002
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1005
|
|
|
+ regMap.Error_msg = Error_msg_1005
|
|
|
+ }
|
|
|
+ this.ServeJson(regMap)
|
|
|
}
|
|
|
|
|
|
-//是否有正在预测或已预测未查看的信息
|
|
|
+// 是否有正在预测或已预测未查看的信息
|
|
|
func isExistsFIng(userId string) (success bool, id string) {
|
|
|
- rfsExist, _ := redis.Exists("other", redis_forecast_status+userId)
|
|
|
- rfrExist, _ := redis.Exists("other", redis_forecast_res+userId)
|
|
|
- rfdExist, _ := redis.Exists("other", redis_forecast_date+userId)
|
|
|
- // log.Println(rfsExist, "--------", rfrExist)
|
|
|
- //五分钟之内 有预测数据 或正在预测。。。。
|
|
|
- if rfdExist && (rfsExist || (rfsExist && rfrExist)) {
|
|
|
- success = true
|
|
|
- } else {
|
|
|
- //有预测过但是没查看的信息
|
|
|
- list, ok := db.Mgo.Find(C_ForecastData, map[string]interface{}{
|
|
|
- "userId": userId,
|
|
|
- "status": 0,
|
|
|
- }, `{"createtime":-1}`, `{"requestData":1,"responseData":1}`, false, -1, -1)
|
|
|
- if ok && list != nil && len(*list) > 0 {
|
|
|
- r := qutil.ObjToMap((*list)[0])
|
|
|
- id = util.EncodeId(BsonIdToSId((*r)["_id"]))
|
|
|
- success = true
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
+ rfsExist, _ := redis.Exists("other", redis_forecast_status+userId)
|
|
|
+ rfrExist, _ := redis.Exists("other", redis_forecast_res+userId)
|
|
|
+ rfdExist, _ := redis.Exists("other", redis_forecast_date+userId)
|
|
|
+ // log.Println(rfsExist, "--------", rfrExist)
|
|
|
+ //五分钟之内 有预测数据 或正在预测。。。。
|
|
|
+ if rfdExist && (rfsExist || (rfsExist && rfrExist)) {
|
|
|
+ success = true
|
|
|
+ } else {
|
|
|
+ //有预测过但是没查看的信息
|
|
|
+ list, ok := db.Mgo.Find(C_ForecastData, map[string]interface{}{
|
|
|
+ "userId": userId,
|
|
|
+ "status": 0,
|
|
|
+ }, `{"createtime":-1}`, `{"requestData":1,"responseData":1}`, false, -1, -1)
|
|
|
+ if ok && list != nil && len(*list) > 0 {
|
|
|
+ r := qutil.ObjToMap((*list)[0])
|
|
|
+ id = util.EncodeId(BsonIdToSId((*r)["_id"]))
|
|
|
+ success = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
type EntInfo struct {
|
|
|
- EntName string `json:"entName"` //企业名称
|
|
|
- Score float64 `json:"score"` //中标概率
|
|
|
- Weight float64 `json:"weight"` //权重
|
|
|
- DateStr string `json:"dateStr"` //establish_date 成立日期
|
|
|
- Phone string `json:"phone"` //company_phone 联系方式
|
|
|
- Area string `json:"area"` //company_area 地区
|
|
|
- City string `json:"city"` //company_city 城市
|
|
|
- Capital float64 `json:"capital"` //capital 注册资本
|
|
|
- Employee_no string `json:"employee_no"` //employee_no 员工人数
|
|
|
- Id string `json:"id"`
|
|
|
+ EntName string `json:"entName"` //企业名称
|
|
|
+ Score float64 `json:"score"` //中标概率
|
|
|
+ Weight float64 `json:"weight"` //权重
|
|
|
+ DateStr string `json:"dateStr"` //establish_date 成立日期
|
|
|
+ Phone string `json:"phone"` //company_phone 联系方式
|
|
|
+ Area string `json:"area"` //company_area 地区
|
|
|
+ City string `json:"city"` //company_city 城市
|
|
|
+ Capital float64 `json:"capital"` //capital 注册资本
|
|
|
+ Employee_no string `json:"employee_no"` //employee_no 员工人数
|
|
|
+ Id string `json:"id"`
|
|
|
}
|
|
|
|
|
|
-//前端每5秒查一次 预测是否完成
|
|
|
+// 前端每5秒查一次 预测是否完成
|
|
|
func (this *Analysis) FWStatus() {
|
|
|
- defer qutil.Catch()
|
|
|
- var regMap = Result{
|
|
|
- Data: []map[string]interface{}{},
|
|
|
- Error_code: Error_code,
|
|
|
- Error_msg: "",
|
|
|
- }
|
|
|
- if this.Method() == METHOD {
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- if userId != "" {
|
|
|
- //父级userid
|
|
|
- // userid := util.MainUserId(userId)
|
|
|
- main_userId, _, _ := util.MainUserId(this.Session())
|
|
|
- rfrExist, _ := redis.Exists("other", redis_forecast_res+userId)
|
|
|
- f_id := redis.GetStr("other", redis_forecast_date+userId)
|
|
|
- var isFFalse = 0 //是否预测失败
|
|
|
- var falseMsg = "" //预测失败备注
|
|
|
- // log.Println("---1--", rfrExist)
|
|
|
- if rfrExist && f_id != "" {
|
|
|
- var resp = []*EntInfo{}
|
|
|
- f_res := redis.Get("other", redis_forecast_res+userId)
|
|
|
- if f_res != nil && f_res.(string) != "" {
|
|
|
- json.Unmarshal([]byte(f_res.(string)), &resp)
|
|
|
- //获取数据为空
|
|
|
- if resp != nil && len(resp) > 0 {
|
|
|
- //rpc 返回预测数据只有企业名称和中标概率 还需要查询企业得成立日期 注册资本 员工人数 地区 城市 联系电话 企业信用库id
|
|
|
- handleData := handleResp(resp)
|
|
|
- //结果更新mongodb中
|
|
|
- if db.Mgo.UpdateById(C_ForecastData, f_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "status": 0,
|
|
|
- "responseData": handleData,
|
|
|
- "upeatetime": time.Now().Unix(),
|
|
|
- },
|
|
|
- }) {
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "id": util.EncodeId(f_id),
|
|
|
- "success": true,
|
|
|
- }
|
|
|
- // 订阅及搜索优化版本dev4.3.4调整为预测成功后才扣次数
|
|
|
- go func(userId, f_id string) {
|
|
|
- main_userId, _, _ := util.MainUserId(this.Session())
|
|
|
- if ok, _ := redis.Exists("newother", "jyPredictedDeduction_"+main_userId); ok {
|
|
|
- //扣除次数
|
|
|
- UpdatePower(main_userId, 15)
|
|
|
- redis.Del("newother", "jyPredictedDeduction_"+main_userId)
|
|
|
- }
|
|
|
- // 预测项目信息 缓存 五分钟
|
|
|
- redisKeys := redis.GetStr("newother", "jyPredicted_five_"+main_userId)
|
|
|
- if redisKeys != "" {
|
|
|
- //缓存默认一天
|
|
|
- redis.Put("newother", "jyPredicted_"+redisKeys, f_id, qutil.IntAllDef(Config.ForecastTime, 86400))
|
|
|
- }
|
|
|
- }(userId, f_id)
|
|
|
- } else {
|
|
|
- isFFalse = 1
|
|
|
- falseMsg = "中标预测二次更新状态出错"
|
|
|
- log.Println(falseMsg, " :", f_id)
|
|
|
- }
|
|
|
- } else {
|
|
|
- isFFalse = 2
|
|
|
- falseMsg = "中标预测redis序列化数据出错" + f_res.(string)
|
|
|
- log.Println(falseMsg, " :", f_id)
|
|
|
- }
|
|
|
- } else {
|
|
|
- isFFalse = 3
|
|
|
- falseMsg = "从redis获取预测数据出错" + f_res.(string)
|
|
|
- log.Println(falseMsg, " :", f_id, f_res)
|
|
|
- }
|
|
|
- //保存请求日志
|
|
|
- go func(f_id, userId, main_userId string, resp []*EntInfo) {
|
|
|
- //log.Println("--resp--", resp)
|
|
|
- var getRes map[string]interface{}
|
|
|
- if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
- log.Println("redis 获取预测参数有误-", userId)
|
|
|
- }
|
|
|
- forecastLog(userId, main_userId, f_id, getRes, resp)
|
|
|
- }(f_id, userId, main_userId, resp)
|
|
|
- } else {
|
|
|
- //预测中
|
|
|
- rfdExist, _ := redis.Exists("other", redis_forecast_date+userId)
|
|
|
- if rfdExist {
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "id": "",
|
|
|
- "success": true,
|
|
|
- }
|
|
|
- } else {
|
|
|
- isFFalse = 4
|
|
|
- falseMsg = "预测超时(五分钟)"
|
|
|
- log.Println(falseMsg, " :", userId)
|
|
|
- }
|
|
|
- }
|
|
|
- if isFFalse > 0 {
|
|
|
- if rfrExist && f_id != "" {
|
|
|
- go func() {
|
|
|
- //发送失败邮件提醒
|
|
|
- getRes := new(util.ForecastS)
|
|
|
- if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
- log.Println("redis 1获取预测参数有误-", userId)
|
|
|
- }
|
|
|
- s_nickname, _ := this.GetSession("s_nickname").(string)
|
|
|
- if s_nickname == "" {
|
|
|
- s_nickname, _ = this.GetSession("app_name").(string)
|
|
|
- }
|
|
|
- SaveFalseLogAndSendMail(userId, falseMsg, f_id, s_nickname, *getRes)
|
|
|
- }()
|
|
|
- }
|
|
|
- //预测失败 清除redis数据
|
|
|
- ClearRedisInfo(userId)
|
|
|
- regMap.Data = map[string]interface{}{
|
|
|
- "id": "",
|
|
|
- "success": false,
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1001
|
|
|
- regMap.Error_msg = Error_msg_1001
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1005
|
|
|
- regMap.Error_msg = Error_msg_1005
|
|
|
- }
|
|
|
- this.ServeJson(regMap)
|
|
|
+ defer qutil.Catch()
|
|
|
+ var regMap = Result{
|
|
|
+ Data: []map[string]interface{}{},
|
|
|
+ Error_code: Error_code,
|
|
|
+ Error_msg: "",
|
|
|
+ }
|
|
|
+ if this.Method() == METHOD {
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ if userId != "" {
|
|
|
+ //父级userid
|
|
|
+ // userid := util.MainUserId(userId)
|
|
|
+ main_userId, _, _ := util.MainUserId(this.Session())
|
|
|
+ rfrExist, _ := redis.Exists("other", redis_forecast_res+userId)
|
|
|
+ f_id := redis.GetStr("other", redis_forecast_date+userId)
|
|
|
+ var isFFalse = 0 //是否预测失败
|
|
|
+ var falseMsg = "" //预测失败备注
|
|
|
+ // log.Println("---1--", rfrExist)
|
|
|
+ if rfrExist && f_id != "" {
|
|
|
+ var resp = []*EntInfo{}
|
|
|
+ f_res := redis.Get("other", redis_forecast_res+userId)
|
|
|
+ if f_res != nil && f_res.(string) != "" {
|
|
|
+ json.Unmarshal([]byte(f_res.(string)), &resp)
|
|
|
+ //获取数据为空
|
|
|
+ if resp != nil && len(resp) > 0 {
|
|
|
+ //rpc 返回预测数据只有企业名称和中标概率 还需要查询企业得成立日期 注册资本 员工人数 地区 城市 联系电话 企业信用库id
|
|
|
+ handleData := handleResp(resp)
|
|
|
+ //结果更新mongodb中
|
|
|
+ if db.Mgo.UpdateById(C_ForecastData, f_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "status": 0,
|
|
|
+ "responseData": handleData,
|
|
|
+ "upeatetime": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ }) {
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "id": util.EncodeId(f_id),
|
|
|
+ "success": true,
|
|
|
+ }
|
|
|
+ // 订阅及搜索优化版本dev4.3.4调整为预测成功后才扣次数
|
|
|
+ go func(userId, f_id string) {
|
|
|
+ main_userId, _, _ := util.MainUserId(this.Session())
|
|
|
+ if ok, _ := redis.Exists("newother", "jyPredictedDeduction_"+main_userId); ok {
|
|
|
+ //扣除次数
|
|
|
+ UpdatePower(main_userId, 15)
|
|
|
+ redis.Del("newother", "jyPredictedDeduction_"+main_userId)
|
|
|
+ }
|
|
|
+ // 预测项目信息 缓存 五分钟
|
|
|
+ redisKeys := redis.GetStr("newother", "jyPredicted_five_"+main_userId)
|
|
|
+ if redisKeys != "" {
|
|
|
+ //缓存默认一天
|
|
|
+ redis.Put("newother", "jyPredicted_"+redisKeys, f_id, qutil.IntAllDef(Config.ForecastTime, 86400))
|
|
|
+ }
|
|
|
+ }(userId, f_id)
|
|
|
+ } else {
|
|
|
+ isFFalse = 1
|
|
|
+ falseMsg = "中标预测更新异常"
|
|
|
+ log.Println("中标预测二次更新状态出错", " :", f_id)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isFFalse = 2
|
|
|
+ falseMsg = "暂无预测结果"
|
|
|
+ log.Println("中标预测redis序列化数据出错", " :", f_id, "---", f_res.(string))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isFFalse = 3
|
|
|
+ falseMsg = "暂无预测结果-"
|
|
|
+ log.Println("从redis获取预测数据出错", f_res.(string), " :", f_id, f_res)
|
|
|
+ }
|
|
|
+ //保存请求日志
|
|
|
+ go func(f_id, userId, main_userId string, resp []*EntInfo) {
|
|
|
+ //log.Println("--resp--", resp)
|
|
|
+ var getRes map[string]interface{}
|
|
|
+ if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
+ log.Println("redis 获取预测参数有误-", userId)
|
|
|
+ }
|
|
|
+ forecastLog(userId, main_userId, f_id, getRes, resp)
|
|
|
+ }(f_id, userId, main_userId, resp)
|
|
|
+ } else {
|
|
|
+ //预测中
|
|
|
+ rfdExist, _ := redis.Exists("other", redis_forecast_date+userId)
|
|
|
+ if rfdExist {
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "id": "",
|
|
|
+ "success": true,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isFFalse = 4
|
|
|
+ falseMsg = "预测超时(五分钟)"
|
|
|
+ log.Println(falseMsg, " :", userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isFFalse > 0 {
|
|
|
+ if rfrExist && f_id != "" {
|
|
|
+ go func() {
|
|
|
+ //发送失败邮件提醒
|
|
|
+ getRes := new(util.ForecastS)
|
|
|
+ if redis.GetNewInterface("other", redis_forecast_status+userId, &getRes) != nil {
|
|
|
+ log.Println("redis 1获取预测参数有误-", userId)
|
|
|
+ }
|
|
|
+ s_nickname, _ := this.GetSession("s_nickname").(string)
|
|
|
+ if s_nickname == "" {
|
|
|
+ s_nickname, _ = this.GetSession("app_name").(string)
|
|
|
+ }
|
|
|
+ SaveFalseLogAndSendMail(userId, falseMsg, f_id, s_nickname, *getRes)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ //预测失败 清除redis数据
|
|
|
+ ClearRedisInfo(userId)
|
|
|
+ regMap.Data = map[string]interface{}{
|
|
|
+ "id": "",
|
|
|
+ "success": false,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1001
|
|
|
+ regMap.Error_msg = Error_msg_1001
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1005
|
|
|
+ regMap.Error_msg = Error_msg_1005
|
|
|
+ }
|
|
|
+ this.ServeJson(regMap)
|
|
|
|
|
|
}
|
|
|
|
|
|
-//查询中标企业名称【带曾用名检索】
|
|
|
+// 查询中标企业名称【带曾用名检索】
|
|
|
const queryFullEntName = `{"query":{"function_score":{"query":{"multi_match":{"query":"%s","type":"phrase","fields":["name","history_name"]}},"field_value_factor":{"field":"company_type_int","modifier":"reciprocal","factor":2}}},"_source":["name","history_name","company_type_int","_id"],"size":%d}`
|
|
|
|
|
|
-//数据填充
|
|
|
+// 数据填充
|
|
|
func handleResp(r []*EntInfo) []*EntInfo {
|
|
|
- if len(r) > 0 {
|
|
|
- for _, v := range r {
|
|
|
- entInfo, _ := db.Mgo_Ent.FindOne(C_FW_qyxy, `{"company_name":"`+v.EntName+`"}`)
|
|
|
- if entInfo == nil || (*entInfo)["_id"] == nil {
|
|
|
- list := elastic.Get("qyxy", "qyxy", fmt.Sprintf(queryFullEntName, v.EntName, 1))
|
|
|
- if list != nil && len(*list) > 0 {
|
|
|
- entInfo = &(*list)[0]
|
|
|
- }
|
|
|
- }
|
|
|
- if entInfo != nil {
|
|
|
- if (*entInfo)["company_area"] != nil {
|
|
|
- v.Area = qutil.ObjToString((*entInfo)["company_area"])
|
|
|
- }
|
|
|
- if (*entInfo)["company_city"] != nil {
|
|
|
- v.City = qutil.ObjToString((*entInfo)["company_city"])
|
|
|
- }
|
|
|
- if (*entInfo)["company_phone"] != nil {
|
|
|
- v.Phone = qutil.ObjToString((*entInfo)["company_phone"])
|
|
|
- }
|
|
|
- if (*entInfo)["establish_date"] != nil {
|
|
|
- v.DateStr = qutil.ObjToString((*entInfo)["establish_date"])
|
|
|
- }
|
|
|
- if (*entInfo)["capital"] != nil {
|
|
|
- v.Capital = qutil.Float64All((*entInfo)["capital"])
|
|
|
- }
|
|
|
- if (*entInfo)["_id"] != nil {
|
|
|
- v.Id = qutil.ObjToString((*entInfo)["_id"])
|
|
|
- }
|
|
|
- if (*entInfo)["annual_reports"] != nil {
|
|
|
- annual_reports := qutil.ObjArrToMapArr((*entInfo)["annual_reports"].([]interface{}))
|
|
|
- if len(annual_reports) > 0 {
|
|
|
- reportOne := annual_reports[0]
|
|
|
- if reportOne["employee_no"] != nil && qutil.ObjToString(reportOne["employee_no"]) != "" {
|
|
|
- employee_no := qutil.ObjToString(reportOne["employee_no"])
|
|
|
- if reg.MatchString(employee_no) {
|
|
|
- v.Employee_no = employee_no
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return r
|
|
|
+ if len(r) > 0 {
|
|
|
+ for _, v := range r {
|
|
|
+ entInfo, _ := db.Mgo_Ent.FindOne(C_FW_qyxy, `{"company_name":"`+v.EntName+`"}`)
|
|
|
+ if entInfo == nil || (*entInfo)["_id"] == nil {
|
|
|
+ list := elastic.Get("qyxy", "qyxy", fmt.Sprintf(queryFullEntName, v.EntName, 1))
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
+ entInfo = &(*list)[0]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if entInfo != nil {
|
|
|
+ if (*entInfo)["company_area"] != nil {
|
|
|
+ v.Area = qutil.ObjToString((*entInfo)["company_area"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["company_city"] != nil {
|
|
|
+ v.City = qutil.ObjToString((*entInfo)["company_city"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["company_phone"] != nil {
|
|
|
+ v.Phone = qutil.ObjToString((*entInfo)["company_phone"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["establish_date"] != nil {
|
|
|
+ v.DateStr = qutil.ObjToString((*entInfo)["establish_date"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["capital"] != nil {
|
|
|
+ v.Capital = qutil.Float64All((*entInfo)["capital"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["_id"] != nil {
|
|
|
+ v.Id = qutil.ObjToString((*entInfo)["_id"])
|
|
|
+ }
|
|
|
+ if (*entInfo)["annual_reports"] != nil {
|
|
|
+ annual_reports := qutil.ObjArrToMapArr((*entInfo)["annual_reports"].([]interface{}))
|
|
|
+ if len(annual_reports) > 0 {
|
|
|
+ reportOne := annual_reports[0]
|
|
|
+ if reportOne["employee_no"] != nil && qutil.ObjToString(reportOne["employee_no"]) != "" {
|
|
|
+ employee_no := qutil.ObjToString(reportOne["employee_no"])
|
|
|
+ if reg.MatchString(employee_no) {
|
|
|
+ v.Employee_no = employee_no
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return r
|
|
|
}
|
|
|
|
|
|
-//结果
|
|
|
+// 结果
|
|
|
func (this *Analysis) FWResult() {
|
|
|
- defer qutil.Catch()
|
|
|
- var regMap = Result{
|
|
|
- Data: []map[string]interface{}{},
|
|
|
- Error_code: Error_code,
|
|
|
- Error_msg: "",
|
|
|
- }
|
|
|
- if true || this.Method() == METHOD {
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- f_id := this.GetString("id")
|
|
|
- // f_id = util.EncodeId(f_id)
|
|
|
- if f_id != "" {
|
|
|
- f_id = util.DecodeId(f_id)
|
|
|
- res, ok := db.Mgo.FindById(C_ForecastData, f_id, `{"requestData":1,"responseData":1}`)
|
|
|
- if ok {
|
|
|
- if !db.Mgo.UpdateById(C_ForecastData, f_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{"status": 1}, //中标预测信息已读
|
|
|
- }) {
|
|
|
- log.Println("中标预测信息已读修改报错:", userId, time.Now().Unix())
|
|
|
- } else {
|
|
|
- if res != nil {
|
|
|
- delete((*res), "_id")
|
|
|
- requestData := *qutil.ObjToMap((*res)["requestData"])
|
|
|
- if requestData != nil && requestData["id"] != nil {
|
|
|
- abstract := *elastic.GetById(P_INDEX, P_TYPE, requestData["id"].(string))
|
|
|
- if len(abstract) > 0 {
|
|
|
- requestData["agency"] = abstract[0]["agency"]
|
|
|
- requestData["_area"] = abstract[0]["area"]
|
|
|
- requestData["_city"] = abstract[0]["city"]
|
|
|
- requestData["buyerperson"] = abstract[0]["buyerperson"]
|
|
|
- requestData["buyertel"] = abstract[0]["buyertel"]
|
|
|
- }
|
|
|
- requestData["id"] = util.EncodeId(requestData["id"].(string))
|
|
|
- requestData["infoid"] = util.EncodeId(requestData["infoid"].(string))
|
|
|
- }
|
|
|
- delete(requestData, "redisfkey")
|
|
|
- //结果
|
|
|
- responseData := qutil.ObjArrToMapArr((*res)["responseData"].([]interface{}))
|
|
|
- if responseData != nil && len(responseData) > 0 {
|
|
|
- for _, v := range responseData {
|
|
|
- rdv := *qutil.ObjToMap(v)
|
|
|
- entId := qutil.ObjToString(rdv["id"])
|
|
|
- if rdv["id"] == nil || qutil.ObjToString(rdv["id"]) == "" {
|
|
|
- entName := qutil.ObjToString(rdv["entname"])
|
|
|
- entId = entity.GetEntIdByQYXY(entName)
|
|
|
- }
|
|
|
- rdv["entId"] = util.EncodeId(entId)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- regMap.Data = res
|
|
|
- go ClearRedisInfo(userId)
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("forecast_find_err:")
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1002
|
|
|
- regMap.Error_msg = Error_msg_1002
|
|
|
- }
|
|
|
- } else {
|
|
|
- regMap.Error_code = Error_code_1005
|
|
|
- regMap.Error_msg = Error_msg_1005
|
|
|
- }
|
|
|
- this.ServeJson(regMap)
|
|
|
+ defer qutil.Catch()
|
|
|
+ var regMap = Result{
|
|
|
+ Data: []map[string]interface{}{},
|
|
|
+ Error_code: Error_code,
|
|
|
+ Error_msg: "",
|
|
|
+ }
|
|
|
+ if true || this.Method() == METHOD {
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ f_id := this.GetString("id")
|
|
|
+ // f_id = util.EncodeId(f_id)
|
|
|
+ if f_id != "" {
|
|
|
+ f_id = util.DecodeId(f_id)
|
|
|
+ res, ok := db.Mgo.FindById(C_ForecastData, f_id, `{"requestData":1,"responseData":1}`)
|
|
|
+ if ok {
|
|
|
+ if !db.Mgo.UpdateById(C_ForecastData, f_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{"status": 1}, //中标预测信息已读
|
|
|
+ }) {
|
|
|
+ log.Println("中标预测信息已读修改报错:", userId, time.Now().Unix())
|
|
|
+ } else {
|
|
|
+ if res != nil {
|
|
|
+ delete((*res), "_id")
|
|
|
+ requestData := *qutil.ObjToMap((*res)["requestData"])
|
|
|
+ if requestData != nil && requestData["id"] != nil {
|
|
|
+ abstract := *elastic.GetById(P_INDEX, P_TYPE, requestData["id"].(string))
|
|
|
+ if len(abstract) > 0 {
|
|
|
+ requestData["agency"] = abstract[0]["agency"]
|
|
|
+ requestData["_area"] = abstract[0]["area"]
|
|
|
+ requestData["_city"] = abstract[0]["city"]
|
|
|
+ requestData["buyerperson"] = abstract[0]["buyerperson"]
|
|
|
+ requestData["buyertel"] = abstract[0]["buyertel"]
|
|
|
+ }
|
|
|
+ requestData["id"] = util.EncodeId(requestData["id"].(string))
|
|
|
+ requestData["infoid"] = util.EncodeId(requestData["infoid"].(string))
|
|
|
+ }
|
|
|
+ delete(requestData, "redisfkey")
|
|
|
+ //结果
|
|
|
+ responseData := qutil.ObjArrToMapArr((*res)["responseData"].([]interface{}))
|
|
|
+ if responseData != nil && len(responseData) > 0 {
|
|
|
+ for _, v := range responseData {
|
|
|
+ rdv := *qutil.ObjToMap(v)
|
|
|
+ entId := qutil.ObjToString(rdv["id"])
|
|
|
+ if rdv["id"] == nil || qutil.ObjToString(rdv["id"]) == "" {
|
|
|
+ entName := qutil.ObjToString(rdv["entname"])
|
|
|
+ entId = entity.GetEntIdByQYXY(entName)
|
|
|
+ }
|
|
|
+ rdv["entId"] = util.EncodeId(entId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ regMap.Data = res
|
|
|
+ go ClearRedisInfo(userId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("forecast_find_err:")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1002
|
|
|
+ regMap.Error_msg = Error_msg_1002
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regMap.Error_code = Error_code_1005
|
|
|
+ regMap.Error_msg = Error_msg_1005
|
|
|
+ }
|
|
|
+ this.ServeJson(regMap)
|
|
|
}
|
|
|
|
|
|
-//预测结果日志
|
|
|
+// 预测结果日志
|
|
|
func forecastLog(userId, userid, f_id string, getRes map[string]interface{}, resp []*EntInfo) {
|
|
|
- id := db.Mgo.Save(C_ForecastLog, map[string]interface{}{
|
|
|
- "userId": userId,
|
|
|
- "f_userId": userid,
|
|
|
- "createtime": time.Now().Unix(),
|
|
|
- "f_id": f_id,
|
|
|
- "requestData": getRes,
|
|
|
- "responseData": resp,
|
|
|
- })
|
|
|
- if id == "" {
|
|
|
- log.Println("forecast-log-err:")
|
|
|
- }
|
|
|
+ id := db.Mgo.Save(C_ForecastLog, map[string]interface{}{
|
|
|
+ "userId": userId,
|
|
|
+ "f_userId": userid,
|
|
|
+ "createtime": time.Now().Unix(),
|
|
|
+ "f_id": f_id,
|
|
|
+ "requestData": getRes,
|
|
|
+ "responseData": resp,
|
|
|
+ })
|
|
|
+ if id == "" {
|
|
|
+ log.Println("forecast-log-err:")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-//中标信息预测结束
|
|
|
+// 中标信息预测结束
|
|
|
func ClearRedisInfo(userId string) {
|
|
|
- redis.Del("other", redis_forecast_res+userId)
|
|
|
- redis.Del("other", redis_forecast_status+userId)
|
|
|
- redis.Del("other", redis_forecast_date+userId)
|
|
|
+ redis.Del("other", redis_forecast_res+userId)
|
|
|
+ redis.Del("other", redis_forecast_status+userId)
|
|
|
+ redis.Del("other", redis_forecast_date+userId)
|
|
|
}
|
|
|
|
|
|
-//报错预测失败日志 并发送邮件
|
|
|
+// 报错预测失败日志 并发送邮件
|
|
|
func SaveFalseLogAndSendMail(userId, msg, f_id, nickname string, res util.ForecastS) {
|
|
|
- email := Config.WarnMailbox
|
|
|
- if len(email) > 0 {
|
|
|
- var resHtml = ``
|
|
|
- var divH2 = "420px"
|
|
|
- // log.Println("res:", res)
|
|
|
- if len(res.BuyerContent) > 0 {
|
|
|
- divH2 = "535px"
|
|
|
- resHtml = `<p>中标预测内容:<div style="margin-left: 30px;font-size: 13px;"><p style="line-height: 12px;">项目名称:"` + res.Pname + `"</p><p style="line-height: 12px;">采购内容:"` + strings.Join(res.BuyerContent, ",") + `"</p><p style="line-height: 12px;">采购单位:"` + res.Buyer + `"</p><p style="line-height: 12px;">采购预算:"` + strconv.FormatFloat(res.Budget, 'f', -1, 64) + `"</p><p style="line-height: 12px;">区域:"` + res.Area + " " + res.City + `"</p></div></p>`
|
|
|
- }
|
|
|
- content := `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body style="margin: 0;padding: 0;"><div class="Email" id="Email" style="width: 100%%;height: 100%%;display: flex;flex-direction: column;align-items: center; background: #E5E5E5;"><div class="emailmain" style="width: 1200px;height: ` + divH2 + `;border-top: 8px solid #2CB7CA;border-radius: 8px; background: #fff; margin-top: 107px; padding: 0 40px;"><div class="emailmain_top" style="height: 88px;width: 100%%; border-bottom: 1px solid #F7F7F7; display: flex;justify-content: center;align-items: center;"><img src="https://www.jianyu360.com/images/swordfish/sf_01.png" alt="" style="width: 130px;"></div><div class="emailmain_bottom" style="display: flex;flex-direction: column; align-items: center;"><p class="emailmain_text" style="margin-top: 10px;width: 960px;font-size: 16px;line-height: 24px;color: #1D1D1D;">尊敬的管理员:<br> 您好,中标预测失败信息如下:</p> <div class="download" style="margin-top: 0px;width: 100%%; height: 30px;justify-content: center;align-items: center;"><p>用户昵称:"` + nickname + `"</p><p>用户userid:"` + userId + `"</p><p>中标预测信息id:"` + f_id + `"</p><p>中标预测失败原因:"` + msg + `"</p>` + resHtml + `</div></div></div><p class="havapro"style="font-size: 14px;height: 24px;color: #686868;margin-top: 32px;">如有问题请<a href="mailto:bd@topnet.net.cn" class="click_here" id="click_here" style="color: #0987FF;cursor: pointer;text-decoration:none;">点击此处</a>,进行意见反馈</p></div></body></html>`
|
|
|
- for _, v := range email {
|
|
|
- if regexp.MustCompile("^\\d+$").MatchString(v) {
|
|
|
- continue
|
|
|
- }
|
|
|
- if !util.SendRetryMail(Config.ReTry, v, Config.WarnMbTitle, content, "", nil, GmailAuth) {
|
|
|
- log.Println("预测失败邮件发送失败")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ email := Config.WarnMailbox
|
|
|
+ if len(email) > 0 {
|
|
|
+ var resHtml = ``
|
|
|
+ var divH2 = "420px"
|
|
|
+ // log.Println("res:", res)
|
|
|
+ if len(res.BuyerContent) > 0 {
|
|
|
+ divH2 = "535px"
|
|
|
+ resHtml = `<p>中标预测内容:<div style="margin-left: 30px;font-size: 13px;"><p style="line-height: 12px;">项目名称:"` + res.Pname + `"</p><p style="line-height: 12px;">采购内容:"` + strings.Join(res.BuyerContent, ",") + `"</p><p style="line-height: 12px;">采购单位:"` + res.Buyer + `"</p><p style="line-height: 12px;">采购预算:"` + strconv.FormatFloat(res.Budget, 'f', -1, 64) + `"</p><p style="line-height: 12px;">区域:"` + res.Area + " " + res.City + `"</p></div></p>`
|
|
|
+ }
|
|
|
+ content := `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body style="margin: 0;padding: 0;"><div class="Email" id="Email" style="width: 100%%;height: 100%%;display: flex;flex-direction: column;align-items: center; background: #E5E5E5;"><div class="emailmain" style="width: 1200px;height: ` + divH2 + `;border-top: 8px solid #2CB7CA;border-radius: 8px; background: #fff; margin-top: 107px; padding: 0 40px;"><div class="emailmain_top" style="height: 88px;width: 100%%; border-bottom: 1px solid #F7F7F7; display: flex;justify-content: center;align-items: center;"><img src="https://www.jianyu360.com/images/swordfish/sf_01.png" alt="" style="width: 130px;"></div><div class="emailmain_bottom" style="display: flex;flex-direction: column; align-items: center;"><p class="emailmain_text" style="margin-top: 10px;width: 960px;font-size: 16px;line-height: 24px;color: #1D1D1D;">尊敬的管理员:<br> 您好,中标预测失败信息如下:</p> <div class="download" style="margin-top: 0px;width: 100%%; height: 30px;justify-content: center;align-items: center;"><p>用户昵称:"` + nickname + `"</p><p>用户userid:"` + userId + `"</p><p>中标预测信息id:"` + f_id + `"</p><p>中标预测失败原因:"` + msg + `"</p>` + resHtml + `</div></div></div><p class="havapro"style="font-size: 14px;height: 24px;color: #686868;margin-top: 32px;">如有问题请<a href="mailto:bd@topnet.net.cn" class="click_here" id="click_here" style="color: #0987FF;cursor: pointer;text-decoration:none;">点击此处</a>,进行意见反馈</p></div></body></html>`
|
|
|
+ for _, v := range email {
|
|
|
+ if regexp.MustCompile("^\\d+$").MatchString(v) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !util.SendRetryMail(Config.ReTry, v, Config.WarnMbTitle, content, "", nil, GmailAuth) {
|
|
|
+ log.Println("预测失败邮件发送失败")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|