Commit 3e5b2333 by mushishixian

fix conflict

parents 97fc5f98 ec807e10
......@@ -10,3 +10,4 @@ cmd.exe~
/bat/logs/
/conf/*.ini
/conf/prod
The file could not be displayed because it is too large.
[web]
port = 9001
port = 9008
mode = debug
cors_domain = http://bom.liexin.com
cors_domain = http://bom.liexin.com,http://liexin.com,http://www.liexin.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......
package main
import (
"fmt"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq"
"time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
//return errors.New("顶顶顶顶")
return nil
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(dataByte []byte) error {
fmt.Println(string(dataByte))
fmt.Println("任务处理失败了,我要进入db日志库了")
fmt.Println("任务处理失败了,发送钉钉消息通知主人")
return nil
}
func main() {
//消费者实现 下面接口即可
//type Receiver interface {
// Consumer([]byte) error
//}
print("开始")
t := &RecvPro{}
queueExchange := &rabbitmq.QueueExchange{
"szpurchase_message_tasks",
"szpurchase_message_tasks",
"szpurchase_message_tasks",
"direct",
"amqp://guest:guest@192.168.2.232:5672/",
}
print("3333434")
for{
print("")
mq := rabbitmq.New(queueExchange)
mq.RegisterReceiver(t)
err :=mq.Start()
if err != nil{
fmt.Println(err)
}
time.Sleep(time.Second)
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/ichunt2019/go-msgserver v1.0.5 // indirect
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0
......@@ -53,6 +54,7 @@ require (
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/yaml.v2 v2.3.0 // indirect
labix.org/v2/mgo v0.0.0-20140701140051-000000000287 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb
)
......
......@@ -8,12 +8,12 @@ import (
)
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "http://footstone.liexin.net")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowHeaders: []string{"x-requested-with", "Authorization", "Content-Type"},
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
......
......@@ -108,6 +108,7 @@ type DullGoodsData struct {
GoodsUrl string `json:"goods_url"`
CompanyName string `json:"-"`
ProviderName string `json:"-"`
Attrs interface{} `json:"attrs"`
}
type Attr struct {
......
......@@ -5,7 +5,6 @@ import (
"github.com/gin-gonic/gin"
"runtime"
"strconv"
"strings"
)
type Response struct {
......@@ -60,10 +59,10 @@ func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response)
} else {
referer := ctx.Request.Referer()
referer = strings.TrimRight(referer, "/")
ctx.Header("Access-Control-Allow-Origin", referer)
ctx.Header("Access-Control-Allow-Credentials", "true")
//referer := ctx.Request.Referer()
//referer = strings.TrimRight(referer, "/")
//ctx.Header("Access-Control-Allow-Origin", referer)
//ctx.Header("Access-Control-Allow-Credentials", "true")
//允许跨站访问的站点域名
//跨域请求头设置
ctx.JSON(200, response)
......
package mongo
import (
"fmt"
"gopkg.in/mgo.v2"
"search_server/pkg/config"
"strconv"
......@@ -30,8 +29,8 @@ func getconn(mongoConfig config.MongoDbDatabase) (*mgo.Session ,error){
if err != nil {
return nil ,err
}
fmt.Println("url",url)
fmt.Println("maxPoolSizeInt",maxPoolSizeInt)
//fmt.Println("url",url)
//fmt.Println("maxPoolSizeInt",maxPoolSizeInt)
session.SetPoolLimit(maxPoolSizeInt)
session.SetMode(mgo.Monotonic, true)
myDB :=session.DB(mongoConfig.Database)
......
......@@ -25,7 +25,12 @@ func GetGoodsInfo(ctx *gin.Context,goodsIds []string) (goodsList []model.ApiGood
"power[newCustomer]": isNewCustomer,
"power[member]": isMember,
}
common.PrintDebugHtml(ctx,params)
goodsList, _, err = CurlGoodsInfo(ctx,goodsIdsStr, params)
common.PrintDebugHtml(ctx,goodsList)
return
}
......
......@@ -73,6 +73,7 @@ eg:
https://ichunt.com/optimum-9987_1.html?ev=brand_12042^2660_128036||128037
class_id2=9987 page=1 ev:属性id+属性值id
doc: https://www.tapd.cn/20210831/markdown_wikis/show/#1120210831001000440
*/
func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResponse) {
qs.getQueryAttr(ctx)
......@@ -159,7 +160,7 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
}
A.Set("aggs",aggs)
results.Data = aggs
results.Data = A
return
}
......@@ -184,7 +185,24 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
}
common.PrintDebugHtml(ctx,esResult)
goodsIds := GetGoodsIdsByEs(esResult)
goodsIds := make([]string,0) //goods_id
attrs := make(map[string][]map[string]string) //属性
gjArray := gjson.Get(esResult, "hits.hits.#._source").Array()
for _, item := range gjArray {
goods_id := item.Get("goods_id").String()
goodsIds = append(goodsIds, goods_id)
temp := make([]map[string]string,0)
for _,attr := range item.Get("attrs").Array() {
temp = append(temp, map[string]string{
"attr_name":attr.Get("attr_name").String(),
"attr_value":attr.Get("attr_value").String(),
})
}
attrs[goods_id] = temp
}
//判断返回总条数
total := gjson.Get(esResult, "hits.total").Int()
if total == 0 {
......@@ -197,9 +215,9 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
A := orderedmap.New() //初始化有序map,拼接data 数据
results.ErrorCode = 0;
results.ErrorMsg = "查询成功";
page := PageClear(ctx,10,total);
page := PageClear(ctx,total);
page["took"] = gjson.Get(esResult, "took").Int()
A.Set("page_data",page) //分页信息
A.Set("page",page) //分页信息
//aggs := orderedmap.New() //拼接aggs
common.PrintDebugHtml(ctx,goodsIds)
......@@ -228,6 +246,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
ApiGoods:v,
GoodsUrl: GoodsUrl,
BrandUrl: BrandUrl,
Attrs: attrs[v.GoodsId],
})
}
......@@ -237,39 +256,29 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
}
//處理分頁信息
func PageClear(ctx *gin.Context,pagesize int64,hitsTotal int64) map[string]interface{}{
totalPage := math.Ceil(float64(hitsTotal)/float64(pagesize))
var (
total int64
offsetInt int
err error
)
func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
page_size := ctx.Request.FormValue("page_size")
if page_size == "" {
page_size = "10";
}
totalPage := math.Ceil(float64(total)/common.MyFloat64(page_size))
if total > 10000 {
total = 10000
}
page := make(map[string]interface{},0)
if totalPage > 1{
if hitsTotal > 10000 {
total = 10000
}else{
total = hitsTotal
}
p := ctx.Request.FormValue("page")
if p == ""{
p = "1"
}
offset := ctx.Request.FormValue("offset")
offsetInt, err = strconv.Atoi(offset)
if err == nil && offsetInt > 0{
offset = strconv.FormatInt(int64(offsetInt),10)
}else{
offsetInt = 10
offset = "10"
}
//如果是自营同步输出
//自定義分頁
page["orgin_search"] = REQUEST
page["total"] = strconv.FormatInt(total,10)
page["current_page"] = p
page["offset"] = offset
page["offset"] = page_size
if totalPage > 1000{
page["total_page"] = "1000"
}else{
......@@ -277,6 +286,8 @@ func PageClear(ctx *gin.Context,pagesize int64,hitsTotal int64) map[string]inter
}
pageData := make(map[int]int,0)
pInt := int(1)
var err error
pInt, err = strconv.Atoi(p)
if err != nil{
pInt = int(1)
......@@ -308,7 +319,9 @@ func PageClear(ctx *gin.Context,pagesize int64,hitsTotal int64) map[string]inter
}
page["page_data"] = common.MapSort(pageData)
}else{
page["total"] = 1
page["total"] = total
page["total_page"] = totalPage
page["page_data"] = ""
}
return page
}
\ No newline at end of file
......@@ -28,6 +28,12 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
}else{
query1.Must(elastic.NewTermQuery("class_id2",class_id2))
}
if ctx.Request.FormValue("avail_rank") == "1" { //只显示有货
query.Must(elastic.NewRangeQuery("stock").Gt(0))
}
if ctx.Request.FormValue("goods_name/condition") != "" { //型号搜索
query1.Must(elastic.NewTermQuery("goods_name",ctx.Request.FormValue("goods_name/condition")))
}
//存在属性查询
isClassAttr := 0 //存在其他属性搜索
......@@ -76,9 +82,22 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
}
}
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id")) //显示字段
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id","attrs")) //显示字段
source.Size(common.MyInt(page_size))
source.From(page_from)
//排序
if ctx.Request.FormValue("stock_rank") == "2" {
source.Sort("stock",true) //true asc
}else{
source.Sort("stock",false) //true asc
}
if ctx.Request.FormValue("single_rank") == "2" {
source.Sort("lower_price",true) //true asc
}else{
source.Sort("lower_price",false) //true asc
}
}
query.Must(query1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment