|
|
|
|
package publicmethod
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get请求
|
|
|
|
|
func CurlGet(getUrl string) []byte {
|
|
|
|
|
client := &http.Client{}
|
|
|
|
|
reqest, err := http.NewRequest("GET", getUrl, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
response, _ := client.Do(reqest)
|
|
|
|
|
defer response.Body.Close()
|
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
|
return body
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Post请求 json
|
|
|
|
|
func CurlPostJosn(postUrl string, jsonData []byte) []byte {
|
|
|
|
|
req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData))
|
|
|
|
|
req.Header.Set("Content-Type", "application/json;charset=utf-8")
|
|
|
|
|
client := &http.Client{}
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
|
|
|
return body
|
|
|
|
|
}
|