Commit 48a132a4 by wang

删除无用的

parent c9fcb4a4
......@@ -11,8 +11,6 @@ cmd.exe~
/conf/prod/*.ini
/go.mod
/conf
/logs
/mylogs
/doc/test
### 日志
### 同步日志
#### 调用方法
不需要额外配置
#### 同步调用方法(不需要额外配置)
```json
import ("go_sku_server/pkg/logger")
......
package main
import "fmt"
func main() {
funtest3(funtest)
}
func funtest3( a func(s string)) {
a("123123")
}
func funtest(s string) {
fmt.Print(s)
}
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/util/gconv"
"reflect"
)
type Struct1 struct {
A string `json:"a"`
B string `json:"b"`
C string `json:"c"`
D int `json:"d"`
E string `json:"e"`
F int `json:"f"`
G string `json:"g"`
}
type jsonStr string
/**
@author wangsong
redis hash sku 结构,主要是用作新增插入用
poolSkuSave 插入redis就是这些字段
*/
type SkuRedisInfo struct {
SpuId string `json:"spu_id"`
Encoded int `json:"encoded"`//供应商编码
Moq int `json:"moq" form:"moq" binding:"required"`//起订量
Mpq int `json:"mpq" form:"mpq" binding:"required"`//标准包装量
OldGoodsId int64 `json:"old_goods_id"`//老商品ID
GoodsType int `json:"goods_type"`//'0:自营 1:联营 2:专卖',
GoodsStatus int64 `json:"goods_status"`//sku状态 '商品状态 0:待审核 1:审核通过(上架)2:审核不通过 3:下架 4:删除'
BatchSn string `json:"batch_sn" form:"batch_sn" `//批次
Stock int `json:"stock" form:"stock" `//库存
HkDeliveryTime string `json:"hk_delivery_time" form:"hk_delivery_time" `//香港货期
CnDeliveryTime string `json:"cn_delivery_time" form:"cn_delivery_time" `//大陆货期
LadderPrice string `json:"ladder_price" form:"ladder_price" `//阶梯价钱
UpdateTime int `json:"update_time" xorm:"created"`
GoodsImages string `json:"goods_images" form:"goods_images" `//商品图片 所属spu
Canal string `json:"canal" form:"canal" `//渠道开发员ID
SupplierId int `json:"supplier_id" form:"supplier_id" binding:"required"`
CpTime int `json:"cp_time" form:"cp_time" `//茂则成本添加时间
}
func main() {
redisInfo:=SkuRedisInfo{}
redisInfo.SpuId="";
redisInfo.LadderPrice=`[{"purchases":5,"price_us":0.1677,"price_cn":0}]`
redisInfo.Moq=123
var jsonredisInfo map[string]interface{}
bytes, err:= json.Marshal(redisInfo)
if(err!=nil){
fmt.Println("错误")
//fmt.Println(err.Error())
}else{
json.Unmarshal([]byte(bytes),&jsonredisInfo)
//fmt.Printf("%+v", jsonredisInfo)
}
var jsonMap map[string]interface{}
var ladderPrice []map[string]interface{}
err = json.Unmarshal([]byte(`{"spu_id":2160610278284142904,"encoded":"","moq":5,"mpq":"1","old_goods_id":0,"goods_type":1,"goods_status":1,"batch_sn":"","stock":13583,"hk_delivery_time":"","cn_delivery_time":"","ladder_price":[{"purchases":5,"price_us":0.1677,"price_cn":0},{"purchases":25,"price_us":0.0852,"price_cn":0},{"purchases":107,"price_us":0.0505,"price_cn":0},{"purchases":501,"price_us":0.0481,"price_cn":0}],"update_time":1606890001,"goods_images":"","canal":"","supplier_id":4}`),&jsonMap)
for key,_:= range jsonMap{
if _, ok := jsonredisInfo[key]; ok {//有值
if(!reflect.ValueOf(jsonredisInfo[key]).IsZero()){//如果需要改的数据不为空,就要赋值到
s:=reflect.ValueOf(jsonredisInfo[key])
if(key=="ladder_price"){//ladder_price 需要单独处理下,如果直接赋值,会出现 斜划线 "\"
if(s.Kind()==reflect.String){
fmt.Println("是字符串")
}
ladderPriceStr:=gconv.String(jsonredisInfo[key])
err=json.Unmarshal([]byte(ladderPriceStr),&ladderPrice)
continue
}
if(s.Kind()==reflect.String){ //string
jsonMap[key]=gconv.String(jsonredisInfo[key])
}else{
jsonMap[key]=gconv.Int(jsonredisInfo[key]) //int
}
}else{//没有数据,其实不需要改,纠正一下类型。
s:=reflect.ValueOf(jsonredisInfo[key])
if(s.Kind()==reflect.String){ //string
jsonMap[key]=gconv.String(jsonMap[key])
}else{
jsonMap[key]=gconv.Int(jsonMap[key]) //int
}
}
reflect.ValueOf(jsonMap[key]).Kind()
}
}
if(err!=nil){
fmt.Println("错误")
fmt.Println(err.Error())
}else{
str,_:=json.Marshal(jsonMap)
fmt.Printf(string(str))
//fmt.Printf("%+v", jsonMap)
}
//reflect1(jsonMap,struct1)
}
/**
合并map,都有值以map1为主,字段类型以map1为主
*/
func mergeMap(map1 map[string]interface{},map2 map[string]interface{}) map[string]interface{} {
var newMap map[string]interface{}
newMap=map1//以map1为主,就先将map1给到newMap
//先算mp1
for key,_:= range map1{
if(!reflect.ValueOf(map1[key]).IsZero()){//如果不为空,就以取map1的值
s:=reflect.ValueOf(map1[key])
if(s.Kind()==reflect.String){ //string
newMap[key]=gconv.String(map1[key])
}else{
newMap[key]=gconv.Int(map1[key]) //int
}
delete(map2, key)//删一个重复的map2的key
}else{//没有数据,取mp2的值,类型要是map1字段的类型
if _, ok := map2[key]; ok { //map1的key在map2是否存在,不存在就不处理
if(!reflect.ValueOf(map2[key]).IsZero()){ //map2不能为0值才处理
m1 :=reflect.ValueOf(map1[key])
if(m1.Kind()==reflect.String){ //string
newMap[key]=gconv.String(map2[key])
}else{
newMap[key]=gconv.Int(map2[key]) //int
}
}
delete(map2, key)//删一个重复的map2的key
}
}
}
//处理map2,重复的被删了,剩下的直接添加
for key,value:= range map2{
s:=reflect.ValueOf(value)
if(s.Kind()==reflect.String){ //string
newMap[key]=gconv.String(value)
}else{
newMap[key]=gconv.Int(value) //int
}
}
return newMap
}
func test() {
/*if(key=="ladder_price"){//ladder_price 需要单独处理下,如果直接赋值,会出现 斜划线 "\"
if(s.Kind()==reflect.String){
fmt.Println("是字符串")
}
ladderPriceStr:=gconv.String(jsonredisInfo[key])
err=json.Unmarshal([]byte(ladderPriceStr),&ladderPrice)
continue
}*/
}
func reflect1(jsonMap map[string]interface{},interface2 interface{}) {
//var newMap map[string]interface{}
sval := reflect.ValueOf(interface2).Elem()
for i := 0; i < sval.NumField(); i++ {
name := sval.Type().Field(i).Name
jsonOneValue:=reflect.ValueOf(jsonMap[name])
if(jsonOneValue.IsZero()){//0值
if(jsonOneValue.Kind()==reflect.TypeOf(sval.Field(i)).Kind()){
}
//直接覆盖
}else{//非0值
}
fmt.Println(sval.Field(i))
}
}
func reflect_exp(struct1 interface{},struct2 interface{})error {
return nil
/*sval := reflect.ValueOf(struct1).Elem()
dval := reflect.ValueOf(struct2).Elem()
for i := 0; i < sval.NumField(); i++ {
value := sval.Field(i)
fmt.Println(value)
if (statusType == 1) { //如果struct1 字段值为零值就不覆盖struct2对应的字段值
if (value.IsZero()) {
continue
}
}
}*/
}
func exp() {
var jsonBlob = [ ] byte ( ` [
{ "Name" : "Platypus" , "Order" : "Monotremata" } ,
{ "Name" : "Quoll" , "Order" : "Dasyuromorphia" }
] ` )
type Animal struct {
Name string
Order string
}
var animals [ ] Animal
err := json. Unmarshal ( jsonBlob , & animals )
if err != nil {
fmt. Println ( "error:" , err )
}
fmt. Printf ( "%+v" , animals )
}
\ No newline at end of file
package main
import (
"fmt"
"sort"
)
//阶梯价格排 序算dfsdf法
type LadderPriceSorter []map[string]string
func (a LadderPriceSorter) Len() int {
return len(a)
}
func (a LadderPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a LadderPriceSorter) Less(i, j int) bool {
return a[j]["sort"] > a[i]["sort"]
}
func main() {
s:=make(map[string]string)
s["sort"]="60";
s2:=make(map[string]string)
s2["sort"]="56"
var slic LadderPriceSorter
slic=append(slic,s)
slic=append(slic,s2)
fmt.Printf("%+v", slic)
sort.Sort(LadderPriceSorter(slic))
fmt.Printf("%+v", slic)
}
package main
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"reflect"
)
func main() {
s:="sdfsdf"
var a int
atype := reflect.ValueOf(a).Type()
vtype := reflect.ValueOf(s).Type()
fmt.Printf("type address:%v\n", atype)
fmt.Println("convertible:", vtype.ConvertibleTo(atype))
fmt.Println(gconv.Int(s))
return
}
\ No newline at end of file
package main
import (
"fmt"
"reflect"
)
type Person struct {
Name string
Age int
}
func IsZeroOfUnderlyingType(x interface{}) bool {
return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface())
}
func main() {
var person Person //定义一个零值
fmt.Println(IsZeroOfUnderlyingType(person)) //零值结构体,输出true
person.Name = "chenqiognhe" //结构体属性Name赋值
fmt.Println(IsZeroOfUnderlyingType(person)) //输出false
fmt.Println(IsZeroOfUnderlyingType(person.Age)) //Age仍是零值,输出true
person.Age = 18 //Age赋值
fmt.Println(IsZeroOfUnderlyingType(person.Age)) //输出false
}
\ No newline at end of file
......@@ -36,9 +36,6 @@ func Loginit() {
}
/**
初始化 log(github.com/ichunt2019/log)
*/
/**
@param path 路径 比如sku_save 即文件夹是 sku 文件名类似 是save_2020-12-10.log
......
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