xuzhiheng vor 4 Jahren
Ursprung
Commit
4d1333e8b4

+ 2 - 0
src/client/client.go

@@ -129,6 +129,7 @@ func (c *Client) CuserRuleCreate() {
 				data["entUserId"] = entUserId
 			}
 			data["entId"] = qu.IntAll(user["ent_id"])
+			data["appid"] = qu.ObjToString(user["app_id"])
 			data["i_createtime"] = i_createtime
 			data["s_createuser"] = user["name"]
 			s_namekey := gopinyin.Convert(qu.ObjToString(data["s_name"]), false)
@@ -147,6 +148,7 @@ func (c *Client) CuserRuleCreate() {
 			} else {
 				data["entUserId"] = entUserId
 			}
+			data["appid"] = qu.ObjToString(user["app_id"])
 			data["entId"] = qu.IntAll(user["ent_id"])
 			query := bson.M{
 				"_id": mongoutil.StringTOBsonId(id),

+ 1 - 1
src/config.json

@@ -216,7 +216,7 @@
     "jyMDBXQQIDCQBeSUdBITNf",
     "jyFApXQQIEAw5TTUZOMBpD"
   ],
-  "redis_addrs": "datag=192.168.3.128:1712,other=192.168.3.128:1712",
+  "redis_addrs": "datag=192.168.3.128:1712,export=192.168.3.128:1712",
   "jyMysql": {
     "username": "root",
     "password": "Topnet123",

+ 193 - 71
src/service/private_service.go

@@ -6,16 +6,18 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"os"
 	qu "qfw/util"
 	gm "qfw/util/mail"
+	"qfw/util/redis"
 	"regexp"
-	"sort"
 	"strings"
 	"time"
 	"unicode/utf8"
 	. "util"
 
 	"github.com/go-xweb/xweb"
+	"github.com/tealeg/xlsx"
 	"gopkg.in/mgo.v2/bson"
 )
 
