|
@@ -0,0 +1,375 @@
|
|
|
+package dealer
|
|
|
+
|
|
|
+import (
|
|
|
+ log "github.com/donnie4w/go-logger/logger"
|
|
|
+ qu "qfw/util"
|
|
|
+ "regexp"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+ ul "util"
|
|
|
+)
|
|
|
+
|
|
|
+func exportDealerProClass() {
|
|
|
+ sess := ul.Save_Mgo.GetMgoConn()
|
|
|
+ defer ul.Save_Mgo.DestoryMongoConn(sess)
|
|
|
+ q, total := map[string]interface{}{}, 0
|
|
|
+ it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
|
|
|
+ "dealer_name": 1,
|
|
|
+ "company_id": 1,
|
|
|
+ "name_id": 1,
|
|
|
+ }).Iter()
|
|
|
+ for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
+ if total%10000 == 0 {
|
|
|
+ log.Debug("curent index ", total)
|
|
|
+ }
|
|
|
+ ul.Pool_Mgo <- true
|
|
|
+ ul.Wg_Mgo.Add(1)
|
|
|
+ go func(tmp map[string]interface{}) {
|
|
|
+ defer func() {
|
|
|
+ <-ul.Pool_Mgo
|
|
|
+ ul.Wg_Mgo.Done()
|
|
|
+ }()
|
|
|
+ dealWithDealerProClassInfo(tmp)
|
|
|
+ }(tmp)
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ ul.Wg_Mgo.Wait()
|
|
|
+ log.Debug("is over ... ")
|
|
|
+ time.Sleep(time.Second * 2)
|
|
|
+}
|
|
|
+
|
|
|
+func dealWithDealerProClassInfo(tmp map[string]interface{}) {
|
|
|
+ //去查生产经营等范围
|
|
|
+ dealer_id := qu.ObjToString(tmp["name_id"])
|
|
|
+ company_id := qu.ObjToString(tmp["company_id"])
|
|
|
+ dealer_name := qu.ObjToString(tmp["dealer_name"])
|
|
|
+ dataArr, _ := ul.Save_Mgo.Find("nmpa_company_new", map[string]interface{}{
|
|
|
+ "company": dealer_name,
|
|
|
+ }, nil, nil)
|
|
|
+ ScRangeArr, JyRangeArr := []string{}, []string{}
|
|
|
+ for _, v := range dataArr {
|
|
|
+ classify := qu.ObjToString(v["classify"])
|
|
|
+ if strings.Contains(classify, "生产") {
|
|
|
+ ScRangeArr = append(ScRangeArr, qu.ObjToString(v["product_range"]))
|
|
|
+ } else if strings.Contains(classify, "经营") {
|
|
|
+ JyRangeArr = append(JyRangeArr, qu.ObjToString(v["business_range"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ScCodeArr, JyCodeArr := []string{}, []string{}
|
|
|
+ for _, v := range ScRangeArr {
|
|
|
+ ScCodeArr = append(ScCodeArr, figureScRangeInfo(qu.ObjToString(v))...)
|
|
|
+ }
|
|
|
+ for _, v := range JyRangeArr {
|
|
|
+ JyCodeArr = append(JyCodeArr, figureJyRangeInfo(qu.ObjToString(v))...)
|
|
|
+ }
|
|
|
+ //对数组去重
|
|
|
+ ScCodeArr, JyCodeArr = figureRepeatArr(ScCodeArr), figureRepeatArr(JyCodeArr)
|
|
|
+ ScCodeArr, JyCodeArr = figureMergerArr(ScCodeArr), figureMergerArr(JyCodeArr)
|
|
|
+
|
|
|
+ for _, v := range ScCodeArr {
|
|
|
+ info := map[string]interface{}{}
|
|
|
+ info["dealer_id"] = dealer_id
|
|
|
+ info["company_id"] = company_id
|
|
|
+ info["dealer_name"] = dealer_name
|
|
|
+ info["business_model"] = 1
|
|
|
+ info["sdequipment_code"] = v
|
|
|
+ ul.Save_Mgo.Save("nmpa_dealer_classcode", info)
|
|
|
+ }
|
|
|
+ for _, v := range JyCodeArr {
|
|
|
+ info := map[string]interface{}{}
|
|
|
+ info["dealer_id"] = dealer_id
|
|
|
+ info["company_id"] = company_id
|
|
|
+ info["dealer_name"] = dealer_name
|
|
|
+ info["business_model"] = 2
|
|
|
+ info["sdequipment_code"] = v
|
|
|
+ ul.Save_Mgo.Save("nmpa_dealer_classcode", info)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//生产范围计算
|
|
|
+func figureScRangeInfo(product_range string) []string {
|
|
|
+ codeArr := []string{}
|
|
|
+ matchArr1 := ul.ScRangeReg1.FindAllString(product_range, -1)
|
|
|
+ if len(matchArr1) > 0 {
|
|
|
+ for _, v1 := range matchArr1 {
|
|
|
+ name := ul.ScRangeReg1.ReplaceAllString(v1, "${4}")
|
|
|
+ name = ul.ScRangeClean1.ReplaceAllString(name, "")
|
|
|
+ name = ul.ScRangeClean2.ReplaceAllString(name, "")
|
|
|
+ yl_code := ul.YlqxNameCode[name]
|
|
|
+ if yl_code != "" {
|
|
|
+ codeArr = append(codeArr, yl_code)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ matchArr2 := ul.ScRangeReg2.FindAllString(product_range, -1)
|
|
|
+ for _, v1 := range matchArr2 {
|
|
|
+ if strings.Contains(v1, "分类目录") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ name := ul.ScRangeReg2.ReplaceAllString(v1, "${2}")
|
|
|
+ name = ul.ScRangeClean1.ReplaceAllString(name, "")
|
|
|
+ name = ul.ScRangeClean2.ReplaceAllString(name, "")
|
|
|
+ yl_code := ul.YlqxNameCode[name]
|
|
|
+ if yl_code != "" {
|
|
|
+ codeArr = append(codeArr, yl_code)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return codeArr
|
|
|
+}
|
|
|
+
|
|
|
+//经营范围范围计算
|
|
|
+func figureJyRangeInfo(business_range string) []string {
|
|
|
+ codesArr := []string{}
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg1, "A")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg2, "")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg3, "A")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg4, "B")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg5, "")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg6, "C")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg7, "A")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg8, "B")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg9, "C")
|
|
|
+ figureRuleRegexpInfo(&codesArr, business_range, ul.JySpecReg1, "S")
|
|
|
+ return codesArr
|
|
|
+}
|
|
|
+
|
|
|
+func figureRuleRegexpInfo(codesArr *[]string, business_range string, JyRangeReg *regexp.Regexp, ruleCode string) {
|
|
|
+ arr := JyRangeReg.FindAllString(business_range, -1)
|
|
|
+ for _, v := range arr {
|
|
|
+ text := JyRangeReg.ReplaceAllString(v, "${1}")
|
|
|
+ yl_code := ""
|
|
|
+ if ruleCode == "A" {
|
|
|
+ yl_code = ul.JyCodeA[text]
|
|
|
+ } else if ruleCode == "B" {
|
|
|
+ yl_code = ul.JyCodeB[text]
|
|
|
+ } else if ruleCode == "C" {
|
|
|
+ yl_code = ul.JyCodeC[text]
|
|
|
+ } else if ruleCode == "S" {
|
|
|
+ if strings.Contains(text, "体外诊断试剂") && !ul.JyExcludeReg1.MatchString(text) {
|
|
|
+ yl_code = "23"
|
|
|
+ } else {
|
|
|
+ yl_code = "22"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ yl_code = ul.YlqxNameCode[text]
|
|
|
+ }
|
|
|
+ if yl_code != "" {
|
|
|
+ *codesArr = append(*codesArr, yl_code)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func figureRepeatArr(arr []string) []string {
|
|
|
+ new_arr := []string{}
|
|
|
+ temp := map[string]string{}
|
|
|
+ for _, v := range arr {
|
|
|
+ if temp[v] == "" {
|
|
|
+ temp[v] = v
|
|
|
+ new_arr = append(new_arr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new_arr
|
|
|
+}
|
|
|
+
|
|
|
+func figureMergerArr(arr []string) []string {
|
|
|
+ //2 2 3 4 位
|
|
|
+ temp := map[string]string{}
|
|
|
+ for _, v := range arr {
|
|
|
+ temp[v] = v
|
|
|
+ }
|
|
|
+ new_arr := []string{}
|
|
|
+ for _, v := range arr {
|
|
|
+ isValid := false
|
|
|
+ l := len(v)
|
|
|
+ if l == 2 {
|
|
|
+ isValid = true
|
|
|
+ } else if l == 4 {
|
|
|
+ if temp[v[:2]] == "" {
|
|
|
+ isValid = true
|
|
|
+ }
|
|
|
+ } else if l == 7 {
|
|
|
+ if temp[v[:2]] == "" && temp[v[:4]] == "" {
|
|
|
+ isValid = true
|
|
|
+ }
|
|
|
+ } else if l == 11 {
|
|
|
+ if temp[v[:2]] == "" && temp[v[:4]] == "" && temp[v[:7]] == "" {
|
|
|
+ isValid = true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ if isValid {
|
|
|
+ new_arr = append(new_arr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new_arr
|
|
|
+}
|
|
|
+
|
|
|
+func exportDealerProductClassInfo() {
|
|
|
+ classCodeArr := ul.MysqlSubjectTool.Find("dwd_f_yl_dealer_pro_classify", nil, "", "", -1, -1)
|
|
|
+ productsArr := ul.MysqlSubjectTool.Find("dwd_f_yl_dealer_pro_baseinfo", nil, "dealer_id,company_id,company_name,product_name,sdproduct_name,sdequipment_code,medical_equipment_class1,medical_equipment_class2,medical_equipment_class3", "", -1, -1)
|
|
|
+ if productsArr == nil || classCodeArr == nil {
|
|
|
+ log.Debug("无数据 ...")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ScClassTemp, JyClassTemp := map[string][]string{}, map[string][]string{}
|
|
|
+ for _, v := range *classCodeArr {
|
|
|
+ dealer_id := qu.ObjToString(v["dealer_id"])
|
|
|
+ sdequipment_code := qu.ObjToString(v["sdequipment_code"])
|
|
|
+ business_model := qu.IntAll(v["business_model"])
|
|
|
+ if business_model == 1 {
|
|
|
+ sc_info := ScClassTemp[dealer_id]
|
|
|
+ if sc_info == nil {
|
|
|
+ ScClassTemp[dealer_id] = []string{sdequipment_code}
|
|
|
+ } else {
|
|
|
+ sc_info = append(sc_info, sdequipment_code)
|
|
|
+ ScClassTemp[dealer_id] = sc_info
|
|
|
+ }
|
|
|
+ } else if business_model == 2 {
|
|
|
+ jy_info := JyClassTemp[dealer_id]
|
|
|
+ if jy_info == nil {
|
|
|
+ JyClassTemp[dealer_id] = []string{sdequipment_code}
|
|
|
+ } else {
|
|
|
+ jy_info = append(jy_info, sdequipment_code)
|
|
|
+ JyClassTemp[dealer_id] = jy_info
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Debug("企业能力~", len(ScClassTemp), "~", len(JyClassTemp))
|
|
|
+ log.Debug("企业产品数量~", len(*productsArr))
|
|
|
+
|
|
|
+ for _, v := range *productsArr {
|
|
|
+ dealer_id := qu.ObjToString(v["dealer_id"])
|
|
|
+ company_id := qu.ObjToString(v["company_id"])
|
|
|
+ company_name := qu.ObjToString(v["company_name"])
|
|
|
+ product_name := qu.ObjToString(v["product_name"])
|
|
|
+ sdproduct_name := qu.ObjToString(v["sdproduct_name"])
|
|
|
+ sdequipment_code := qu.ObjToString(v["sdequipment_code"])
|
|
|
+ medical_equipment_class1 := qu.ObjToString(v["medical_equipment_class1"])
|
|
|
+ medical_equipment_class2 := qu.ObjToString(v["medical_equipment_class2"])
|
|
|
+ medical_equipment_class3 := qu.ObjToString(v["medical_equipment_class3"])
|
|
|
+ if sdequipment_code == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if ScClassTemp[dealer_id] != nil {
|
|
|
+ if figureConformToClass(ScClassTemp[dealer_id], sdequipment_code) {
|
|
|
+ //符合
|
|
|
+ info := map[string]interface{}{}
|
|
|
+ info["company_id"] = company_id
|
|
|
+ info["dealer_id"] = dealer_id
|
|
|
+ info["dealer_name"] = company_name
|
|
|
+ info["sdequipment_code"] = sdequipment_code
|
|
|
+ info["business_model"] = 1
|
|
|
+ info["medical_equipment_class1"] = medical_equipment_class1
|
|
|
+ info["medical_equipment_class2"] = medical_equipment_class2
|
|
|
+ info["medical_equipment_class3"] = medical_equipment_class3
|
|
|
+ info["sdproduct_name"] = sdproduct_name
|
|
|
+ info["product_name"] = product_name
|
|
|
+ ul.Save_Mgo.Save("nmpa_dealer_class_product", info)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if JyClassTemp[dealer_id] != nil {
|
|
|
+ if figureConformToClass(JyClassTemp[dealer_id], sdequipment_code) {
|
|
|
+ //符合
|
|
|
+ info := map[string]interface{}{}
|
|
|
+ info["company_id"] = company_id
|
|
|
+ info["dealer_id"] = dealer_id
|
|
|
+ info["dealer_name"] = company_name
|
|
|
+ info["sdequipment_code"] = sdequipment_code
|
|
|
+ info["business_model"] = 2
|
|
|
+ info["medical_equipment_class1"] = medical_equipment_class1
|
|
|
+ info["medical_equipment_class2"] = medical_equipment_class2
|
|
|
+ info["medical_equipment_class3"] = medical_equipment_class3
|
|
|
+ info["sdproduct_name"] = sdproduct_name
|
|
|
+ info["product_name"] = product_name
|
|
|
+ ul.Save_Mgo.Save("nmpa_dealer_class_product", info)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Debug("is over ...")
|
|
|
+ time.Sleep(time.Second * 2)
|
|
|
+}
|
|
|
+
|
|
|
+func figureConformToClass(arr []string, code string) bool {
|
|
|
+ l := len(code)
|
|
|
+ for _, v := range arr {
|
|
|
+ if v == code {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if l == 4 {
|
|
|
+ c2 := code[:2]
|
|
|
+ if c2 == v {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else if l == 7 {
|
|
|
+ c2, c4 := code[:2], code[:4]
|
|
|
+ if c2 == v || c4 == v {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else if l == 11 {
|
|
|
+ c2, c4, c7 := code[:2], code[:4], code[:7]
|
|
|
+ if c2 == v || c4 == v || c7 == v {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+//导入tidb数据
|
|
|
+func importDealerClassCodeInfoTidb() {
|
|
|
+ sess := ul.Save_Mgo.GetMgoConn()
|
|
|
+ defer ul.Save_Mgo.DestoryMongoConn(sess)
|
|
|
+ q, total := map[string]interface{}{}, 0
|
|
|
+ it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_dealer_classcode").Find(&q).Iter()
|
|
|
+ for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
+ if total%10000 == 0 {
|
|
|
+ log.Debug("curent index ", total)
|
|
|
+ }
|
|
|
+ ul.Pool_Mgo <- true
|
|
|
+ ul.Wg_Mgo.Add(1)
|
|
|
+ go func(tmp map[string]interface{}) {
|
|
|
+ defer func() {
|
|
|
+ <-ul.Pool_Mgo
|
|
|
+ ul.Wg_Mgo.Done()
|
|
|
+ }()
|
|
|
+ tmpid := ul.BsonTOStringId(tmp["_id"])
|
|
|
+ ul.DeleteField(&tmp, "_id")
|
|
|
+ ul.InsertMysqlSubjectData("dwd_f_yl_dealer_pro_classify", tmp, tmpid)
|
|
|
+ }(tmp)
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ ul.Wg_Mgo.Wait()
|
|
|
+ log.Debug("is over ... ")
|
|
|
+ time.Sleep(time.Second * 2)
|
|
|
+}
|
|
|
+func importDealerProductClassInfoTidb() {
|
|
|
+ sess := ul.Save_Mgo.GetMgoConn()
|
|
|
+ defer ul.Save_Mgo.DestoryMongoConn(sess)
|
|
|
+ q, total := map[string]interface{}{}, 0
|
|
|
+ it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_dealer_class_product").Find(&q).Iter()
|
|
|
+ for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
+ if total%10000 == 0 {
|
|
|
+ log.Debug("curent index ", total)
|
|
|
+ }
|
|
|
+ ul.Pool_Mgo <- true
|
|
|
+ ul.Wg_Mgo.Add(1)
|
|
|
+ go func(tmp map[string]interface{}) {
|
|
|
+ defer func() {
|
|
|
+ <-ul.Pool_Mgo
|
|
|
+ ul.Wg_Mgo.Done()
|
|
|
+ }()
|
|
|
+ tmpid := ul.BsonTOStringId(tmp["_id"])
|
|
|
+ ul.DeleteField(&tmp, "_id")
|
|
|
+ ul.InsertMysqlSubjectData("dwd_f_yl_dealer_product_info", tmp, tmpid)
|
|
|
+ }(tmp)
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ ul.Wg_Mgo.Wait()
|
|
|
+ log.Debug("is over ... ")
|
|
|
+ time.Sleep(time.Second * 2)
|
|
|
+}
|