|
@@ -1,94 +1,38 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
log "github.com/donnie4w/go-logger/logger"
|
|
|
qu "qfw/util"
|
|
|
"strings"
|
|
|
"unicode/utf8"
|
|
|
)
|
|
|
-var class_all_data = map[string]*ClassAll{}
|
|
|
-var class_data = map[string]string{} //记录四级分类
|
|
|
-
|
|
|
-type ClassAll struct {
|
|
|
- Name string
|
|
|
- Code string
|
|
|
- Level string
|
|
|
- Pcode string
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func initClass() {
|
|
|
- sess := save_mgo.GetMgoConn()
|
|
|
- defer save_mgo.DestoryMongoConn(sess)
|
|
|
- q,total:=map[string]interface{}{},0
|
|
|
- it := sess.DB(save_mgo.DbName).C("zktest_mysql_ylqxclass").Find(&q).Iter()
|
|
|
- for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
|
|
|
- name := qu.ObjToString(tmp["name"])
|
|
|
- code:=qu.ObjToString(tmp["code"])
|
|
|
- level:=qu.ObjToString(tmp["level"])
|
|
|
- pcode:=qu.ObjToString(tmp["pcode"])
|
|
|
- class_all_data[code] = &ClassAll{
|
|
|
- name,
|
|
|
- code,
|
|
|
- level,
|
|
|
- pcode,
|
|
|
- }
|
|
|
- if level=="4" {
|
|
|
- class_data[name] = code
|
|
|
- }
|
|
|
- tmp = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Debug("init class 完毕~",len(class_all_data),len(class_data))
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
//保存-mysql
|
|
|
-func productSaveMysql() {
|
|
|
+func saveProductMysql() {
|
|
|
sess := save_mgo.GetMgoConn()
|
|
|
defer save_mgo.DestoryMongoConn(sess)
|
|
|
q,total:=map[string]interface{}{},0
|
|
|
- it := sess.DB(save_mgo.DbName).C("zktest_mysql_product_info").Find(&q).Iter()
|
|
|
+ it := sess.DB(save_mgo.DbName).C(o_product_coll).Find(&q).Iter()
|
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
|
|
|
if total%10000==0 {
|
|
|
log.Debug("curent index ",total)
|
|
|
}
|
|
|
- //main_part
|
|
|
- //changes
|
|
|
-
|
|
|
- company_id := qu.ObjToString(tmp["company_id"])
|
|
|
- if company_id!="" {
|
|
|
- delete(tmp,"_id")
|
|
|
- main_part := qu.ObjToString(tmp["main_part"])
|
|
|
- changes := qu.ObjToString(tmp["changes"])
|
|
|
-
|
|
|
- if utf8.RuneCountInString(main_part)>2000 {
|
|
|
- tmp["main_part"] = ""
|
|
|
- log.Debug("main_part~",company_id)
|
|
|
- }
|
|
|
- if utf8.RuneCountInString(changes)>2000{
|
|
|
- tmp["changes"] = ""
|
|
|
- log.Debug("changes~",company_id)
|
|
|
- }
|
|
|
-
|
|
|
- MysqlTool.Insert("f_product",tmp)
|
|
|
- }
|
|
|
+ delete(tmp,"_id")
|
|
|
+ MysqlTool.Insert("f_product",tmp)
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
-
|
|
|
- log.Debug("is over ",total)
|
|
|
+ log.Debug("is product over ",total)
|
|
|
}
|
|
|
|
|
|
|
|
|
//导出-产品信息
|
|
|
-func exportProductMgo() {
|
|
|
-
|
|
|
- initClass() //内存初始化-分类
|
|
|
+func exportProductMysql() {
|
|
|
|
|
|
sess := save_mgo.GetMgoConn()
|
|
|
defer save_mgo.DestoryMongoConn(sess)
|
|
|
q,total:=map[string]interface{}{},0
|
|
|
- it := sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Iter()
|
|
|
+ it := sess.DB(save_mgo.DbName).C(s_product_coll).Find(&q).Iter()
|
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
|
|
|
if total%10000==0 {
|
|
|
log.Debug("curent index ",total)
|
|
@@ -97,37 +41,42 @@ func exportProductMgo() {
|
|
|
if reg_company!="" {
|
|
|
data := buildInsertData(tmp)
|
|
|
if data!=nil && len(data)>2 {
|
|
|
- save_mgo.Save("zktest_mysql_product_info",data)
|
|
|
+ save_mgo.Save(o_product_coll,data)
|
|
|
}
|
|
|
}
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
- log.Debug("is over ",total)
|
|
|
+ log.Debug("is product over ",total)
|
|
|
}
|
|
|
|
|
|
|
|
|
+//构建数据
|
|
|
func buildInsertData(tmp map[string]interface{}) map[string]interface{}{
|
|
|
data:=map[string]interface{}{}
|
|
|
company_name :=qu.ObjToString(tmp["reg_company"])
|
|
|
- c_data := save_mgo.FindOne("zktest_mysql_company_info", map[string]interface{}{
|
|
|
+ c_data := save_mgo.FindOne(o_company_coll, map[string]interface{}{
|
|
|
"company_name":company_name,
|
|
|
})
|
|
|
if c_data!=nil && len(c_data)>2 {
|
|
|
data["company_id"] = qu.ObjToString(c_data["company_id"])
|
|
|
data["business_type"] = qu.ObjToString(c_data["business_type"])
|
|
|
}else {
|
|
|
+ //当前产品-对应企业-未关联f_company 需要比对别名表-修改此三个字段
|
|
|
data["company_id"] = ""
|
|
|
data["business_type"] = ""
|
|
|
- }
|
|
|
|
|
|
+ //查询别名表--待定
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
data["regno"] = qu.ObjToString(tmp["reg_no"])
|
|
|
data["company_name"] = qu.ObjToString(tmp["reg_company"])
|
|
|
data["company_address"] = qu.ObjToString(tmp["reg_address"])
|
|
|
data["brand"] = ""
|
|
|
data["make_adress"] = qu.ObjToString(tmp["product_address"])
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
p_class:= qu.ObjToString(tmp["p_class"])
|
|
|
if p_class=="国产" {
|
|
|
data["make_country"] = "1"
|
|
@@ -136,20 +85,25 @@ func buildInsertData(tmp map[string]interface{}) map[string]interface{}{
|
|
|
}else {
|
|
|
data["make_country"] = ""
|
|
|
}
|
|
|
-
|
|
|
data["agent_name"] = qu.ObjToString(tmp["agent_name"])
|
|
|
data["agent_address"] = qu.ObjToString(tmp["agent_address"])
|
|
|
data["model"] = qu.ObjToString(tmp["model"])
|
|
|
- data["main_part"] = qu.ObjToString(tmp["main_component"])
|
|
|
data["product_descrip"] = qu.ObjToString(tmp["product_depict"])
|
|
|
data["use_scope "] = qu.ObjToString(tmp["application"])
|
|
|
data["storage_conditions"] = qu.ObjToString(tmp["conditions_use"])
|
|
|
data["remark"] = qu.ObjToString(tmp["remark"])
|
|
|
data["approve_depart"] = qu.ObjToString(tmp["badw"])
|
|
|
-
|
|
|
- data["changes"] = qu.ObjToString(tmp["changes"])
|
|
|
+ main_part := qu.ObjToString(tmp["main_component"])
|
|
|
+ changes := qu.ObjToString(tmp["changes"])
|
|
|
+ if utf8.RuneCountInString(main_part)>2000 {
|
|
|
+ main_part = ""
|
|
|
+ }
|
|
|
+ if utf8.RuneCountInString(changes)>2000{
|
|
|
+ changes = ""
|
|
|
+ }
|
|
|
+ data["main_part"] = main_part
|
|
|
+ data["changes"] = changes
|
|
|
type_str := qu.ObjToString(tmp["type"])
|
|
|
-
|
|
|
approve_date,validity_date := "",""
|
|
|
validity_date = qu.ObjToString(tmp["yxqz"])
|
|
|
if type_str == "注册" {
|
|
@@ -161,8 +115,6 @@ func buildInsertData(tmp map[string]interface{}) map[string]interface{}{
|
|
|
}else {
|
|
|
data["regist_type"] = ""
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
//处理-日期-格式-多变
|
|
|
if approve_date != "" {
|
|
|
approve_date_new := timeStandata(approve_date)
|
|
@@ -170,42 +122,40 @@ func buildInsertData(tmp map[string]interface{}) map[string]interface{}{
|
|
|
data["approve_date"] = approve_date_new
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if validity_date != "" {
|
|
|
validity_date_new := timeStandata(validity_date)
|
|
|
if validity_date_new!="" {
|
|
|
data["validity_date"] = validity_date_new
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
data["source_channel"] = qu.ObjToString(tmp["jy_class"])
|
|
|
class := qu.ObjToString(tmp["class"])
|
|
|
if class == "/" {
|
|
|
class = ""
|
|
|
}
|
|
|
-
|
|
|
+ data["manage_type"] = class
|
|
|
product_name := qu.ObjToString(tmp["product_name"])
|
|
|
-
|
|
|
- data["manage_type"] = qu.ObjToString(tmp["class"])
|
|
|
data["product_name"] = product_name
|
|
|
-
|
|
|
-
|
|
|
- //product_class1 2 3 4 - 比对数据
|
|
|
- //先匹配4级结构
|
|
|
- if class_data[product_name]=="" {
|
|
|
- data["product_class1"] = qu.ObjToString(tmp["product_class"])
|
|
|
- data["product_class2"] = qu.ObjToString(tmp["product_class_1"])
|
|
|
- data["product_class3"] = qu.ObjToString(tmp["product_class_2"])
|
|
|
- data["product_class4"] = ""
|
|
|
- }else {
|
|
|
- class_code := class_data[product_name]
|
|
|
- data["product_class1"] = class_all_data[class_code[:2]].Name
|
|
|
- data["product_class2"] = class_all_data[class_code[:4]].Name
|
|
|
- data["product_class3"] = class_all_data[class_code[:6]].Name
|
|
|
+ product_class_1 := qu.ObjToString(tmp["product_class"])
|
|
|
+ product_class_2 := qu.ObjToString(tmp["product_class_1"])
|
|
|
+ product_class_3 := qu.ObjToString(tmp["product_class_2"])
|
|
|
+ key_4 := "四级_"+product_name
|
|
|
+ code_4 := proclass_name_dict[key_4]
|
|
|
+ if code_4!="" {
|
|
|
+ data["product_code"] = code_4
|
|
|
+ data["product_class1"] = proclass_code_dict[code_4[:2]]
|
|
|
+ data["product_class2"] = proclass_code_dict[code_4[:4]]
|
|
|
+ data["product_class3"] = proclass_code_dict[code_4[:8]]
|
|
|
data["product_class4"] = product_name
|
|
|
+ }else {
|
|
|
+ pro_key := fmt.Sprintf("%s_%s_%s",product_class_1,product_class_2,product_class_3)
|
|
|
+ code := proclass_name_dict[pro_key]
|
|
|
+ data["product_code"] = code
|
|
|
+ data["product_class1"] = product_class_1
|
|
|
+ data["product_class2"] = product_class_2
|
|
|
+ data["product_class3"] = product_class_3
|
|
|
+ data["product_class4"] = ""
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return data
|
|
|
}
|
|
|
|