zhangjinkun 5 years ago
parent
commit
aacd115f96
2 changed files with 4 additions and 9 deletions
  1. 2 8
      udpfilterdup/src/datamap.go
  2. 2 1
      udpfilterdup/src/main.go

+ 2 - 8
udpfilterdup/src/datamap.go

@@ -227,9 +227,10 @@ func NewInfo(tmp map[string]interface{}) *Info {
 
 //判重方法
 func (d *datamap) check(info *Info) (b bool, source *Info, reason string) {
+	d.lock.Lock()
+	defer d.lock.Unlock()
 	keys := []string{}
 	//不同时间段
-	d.lock.Lock()
 	for k, _ := range d.keys {
 		//...代码
 		keys = append(keys, fmt.Sprintf("%s_%s_%s", k, info.subtype, info.area))
@@ -237,13 +238,10 @@ func (d *datamap) check(info *Info) (b bool, source *Info, reason string) {
 			keys = append(keys, fmt.Sprintf("%s_%s_%s", k, info.subtype, "全国"))
 		}
 	}
-	d.lock.Unlock()
 
 L:
 	for _, k := range keys {
-		d.lock.Lock()
 		data := d.data[k]
-		d.lock.Unlock()
 		if len(data) > 0 { //对比v   找到同类型,同省或全国的数据作对比
 			for _, v := range data {
 				reason = ""
@@ -254,9 +252,7 @@ L:
 				if info.subtype == v.subtype {
 					//站点配置--
 					if info.site != "" {
-						sitelock.Lock()
 						dict := SiteMap[info.site]
-						sitelock.Unlock()
 						if dict != nil {
 							//临时改变--具体值
 							if info.area == "全国" && dict["area"] != "" {
@@ -340,7 +336,6 @@ L:
 		ct := info.publishtime
 		dkey := qutil.FormatDateByInt64(&ct, qutil.Date_yyyyMMdd)
 		k := fmt.Sprintf("%s_%s_%s", dkey, info.subtype, info.area)
-		d.lock.Lock()
 		data := d.data[k]
 		if data == nil {
 			data = []*Info{info}
@@ -353,7 +348,6 @@ L:
 			data = append(data, info)
 			d.data[k] = data
 		}
-		d.lock.Unlock()
 	}
 
 	return

+ 2 - 1
udpfilterdup/src/main.go

@@ -105,7 +105,8 @@ func main() {
 
 //测试组人员使用
 func mainT() {
-	//568551000000000000000000,5e0f65000000000000000000
+	//sid = "568551000000000000000000"
+	//eid = "5e0f65000000000000000000"
 	mapinfo := map[string]interface{}{}
 	if sid == "" || eid == "" {
 		log.Println("sid,eid参数不能为空")