|
@@ -11,6 +11,7 @@ import (
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
|
mu "mfw/util"
|
|
|
+ "mime/multipart"
|
|
|
"mongodb"
|
|
|
"net"
|
|
|
"net/http"
|
|
@@ -1153,6 +1154,7 @@ func (jy *RepairRule) UpFile() {
|
|
|
if jy.Method() == "POST" {
|
|
|
user := jy.GetSession("user").(map[string]interface{})
|
|
|
identity := jy.GetString("identity")
|
|
|
+ isCover, _ := jy.GetBool("isCover") // 是否覆盖已有附件
|
|
|
var id string
|
|
|
if len(identity) == 24 {
|
|
|
id = identity
|
|
@@ -1163,6 +1165,20 @@ func (jy *RepairRule) UpFile() {
|
|
|
}
|
|
|
qu.Debug("download --- url/id ---", id)
|
|
|
files := jy.GetString("files")
|
|
|
+ mf, err := jy.GetFiles()
|
|
|
+ if err != nil {
|
|
|
+ qu.Debug("File Received Failed:", err)
|
|
|
+ jy.ServeJson(map[string]interface{}{
|
|
|
+ "rep": false,
|
|
|
+ "msg": "附件上传失败",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fileMap := make(map[string]*multipart.File)
|
|
|
+ for _, hf := range mf {
|
|
|
+ f, _ := hf.Open()
|
|
|
+ fileMap[hf.Filename] = &f
|
|
|
+ }
|
|
|
var fileArr []map[string]interface{}
|
|
|
if err := json.Unmarshal([]byte(files), &fileArr); err != nil {
|
|
|
qu.Debug("UserInfo Unmarshal Failed:", err)
|
|
@@ -1177,16 +1193,30 @@ func (jy *RepairRule) UpFile() {
|
|
|
for _, m := range fileArr {
|
|
|
download := qu.ObjToString(m["org_url"])
|
|
|
filename := qu.ObjToString(m["filename"])
|
|
|
- res, err := http.Get(download)
|
|
|
- if err != nil {
|
|
|
- qu.Debug("Download url error ---", download)
|
|
|
- jy.ServeJson(map[string]interface{}{
|
|
|
- "rep": false,
|
|
|
- "msg": "文件下载失败",
|
|
|
- })
|
|
|
- return
|
|
|
+ var bt []byte
|
|
|
+ if download == "" {
|
|
|
+ f := fileMap[filename]
|
|
|
+ if f == nil {
|
|
|
+ qu.Debug("File find error ---" + filename)
|
|
|
+ jy.ServeJson(map[string]interface{}{
|
|
|
+ "rep": false,
|
|
|
+ "msg": "未找到文件",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ bt, _ = ioutil.ReadAll(*f)
|
|
|
+ } else {
|
|
|
+ res, err := http.Get(download)
|
|
|
+ bt, _ = ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ qu.Debug("Download url error ---", download)
|
|
|
+ jy.ServeJson(map[string]interface{}{
|
|
|
+ "rep": false,
|
|
|
+ "msg": "文件下载失败",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
- bt, _ := ioutil.ReadAll(res.Body)
|
|
|
key := GetHashKey(bt) + TypeByExt(filename)
|
|
|
b, err := OssPutObject(key, bytes.NewReader(bt))
|
|
|
if b {
|
|
@@ -1203,7 +1233,7 @@ func (jy *RepairRule) UpFile() {
|
|
|
qu.Debug("File upload error ---", err)
|
|
|
jy.ServeJson(map[string]interface{}{
|
|
|
"rep": false,
|
|
|
- "msg": "文件上传失败",
|
|
|
+ "msg": "文件上传oss失败",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
@@ -1215,47 +1245,59 @@ func (jy *RepairRule) UpFile() {
|
|
|
} else {
|
|
|
coll = "bidding_back"
|
|
|
}
|
|
|
- info, _ := JYMgo.FindById(coll, id, map[string]interface{}{"projectinfo": 1})
|
|
|
- if len(*info) > 0 {
|
|
|
- if (*info)["projectinfo"] != nil {
|
|
|
- if attsMap := (*info)["projectinfo"].(map[string]interface{}); attsMap["attachments"] != nil {
|
|
|
- maps := attsMap["attachments"].(map[string]interface{})
|
|
|
- max := 0
|
|
|
- for k, _ := range maps {
|
|
|
- if qu.IntAll(k) > max {
|
|
|
- max = qu.IntAll(k)
|
|
|
+ if isCover {
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
+ for i, att := range atts {
|
|
|
+ tmp[strconv.Itoa(i+1)] = att
|
|
|
+ }
|
|
|
+ attsmap := make(map[string]interface{})
|
|
|
+ attsmap["attachments"] = tmp
|
|
|
+ updateMap := make(map[string]interface{})
|
|
|
+ updateMap["projectinfo"] = attsmap
|
|
|
+ JYMgo.UpdateById(coll, id, map[string]interface{}{"$set": updateMap})
|
|
|
+ } else {
|
|
|
+ info, _ := JYMgo.FindById(coll, id, map[string]interface{}{"projectinfo": 1})
|
|
|
+ if len(*info) > 0 {
|
|
|
+ if (*info)["projectinfo"] != nil {
|
|
|
+ if attsMap := (*info)["projectinfo"].(map[string]interface{}); attsMap["attachments"] != nil {
|
|
|
+ maps := attsMap["attachments"].(map[string]interface{})
|
|
|
+ max := 0
|
|
|
+ for k, _ := range maps {
|
|
|
+ if qu.IntAll(k) > max {
|
|
|
+ max = qu.IntAll(k)
|
|
|
+ }
|
|
|
}
|
|
|
+ for i, att := range atts {
|
|
|
+ maps[strconv.Itoa(i+max+1)] = att
|
|
|
+ }
|
|
|
+ attsMap["attachments"] = maps
|
|
|
+ } else {
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
+ for i, att := range atts {
|
|
|
+ tmp[strconv.Itoa(i+1)] = att
|
|
|
+ }
|
|
|
+ attsMap["attachments"] = tmp
|
|
|
}
|
|
|
- for i, att := range atts {
|
|
|
- maps[strconv.Itoa(i+max+1)] = att
|
|
|
- }
|
|
|
- attsMap["attachments"] = maps
|
|
|
+ delete(*info, "_id")
|
|
|
+ JYMgo.UpdateById(coll, id, map[string]interface{}{"$set": *info})
|
|
|
} else {
|
|
|
tmp := make(map[string]interface{})
|
|
|
for i, att := range atts {
|
|
|
tmp[strconv.Itoa(i+1)] = att
|
|
|
}
|
|
|
- attsMap["attachments"] = tmp
|
|
|
+ attsmap := make(map[string]interface{})
|
|
|
+ attsmap["attachments"] = tmp
|
|
|
+ updateMap := make(map[string]interface{})
|
|
|
+ updateMap["projectinfo"] = attsmap
|
|
|
+ JYMgo.UpdateById(coll, id, map[string]interface{}{"$set": updateMap})
|
|
|
}
|
|
|
- delete(*info, "_id")
|
|
|
- JYMgo.UpdateById(coll, id, map[string]interface{}{"$set": *info})
|
|
|
} else {
|
|
|
- tmp := make(map[string]interface{})
|
|
|
- for i, att := range atts {
|
|
|
- tmp[strconv.Itoa(i+1)] = att
|
|
|
- }
|
|
|
- attsmap := make(map[string]interface{})
|
|
|
- attsmap["attachments"] = tmp
|
|
|
- updateMap := make(map[string]interface{})
|
|
|
- updateMap["projectinfo"] = attsmap
|
|
|
- JYMgo.UpdateById(coll, id, map[string]interface{}{"$set": updateMap})
|
|
|
+ jy.ServeJson(map[string]interface{}{
|
|
|
+ "rep": false,
|
|
|
+ "msg": "id查询失败, " + id,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
- } else {
|
|
|
- jy.ServeJson(map[string]interface{}{
|
|
|
- "rep": false,
|
|
|
- "msg": "id查询失败, " + id,
|
|
|
- })
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
jy.ServeJson(map[string]interface{}{
|