KPI绩效考核系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.6 KiB

package publicmethod
import (
"encoding/json"
"errors"
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/overall"
"net/http"
"github.com/gin-gonic/gin"
)
// 格式化输出
func Result(code int, data interface{}, c *gin.Context, msgAry ...string) {
var msg string
if _, isTrue := ErrorCodeMsg[code]; isTrue {
msg = ErrorCodeMsg[code]
}
if len(msgAry) > 0 {
for _, v := range msgAry {
if msg == "" {
msg = fmt.Sprintf("%v", v)
} else {
msg = fmt.Sprintf("%v。%v", msg, v)
}
}
}
c.JSON(http.StatusOK, Reply{code, msg, data}) //输出json格式数据
}
//列表输出标准格式
/*
@total 总数
@count 当前页总数
@page 页数
@pageSize 每页显示数量
@data 返回数据
*/
func ResultList(code, page, pageSize int, total, count int64, data interface{}, c *gin.Context) (printMap map[string]interface{}) {
outMap := MapOut[string]()
outMap["count"] = count
outMap["total"] = total
outMap["page"] = page
outMap["pageSize"] = pageSize
outMap["list"] = data
printMap = outMap
Result(code, outMap, c)
return
}
// 登录信息转换
func LoginMyCont(c *gin.Context) (myCont modelshr.ManCont, err error) {
context, exi := c.Get(overall.MyContJwt)
if exi != true {
err = errors.New("对不起!你没有该功能的操作权限!1")
return
}
jsonCont, jsonErr := json.Marshal(context)
// fmt.Printf("LoginMyCont--------->%v\n", string(jsonCont))
if jsonErr != nil {
err = jsonErr
return
}
jsonUnErr := json.Unmarshal(jsonCont, &myCont)
if jsonUnErr != nil {
err = jsonUnErr
return
}
return
}