|
@@ -14,6 +14,7 @@ import (
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
"go.uber.org/zap"
|
|
|
"io"
|
|
|
+ "os"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -26,6 +27,7 @@ type CustomerRule struct {
|
|
|
productData xweb.Mapper `xweb:"/customerRule/cuser/produce"` //生成预览数据
|
|
|
demoData xweb.Mapper `xweb:"/customerRule/rule/preview"` //预览数据
|
|
|
dataTest xweb.Mapper `xweb:"/customerRule/rule/dataTest/(.*)"` //规则测试
|
|
|
+ downloadRule xweb.Mapper `xweb:"/customerRule/rule/downloadrule"` //下载规则
|
|
|
}
|
|
|
|
|
|
var (
|
|
@@ -580,3 +582,40 @@ func exactMatch(rule string, data []map[string]interface{}, nameArr []string) bo
|
|
|
}
|
|
|
return output.(bool)
|
|
|
}
|
|
|
+
|
|
|
+func (this *CustomerRule) DownloadRule() {
|
|
|
+ defer common.Catch()
|
|
|
+ id := this.GetString("id")
|
|
|
+ // 验证一下规则
|
|
|
+ user, ok := this.GetSession("user").(map[string]interface{})
|
|
|
+ if !ok {
|
|
|
+ this.ServeJson("身份异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uID := ""
|
|
|
+ users, ok := util.Mgo.FindOne("cuser", map[string]interface{}{"s_name": user["name"], "b_delete": false})
|
|
|
+ if users != nil && ok {
|
|
|
+ uID = mongodb.BsonIdToSId((*users)["_id"])
|
|
|
+ }
|
|
|
+ if uID == "" {
|
|
|
+ this.ServeJson("身份异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count := util.Mgo.Count("cuserdepartrule", map[string]interface{}{"_id": mongodb.StringTOBsonId(id), "s_userid": uID, "b_delete": false})
|
|
|
+ if count <= 0 {
|
|
|
+ this.ServeJson("规则异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ path := util.ResponseXlsx_Rule(id)
|
|
|
+ if path == "" {
|
|
|
+ this.ServeJson("没有数据")
|
|
|
+ } else {
|
|
|
+ arr := strings.Split(path, "/")
|
|
|
+ this.ResponseWriter.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", arr[len(arr)-1]))
|
|
|
+ this.ServeFile(path)
|
|
|
+ go func(path string) {
|
|
|
+ time.Sleep(time.Minute * 3)
|
|
|
+ os.Remove(path)
|
|
|
+ }(path)
|
|
|
+ }
|
|
|
+}
|