|
@@ -5,14 +5,6 @@ import (
|
|
|
"encoding/hex"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- "github.com/axetroy/go-fs"
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
- "../../pkg/app"
|
|
|
- "../../pkg/e"
|
|
|
- "../../pkg/logging"
|
|
|
- "../../pkg/setting"
|
|
|
- "../../routers/restful"
|
|
|
- "github.com/nfnt/resize"
|
|
|
"image"
|
|
|
"image/gif"
|
|
|
"image/jpeg"
|
|
@@ -24,6 +16,17 @@ import (
|
|
|
"path"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+
|
|
|
+ "../../pkg/app"
|
|
|
+ "../../pkg/e"
|
|
|
+ "../../pkg/logging"
|
|
|
+ "../../pkg/setting"
|
|
|
+ "../../routers/restful"
|
|
|
+ "github.com/astaxie/beego/logs"
|
|
|
+ "github.com/axetroy/go-fs"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "github.com/nfnt/resize"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
)
|
|
|
|
|
|
// 支持的图片后缀名
|
|
@@ -46,12 +49,11 @@ Handler the parse error
|
|
|
*/
|
|
|
func parseFormFail(context *gin.Context) {
|
|
|
context.JSON(http.StatusBadRequest, gin.H{
|
|
|
- "msg" : "fail",
|
|
|
+ "msg": "fail",
|
|
|
"message": "Can not parse form",
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
Upload file handler
|
|
|
*/
|
|
@@ -59,12 +61,12 @@ func UploadFile(context *gin.Context) {
|
|
|
appG := app.Gin{C: context}
|
|
|
dictId := context.Param("id")
|
|
|
dictName := context.Param("name")
|
|
|
- logging.Info("UploadFile ",context.Keys,dictId,dictName)
|
|
|
+ logging.Info("UploadFile ", context.Keys, dictId, dictName)
|
|
|
var (
|
|
|
isSupportFile bool
|
|
|
- maxUploadSize = setting.AppSetting.FileMaxSize // 最大上传大小
|
|
|
+ maxUploadSize = setting.AppSetting.FileMaxSize // 最大上传大小
|
|
|
allowTypes = setting.AppSetting.FileAllowType // 可上传的文件类型
|
|
|
- distPath string // 最终的输出目录
|
|
|
+ distPath string // 最终的输出目录
|
|
|
err error
|
|
|
file *multipart.FileHeader
|
|
|
src multipart.File
|
|
@@ -114,14 +116,14 @@ func UploadFile(context *gin.Context) {
|
|
|
fileName := md5string + extname
|
|
|
// Destination
|
|
|
|
|
|
- filePath := setting.CurrentPath+setting.AppSetting.FileSavePath+dictName+"/"
|
|
|
- err = PathCheck(filePath) //检查路径并创建
|
|
|
+ filePath := setting.CurrentPath + setting.AppSetting.FileSavePath + dictName + "/"
|
|
|
+ err = PathCheck(filePath) //检查路径并创建
|
|
|
if err != nil {
|
|
|
- fmt.Println("PathCheck err",err)
|
|
|
+ fmt.Println("PathCheck err", err)
|
|
|
}
|
|
|
distPath = path.Join(filePath, fileName)
|
|
|
if dist, err = os.Create(distPath); err != nil {
|
|
|
- fmt.Println("Create err",err)
|
|
|
+ fmt.Println("Create err", err)
|
|
|
}
|
|
|
defer dist.Close()
|
|
|
//distPath = setting.CurrentPath + setting.AppSetting.FileSavePath +"/"+ fileName
|
|
@@ -143,46 +145,46 @@ func UploadFile(context *gin.Context) {
|
|
|
params := context.Request.Form
|
|
|
|
|
|
if sqlname != "" {
|
|
|
- sql, p := restful.GetSqlByNameDB(sqlname)//todo insertcustomdoc
|
|
|
- if sql != ""{
|
|
|
+ sql, p := restful.GetSqlByNameDB(sqlname) //todo insertcustomdoc
|
|
|
+ if sql != "" {
|
|
|
s_params := make([]interface{}, 0)
|
|
|
- paramslist := strings.Split(p,",")
|
|
|
+ paramslist := strings.Split(p, ",")
|
|
|
|
|
|
- if len(paramslist)>0 && p!="" {
|
|
|
+ if len(paramslist) > 0 && p != "" {
|
|
|
for _, value := range paramslist {
|
|
|
- fmt.Println("s_params value",s_params,value)
|
|
|
- if (strings.ToLower(strings.Trim(value," "))=="username"){//picpath, picname, username, newpicname
|
|
|
+ fmt.Println("s_params value", s_params, value)
|
|
|
+ if strings.ToLower(strings.Trim(value, " ")) == "username" { //picpath, picname, username, newpicname
|
|
|
tempv := params.Get("jwt_username")
|
|
|
s_params = append(s_params, tempv)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="docname"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "docname" {
|
|
|
s_params = append(s_params, file.Filename)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="newdocname"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "newdocname" {
|
|
|
s_params = append(s_params, fileName)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="docpath"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "docpath" {
|
|
|
s_params = append(s_params, dictName) //
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="dictid"){
|
|
|
- s_params = append(s_params,dictId) //
|
|
|
- fmt.Println("s_params",s_params,dictId)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="filesize"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "dictid" {
|
|
|
+ s_params = append(s_params, dictId) //
|
|
|
+ fmt.Println("s_params", s_params, dictId)
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "filesize" {
|
|
|
s_params = append(s_params, file.Size) //
|
|
|
- }else{
|
|
|
- s_params = append(s_params, params.Get(strings.Trim(value," ")))
|
|
|
+ } else {
|
|
|
+ s_params = append(s_params, params.Get(strings.Trim(value, " ")))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
execresult, err = execDataBySql(sql, s_params)
|
|
|
- if err != nil{
|
|
|
- fmt.Println("execDataBySql err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("execDataBySql err", err)
|
|
|
appG.Response(http.StatusOK, e.ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
context.JSON(http.StatusOK, gin.H{
|
|
|
- "hash": md5string,
|
|
|
- "filename": fileName,
|
|
|
- "origin": file.Filename,
|
|
|
- "size": file.Size,
|
|
|
- "execresult": execresult,
|
|
|
+ "hash": md5string,
|
|
|
+ "filename": fileName,
|
|
|
+ "origin": file.Filename,
|
|
|
+ "size": file.Size,
|
|
|
+ "execresult": execresult,
|
|
|
})
|
|
|
|
|
|
}
|
|
@@ -191,10 +193,10 @@ func UploadFile(context *gin.Context) {
|
|
|
Upload image handler
|
|
|
*/
|
|
|
func UploaderImage(context *gin.Context) {
|
|
|
- logging.Info("UploaderImage ",context.Keys)
|
|
|
+ logging.Info("UploaderImage ", context.Keys)
|
|
|
var (
|
|
|
maxUploadSize = setting.AppSetting.ImageMaxSize // 最大上传大小
|
|
|
- distPath string // 最终的输出目录
|
|
|
+ distPath string // 最终的输出目录
|
|
|
err error
|
|
|
file *multipart.FileHeader
|
|
|
src multipart.File
|
|
@@ -236,7 +238,6 @@ func UploaderImage(context *gin.Context) {
|
|
|
|
|
|
fileName := md5string + extname
|
|
|
|
|
|
-
|
|
|
//savePathDir := setting.CurrentPath+setting.AppSetting.ImageSavePath+fileName+"/"
|
|
|
//_,err = os.Stat(savePathDir)
|
|
|
//if err == nil {
|
|
@@ -249,14 +250,14 @@ func UploaderImage(context *gin.Context) {
|
|
|
// }//目录不存在则创建
|
|
|
//}
|
|
|
// Destination
|
|
|
- picPath := setting.CurrentPath+setting.AppSetting.ImageSavePath+sqlname+"/"
|
|
|
- err = PathCheck(picPath) //检查路径并创建
|
|
|
+ picPath := setting.CurrentPath + setting.AppSetting.ImageSavePath + sqlname + "/"
|
|
|
+ err = PathCheck(picPath) //检查路径并创建
|
|
|
if err != nil {
|
|
|
- fmt.Println("PathCheck err",err)
|
|
|
+ fmt.Println("PathCheck err", err)
|
|
|
}
|
|
|
distPath = path.Join(picPath, fileName)
|
|
|
if dist, err = os.Create(distPath); err != nil {
|
|
|
- fmt.Println("Create err",err)
|
|
|
+ fmt.Println("Create err", err)
|
|
|
}
|
|
|
defer dist.Close()
|
|
|
|
|
@@ -271,19 +272,19 @@ func UploaderImage(context *gin.Context) {
|
|
|
|
|
|
// 压缩缩略图
|
|
|
// 不管成功与否,都会进行下一步的返回
|
|
|
- if _, err := thumbnailify(distPath,sqlname); err != nil {
|
|
|
- logging.Error("thumbnailify_err",err)
|
|
|
- picThumbnailPath := setting.CurrentPath+setting.AppSetting.ThumbnailSavePath+sqlname+"/"
|
|
|
+ if _, err := thumbnailify(distPath, sqlname); err != nil {
|
|
|
+ logging.Error("thumbnailify_err", err)
|
|
|
+ picThumbnailPath := setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + sqlname + "/"
|
|
|
println(picThumbnailPath)
|
|
|
- err = PathCheck(picThumbnailPath) //检查路径并创建
|
|
|
+ err = PathCheck(picThumbnailPath) //检查路径并创建
|
|
|
distThumbnailPath := path.Join(picThumbnailPath, fileName)
|
|
|
println(distThumbnailPath)
|
|
|
distThumbnail, err := os.Create(distThumbnailPath)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("CreateThumbnail err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("CreateThumbnail err", err)
|
|
|
}
|
|
|
srcThumbnail, err := file.Open()
|
|
|
- if err != nil {
|
|
|
+ if err != nil {
|
|
|
//
|
|
|
}
|
|
|
io.Copy(distThumbnail, srcThumbnail)
|
|
@@ -296,49 +297,48 @@ func UploaderImage(context *gin.Context) {
|
|
|
|
|
|
if sqlname != "" {
|
|
|
sql, p := restful.GetSqlByNameDB(sqlname)
|
|
|
- if sql != ""{
|
|
|
+ if sql != "" {
|
|
|
s_params := make([]interface{}, 0)
|
|
|
- paramslist := strings.Split(p,",")
|
|
|
- if len(paramslist)>0 && p!="" {
|
|
|
+ paramslist := strings.Split(p, ",")
|
|
|
+ if len(paramslist) > 0 && p != "" {
|
|
|
for _, value := range paramslist {
|
|
|
- if (strings.ToLower(strings.Trim(value," "))=="username"){//picpath, picname, username, newpicname
|
|
|
+ if strings.ToLower(strings.Trim(value, " ")) == "username" { //picpath, picname, username, newpicname
|
|
|
tempv := params.Get("jwt_username")
|
|
|
s_params = append(s_params, tempv)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="picname"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "picname" {
|
|
|
s_params = append(s_params, file.Filename)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="newpicname"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "newpicname" {
|
|
|
s_params = append(s_params, fileName)
|
|
|
- }else if (strings.ToLower(strings.Trim(value," "))=="picpath"){
|
|
|
+ } else if strings.ToLower(strings.Trim(value, " ")) == "picpath" {
|
|
|
s_params = append(s_params, sqlname) //全路径加文件名
|
|
|
- } else{
|
|
|
- s_params = append(s_params, params.Get(strings.Trim(value," ")))
|
|
|
+ } else {
|
|
|
+ s_params = append(s_params, params.Get(strings.Trim(value, " ")))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
execresult, err = execDataBySql(sql, s_params)
|
|
|
- if err != nil{
|
|
|
- fmt.Println("execDataBySql err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("execDataBySql err", err)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
context.JSON(http.StatusOK, gin.H{
|
|
|
- "hash": md5string,
|
|
|
- "filename": fileName,
|
|
|
- "origin": file.Filename,
|
|
|
- "size": file.Size,
|
|
|
- "execresult": execresult,
|
|
|
+ "hash": md5string,
|
|
|
+ "filename": fileName,
|
|
|
+ "origin": file.Filename,
|
|
|
+ "size": file.Size,
|
|
|
+ "execresult": execresult,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
Upload image handler
|
|
|
*/
|
|
|
func UploaderTmrImage(context *gin.Context) {
|
|
|
- logging.Info("UploaderTmrImage ",context.Keys)
|
|
|
+ logging.Info("UploaderTmrImage ", context.Keys)
|
|
|
var (
|
|
|
maxUploadSize = setting.AppSetting.ImageMaxSize // 最大上传大小
|
|
|
- distPath string // 最终的输出目录
|
|
|
+ distPath string // 最终的输出目录
|
|
|
err error
|
|
|
file *multipart.FileHeader
|
|
|
src multipart.File
|
|
@@ -352,24 +352,23 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
|
|
|
pastureid := context.GetHeader("pastureid") //牧场id
|
|
|
projuctid := context.GetHeader("projuctid") // 主计划id
|
|
|
- pfid := context.GetHeader("pfid") // 配方id
|
|
|
- optid := context.GetHeader("optid") //子计划id
|
|
|
+ pfid := context.GetHeader("pfid") // 配方id
|
|
|
+ optid := context.GetHeader("optid") //子计划id
|
|
|
catchtime := context.GetHeader("catchtime") // 捕获时间
|
|
|
- picclass := context.GetHeader("picclass") // 图片分类
|
|
|
-
|
|
|
+ picclass := context.GetHeader("picclass") // 图片分类
|
|
|
|
|
|
extname := strings.ToLower(path.Ext(file.Filename))
|
|
|
|
|
|
if isImage(extname) == false {
|
|
|
context.JSON(http.StatusBadRequest, gin.H{
|
|
|
- "msg" : "fail",
|
|
|
+ "msg": "fail",
|
|
|
"message": "不支持的上传文件类型: " + extname,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
if file.Size > int64(maxUploadSize) {
|
|
|
context.JSON(http.StatusBadRequest, gin.H{
|
|
|
- "msg" : "fail",
|
|
|
+ "msg": "fail",
|
|
|
"message": "上传文件太大, 最大文件大小限制为(byte): " + strconv.Itoa(int(maxUploadSize)),
|
|
|
})
|
|
|
return
|
|
@@ -388,7 +387,6 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
|
|
|
fileName := md5string + extname
|
|
|
|
|
|
-
|
|
|
//savePathDir := setting.CurrentPath+setting.AppSetting.ImageSavePath+fileName+"/"
|
|
|
//_,err = os.Stat(savePathDir)
|
|
|
//if err == nil {
|
|
@@ -401,14 +399,14 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
// }//目录不存在则创建
|
|
|
//}
|
|
|
// Destination
|
|
|
- picPath := setting.CurrentPath+setting.AppSetting.ImageSavePath+projuctid+"/"
|
|
|
- err = PathCheck(picPath) //检查路径并创建
|
|
|
+ picPath := setting.CurrentPath + setting.AppSetting.ImageSavePath + projuctid + "/"
|
|
|
+ err = PathCheck(picPath) //检查路径并创建
|
|
|
if err != nil {
|
|
|
- fmt.Println("PathCheck err",err)
|
|
|
+ fmt.Println("PathCheck err", err)
|
|
|
}
|
|
|
distPath = path.Join(picPath, fileName)
|
|
|
if dist, err = os.Create(distPath); err != nil {
|
|
|
- fmt.Println("Create err",err)
|
|
|
+ fmt.Println("Create err", err)
|
|
|
}
|
|
|
defer dist.Close()
|
|
|
|
|
@@ -423,19 +421,19 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
|
|
|
// 压缩缩略图
|
|
|
// 不管成功与否,都会进行下一步的返回
|
|
|
- if _, err := thumbnailify(distPath,projuctid); err != nil {
|
|
|
- logging.Error("thumbnailify_err",err)
|
|
|
- picThumbnailPath := setting.CurrentPath+setting.AppSetting.ThumbnailSavePath+projuctid+"/"
|
|
|
+ if _, err := thumbnailify(distPath, projuctid); err != nil {
|
|
|
+ logging.Error("thumbnailify_err", err)
|
|
|
+ picThumbnailPath := setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + projuctid + "/"
|
|
|
println(picThumbnailPath)
|
|
|
- err = PathCheck(picThumbnailPath) //检查路径并创建
|
|
|
+ err = PathCheck(picThumbnailPath) //检查路径并创建
|
|
|
distThumbnailPath := path.Join(picThumbnailPath, fileName)
|
|
|
println(distThumbnailPath)
|
|
|
distThumbnail, err := os.Create(distThumbnailPath)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("CreateThumbnail err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("CreateThumbnail err", err)
|
|
|
}
|
|
|
srcThumbnail, err := file.Open()
|
|
|
- if err != nil {
|
|
|
+ if err != nil {
|
|
|
//
|
|
|
}
|
|
|
io.Copy(distThumbnail, srcThumbnail)
|
|
@@ -449,12 +447,12 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
|
|
|
if sqlname != "" {
|
|
|
sql, p := restful.GetSqlByNameDB(sqlname)
|
|
|
- if sql != ""{
|
|
|
+ if sql != "" {
|
|
|
s_params := make([]interface{}, 0)
|
|
|
- paramslist := strings.Split(p,",")
|
|
|
- if len(paramslist)>0 && p!="" {
|
|
|
+ paramslist := strings.Split(p, ",")
|
|
|
+ if len(paramslist) > 0 && p != "" {
|
|
|
for _, value := range paramslist {
|
|
|
- switch strings.ToLower(strings.Trim(value," ")) {
|
|
|
+ switch strings.ToLower(strings.Trim(value, " ")) {
|
|
|
case "username":
|
|
|
tempv := params.Get("jwt_username")
|
|
|
s_params = append(s_params, tempv)
|
|
@@ -477,23 +475,23 @@ func UploaderTmrImage(context *gin.Context) {
|
|
|
case "picclass":
|
|
|
s_params = append(s_params, picclass)
|
|
|
default:
|
|
|
- s_params = append(s_params, params.Get(strings.Trim(value," ")))
|
|
|
+ s_params = append(s_params, params.Get(strings.Trim(value, " ")))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
execresult, err = execDataBySql(sql, s_params)
|
|
|
- if err != nil{
|
|
|
- fmt.Println("execDataBySql err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("execDataBySql err", err)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
context.JSON(http.StatusOK, gin.H{
|
|
|
- "msg" : "ok",
|
|
|
- "hash": md5string,
|
|
|
- "filename": fileName,
|
|
|
- "origin": file.Filename,
|
|
|
- "size": file.Size,
|
|
|
- "execresult": execresult,
|
|
|
+ "msg": "ok",
|
|
|
+ "hash": md5string,
|
|
|
+ "filename": fileName,
|
|
|
+ "origin": file.Filename,
|
|
|
+ "size": file.Size,
|
|
|
+ "execresult": execresult,
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -502,7 +500,7 @@ Get file raw
|
|
|
*/
|
|
|
func GetFileRaw(context *gin.Context) {
|
|
|
filename := context.Param("filename")
|
|
|
- logging.Info("GetFileRaw ",context.Keys,filename)
|
|
|
+ logging.Info("GetFileRaw ", context.Keys, filename)
|
|
|
|
|
|
filePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, filename)
|
|
|
if isExistFile := fs.PathExists(filePath); isExistFile == false {
|
|
@@ -518,13 +516,13 @@ Download a file
|
|
|
*/
|
|
|
func DownloadFile(context *gin.Context) {
|
|
|
filename := context.Param("filename")
|
|
|
- logging.Info("DownloadFile ",context.Keys,filename)
|
|
|
+ logging.Info("DownloadFile ", context.Keys, filename)
|
|
|
eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_doc where id = ? ", filename).QueryString()
|
|
|
if eqpic == nil {
|
|
|
http.NotFound(context.Writer, context.Request)
|
|
|
return
|
|
|
}
|
|
|
- originFilePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath,eqpic[0]["docpath"],eqpic[0]["newdocname"])
|
|
|
+ originFilePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, eqpic[0]["docpath"], eqpic[0]["newdocname"])
|
|
|
if fs.PathExists(originFilePath) == false {
|
|
|
// if the path not found
|
|
|
http.NotFound(context.Writer, context.Request)
|
|
@@ -534,20 +532,19 @@ func DownloadFile(context *gin.Context) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
Get Origin image
|
|
|
*/
|
|
|
func GetOriginImage(context *gin.Context) {
|
|
|
//appG := app.Gin{C: context}
|
|
|
filename := context.Param("filename")
|
|
|
- logging.Info("GetOriginImage ",context.Keys,filename)
|
|
|
+ logging.Info("GetOriginImage ", context.Keys, filename)
|
|
|
eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_pic where id = ? ", filename).QueryString()
|
|
|
if eqpic == nil {
|
|
|
http.NotFound(context.Writer, context.Request)
|
|
|
return
|
|
|
}
|
|
|
- originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath,eqpic[0]["picpath"],eqpic[0]["newpicname"])
|
|
|
+ originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, eqpic[0]["picpath"], eqpic[0]["newpicname"])
|
|
|
if fs.PathExists(originImagePath) == false {
|
|
|
// if the path not found
|
|
|
http.NotFound(context.Writer, context.Request)
|
|
@@ -562,13 +559,13 @@ Get thumbnail image
|
|
|
*/
|
|
|
func GetThumbnailImage(context *gin.Context) {
|
|
|
filename := context.Param("filename")
|
|
|
- logging.Info("GetThumbnailImage ",context.Keys,filename)
|
|
|
+ logging.Info("GetThumbnailImage ", context.Keys, filename)
|
|
|
eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_pic where id = ? ", filename).QueryString()
|
|
|
if eqpic == nil {
|
|
|
http.NotFound(context.Writer, context.Request)
|
|
|
return
|
|
|
}
|
|
|
- thumbnailImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath,eqpic[0]["picpath"],eqpic[0]["newpicname"])
|
|
|
+ thumbnailImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath, eqpic[0]["picpath"], eqpic[0]["newpicname"])
|
|
|
originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, filename)
|
|
|
|
|
|
if fs.PathExists(thumbnailImagePath) == false {
|
|
@@ -587,17 +584,17 @@ func GetThumbnailImage(context *gin.Context) {
|
|
|
/**
|
|
|
Generate thumbnail
|
|
|
*/
|
|
|
-func thumbnailify(imagePath,subdirectory string) (outputPath string, err error) {
|
|
|
+func thumbnailify(imagePath, subdirectory string) (outputPath string, err error) {
|
|
|
var (
|
|
|
- file *os.File
|
|
|
- img image.Image
|
|
|
+ file *os.File
|
|
|
+ img image.Image
|
|
|
)
|
|
|
Filename := strings.ToLower(path.Base(imagePath))
|
|
|
extname := strings.ToLower(path.Ext(imagePath))
|
|
|
- outputPath = setting.CurrentPath + setting.AppSetting.ThumbnailSavePath +subdirectory+ "/" + Filename
|
|
|
- err = PathCheck(setting.CurrentPath + setting.AppSetting.ThumbnailSavePath +subdirectory)
|
|
|
- if err !=nil{
|
|
|
- fmt.Println("thumbnailify PathCheck err",err)
|
|
|
+ outputPath = setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + subdirectory + "/" + Filename
|
|
|
+ err = PathCheck(setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + subdirectory)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("thumbnailify PathCheck err", err)
|
|
|
}
|
|
|
// 读取文件
|
|
|
if file, err = os.Open(imagePath); err != nil {
|
|
@@ -627,7 +624,7 @@ func thumbnailify(imagePath,subdirectory string) (outputPath string, err error)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- m := resize.Thumbnail(uint( setting.AppSetting.ThumbnailMaxWidth), uint(setting.AppSetting.ThumbnailMaxHeight), img, resize.Lanczos3)
|
|
|
+ m := resize.Thumbnail(uint(setting.AppSetting.ThumbnailMaxWidth), uint(setting.AppSetting.ThumbnailMaxHeight), img, resize.Lanczos3)
|
|
|
|
|
|
out, err := os.Create(outputPath)
|
|
|
if err != nil {
|
|
@@ -657,7 +654,7 @@ func thumbnailify(imagePath,subdirectory string) (outputPath string, err error)
|
|
|
}
|
|
|
|
|
|
func UploadFiles(c *gin.Context) {
|
|
|
- logging.Info("UploadFiles ",c.Keys)
|
|
|
+ logging.Info("UploadFiles ", c.Keys)
|
|
|
appG := app.Gin{C: c}
|
|
|
err := c.Request.ParseMultipartForm(200000)
|
|
|
if err != nil {
|
|
@@ -696,16 +693,16 @@ func UploadFiles(c *gin.Context) {
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, "upload successful \n")
|
|
|
}
|
|
|
}
|
|
|
-func PathCheck(path string)(err error){
|
|
|
- b,err :=PathExists(path)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("exist err",err)
|
|
|
+func PathCheck(path string) (err error) {
|
|
|
+ b, err := PathExists(path)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("exist err", err)
|
|
|
}
|
|
|
- if !b{
|
|
|
- fmt.Println(path," 目录不存在,重新创建")
|
|
|
+ if !b {
|
|
|
+ fmt.Println(path, " 目录不存在,重新创建")
|
|
|
err = os.Mkdir(path, 0777)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Mkdir err",err)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Mkdir err", err)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
@@ -719,4 +716,78 @@ func PathExists(path string) (bool, error) {
|
|
|
return false, nil
|
|
|
}
|
|
|
return false, err
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+func GetBarfeedremainExcel(c *gin.Context) {
|
|
|
+
|
|
|
+ var file *xlsx.File
|
|
|
+ var sheet *xlsx.Sheet
|
|
|
+ var row *xlsx.Row
|
|
|
+ var cell *xlsx.Cell
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ style.ApplyBorder = true
|
|
|
+ border := *xlsx.NewBorder("thin", "thin", "thin", "thin")
|
|
|
+
|
|
|
+ style.Border = border
|
|
|
+
|
|
|
+ style.Font.Size = 11
|
|
|
+ style.Alignment = xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ // ShrinkToFit: true,
|
|
|
+
|
|
|
+ }
|
|
|
+ style.ApplyBorder = true
|
|
|
+
|
|
|
+ file = xlsx.NewFile()
|
|
|
+ sheet, _ = file.AddSheet("Sheet1")
|
|
|
+ // row = sheet.AddRow()
|
|
|
+ // cell = row.AddCell()
|
|
|
+
|
|
|
+ row = sheet.AddRow()
|
|
|
+ cell = row.AddCell()
|
|
|
+ cell.Value = "栏舍名称"
|
|
|
+ // cell.Merge(0, 1)
|
|
|
+ cell.SetStyle(style)
|
|
|
+ cell = row.AddCell()
|
|
|
+
|
|
|
+ cell.SetValue("剩料量(kg)")
|
|
|
+ cell.SetStyle(style)
|
|
|
+ cell = row.AddCell()
|
|
|
+
|
|
|
+ cell.SetValue("班次(第一班,第二班,第三班)")
|
|
|
+ cell.SetStyle(style)
|
|
|
+ cell = row.AddCell()
|
|
|
+
|
|
|
+ cell.SetValue("收集时间")
|
|
|
+ cell.SetStyle(style)
|
|
|
+ cell = row.AddCell()
|
|
|
+
|
|
|
+ cell.SetValue("操作人")
|
|
|
+ cell.SetStyle(style)
|
|
|
+ cell = row.AddCell()
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ dataList, err := tx.SQL(`select bname from bar where pastureid = (select column_default as pastureid from information_schema.COLUMNS
|
|
|
+ WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid') order by sort ,id`, setting.DatabaseSetting.Name).Query().List()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("CronScheduled-error-1:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, data := range dataList {
|
|
|
+ row = sheet.AddRow()
|
|
|
+ cell = row.AddCell()
|
|
|
+ cell.SetValue(data["bname"])
|
|
|
+ cell.SetStyle(style)
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
+ c.Header("Content-Disposition", "attachment; filename="+"栏舍剩料记录导入模板.xlsx")
|
|
|
+ c.Header("Content-Transfer-Encoding", "binary")
|
|
|
+
|
|
|
+ _ = file.Write(c.Writer)
|
|
|
+}
|