package controllers
|
|
|
|
import (
|
|
"LAPP_SJA_ME/utils"
|
|
"LAPP_SJA_ME/web/middleware/jwts"
|
|
"LAPP_SJA_ME/web/models"
|
|
"LAPP_SJA_ME/web/supports"
|
|
"github.com/kataras/iris"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
// TOD引擎
|
|
func UploadLab(ctx iris.Context) {
|
|
|
|
user, ok := jwts.ParseToken(ctx)
|
|
utils.TrimStruct(user, *user)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
var (
|
|
lab *models.LAB
|
|
err error
|
|
)
|
|
|
|
//日志
|
|
logs := new(models.LeitServerLog)
|
|
logs.File = "/controllers/PlnForecastLanding_controller.go"
|
|
logs.Level = "info"
|
|
logs.Function = "UpfilePlnForecastLanding"
|
|
logs.Message = "上传预测报表文件"
|
|
logs.Operator = user.Userid
|
|
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
logs.InsertRecord()
|
|
|
|
//获取通过iris.WithPostMaxMemory获取的最大上传值大小。
|
|
maxSize := ctx.Application().ConfigurationReadOnly().GetPostMaxMemory()
|
|
err = ctx.Request().ParseMultipartForm(maxSize)
|
|
if err != nil {
|
|
ctx.StatusCode(iris.StatusInternalServerError)
|
|
ctx.WriteString(err.Error())
|
|
return
|
|
}
|
|
form := ctx.Request().MultipartForm
|
|
files := form.File["upload[]"]
|
|
savePath := ""
|
|
filename := ""
|
|
for _, file := range files {
|
|
filename = file.Filename
|
|
savePath = "web/public/uploadxlsx/" + filename
|
|
// 上传文件至指定目录
|
|
err := utils.SaveUploadedFile(file, savePath)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
savePath,_ = utils.GetCurrentPath(savePath)
|
|
// 初始化
|
|
lab = &models.LAB{}
|
|
if err = models.ParseLabEdi(savePath, lab); err != nil {
|
|
log.Printf("Failed to parse due to: %v", err)
|
|
supports.Error(ctx, iris.StatusBadRequest, "数据解析失败", nil)
|
|
return
|
|
}
|
|
tab := new(models.PlnForecastLanding)
|
|
tab.Finr = user.Pid
|
|
tab.Adddate = utils.TimeFormat(time.Now(),"yyyyMMdd")
|
|
err = tab.SaveParseResult(filename, lab)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
supports.Ok(ctx, supports.OptionSuccess, "")
|
|
return
|
|
}
|