|
@@ -15,13 +15,13 @@ import (
|
|
|
**/
|
|
|
var (
|
|
|
//清理品目中数字
|
|
|
- itemclear = regexp.MustCompile("^[\\d一二三四五六七八九十]+")
|
|
|
+ numclear = regexp.MustCompile("^[\\d一二三四五六七八九十.]+")
|
|
|
//清理表格title中的不需要的内容
|
|
|
tabletitleclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n、.,.。、_/((人民币万元件个公斤))]")
|
|
|
//清理表格中是key中包含的空格或数字等
|
|
|
tablekeyclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n、.,.。、_/]+|^[\\d一二三四五六七八九十]+[、.]*|[((【\\[].*?[))】\\]]")
|
|
|
//清理表格td中的符号
|
|
|
- tabletdclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n、,。、_??;;~\\-#\\\\]*|(详?见)附(件|图)")
|
|
|
+ tabletdclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n、,。、_??;;~\\-#\\\\()(){}【】\\[\\]<>《》{}〔〕¥$]*")
|
|
|
//判断key是金额,对万元的处理
|
|
|
moneyreg = regexp.MustCompile("(预算|费|价|额|规模|投资)")
|
|
|
//根据表格的内容判断是不是表头,如果含有金额则不是表头
|
|
@@ -786,7 +786,7 @@ func (table *Table) Analy(contactFormat *u.ContactFormat) []*Table {
|
|
|
table.FindKV()
|
|
|
//table中抽取品牌
|
|
|
if u.IsBrandGoods {
|
|
|
- table.analyBrand1()
|
|
|
+ table.analyBrand()
|
|
|
}
|
|
|
//判断是否是多包,并处理分包的
|
|
|
table.CheckMultiPackageByTable()
|
|
@@ -2669,16 +2669,15 @@ L:
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
-func (table *Table) analyBrand1() {
|
|
|
+func (table *Table) analyBrand() {
|
|
|
//5c2d8c05a5cb26b9b782572b
|
|
|
//产品名称 品牌 规格 单价 单位 数量 小计 质保期
|
|
|
- lineMapArr1 := make(map[string]*SortMap)
|
|
|
- lineMap1 := make(map[string]*SortMap)
|
|
|
+ lineMapArr := make(map[string]*SortMap)
|
|
|
+ lineMap := make(map[string]*SortMap)
|
|
|
brandRule := u.BrandRules
|
|
|
//将val为数组和string的分开
|
|
|
for _, key := range table.SortKV.Keys { //遍历table.SortKV.Keys而不是直接遍历table.SortKV.Map是为了得到table头的顺序
|
|
|
val := table.SortKV.Map[key]
|
|
|
- //qutil.Debug(key, "====", val)
|
|
|
key = regReplAllSpace.ReplaceAllString(key, "")
|
|
|
key = strings.Replace(key, "", "", -1) //处理一个特殊的采购量 经上层处理空格后未处理掉
|
|
|
if realTypeVal, ok := val.([]string); ok { //val为数组 {"数量":["1","2","3"]}
|
|
@@ -2695,7 +2694,7 @@ func (table *Table) analyBrand1() {
|
|
|
}
|
|
|
realTypeVal = valArr
|
|
|
line := underline.FindString(key)
|
|
|
- lineValMap1 := lineMapArr1[line]
|
|
|
+ lineValMap1 := lineMapArr[line]
|
|
|
i := 1
|
|
|
L:
|
|
|
for { //去除数组空数据
|
|
@@ -2714,11 +2713,11 @@ func (table *Table) analyBrand1() {
|
|
|
if lineValMap1 == nil && len(realTypeVal) != 0 {
|
|
|
tmp := NewSortMap()
|
|
|
tmp.AddKey(key, dislodgeNull)
|
|
|
- lineMapArr1[line] = tmp
|
|
|
+ lineMapArr[line] = tmp
|
|
|
} else {
|
|
|
lineValMap1.AddKey(key, dislodgeNull)
|
|
|
}
|
|
|
- //qutil.Debug("lineMapArr1---", lineMapArr1[line].Keys, lineMapArr1[line].Map)
|
|
|
+ //qutil.Debug("lineMapArr---", lineMapArr[line].Keys, lineMapArr[line].Map)
|
|
|
} else if realTypeVal, b := val.(string); b { //val为字符串 {"数量":"1"}
|
|
|
/*
|
|
|
{
|
|
@@ -2733,15 +2732,15 @@ func (table *Table) analyBrand1() {
|
|
|
}
|
|
|
realTypeVal = valArr[0]
|
|
|
line := underline.FindString(key)
|
|
|
- lineValMap1 := lineMap1[line]
|
|
|
+ lineValMap1 := lineMap[line]
|
|
|
if lineValMap1 == nil {
|
|
|
tmp := NewSortMap()
|
|
|
tmp.AddKey(key, realTypeVal)
|
|
|
- lineMap1[line] = tmp
|
|
|
+ lineMap[line] = tmp
|
|
|
} else {
|
|
|
lineValMap1.AddKey(key, realTypeVal)
|
|
|
}
|
|
|
- //qutil.Debug("lineMap1---", lineMap1[line].Keys, lineMap1[line].Map)
|
|
|
+ //qutil.Debug("lineMap---", lineMap[line].Keys, lineMap[line].Map)
|
|
|
} else {
|
|
|
// "_id" : ObjectId("5c2c3802a5cb26b9b78646c4")5c2b0551a5cb26b9b7cb05db否5c2a42e6a5cb26b9b763ba5a采购人:一、采购人5c2b06f5a5cb26b9b7cc4409
|
|
|
//成交供应商排名 [map[entname:昆明合优科技有限公司 sortstr:第一中标候选人 sort:1] map[sort:2 entname:昆明厚起科技有限公司 sortstr:第二中标候选人] map[entname:云南远安科技发展有限公司 sortstr:第三中标候选人 sort:3]]
|
|
@@ -2749,32 +2748,30 @@ func (table *Table) analyBrand1() {
|
|
|
}
|
|
|
}
|
|
|
//处理数组数据后,匹配必须title和替换要保存的title
|
|
|
- //qutil.Debug("lineMapArr1----", len(lineMapArr1))
|
|
|
- if len(lineMapArr1) > 0 {
|
|
|
- for _, aMap := range lineMapArr1 {
|
|
|
+ //qutil.Debug("lineMapArr----", len(lineMapArr))
|
|
|
+ if len(lineMapArr) > 0 {
|
|
|
+ for _, aMap := range lineMapArr {
|
|
|
maxNum := 0
|
|
|
arrcount1 := 0 //记录key是否存在必须title(数组数据)
|
|
|
arrcount2 := 0
|
|
|
ka := make(map[string][]string) //最终存储数据
|
|
|
//qutil.Debug("aMap.Keys----", aMap.Keys)
|
|
|
for _, k0 := range aMap.Keys {
|
|
|
+ match := false //记录must是否匹配到
|
|
|
v0 := aMap.Map[k0].([]string)
|
|
|
- //qutil.Debug("k0:", k0, "v0:", v0)
|
|
|
//匹配必须title
|
|
|
for nameM, r := range brandRule["must"] {
|
|
|
if convert(k0, r) { //匹配成功
|
|
|
+ v0tmp1 := v0
|
|
|
+ match = true
|
|
|
if len(ka[nameM]) != 0 && strings.Contains(k0, "描述") { //防止k0匹配到多次 和特殊情况 物料名称 物料描述同时出现
|
|
|
continue
|
|
|
}
|
|
|
if nameM == "itemname" || nameM == "modal" {
|
|
|
+ hasGoods(table, v0...) //判断itemname和modal中有没有商品
|
|
|
if nameM == "itemname" {
|
|
|
- varr, f := filteritem(v0...) //过滤品目
|
|
|
- if f {
|
|
|
- break
|
|
|
- }
|
|
|
- v0 = varr
|
|
|
+ v0tmp1 = filteritem(v0...) //过滤itemname
|
|
|
}
|
|
|
- hasGoods(table, v0...) //判断itemname和modal中有没有商品
|
|
|
}
|
|
|
if nameM == "brandname" || nameM == "modal" {
|
|
|
if len(ka["brandname"]) == 0 {
|
|
@@ -2784,17 +2781,38 @@ func (table *Table) analyBrand1() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //unitprice
|
|
|
+ if nameM == "unitprice" { //处理金额
|
|
|
+ v0tmp1 = dealPrice(k0, v0...)
|
|
|
+ }
|
|
|
if nameM != "brandname" && len(ka[nameM]) == 0 {
|
|
|
- ka[nameM] = v0
|
|
|
+ ka[nameM] = v0tmp1
|
|
|
}
|
|
|
arrcount1++
|
|
|
}
|
|
|
}
|
|
|
//替换其它要保存字段
|
|
|
- for nameR, r := range brandRule["replace"] {
|
|
|
- if convert(k0, r) { //匹配成功
|
|
|
- ka[nameR] = v0
|
|
|
- arrcount2++
|
|
|
+ if !match { //must未匹配,匹配replace
|
|
|
+ for nameR, r := range brandRule["replace"] {
|
|
|
+ if convert(k0, r) { //匹配成功
|
|
|
+ v0tmp2 := v0
|
|
|
+ //totalprice
|
|
|
+ if nameR == "totalprice" { //处理金额
|
|
|
+ v0tmp2 = dealPrice(k0, v0...)
|
|
|
+ }
|
|
|
+ //number
|
|
|
+ if nameR == "number" { //处理数量
|
|
|
+ uname0 := []string{}
|
|
|
+ v0tmp2, uname0 = dealNumber(v0...)
|
|
|
+ if len(ka["unitname"]) == 0 && len(uname0) != 0 {
|
|
|
+ ka["unitname"] = uname0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(v0tmp2) > 0 {
|
|
|
+ ka[nameR] = v0tmp2
|
|
|
+ }
|
|
|
+ arrcount2++
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -2807,7 +2825,6 @@ func (table *Table) analyBrand1() {
|
|
|
// }
|
|
|
// }
|
|
|
//找最终存储数据的最大len(arr),小的补空
|
|
|
- //fmt.Println("ka==============", ka)
|
|
|
for _, vf1 := range ka {
|
|
|
lenVal := len(vf1)
|
|
|
if lenVal > maxNum {
|
|
@@ -2836,14 +2853,15 @@ func (table *Table) analyBrand1() {
|
|
|
}
|
|
|
}
|
|
|
//处理string数据后,匹配必须title和替换要保存的title
|
|
|
- //qutil.Debug("lineMap1----", len(lineMap1))
|
|
|
- if len(lineMap1) > 0 {
|
|
|
- for _, sMap := range lineMap1 {
|
|
|
+ //qutil.Debug("lineMap----", len(lineMap))
|
|
|
+ if len(lineMap) > 0 {
|
|
|
+ for _, sMap := range lineMap {
|
|
|
strcount1 := 0 //记录key是否存在必须title(字符串数据)
|
|
|
strcount2 := 0
|
|
|
endStrMap := make(map[string]string)
|
|
|
//qutil.Debug(k, "aMap.Keys----", sMap.Keys)
|
|
|
for _, k1 := range sMap.Keys {
|
|
|
+ match := false //记录must是否匹配到
|
|
|
v1 := qutil.ObjToString(sMap.Map[k1])
|
|
|
// for k1, v1 := range sMap {
|
|
|
//qutil.Debug(k1, "++++++++++", v1)
|
|
@@ -2853,269 +2871,65 @@ func (table *Table) analyBrand1() {
|
|
|
//匹配必须title
|
|
|
for nameM, r := range brandRule["must"] {
|
|
|
if convert(k1, r) { //匹配成功
|
|
|
+ v1tmp1 := v1
|
|
|
+ match = true
|
|
|
if nameM == "itemname" || nameM == "modal" { //特殊处理itemname
|
|
|
+ hasGoods(table, v1)
|
|
|
if nameM == "itemname" {
|
|
|
- varr, f := filteritem(v1) //过滤品目
|
|
|
- if f {
|
|
|
+ v1tmp1 = filteritem(v1)[0] //过滤itemname
|
|
|
+ if v1tmp1 == "" {
|
|
|
break
|
|
|
}
|
|
|
- v1 = varr[0]
|
|
|
}
|
|
|
- hasGoods(table, v1)
|
|
|
}
|
|
|
if nameM == "brandname" || nameM == "modal" { //特殊处理brandname
|
|
|
- if len(endStrMap["brandname"]) == 0 {
|
|
|
+ if endStrMap["brandname"] == "" {
|
|
|
brand, allNull := hasBrand(table, v1)
|
|
|
if !allNull {
|
|
|
endStrMap["brandname"] = brand[0]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if nameM != "brandname" && len(endStrMap[nameM]) == 0 {
|
|
|
- endStrMap[nameM] = v1
|
|
|
+ //unitprice
|
|
|
+ if nameM == "unitprice" { //处理金额
|
|
|
+ v1tmp1 = dealPrice(k1, v1)[0]
|
|
|
+ }
|
|
|
+ if nameM != "brandname" && endStrMap[nameM] == "" {
|
|
|
+ endStrMap[nameM] = v1tmp1
|
|
|
}
|
|
|
strcount1++
|
|
|
}
|
|
|
}
|
|
|
//替换其它要保存字段
|
|
|
- for nameR, r := range brandRule["replace"] {
|
|
|
- if convert(k1, r) { //匹配成功
|
|
|
- endStrMap[nameR] = v1
|
|
|
- strcount2++
|
|
|
- }
|
|
|
- }
|
|
|
- //}
|
|
|
- }
|
|
|
- //原始字符串数据处理
|
|
|
- hasKey(table, strcount1) //是否匹配到table中的标题
|
|
|
- //qutil.Debug("endStrMap----", endStrMap)
|
|
|
- if strcount1 >= 1 {
|
|
|
- if strcount1+strcount2 == 1 { //删除只匹配到一个价钱(总价)
|
|
|
- delete(endStrMap, "unitprice")
|
|
|
- }
|
|
|
- finishData := dealStrData(endStrMap) //处理数据
|
|
|
- if len(finishData) > 0 {
|
|
|
- table.BrandData = append(table.BrandData, finishData)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (table *Table) analyBrand() {
|
|
|
- //5c2d8c05a5cb26b9b782572b
|
|
|
- //产品名称 品牌 规格 单价 单位 数量 小计 质保期
|
|
|
- lineMap := make(map[string]map[string]string)
|
|
|
- lineMapArr := make(map[string]map[string][]string)
|
|
|
- brandRule := u.BrandRules
|
|
|
- //将val为数组和string的分开
|
|
|
- //qutil.Debug("table.SortKV.Map====", table.SortKV.Map)
|
|
|
- for key, val := range table.SortKV.Map {
|
|
|
- key = regReplAllSpace.ReplaceAllString(key, "")
|
|
|
- key = strings.Replace(key, "", "", -1) //处理一个特殊的采购量 经上层处理空格后未处理掉
|
|
|
- if realTypeVal, ok := val.([]string); ok { //val为数组 {"数量":["1","2","3"]}
|
|
|
- /*
|
|
|
- {
|
|
|
- "商品":["",""],
|
|
|
- "商品_"["",""],
|
|
|
- }
|
|
|
-
|
|
|
- */
|
|
|
- // valArr, f := filterval(realTypeVal...)
|
|
|
- // if f {
|
|
|
- // qutil.Debug("----", key, valArr)
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // realTypeVal = valArr
|
|
|
- //hasGoods1(table, realTypeVal) //判断val中是否含产品
|
|
|
- //hasBrand1(table, realTypeVal) //判断val中是否含品牌
|
|
|
- line := underline.FindString(key)
|
|
|
- lineValMap := lineMapArr[line]
|
|
|
- //qutil.Debug("----", key, line, lineValMap)
|
|
|
- i := 1
|
|
|
- L:
|
|
|
- for { //去除数组空数据
|
|
|
- last := realTypeVal[len(realTypeVal)-i]
|
|
|
- if last == "" {
|
|
|
- i++
|
|
|
- if i > len(realTypeVal) {
|
|
|
- break
|
|
|
- }
|
|
|
- goto L
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- dislodgeNull := realTypeVal[:(len(realTypeVal) - i + 1)] //去除数组中空数据
|
|
|
- if len(lineValMap) == 0 && len(realTypeVal) != 0 { //没有数据
|
|
|
- lineMapArr[line] = map[string][]string{key: dislodgeNull}
|
|
|
- } else { //新增数据
|
|
|
- if len(dislodgeNull) != 0 {
|
|
|
- lineValMap[key] = dislodgeNull
|
|
|
- }
|
|
|
- }
|
|
|
- //qutil.Debug("lineMapArr---", lineMapArr)
|
|
|
- } else if realTypeVal, b := val.(string); b { //val为字符串 {"数量":"1"}
|
|
|
- /*
|
|
|
- {
|
|
|
- "商品:"",名称:"",
|
|
|
- "商品_:"",名称_:"",
|
|
|
- "商品__:"",名称__:"",
|
|
|
- }
|
|
|
- */
|
|
|
- // valArr, f := filterval(realTypeVal)
|
|
|
- // if f {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // realTypeVal = valArr[0]
|
|
|
- //hasGoods1(table, realTypeVal) //判断val中是否含产品
|
|
|
- //hasBrand1(table, realTypeVal) //判断val中是否含品牌
|
|
|
- line := underline.FindString(key)
|
|
|
- lineValMap := lineMap[line]
|
|
|
- if len(lineValMap) == 0 { //没有数据
|
|
|
- lineMap[line] = map[string]string{key: realTypeVal}
|
|
|
- } else {
|
|
|
- lineValMap[key] = realTypeVal
|
|
|
- }
|
|
|
- } else {
|
|
|
- // "_id" : ObjectId("5c2c3802a5cb26b9b78646c4")
|
|
|
- //成交供应商排名 [map[entname:昆明合优科技有限公司 sortstr:第一中标候选人 sort:1] map[sort:2 entname:昆明厚起科技有限公司 sortstr:第二中标候选人] map[entname:云南远安科技发展有限公司 sortstr:第三中标候选人 sort:3]]
|
|
|
- //fmt.Println("err data:", key, val)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //处理数组数据后,匹配必须title和替换要保存的title
|
|
|
- if len(lineMapArr) > 0 {
|
|
|
- for _, aMap := range lineMapArr {
|
|
|
- maxNum := 0
|
|
|
- arrcount1 := 0 //记录key是否存在必须title(数组数据)
|
|
|
- arrcount2 := 0
|
|
|
- ka := make(map[string][]string) //最终存储数据
|
|
|
- //fmt.Println("++++++++++++", aMap)
|
|
|
- for k0, v0 := range aMap {
|
|
|
- //qutil.Debug("k0:", k0, "v0:", v0, len(v0))
|
|
|
- //匹配必须title
|
|
|
- for nameM, r := range brandRule["must"] {
|
|
|
- if convert(k0, r) { //匹配成功
|
|
|
- if len(ka[nameM]) != 0 && strings.Contains(k0, "描述") { //防止k0匹配到多次 和特殊情况 物料名称 物料描述同时出现
|
|
|
- continue
|
|
|
- }
|
|
|
- if nameM == "itemname" || nameM == "modal" {
|
|
|
- if nameM == "itemname" {
|
|
|
- varr, f := filteritem(v0...) //过滤品目
|
|
|
- if f {
|
|
|
- break
|
|
|
- }
|
|
|
- v0 = varr
|
|
|
- }
|
|
|
- hasGoods(table, v0...) //判断itemname和modal中有没有商品
|
|
|
- }
|
|
|
- if nameM == "brandname" || nameM == "modal" {
|
|
|
- //qutil.Debug(nameM, "++++++", len(ka["brandname"]), len(v0))
|
|
|
- if len(ka["brandname"]) == 0 {
|
|
|
- brand, allNull := hasBrand(table, v0...)
|
|
|
- //qutil.Debug(len(brand), "-------", nameM, brand)
|
|
|
- if !allNull {
|
|
|
- ka["brandname"] = brand
|
|
|
- }
|
|
|
- //qutil.Debug("brandname====", len(ka["brandname"]), ka["brandname"])
|
|
|
+ if !match {
|
|
|
+ for nameR, r := range brandRule["replace"] {
|
|
|
+ if convert(k1, r) { //匹配成功
|
|
|
+ v1tmp2 := v1
|
|
|
+ //totalprice
|
|
|
+ if nameR == "totalprice" { //处理金额
|
|
|
+ v1tmp2 = dealPrice(k1, v1)[0]
|
|
|
}
|
|
|
- }
|
|
|
- if nameM != "brandname" {
|
|
|
- ka[nameM] = v0
|
|
|
- }
|
|
|
- arrcount1++
|
|
|
- }
|
|
|
- }
|
|
|
- //替换其它要保存字段
|
|
|
- for nameR, r := range brandRule["replace"] {
|
|
|
- if convert(k0, r) { //匹配成功
|
|
|
- ka[nameR] = v0
|
|
|
- arrcount2++
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //找最终存储数据的最小len(arr)
|
|
|
- // for _, vf := range ka {
|
|
|
- // //找最短的数组
|
|
|
- // lenVal := len(vf)
|
|
|
- // if minNum == 0 || minNum > lenVal { //maxNum = len(最短数组)
|
|
|
- // minNum = lenVal
|
|
|
- // }
|
|
|
- // }
|
|
|
- //找最终存储数据的最大len(arr),小的补空
|
|
|
- //fmt.Println("ka==============", ka)
|
|
|
- for _, vf1 := range ka {
|
|
|
- lenVal := len(vf1)
|
|
|
- if lenVal > maxNum {
|
|
|
- maxNum = lenVal
|
|
|
- }
|
|
|
- }
|
|
|
- finishKa := make(map[string][]string)
|
|
|
- for vf2K, vf2 := range ka {
|
|
|
- if len(vf2) < maxNum {
|
|
|
- lenMv := maxNum - len(vf2)
|
|
|
- for i := 0; i < lenMv; i++ {
|
|
|
- vf2 = append(vf2, "")
|
|
|
- }
|
|
|
- }
|
|
|
- finishKa[vf2K] = vf2
|
|
|
- }
|
|
|
- hasKey(table, arrcount1) //是否匹配到table中的标题
|
|
|
- if arrcount1 >= 1 {
|
|
|
- if arrcount1+arrcount2 == 1 { //删除只匹配到一个价钱(总价)
|
|
|
- delete(finishKa, "unitprice")
|
|
|
- }
|
|
|
- finishData := dealArrData(maxNum, finishKa)
|
|
|
- table.BrandData = append(table.BrandData, finishData)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //处理string数据后,匹配必须title和替换要保存的title
|
|
|
- if len(lineMap) > 0 {
|
|
|
- for _, sMap := range lineMap {
|
|
|
- strcount1 := 0 //记录key是否存在必须title(字符串数据)
|
|
|
- strcount2 := 0
|
|
|
- endStrMap := make(map[string]string)
|
|
|
- for k1, v1 := range sMap {
|
|
|
- //qutil.Debug(k1, "++++++++++", v1)
|
|
|
- //匹配必须title
|
|
|
- for nameM, r := range brandRule["must"] {
|
|
|
- if convert(k1, r) { //匹配成功
|
|
|
- if nameM == "itemname" || nameM == "modal" { //特殊处理itemname
|
|
|
- if nameM == "itemname" {
|
|
|
- varr, f := filteritem(v1) //过滤品目
|
|
|
- if f {
|
|
|
- break
|
|
|
+ //number
|
|
|
+ if nameR == "number" { //处理数量
|
|
|
+ varr1, uname1 := dealNumber(v1)
|
|
|
+ v1tmp2 = varr1[0]
|
|
|
+ //从number中获取到的单位
|
|
|
+ if endStrMap["unitname"] == "" && uname1[0] != "" {
|
|
|
+ endStrMap["unitname"] = uname1[0]
|
|
|
}
|
|
|
- v1 = varr[0]
|
|
|
}
|
|
|
- hasGoods(table, v1)
|
|
|
- }
|
|
|
- if nameM == "brandname" || nameM == "modal" { //特殊处理brandname
|
|
|
- if len(endStrMap["brandname"]) == 0 {
|
|
|
- brand, allNull := hasBrand(table, v1)
|
|
|
- if !allNull {
|
|
|
- endStrMap["brandname"] = brand[0]
|
|
|
- }
|
|
|
+ if v1tmp2 != "" {
|
|
|
+ endStrMap[nameR] = v1tmp2
|
|
|
}
|
|
|
+ strcount2++
|
|
|
}
|
|
|
- if nameM != "brandname" {
|
|
|
- endStrMap[nameM] = v1
|
|
|
- }
|
|
|
- strcount1++
|
|
|
- }
|
|
|
- }
|
|
|
- //替换其它要保存字段
|
|
|
- for nameR, r := range brandRule["replace"] {
|
|
|
- if convert(k1, r) { //匹配成功
|
|
|
- endStrMap[nameR] = v1
|
|
|
- strcount2++
|
|
|
}
|
|
|
}
|
|
|
+ //}
|
|
|
}
|
|
|
//原始字符串数据处理
|
|
|
hasKey(table, strcount1) //是否匹配到table中的标题
|
|
|
+ //qutil.Debug("endStrMap----", endStrMap)
|
|
|
if strcount1 >= 1 {
|
|
|
if strcount1+strcount2 == 1 { //删除只匹配到一个价钱(总价)
|
|
|
delete(endStrMap, "unitprice")
|
|
@@ -3201,13 +3015,13 @@ func assembleData(m interface{}, n int) []map[string]string {
|
|
|
datas[i] = data
|
|
|
}
|
|
|
//end
|
|
|
- // for _, fdv := range datas { //清除空数据和只含特殊符号的数据
|
|
|
- // for fmk, fmv := range fdv {
|
|
|
- // if tabletdclear.ReplaceAllString(fmv, "") == "" {
|
|
|
- // delete(fdv, fmk)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
+ for _, fdv := range datas { //清除空数据和只含特殊符号的数据
|
|
|
+ for fmk, fmv := range fdv {
|
|
|
+ if tabletdclear.ReplaceAllString(fmv, "") == "" {
|
|
|
+ delete(fdv, fmk)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} else { //字符串数据
|
|
|
realTypeM := m.(map[string]string)
|
|
|
datas = append(datas, realTypeM)
|
|
@@ -3281,6 +3095,7 @@ func assembleData(m interface{}, n int) []map[string]string {
|
|
|
//}
|
|
|
|
|
|
func convert(key, r string) bool {
|
|
|
+ defer qutil.Catch()
|
|
|
flag := false
|
|
|
key = tabletitleclear.ReplaceAllString(key, "")
|
|
|
reg, err := regexp.Compile(r)
|
|
@@ -3293,6 +3108,7 @@ func convert(key, r string) bool {
|
|
|
}
|
|
|
|
|
|
func hasKey(table *Table, n int) {
|
|
|
+ defer qutil.Catch()
|
|
|
if table.TableResult.HasKey == 1 {
|
|
|
return
|
|
|
}
|
|
@@ -3301,67 +3117,8 @@ func hasKey(table *Table, n int) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-////是否有商品
|
|
|
-//func hasGoods1(table *Table, data interface{}) {
|
|
|
-// if table.TableResult.HasGoods == 1 {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// sData, ok := data.(string)
|
|
|
-// proFlag := ""
|
|
|
-// if ok { //string数据检查goods
|
|
|
-// if sData != "" {
|
|
|
-// proFlag = u.GoodsGet.CheckSensitiveWord(sData)
|
|
|
-// if len(proFlag) > 0 {
|
|
|
-// table.TableResult.HasGoods = 1
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else { //arr数据检查goods
|
|
|
-// arrData := data.([]string)
|
|
|
-// if len(arrData) > 0 {
|
|
|
-// for _, src := range arrData {
|
|
|
-// if src != "" {
|
|
|
-// proFlag = u.GoodsGet.CheckSensitiveWord(src)
|
|
|
-// if len(proFlag) > 0 {
|
|
|
-// table.TableResult.HasGoods = 1
|
|
|
-// break
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
-////是否有品牌
|
|
|
-//func hasBrand1(table *Table, data interface{}) {
|
|
|
-// if table.TableResult.HasBrand == 1 {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// sData, ok := data.(string)
|
|
|
-// if ok { //string数据检查brand
|
|
|
-// if sData != "" {
|
|
|
-// brand := u.BrandGet.CheckSensitiveWord(sData)
|
|
|
-// if len(brand) > 0 {
|
|
|
-// fmt.Println("brand:", brand, sData)
|
|
|
-// table.TableResult.HasBrand = 1
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else { //arr数据检查brand
|
|
|
-// arrData := data.([]string)
|
|
|
-// if len(arrData) > 0 {
|
|
|
-// for _, src := range arrData {
|
|
|
-// if src != "" {
|
|
|
-// brand := u.BrandGet.CheckSensitiveWord(src)
|
|
|
-// if len(brand) > 0 {
|
|
|
-// table.TableResult.HasBrand = 1
|
|
|
-// break
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|
|
|
-
|
|
|
func hasGoods(table *Table, data ...string) {
|
|
|
+ defer qutil.Catch()
|
|
|
goodsArr := make([]string, len(data))
|
|
|
//fmt.Println("table.TableResult.HasGoods=====", table.TableResult.HasGoods)
|
|
|
if table.TableResult.HasGoods == 1 {
|
|
@@ -3380,6 +3137,7 @@ func hasGoods(table *Table, data ...string) {
|
|
|
}
|
|
|
}
|
|
|
func hasBrand(table *Table, data ...string) ([]string, bool) {
|
|
|
+ defer qutil.Catch()
|
|
|
//fmt.Println("table.TableResult.HasBrand---------", table.TableResult.HasBrand)
|
|
|
brandArr := make([]string, len(data))
|
|
|
// if table.TableResult.HasBrand == 1 {
|
|
@@ -3404,6 +3162,7 @@ func hasBrand(table *Table, data ...string) ([]string, bool) {
|
|
|
|
|
|
//过滤td值
|
|
|
func filterval(val ...string) ([]string, bool) {
|
|
|
+ defer qutil.Catch()
|
|
|
flag := false
|
|
|
for i, v := range val {
|
|
|
afterFilter := tabletdclear.ReplaceAllString(v, "")
|
|
@@ -3418,17 +3177,340 @@ func filterval(val ...string) ([]string, bool) {
|
|
|
return val, flag
|
|
|
}
|
|
|
|
|
|
-//过滤错误的品目值
|
|
|
-func filteritem(itemval ...string) ([]string, bool) {
|
|
|
- flag := false
|
|
|
- for i, v := range itemval {
|
|
|
- afterFilter := itemclear.ReplaceAllString(v, "")
|
|
|
- if afterFilter == "" {
|
|
|
- flag = true
|
|
|
+//过滤itemname全是数字
|
|
|
+func filteritem(itemval ...string) []string {
|
|
|
+ defer qutil.Catch()
|
|
|
+ result := []string{}
|
|
|
+ for _, v := range itemval {
|
|
|
+ afterFilter := numclear.ReplaceAllString(v, "")
|
|
|
+ if afterFilter != "" {
|
|
|
+ result = append(result, v)
|
|
|
} else {
|
|
|
- flag = false
|
|
|
+ result = append(result, afterFilter)
|
|
|
}
|
|
|
- itemval[i] = afterFilter
|
|
|
}
|
|
|
- return itemval, flag
|
|
|
+ return result
|
|
|
}
|
|
|
+
|
|
|
+//处理价格
|
|
|
+func dealPrice(key string, val ...string) []string {
|
|
|
+ defer qutil.Catch()
|
|
|
+ iswan := strings.Contains(key, "万") //表格title中带有万
|
|
|
+ result := []string{}
|
|
|
+ for _, v := range val { //1.00万元 1元
|
|
|
+ tmparr := strings.Split(v, ".")
|
|
|
+ tmparr[0] = moneyNum.ReplaceAllString(tmparr[0], "")
|
|
|
+ if iswan {
|
|
|
+ result = append(result, tmparr[0]+"0000")
|
|
|
+ } else {
|
|
|
+ if strings.Contains(v, "万") { //价格中带有万
|
|
|
+ result = append(result, tmparr[0]+"0000")
|
|
|
+ } else {
|
|
|
+ result = append(result, tmparr[0])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+//处理number
|
|
|
+func dealNumber(val ...string) ([]string, []string) {
|
|
|
+ defer qutil.Catch()
|
|
|
+ unitnameArr := []string{}
|
|
|
+ result := []string{}
|
|
|
+ for _, v := range val { //1个 1.00个
|
|
|
+ n := numclear.FindString(v)
|
|
|
+ unitname := numclear.ReplaceAllString(v, "") //匹配个数后的单位
|
|
|
+ unitnameArr = append(unitnameArr, unitname)
|
|
|
+ //val[i] = strings.Split(n, ".")[0]
|
|
|
+ result = append(result, strings.Split(n, ".")[0])
|
|
|
+ }
|
|
|
+ return result, unitnameArr
|
|
|
+}
|
|
|
+
|
|
|
+//func (table *Table) analyBrand() {
|
|
|
+// //5c2d8c05a5cb26b9b782572b
|
|
|
+// //产品名称 品牌 规格 单价 单位 数量 小计 质保期
|
|
|
+// lineMap := make(map[string]map[string]string)
|
|
|
+// lineMapArr := make(map[string]map[string][]string)
|
|
|
+// brandRule := u.BrandRules
|
|
|
+// //将val为数组和string的分开
|
|
|
+// //qutil.Debug("table.SortKV.Map====", table.SortKV.Map)
|
|
|
+// for key, val := range table.SortKV.Map {
|
|
|
+// key = regReplAllSpace.ReplaceAllString(key, "")
|
|
|
+// key = strings.Replace(key, "", "", -1) //处理一个特殊的采购量 经上层处理空格后未处理掉
|
|
|
+// if realTypeVal, ok := val.([]string); ok { //val为数组 {"数量":["1","2","3"]}
|
|
|
+// /*
|
|
|
+// {
|
|
|
+// "商品":["",""],
|
|
|
+// "商品_"["",""],
|
|
|
+// }
|
|
|
+
|
|
|
+// */
|
|
|
+// // valArr, f := filterval(realTypeVal...)
|
|
|
+// // if f {
|
|
|
+// // qutil.Debug("----", key, valArr)
|
|
|
+// // continue
|
|
|
+// // }
|
|
|
+// // realTypeVal = valArr
|
|
|
+// //hasGoods1(table, realTypeVal) //判断val中是否含产品
|
|
|
+// //hasBrand1(table, realTypeVal) //判断val中是否含品牌
|
|
|
+// line := underline.FindString(key)
|
|
|
+// lineValMap := lineMapArr[line]
|
|
|
+// //qutil.Debug("----", key, line, lineValMap)
|
|
|
+// i := 1
|
|
|
+// L:
|
|
|
+// for { //去除数组空数据
|
|
|
+// last := realTypeVal[len(realTypeVal)-i]
|
|
|
+// if last == "" {
|
|
|
+// i++
|
|
|
+// if i > len(realTypeVal) {
|
|
|
+// break
|
|
|
+// }
|
|
|
+// goto L
|
|
|
+// } else {
|
|
|
+// break
|
|
|
+// }
|
|
|
+// }
|
|
|
+// dislodgeNull := realTypeVal[:(len(realTypeVal) - i + 1)] //去除数组中空数据
|
|
|
+// if len(lineValMap) == 0 && len(realTypeVal) != 0 { //没有数据
|
|
|
+// lineMapArr[line] = map[string][]string{key: dislodgeNull}
|
|
|
+// } else { //新增数据
|
|
|
+// if len(dislodgeNull) != 0 {
|
|
|
+// lineValMap[key] = dislodgeNull
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //qutil.Debug("lineMapArr---", lineMapArr)
|
|
|
+// } else if realTypeVal, b := val.(string); b { //val为字符串 {"数量":"1"}
|
|
|
+// /*
|
|
|
+// {
|
|
|
+// "商品:"",名称:"",
|
|
|
+// "商品_:"",名称_:"",
|
|
|
+// "商品__:"",名称__:"",
|
|
|
+// }
|
|
|
+// */
|
|
|
+// // valArr, f := filterval(realTypeVal)
|
|
|
+// // if f {
|
|
|
+// // continue
|
|
|
+// // }
|
|
|
+// // realTypeVal = valArr[0]
|
|
|
+// //hasGoods1(table, realTypeVal) //判断val中是否含产品
|
|
|
+// //hasBrand1(table, realTypeVal) //判断val中是否含品牌
|
|
|
+// line := underline.FindString(key)
|
|
|
+// lineValMap := lineMap[line]
|
|
|
+// if len(lineValMap) == 0 { //没有数据
|
|
|
+// lineMap[line] = map[string]string{key: realTypeVal}
|
|
|
+// } else {
|
|
|
+// lineValMap[key] = realTypeVal
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // "_id" : ObjectId("5c2c3802a5cb26b9b78646c4")
|
|
|
+// //成交供应商排名 [map[entname:昆明合优科技有限公司 sortstr:第一中标候选人 sort:1] map[sort:2 entname:昆明厚起科技有限公司 sortstr:第二中标候选人] map[entname:云南远安科技发展有限公司 sortstr:第三中标候选人 sort:3]]
|
|
|
+// //fmt.Println("err data:", key, val)
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// //处理数组数据后,匹配必须title和替换要保存的title
|
|
|
+// if len(lineMapArr) > 0 {
|
|
|
+// for _, aMap := range lineMapArr {
|
|
|
+// maxNum := 0
|
|
|
+// arrcount1 := 0 //记录key是否存在必须title(数组数据)
|
|
|
+// arrcount2 := 0
|
|
|
+// ka := make(map[string][]string) //最终存储数据
|
|
|
+// //fmt.Println("++++++++++++", aMap)
|
|
|
+// for k0, v0 := range aMap {
|
|
|
+// //qutil.Debug("k0:", k0, "v0:", v0, len(v0))
|
|
|
+// //匹配必须title
|
|
|
+// for nameM, r := range brandRule["must"] {
|
|
|
+// if convert(k0, r) { //匹配成功
|
|
|
+// if len(ka[nameM]) != 0 && strings.Contains(k0, "描述") { //防止k0匹配到多次 和特殊情况 物料名称 物料描述同时出现
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// if nameM == "itemname" || nameM == "modal" {
|
|
|
+// if nameM == "itemname" {
|
|
|
+// varr, f := filteritem(v0...) //过滤品目
|
|
|
+// if f {
|
|
|
+// break
|
|
|
+// }
|
|
|
+// v0 = varr
|
|
|
+// }
|
|
|
+// hasGoods(table, v0...) //判断itemname和modal中有没有商品
|
|
|
+// }
|
|
|
+// if nameM == "brandname" || nameM == "modal" {
|
|
|
+// //qutil.Debug(nameM, "++++++", len(ka["brandname"]), len(v0))
|
|
|
+// if len(ka["brandname"]) == 0 {
|
|
|
+// brand, allNull := hasBrand(table, v0...)
|
|
|
+// //qutil.Debug(len(brand), "-------", nameM, brand)
|
|
|
+// if !allNull {
|
|
|
+// ka["brandname"] = brand
|
|
|
+// }
|
|
|
+// //qutil.Debug("brandname====", len(ka["brandname"]), ka["brandname"])
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if nameM != "brandname" {
|
|
|
+// ka[nameM] = v0
|
|
|
+// }
|
|
|
+// arrcount1++
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //替换其它要保存字段
|
|
|
+// for nameR, r := range brandRule["replace"] {
|
|
|
+// if convert(k0, r) { //匹配成功
|
|
|
+// ka[nameR] = v0
|
|
|
+// arrcount2++
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //找最终存储数据的最小len(arr)
|
|
|
+// // for _, vf := range ka {
|
|
|
+// // //找最短的数组
|
|
|
+// // lenVal := len(vf)
|
|
|
+// // if minNum == 0 || minNum > lenVal { //maxNum = len(最短数组)
|
|
|
+// // minNum = lenVal
|
|
|
+// // }
|
|
|
+// // }
|
|
|
+// //找最终存储数据的最大len(arr),小的补空
|
|
|
+// //fmt.Println("ka==============", ka)
|
|
|
+// for _, vf1 := range ka {
|
|
|
+// lenVal := len(vf1)
|
|
|
+// if lenVal > maxNum {
|
|
|
+// maxNum = lenVal
|
|
|
+// }
|
|
|
+// }
|
|
|
+// finishKa := make(map[string][]string)
|
|
|
+// for vf2K, vf2 := range ka {
|
|
|
+// if len(vf2) < maxNum {
|
|
|
+// lenMv := maxNum - len(vf2)
|
|
|
+// for i := 0; i < lenMv; i++ {
|
|
|
+// vf2 = append(vf2, "")
|
|
|
+// }
|
|
|
+// }
|
|
|
+// finishKa[vf2K] = vf2
|
|
|
+// }
|
|
|
+// hasKey(table, arrcount1) //是否匹配到table中的标题
|
|
|
+// if arrcount1 >= 1 {
|
|
|
+// if arrcount1+arrcount2 == 1 { //删除只匹配到一个价钱(总价)
|
|
|
+// delete(finishKa, "unitprice")
|
|
|
+// }
|
|
|
+// finishData := dealArrData(maxNum, finishKa)
|
|
|
+// table.BrandData = append(table.BrandData, finishData)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //处理string数据后,匹配必须title和替换要保存的title
|
|
|
+// if len(lineMap) > 0 {
|
|
|
+// for _, sMap := range lineMap {
|
|
|
+// strcount1 := 0 //记录key是否存在必须title(字符串数据)
|
|
|
+// strcount2 := 0
|
|
|
+// endStrMap := make(map[string]string)
|
|
|
+// for k1, v1 := range sMap {
|
|
|
+// //qutil.Debug(k1, "++++++++++", v1)
|
|
|
+// //匹配必须title
|
|
|
+// for nameM, r := range brandRule["must"] {
|
|
|
+// if convert(k1, r) { //匹配成功
|
|
|
+// if nameM == "itemname" || nameM == "modal" { //特殊处理itemname
|
|
|
+// if nameM == "itemname" {
|
|
|
+// varr, f := filteritem(v1) //过滤品目
|
|
|
+// if f {
|
|
|
+// break
|
|
|
+// }
|
|
|
+// v1 = varr[0]
|
|
|
+// }
|
|
|
+// hasGoods(table, v1)
|
|
|
+// }
|
|
|
+// if nameM == "brandname" || nameM == "modal" { //特殊处理brandname
|
|
|
+// if len(endStrMap["brandname"]) == 0 {
|
|
|
+// brand, allNull := hasBrand(table, v1)
|
|
|
+// if !allNull {
|
|
|
+// endStrMap["brandname"] = brand[0]
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if nameM != "brandname" {
|
|
|
+// endStrMap[nameM] = v1
|
|
|
+// }
|
|
|
+// strcount1++
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //替换其它要保存字段
|
|
|
+// for nameR, r := range brandRule["replace"] {
|
|
|
+// if convert(k1, r) { //匹配成功
|
|
|
+// endStrMap[nameR] = v1
|
|
|
+// strcount2++
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //原始字符串数据处理
|
|
|
+// hasKey(table, strcount1) //是否匹配到table中的标题
|
|
|
+// if strcount1 >= 1 {
|
|
|
+// if strcount1+strcount2 == 1 { //删除只匹配到一个价钱(总价)
|
|
|
+// delete(endStrMap, "unitprice")
|
|
|
+// }
|
|
|
+// finishData := dealStrData(endStrMap) //处理数据
|
|
|
+// if len(finishData) > 0 {
|
|
|
+// table.BrandData = append(table.BrandData, finishData)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
+////是否有商品
|
|
|
+//func hasGoods1(table *Table, data interface{}) {
|
|
|
+// if table.TableResult.HasGoods == 1 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// sData, ok := data.(string)
|
|
|
+// proFlag := ""
|
|
|
+// if ok { //string数据检查goods
|
|
|
+// if sData != "" {
|
|
|
+// proFlag = u.GoodsGet.CheckSensitiveWord(sData)
|
|
|
+// if len(proFlag) > 0 {
|
|
|
+// table.TableResult.HasGoods = 1
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else { //arr数据检查goods
|
|
|
+// arrData := data.([]string)
|
|
|
+// if len(arrData) > 0 {
|
|
|
+// for _, src := range arrData {
|
|
|
+// if src != "" {
|
|
|
+// proFlag = u.GoodsGet.CheckSensitiveWord(src)
|
|
|
+// if len(proFlag) > 0 {
|
|
|
+// table.TableResult.HasGoods = 1
|
|
|
+// break
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
+////是否有品牌
|
|
|
+//func hasBrand1(table *Table, data interface{}) {
|
|
|
+// if table.TableResult.HasBrand == 1 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// sData, ok := data.(string)
|
|
|
+// if ok { //string数据检查brand
|
|
|
+// if sData != "" {
|
|
|
+// brand := u.BrandGet.CheckSensitiveWord(sData)
|
|
|
+// if len(brand) > 0 {
|
|
|
+// fmt.Println("brand:", brand, sData)
|
|
|
+// table.TableResult.HasBrand = 1
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else { //arr数据检查brand
|
|
|
+// arrData := data.([]string)
|
|
|
+// if len(arrData) > 0 {
|
|
|
+// for _, src := range arrData {
|
|
|
+// if src != "" {
|
|
|
+// brand := u.BrandGet.CheckSensitiveWord(src)
|
|
|
+// if len(brand) > 0 {
|
|
|
+// table.TableResult.HasBrand = 1
|
|
|
+// break
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|