@@ -45,14 +47,14 @@ func (f *Private) Keydatademo(world string) {
 		if time.Now().Sub(time.Unix(ctimeint, 0)).Hours()/24 < Subday {
 			var tagfield *map[string]interface{}
 			if typeStr == "private" {
-				tagfield, _ = Mgo.FindOneByField("entniche_rule", bson.M{"s_dataid": world}, bson.M{"i_extfieldstype": 1, "i_estotal": 1, "s_userid": 1})
-				customer := JyMysql.FindOne("entniche_info", map[string]interface{}{"id": (*tagfield)["entId"]}, "name", "")
+				tagfield, _ = Mgo.FindOne("entniche_rule", bson.M{"s_dataid": world})
+				customer := JyMysql.FindOne("entniche_info", map[string]interface{}{"id": qu.IntAll((*tagfield)["entId"])}, "name", "")
 				(*tagfield)["s_customer"] = (*customer)["name"]
 			}
 			if (*tagfield) != nil && len(*tagfield) > 0 {
-				if qu.Int64All((*tagfield)["i_extfieldstype"]) == Standard {
+				if qu.IntAll((*tagfield)["i_extfieldstype"]) == Standard {
 					tmp["fieldtype"] = Standardstr
-				} else if qu.Int64All((*tagfield)["i_extfieldstype"]) == Advanced {
+				} else if qu.IntAll((*tagfield)["i_extfieldstype"]) == Advanced {
 					tmp["fieldtype"] = Advancedstr
 				} else {
 					f.ServeJson(map[string]string{
@@ -138,83 +140,203 @@ func (f *Private) Keydatademo(world string) {
 }
 
 func (f *Private) Keydataoption(world string) {
-	destr := qu.SE.DecodeString(world)
+	// destr := qu.SE.DecodeString(world)
 	tmp := make(map[string]interface{})
+	idMap := make(map[string]bool)
+	infoArr := []map[string]interface{}{}
 	bytes := f.Body()
 	err := json.Unmarshal(bytes, &tmp)
-	if err == nil && len(destr) > 10 {
-		ctime := destr[:10]
-		ctimeint := qu.Int64All(ctime)
-		if time.Now().Sub(time.Unix(ctimeint, 0)).Hours()/24 < Subday {
-			res, _ := Mgo.FindOne("tags", bson.M{"s_dataid": world})
-			if nil != res && len(*res) > 0 {
-				feedback := make(map[string]interface{})
-				feedback["s_dataid"] = world
-				feedback["s_customer"] = (*res)["s_customer"]
-				feedback["s_name"] = (*res)["s_name"]
-				feedback["s_opinion"] = tmp["option"]
-				feedback["i_num"] = len(tmp["urls"].([]interface{}))
-				feedback["l_feedbacktime"] = time.Now().Unix()
-
-				tmps := make([]map[string]interface{}, 0)
-				for _, tt := range tmp["urls"].([]interface{}) {
-					ttres, _ := Mgo.FindOne("tagsdata", bson.M{"s_jyhref": tt})
-					if nil != ttres && len(*ttres) > 0 {
-						tmps = append(tmps, *ttres)
+	newCount := 0
+	datas, _ := Mgo.FindOne("entniche_rule", bson.M{"s_dataid": world})
+	entId := qu.IntAll((*datas)["entId"])
+	entUserId := qu.IntAll((*datas)["entUserId"])
+	current := GetCurrentCount2(entId, entUserId)
+	log.Println("数据余额", current)
+	filterStr := ""
+	isFirst := tmp["isFirst"].(bool)
+	newIdArr := []string{}
+	if err == nil {
+		if idArr, ok := tmp["urls"].([]interface{}); ok {
+			idsArr := []string{}
+			for _, v := range idArr {
+				idsArr = append(idsArr, v.(string))
+				idMap[v.(string)] = true
+			}
+			filterStr = strings.Join(idsArr, ",")
+		}
+		res, ok := Mgo.Find("tagsdata", bson.M{"s_dataid": world}, nil, nil, false, -1, -1)
+		if ok && res != nil && *res != nil && len(*res) > 0 {
+			for _, v := range *res {
+				infoid := qu.ObjToString(v["info_id"])
+				if idMap[infoid] {
+					isExist, err := redis.Exists("export", "entexportdata_"+infoid+"_"+fmt.Sprintln(entId))
+					if err != nil {
+						log.Println("企业订阅数据导出redis判重失败")
+					} else if isExist {
+						log.Println("数据重复,id ", infoid, "entid ", entId, "userid ", entUserId)
+					} else {
+						newCount++
 					}
-				}
-
-				keysnum := make(map[string]int)
-				for _, v := range tmps {
-					for _, vv := range strings.Split(qu.ObjToString(v["s_matchkey"]), ",") {
-						keysnum[vv] += 1
+					if !isFirst {
+						v["id"] = infoid
+						v["jybxhref"] = v["s_jyhref"]
+						v["createtime"] = time.Now().Unix()
+						newIdArr = append(newIdArr, infoid)
 					}
+					infoArr = append(infoArr, v)
 				}
-				keynums := []keynum{}
-				for k, v := range keysnum {
-					keynums = append(keynums, keynum{k, v})
-				}
-
-				sort.Slice(keynums, func(i, j int) bool {
-					return keynums[i].Num > keynums[j].Num
-				})
-				keyssort := []string{}
-				for _, v := range keynums {
-					keyssort = append(keyssort, v.Key)
-				}
-				feedback["o_matchkey"] = keyssort
-				pid := Mgo.Save("feedback", feedback)
-				if len(pid) < 1 {
-					log.Println("mongo save err")
-					return
-				}
+			}
+		}
+	}
+	log.Println("数据量", len(infoArr))
+	log.Println("新导出", newCount)
+	isExport := true
+	if newCount > current {
+		isExport = false
+	} else {
+		go func() {
+			for _, v := range newIdArr {
+				redis.Put("export", "entexportdata_"+v+"_"+fmt.Sprintln(entId), 1, -1)
+			}
+		}()
+	}
+	res := map[string]interface{}{
+		"count":    len(infoArr),
+		"newCount": newCount,
+		"current":  current,
+		"isExport": isExport,
+	}
+	if !isFirst {
+		if len(infoArr) > 0 {
+			dataType := qu.IntAll((*datas)["i_extfieldstype"])
+			s_name := qu.ObjToString((*datas)["s_name"])
+			xlsxUrl := GetXlsxfile(infoArr, dataType, s_name)
+			log.Println("生成完成", xlsxUrl)
+			exportId := SaveExportLog2(entId, entUserId, len(infoArr), newCount, xlsxUrl, "1", filterStr)
+			DeductNum2(entId, newCount, entUserId, exportId)
+			res["xlsxUrl"] = xlsxUrl
+		}
+	}
+	f.ServeJson(res)
+}
 
-				for _, v := range tmps {
-					savetmp := map[string]interface{}{}
-					savetmp["s_pid"] = pid
-					savetmp["s_infoid"] = urlToId(qu.ObjToString(v["s_jyhref"]))
-					savetmp["s_jyhref"] = qu.ObjToString(v["s_jyhref"])
-					savetmp["s_matchkey"] = qu.ObjToString(v["s_matchkey"])
-					savetmp["s_projectname"] = qu.ObjToString(v["projectname"])
-					savetmp["s_title"] = qu.ObjToString(v["title"])
-					savetmp["s_buyerclass"] = qu.ObjToString(v["buyerclass"])
-					savetmp["s_subtype"] = qu.ObjToString(v["subtype"])
-					savetmp["s_purchasing"] = qu.ObjToString(v["s_purchasing"])
-					Mgo.Save("feedback_info", savetmp)
-				}
-				f.ServeJson(map[string]string{
-					"code": "1",
-					"err":  "提交成功",
-				})
-				go sendMail(*res, qu.ObjToString(tmp["option"])) //发送邮件
-				return
+func GetXlsxfile(mMap []map[string]interface{}, dataType int, fn string) string {
+	xf, err := xlsx.OpenFile("web/res/fields.xlsx")
+	if err != nil {
+		log.Println("fields file not foud", err.Error())
+	}
+	style := xlsx.NewStyle()
+	style.Font.Size = 12
+	style.Font.Bold = true
+	style.Alignment.Vertical = "center"
+	style.Alignment.Horizontal = "center"
+	if dataType == 1 {
+		sh := xf.Sheets[0]
+		for i, v := range mMap {
+			row := sh.AddRow()
+			row.AddCell().SetInt(i + 1)
+			row.AddCell().SetValue(v["s_matchkey"])
+			row.AddCell().SetValue(v["area"])
+			row.AddCell().SetValue(v["city"])
+			row.AddCell().SetValue(v["title"])
+			row.AddCell().SetValue(v["subtype"])
+			if v["publishtime"] != nil {
+				row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
+			} else {
+				row.AddCell()
 			}
+			row.AddCell().SetValue(v["buyer"])
+			row.AddCell().SetValue(v["winner"])
+			if v["bidamount"] != nil {
+				row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+			} else {
+				row.AddCell()
+			}
+			row.AddCell().SetValue(v["projectname"])
+			row.AddCell().SetValue(v["detail"])
+			row.AddCell().SetValue(v["jybxhref"])
+			ids := SE.EncodeString(qu.ObjToString(v["id"]))
+			row.AddCell().SetValue(ids)
 		}
+		xf.Sheets = xf.Sheets[0:1]
+	} else if dataType == 2 {
+		sh := xf.Sheets[1]
+		for _, v := range mMap {
+			row := sh.AddRow()
+			row.AddCell().SetValue(v["s_matchkey"])
+			row.AddCell().SetValue(v["area"])
+			row.AddCell().SetValue(v["city"])
+			row.AddCell().SetValue(v["title"])
+			row.AddCell().SetValue(v["subtype"])
+			row.AddCell().SetValue(v["detail"])
+			if v["publishtime"] != nil {
+				row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
+			} else {
+				row.AddCell()
+			}
+			row.AddCell().SetValue(v["href"])
+			row.AddCell().SetValue(v["jybxhref"])
+			row.AddCell().SetValue(v["projectname"])
+			row.AddCell().SetValue(v["projectcode"])
+			row.AddCell().SetValue(v["projectscope"])
+			if v["budget"] != nil {
+				row.AddCell().SetFloat(qu.Float64All(v["budget"]))
+			} else {
+				row.AddCell()
+			}
+			if v["bidamount"] != nil {
+				row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+			} else {
+				row.AddCell()
+			}
+			if v["bidopentime"] != nil {
+				row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02"))
+			} else {
+				row.AddCell()
+			}
+			row.AddCell().SetValue(v["buyer"])
+			row.AddCell().SetValue(v["buyerperson"])
+			row.AddCell().SetValue(v["buyertel"])
+			row.AddCell().SetValue(v["agency"])
+			row.AddCell().SetValue(v["s_winner"])
+			row.AddCell().SetValue(v["winnerperson"])
+			row.AddCell().SetValue(v["winnertel"])
+			row.AddCell().SetValue(v["legal_person"])
+			row.AddCell().SetValue(v["company_phone"])
+			row.AddCell().SetValue(v["company_email"])
+			ids := SE.EncodeString(qu.ObjToString(v["id"]))
+			row.AddCell().SetValue(ids)
+		}
+		xf.Sheets = xf.Sheets[1:2]
 	}
-	f.ServeJson(map[string]string{
-		"err": "参数失效",
-	})
+	xf.Sheets[0].Name = "详细数据"
+	//生文件
+	//t := strconv.FormatInt(time.Now().Unix(), 10)
+	t := time.Now().Format("20060102")
+	dir := "./web/res/xlsx/" + t + "/"
+	if b, _ := PathExists(dir); !b {
+		err1 := os.MkdirAll(dir, os.ModePerm)
+		if err1 != nil {
+			log.Println("mkdir err", dir)
+		}
+	}
+	//fname := t + ".xlsx"
+	fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4))
+	log.Println("fname", fname)
+	err = xf.Save(dir + fname)
+	xlsxUrls := "/xlsx/" + t + "/" + fname
+	return xlsxUrls
+}
 
+func PathExists(path string) (bool, error) {
+	_, err := os.Stat(path)
+	if err == nil {
+		return true, nil
+	}
+	if os.IsNotExist(err) {
+		return false, nil
+	}
+	return false, err
 }
 
 type keynum struct {

+ 1 - 1
src/util/config.go

@@ -318,7 +318,7 @@ func initdb() {
 		I_size:  qu.IntAllDef(es["pool"], 15),
 	}
 	Es.InitElasticSize()
-	redis.InitRedis(qu.ObjToString(Sysconfig["redis_addrs"]))
+	redis.InitRedisBySize(qu.ObjToString(Sysconfig["redis_addrs"]), 100, 30, 300)
 	Index = qu.ObjToString(es["index"])
 	Itype = qu.ObjToString(es["itype"])
 	jyMysql := qu.ObjToMap(Sysconfig["jyMysql"])

+ 10 - 10
src/util/cost_util.go

@@ -62,19 +62,19 @@ func DeductNum2(entId int, newCount int, userId int, exportId int64) bool {
 }
 
 // 存导出日志
-func SaveExportLog2(entId, entUserId, count, newCount, remain_nums, export_nums int, xlsxUrl, types, filterStr string) (exportId int64) {
+func SaveExportLog2(entId, entUserId, count, newCount int, xlsxUrl, types, filterStr string) (exportId int64) {
 	query := map[string]interface{}{
 		"id":     entUserId,
 		"ent_id": entId,
 	}
-	set := map[string]interface{}{
-		"remain_nums": remain_nums - newCount,
-		"export_nums": export_nums + newCount,
-	}
-	ok := JyMysql.Update("entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": entUserId}, set)
-	if !ok {
-		log.Println("修改导出条数失败", query, remain_nums, newCount)
-	}
+	// set := map[string]interface{}{
+	// 	"remain_nums": remain_nums - newCount,
+	// 	"export_nums": export_nums + newCount,
+	// }
+	// ok := JyMysql.Update("entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": entUserId}, set)
+	// if !ok {
+	// 	log.Println("修改导出条数失败", query, remain_nums, newCount)
+	// }
 	userData := JyMysql.FindOne("entniche_user", query, "name,phone", "")
 	if userData != nil {
 		name := util.ObjToString((*userData)["name"])
@@ -83,7 +83,7 @@ func SaveExportLog2(entId, entUserId, count, newCount, remain_nums, export_nums
 		exportId = JyMysql.Insert("entniche_export_log", map[string]interface{}{
 			"user_name":    name,
 			"export_time":  util.FormatDate(&now, util.Date_Full_Layout),
-			"data_source":  "1",
+			"data_source":  "3",
 			"export_num":   count,
 			"deduct_num":   newCount,
 			"download_url": xlsxUrl,

+ 2 - 1
src/util/utiltag.go

@@ -109,6 +109,7 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 			item := make(map[string]interface{})
 			if json.Unmarshal(*v.Source, &item) == nil {
 				delete(item, "_id")
+				item["appid"] = tags["appid"]
 				item["info_id"] = v.Id
 				item["s_dataid"] = sdataid
 				item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id))
@@ -207,7 +208,7 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 				datas = append(datas, item)
 			}
 		}
-		Mgo.Update("cuserdepartrule", bson.M{"_id": tags["_id"]}, bson.M{
+		Mgo.Update("entniche_rule", bson.M{"_id": tags["_id"]}, bson.M{
 			"$set": bson.M{
 				"i_estotal": searchResult.Hits.TotalHits,
 			}}, false, false)

+ 1 - 1
src/web/templates/client/cuser_rule_create.html

@@ -443,7 +443,7 @@
         "s_globaladdkeymatch": "",
         "s_globalnotkey": "",
         "s_globalnotkeymatch": "",
-        "i_maxnum": 100,
+        "i_maxnum": 5000,
         "i_starttime": 0,
         "i_endtime": 0,
         "i_extfieldstype": 2,

+ 1 - 1
src/web/templates/client/cuser_rule_edit.html

@@ -372,7 +372,7 @@
                                         <label class="col-sm-2 control-label ">高级字段包</label>
                                         <div class="col-sm-3">
                                             <select class="form-control" id="extfiledselect" style="border-radius:3px"
-                                                    readonly disabled>
+                                                    readonly>
                                                 <option value="1">否</option>
                                                 <option value="2">是</option>
                                             </select>