Commit cd90f610 by huangchengyi

1.0

parent 81d98087
package main
import (
"flag"
"goods_machining/boot"
)
func main() {
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
var mod string;
flag.StringVar(&mod, "m", "all", "请输入模块id") // 单独计算某个模块,默认计算全部,0计算全部
flag.Parse()
if err := boot.Boot(path); err != nil {
panic(err)
}
}
......@@ -10,7 +10,7 @@ import (
)
const goods_slice_count = 50 //每多少个型号id开启一个协程
const goods_slice_count = 1 //每多少个型号id开启一个协程
/*
查询商品详情(自营或者联营)
......@@ -92,3 +92,6 @@ func Synchronization(c *gin.Context) {
common.Output(0,"查询成功",GoodsRes)
}
......@@ -421,4 +421,7 @@ func MyFloat64ToStr(numb float64) string {
func MyInt64ToStr(numb int64) string {
return strconv.FormatInt(numb,10)
}
func MyIntToStr(i int) string {
return strconv.Itoa(i)
}
////////////类型转换/////////////////////
\ No newline at end of file
......@@ -73,27 +73,30 @@ eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func HgetPi(redisConn *redis.Conn,hkey string,targetIds []string) map[string]string {
func HgetPi(redisCon string,hkey string,targetIds []string) map[string]string {
redisConn := Conn(redisCon)
defer redisConn.Close()
skuArr := make(map[string]string,0)
if len(targetIds) == 1 {
oneId := targetIds[0]
info,_ := String((*redisConn).Do("HGET",hkey,oneId))
info,err := String(redisConn.Do("HGET",hkey,oneId))
fmt.Print(err)
if info == "" {
skuArr[oneId] = ""
}else{
skuArr[oneId] = info
}
fmt.Print("单个获取")
return skuArr
}
for _,v := range targetIds{
(*redisConn).Send("HGet",hkey,v)
redisConn.Send("HGet",hkey,v)
}
(*redisConn).Flush()
redisConn.Flush()
for _,goods_id := range targetIds{
info,_ := (*redisConn).Receive()
info,_ := redisConn.Receive()
if info == nil{
skuArr[goods_id] = ""
continue;
......
......@@ -17,12 +17,14 @@ type ZiyingService struct {
*/
func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]interface{}, wg *sync.WaitGroup) {
defer wg.Done();
redisConn := gredis.Conn("search_r")
//redisConn := gredis.Conn("search_r")
/////批量获取商品详情
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",goodsIds)
skuArr := gredis.HgetPi("search_r","Self_SelfGoods",goodsIds)
fmt.Print(skuArr)
for goods_id,info := range skuArr {
A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id",goods_id)
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
......
package service
import (
"fmt"
"github.com/tidwall/gjson"
"goods_machining/pkg/common"
"goods_machining/pkg/gredis"
"goods_machining/pkg/mysql"
)
// 自营定时任务服务
type ZyCronService struct {
}
/*
计算自营折扣信息
*/
func (a *ZyCronService) ZyDiscount(goodsId string) {
var (
i int
goodsIdTemp string
dbSpu = mysql.Conn("liexin_data") //spu实例化链接
redisConn = gredis.Conn("search_r")
)
defer redisConn.Close()
page_size := 1000
for i=1;i<=1000;i++ {
start := 0;
if i== 1 {
start = 0;
}else{
start = (i-1)*page_size
}
sql := "select goods_id from lie_goods where self_supplier_type = 1 and stock >0 limit "+common.MyIntToStr(page_size)+","+common.MyIntToStr(start);
if goodsId != "" {
sql = "select goods_id from lie_goods where self_supplier_type = 1 and stock >0 limit "+goodsId;
}
goodsInfos, err := dbSpu.QueryString(sql)
if err != nil || len(goodsInfos) == 0{
fmt.Print("查询没有数据")
break;
}
for _,info := range goodsInfos{
now_goods_id := info["goods_id"]
/********开始计算系数******/
fmt.Println("开始计算系数"+goodsIdTemp)
goodsBatch,_ := gredis.String(redisConn.Do("HGET","Self_goods_batch",now_goods_id)) //获取商品批次信息
apiGoodsList := gjson.Get(goodsBatch, "dc_time").Array()
var EarlyAddTime int64 = 0; //最早的批次
for _, goods := range apiGoodsList {
dc_time := goods.Get("dc_time").Int()
if EarlyAddTime == 0 {
EarlyAddTime = dc_time
continue;
}
if dc_time < EarlyAddTime {
EarlyAddTime = dc_time
}
}
if EarlyAddTime == 0 {
fmt.Println("没有批次信息")
continue;
}
}
//redisWrite.Do("HSET",config.Get("redis_all.BRAND_NAME_ALL").String(),brandkey,brandId)
}
}
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