|
@@ -1,62 +1,62 @@
|
|
package util
|
|
package util
|
|
|
|
|
|
import (
|
|
import (
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
|
- "bytes"
|
|
|
|
- "crypto/md5"
|
|
|
|
- "encoding/hex"
|
|
|
|
- "encoding/json"
|
|
|
|
- "fmt"
|
|
|
|
- "jy/src/jfw/modules/publicapply/src/config"
|
|
|
|
- "jy/src/jfw/modules/publicapply/src/db"
|
|
|
|
- "log"
|
|
|
|
- "net/http"
|
|
|
|
- "regexp"
|
|
|
|
- "strconv"
|
|
|
|
- "strings"
|
|
|
|
- "time"
|
|
|
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
|
+ "bytes"
|
|
|
|
+ "crypto/md5"
|
|
|
|
+ "encoding/hex"
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "fmt"
|
|
|
|
+ "jy/src/jfw/modules/publicapply/src/config"
|
|
|
|
+ "jy/src/jfw/modules/publicapply/src/db"
|
|
|
|
+ "log"
|
|
|
|
+ "net/http"
|
|
|
|
+ "regexp"
|
|
|
|
+ "strconv"
|
|
|
|
+ "strings"
|
|
|
|
+ "time"
|
|
|
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
)
|
|
)
|
|
|
|
|
|
var ClearHtml = regexp.MustCompile("<[^>]*>")
|
|
var ClearHtml = regexp.MustCompile("<[^>]*>")
|
|
var (
|
|
var (
|
|
- queryBoolShould = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
|
- queryBoolMustBoolShould = `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
|
|
|
|
- queryBase = `{"query":{"bool":{"must":[%s]}},"_source":["_id"],"from":0,"size":%d}`
|
|
|
|
- gte = `"gte": %s`
|
|
|
|
- lte = `"lte": %s`
|
|
|
|
- queryBoolMust = `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
|
|
|
|
- multiMatch = `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
|
|
- idTerms = `{"terms":{"_id":["%s"]}}`
|
|
|
|
- topTypeMap = map[string]string{
|
|
|
|
- "招标预告": "预告",
|
|
|
|
- "招标公告": "招标",
|
|
|
|
- "招标结果": "结果",
|
|
|
|
- "招标信用信息": "其它",
|
|
|
|
- "拟建项目": "拟建",
|
|
|
|
- "采购意向": "采购意向",
|
|
|
|
- }
|
|
|
|
|
|
+ queryBoolShould = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
|
+ queryBoolMustBoolShould = `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
|
|
|
|
+ queryBase = `{"query":{"bool":{"must":[%s]}},"_source":["_id"],"from":0,"size":%d}`
|
|
|
|
+ gte = `"gte": %s`
|
|
|
|
+ lte = `"lte": %s`
|
|
|
|
+ queryBoolMust = `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
|
|
|
|
+ multiMatch = `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
|
|
+ idTerms = `{"terms":{"_id":["%s"]}}`
|
|
|
|
+ topTypeMap = map[string]string{
|
|
|
|
+ "招标预告": "预告",
|
|
|
|
+ "招标公告": "招标",
|
|
|
|
+ "招标结果": "结果",
|
|
|
|
+ "招标信用信息": "其它",
|
|
|
|
+ "拟建项目": "拟建",
|
|
|
|
+ "采购意向": "采购意向",
|
|
|
|
+ }
|
|
)
|
|
)
|
|
|
|
|
|
// 加密
|
|
// 加密
|
|
func EncodeId(sid string) string {
|
|
func EncodeId(sid string) string {
|
|
- if sid == "" {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
- return encrypt.EncodeArticleId2ByCheck(sid)
|
|
|
|
|
|
+ if sid == "" {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+ return encrypt.EncodeArticleId2ByCheck(sid)
|
|
}
|
|
}
|
|
|
|
|
|
// 解密
|
|
// 解密
|
|
func DecodeId(eid string) string {
|
|
func DecodeId(eid string) string {
|
|
- if eid == "" {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
- return encrypt.CommonDecodeArticle("content", eid)[0]
|
|
|
|
|
|
+ if eid == "" {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+ return encrypt.CommonDecodeArticle("content", eid)[0]
|
|
}
|
|
}
|
|
|
|
|
|
//收藏列表
|
|
//收藏列表
|
|
@@ -68,566 +68,566 @@ func DecodeId(eid string) string {
|
|
开始时间-结束时间:1622476800-1623859200
|
|
开始时间-结束时间:1622476800-1623859200
|
|
*/
|
|
*/
|
|
type CollList struct {
|
|
type CollList struct {
|
|
- Pagenum int `json:"pagenum"` //页数
|
|
|
|
- Label string `json:"label"` //标签 用,分隔开
|
|
|
|
- SelectTime string `json:"selectTime"` //收藏时间
|
|
|
|
- Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
|
- BuyerPhone string `json:"buyerTel"` //是否需要采购单位联系方式 y:需要
|
|
|
|
- WinnerPhone string `json:"winnerTel"` //是否需要中标单位联系方式 y:需要
|
|
|
|
- Pagesize int `json:"pagesize"` //每页展示数量
|
|
|
|
- KeyWords string `json:"keyWords"` // 匹配标题正文 到es里面查
|
|
|
|
- PublishTime string `json:"publishTime"` // 发布时间 到es里面查
|
|
|
|
- TopType string `json:"topType"` // 信息类型-一级分类 到es里面查
|
|
|
|
- Subtype string `json:"subtype"` // 信息类型-二级分类 到es里面查
|
|
|
|
- Province string `json:"province"` // 项目地区_省份 到es里面查
|
|
|
|
- City string `json:"city"` // 项目地区_城市 到es里面查
|
|
|
|
- District string `json:"district"` // 项目地区_区县 到es里面查
|
|
|
|
- Price string `json:"price"` // 金额区间 到es里面查
|
|
|
|
- Industry string `json:"industry"` // 行业分类 到es里面查
|
|
|
|
|
|
+ Pagenum int `json:"pagenum"` //页数
|
|
|
|
+ Label string `json:"label"` //标签 用,分隔开
|
|
|
|
+ SelectTime string `json:"selectTime"` //收藏时间
|
|
|
|
+ Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
|
+ BuyerPhone string `json:"buyerTel"` //是否需要采购单位联系方式 y:需要
|
|
|
|
+ WinnerPhone string `json:"winnerTel"` //是否需要中标单位联系方式 y:需要
|
|
|
|
+ Pagesize int `json:"pagesize"` //每页展示数量
|
|
|
|
+ KeyWords string `json:"keyWords"` // 匹配标题正文 到es里面查
|
|
|
|
+ PublishTime string `json:"publishTime"` // 发布时间 到es里面查
|
|
|
|
+ TopType string `json:"topType"` // 信息类型-一级分类 到es里面查
|
|
|
|
+ Subtype string `json:"subtype"` // 信息类型-二级分类 到es里面查
|
|
|
|
+ Province string `json:"province"` // 项目地区_省份 到es里面查
|
|
|
|
+ City string `json:"city"` // 项目地区_城市 到es里面查
|
|
|
|
+ District string `json:"district"` // 项目地区_区县 到es里面查
|
|
|
|
+ Price string `json:"price"` // 金额区间 到es里面查
|
|
|
|
+ Industry string `json:"industry"` // 行业分类 到es里面查
|
|
}
|
|
}
|
|
|
|
|
|
// 搜藏列表-tidb 查询条件 个人标签、收藏时间、采购单位、采购单位联系方式、中标单位联系方式
|
|
// 搜藏列表-tidb 查询条件 个人标签、收藏时间、采购单位、采购单位联系方式、中标单位联系方式
|
|
func CollListSql(c *CollList, isPay bool, userid string) string {
|
|
func CollListSql(c *CollList, isPay bool, userid string) string {
|
|
- sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
|
- limit := config.BidCollConfig.FreeUserCollLimit
|
|
|
|
- //个人标签
|
|
|
|
- if c.Label != "" {
|
|
|
|
- i := 0
|
|
|
|
- sql += ` and `
|
|
|
|
- if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
|
|
|
|
- sql += `(`
|
|
|
|
- for _, v := range labelArr {
|
|
|
|
- i++
|
|
|
|
- labid := encrypt.SE.DecodeString(v)
|
|
|
|
- if i == len(labelArr) {
|
|
|
|
- sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
|
|
|
|
- } else {
|
|
|
|
- sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- sql += `)`
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- now := time.Now()
|
|
|
|
- start, end := "", ""
|
|
|
|
- //收藏时间
|
|
|
|
- if c.SelectTime == "lately-7" { //最近7天
|
|
|
|
- start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
- } else if c.SelectTime == "lately-30" { //最近30天
|
|
|
|
- start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
- } else if c.SelectTime == "thisyear" { //去年
|
|
|
|
- start = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
- end = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
- } else if len(strings.Split(c.SelectTime, "-")) == 2 {
|
|
|
|
- if c.SelectTime != "0-0" {
|
|
|
|
- starttime := strings.Split(c.SelectTime, "-")[0]
|
|
|
|
- startstamp, _ := strconv.Atoi(starttime)
|
|
|
|
- start = time.Unix(int64(startstamp), 0).Format(Date_Full_Layout)
|
|
|
|
- endtime := strings.Split(c.SelectTime, "-")[1]
|
|
|
|
- et, _ := strconv.ParseInt(endtime, 0, 64)
|
|
|
|
- etTime := time.Unix(et, 0)
|
|
|
|
- end = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if start != "" && end != "" {
|
|
|
|
- sql += ` and createdate >= '` + start + `' and createdate < '` + end + `'`
|
|
|
|
- } else if start != "" && end == "" {
|
|
|
|
- sql += ` and createdate >= '` + start + `'`
|
|
|
|
- } else if start == "" && end != "" {
|
|
|
|
- sql += ` and createdate < '` + end + `'`
|
|
|
|
- }
|
|
|
|
- if isPay {
|
|
|
|
|
|
+ sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
|
+ limit := config.BidCollConfig.FreeUserCollLimit
|
|
|
|
+ //个人标签
|
|
|
|
+ if c.Label != "" {
|
|
|
|
+ i := 0
|
|
|
|
+ sql += ` and `
|
|
|
|
+ if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
|
|
|
|
+ sql += `(`
|
|
|
|
+ for _, v := range labelArr {
|
|
|
|
+ i++
|
|
|
|
+ labid := encrypt.SE.DecodeString(v)
|
|
|
|
+ if i == len(labelArr) {
|
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
|
|
|
|
+ } else {
|
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sql += `)`
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ now := time.Now()
|
|
|
|
+ start, end := "", ""
|
|
|
|
+ //收藏时间
|
|
|
|
+ if c.SelectTime == "lately-7" { //最近7天
|
|
|
|
+ start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
+ } else if c.SelectTime == "lately-30" { //最近30天
|
|
|
|
+ start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
+ } else if c.SelectTime == "thisyear" { //去年
|
|
|
|
+ start = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
+ end = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
+ } else if len(strings.Split(c.SelectTime, "-")) == 2 {
|
|
|
|
+ if c.SelectTime != "0-0" {
|
|
|
|
+ starttime := strings.Split(c.SelectTime, "-")[0]
|
|
|
|
+ startstamp, _ := strconv.Atoi(starttime)
|
|
|
|
+ start = time.Unix(int64(startstamp), 0).Format(Date_Full_Layout)
|
|
|
|
+ endtime := strings.Split(c.SelectTime, "-")[1]
|
|
|
|
+ et, _ := strconv.ParseInt(endtime, 0, 64)
|
|
|
|
+ etTime := time.Unix(et, 0)
|
|
|
|
+ end = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if start != "" && end != "" {
|
|
|
|
+ sql += ` and createdate >= '` + start + `' and createdate < '` + end + `'`
|
|
|
|
+ } else if start != "" && end == "" {
|
|
|
|
+ sql += ` and createdate >= '` + start + `'`
|
|
|
|
+ } else if start == "" && end != "" {
|
|
|
|
+ sql += ` and createdate < '` + end + `'`
|
|
|
|
+ }
|
|
|
|
+ if isPay {
|
|
|
|
|
|
- //采购单位 用,分隔开
|
|
|
|
- if c.Buyerclass != "" {
|
|
|
|
- i := 0
|
|
|
|
- sql += ` and buyerclass in (`
|
|
|
|
- if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
|
|
|
|
- for _, v := range buyClassArr {
|
|
|
|
- i++
|
|
|
|
- buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
|
|
|
|
- if i == len(buyClassArr) {
|
|
|
|
- sql += buyerclassid + `)`
|
|
|
|
- } else {
|
|
|
|
- sql += buyerclassid + ","
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //是否存在采购单位电话
|
|
|
|
- if c.BuyerPhone == "y" {
|
|
|
|
- sql += ` and buyerinfo = 1`
|
|
|
|
- } //else if c.BuyerPhone == -1 {
|
|
|
|
- //sql += ` and buyerinfo = 0`
|
|
|
|
- //}
|
|
|
|
- //是否存在中标单位电话
|
|
|
|
- if c.WinnerPhone == "y" { // p480二期参数调整
|
|
|
|
- sql += ` and winnerinfo = 1`
|
|
|
|
- } // else if c.WinnerPhone == -1 {
|
|
|
|
- // sql += ` and winnerinfo = 0`
|
|
|
|
- //}
|
|
|
|
- limit = config.BidCollConfig.PayUserCollLimit
|
|
|
|
- }
|
|
|
|
- sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
|
- return sql
|
|
|
|
|
|
+ //采购单位 用,分隔开
|
|
|
|
+ if c.Buyerclass != "" {
|
|
|
|
+ i := 0
|
|
|
|
+ sql += ` and buyerclass in (`
|
|
|
|
+ if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
|
|
|
|
+ for _, v := range buyClassArr {
|
|
|
|
+ i++
|
|
|
|
+ buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
|
|
|
|
+ if i == len(buyClassArr) {
|
|
|
|
+ sql += buyerclassid + `)`
|
|
|
|
+ } else {
|
|
|
|
+ sql += buyerclassid + ","
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //是否存在采购单位电话
|
|
|
|
+ if c.BuyerPhone == "y" {
|
|
|
|
+ sql += ` and buyerinfo = 1`
|
|
|
|
+ } //else if c.BuyerPhone == -1 {
|
|
|
|
+ //sql += ` and buyerinfo = 0`
|
|
|
|
+ //}
|
|
|
|
+ //是否存在中标单位电话
|
|
|
|
+ if c.WinnerPhone == "y" { // p480二期参数调整
|
|
|
|
+ sql += ` and winnerinfo = 1`
|
|
|
|
+ } // else if c.WinnerPhone == -1 {
|
|
|
|
+ // sql += ` and winnerinfo = 0`
|
|
|
|
+ //}
|
|
|
|
+ limit = config.BidCollConfig.PayUserCollLimit
|
|
|
|
+ }
|
|
|
|
+ sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
|
+ return sql
|
|
}
|
|
}
|
|
|
|
|
|
// CollListESQuery 收藏列表es查询条件 匹配标题正 发布时间 信息类型 项目地区 金额区间
|
|
// CollListESQuery 收藏列表es查询条件 匹配标题正 发布时间 信息类型 项目地区 金额区间
|
|
func CollListESQuery(c *CollList, idmapList []map[string]interface{}) (qstr string, idList []string, keyMustStr string) {
|
|
func CollListESQuery(c *CollList, idmapList []map[string]interface{}) (qstr string, idList []string, keyMustStr string) {
|
|
- m := map[string]struct{}{}
|
|
|
|
- musts := []string{}
|
|
|
|
- for _, v := range idmapList {
|
|
|
|
- if _, ok := m[qutil.ObjToString(v["bid"])]; ok {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- m[qutil.ObjToString(v["bid"])] = struct{}{}
|
|
|
|
- idList = append(idList, qutil.ObjToString(v["bid"]))
|
|
|
|
- }
|
|
|
|
- musts = append(musts, fmt.Sprintf(idTerms, strings.Join(idList, `","`)))
|
|
|
|
- query := ``
|
|
|
|
- //省份
|
|
|
|
- area := c.Province
|
|
|
|
- if area != "" {
|
|
|
|
- query += `{"terms":{"area":[`
|
|
|
|
- for k, v := range strings.Split(area, ",") {
|
|
|
|
- if k > 0 {
|
|
|
|
- query += `,`
|
|
|
|
- }
|
|
|
|
- query += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- query += `]}}`
|
|
|
|
- }
|
|
|
|
- //市--
|
|
|
|
- city := c.City
|
|
|
|
- if city != "" {
|
|
|
|
- if len(query) > 0 {
|
|
|
|
- query += ","
|
|
|
|
- }
|
|
|
|
- query += `{"terms":{"city":[`
|
|
|
|
- for k, v := range strings.Split(city, ",") {
|
|
|
|
- if k > 0 {
|
|
|
|
- query += `,`
|
|
|
|
- }
|
|
|
|
- query += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- query += `]}}`
|
|
|
|
- }
|
|
|
|
- district := c.District
|
|
|
|
- if district != "" {
|
|
|
|
- if len(query) > 0 {
|
|
|
|
- query += ","
|
|
|
|
- }
|
|
|
|
- for k, v := range strings.Split(district, ",") {
|
|
|
|
- if k > 0 {
|
|
|
|
- query += `,`
|
|
|
|
- }
|
|
|
|
- cityName := strings.Split(v, "_")[0]
|
|
|
|
- districtName := strings.Split(v, "_")[1]
|
|
|
|
- queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
|
|
|
|
- query += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
|
|
|
|
- }
|
|
|
|
|
|
+ m := map[string]struct{}{}
|
|
|
|
+ musts := []string{}
|
|
|
|
+ for _, v := range idmapList {
|
|
|
|
+ if _, ok := m[qutil.ObjToString(v["bid"])]; ok {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ m[qutil.ObjToString(v["bid"])] = struct{}{}
|
|
|
|
+ idList = append(idList, qutil.ObjToString(v["bid"]))
|
|
|
|
+ }
|
|
|
|
+ musts = append(musts, fmt.Sprintf(idTerms, strings.Join(idList, `","`)))
|
|
|
|
+ query := ``
|
|
|
|
+ //省份
|
|
|
|
+ area := c.Province
|
|
|
|
+ if area != "" {
|
|
|
|
+ query += `{"terms":{"area":[`
|
|
|
|
+ for k, v := range strings.Split(area, ",") {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ query += `,`
|
|
|
|
+ }
|
|
|
|
+ query += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ query += `]}}`
|
|
|
|
+ }
|
|
|
|
+ //市--
|
|
|
|
+ city := c.City
|
|
|
|
+ if city != "" {
|
|
|
|
+ if len(query) > 0 {
|
|
|
|
+ query += ","
|
|
|
|
+ }
|
|
|
|
+ query += `{"terms":{"city":[`
|
|
|
|
+ for k, v := range strings.Split(city, ",") {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ query += `,`
|
|
|
|
+ }
|
|
|
|
+ query += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ query += `]}}`
|
|
|
|
+ }
|
|
|
|
+ district := c.District
|
|
|
|
+ if district != "" {
|
|
|
|
+ if len(query) > 0 {
|
|
|
|
+ query += ","
|
|
|
|
+ }
|
|
|
|
+ for k, v := range strings.Split(district, ",") {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ query += `,`
|
|
|
|
+ }
|
|
|
|
+ cityName := strings.Split(v, "_")[0]
|
|
|
|
+ districtName := strings.Split(v, "_")[1]
|
|
|
|
+ queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
|
|
|
|
+ query += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
- if query != "" {
|
|
|
|
- query = fmt.Sprintf(queryBoolShould, query)
|
|
|
|
- }
|
|
|
|
- //发布时间
|
|
|
|
- publishTime := c.PublishTime
|
|
|
|
- if publishTime != "" {
|
|
|
|
- startTime, endTime := "", ""
|
|
|
|
- now := time.Now()
|
|
|
|
- switch publishTime {
|
|
|
|
- case "lately-7":
|
|
|
|
- startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
- case "lately-30":
|
|
|
|
- startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
- case "thisyear":
|
|
|
|
- startTime = fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
- endTime = fmt.Sprint(now.Unix())
|
|
|
|
- case "threeyear":
|
|
|
|
- startTime = fmt.Sprint(time.Date(now.Year()-3, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
- endTime = fmt.Sprint(now.Unix())
|
|
|
|
- case "fiveyear":
|
|
|
|
- startTime = fmt.Sprint(time.Date(now.Year()-5, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
- endTime = fmt.Sprint(now.Unix())
|
|
|
|
- default:
|
|
|
|
- if len(strings.Split(publishTime, "-")) > 1 {
|
|
|
|
- startTime = strings.Split(publishTime, "-")[0]
|
|
|
|
- endTime = strings.Split(publishTime, "-")[1]
|
|
|
|
- //电脑端 时间选择 开始时间当天和结束时间当天相同
|
|
|
|
- if startTime == endTime {
|
|
|
|
- et, _ := strconv.ParseInt(endTime, 0, 64)
|
|
|
|
- etTime := time.Unix(et, 0)
|
|
|
|
- endTime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if startTime != "" || endTime != "" {
|
|
|
|
- if len(query) > 0 {
|
|
|
|
- query += ","
|
|
|
|
- }
|
|
|
|
- query += `{"range":{"publishtime":{`
|
|
|
|
- if startTime != "" {
|
|
|
|
- query += `"gte":` + startTime
|
|
|
|
- }
|
|
|
|
- if startTime != "" && endTime != "" {
|
|
|
|
- query += `,`
|
|
|
|
- }
|
|
|
|
- if endTime != "" {
|
|
|
|
- query += `"lt":` + endTime
|
|
|
|
- }
|
|
|
|
- query += `}}}`
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //信息类型-二级
|
|
|
|
- subtype := c.Subtype
|
|
|
|
- topType := qutil.If(c.TopType != "", strings.Split(c.TopType, ","), []string{}).([]string)
|
|
|
|
- allType := ``
|
|
|
|
- //二级分类
|
|
|
|
- if subtype != "" {
|
|
|
|
- var typeInt = 0
|
|
|
|
- allType += `{"terms":{"subtype":[`
|
|
|
|
- for k, v := range strings.Split(subtype, ",") {
|
|
|
|
- if tType := qutil.If(topTypeMap[v] != "" && c.TopType == "", topTypeMap[v], "").(string); tType != "" {
|
|
|
|
- topType = append(topType, tType)
|
|
|
|
- typeInt += 1
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- if k > typeInt {
|
|
|
|
- allType += `,`
|
|
|
|
- }
|
|
|
|
- allType += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- allType += `]}}`
|
|
|
|
- if typeInt == len(strings.Split(subtype, ",")) {
|
|
|
|
- allType = ``
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //信息类型 一级分类
|
|
|
|
- log.Println("topType:", topType)
|
|
|
|
- if len(topType) > 0 {
|
|
|
|
- if allType != "" {
|
|
|
|
- allType += ","
|
|
|
|
- }
|
|
|
|
- allType += `{"terms":{"toptype":[`
|
|
|
|
- for k, v := range topType {
|
|
|
|
- if k > 0 {
|
|
|
|
- allType += `,`
|
|
|
|
- }
|
|
|
|
- allType += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- allType += `]}}`
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ if query != "" {
|
|
|
|
+ query = fmt.Sprintf(queryBoolShould, query)
|
|
|
|
+ }
|
|
|
|
+ //发布时间
|
|
|
|
+ publishTime := c.PublishTime
|
|
|
|
+ if publishTime != "" {
|
|
|
|
+ startTime, endTime := "", ""
|
|
|
|
+ now := time.Now()
|
|
|
|
+ switch publishTime {
|
|
|
|
+ case "lately-7":
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
+ case "lately-30":
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
+ case "thisyear":
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
+ endTime = fmt.Sprint(now.Unix())
|
|
|
|
+ case "threeyear":
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year()-3, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
+ endTime = fmt.Sprint(now.Unix())
|
|
|
|
+ case "fiveyear":
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year()-5, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
+ endTime = fmt.Sprint(now.Unix())
|
|
|
|
+ default:
|
|
|
|
+ if len(strings.Split(publishTime, "-")) > 1 {
|
|
|
|
+ startTime = strings.Split(publishTime, "-")[0]
|
|
|
|
+ endTime = strings.Split(publishTime, "-")[1]
|
|
|
|
+ //电脑端 时间选择 开始时间当天和结束时间当天相同
|
|
|
|
+ if startTime == endTime {
|
|
|
|
+ et, _ := strconv.ParseInt(endTime, 0, 64)
|
|
|
|
+ etTime := time.Unix(et, 0)
|
|
|
|
+ endTime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if startTime != "" || endTime != "" {
|
|
|
|
+ if len(query) > 0 {
|
|
|
|
+ query += ","
|
|
|
|
+ }
|
|
|
|
+ query += `{"range":{"publishtime":{`
|
|
|
|
+ if startTime != "" {
|
|
|
|
+ query += `"gte":` + startTime
|
|
|
|
+ }
|
|
|
|
+ if startTime != "" && endTime != "" {
|
|
|
|
+ query += `,`
|
|
|
|
+ }
|
|
|
|
+ if endTime != "" {
|
|
|
|
+ query += `"lt":` + endTime
|
|
|
|
+ }
|
|
|
|
+ query += `}}}`
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //信息类型-二级
|
|
|
|
+ subtype := c.Subtype
|
|
|
|
+ topType := qutil.If(c.TopType != "", strings.Split(c.TopType, ","), []string{}).([]string)
|
|
|
|
+ allType := ``
|
|
|
|
+ //二级分类
|
|
|
|
+ if subtype != "" {
|
|
|
|
+ var typeInt = 0
|
|
|
|
+ allType += `{"terms":{"subtype":[`
|
|
|
|
+ for k, v := range strings.Split(subtype, ",") {
|
|
|
|
+ if tType := qutil.If(topTypeMap[v] != "" && c.TopType == "", topTypeMap[v], "").(string); tType != "" {
|
|
|
|
+ topType = append(topType, tType)
|
|
|
|
+ typeInt += 1
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if k > typeInt {
|
|
|
|
+ allType += `,`
|
|
|
|
+ }
|
|
|
|
+ allType += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ allType += `]}}`
|
|
|
|
+ if typeInt == len(strings.Split(subtype, ",")) {
|
|
|
|
+ allType = ``
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //信息类型 一级分类
|
|
|
|
+ log.Println("topType:", topType)
|
|
|
|
+ if len(topType) > 0 {
|
|
|
|
+ if allType != "" {
|
|
|
|
+ allType += ","
|
|
|
|
+ }
|
|
|
|
+ allType += `{"terms":{"toptype":[`
|
|
|
|
+ for k, v := range topType {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ allType += `,`
|
|
|
|
+ }
|
|
|
|
+ allType += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ allType += `]}}`
|
|
|
|
+ }
|
|
|
|
|
|
- if allType != "" {
|
|
|
|
- if query != "" {
|
|
|
|
- query += ","
|
|
|
|
- }
|
|
|
|
- query += fmt.Sprintf(queryBoolShould, allType)
|
|
|
|
- }
|
|
|
|
- if query != "" {
|
|
|
|
- musts = append(musts, query)
|
|
|
|
- }
|
|
|
|
- if c.KeyWords != "" {
|
|
|
|
- var (
|
|
|
|
- keyWordsMusts, wordsMusts []string
|
|
|
|
- )
|
|
|
|
- for _, v := range strings.Split(c.KeyWords, " ") {
|
|
|
|
- if elastic.ReplaceYH(v) == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- keyWordsMusts = append(keyWordsMusts, fmt.Sprintf(fmt.Sprintf(multiMatch, "%s", `"title","detail"`), elastic.ReplaceYH(v)))
|
|
|
|
- }
|
|
|
|
- //包含所有
|
|
|
|
- wordsMusts = append(wordsMusts, keyWordsMusts...)
|
|
|
|
- if len(wordsMusts) > 0 {
|
|
|
|
- keyMustStr = fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ","))
|
|
|
|
- musts = append(musts, keyMustStr)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //行业
|
|
|
|
- if c.Industry != "" {
|
|
|
|
- musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(c.Industry, ",", `","`)+`"`))
|
|
|
|
- }
|
|
|
|
- //价格
|
|
|
|
- if c.Price != "" && len(strings.Split(c.Price, "-")) > 1 {
|
|
|
|
- minPrice, maxPrice := strings.Split(c.Price, "-")[0], strings.Split(c.Price, "-")[1]
|
|
|
|
- if minPrice != "" || maxPrice != "" {
|
|
|
|
- sq := ``
|
|
|
|
- if minPrice != "" {
|
|
|
|
- min, _ := strconv.ParseFloat(minPrice, 64)
|
|
|
|
- minPrice = fmt.Sprintf("%.0f", min*10000)
|
|
|
|
- if minPrice == "0" {
|
|
|
|
- minPrice = ""
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if maxPrice != "" {
|
|
|
|
- max, _ := strconv.ParseFloat(maxPrice, 64)
|
|
|
|
- maxPrice = fmt.Sprintf("%.0f", max*10000)
|
|
|
|
- if maxPrice == "0" {
|
|
|
|
- maxPrice = ""
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if minPrice != "" {
|
|
|
|
- sq += fmt.Sprintf(gte, minPrice)
|
|
|
|
- }
|
|
|
|
- if minPrice != "" && maxPrice != "" {
|
|
|
|
- sq += `,`
|
|
|
|
- }
|
|
|
|
- if maxPrice != "" {
|
|
|
|
- sq += fmt.Sprintf(lte, maxPrice)
|
|
|
|
- }
|
|
|
|
- if minPrice != "" || maxPrice != "" {
|
|
|
|
- query_price := fmt.Sprintf(queryBoolShould, fmt.Sprintf(queryBoolMustBoolShould, sq, sq))
|
|
|
|
- musts = append(musts, query_price)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- qstr = fmt.Sprintf(queryBase, strings.Join(musts, ","), len(idList))
|
|
|
|
- log.Println("qstr:", qstr)
|
|
|
|
- return
|
|
|
|
|
|
+ if allType != "" {
|
|
|
|
+ if query != "" {
|
|
|
|
+ query += ","
|
|
|
|
+ }
|
|
|
|
+ query += fmt.Sprintf(queryBoolShould, allType)
|
|
|
|
+ }
|
|
|
|
+ if query != "" {
|
|
|
|
+ musts = append(musts, query)
|
|
|
|
+ }
|
|
|
|
+ if c.KeyWords != "" {
|
|
|
|
+ var (
|
|
|
|
+ keyWordsMusts, wordsMusts []string
|
|
|
|
+ )
|
|
|
|
+ for _, v := range strings.Split(c.KeyWords, " ") {
|
|
|
|
+ if elastic.ReplaceYH(v) == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ keyWordsMusts = append(keyWordsMusts, fmt.Sprintf(fmt.Sprintf(multiMatch, "%s", `"title","detail"`), elastic.ReplaceYH(v)))
|
|
|
|
+ }
|
|
|
|
+ //包含所有
|
|
|
|
+ wordsMusts = append(wordsMusts, keyWordsMusts...)
|
|
|
|
+ if len(wordsMusts) > 0 {
|
|
|
|
+ keyMustStr = fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ","))
|
|
|
|
+ musts = append(musts, keyMustStr)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //行业
|
|
|
|
+ if c.Industry != "" {
|
|
|
|
+ musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(c.Industry, ",", `","`)+`"`))
|
|
|
|
+ }
|
|
|
|
+ //价格
|
|
|
|
+ if c.Price != "" && len(strings.Split(c.Price, "-")) > 1 {
|
|
|
|
+ minPrice, maxPrice := strings.Split(c.Price, "-")[0], strings.Split(c.Price, "-")[1]
|
|
|
|
+ if minPrice != "" || maxPrice != "" {
|
|
|
|
+ sq := ``
|
|
|
|
+ if minPrice != "" {
|
|
|
|
+ min, _ := strconv.ParseFloat(minPrice, 64)
|
|
|
|
+ minPrice = fmt.Sprintf("%.0f", min*10000)
|
|
|
|
+ if minPrice == "0" {
|
|
|
|
+ minPrice = ""
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if maxPrice != "" {
|
|
|
|
+ max, _ := strconv.ParseFloat(maxPrice, 64)
|
|
|
|
+ maxPrice = fmt.Sprintf("%.0f", max*10000)
|
|
|
|
+ if maxPrice == "0" {
|
|
|
|
+ maxPrice = ""
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if minPrice != "" {
|
|
|
|
+ sq += fmt.Sprintf(gte, minPrice)
|
|
|
|
+ }
|
|
|
|
+ if minPrice != "" && maxPrice != "" {
|
|
|
|
+ sq += `,`
|
|
|
|
+ }
|
|
|
|
+ if maxPrice != "" {
|
|
|
|
+ sq += fmt.Sprintf(lte, maxPrice)
|
|
|
|
+ }
|
|
|
|
+ if minPrice != "" || maxPrice != "" {
|
|
|
|
+ query_price := fmt.Sprintf(queryBoolShould, fmt.Sprintf(queryBoolMustBoolShould, sq, sq))
|
|
|
|
+ musts = append(musts, query_price)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ qstr = fmt.Sprintf(queryBase, strings.Join(musts, ","), len(idList))
|
|
|
|
+ log.Println("qstr:", qstr)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// es里面的筛选条件再过滤一次id
|
|
// es里面的筛选条件再过滤一次id
|
|
func GetEsCollListId(esQuery string, idList []string) (ids []map[string]interface{}) {
|
|
func GetEsCollListId(esQuery string, idList []string) (ids []map[string]interface{}) {
|
|
- //idList 是为了最后处理有序
|
|
|
|
- // 查询
|
|
|
|
- rs := elastic.Get("bidding", "bidding", esQuery)
|
|
|
|
- if rs == nil {
|
|
|
|
- log.Println("未获取到数据")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- idMap := map[string]struct{}{}
|
|
|
|
- if rs != nil {
|
|
|
|
- for _, v := range *rs {
|
|
|
|
- _id := qutil.ObjToString(v["_id"])
|
|
|
|
- if _, ok := idMap[_id]; !ok {
|
|
|
|
- idMap[_id] = struct{}{}
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //idList 是为了最后处理有序
|
|
|
|
+ // 查询
|
|
|
|
+ rs := elastic.Get("bidding", "bidding", esQuery)
|
|
|
|
+ if rs == nil {
|
|
|
|
+ log.Println("未获取到数据")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ idMap := map[string]struct{}{}
|
|
|
|
+ if rs != nil {
|
|
|
|
+ for _, v := range *rs {
|
|
|
|
+ _id := qutil.ObjToString(v["_id"])
|
|
|
|
+ if _, ok := idMap[_id]; !ok {
|
|
|
|
+ idMap[_id] = struct{}{}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // 获取有序数组
|
|
|
|
- for i := 0; i < len(idList); i++ {
|
|
|
|
- if _, ok := idMap[idList[i]]; ok {
|
|
|
|
- ids = append(ids, map[string]interface{}{
|
|
|
|
- "bid": idList[i],
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ // 获取有序数组
|
|
|
|
+ for i := 0; i < len(idList); i++ {
|
|
|
|
+ if _, ok := idMap[idList[i]]; ok {
|
|
|
|
+ ids = append(ids, map[string]interface{}{
|
|
|
|
+ "bid": idList[i],
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
func ConfirmIntArr(arr []interface{}) []int {
|
|
func ConfirmIntArr(arr []interface{}) []int {
|
|
- tmp := make([]int, 0)
|
|
|
|
- for _, v := range arr {
|
|
|
|
- tmp = append(tmp, qutil.IntAll(v))
|
|
|
|
- }
|
|
|
|
- return tmp
|
|
|
|
|
|
+ tmp := make([]int, 0)
|
|
|
|
+ for _, v := range arr {
|
|
|
|
+ tmp = append(tmp, qutil.IntAll(v))
|
|
|
|
+ }
|
|
|
|
+ return tmp
|
|
}
|
|
}
|
|
|
|
|
|
// 判断同一个数组是否重复
|
|
// 判断同一个数组是否重复
|
|
func IsRepeat(slice1 []string) bool {
|
|
func IsRepeat(slice1 []string) bool {
|
|
- m := make(map[string]int)
|
|
|
|
- for _, v := range slice1 {
|
|
|
|
- m[v]++
|
|
|
|
- if m[v] > 1 {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false
|
|
|
|
|
|
+ m := make(map[string]int)
|
|
|
|
+ for _, v := range slice1 {
|
|
|
|
+ m[v]++
|
|
|
|
+ if m[v] > 1 {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
|
|
|
|
// 判断数组是否包含
|
|
// 判断数组是否包含
|
|
func IsContain(slice []string, s string) bool {
|
|
func IsContain(slice []string, s string) bool {
|
|
- for _, qq := range slice {
|
|
|
|
- if qq == s {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false
|
|
|
|
|
|
+ for _, qq := range slice {
|
|
|
|
+ if qq == s {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
|
|
|
|
// jsonStr转map
|
|
// jsonStr转map
|
|
func JsonToMap(jsonStr string) (map[string]interface{}, error) {
|
|
func JsonToMap(jsonStr string) (map[string]interface{}, error) {
|
|
- m := map[string]interface{}{}
|
|
|
|
- err := json.Unmarshal([]byte(jsonStr), &m)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Printf("Unmarshal with error: %+v\n", err)
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
- return m, nil
|
|
|
|
|
|
+ m := map[string]interface{}{}
|
|
|
|
+ err := json.Unmarshal([]byte(jsonStr), &m)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Printf("Unmarshal with error: %+v\n", err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return m, nil
|
|
}
|
|
}
|
|
|
|
|
|
// 判断stringArr相等方法
|
|
// 判断stringArr相等方法
|
|
func StringArrEqual(a, b []string) bool {
|
|
func StringArrEqual(a, b []string) bool {
|
|
- if (len(a) == 0) != (len(b) == 0) {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- if len(a) != len(b) {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- for i := range a {
|
|
|
|
- if a[i] != b[i] {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true
|
|
|
|
|
|
+ if (len(a) == 0) != (len(b) == 0) {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ if len(a) != len(b) {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ for i := range a {
|
|
|
|
+ if a[i] != b[i] {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
|
|
|
|
// 获取频次信息:fre="周-1"(每周周一);"天-3":每三天一个周期;"日-3":每天三点;
|
|
// 获取频次信息:fre="周-1"(每周周一);"天-3":每三天一个周期;"日-3":每天三点;
|
|
func GetFrequencyInfo(fre string) (string, bool, int) {
|
|
func GetFrequencyInfo(fre string) (string, bool, int) {
|
|
- if fre != "" && len(strings.Split(fre, "-")) > 1 {
|
|
|
|
- f := strings.Split(fre, "-")[0]
|
|
|
|
- d, _ := strconv.Atoi(strings.Split(fre, "-")[1])
|
|
|
|
- switch f {
|
|
|
|
- case "月":
|
|
|
|
- day := time.Now().Day()
|
|
|
|
- return fmt.Sprintf("nps_%s", time.Now().Month().String()), day == d, 31 * 24 * 60 * 60
|
|
|
|
- case "周":
|
|
|
|
- mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
|
- return fmt.Sprintf("nps_%s", WeekByDate(time.Now())), mi == d, 7 * 24 * 60 * 60
|
|
|
|
- case "日":
|
|
|
|
- day := time.Now().Day()
|
|
|
|
- hour := time.Now().Hour()
|
|
|
|
- return fmt.Sprintf("nps_%s", strconv.Itoa(day)), hour == d, 24 * 60 * 60
|
|
|
|
- case "天":
|
|
|
|
- return func(d int) (string, bool, int) {
|
|
|
|
- //周末不显示
|
|
|
|
- mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
|
- now := time.Now()
|
|
|
|
- isWeekday := mi < d
|
|
|
|
- expireTime := 0
|
|
|
|
- if isWeekday {
|
|
|
|
- expireTime = int(time.Date(now.Year(), now.Month(), now.Day()+d-mi, 0, 0, 0, 0, now.Location()).Unix() - now.Unix())
|
|
|
|
- }
|
|
|
|
- return fmt.Sprintf("nps_%d", d), isWeekday, expireTime
|
|
|
|
- }(d)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return "", false, 0
|
|
|
|
|
|
+ if fre != "" && len(strings.Split(fre, "-")) > 1 {
|
|
|
|
+ f := strings.Split(fre, "-")[0]
|
|
|
|
+ d, _ := strconv.Atoi(strings.Split(fre, "-")[1])
|
|
|
|
+ switch f {
|
|
|
|
+ case "月":
|
|
|
|
+ day := time.Now().Day()
|
|
|
|
+ return fmt.Sprintf("nps_%s", time.Now().Month().String()), day == d, 31 * 24 * 60 * 60
|
|
|
|
+ case "周":
|
|
|
|
+ mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
|
+ return fmt.Sprintf("nps_%s", WeekByDate(time.Now())), mi == d, 7 * 24 * 60 * 60
|
|
|
|
+ case "日":
|
|
|
|
+ day := time.Now().Day()
|
|
|
|
+ hour := time.Now().Hour()
|
|
|
|
+ return fmt.Sprintf("nps_%s", strconv.Itoa(day)), hour == d, 24 * 60 * 60
|
|
|
|
+ case "天":
|
|
|
|
+ return func(d int) (string, bool, int) {
|
|
|
|
+ //周末不显示
|
|
|
|
+ mi := ConvertWeekday(time.Now().Weekday().String())
|
|
|
|
+ now := time.Now()
|
|
|
|
+ isWeekday := mi < d
|
|
|
|
+ expireTime := 0
|
|
|
|
+ if isWeekday {
|
|
|
|
+ expireTime = int(time.Date(now.Year(), now.Month(), now.Day()+d-mi, 0, 0, 0, 0, now.Location()).Unix() - now.Unix())
|
|
|
|
+ }
|
|
|
|
+ return fmt.Sprintf("nps_%d", d), isWeekday, expireTime
|
|
|
|
+ }(d)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return "", false, 0
|
|
}
|
|
}
|
|
|
|
|
|
// 获取当年第几周
|
|
// 获取当年第几周
|
|
func WeekByDate(t time.Time) string {
|
|
func WeekByDate(t time.Time) string {
|
|
- yearDay := t.YearDay()
|
|
|
|
- yearFirstDay := t.AddDate(0, 0, -yearDay+1)
|
|
|
|
- firstDayInWeek := int(yearFirstDay.Weekday())
|
|
|
|
|
|
+ yearDay := t.YearDay()
|
|
|
|
+ yearFirstDay := t.AddDate(0, 0, -yearDay+1)
|
|
|
|
+ firstDayInWeek := int(yearFirstDay.Weekday())
|
|
|
|
|
|
- //今年第一周有几天
|
|
|
|
- firstWeekDays := 1
|
|
|
|
- if firstDayInWeek != 0 {
|
|
|
|
- firstWeekDays = 7 - firstDayInWeek + 1
|
|
|
|
- }
|
|
|
|
- var week int
|
|
|
|
- if yearDay <= firstWeekDays {
|
|
|
|
- week = 1
|
|
|
|
- } else {
|
|
|
|
- week = (yearDay-firstWeekDays)/7 + 2
|
|
|
|
- }
|
|
|
|
- return fmt.Sprintf("%d-%d", t.Year(), week)
|
|
|
|
|
|
+ //今年第一周有几天
|
|
|
|
+ firstWeekDays := 1
|
|
|
|
+ if firstDayInWeek != 0 {
|
|
|
|
+ firstWeekDays = 7 - firstDayInWeek + 1
|
|
|
|
+ }
|
|
|
|
+ var week int
|
|
|
|
+ if yearDay <= firstWeekDays {
|
|
|
|
+ week = 1
|
|
|
|
+ } else {
|
|
|
|
+ week = (yearDay-firstWeekDays)/7 + 2
|
|
|
|
+ }
|
|
|
|
+ return fmt.Sprintf("%d-%d", t.Year(), week)
|
|
}
|
|
}
|
|
|
|
|
|
func ConvertWeekday(weekday string) int {
|
|
func ConvertWeekday(weekday string) int {
|
|
- _weekday := 0
|
|
|
|
- if weekday == "Sunday" {
|
|
|
|
- _weekday = 7
|
|
|
|
- } else if weekday == "Monday" {
|
|
|
|
- _weekday = 1
|
|
|
|
- } else if weekday == "Tuesday" {
|
|
|
|
- _weekday = 2
|
|
|
|
- } else if weekday == "Wednesday" {
|
|
|
|
- _weekday = 3
|
|
|
|
- } else if weekday == "Thursday" {
|
|
|
|
- _weekday = 4
|
|
|
|
- } else if weekday == "Friday" {
|
|
|
|
- _weekday = 5
|
|
|
|
- } else if weekday == "Saturday" {
|
|
|
|
- _weekday = 6
|
|
|
|
- }
|
|
|
|
- return _weekday
|
|
|
|
|
|
+ _weekday := 0
|
|
|
|
+ if weekday == "Sunday" {
|
|
|
|
+ _weekday = 7
|
|
|
|
+ } else if weekday == "Monday" {
|
|
|
|
+ _weekday = 1
|
|
|
|
+ } else if weekday == "Tuesday" {
|
|
|
|
+ _weekday = 2
|
|
|
|
+ } else if weekday == "Wednesday" {
|
|
|
|
+ _weekday = 3
|
|
|
|
+ } else if weekday == "Thursday" {
|
|
|
|
+ _weekday = 4
|
|
|
|
+ } else if weekday == "Friday" {
|
|
|
|
+ _weekday = 5
|
|
|
|
+ } else if weekday == "Saturday" {
|
|
|
|
+ _weekday = 6
|
|
|
|
+ }
|
|
|
|
+ return _weekday
|
|
}
|
|
}
|
|
|
|
|
|
// map转结构体
|
|
// map转结构体
|
|
func JsonUnmarshal(m interface{}, s interface{}) interface{} {
|
|
func JsonUnmarshal(m interface{}, s interface{}) interface{} {
|
|
- var b []byte
|
|
|
|
- if v, ok := m.(string); ok {
|
|
|
|
- b = []byte(v)
|
|
|
|
- } else if v, ok := m.([]byte); ok {
|
|
|
|
- b = v
|
|
|
|
- } else {
|
|
|
|
- b, _ = json.Marshal(m)
|
|
|
|
- }
|
|
|
|
- json.Unmarshal(b, &s)
|
|
|
|
- return s
|
|
|
|
|
|
+ var b []byte
|
|
|
|
+ if v, ok := m.(string); ok {
|
|
|
|
+ b = []byte(v)
|
|
|
|
+ } else if v, ok := m.([]byte); ok {
|
|
|
|
+ b = v
|
|
|
|
+ } else {
|
|
|
|
+ b, _ = json.Marshal(m)
|
|
|
|
+ }
|
|
|
|
+ json.Unmarshal(b, &s)
|
|
|
|
+ return s
|
|
}
|
|
}
|
|
|
|
|
|
// 获取当天剩余时间
|
|
// 获取当天剩余时间
|
|
var (
|
|
var (
|
|
- timeOut int64 = 24 * 60 * 60
|
|
|
|
|
|
+ timeOut int64 = 24 * 60 * 60
|
|
)
|
|
)
|
|
|
|
|
|
func GetLastTime() int64 {
|
|
func GetLastTime() int64 {
|
|
- t := time.Now()
|
|
|
|
- midnight := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
|
|
|
|
- if midnight.After(t) {
|
|
|
|
- return midnight.Unix() - t.Unix()
|
|
|
|
- }
|
|
|
|
- return timeOut
|
|
|
|
|
|
+ t := time.Now()
|
|
|
|
+ midnight := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
|
|
|
|
+ if midnight.After(t) {
|
|
|
|
+ return midnight.Unix() - t.Unix()
|
|
|
|
+ }
|
|
|
|
+ return timeOut
|
|
}
|
|
}
|
|
|
|
|
|
func GetMD5(data string) string {
|
|
func GetMD5(data string) string {
|
|
- hash := md5.Sum([]byte(data))
|
|
|
|
- encryptedData := hex.EncodeToString(hash[:])
|
|
|
|
- return encryptedData
|
|
|
|
|
|
+ hash := md5.Sum([]byte(data))
|
|
|
|
+ encryptedData := hex.EncodeToString(hash[:])
|
|
|
|
+ return encryptedData
|
|
}
|
|
}
|
|
|
|
|
|
// 创建订单号
|
|
// 创建订单号
|
|
func GetOrderCode() string {
|
|
func GetOrderCode() string {
|
|
- return <-jy.VarOrderCode.Pool
|
|
|
|
|
|
+ return <-jy.VarOrderCode.Pool
|
|
}
|
|
}
|
|
|
|
|
|
// ClearCookie 清楚前端cookie 缓存
|
|
// ClearCookie 清楚前端cookie 缓存
|
|
func ClearCookie(w http.ResponseWriter, name string) {
|
|
func ClearCookie(w http.ResponseWriter, name string) {
|
|
- if name == "" {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- for _, nk := range strings.Split(name, ",") {
|
|
|
|
- if nk != "" {
|
|
|
|
- http.SetCookie(w, &http.Cookie{
|
|
|
|
- Name: nk,
|
|
|
|
- Value: "",
|
|
|
|
- Path: "/",
|
|
|
|
- HttpOnly: false,
|
|
|
|
- MaxAge: -1,
|
|
|
|
- Expires: time.Now().Add(-1),
|
|
|
|
- Domain: httpsession.Domain,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if name == "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, nk := range strings.Split(name, ",") {
|
|
|
|
+ if nk != "" {
|
|
|
|
+ http.SetCookie(w, &http.Cookie{
|
|
|
|
+ Name: nk,
|
|
|
|
+ Value: "",
|
|
|
|
+ Path: "/",
|
|
|
|
+ HttpOnly: false,
|
|
|
|
+ MaxAge: -1,
|
|
|
|
+ Expires: time.Now().Add(-1),
|
|
|
|
+ Domain: httpsession.Domain,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func SendBot(webhookURL, msg string) (b bool) {
|
|
func SendBot(webhookURL, msg string) (b bool) {
|
|
- // 构造请求体
|
|
|
|
- payload := map[string]interface{}{
|
|
|
|
- "msgtype": "text",
|
|
|
|
- "text": map[string]string{
|
|
|
|
- "content": msg,
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- // 转换为 JSON 字符串
|
|
|
|
- payloadBytes, err := json.Marshal(payload)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Println("Error :", err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- // 发送 POST 请求
|
|
|
|
- resp, err := http.Post(webhookURL, "application/json", bytes.NewReader(payloadBytes))
|
|
|
|
- if err != nil {
|
|
|
|
- log.Println("Error :", err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- defer resp.Body.Close()
|
|
|
|
- b = true
|
|
|
|
- return
|
|
|
|
|
|
+ // 构造请求体
|
|
|
|
+ payload := map[string]interface{}{
|
|
|
|
+ "msgtype": "text",
|
|
|
|
+ "text": map[string]string{
|
|
|
|
+ "content": msg,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ // 转换为 JSON 字符串
|
|
|
|
+ payloadBytes, err := json.Marshal(payload)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("Error :", err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // 发送 POST 请求
|
|
|
|
+ resp, err := http.Post(webhookURL, "application/json", bytes.NewReader(payloadBytes))
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("Error :", err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer resp.Body.Close()
|
|
|
|
+ b = true
|
|
|
|
+ return
|
|
}
|
|
}
|