// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
|
|
|
|
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kataras/iris/v12"
|
|
"github.com/kataras/iris/v12/core/router"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/global"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/task"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/utils"
|
|
logUtils "leit.com/LAPP_CHEERSSON_BACKEND/utils/log"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/web/middleware/jwts"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/web/supports"
|
|
"strings"
|
|
)
|
|
|
|
func RegisterOrg(party router.Party, path string) {
|
|
party.Handle("GET", path, func(ctx iris.Context) {
|
|
_, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
data := task.ImportOrg()
|
|
supports.Ok(ctx, supports.OptionSuccess, data)
|
|
})
|
|
}
|
|
func RegisterEmpinfo(party router.Party, path string) {
|
|
party.Handle("GET", path, func(ctx iris.Context) {
|
|
_, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
data := task.ImportEmpinfo()
|
|
supports.Ok(ctx, supports.OptionSuccess, data)
|
|
})
|
|
}
|
|
|
|
//读取日志
|
|
func RegisterReadLog(party router.Party, path string) {
|
|
party.Get(path+"/{model:string}"+"/{fileName:string}", func(ctx iris.Context) {
|
|
|
|
model := ctx.Params().GetString("model")
|
|
fileName := ctx.Params().GetString("fileName")
|
|
data := logUtils.Read(model, fileName)
|
|
ctx.Write(data)
|
|
})
|
|
}
|
|
|
|
//同步采购
|
|
func RegisterCaiGou(party router.Party, path string) {
|
|
party.Get(path, func(ctx iris.Context) {
|
|
task.ImportChaigou()
|
|
supports.Ok(ctx, supports.OptionSuccess, nil)
|
|
})
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Function Name : RegisterUploadMustPic
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description : 为一个通过主键处理多条RegisterUploadMustPic的方法注册路由
|
|
*
|
|
* @Function Parameters : 路由分组
|
|
*
|
|
* @Function Parameters : HTTP方法
|
|
*
|
|
* @Function Parameters : 路径
|
|
*
|
|
* @Function Parameters : 实际处理请求的方法
|
|
*
|
|
* @Author : 代码生成器创建
|
|
*
|
|
* @Date : 2021-03-18 22:49:12
|
|
*
|
|
******************************************************************************/
|
|
func RegisterUploadMustPic(party router.Party, httpMethod string, path string, method func(*global.User) error) {
|
|
|
|
party.Handle(httpMethod, path, func(ctx iris.Context) {
|
|
user, ok := jwts.ParseToken(ctx)
|
|
if !ok {
|
|
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
|
|
return
|
|
}
|
|
|
|
var err error = nil
|
|
//获取通过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"]
|
|
var uploadfiles []string
|
|
for _, file := range files {
|
|
if !utils.ValueIsEmpty(file.Filename) {
|
|
filename := strings.Split(file.Filename, ".")
|
|
filetype := filename[1]
|
|
guid := utils.MakeOrderSn(user.UserId)
|
|
filPath := "public/uploadfile/" + guid + "." + filetype
|
|
savePath := "web/public/uploadfile/" + guid + "." + filetype
|
|
// 上传文件至指定目录
|
|
err := utils.SaveUploadedFile(file, savePath)
|
|
if err != nil {
|
|
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
|
|
return
|
|
}
|
|
fmt.Println(filPath)
|
|
uploadfiles = append(uploadfiles, filPath)
|
|
}
|
|
}
|
|
picPath := strings.Join(uploadfiles, ",")
|
|
supports.Ok(ctx, supports.OptionSuccess, picPath)
|
|
})
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Function Name : RegisterUploadPic
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description : 上传图片的方法注册路由
|
|
*
|
|
* @Function Parameters : 路由分组
|
|
*
|
|
* @Function Parameters : 路径
|
|
*
|
|
* @Function Parameters : 实际处理请求的方法
|
|
*
|
|
* @Author : 代码生成器创建
|
|
*
|
|
* @Date : 2021-03-18 22:49:12
|
|
*
|
|
******************************************************************************/
|
|
func RegisterUploadPic(party router.Party, path string, method func(*global.User) error) {
|
|
RegisterUploadMustPic(party, "POST", path, method)
|
|
}
|