|
@@ -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 {
|