Commit 9bf9e037 authored by haoyanbin's avatar haoyanbin

1

parents
Pipeline #425 failed with stages
FROM golang:1.19 as builder
# 设置环境变量GO111MODULE为on
ENV GO111MODULE=on
# 设置环境变量GOPROXY为https://goproxy.io,direct
ENV GOPROXY=https://goproxy.cn,direct
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝server项目到工作目录
COPY . .
# go env为查看go的环境变量, go build -o server . 为打包项目,二进制
# RUN go build -o server .
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o server .
# ======= 以下为多阶段构建 =======
# 声明镜像来源为alpine:latest
FROM alpine:latest
ENV TZ=Asia/Shanghai
RUN echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories \
&& apk --no-cache add tzdata zeromq \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo '$TZ' > /etc/timezone
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝打包好的server二进制文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/server ./
# 拷贝config.yaml配置文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/config.yaml ./
# 拷贝resource静态文件夹到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/resource ./resource
# 运行打包好的二进制
RUN pwd \
&& ls
EXPOSE 8051
ENTRYPOINT ["/go/src/gin-vue-admin/server"]
FROM golang:1.19 as builder
# 设置环境变量GO111MODULE为on
ENV GO111MODULE=on
# 设置环境变量GOPROXY为https://goproxy.io,direct
ENV GOPROXY=https://goproxy.cn,direct
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝server项目到工作目录
COPY . .
# go env为查看go的环境变量, go build -o server . 为打包项目,二进制
# RUN go build -o server .
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o server .
# ======= 以下为多阶段构建 =======
# 声明镜像来源为alpine:latest
FROM alpine:latest
ENV TZ=Asia/Shanghai
RUN echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories \
&& apk --no-cache add tzdata zeromq \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo '$TZ' > /etc/timezone
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝打包好的server二进制文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/server ./
# 拷贝config.yaml配置文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/online/config.yaml ./
# 拷贝resource静态文件夹到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/resource ./resource
# 运行打包好的二进制
RUN pwd \
&& ls
EXPOSE 8052
ENTRYPOINT ["/go/src/gin-vue-admin/server"]
\ No newline at end of file
FROM golang:1.19 as builder
# 设置环境变量GO111MODULE为on
ENV GO111MODULE=on
# 设置环境变量GOPROXY为https://goproxy.io,direct
ENV GOPROXY=https://goproxy.cn,direct
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝server项目到工作目录
COPY . .
# go env为查看go的环境变量, go build -o server . 为打包项目,二进制
# RUN go build -o server .
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o server .
# ======= 以下为多阶段构建 =======
# 声明镜像来源为alpine:latest
FROM alpine:latest
ENV TZ=Asia/Shanghai
RUN echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories \
&& apk --no-cache add tzdata zeromq \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo '$TZ' > /etc/timezone
# 声明工作目录
WORKDIR /go/src/gin-vue-admin
# 拷贝打包好的server二进制文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/server ./
# 拷贝config.yaml配置文件到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/onlinebk/config.yaml ./
# 拷贝resource静态文件夹到当前工作目录
COPY --from=builder /go/src/gin-vue-admin/resource ./resource
# 运行打包好的二进制
RUN pwd \
&& ls
EXPOSE 8052
ENTRYPOINT ["/go/src/gin-vue-admin/server"]
\ No newline at end of file
整理代码结构
``` lua
web
├── api/v1 -- 主要API
| ├── sys_initdb.go -- ico
| └── sys_user.go --
├── config -- 配置文件 设定操作的结构体
| ├── auto_code.go -- ico captcha.go
| ├── ... -- ico captcha.go
| └── zap.go -- core
├── core -- 主要结构代码
| ├── server_other.go -- ico captcha.go
| ├── ... -- ico captcha.go
| └── zap.go --
├── docs -- 文档系统
| ├── docs.go -- ico captcha.go
| ├── swagger.json -- json
| └── swagger.yaml -- yaml
├── global -- global
├── initialize -- initialize
├── middleware -- 中间键
├── model -- global
├── request -- 所有请求model结构体
| | ├── common.go
| | ├── ...
| | └── sys_user.go -- yaml
| ├── response -- 返回数据
| | ├── common.go
| | ├── ...
| | └── sys_user.go -- yaml
├── packfile -- 文件写入
├── resource -- 资源文件
├── router -- 路由
├── service -- service层
├── source -- 文件目录操作
├── utils
├── config.yaml --
├── Dockerfile -- docker配置
├── go.mod -- mod 配置
├── go.sum -- sum
├── latest_log -- vue-cli 配置
└── main.go -- package.json
```
\ No newline at end of file
package mobile
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Router /ai/apiOwn [post]
func ApiOwn(c *gin.Context) {
var req request.ApiOwnReq
_ = c.ShouldBindJSON(&req)
var err error
data := ""
if req.ApiMethod == "GET" {
postData := make(map[string]string)
data, err = utils.Get(req.ApiUrl, postData, "", 1)
} else {
data = utils.Post(req.ApiUrl, req.ApiData, "", 1)
}
reply := new(interface{})
utils.UnserislizeJson(data, reply)
//用户调用api日志
apiLog := model.ApiLog{
UserId: getUserID(c),
Status: 1,
Api: req.ApiUrl,
Req: string(utils.SerializeJson(req)),
Reply: string(utils.SerializeJson(reply)),
}
service.CreateApiLog(apiLog)
if data == "" {
global.GVA_LOG.Error("失败!", zap.Any("err", err))
response.FailWithMessage("失败", c)
} else {
response.OkWithData(reply, c)
}
return
}
// @Router /ai/apiField [get]
func ApiField(c *gin.Context) {
var req request.ApiFieldReq
_ = c.ShouldBindJSON(&req)
title := make(map[string]string, 0)
title["t1"] = "视频学习"
title["t2"] = "病例学习"
title["t3"] = "智能诊断"
title["t4"] = "看病例"
title["t5"] = "买商品"
response.OkWithData(title, c)
return
}
package mobile
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Router /ai/aiUploadToCos [post]
func InterpretationInfo(c *gin.Context) {
var req request.InterpretationInfoReq
_ = c.ShouldBindJSON(&req)
if req.Id == "" || req.Id == "0" {
response.FailWithMessage("数据有误,请重新生成二维码", c)
}
var err error
token := utils.NewLogin()
reply := utils.InterpretationInfo(&req, token)
//用户调用api日志
apiLog := model.ApiLog{
UserId: getUserID(c),
Status: reply.Code,
Api: "/api/v1/dcm-interpretation-manager/",
Req: string(utils.SerializeJson(req)),
Reply: string(utils.SerializeJson(reply.Data)),
}
service.CreateApiLog(apiLog)
if reply.Code != 200 {
global.GVA_LOG.Error("失败!", zap.Any("err", err))
response.FailWithMessage("失败", c)
} else {
response.OkWithData(reply.Data, c)
}
return
}
package mobile
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"time"
)
func PointsAddByMobile(c *gin.Context) {
var req request.PointsLogInsertReq
_ = c.ShouldBindJSON(&req)
var err error
cTime := time.Now()
if req.Phone == "" {
response.ApiFailWithMessage(2002, "医生手机号不得为空", c)
return
}
if service.IsPointsLog(req.OtherNo) > 0 {
response.ApiFailWithMessage(2001, "数据重复", c)
return
}
userData := service.FindUserByMobile(req.Phone)
pointsNum := new(request.PointsNumByMobileReply)
pointsNum.HospitalNum, pointsNum.DoctorNum = service.GetPointsLogNum(req.HospitalCode, int(userData.ID))
if pointsNum.HospitalNum > 1 {
}
if pointsNum.DoctorNum > 1 {
}
//积分流水
reqPointsLog := model.PointsLog{}
reqPointsLog.HospitalCode = req.HospitalCode
reqPointsLog.UserId = int(userData.ID)
reqPointsLog.ChangeType = 2
reqPointsLog.ChangeTime = cTime
reqPointsLog.ChangeNum = 100
reqPointsLog.NowPointsNum = userData.PointsNum + reqPointsLog.ChangeNum
reqPointsLog.Remark = "提交金像奖病历"
reqPointsLog.OtherNo = req.OtherNo
reqPointsLog.CreateTime = cTime
if req.Source < 2 {
reqPointsLog.Source = 1
}
err = service.CreatePointsLog(reqPointsLog)
if err != nil {
global.GVA_LOG.Error("赠送失败!", zap.Any("err", err))
response.FailWithMessage("赠送失败", c)
return
}
//修改积分
err = service.UpdateUserPoints(int(userData.ID), 1, reqPointsLog.ChangeNum)
//用户操作日志
apiLog := model.ApiLog{
UserId: userData.ID,
Api: "/points/addByMobile",
Req: string(utils.SerializeJson(req)),
Reply: "",
}
service.CreateApiLog(apiLog)
//fmt.Println(reply)
response.ApiOk(c)
return
}
func PointsNumByMobile(c *gin.Context) {
var req request.PointsLogInsertReq
_ = c.ShouldBindJSON(&req)
if req.Phone == "" {
response.ApiFailWithMessage(2002, "医生手机号不得为空", c)
return
}
userData := service.FindUserByMobile(req.Phone)
reply := new(request.PointsNumByMobileReply)
reply.HospitalNum, reply.DoctorNum = service.GetPointsLogNum(req.HospitalCode, int(userData.ID))
//用户操作日志
apiLog := model.ApiLog{
UserId: userData.ID,
Api: "/points/pointsDataByMobile",
Req: string(utils.SerializeJson(req)),
Reply: string(utils.SerializeJson(reply)),
}
service.CreateApiLog(apiLog)
//fmt.Println(reply)
response.ApiOkWithData(reply, c)
return
}
func GetPointsList(c *gin.Context) {
var req request.GetPointsLogListReq
_ = c.ShouldBindJSON(&req)
userId := getUserID(c)
req.UserId = int(userId)
err, list, total := service.GetPointsLogList(req)
_, userData := service.GetUserInfo(userId)
pointsData := request.PointsData{}
pointsData.PointsTotal = userData.PointsNum
pointsData.PointsIncomeTotal = service.GetPointsData(int(userId), 2)
pointsData.PointsExpendTotal = service.GetPointsData(int(userId), 3)
reply := request.GetPointsLogListReply{}
reply.List = list
reply.Total = total
reply.PointsData = pointsData
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(reply, c)
}
return
}
package mobile
import (
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags ReportComment
// @Summary 查询书列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReadBooks true "查询书列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/getReadBooks [get]
func GetReadBooks(c *gin.Context) {
if err, readBooks := service.GetReadBooks(); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"readBooks": readBooks}, c)
}
return
}
// @Tags ReportComment
// @Summary 用bookId查询书目录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReadCatalog true "查询书目录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/getReadCatalog [post]
func GetReadCatalog(c *gin.Context) {
var req request.GetReadCatalog
_ = c.ShouldBindJSON(&req)
if err, catalogs := service.GetReadCatalog(req.Id); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
reply := utils.GetBookCatalogs(catalogs, 0)
response.OkWithData(gin.H{"catalogs": reply}, c)
}
return
}
// @Tags ReportComment
// @Summary 用cataId查询文章
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReadBooks true "查询文章"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/getReadBooks [post]
func GetReadContent(c *gin.Context) {
var req request.GetReadContent
_ = c.ShouldBindJSON(&req)
if err, content := service.GetReadContent(req.Id); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(content, c)
}
return
}
// @Tags ReportComment
// @Summary 查询用户浏览历史
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReadHistoryReq true "查询浏览历史"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/getReadHistory [post]
func GetReadHistory(c *gin.Context) {
var req request.GetReadHistoryReq
_ = c.ShouldBindJSON(&req)
if err, content := service.GetReadHistory(req); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(content, c)
}
return
}
// @Tags ReportComment
// @Summary 新增浏览记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadHistory true "新增浏览记录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"新增成功"}"
// @Router /read/addReadHistory [post]
func AddReadHistory(c *gin.Context) {
var req request.CreateReadHistory
_ = c.ShouldBindJSON(&req)
service.CreateReadHistory(req)
response.OkWithMessage("创建成功", c)
}
// @Tags ReportComment
// @Summary 更新浏览记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadHistory true "更新浏览记录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /read/updateReadHistory [post]
func UpdateReadHistory(c *gin.Context) {
var req request.CreateReadHistory
_ = c.ShouldBindJSON(&req)
service.UpdateReadHistory(req)
response.OkWithMessage("更新成功", c)
}
package mobile
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
func GetSurveyUserList(c *gin.Context) {
var req request.GetSurveyUserListReq
_ = c.ShouldBindJSON(&req)
response.OkWithData(req, c)
return
}
func CreateSurveyUser(c *gin.Context) {
var req request.CreateSurveyUserReq
_ = c.ShouldBindJSON(&req)
SurveyUser := model.SurveyUser{
SurveyId: 1,
UserId: req.UserId,
Contacts: req.Contacts,
ContactsMobile: req.ContactsMobile,
CreateTime: utils.NowTime(),
}
_, surveyUserId := service.CreateSurveyUser(SurveyUser)
for _, v := range req.Data {
v.SurveyUserId = surveyUserId
service.CreateSurveyUserData(v)
}
return
}
func CreateSurveyLog(c *gin.Context) {
var req model.SurveyLog
_ = c.ShouldBindJSON(&req)
req.CreateTime = utils.NowTime()
if err := service.CreateSurveyLog(req); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
return
}
This diff is collapsed.
package mobile
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"time"
)
func OpenVip(c *gin.Context) {
var req request.OpenVipReq
_ = c.ShouldBindJSON(&req)
//response.OkWithData(gin.H{"reply": req}, c)
//return
err, vipConf := service.GetVipConf(req.VipId)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
userId := getUserID(c)
err, userData := service.GetUserInfo(userId)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
if req.IsPoints == 1 {
req.Money = req.Money - req.PointsNum
}
if req.IsPoints == 1 && req.PointsNum > (userData.PointsNum-userData.PointsNumFreeze) {
fmt.Println(req.PointsNum, userData.PointsNum)
response.FailWithMessage("支付失败,积分数量不足", c)
return
}
if req.IsPoints == 1 && vipConf.VipMoney != req.Money+req.PointsNum {
fmt.Println(vipConf.VipMoney, req.Money, req.PointsNum)
response.FailWithMessage("支付失败,支付金额有误", c)
return
}
if req.Money < 1 {
fmt.Println(req.Money)
response.FailWithMessage("支付失败,支付金额有误", c)
return
}
//创建vip订单
reqVipOrder := model.VipOrder{}
reqVipOrder.OrderNo = utils.GetOrderNo("V", int(userId))
reqVipOrder.UserId = int(userId)
reqVipOrder.VipLevel = vipConf.VipLevel
reqVipOrder.VipMoney = vipConf.VipMoney
reqVipOrder.VipDay = vipConf.VipDay
reqVipOrder.VipConfId = vipConf.Id
reqVipOrder.PayMoney = req.Money
reqVipOrder.Status = 1
reqVipOrder.IsPoints = req.IsPoints
reqVipOrder.PointsNum = req.PointsNum
err = service.CreateVipOrder(reqVipOrder)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
if req.IsPoints == 1 {
//创建积分订单
reqPointsOrder := model.PointsOrder{}
reqPointsOrder.UserId = int(userId)
reqPointsOrder.PayType = 1
reqPointsOrder.PayStatus = 1
reqPointsOrder.PointsNo = utils.GetOrderNo("P", int(userId))
reqPointsOrder.PointsNum = req.PointsNum
reqPointsOrder.OtherNo = reqVipOrder.OrderNo
reqPointsOrder.Remark = "vip抵扣"
err = service.CreatePointsOrder(reqPointsOrder)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
}
//发起支付
orderPay := new(request.OrderPayReq)
orderPay.OrderNo = reqVipOrder.OrderNo
orderPay.PayMoney = float64(req.Money) / 100
orderPay.WxCode = req.WxCode
orderPay.PayCallBack = global.GVA_CONFIG.Pay.PayCallBack
orderPay.UserType = req.UserType
if req.Openid == "" {
//orderPay.Openid = userData.Openid
global.GVA_LOG.Error("openid为空", zap.Any("err", err))
//response.FailWithMessage("用户数据有误", c)
//return
} else {
orderPay.Openid = req.Openid
}
//req.Openid = ""
reply, err := goPay(orderPay)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
//fmt.Println(reply)
response.OkWithData(gin.H{"reply": reply}, c)
return
}
func goPay(orderPay *request.OrderPayReq) (interface{}, error) {
//orderPayLog, _ := json.Marshal(orderPay)
//收款账户配置
var err error
if orderPay.Openid == "" {
//orderPay.Openid, err = wx.GetOpenId(global.GVA_CONFIG.Bkwx.Appid,
// global.GVA_CONFIG.Bkwx.Appsecret, orderPay.WxCode)
//获取openid
//if err != nil || orderPay.Openid == "" {
//fmt.Println(err)
return nil, errors.New("openid不存在,支付失败")
//}
}
confData := service.GetSysConf("pay_conf")
confVal := new(request.SysConfPayConf)
utils.UnserislizeJson(confData, confVal)
data, err := utils.Pay(orderPay, confVal.PayNum)
if err != nil || data == nil {
return "", err
}
//data = orderPay.OrderNo
return data, nil
}
func GetVipList(c *gin.Context) {
var req request.GetVipConfListReq
_ = c.ShouldBindJSON(&req)
req.IsNewUser = 1
if service.IsNewUser(int(getUserID(c))) > 0 {
req.IsNewUser = 0
}
err, list, total := service.GetVipConfList(req)
reply := request.GetVipConfListReply{}
reply.List = list
reply.Total = total
if pointsConf := service.GetSysConf("points"); pointsConf != "" {
confValPoints := new(request.SysConfPoints)
utils.UnserislizeJson(pointsConf, confValPoints)
reply.SysConfPoints = *confValPoints
}
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(reply, "获取成功", c)
}
return
}
func CallBack(c *gin.Context) {
var req request.CallBackReq
_ = c.ShouldBindJSON(&req)
_, logData := service.GetApiLogInfoForReq(string(utils.SerializeJson(req)))
if logData.Id > 0 {
return
}
//用户调用api日志
apiLog := model.ApiLog{
UserId: 1,
Status: 1,
Api: "/vip/callBack",
Req: string(utils.SerializeJson(req)),
Reply: "",
}
service.CreateApiLog(apiLog)
err, vipOrder := service.GetVipOrder(req.AttachInfo)
if err != nil {
fmt.Println("GetVipOrder", err)
}
if vipOrder.Status == 2 {
//return
}
//修改订单信息
err = service.UpdateVipOrder(req)
if err != nil {
fmt.Println("UpdateVipOrder", err)
}
if req.AttachInfo[0:3] == "WXP" {
} else {
err, vipUser := service.GetVipUser(vipOrder.UserId)
if err != nil {
fmt.Println("GetVipUser", err)
}
if vipOrder.IsPoints == 1 && vipOrder.PointsNum != 0 {
//修改积分订单,扣减积分
err = service.UpdatePointsOrderForOtherNo(req.AttachInfo)
if err != nil {
fmt.Println("UpdatePointsOrderForOtherNo", err)
}
err = service.UpdateUserPoints(vipOrder.UserId, 2, vipOrder.PointsNum)
if err != nil {
fmt.Println("UpdateUserPoints", err)
}
err, userData := service.GetUserInfo(uint(vipOrder.UserId))
if err != nil {
fmt.Println("GetUserInfo", err)
}
cTime := time.Now()
//积分流水
reqPointsLog := model.PointsLog{}
reqPointsLog.UserId = vipOrder.UserId
reqPointsLog.ChangeType = 3
reqPointsLog.ChangeTime = cTime
reqPointsLog.ChangeNum = vipOrder.PointsNum
reqPointsLog.NowPointsNum = userData.PointsNum
reqPointsLog.Remark = "VIP业务"
reqPointsLog.OtherNo = req.AttachInfo
reqPointsLog.Source = 2
reqPointsLog.CreateTime = cTime
err = service.CreatePointsLog(reqPointsLog)
if err != nil {
global.GVA_LOG.Error("赠送失败!", zap.Any("err", err))
response.FailWithMessage("赠送失败", c)
return
}
}
//增加时间
if vipUser.Id != 0 {
reqVipUser := model.VipUser{}
reqVipUser.UserId = vipOrder.UserId
reqVipUser.VipLevel = vipOrder.VipLevel
if time.Now().Before(vipUser.MaturityTime) {
reqVipUser.MaturityTime = vipUser.MaturityTime.AddDate(0, 0, vipOrder.VipDay)
} else {
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, vipOrder.VipDay)
}
if err := service.UpdateVipUser(reqVipUser, vipOrder.UserId); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
} else {
reqVipUser := model.VipUser{}
reqVipUser.UserId = vipOrder.UserId
reqVipUser.VipLevel = vipOrder.VipLevel
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, vipOrder.VipDay)
if err := service.CreateVipUser(reqVipUser); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
}
return
}
func OpenVipOwn(c *gin.Context) {
var req request.OpenVipOwnReq
_ = c.ShouldBindJSON(&req)
//用户调用api日志
apiLog := model.ApiLog{
UserId: 1,
Status: 1,
Api: "/vip/openVipOwn",
Req: string(utils.SerializeJson(req)),
Reply: "",
}
service.CreateApiLog(apiLog)
userInfo := service.FindUserByMobile(req.Mobile)
if userInfo.ID == 0 {
response.FailWithMessage("用户未注册", c)
return
//user := model.SysUser{
// Mobile: req.Mobile,
//}
//_, userInfo = service.UserRegister(user)
}
userId := int(userInfo.ID)
var replyVipUser model.VipUser
var err error
if service.IsVipUser(userId) == 1 {
err, replyVipUser = service.GetVipUser(userId)
if err != nil {
fmt.Println(err)
return
}
}
reqVipUser := model.VipUser{}
reqVipUser.UserId = userId
reqVipUser.VipLevel = 2
//增加时间
if replyVipUser.Id != 0 {
if time.Now().Before(replyVipUser.MaturityTime) {
reqVipUser.MaturityTime = replyVipUser.MaturityTime.AddDate(0, 0, req.Day)
} else {
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, req.Day)
}
if err := service.UpdateVipUser(reqVipUser, userId); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
return
}
} else {
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, req.Day)
if err := service.CreateVipUser(reqVipUser); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
return
}
}
response.OkWithData(reqVipUser, c)
return
}
package mobile
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"gin-vue-admin/utils/wx"
"github.com/gin-gonic/gin"
)
type GetUnlimitedReq struct {
HospitalCode string `json:"hospitalCode"`
DoctorPhone string `json:"doctorPhone"`
OtherNo string `json:"otherNo"`
QrType string `json:"qrType"`
}
type GetUnlimitedForSurveyReply struct {
QrData string `json:"qrData"`
OpenLink string `json:"openLink"`
}
type GetUnlimitedData struct {
Scene string `json:"scene"` //最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
Page string `json:"page"` //必须是已经发布的小程序存在的页面(否则报错),例如 pages/index/index, 根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面
Width int `json:"width"` //二维码的宽度,单位 px,最小 280px,最大 1280px
ColorR string `json:"color_r"` //设置颜色
ColorG string `json:"color_g"` //设置颜色
ColorB string `json:"color_b"` //设置颜色
}
type GetSchemeReq struct {
Path string `json:"path"`
Query string `json:"query"`
}
type GetTokenData struct {
Code int `json:"code"`
Data string `json:"data"`
Msg string `json:"msg"`
}
func GetUnlimitedForOther(c *gin.Context) {
var req GetUnlimitedReq
_ = c.ShouldBindJSON(&req)
token := getToken()
data := GetUnlimitedData{}
data.Scene = req.HospitalCode + ";" + req.DoctorPhone + ";" + req.OtherNo + ";" + req.QrType
data.Page = ""
errcode, reply := getUnlimited(token, data)
if errcode != 200 {
response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
} else {
response.OkWithData(reply, c)
return
}
}
func GetUnlimited(c *gin.Context) {
var req GetUnlimitedReq
_ = c.ShouldBindJSON(&req)
token := getToken()
data := GetUnlimitedData{}
data.Scene = req.HospitalCode + ";" + req.DoctorPhone + ";" + req.OtherNo + ";1"
data.Page = ""
errcode, reply := getUnlimited(token, data)
if errcode != 200 {
response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
} else {
response.OkWithData(reply, c)
return
}
}
func GetUnlimitedForReport(c *gin.Context) {
var req GetUnlimitedReq
_ = c.ShouldBindJSON(&req)
token := getToken()
data := GetUnlimitedData{}
data.Scene = req.HospitalCode + ";" + req.DoctorPhone + ";" + req.OtherNo + ";4"
data.Page = "pages/casesDetail/casesDetail"
errcode, reply := getUnlimited(token, data)
if errcode != 200 {
response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
} else {
response.OkWithData(reply, c)
return
}
}
func GetUnlimitedForSurvey(c *gin.Context) {
var req GetUnlimitedReq
_ = c.ShouldBindJSON(&req)
token := getToken()
data := GetUnlimitedData{}
data.Scene = req.HospitalCode + ";" + req.DoctorPhone + ";" + req.OtherNo + ";2"
//data.Page = ""
data.Page = "doctor/questionnaire/q1"
errcode, qrData := getUnlimited(token, data)
if errcode != 200 {
response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
}
schemeReq := GetSchemeReq{}
schemeReq.Path = data.Page
schemeReq.Query = data.Scene
errcode, openLink := getScheme(token, schemeReq)
reply := GetUnlimitedForSurveyReply{}
reply.QrData = qrData.(string)
reply.OpenLink = openLink
if errcode != 200 {
response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
} else {
response.OkWithData(reply, c)
return
}
}
func getToken() string {
if global.GVA_CONFIG.Common.Type == "2" {
url := "https://medical.pet-dbc.cn/mobile/getTokenForLines"
postData := make(map[string]string)
resp := utils.Post(url, &postData, "", 1)
fmt.Println(resp)
reply := new(GetTokenData)
utils.UnserislizeJson(resp, reply)
return reply.Data
//return "reply.Data"
} else {
token := service.GetWxToken()
if token != "" {
return token
}
}
tokenRes, err := wx.GetAccessToken(global.GVA_CONFIG.Wx.Appid, global.GVA_CONFIG.Wx.Appsecret)
if tokenRes == nil {
//response.FailWithDetailedCode(411, "", "accesstoken获取失败", c)
return ""
}
if err != nil {
fmt.Println("GetAccessToken", err)
//response.FailWithDetailedCode(412, "", "accesstoken获取失败", c)
return ""
}
service.CreateWxToken(tokenRes.AccessToken)
return tokenRes.AccessToken
}
func delToken() string {
if global.GVA_CONFIG.Common.Type == "2" {
url := "https://medical.pet-dbc.cn/mobile/delTokenForLines"
postData := make(map[string]string)
resp := utils.Post(url, &postData, "", 1)
fmt.Println(resp)
reply := new(GetTokenData)
utils.UnserislizeJson(resp, reply)
return reply.Data
//return "reply.Data"
} else {
service.DelWxToken()
}
return getToken()
}
// @Description 小程序二维码
// @Param body body GetUnlimitedReq true "输入项"
// @Success 200 {object} utils.ResponseData
// @router /api/v1/wxapp/get-unlimited [post]
func getUnlimited(token string, req GetUnlimitedData) (int, interface{}) {
reply, err := wx.GetUnlimited(token, req.Scene, req.Page, 280, "0", "0", "0")
if err != nil {
fmt.Println("获取二维码报错:", err)
token := delToken()
return getUnlimited(token, req)
}
return 200, reply
}
func getScheme(token string, req GetSchemeReq) (int, string) {
reply := wx.GetScheme(token, req.Path, req.Query)
return 200, reply
}
func GetTokenForLines(c *gin.Context) {
response.OkWithData(getToken(), c)
return
}
func DelTokenForLines(c *gin.Context) {
response.OkWithData(delToken(), c)
return
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"io/ioutil"
"strconv"
)
// @Tags ExaFileUploadAndDownload
// @Summary 断点续传到服务器
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "an example for breakpoint resume, 断点续传示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /fileUploadAndDownload/breakpointContinue [post]
func BreakpointContinue(c *gin.Context) {
fileMd5 := c.Request.FormValue("fileMd5")
fileName := c.Request.FormValue("fileName")
chunkMd5 := c.Request.FormValue("chunkMd5")
chunkNumber, _ := strconv.Atoi(c.Request.FormValue("chunkNumber"))
chunkTotal, _ := strconv.Atoi(c.Request.FormValue("chunkTotal"))
_, FileHeader, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
f, err := FileHeader.Open()
if err != nil {
global.GVA_LOG.Error("文件读取失败!", zap.Any("err", err))
response.FailWithMessage("文件读取失败", c)
return
}
defer f.Close()
cen, _ := ioutil.ReadAll(f)
if !utils.CheckMd5(cen, chunkMd5) {
global.GVA_LOG.Error("检查md5失败!", zap.Any("err", err))
response.FailWithMessage("检查md5失败", c)
return
}
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
global.GVA_LOG.Error("查找或创建记录失败!", zap.Any("err", err))
response.FailWithMessage("查找或创建记录失败", c)
return
}
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
if err != nil {
global.GVA_LOG.Error("断点续传失败!", zap.Any("err", err))
response.FailWithMessage("断点续传失败", c)
return
}
if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil {
global.GVA_LOG.Error("创建文件记录失败!", zap.Any("err", err))
response.FailWithMessage("创建文件记录失败", c)
return
}
response.OkWithMessage("切片创建成功", c)
}
// @Tags ExaFileUploadAndDownload
// @Summary 查找文件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "Find the file, 查找文件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查找成功"}"
// @Router /fileUploadAndDownload/findFile [post]
func FindFile(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName")
chunkTotal, _ := strconv.Atoi(c.Query("chunkTotal"))
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
global.GVA_LOG.Error("查找失败!", zap.Any("err", err))
response.FailWithMessage("查找失败", c)
} else {
response.OkWithDetailed(response.FileResponse{File: file}, "查找成功", c)
}
}
// @Tags ExaFileUploadAndDownload
// @Summary 创建文件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "上传文件完成"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"file uploaded, 文件创建成功"}"
// @Router /fileUploadAndDownload/findFile [post]
func BreakpointContinueFinish(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName")
err, filePath := utils.MakeFile(fileName, fileMd5)
if err != nil {
global.GVA_LOG.Error("文件创建失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建失败", c)
} else {
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
}
}
// @Tags ExaFileUploadAndDownload
// @Summary 删除切片
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "删除缓存切片"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
// @Router /fileUploadAndDownload/removeChunk [post]
func RemoveChunk(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName")
filePath := c.Query("filePath")
err := utils.RemoveChunk(fileMd5)
err = service.DeleteFileChunk(fileMd5, fileName, filePath)
if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c)
} else {
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags ExaCustomer
// @Summary 创建客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "客户用户名, 客户手机号码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /customer/customer [post]
func CreateExaCustomer(c *gin.Context) {
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
customer.SysUserID = getUserID(c)
customer.SysUserAuthorityID = getUserAuthorityId(c)
if err := service.CreateExaCustomer(customer); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags ExaCustomer
// @Summary 删除客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /customer/customer [delete]
func DeleteExaCustomer(c *gin.Context) {
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.DeleteExaCustomer(customer); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags ExaCustomer
// @Summary 更新客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "客户ID, 客户信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /customer/customer [put]
func UpdateExaCustomer(c *gin.Context) {
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.UpdateExaCustomer(&customer); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags ExaCustomer
// @Summary 获取单一客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customer [get]
func GetExaCustomer(c *gin.Context) {
var customer model.ExaCustomer
_ = c.ShouldBindQuery(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, data := service.GetExaCustomer(customer.ID)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.ExaCustomerResponse{Customer: data}, "获取成功", c)
}
}
// @Tags ExaCustomer
// @Summary 分页获取权限客户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customerList [get]
func GetExaCustomerList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindQuery(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.PageResult{
List: customerList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// /excel/importExcel 接口,与upload接口作用类似,只是把文件存到resource/excel目录下,用于导入Excel时存放Excel文件(ExcelImport.xlsx)
// /excel/loadExcel接口,用于读取resource/excel目录下的文件((ExcelImport.xlsx)并加载为[]model.SysBaseMenu类型的示例数据
// /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回
// /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板
// @Tags excel
// @Summary 导出Excel
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/octet-stream
// @Param data body model.ExcelInfo true "导出Excel文件信息"
// @Success 200
// @Router /excel/exportExcel [post]
func ExportExcel(c *gin.Context) {
var excelInfo model.ExcelInfo
_ = c.ShouldBindJSON(&excelInfo)
filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
err := service.ParseInfoList2Excel(excelInfo.InfoList, filePath)
if err != nil {
global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
response.FailWithMessage("转换Excel失败", c)
return
}
c.Writer.Header().Add("success", "true")
c.File(filePath)
}
// @Tags excel
// @Summary 导入Excel文件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "导入Excel文件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
// @Router /excel/importExcel [post]
func ImportExcel(c *gin.Context) {
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
_ = c.SaveUploadedFile(header, global.GVA_CONFIG.Excel.Dir+"ExcelImport.xlsx")
response.OkWithMessage("导入成功", c)
}
// @Tags excel
// @Summary 加载Excel数据
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}"
// @Router /excel/loadExcel [get]
func LoadExcel(c *gin.Context) {
menus, err := service.ParseExcel2InfoList()
if err != nil {
global.GVA_LOG.Error("加载数据失败!", zap.Any("err", err))
response.FailWithMessage("加载数据失败", c)
return
}
response.OkWithDetailed(response.PageResult{
List: menus,
Total: int64(len(menus)),
Page: 1,
PageSize: 999,
}, "加载数据成功", c)
}
// @Tags excel
// @Summary 下载模板
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param fileName query string true "模板名称"
// @Success 200
// @Router /excel/downloadTemplate [get]
func DownloadTemplate(c *gin.Context) {
fileName := c.Query("fileName")
filePath := global.GVA_CONFIG.Excel.Dir + fileName
ok, err := utils.PathExists(filePath)
if !ok || err != nil {
global.GVA_LOG.Error("文件不存在!", zap.Any("err", err))
response.FailWithMessage("文件不存在", c)
return
}
c.Writer.Header().Add("success", "true")
c.File(filePath)
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags ExaFileUploadAndDownload
// @Summary 上传文件示例
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "上传文件示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Router /fileUploadAndDownload/upload [post]
func UploadFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, "", "", "") // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
func UploadFileImage(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, global.GVA_CONFIG.AliyunOSSImage.Directory, global.GVA_CONFIG.AliyunOSSImage.BucketName, global.GVA_CONFIG.AliyunOSSImage.BucketUrl) // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
func AiUploadFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, "uploads", "ai-bianque", "https://ai-bianque.oss-cn-beijing.aliyuncs.com") // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
func AiImageUploadFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, "image_uploads", "ai-bianque", "https://ai-bianque.oss-cn-beijing.aliyuncs.com") // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
func BianQueUploadFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, "", "", "") // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
func BianQueImageUploadFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave, "", "", "") // 文件上传后拿到文件路径
if err != nil {
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
// @Tags ExaFileUploadAndDownload
// @Summary 删除文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fileUploadAndDownload/deleteFile [post]
func DeleteFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
_ = c.ShouldBindJSON(&file)
if err := service.DeleteFile(file); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
}
// @Tags ExaFileUploadAndDownload
// @Summary 分页文件列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fileUploadAndDownload/getFileList [post]
func GetFileList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
err, list, total := service.GetFileRecordInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SimpleUploader
// @Summary 断点续传插件版示例
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "断点续传插件版示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /simpleUploader/upload [post]
func SimpleUploaderUpload(c *gin.Context) {
var chunk model.ExaSimpleUploader
_, header, err := c.Request.FormFile("file")
chunk.Filename = c.PostForm("filename")
chunk.ChunkNumber = c.PostForm("chunkNumber")
chunk.CurrentChunkSize = c.PostForm("currentChunkSize")
chunk.Identifier = c.PostForm("identifier")
chunk.TotalSize = c.PostForm("totalSize")
chunk.TotalChunks = c.PostForm("totalChunks")
var chunkDir = "./chunk/" + chunk.Identifier + "/"
hasDir, _ := utils.PathExists(chunkDir)
if !hasDir {
if err := utils.CreateDir(chunkDir); err != nil {
global.GVA_LOG.Error("创建目录失败!", zap.Any("err", err))
}
}
chunkPath := chunkDir + chunk.Filename + chunk.ChunkNumber
err = c.SaveUploadedFile(header, chunkPath)
if err != nil {
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
}
chunk.CurrentChunkPath = chunkPath
err = service.SaveChunk(chunk)
if err != nil {
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
} else {
response.OkWithMessage("切片创建成功", c)
}
}
// @Tags SimpleUploader
// @Summary 断点续传插件版示例
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /simpleUploader/checkFileMd5 [get]
func CheckFileMd5(c *gin.Context) {
md5 := c.Query("md5")
err, chunks, isDone := service.CheckFileMd5(md5)
if err != nil {
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithDetailed(gin.H{
"chunks": chunks,
"isDone": isDone,
}, "查询成功", c)
}
}
// @Tags SimpleUploader
// @Summary 合并文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"合并成功"}"
// @Router /simpleUploader/mergeFileMd5 [get]
func MergeFileMd5(c *gin.Context) {
md5 := c.Query("md5")
fileName := c.Query("fileName")
err := service.MergeFileMd5(md5, fileName)
if err != nil {
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithMessage("合并成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags report
// @Summary 用id查询目录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportInfoReq true "用id查询report"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/GetCatalogList [post]
func GetCatalogList(c *gin.Context) {
var req request.GetReadCatalog
_ = c.ShouldBindJSON(&req)
if err, catalogs := service.GetReadCatalog(req.Id); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
reply := utils.GetBookCatalogs(catalogs, 0)
response.OkWithData(gin.H{"list": reply}, c)
}
return
}
// @Tags report
// @Summary 分页获取文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportListReq true "分页获取文章列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /read/getReadContentList [post]
func GetReadContentList(c *gin.Context) {
var req request.GetReadContentReq
_ = c.ShouldBindJSON(&req)
var err error
// err, reportList, total := service.GetReportList(req, userId, order)
err, reportList, total := service.GetAdminReadContent(req)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
return
}
response.OkWithDetailed(response.PageResult{
List: reportList,
Total: total,
Page: req.Page,
PageSize: req.PageSize,
}, "获取成功", c)
return
}
// @Tags report
// @Summary 分页获取文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportListReq true "分页获取文章详情"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /read/GetReadContent [post]
func GetReadContent(c *gin.Context) {
var req request.GetReadContentReq
_ = c.ShouldBindJSON(&req)
if err, content := service.GetReadContent(req.ReadCatalogId); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(content, c)
}
return
}
// 创建目录
// @Tags report
// @Summary 创建目录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadCatalog true "创建目录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /read/createReadCatalog [post]
func CreateReadCatalog(c *gin.Context) {
var req request.CreateReadCatalog
_ = c.ShouldBindJSON(&req)
service.CreateReadCatalog(req)
response.OkWithMessage("创建成功", c)
}
// 创建文章
// @Tags report
// @Summary 创建文章
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadContent true "创建文章"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /read/createReadContent [post]
func CreateReadContent(c *gin.Context) {
var req request.CreateReadContent
_ = c.ShouldBindJSON(&req)
service.CreateReadContent(req)
response.OkWithMessage("创建成功", c)
}
// 更新目录
func UpdateCatalog(c *gin.Context) {
var req request.CreateReadCatalog
_ = c.ShouldBindJSON(&req)
service.UpdateReadCatalog(req)
response.OkWithMessage("修改成功", c)
}
// 更新文章
func UpdateReadContent(c *gin.Context) {
var req request.CreateReadContent
_ = c.ShouldBindJSON(&req)
service.UpdateReadContent(req)
response.OkWithMessage("修改成功", c)
}
// 删除目录
func DeleteReadCatalog(c *gin.Context) {
var req request.CreateReadCatalog
_ = c.ShouldBindJSON(&req)
service.DeleteReadCatalog(req)
response.OkWithMessage("修改成功", c)
}
// 删除文章
func DeleteReadContent(c *gin.Context) {
var req request.CreateReadContent
_ = c.ShouldBindJSON(&req)
service.DeleteReadContent(req)
response.OkWithMessage("修改成功", c)
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysApi
// @Summary 创建基础api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /api/createApi [post]
func CreateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.CreateApi(api); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysApi
// @Summary 删除api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.DeleteApi(api); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysApi
// @Summary 分页获取API列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SearchApiParams true "分页获取API列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getApiList [post]
func GetApiList(c *gin.Context) {
var pageInfo request.SearchApiParams
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, list, total := service.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
// @Tags SysApi
// @Summary 根据id获取api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "根据id获取api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getApiById [post]
func GetApiById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, api := service.GetApiById(idInfo.ID)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(response.SysAPIResponse{Api: api}, c)
}
}
// @Tags SysApi
// @Summary 创建基础api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /api/updateApi [post]
func UpdateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.UpdateApi(api); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改成功", c)
}
}
// @Tags SysApi
// @Summary 获取所有的Api 不分页
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getAllApis [post]
func GetAllApis(c *gin.Context) {
if err, apis := service.GetAllApis(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.SysAPIListResponse{Apis: apis}, "获取成功", c)
}
}
// @Tags SysApi
// @Summary 删除选中Api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /api/deleteApisByIds [delete]
func DeleteApisByIds(c *gin.Context) {
var ids request.IdsReq
_ = c.ShouldBindJSON(&ids)
if err := service.DeleteApisByIds(ids); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags Authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /authority/createAuthority [post]
func CreateAuthority(c *gin.Context) {
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, authBack := service.CreateAuthority(authority); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
}
}
// @Tags Authority
// @Summary 拷贝角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"拷贝成功"}"
// @Router /authority/copyAuthority [post]
func CopyAuthority(c *gin.Context) {
var copyInfo response.SysAuthorityCopyResponse
_ = c.ShouldBindJSON(&copyInfo)
if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(copyInfo.Authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, authBack := service.CopyAuthority(copyInfo); err != nil {
global.GVA_LOG.Error("拷贝失败!", zap.Any("err", err))
response.FailWithMessage("拷贝失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
}
}
// @Tags Authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "删除角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /authority/deleteAuthority [post]
func DeleteAuthority(c *gin.Context) {
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败"+err.Error(), c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags Authority
// @Summary 更新角色信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /authority/updateAuthority [post]
func UpdateAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
if err := utils.Verify(auth, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, authority := service.UpdateAuthority(auth); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authority}, "更新成功", c)
}
}
// @Tags Authority
// @Summary 分页获取角色列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/getAuthorityList [post]
func GetAuthorityList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, list, total := service.GetAuthorityInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
// @Tags Authority
// @Summary 设置角色资源权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "设置角色资源权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /authority/setDataAuthority [post]
func SetDataAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.SetDataAuthority(auth); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败"+err.Error(), c)
} else {
response.OkWithMessage("设置成功", c)
}
}
package v1
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"net/url"
"os"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags AutoCode
// @Summary 预览创建后的代码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.AutoCodeStruct true "预览创建代码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/preview [post]
func PreviewTemp(c *gin.Context) {
var a model.AutoCodeStruct
_ = c.ShouldBindJSON(&a)
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
autoCode, err := service.PreviewTemp(a)
if err != nil {
global.GVA_LOG.Error("预览失败!", zap.Any("err", err))
response.FailWithMessage("预览失败", c)
} else {
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
}
}
// @Tags AutoCode
// @Summary 自动代码模板
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.AutoCodeStruct true "创建自动代码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/createTemp [post]
func CreateTemp(c *gin.Context) {
var a model.AutoCodeStruct
_ = c.ShouldBindJSON(&a)
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if a.AutoCreateApiToSql {
if err := service.AutoCreateApi(&a); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
return
}
}
err := service.CreateTemp(a)
if err != nil {
if errors.Is(err, model.AutoMoveErr) {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msgtype", "success")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
} else {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
_ = os.Remove("./ginvueadmin.zip")
}
} else {
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/json")
c.Writer.Header().Add("success", "true")
c.File("./ginvueadmin.zip")
_ = os.Remove("./ginvueadmin.zip")
}
}
// @Tags AutoCode
// @Summary 获取当前数据库所有表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getTables [get]
func GetTables(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
err, tables := service.GetTables(dbName)
if err != nil {
global.GVA_LOG.Error("查询table失败!", zap.Any("err", err))
response.FailWithMessage("查询table失败", c)
} else {
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
}
}
// @Tags AutoCode
// @Summary 获取当前所有数据库
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getDatabase [get]
func GetDB(c *gin.Context) {
if err, dbs := service.GetDB(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
}
}
// @Tags AutoCode
// @Summary 获取当前表所有字段
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getColumn [get]
func GetColumn(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
tableName := c.Query("tableName")
if err, columns := service.GetColumn(tableName, dbName); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"go.uber.org/zap"
)
var store = base64Captcha.DefaultMemStore
// @Tags Base
// @Summary 生成验证码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}"
// @Router /base/captcha [post]
func Captcha(c *gin.Context) {
// 字符,公式,验证码配置
// 生成默认数字的driver
driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
cp := base64Captcha.NewCaptcha(driver, store)
if id, b64s, err := cp.Generate(); err != nil {
global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err))
response.FailWithMessage("验证码获取失败", c)
} else {
response.OkWithDetailed(response.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
}, "验证码获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags Casbin
// @Summary 更新角色api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /casbin/UpdateCasbin [post]
func UpdateCasbin(c *gin.Context) {
var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr)
if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags Casbin
// @Summary 获取权限列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func GetPolicyPathByAuthorityId(c *gin.Context) {
var casbin request.CasbinInReceive
_ = c.ShouldBindJSON(&casbin)
if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId)
response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c)
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionary
// @Summary 创建SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionary/createSysDictionary [post]
func CreateSysDictionary(c *gin.Context) {
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.CreateSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysDictionary
// @Summary 删除SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionary/deleteSysDictionary [delete]
func DeleteSysDictionary(c *gin.Context) {
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.DeleteSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysDictionary
// @Summary 更新SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionary/updateSysDictionary [put]
func UpdateSysDictionary(c *gin.Context) {
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.UpdateSysDictionary(&dictionary); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysDictionary
// @Summary 用id查询SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "ID或字典英名"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionary/findSysDictionary [get]
func FindSysDictionary(c *gin.Context) {
var dictionary model.SysDictionary
_ = c.ShouldBindQuery(&dictionary)
if err, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
}
}
// @Tags SysDictionary
// @Summary 分页获取SysDictionary列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionary/getSysDictionaryList [get]
func GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch
_ = c.ShouldBindQuery(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, list, total := service.GetSysDictionaryInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionaryDetail
// @Summary 创建SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
func CreateSysDictionaryDetail(c *gin.Context) {
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.CreateSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 删除SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func DeleteSysDictionaryDetail(c *gin.Context) {
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.DeleteSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 更新SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "更新SysDictionaryDetail"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func UpdateSysDictionaryDetail(c *gin.Context) {
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.UpdateSysDictionaryDetail(&detail); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 用id查询SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "用id查询SysDictionaryDetail"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func FindSysDictionaryDetail(c *gin.Context) {
var detail model.SysDictionaryDetail
_ = c.ShouldBindQuery(&detail)
if err := utils.Verify(detail, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, resysDictionaryDetail := service.GetSysDictionaryDetail(detail.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, "查询成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 分页获取SysDictionaryDetail列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
func GetSysDictionaryDetailList(c *gin.Context) {
var pageInfo request.SysDictionaryDetailSearch
_ = c.ShouldBindQuery(&pageInfo)
if err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags System
// @Summary 发送测试邮件
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/emailTest [post]
func EmailTest(c *gin.Context) {
if err := service.EmailTest(); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
response.FailWithMessage("发送失败", c)
} else {
response.OkWithData("发送成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags Jwt
// @Summary jwt加入黑名单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"拉黑成功"}"
// @Router /jwt/jsonInBlacklist [post]
func JsonInBlacklist(c *gin.Context) {
token := c.Request.Header.Get("x-token")
jwt := model.JwtBlacklist{Jwt: token}
if err := service.JsonInBlacklist(jwt); err != nil {
global.GVA_LOG.Error("jwt作废失败!", zap.Any("err", err))
response.FailWithMessage("jwt作废失败", c)
} else {
response.OkWithMessage("jwt作废成功", c)
}
}
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenu [post]
func GetMenu(c *gin.Context) {
a := getUserAuthorityId(c)
fmt.Println(a)
if err, menus := service.GetMenuTree(getUserAuthorityId(c)); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.SysMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuTree [post]
func GetBaseMenuTree(c *gin.Context) {
if err, menus := service.GetBaseMenuTree(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags AuthorityMenu
// @Summary 增加menu和角色关联关系
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AddMenuAuthorityInfo true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addMenuAuthority [post]
func AddMenuAuthority(c *gin.Context) {
var authorityMenu request.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&authorityMenu)
if err := utils.Verify(authorityMenu, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags AuthorityMenu
// @Summary 获取指定角色menu
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetAuthorityId true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/GetMenuAuthority [post]
func GetMenuAuthority(c *gin.Context) {
var param request.GetAuthorityId
_ = c.ShouldBindJSON(&param)
if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, menus := service.GetMenuAuthority(&param); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithDetailed(response.SysMenusResponse{Menus: menus}, "获取失败", c)
} else {
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
}
}
// @Tags Menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addBaseMenu [post]
func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.AddBaseMenu(menu); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags Menu
// @Summary 删除菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /menu/deleteBaseMenu [post]
func DeleteBaseMenu(c *gin.Context) {
var menu request.GetById
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.DeleteBaseMenu(menu.ID); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags Menu
// @Summary 更新菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /menu/updateBaseMenu [post]
func UpdateBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.UpdateBaseMenu(menu); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags Menu
// @Summary 根据id获取菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuById [post]
func GetBaseMenuById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, menu := service.GetBaseMenuById(idInfo.ID); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
}
}
// @Tags Menu
// @Summary 分页获取基础menu列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenuList [post]
func GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, menuList, total := service.GetInfoList(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysOperationRecord
// @Summary 创建SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "创建SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/createSysOperationRecord [post]
func CreateSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
if err := service.CreateSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "SysOperationRecord模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
if err := service.DeleteSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
if err := service.DeleteSysOperationRecordByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("批量删除成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 用id查询SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "Id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysOperationRecord/findSysOperationRecord [get]
func FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindQuery(&sysOperationRecord)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(gin.H{"resysOperationRecord": resysOperationRecord}, "查询成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 分页获取SysOperationRecord列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/getSysOperationRecordList [get]
func GetSysOperationRecordList(c *gin.Context) {
var pageInfo request.SysOperationRecordSearch
_ = c.ShouldBindQuery(&pageInfo)
if err, list, total := service.GetSysOperationRecordInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags System
// @Summary 获取配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getSystemConfig [post]
func GetSystemConfig(c *gin.Context) {
if err, config := service.GetSystemConfig(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c)
}
}
// @Tags System
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /system/setSystemConfig [post]
func SetSystemConfig(c *gin.Context) {
var sys model.System
_ = c.ShouldBindJSON(&sys)
if err := service.SetSystemConfig(sys); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData("设置成功", c)
}
}
// @Tags System
// @Summary 重启系统
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
// @Router /system/reloadSystem [post]
func ReloadSystem(c *gin.Context) {
err := utils.Reload()
if err != nil {
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
response.FailWithMessage("重启系统失败", c)
} else {
response.OkWithMessage("重启系统成功", c)
}
}
// @Tags System
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
func GetServerInfo(c *gin.Context) {
if server, err := service.GetServerInfo(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
}
}
This diff is collapsed.
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"go.uber.org/zap"
"strconv"
"time"
)
func GetMobileUserList(c *gin.Context) {
var req request.GetMobileUserListReq
_ = c.ShouldBindJSON(&req)
req.IsManager = "0"
req.UserType = global.GVA_CONFIG.System.Usertype
if err, list, total := service.GetMobileUserList(req); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: req.Page,
PageSize: req.PageSize,
}, "获取成功", c)
}
}
func GetMobileUserInfo(c *gin.Context) {
var req request.GetMobileUserInfoReq
_ = c.ShouldBindJSON(&req)
if err, list := service.GetMobileUserInfo(req.Id); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(list, c)
}
}
func ExportMobileUser(c *gin.Context) {
var req request.GetMobileUserListReq
_ = c.ShouldBindQuery(&req)
req.Page = 1
req.PageSize = 9999
req.IsManager = "0"
req.UserType = global.GVA_CONFIG.System.Usertype
_, reply, _ := service.GetMobileUserList(req)
fileName := "谛医用户列表" + time.Now().Format("20060102")
f := excelize.NewFile()
// Create a new sheet.
index := f.NewSheet(fileName)
f.SetCellValue(fileName, "A1", "登录手机号")
f.SetCellValue(fileName, "B1", "注册时间")
f.SetCellValue(fileName, "C1", "姓名")
f.SetCellValue(fileName, "D1", "认证手机号")
f.SetCellValue(fileName, "E1", "工龄")
f.SetCellValue(fileName, "F1", "工作医院")
f.SetCellValue(fileName, "G1", "职位")
f.SetCellValue(fileName, "H1", "省")
f.SetCellValue(fileName, "I1", "市")
f.SetCellValue(fileName, "J1", "区")
f.SetCellValue(fileName, "K1", "详细地址")
f.SetCellValue(fileName, "L1", "最新开通vip时间")
f.SetCellValue(fileName, "M1", "vip到期时间")
f.SetCellValue(fileName, "N1", "vip开通方式")
for k, v := range reply {
level := ""
if v.VipLevel == "1" {
level = "体验版"
} else if v.VipLevel == "2" {
level = "赠送版"
} else if v.VipLevel == "3" {
level = "付费版"
}
a := strconv.Itoa(k + 2)
f.SetCellValue(fileName, "A"+a, v.Mobile)
f.SetCellValue(fileName, "B"+a, utils.String2Time(v.CreatedAt))
f.SetCellValue(fileName, "C"+a, v.Name)
f.SetCellValue(fileName, "D"+a, v.Phone)
f.SetCellValue(fileName, "E"+a, v.WorkingYears)
f.SetCellValue(fileName, "F"+a, v.WorkingPlace)
f.SetCellValue(fileName, "G"+a, v.Position)
f.SetCellValue(fileName, "H"+a, v.ProvinceName)
f.SetCellValue(fileName, "I"+a, v.CityName)
f.SetCellValue(fileName, "J"+a, v.CountyName)
f.SetCellValue(fileName, "K"+a, v.HospitalAddress)
f.SetCellValue(fileName, "L"+a, utils.String2Time(v.UpdateTime))
f.SetCellValue(fileName, "M"+a, utils.String2Time(v.MaturityTime))
f.SetCellValue(fileName, "N"+a, level)
}
// Set active sheet of the workbook.
f.SetActiveSheet(index)
// Save xlsx file by the given path.
if err := f.SaveAs("./" + fileName + ".csv"); err != nil {
fmt.Println(err)
return
}
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "./"+fileName+".csv")) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/octet-stream")
c.File("./" + fileName + ".csv")
return
}
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"go.uber.org/zap"
"strconv"
"time"
)
func GetVipOrderList(c *gin.Context) {
var req request.GetVipOrderListReq
_ = c.ShouldBindJSON(&req)
if req.OrderType == "1" {
req.VipLevel = "1,3"
}
if req.OrderType == "2" {
req.VipLevel = "2"
}
req.UserType = global.GVA_CONFIG.System.Usertype
err, list, total := service.GetVipOrderList(req)
for k, v := range list {
list[k].OrderType = v.VipLevel
if v.VipLevel == 3 {
list[k].OrderType = 1
}
}
reply := request.GetVipOrderListReply{}
reply.List = list
reply.Total = total
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(reply, "获取成功", c)
}
return
}
func SetMobileUserVip(c *gin.Context) {
var req request.OpenVipOwnReq
_ = c.ShouldBindJSON(&req)
//用户调用api日志
apiLog := model.ApiLog{
UserId: getUserID(c),
Status: 1,
Api: "/adminUser/setMobileUserVip",
Req: string(utils.SerializeJson(req)),
Reply: "",
}
service.CreateApiLog(apiLog)
userInfo := service.FindUserByMobile(req.Mobile)
if userInfo.ID == 0 {
response.FailWithMessage("用户未注册", c)
return
//user := model.SysUser{
// Mobile: req.Mobile,
//}
//_, userInfo = service.UserRegister(user)
}
userId := int(userInfo.ID)
var replyVipUser model.VipUser
var err error
if service.IsVipUser(userId) == 1 {
err, replyVipUser = service.GetVipUser(userId)
if err != nil {
fmt.Println(err)
return
}
}
//创建vip订单
reqVipOrder := model.VipOrder{}
reqVipOrder.OrderNo = utils.GetOrderNo("V", userId)
reqVipOrder.UserId = userId
reqVipOrder.VipLevel = 2
reqVipOrder.VipMoney = 0
reqVipOrder.VipDay = req.Day
reqVipOrder.VipConfId = 2
reqVipOrder.PayMoney = 0
reqVipOrder.Status = 2
reqVipOrder.IsPoints = 0
reqVipOrder.PointsNum = 0
reqVipOrder.Remark = req.Remark
err = service.CreateVipOrder(reqVipOrder)
if err != nil {
global.GVA_LOG.Error("支付失败!", zap.Any("err", err))
response.FailWithMessage("支付失败", c)
return
}
reqVipUser := model.VipUser{}
reqVipUser.UserId = userId
reqVipUser.VipLevel = 2
//增加时间
if replyVipUser.Id != 0 {
if time.Now().Before(replyVipUser.MaturityTime) {
reqVipUser.MaturityTime = replyVipUser.MaturityTime.AddDate(0, 0, req.Day)
} else {
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, req.Day)
}
if err := service.UpdateVipUser(reqVipUser, userId); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
return
}
} else {
reqVipUser.MaturityTime = time.Now().AddDate(0, 0, req.Day)
if err := service.CreateVipUser(reqVipUser); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
return
}
}
response.OkWithData(reqVipUser, c)
return
}
func ExportVipOrder(c *gin.Context) {
var req request.GetVipOrderListReq
_ = c.ShouldBindQuery(&req)
if req.OrderType == "1" {
req.VipLevel = "1,3"
}
if req.OrderType == "2" {
req.VipLevel = "2"
}
req.PageSize = 99999
req.UserType = global.GVA_CONFIG.System.Usertype
_, list, _ := service.GetVipOrderList(req)
fileName := "谛医会员订单列表" + time.Now().Format("20060102")
f := excelize.NewFile()
// Create a new sheet.
index := f.NewSheet(fileName)
f.SetCellValue(fileName, "A1", "登录手机号")
f.SetCellValue(fileName, "B1", "姓名")
f.SetCellValue(fileName, "C1", "下单时间")
f.SetCellValue(fileName, "D1", "开通天数")
f.SetCellValue(fileName, "E1", "订单金额")
f.SetCellValue(fileName, "F1", "支付金额")
f.SetCellValue(fileName, "G1", "订单类型")
f.SetCellValue(fileName, "H1", "备注")
for k, v := range list {
orderType := "正常订单"
if v.VipLevel == 2 {
orderType = "赠送订单"
}
a := strconv.Itoa(k + 2)
f.SetCellValue(fileName, "A"+a, v.Mobile)
f.SetCellValue(fileName, "B"+a, v.Name)
f.SetCellValue(fileName, "C"+a, v.CreateTime)
f.SetCellValue(fileName, "D"+a, v.VipDay)
f.SetCellValue(fileName, "E"+a, utils.FeeToString(v.VipMoney))
f.SetCellValue(fileName, "F"+a, utils.FeeToString(v.PayMoney))
f.SetCellValue(fileName, "G"+a, orderType)
f.SetCellValue(fileName, "H"+a, v.Remark)
}
// Set active sheet of the workbook.
f.SetActiveSheet(index)
// Save xlsx file by the given path.
if err := f.SaveAs("./" + fileName + ".csv"); err != nil {
fmt.Println(err)
return
}
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "./"+fileName+".csv")) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/octet-stream")
c.File("./" + fileName + ".csv")
return
}
package common
const (
// ErrorStatus 错误
ErrorStatus = -1
// SuccessStatus 成功
SuccessStatus = 0
// LoginTimeOut 登录超时
LoginTimeOut = -1001
// NoLogin 未登录
NoLogin = -1002
// NoOpen 为开通
NoOpen = -1102
// NoBinding
NoBinding = -1003
// NoCloudUser
NoCloudUser = -1005
)
package common
const (
// WXAppID wx app id
//WXAppID = "wx6ff40a576e2f4ca0"
WXAppID = "wxdaba08b26729c256"
// WxSecret wx app 秘钥
//WxSecret = "6756d3f0b6b052dab40beb78bc89291d"
WxSecret = "3e35921309974c2ca34267daa7cae6b3"
// SmsKey 发送短信 key
SmsKey = `1000000001`
// SMSSecret 发送短信秘钥
SMSSecret = `dbc_saas_pc`
// SendSmsURL 发送短信 url
SendSmsURL = `http://saas.pet-dbc.cn:8003/gateway/hospital/wx/send_code`
// CheckSmsURL 校验短信 url
CheckSmsURL = `http://saas.pet-dbc.cn:8003/gateway/hospital/wx/check_code`
)
// code 表名 table name
// code 标识名 Identification
const (
// PetTable 宠物
PetTable string = "his_pet"
// PetTag tag
PetTag string = "P"
// EmployeeTable 员工
EmployeeTable string = "con_employee"
// EmployeeTag tag
EmployeeTag string = "NO"
// OutChargeTable 支出
OutChargeTable string = "c_outcharge"
// OutChargeTag tag
OutChargeTag string = "ZC"
)
var CardType = map[int]string{
1: "发卡",
2: "变更",
3: "充值",
4: "赠额充值",
5: "消费",
6: "赠额消费",
7: "退款",
8: "赠额退款",
9: "取消结算",
10: "赠额取消结算",
11: "取消退款",
12: "赠额取消退款",
13: "退卡",
}
package common
import (
"database/sql"
"errors"
"fmt"
"strings"
"sync"
"time"
)
var (
// DbMap 存放数据库连接的map
DbMap *SafeMap
)
// SafeMap 并发安全
type SafeMap struct {
Db map[string]*sql.DB
mu sync.RWMutex
}
// NewSafeMap 创建并发安全的map
func NewSafeMap() *SafeMap {
if DbMap == nil {
DbMap = &SafeMap{
Db: make(map[string]*sql.DB, 0),
}
}
return DbMap
}
// GetOrStore 获取value 如果没有则放入map中 再进行获取
func (s *SafeMap) GetOrStore(key string) (*sql.DB, error) {
s.mu.Lock()
defer s.mu.Unlock()
db, ok := s.Db[key]
if ok {
// err := db.Ping()
if err != nil {
return nil, err
}
return db, nil
}
db, err = newDBConn(key)
if err != nil {
return nil, err
}
// db.SetConnMaxLifetime()
s.Db[key] = db
return db, nil
}
// Store 往map中放入数据
func (s *SafeMap) Store(key string) error {
s.mu.Lock()
defer s.mu.Unlock()
db, err := newDBConn(key)
if err != nil {
return err
}
s.Db[key] = db
return nil
}
func newDBConn(s string) (*sql.DB, error) {
chainCode := strings.ToLower(s)
if chainCode == "" {
return nil, err
}
// if len(chainCode[:1]) != 1 {
// return nil, err
// }
// word := chainCode[:1]
// i ~ z
// if word > "h" {
// db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2ze095l91j14r251wno.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
// chainCode))
// if err != nil {
// return nil, err
// }
// db.SetConnMaxLifetime(10 * time.Minute)
// err = db.Ping()
// return db, err
// }
// db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2ze8jnj44l6ta299pro.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
// chainCode))
// if err != nil {
// return nil, err
// }
// db.SetConnMaxLifetime(10 * time.Minute)
// err = db.Ping()
// return db, err
if strings.ToLower(chainCode)[0] >= '0' && strings.ToLower(chainCode)[0] <= '8' {
db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2zej0q2rx321k0h1pbo.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
chainCode))
if err != nil {
return nil, err
}
db.SetConnMaxLifetime(10 * time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return db, err
} else if strings.ToLower(chainCode)[0] >= '9' && strings.ToLower(chainCode)[0] <= 'h' {
db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2ze4xxt6w2959o0ftyo.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
chainCode))
if err != nil {
return nil, err
}
db.SetConnMaxLifetime(10 * time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return db, err
} else if strings.ToLower(chainCode)[0] >= 'i' && strings.ToLower(chainCode)[0] <= 'q' {
db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2ze095l91j14r251wno.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
chainCode))
if err != nil {
return nil, err
}
db.SetConnMaxLifetime(10 * time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return db, err
} else if strings.ToLower(chainCode)[0] >= 'r' && strings.ToLower(chainCode)[0] <= 'z' {
db, err := sql.Open("mysql", fmt.Sprintf(`root_dbc:dbc_root888888@tcp(rm-2zeg6r1nvfk968lixyo.mysql.rds.aliyuncs.com:3306)/dbc_%s?charset=utf8`,
chainCode))
if err != nil {
return nil, err
}
db.SetConnMaxLifetime(10 * time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return db, err
} else {
return nil, errors.New("find error chain code")
}
}
package common
import (
"errors"
"gin-vue-admin/model/request"
"github.com/gin-gonic/gin"
)
func GetUserPhone(c *gin.Context) (string, error) {
if claims, exists := c.Get("claims"); exists {
//global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件!")
waitUse := claims.(*request.CustomClaims)
if len(waitUse.Mobile) != 11 {
return "", errors.New("账号错误")
}
return waitUse.Mobile, nil
}
return "", errors.New("参数错误")
}
package common
import (
"database/sql"
"gin-vue-admin/global"
// import mysql
_ "github.com/go-sql-driver/mysql"
)
var (
db *sql.DB
commonDB *sql.DB
err error
)
// NewAccountConn is 连接医院用户库
func NewAccountConn() (*sql.DB, error) {
if db == nil {
db, err = sql.Open("mysql", global.GVA_CONFIG.DoctorDb.Account)
return db, err
}
return db, nil
}
// NewCommonConn is 连接公共用户库
func NewCommonConn() (*sql.DB, error) {
if commonDB == nil {
commonDB, err = sql.Open("mysql", global.GVA_CONFIG.DoctorDb.Common)
return commonDB, err
}
return commonDB, nil
}
// GetResultRow is 获取返回值, 获取一条
func GetResultRow(rows *sql.Rows) map[string]string {
columns, _ := rows.Columns()
scanArgs := make([]interface{}, len(columns))
values := make([][]byte, len(columns))
for j := range values {
scanArgs[j] = &values[j]
}
record := make(map[string]string)
for rows.Next() {
rows.Scan(scanArgs...)
for i, v := range values {
if v != nil {
record[columns[i]] = string(v)
}
}
}
return record
}
// GetResultRows is 获取所有
func GetResultRows(rows *sql.Rows) map[int]map[string]string {
columns, _ := rows.Columns()
values := make([][]byte, len(columns))
scans := make([]interface{}, len(columns))
for k, _ := range values {
scans[k] = &values[k]
}
i := 0
result := make(map[int]map[string]string)
for rows.Next() {
rows.Scan(scans...)
row := make(map[string]string)
for k, v := range values {
key := columns[k]
row[key] = string(v)
}
result[i] = row
i++
}
return result
}
// CloseTx is 有错误则关闭事务、没错则提交事务
func CloseTx(tx *sql.Tx, err error) {
if err != nil {
tx.Rollback()
}
tx.Commit()
}
package common
import (
"errors"
"reflect"
"strconv"
"time"
)
// DataToStructByTag is 根据结构体中sql标签映射数据到结构体中并且转换类型
func DataToStructByTag(data map[string]string, obj interface{}) {
objValue := reflect.ValueOf(obj).Elem()
for i := 0; i < objValue.NumField(); i++ {
//获取sql对应的值
value := data[objValue.Type().Field(i).Tag.Get("sql")]
//获取对应字段的名称
name := objValue.Type().Field(i).Name
//获取对应字段类型
structFieldType := objValue.Field(i).Type()
//获取变量类型,也可以直接写"string类型"
val := reflect.ValueOf(value)
var err error
if structFieldType != val.Type() {
//类型转换
val, err = TypeConversion(value, structFieldType.Name()) //类型转换
if err != nil {
}
}
//设置类型值
objValue.FieldByName(name).Set(val)
}
}
// TypeConversion 类型转换
func TypeConversion(value string, ntype string) (reflect.Value, error) {
if ntype == "string" {
return reflect.ValueOf(value), nil
} else if ntype == "time.Time" {
t, err := time.ParseInLocation("2006-01-02 15:04:05", value, time.Local)
return reflect.ValueOf(t), err
} else if ntype == "Time" {
t, err := time.ParseInLocation("2006-01-02 15:04:05", value, time.Local)
return reflect.ValueOf(t), err
} else if ntype == "int" {
i, err := strconv.Atoi(value)
return reflect.ValueOf(i), err
} else if ntype == "int8" {
i, err := strconv.ParseInt(value, 10, 64)
return reflect.ValueOf(int8(i)), err
} else if ntype == "int32" {
i, err := strconv.ParseInt(value, 10, 64)
return reflect.ValueOf(int64(i)), err
} else if ntype == "int64" {
i, err := strconv.ParseInt(value, 10, 64)
return reflect.ValueOf(i), err
} else if ntype == "float32" {
i, err := strconv.ParseFloat(value, 64)
return reflect.ValueOf(float32(i)), err
} else if ntype == "float64" {
i, err := strconv.ParseFloat(value, 64)
return reflect.ValueOf(i), err
}
//else if .......增加其他一些类型的转换
return reflect.ValueOf(value), errors.New("未知的类型:" + ntype)
}
# Gin-Vue-Admin Global Configuration
# jwt configuration
jwt:
signing-key: 'qmPlus'
expires-time: 604800
buffer-time: 86400
# zap logger configuration
zap:
level: 'info'
format: 'console'
prefix: '[GIN-VUE-ADMIN]'
director: 'log'
link-name: 'latest_log'
show-line: true
encode-level: 'LowercaseColorLevelEncoder'
stacktrace-key: 'stacktrace'
log-in-console: true
# redis configuration
redis:
db: 0
addr: '177.7.0.14:6379'
password: ''
# email configuration
email:
to: 'xxx@qq.com'
port: 465
from: 'xxx@163.com'
host: 'smtp.163.com'
is-ssl: true
secret: 'xxx'
nickname: 'test'
# casbin configuration
casbin:
model-path: './resource/rbac_model.conf'
# system configuration
system:
env: 'public' # Change to "develop" to skip authentication for development mode
addr: 8888
db-type: 'mysql'
oss-type: 'local' # 控制oss选择走本期还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置
use-multipoint: false
# captcha configuration
captcha:
key-long: 6
img-width: 240
img-height: 80
# mysql connect configuration
mysql:
path: ''
config: ''
db-name: ''
username: ''
password: ''
max-idle-conns: 10
max-open-conns: 100
log-mode: false
log-zap: ""
# local configuration
local:
path: 'uploads/file'
# autocode configuration
autocode:
transfer-restart: true
root: ""
server: /server
server-api: /api/v1
server-initialize: /initialize
server-model: /model
server-request: /model/request/
server-router: /router
server-service: /service
web: /web/src
web-api: /api
web-flow: /view
web-form: /view
web-table: /view
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket 和 域名地址)
qiniu:
zone: 'ZoneHuaDong'
bucket: ''
img-path: ''
use-https: false
access-key: ''
secret-key: ''
use-cdn-domains: false
# aliyun oss configuration
aliyun-oss:
endpoint: 'yourEndpoint'
access-key-id: 'yourAccessKeyId'
access-key-secret: 'yourAccessKeySecret'
bucket-name: 'yourBucketName'
bucket-url: 'yourBucketUrl'
# tencent cos configuration
tencent-cos:
bucket: 'xxxxx-10005608'
region: 'ap-shanghai'
secret-id: 'xxxxxxxx'
secret-key: 'xxxxxxxx'
base-url: 'https://gin.vue.admin'
path-prefix: 'gin-vue-admin'
# excel configuration
excel:
dir: './resource/excel/'
# timer task db clear table
Timer:
start: true
spec: "@daily" # 定时任务详细配置参考 https://pkg.go.dev/github.com/robfig/cron/v3
detail: [
# tableName: 需要清理的表名
# compareField: 需要比较时间的字段
# interval: 时间间隔, 具体配置详看 time.ParseDuration() 中字符串表示 且不能为负数
# 2160h = 24 * 30 * 3 -> 三个月
{ tableName: "sys_operation_records" , compareField: "created_at", interval: "2160h" },
#{ tableName: "log2" , compareField: "created_at", interval: "2160h" }
]
This diff is collapsed.
package config
type Ai struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 存储区域
Hostnew string `mapstructure:"hostnew" json:"hostnew" yaml:"hostnew"` // 存储区域
Hostfrac string `mapstructure:"hostfrac" json:"hostfrac" yaml:"hostfrac"` // 存储区域
Token string `mapstructure:"token" json:"token" yaml:"token"` // 存储区域
}
package config
type Autocode struct {
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"`
Root string `mapstructure:"root" json:"root" yaml:"root"`
Server string `mapstructure:"server" json:"server" yaml:"server"`
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
Web string `mapstructure:"web" json:"web" yaml:"web"`
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
}
package config
type Bkwx struct {
Appid string `mapstructure:"appid" json:"appid" yaml:"appid"` // 级别
Appsecret string `mapstructure:"appsecret" json:"appsecret" yaml:"appsecret"` // 输出
Apikey string `mapstructure:"apikey" json:"apikey" yaml:"apikey"` // 日志前缀
Mchid string `mapstructure:"mchid" json:"mchid" yaml:"mchid"` // 日志文件夹
}
package config
type Captcha struct {
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"` // 验证码长度
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"` // 验证码宽度
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"` // 验证码高度
}
package config
type Casbin struct {
ModelPath string `mapstructure:"model-path" json:"modelPath" yaml:"model-path"` // 存放casbin模型的相对路径
}
package config
type Clickhouse struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址:端口
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"` // 高级配置
Database string `mapstructure:"database" json:"database" yaml:"database"` // 数据库名
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
Password string `mapstructure:"password" json:"password" yaml:"password"`
}
package config
type Common struct {
Type string `mapstructure:"type" json:"type" yaml:"type"` // 存储区域
}
This diff is collapsed.
package config
type Dbys struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 存储区域
}
package config
type Dcyp struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 存储区域
}
package config
type DoctorPay struct {
Url string `mapstructure:"url" json:"url" yaml:"url"`
}
type LisOcr struct {
Url string `mapstructure:"url" json:"url" yaml:"url"`
}
type DoctorDb struct {
Account string `mapstructure:"account" json:"account" yaml:"account"`
Common string `mapstructure:"common" json:"common" yaml:"common"`
}
This diff is collapsed.
package config
type Encrypt struct {
Key string `mapstructure:"key" json:"key" yaml:"key"` // 存储区域
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment