maxiaoshan 4 tahun lalu
induk
melakukan
3f1a5b2e60
3 mengubah file dengan 253 tambahan dan 94 penghapusan
  1. 23 6
      src/config.json
  2. 167 82
      src/front/front.go
  3. 63 6
      src/web/templates/list.html

+ 23 - 6
src/config.json

@@ -256,10 +256,6 @@
             }
         ],
         "other": [
-            {
-                "key": "item",
-                "descript": "品目"
-            },
             {
                 "key": "contractname",
                 "descript": "合同名称"
@@ -359,6 +355,27 @@
 		"标签": "tagname",
 		"附加词": "tagname",
 		"信息匹配词": "matchkey",
-		"附件": "filetext"
-	}
+		"附件": "filetext",
+        "创建时间": "createtime",
+        "历史任务id": "historyId",
+        "部门id": "departid",
+        "规则id": "ruleid",
+        "部门名称": "departname",
+        "规则名称": "rulename",
+        "企业客户id": "appid",
+        "采购单位社会征信代码": "buyer_credit_no",
+        "医院等级": "rank",
+        "中标企业社会征信代码": "winner_credit_no",
+        "中标企业注册地址": "company_address",
+        "注册资金(万元)": "capital",
+        "注册时间": "establish_date",
+        "经营范围": "business_scope",
+        "股东名单": "stock_name",
+        "中标企业联系人": "legal_person",
+        "中标企业邮箱": "company_email",
+        "中标企业联系电话": "company_phone",
+        "规则分发依靠字段": "item",
+        "多规则分发依靠字段": "itemdist",
+        "企业id列表": "entidlist"
+    }
 }

+ 167 - 82
src/front/front.go

@@ -37,6 +37,7 @@ type Front struct {
 	importByEs    xweb.Mapper `xweb:"/importbyes"`
 	getEsCount    xweb.Mapper `xweb:"/getescount"`
 	finishCheck   xweb.Mapper `xweb:"/finishcheck"`
+	syncMarked    xweb.Mapper `xweb:"/syncmarked"`
 }
 
 //var IdList *list.List //所有数据
@@ -343,10 +344,9 @@ func (i *Front) Biaozhu() error {
 				errset[f] = (*data)[f]
 			}
 		}
-		if len(errset) > 0 {
-			//qu.Debug("errset---", errset)
-			errUpdata["$set"] = errset
-		}
+		//qu.Debug("errset---", errset)
+		errset["updatetime"] = time.Now().Unix()
+		errUpdata["$set"] = errset
 	}
 	if len(unerrset) > 0 {
 		//qu.Debug("unerrset---", unerrset)
@@ -360,6 +360,7 @@ func (i *Front) Biaozhu() error {
 	update := map[string]interface{}{}
 	if len(set) > 0 {
 		set["ck_data"] = stype
+		set["updatetime"] = time.Now().Unix()
 		update["$set"] = set
 	}
 	if len(unset) > 0 {
@@ -449,11 +450,11 @@ func (i *Front) ImportByExcel() {
 		for rn, row := range rows {
 			if rn == 0 {
 				for j, cell := range row.Cells {
-					val := cell.Value
-					if fieldName := util.Config.CustomerField[val]; fieldName != "" { //客户需求字段
+					title := cell.Value
+					if fieldName := util.Config.CustomerField[title]; fieldName != "" { //客户需求字段
 						cellFieldName[j] = fieldName
 					}
-					if val == "唯一标识" || val == "信息标识" { //id所在列
+					if title == "唯一标识" || title == "信息标识" { //id所在列
 						idcolnum = j
 					}
 				}
@@ -462,12 +463,22 @@ func (i *Front) ImportByExcel() {
 				}
 				continue
 			}
-			if len(row.Cells) != len(rows[0].Cells) {
+			if len(row.Cells) < len(rows[0].Cells) {
 				break
 			}
 			tmp := map[string]interface{}{}
 			for j, f := range cellFieldName {
-				tmp[f] = row.Cells[j].Value
+				if val := row.Cells[j].Value; val != "" {
+					if f == "capital" { //注册资金(万元)
+						cf, _ := row.Cells[j].Float()
+						tmp[f] = cf
+					} else if f == "createtime" { //创建时间
+						ci, _ := row.Cells[j].Int64()
+						tmp[f] = ci
+					} else {
+						tmp[f] = val
+					}
+				}
 			}
 			id := row.Cells[idcolnum].String() //加密的id
 			if id == "" {
@@ -480,6 +491,8 @@ func (i *Front) ImportByExcel() {
 		importNum = len(ids) //excel表数据个数
 		if importNum > 0 {
 			_, msg, successNum = GetDataById(coll, ids, "excel", tmpMap)
+			tmpMap = map[string]map[string]interface{}{}
+			ids = []string{}
 		}
 	}
 	msg = fmt.Sprintf("共查询%d条,导入成功%d条\n", importNum, successNum) + msg
@@ -590,63 +603,55 @@ func (i *Front) ImportByEs() {
 	i.ServeJson(map[string]interface{}{"msg": msg})
 }
 
-//统计抽查
-func (i *Front) Tj() error {
-	comm := map[string]map[string]int{}
-	comm_win := map[string]map[string]int{}
-	pack := map[string]map[string]int{}
-	pack_win := map[string]map[string]int{}
-	list, _ := util.MgoM.Find(util.Config.Totablel, "{}", nil, nil, false, -1, -1)
-	for _, tmp := range *list {
-		for k, val := range tmp {
-			if len(k) > 3 && k[:3] == preKey {
-				comm = mapIntAdd(k, qu.ObjToString(val), comm)
+//同步数据
+func (i *Front) SyncMarked() {
+	syncColl := i.GetString("coll")
+	sess := util.MgoM.GetMgoConn()
+	defer util.MgoM.DestoryMongoConn(sess)
+	it := sess.DB(util.Config.Dbname).C(syncColl).Find(nil).Iter()
+	count, _ := sess.DB(util.Config.Dbname).C(syncColl).Find(nil).Count()
+	n := 0
+	lock := &sync.Mutex{}
+	wg := &sync.WaitGroup{}
+	ch := make(chan bool, 3)
+	result := map[string]map[string]interface{}{}
+	idArr := []string{}
+	for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
+		wg.Add(1)
+		ch <- true
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ch
+				wg.Done()
+			}()
+			id := qu.ObjToString(tmp["id"])
+			if id == "" {
+				return
 			}
-		}
-		if winnerorder, ok := tmp["winnerorder"].([]interface{}); ok {
-			for _, wd := range winnerorder {
-				if winner, ok := wd.(map[string]interface{}); ok {
-					for k, val := range winner {
-						if len(k) > 3 && k[:3] == preKey {
-							comm_win = mapIntAdd(k, qu.ObjToString(val), comm_win)
-						}
-					}
+			tmpMap := map[string]interface{}{}
+			for _, f := range util.Config.CustomerField {
+				if val := tmp[f]; val != nil {
+					tmpMap[f] = val
 				}
 			}
-		}
-		if ptmp, ok := tmp["package"].(map[string]interface{}); ok {
-			for _, pktmp := range ptmp {
-				if pkage, ok := pktmp.(map[string]interface{}); ok {
-					for k, val := range pkage {
-						if len(k) > 3 && k[:3] == preKey {
-							pack = mapIntAdd(k, qu.ObjToString(val), pack)
-						}
-						if k == "winnerorder" {
-							if wtmp, ok := val.([]interface{}); ok {
-								for _, winner := range wtmp {
-									if win, ok := winner.(map[string]interface{}); ok {
-										for wk, wval := range win {
-											if len(k) > 3 && k[:3] == preKey {
-												pack_win = mapIntAdd(wk, qu.ObjToString(wval), pack_win)
-											}
-										}
-									}
-								}
-							}
-						}
-					}
-				}
-			}
-		}
+			lock.Lock()
+			idArr = append(idArr, id)
+			result[id] = tmpMap
+			lock.Unlock()
+		}(tmp)
+		tmp = map[string]interface{}{}
 	}
-	//data := map[string]interface{}{"total": len(list), "comm": comm, "pack": pack, "pack_win": pack_win}
-	//mongodb.Save("extcheck_tj", data)
-	i.T["comm"] = comm
-	i.T["pack"] = pack
-	i.T["comm_win"] = comm_win
-	i.T["pack_win"] = pack_win
-	i.T["total"] = len(*list)
-	return i.Render("tj.html", &i.T)
+	wg.Wait()
+	if count != int64(len(result)) {
+		i.ServeJson(map[string]interface{}{"msg": "同步失败", "flag": false})
+		return
+	}
+	//util.MgoM.C.Database(util.Config.Dbname).Collection(syncColl).Drop(util.MgoM.Ctx) //删除syncColl表(清空数据)
+	success, msg, successNum := GetDataById(syncColl, idArr, "syncoll", result)
+	result = map[string]map[string]interface{}{}
+	idArr = []string{}
+	msg = fmt.Sprintf("共查询%d条,同步成功%d条\n", count, successNum) + msg
+	i.ServeJson(map[string]interface{}{"msg": msg, "flag": success})
 }
 
 //标注完成
@@ -1304,6 +1309,14 @@ func GetDataById(coll string, ids []string, stype string, tmp map[string]map[str
 				wg.Done()
 				<-ch
 			}()
+			/*
+				1.查bidding
+				2.查extract
+				3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义)
+				4.对比marked表,替换已标注过的字段值,补充标记
+				5.合并客户所需字段信息,补充id字段
+				6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息
+			*/
 			tmpBidColl := util.BidColl1 //bidding
 			//查询bidding
 			if id < util.BIDDINGSTARTID {
@@ -1322,12 +1335,30 @@ func GetDataById(coll string, ids []string, stype string, tmp map[string]map[str
 						(*bidData)[k] = v
 					}
 				}
+				//删除item
+				delete((*bidData), "item")
 				//对比marked表是否已标注该数据
 				markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil)
 				if markData != nil && len(*markData) > 0 {
 					UpdateMarkColl(bidData, markData) //比对更新数据
 				} else {
 					(*bidData)["ck_data"] = 0 //设置ck_data默认值0
+					//多包、中标候选人、标的信息是否抽取
+					if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 {
+						(*bidData)["ck_pkgisext"] = true
+					} else {
+						(*bidData)["ck_pkgisext"] = false
+					}
+					if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 {
+						(*bidData)["ck_wodrisext"] = true
+					} else {
+						(*bidData)["ck_wodrisext"] = false
+					}
+					if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 {
+						(*bidData)["ck_pclisext"] = true
+					} else {
+						(*bidData)["ck_pclisext"] = false
+					}
 				}
 				//合并导入表中客户所需的字段
 				if len(tmp) > 0 {
@@ -1335,24 +1366,16 @@ func GetDataById(coll string, ids []string, stype string, tmp map[string]map[str
 						(*bidData)[k] = v
 					}
 				}
-				//多包、中标候选人、标的信息是否抽取
-				if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 {
-					(*bidData)["ck_pkgisext"] = true
-				} else {
-					(*bidData)["ck_pkgisext"] = false
-				}
-				if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 {
-					(*bidData)["ck_wodrisext"] = true
-				} else {
-					(*bidData)["ck_wodrisext"] = false
-				}
-				if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 {
-					(*bidData)["ck_pclisext"] = true
-				} else {
-					(*bidData)["ck_pclisext"] = false
-				}
 				//补充id
 				(*bidData)["id"] = id
+				if stype == "syncoll" { //同步数据时删除原始数据
+					if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 {
+						lock.Lock()
+						*msg += "同步未删除成功数据id:" + id + ";\n"
+						*success = false
+						lock.Unlock()
+					}
+				}
 				//保存数据
 				if util.MgoM.SaveByOriID(coll, bidData) {
 					atomic.AddInt64(&n, 1) //计数
@@ -1360,9 +1383,9 @@ func GetDataById(coll string, ids []string, stype string, tmp map[string]map[str
 					lock.Lock()
 					*success = false
 					if stype == "excel" {
-						*msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n"
+						*msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n"
 					} else {
-						*msg += "未查询到数据:" + id + ";\n"
+						*msg += "未保存成功数据_id:" + id + ";\n"
 					}
 					lock.Unlock()
 				}
@@ -1372,7 +1395,7 @@ func GetDataById(coll string, ids []string, stype string, tmp map[string]map[str
 				if stype == "excel" {
 					*msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n"
 				} else {
-					*msg += "未查询到数据:" + id + ";\n"
+					*msg += "未查询到数据_id:" + id + ";\n"
 				}
 				lock.Unlock()
 			}
@@ -1397,7 +1420,10 @@ func UpdateMarkColl(bidData, markData *map[string]interface{}) {
 				}
 			}
 		}
-		(*markData)["ck_data"] = 0 //marked表中该条数据如果为字段验证,临时表ck_data:0;若为数据验证ck_data:1
+		(*bidData)["ck_data"] = 0 //marked表中该条数据如果为字段验证,临时表ck_data:0;若为数据验证ck_data:1
+	} else if ck_data == 1 {
+		*bidData = *markData
+		(*bidData)["ck_data"] = 1
 	}
 }
 
@@ -1432,3 +1458,62 @@ func GetCheckedAndAllDataInfo() (int, int) {
 	checkedCount := util.MgoM.Count(util.Coll, ckDataQuery)
 	return checkedCount, allCount
 }
+
+//统计抽查
+func (i *Front) Tj() error {
+	comm := map[string]map[string]int{}
+	comm_win := map[string]map[string]int{}
+	pack := map[string]map[string]int{}
+	pack_win := map[string]map[string]int{}
+	list, _ := util.MgoM.Find(util.Config.Totablel, "{}", nil, nil, false, -1, -1)
+	for _, tmp := range *list {
+		for k, val := range tmp {
+			if len(k) > 3 && k[:3] == preKey {
+				comm = mapIntAdd(k, qu.ObjToString(val), comm)
+			}
+		}
+		if winnerorder, ok := tmp["winnerorder"].([]interface{}); ok {
+			for _, wd := range winnerorder {
+				if winner, ok := wd.(map[string]interface{}); ok {
+					for k, val := range winner {
+						if len(k) > 3 && k[:3] == preKey {
+							comm_win = mapIntAdd(k, qu.ObjToString(val), comm_win)
+						}
+					}
+				}
+			}
+		}
+		if ptmp, ok := tmp["package"].(map[string]interface{}); ok {
+			for _, pktmp := range ptmp {
+				if pkage, ok := pktmp.(map[string]interface{}); ok {
+					for k, val := range pkage {
+						if len(k) > 3 && k[:3] == preKey {
+							pack = mapIntAdd(k, qu.ObjToString(val), pack)
+						}
+						if k == "winnerorder" {
+							if wtmp, ok := val.([]interface{}); ok {
+								for _, winner := range wtmp {
+									if win, ok := winner.(map[string]interface{}); ok {
+										for wk, wval := range win {
+											if len(k) > 3 && k[:3] == preKey {
+												pack_win = mapIntAdd(wk, qu.ObjToString(wval), pack_win)
+											}
+										}
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	//data := map[string]interface{}{"total": len(list), "comm": comm, "pack": pack, "pack_win": pack_win}
+	//mongodb.Save("extcheck_tj", data)
+	i.T["comm"] = comm
+	i.T["pack"] = pack
+	i.T["comm_win"] = comm_win
+	i.T["pack_win"] = pack_win
+	i.T["total"] = len(*list)
+	return i.Render("tj.html", &i.T)
+}

+ 63 - 6
src/web/templates/list.html

@@ -43,6 +43,14 @@
             flex-direction: row;
             align-items: center;
         }
+
+        .checkbox-inline{
+            margin-left: -11px;
+        }
+
+        .import-primary{
+            margin-left: 9px;
+        }
     </style>
 </head>
  <body>
@@ -70,7 +78,7 @@
                             placeholder="请输入库名"/>
                  </div>
                  <div class="col-md-1" style="padding-left: 0">
-                     <input type="input" name="coll" class="form-control" value="{{.T.fromtable}}" placeholder="请输入表名"/>
+                     <input type="input" name="coll" id="fromtable" class="form-control" value="{{.T.fromtable}}" placeholder="请输入表名"/>
                  </div>
                  <div class="col-md-7 row-box" style="padding-left: 0">
                      <div class=" row-box" style="padding-left: 0">
@@ -107,10 +115,12 @@
                               <input type="checkbox" name="ispackage"  value="1">分包数据
                          </label>
                      </div>-->
-                     <button type="submit" class="btn btn-primary" id="submitForm">查看</button>
+                     <button type="submit" style="display: none" class="btn btn-primary" id="submitForm"></button>
+                     <div  class="btn btn-primary" style="margin-left: 15px" onclick="alertsync()">查看</div>
+                     <div  class="btn btn-primary" style="margin-left: 15px" onclick="syncmarked()">同步</div>
                  </div>
              </form>
-		 </div>
+         </div>
          <div class="col-md-12">
              <div class="form-group col-md-5" style="padding-left: 0">
                  <textarea class="form-control" name="descript" id="es"></textarea>
@@ -119,10 +129,10 @@
                  <div class="col-md-3" style="padding-left: 0">
                      <input type="input" id="importcoll" class="form-control" value="" placeholder="库表名"/>
                  </div>
-                 <button class="btn btn-primary" onclick='getescount()'>
+                 <button class="btn btn-primary import-primary" onclick='getescount()'>
                      Es导入数据
                  </button>
-                 <button class="btn btn-primary" onclick='importbyexcel()'>
+                 <button class="btn btn-primary import-primary" onclick='importbyexcel()'>
                      导入Excel
                  </button>
              </div>
@@ -329,9 +339,33 @@ function currentPage(currentPage, type){
     console.log("当前页码数:" + currentPage);
 }
 
+function alertsync() {
+    var coll = $("#fromtable").val();
+    if(confirm("是否先同步"+coll+"表中数据?"+"\n"+"(通过ES/Excel导入数据,无需同步)")){
+        if(coll == "marked"){
+            alert("marked表无需同步");
+            return
+        }
+        $.ajax({
+            url:"/syncmarked",
+            type:"post",
+            data:{"coll":coll},
+            success:function (r) {
+                if(r){
+                    console.log(r.msg);
+                    alert(r.msg);
+                    if(r.flag){
+                        $("#submitForm").trigger('click');
+                    }
+                }
+            }
+        })
+    }else{
+        $("#submitForm").trigger('click');
+    }
+}
 
 function submitform(number){
-    console.log(number,{{.T.pagenum}})
     $("#pagenum").val(number);
     $("#submitForm").trigger('click');
 }
@@ -339,6 +373,29 @@ function submitform(number){
 function updateinfo(){
     $("#submitForm").trigger('click');
 }
+
+//同步marked表中的数据
+function syncmarked() {
+    var coll = $("#fromtable").val();
+    if(confirm("确定同步"+coll+"表中数据?")){
+        if(coll == "marked"){
+            alert("marked表无需同步");
+            return
+        }
+        $.ajax({
+            url:"/syncmarked",
+            type:"post",
+            data:{"coll":coll},
+            success:function (r) {
+                if(r){
+                    console.log(r.msg)
+                    alert(r.msg)
+                }
+            }
+        })
+    }
+
+}
 </script>
 
 </html>