152 lines
3.0 KiB
Go
152 lines
3.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"hospital-admin-api/api/responses"
|
|
"hospital-admin-api/api/service"
|
|
"hospital-admin-api/global"
|
|
"strconv"
|
|
)
|
|
|
|
type UserCaCert struct{}
|
|
|
|
// GetUserCloudCert 申请云证书-个人
|
|
func (r *UserCaCert) GetUserCloudCert(c *gin.Context) {
|
|
id := c.Param("user_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
userId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
userCaCertService := service.UserCaCertService{}
|
|
_, err = userCaCertService.GetUserCloudCert(tx, userId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// RenewUserCloudCert 更新云证书-个人-续约
|
|
func (r *UserCaCert) RenewUserCloudCert(c *gin.Context) {
|
|
id := c.Param("user_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
userId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
userCaCertService := service.UserCaCertService{}
|
|
_, err = userCaCertService.RenewUserCloudCert(tx, userId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// RemoveUserCloudCert 注销云证书-个人
|
|
func (r *UserCaCert) RemoveUserCloudCert(c *gin.Context) {
|
|
id := c.Param("user_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
userId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
userCaCertService := service.UserCaCertService{}
|
|
_, err = userCaCertService.RemoveUserCloudCert(tx, userId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// AddUserSignConfig 添加用户签章配置
|
|
// func (r *UserCaCert) AddUserSignConfig(c *gin.Context) {
|
|
// userCaCertRequest := requests.UserCaCertRequest{}
|
|
// req := userCaCertRequest.AddUserSignConfig
|
|
// if err := c.ShouldBind(&req); err != nil {
|
|
// responses.FailWithMessage(err.Error(), c)
|
|
// return
|
|
// }
|
|
//
|
|
// // 参数验证
|
|
// if err := global.Validate.Struct(req); err != nil {
|
|
// responses.FailWithMessage(utils.Translate(err), c)
|
|
// return
|
|
// }
|
|
//
|
|
// // 业务处理
|
|
// tx := global.Db.Begin()
|
|
// defer func() {
|
|
// if r := recover(); r != nil {
|
|
// tx.Rollback()
|
|
// }
|
|
// }()
|
|
//
|
|
// userCaCertService := service.UserCaCertService{}
|
|
// _, err := userCaCertService.AddUserSignConfig(tx, req)
|
|
// if err != nil {
|
|
// tx.Rollback()
|
|
// responses.FailWithMessage(err.Error(), c)
|
|
// return
|
|
// }
|
|
//
|
|
// tx.Commit()
|
|
// responses.Ok(c)
|
|
// }
|