瀏覽代碼

修改邮件推送

5 年之前
父節點
當前提交
2f2fe02ec8
共有 7 個文件被更改,包括 34 次插入16 次删除
  1. 5 3
      README.md
  2. 二進制
      api_test/api_test
  3. 10 6
      api_test/main.go
  4. 1 1
      jyservice/src/config.json
  5. 15 5
      jyservice/src/usermanager/sendmail.go
  6. 1 1
      jyservice/src/usermanager/user.go
  7. 2 0
      jyservice/src/utils/utils.go

+ 5 - 3
README.md

@@ -3,13 +3,15 @@
 2019/9/12
 密钥长度由1024修改为4096
 
-dev2.3.2.3 2019/11/14
-1、增加定时邮件推送功能,默认推送昨天的数据,推送过的不再推
-使用item区分同用户下不同的收件人
+
+dev2.3.2.3 2019/11/14~2019/11/16
+1、增加定时邮件推送功能,默认推送昨天的数据,推送过的不再推,用户增加cronday字段,0取昨天和今天或-1取今天
+使用**item**区分同用户下不同的收件人
 2、对字段的定义,按顺序从config.json中读取fields字段,生成excel动态根据用户配置的字段生成
 3、增加手动发送邮件的接口
 4、增加api_test
 
+
 de2.3.2.2  2019/9/6
 1、增加每个用户的自定义字段,是加或是减
 fields:"subtype,-toptype"

二進制
api_test/api_test


+ 10 - 6
api_test/main.go

@@ -13,11 +13,12 @@ import (
 )
 
 var (
-	appid  = "jyNjdXQgUDAwdaTklMPz5i"
-	key    = "404M0v2j"
-	apiurl = "http://127.0.0.1:8801"
-
-	//apiurl = "https://api.jianyu360.com"
+	//	appid  = "jyNjdXQgUDAwdaTklMPz5i"
+	//	key    = "404M0v2j"
+	//	apiurl = "http://127.0.0.1:8801"
+	appid  = "jyPz5XQgMABgVeTkdOMTBx"
+	key    = "349300qe"
+	apiurl = "https://api.jianyu360.com"
 )
 
 func main() {
@@ -31,6 +32,7 @@ func getToken() (token string) {
 		"timestamp": tm,
 		"signature": MD5(appid + tm + key),
 	})
+	log.Println(res)
 	if res != nil && res["access_token"] != "" {
 		token, _ = res["access_token"].(string)
 	}
@@ -41,7 +43,8 @@ func getData() {
 	token := getToken()
 	data := post(apiurl+"/data/getalldata", map[string]string{
 		"access_token": token,
-		"day":          "-1",
+		"day":          "0",
+		"next":         "1",
 	})
 	log.Println(data)
 }
@@ -57,6 +60,7 @@ func post(url string, form map[string]string) (data map[string]interface{}) {
 	for k, v := range form {
 		str += "&" + k + "=" + v
 	}
+	log.Println(str)
 	res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
 	if err != nil {
 		log.Println("post err:", err.Error())

+ 1 - 1
jyservice/src/config.json

@@ -60,7 +60,7 @@
             "user": "public03@topnet.net.cn"
         }
     ],
