|
@@ -20,12 +20,14 @@ import (
|
|
|
var (
|
|
|
//清理品目中数字
|
|
|
numclear = regexp.MustCompile("^[\\d一二三四五六七八九十.]+")
|
|
|
+ num1 = regexp.MustCompile("(\\d)")
|
|
|
//清理表格title中的不需要的内容
|
|
|
- tabletitleclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n、.,.。、_/((人民币万元件个公斤))]")
|
|
|
+ tabletitleclear = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n\u001c、.,.。、_/((人民币万元件个公斤))]")
|
|
|
+ tabletitleclear2 = regexp.MustCompile("[\\s\u3000\u2003\u00a0\\n\u001c、,。_??;;~\\-#\\\\()(){}【】\\[\\]<>《》{}〔〕]*")
|
|
|
//清理表格中是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\u001c、,。、_??;;~\\-#\\\\()(){}【】\\[\\]<>《》{}〔〕¥$]*")
|
|
|
//判断key是金额,对万元的处理
|
|
|
moneyreg = regexp.MustCompile("(预算|费|价|额|规模|投资)")
|
|
|
//根据表格的内容判断是不是表头,如果含有金额则不是表头
|
|
@@ -653,6 +655,14 @@ func (table *Table) MergerToTableresult() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //抽取prince和number 并列table
|
|
|
+ if len(table.PriceNumberData) > 0 {
|
|
|
+ for _, v := range table.PriceNumberData {
|
|
|
+ if len(v) > 0 {
|
|
|
+ table.TableResult.PriceNumberData = append(table.TableResult.PriceNumberData, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if table.BlockPackage != nil && len(table.BlockPackage.Keys) == 0 {
|
|
|
for _, v := range table.BlockPackage.Keys {
|
|
|
if table.BlockPackage.Map[v] != nil {
|
|
@@ -884,6 +894,11 @@ func (tn *Table) AnalyTables(contactFormat *u.ContactFormat, isSite bool, codeSi
|
|
|
if u.IsBrandGoods {
|
|
|
table.analyBrand()
|
|
|
}
|
|
|
+ //table中抽取单价和个数
|
|
|
+ if u.IsPriceNumber {
|
|
|
+ //qutil.Debug("======================抽取price和number===========")
|
|
|
+ table.extractPriceNumber()
|
|
|
+ }
|
|
|
res, _, _, _, _ := CheckCommon(table.Tag, "abandontable")
|
|
|
if !res {
|
|
|
//过滤、标准化、合并kv,table.StandKV,table.StandKVWeight
|
|
@@ -2167,7 +2182,7 @@ func (tn *Table) manyPackageProcessByIndex(index []string, standIndex_pos []int,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if k1 == "单价"{
|
|
|
+ if k1 == "单价" {
|
|
|
continue
|
|
|
}
|
|
|
tn.assemblePackage(k1, v, sv2, isSite, codeSite)
|
|
@@ -3192,6 +3207,176 @@ func (tn *Table) tdkv(td *TD) []*u.Kv {
|
|
|
return thisTdKvs
|
|
|
}
|
|
|
|
|
|
+func (table *Table) extractPriceNumber() {
|
|
|
+ lineMapArr := make(map[string]*SortMap)
|
|
|
+ lineMap := make(map[string]*SortMap)
|
|
|
+ lineMapArr, lineMap = initLineMapLineMapArr(table) //不同数据类型的数据组合
|
|
|
+ //qutil.Debug("lineMapArr----", lineMapArr)
|
|
|
+ if len(lineMapArr) > 0 {
|
|
|
+ for _, arrMap := range lineMapArr {
|
|
|
+ resultArrMap := table.matchMapArrPrinceNumber(arrMap) //最终数据
|
|
|
+ //qutil.Debug("resultArrMap-------------------", resultArrMap)
|
|
|
+ //处理数组长度不一致情况
|
|
|
+ if len(resultArrMap) > 0 {
|
|
|
+ numLen := len(resultArrMap["number"])
|
|
|
+ priceLen := len(resultArrMap["price"])
|
|
|
+ itemLen := len(resultArrMap["item"])
|
|
|
+ maxNum := numLen //获取最大长度
|
|
|
+ if numLen == 0 { //没有
|
|
|
+ maxNum = priceLen
|
|
|
+ }
|
|
|
+ //取个数数据的长度为基准(数据长度可能不一致)
|
|
|
+ if numLen != priceLen && numLen > 0 && priceLen > 0 { //有number和price数据且长度不同,进行数据增减补齐
|
|
|
+ if priceLen > numLen { //price多,删
|
|
|
+ tmpArr := resultArrMap["price"]
|
|
|
+ resultArrMap["price"] = tmpArr[:numLen]
|
|
|
+ } else if priceLen < numLen { //price少,补空
|
|
|
+ for {
|
|
|
+ resultArrMap["price"] = append(resultArrMap["price"], "")
|
|
|
+ //qutil.Debug("=============price==============")
|
|
|
+ if len(resultArrMap["price"]) == numLen {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if maxNum > 0 && itemLen > 0 && maxNum != itemLen { //有price或者number,item长度保持一致
|
|
|
+ if itemLen > maxNum {
|
|
|
+ tmpArr := resultArrMap["item"]
|
|
|
+ resultArrMap["item"] = tmpArr[:maxNum]
|
|
|
+ } else if itemLen < maxNum {
|
|
|
+ for {
|
|
|
+ resultArrMap["item"] = append(resultArrMap["item"], "")
|
|
|
+ //qutil.Debug("=============item==============")
|
|
|
+ if len(resultArrMap["item"]) == maxNum {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //封装成一一对应数据
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "price" :["123","125"],
|
|
|
+ "number" :["1","12"]
|
|
|
+ }
|
|
|
+ 转换为:
|
|
|
+ [
|
|
|
+ {"price":"123","number":"1"},
|
|
|
+ {"price":"125","number":"12"}
|
|
|
+ ]
|
|
|
+ */
|
|
|
+ finishData := []map[string]interface{}{}
|
|
|
+ //qutil.Debug("maxNum--------------------", maxNum)
|
|
|
+ for t := 0; t < maxNum; t++ {
|
|
|
+ tmpMap := make(map[string]interface{})
|
|
|
+ if len(resultArrMap["number"]) > 0 {
|
|
|
+ number := resultArrMap["number"][t]
|
|
|
+ tmpMap["number"] = number
|
|
|
+ }
|
|
|
+ if len(resultArrMap["price"]) > 0 {
|
|
|
+ price := resultArrMap["price"][t]
|
|
|
+ tmpMap["price"] = price
|
|
|
+ }
|
|
|
+ if len(resultArrMap["item"]) > 0 {
|
|
|
+ item := resultArrMap["item"][t]
|
|
|
+ runeItem := []rune(qutil.ObjToString(item))
|
|
|
+ if len(runeItem) > 50 {
|
|
|
+ tmpMap["item"] = string(runeItem[:50])
|
|
|
+ } else {
|
|
|
+ tmpMap["item"] = item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finishData = append(finishData, tmpMap)
|
|
|
+ }
|
|
|
+ //qutil.Debug(finishData)
|
|
|
+ if len(finishData) > 0 {
|
|
|
+ table.PriceNumberData = append(table.PriceNumberData, finishData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(lineMap) > 0 {
|
|
|
+ for _, strMap := range lineMap {
|
|
|
+ resultStrMap := table.matchMapPrinceNumber(strMap)
|
|
|
+ //qutil.Debug("resultStrMap---", resultStrMap)
|
|
|
+ if len(resultStrMap) > 0 {
|
|
|
+ if resultStrMap["price"] != nil || resultStrMap["number"] != nil { //有price或者number在保存
|
|
|
+ if item := qutil.ObjToString(resultStrMap["item"]); item != "" { //item过长截取
|
|
|
+ runeItem := []rune(item)
|
|
|
+ if len(runeItem) > 50 {
|
|
|
+ resultStrMap["item"] = string(runeItem[:50])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finishData := []map[string]interface{}{}
|
|
|
+ finishData = append(finishData, resultStrMap)
|
|
|
+ //qutil.Debug("finishData---", finishData)
|
|
|
+ if len(finishData) > 0 {
|
|
|
+ table.PriceNumberData = append(table.PriceNumberData, finishData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //qutil.Debug("table.PriceNumberData---------", table.PriceNumberData)
|
|
|
+}
|
|
|
+
|
|
|
+//数组数据抽取price和number
|
|
|
+func (table *Table) matchMapArrPrinceNumber(arrMap *SortMap) map[string][]interface{} {
|
|
|
+ result := make(map[string][]interface{}) //最终存储数据
|
|
|
+ for _, key := range arrMap.Keys {
|
|
|
+ val := arrMap.Map[key].([]string)
|
|
|
+ for f, reg := range u.PriceNumberReg {
|
|
|
+ key = tabletitleclear2.ReplaceAllString(key, "") //过滤
|
|
|
+ if reg.MatchString(key) { //匹配成功
|
|
|
+ //qutil.Debug("arr----key", key, val, f)
|
|
|
+ tmp := []interface{}{}
|
|
|
+ if f == "price" {
|
|
|
+ tmp = dealPriceInterface(key, val...) //处理金额,单位转换
|
|
|
+ } else if f == "number" {
|
|
|
+ tmp = dealNumberInterface(val...) //处理数量
|
|
|
+ } else {
|
|
|
+ for _, v := range val {
|
|
|
+ tmp = append(tmp, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(tmp) > 0 {
|
|
|
+ result[f] = tmp
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+//字符串数据抽取price和number
|
|
|
+func (table *Table) matchMapPrinceNumber(strMap *SortMap) map[string]interface{} {
|
|
|
+ result := make(map[string]interface{})
|
|
|
+ for _, key := range strMap.Keys {
|
|
|
+ val := qutil.ObjToString(strMap.Map[key])
|
|
|
+ for f, reg := range u.PriceNumberReg {
|
|
|
+ key = tabletitleclear2.ReplaceAllString(key, "") //过滤
|
|
|
+ if reg.MatchString(key) { //匹配成功
|
|
|
+ //qutil.Debug("str----key", key, val)
|
|
|
+ if f == "price" {
|
|
|
+ if len(regHz.FindAllString(val, -1)) > 5 { //price中汉字过多视为内容错误
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ tmp := dealPriceInterface(key, val)[0] //处理金额,单位转换
|
|
|
+ result[f] = tmp
|
|
|
+ } else if f == "number" {
|
|
|
+ tmp := dealNumberInterface(val)[0]
|
|
|
+ result[f] = tmp
|
|
|
+ } else {
|
|
|
+ result[f] = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
//table中抽取品牌,table.BrandData
|
|
|
func (table *Table) analyBrand() {
|
|
|
//5c2d8c05a5cb26b9b782572b
|
|
@@ -3247,7 +3432,7 @@ func (table *Table) analyBrand() {
|
|
|
delete(finishKa, "unitprice")
|
|
|
}
|
|
|
finishData := dealArrData(maxNum, finishKa)
|
|
|
- table.BrandData = append(table.BrandData, finishData) //存储了table.BrandData
|
|
|
+ table.BrandData = append(table.BrandData, finishData) //存储table.BrandData
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -3422,6 +3607,7 @@ func initLineMapLineMapArr(table *Table) (lineMapArr map[string]*SortMap, lineMa
|
|
|
val := table.SortKV.Map[key]
|
|
|
key = regReplAllSpace.ReplaceAllString(key, "")
|
|
|
key = strings.Replace(key, "", "", -1) //处理一个特殊的采购量 经上层处理空格后未处理掉
|
|
|
+ //qutil.Debug(key, "---------------------------", val)
|
|
|
if realTypeVal, ok := val.([]string); ok { //val为数组 {"数量":["1","2","3"]}
|
|
|
/*
|
|
|
{
|
|
@@ -3762,23 +3948,66 @@ func filterItem(itemval ...string) []string {
|
|
|
}
|
|
|
|
|
|
//处理价格
|
|
|
-func dealPrice(key string, val ...string) []string {
|
|
|
+func dealPriceInterface(key string, val ...string) (result []interface{}) {
|
|
|
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])
|
|
|
+ for _, v := range val {
|
|
|
+ if num1.MatchString(v) { //含数字
|
|
|
+ tdIsWan := strings.Contains(v, "万")
|
|
|
+ if !tdIsWan {
|
|
|
+ if strings.Contains(key, "万") {
|
|
|
+ v = v + "万"
|
|
|
+ }
|
|
|
}
|
|
|
+ data := []interface{}{v, ""}
|
|
|
+ money := clear.ObjToMoney(data)[0]
|
|
|
+ result = append(result, money)
|
|
|
+ } else {
|
|
|
+ result = append(result, "")
|
|
|
}
|
|
|
}
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//处理number
|
|
|
+func dealNumberInterface(val ...string) (result []interface{}) {
|
|
|
+ defer qutil.Catch()
|
|
|
+ for _, v := range val { //1个 1.00个
|
|
|
+ n := numclear.FindString(v)
|
|
|
+ if n == "" {
|
|
|
+ result = append(result, "")
|
|
|
+ } else if tmp := clear.NumChar[n]; tmp != nil { //一二三...
|
|
|
+ result = append(result, tmp)
|
|
|
+ } else { //数字
|
|
|
+ result = append(result, qutil.IntAll(strings.Split(n, ".")[0]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//处理价格
|
|
|
+func dealPrice(key string, val ...string) []string {
|
|
|
+ defer qutil.Catch()
|
|
|
+ result := []string{}
|
|
|
+ for _, v := range val {
|
|
|
+ data := []interface{}{v, key}
|
|
|
+ money := clear.ObjToMoney(data)[0]
|
|
|
+ result = append(result, fmt.Sprintf("%v", money))
|
|
|
+ }
|
|
|
+
|
|
|
+ // result := []string{}
|
|
|
+ // for _, v := range val { //1.00万元 1元 2.25元/斤
|
|
|
+ // tmparr := strings.Split(v, ".")
|
|
|
+ // tmparr[0] = moneyNum.ReplaceAllString(tmparr[0], "")
|
|
|
+ // if iswan {
|
|
|
+ // result = append(result, tmparr[0]+"0000")
|
|
|
+ // } else { //td val值带万
|
|
|
+ // if strings.Contains(v, "万") { //价格中带有万
|
|
|
+ // result = append(result, tmparr[0]+"0000")
|
|
|
+ // } else {
|
|
|
+ // result = append(result, tmparr[0])
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
return result
|
|
|
}
|
|
|
|