-    "cron-sendmail": "0 20 16 * * ?",
+    "cron-sendmail": "0 4 15 * * ?",
     "fields": {
         "title": "公告标题",
         "content": "公告内容",

+ 15 - 5
jyservice/src/usermanager/sendmail.go

@@ -52,7 +52,8 @@ func init() {
 }
 
 func sm() {
-	sendmail("", -1, 1, "")
+	//bforce要是0,不发送已经发过的信息
+	sendmail("", -1, 0, "", true)
 }
 
 //调用url地址发送邮件
@@ -68,7 +69,7 @@ func SendMailByAppid(w http.ResponseWriter, r *http.Request) {
 			day = qu.IntAll(days)
 		}
 		force1 := qu.IntAll(force)
-		sendmail(appid, day, force1, fn)
+		sendmail(appid, day, force1, fn, false)
 		w.Write([]byte("ok"))
 	} else {
 		w.Write([]byte("param error"))
@@ -80,8 +81,9 @@ func SendMailByAppid(w http.ResponseWriter, r *http.Request) {
 appid 用户身份
 days -1发送昨天数据 -3发送前三天数据
 force 1不判断bget 0判断bget为1的不发送
+bcron 只能,取用户表cronday的值是0 或 -1
 **/
-func sendmail(appid string, days int, force int, fn string) {
+func sendmail(appid string, days int, force int, fn string, bcron bool) {
 	query := map[string]interface{}{
 		"mails": map[string]interface{}{
 			"$exists": 1,
@@ -110,6 +112,7 @@ func sendmail(appid string, days int, force int, fn string) {
 			}
 			appfields, _ := v["fields"].(string)
 			mails, _ := v["mails"].(map[string]interface{})
+			cronday := qu.IntAllDef(v["cronday"], 0)
 			if len(mails) > 0 && appid != "" && len(planname) > 1 {
 				GetDataMapLock.Lock()
 				appidLock := GetDataMap[appid]
@@ -141,6 +144,13 @@ func sendmail(appid string, days int, force int, fn string) {
 				}
 				st, _ := GetDayMinMax(time.Now())
 				st1 := st + int64(days*86400)
+				if bcron { //如果是定时任务取cronday的值只能为0或-1,-1只发昨天的数据,0发最近两天的bget不为1的数据
+					st1 = st - 86400 //昨天0点
+					if cronday == 0 {
+						st = time.Now().Unix() //当前时间
+					}
+					fn = time.Now().Format("2006-01-02-15")
+				}
 				dataQuery["createtime"] = map[string]interface{}{
 					"$gte": st1,
 					"$lt":  st,
@@ -184,7 +194,7 @@ func sendmail(appid string, days int, force int, fn string) {
 					}
 				}
 				fields2["item"] = 1
-				log.Info(fields2)
+				log.Info(fields2, dataQuery)
 				data, bdata := Mgo.Find("usermail", dataQuery, `{"_id":1}`, fields2, false, -1, -1)
 				firstId, lastId := "", ""
 				if bdata && data != nil && *data != nil && len(*data) > 0 {
@@ -323,7 +333,7 @@ func GetBidInfoXlsx(appid string, fn string, mails map[string]interface{}, field
 				log.Println("mkdir err", dir)
 			}
 		}
-		fname := key + "_" + fn + qu.GetRandom(4) + ".xlsx"
+		fname := key + "_" + fn + "_N" + qu.GetRandom(4) + ".xlsx"
 		err := fx.Save(dir + fname)
 		if err != nil {
 			log.Info("xls error", appid, fname)

+ 1 - 1
jyservice/src/usermanager/user.go

@@ -34,7 +34,7 @@ func NewUser(w http.ResponseWriter, r *http.Request) {
 	//	appid := "jy" + EncodeUtil.EncodeString(str)
 	appid := GetAppid(t.Unix())
 	key := util.GetComplexRandom(8, 3, 5)
-	id := Mgo.Save("user", &map[string]interface{}{"username": username, "createtime": t.Unix(), "appid": appid, "key": key})
+	id := Mgo.Save("user", &map[string]interface{}{"username": username, "createtime": t.Unix(), "appid": appid, "key": key, "bnormal": int32(1)})
 	log.Debug("create user success!", "\t", username)
 	ret := JSON{"msg": "err"}
 	if len(id) > 10 {

+ 2 - 0
jyservice/src/utils/utils.go

@@ -32,6 +32,8 @@ const (
 	MSG_E6            = "签名过期"
 	CODE_E7           = 1007
 	MSG_E7            = "签名错误"
+	CODE_E8           = 1008
+	MSG_E8            = "服务条数过超月限额"
 	CODE_ERR_E0       = 4000
 	MSG_ERR_E         = "内部错误"
 	CODE_ERR_E1       = 4001