新增云证书操作
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/global"
|
||||
"strconv"
|
||||
)
|
||||
@@ -34,16 +33,119 @@ func (r *UserCaCert) GetUserCloudCert(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
|
||||
if config.C.Env == "prod" {
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err = userCaCertService.GetUserCloudCert(tx, userId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
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)
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package requests
|
||||
|
||||
type UserCaCertRequest struct {
|
||||
AddUserSignConfig // 添加用户签章配置
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
type AddUserSignConfig struct {
|
||||
Type int `json:"type" form:"type" validate:"required,oneof=1 2 3" label:"类型"` // 1:医院 2:医生 3:药师
|
||||
UserId string `json:"user_id" form:"user_id" label:"ID"` // 用户id,当type=2,3时需要
|
||||
}
|
||||
@@ -547,14 +547,14 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 用户
|
||||
userGroup := certGroup.Group("/user")
|
||||
{
|
||||
// 更新云证书-个人
|
||||
userGroup.GET("/renew/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
// 更新云证书-个人-续约
|
||||
userGroup.PUT("/renew/:user_id", api.UserCaCert.RenewUserCloudCert)
|
||||
|
||||
// 注销云证书-个人
|
||||
userGroup.PUT("/remove/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
userGroup.PUT("/remove/:user_id", api.UserCaCert.RemoveUserCloudCert)
|
||||
|
||||
// 申请云证书-个人
|
||||
userGroup.GET("/:user_id", api.UserCaCert.GetUserCloudCert)
|
||||
userGroup.POST("/:user_id", api.UserCaCert.GetUserCloudCert)
|
||||
}
|
||||
|
||||
// 医院
|
||||
@@ -574,10 +574,10 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 签章
|
||||
signGroup := caGroup.Group("/sign")
|
||||
{
|
||||
// 申请
|
||||
signGroup.GET("/renew/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
// 添加签章配置
|
||||
// signGroup.POST("", api.UserCaCert.AddUserSignConfig)
|
||||
|
||||
// 更新
|
||||
// 更新签章配置
|
||||
signGroup.GET("/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
@@ -77,7 +76,6 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
|
||||
// 计算三天后的时间与当前时间的时间差
|
||||
timeDifference := threeDaysLater.Sub(time.Now())
|
||||
fmt.Println(timeDifference)
|
||||
|
||||
if timeDifference < 0 {
|
||||
return false, errors.New("订单已完成,无法取消")
|
||||
|
||||
@@ -255,3 +255,309 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// RenewUserCloudCert 更新云证书-个人
|
||||
func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
return false, errors.New("医生未申请云证书,无法操作")
|
||||
}
|
||||
|
||||
if userCaCert.IsLatest == 0 {
|
||||
return false, errors.New("医生云证书非最新,请执行更新")
|
||||
}
|
||||
|
||||
if !userCaCert.CertExpireTime.IsEmpty() {
|
||||
timeDifference := time.Time(userCaCert.CertExpireTime).Sub(time.Now())
|
||||
|
||||
if timeDifference > 60*24*time.Hour {
|
||||
return false, errors.New("云证书有效期大于60天,无法更新")
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 医生
|
||||
if user.UserType == 2 {
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
if err != nil || userDoctorInfo == nil {
|
||||
return false, errors.New("医生详情数据错误")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先通过身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.MultiPointStatus != 1 {
|
||||
return false, errors.New("请先完成多点执业认证")
|
||||
}
|
||||
}
|
||||
|
||||
// 修改云证书
|
||||
cloudCertRequestData := &ca.RenewCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书更新告知",
|
||||
}
|
||||
|
||||
cloudCertResponse, err := ca.RenewCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表
|
||||
data := make(map[string]interface{})
|
||||
data["cert_base64"] = cloudCertResponse.CertBase64
|
||||
data["cert_chain_p7"] = cloudCertResponse.CertP7
|
||||
data["cert_serial_number"] = cloudCertResponse.CertSerialnumber
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("审核失败")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// RemoveUserCloudCert 注销云证书-个人
|
||||
func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
return false, errors.New("用户未申请云证书,无法操作")
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 医生
|
||||
if user.UserType == 2 {
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
if err != nil || userDoctorInfo == nil {
|
||||
return false, errors.New("医生详情数据错误")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先通过身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.MultiPointStatus != 1 {
|
||||
return false, errors.New("请先完成多点执业认证")
|
||||
}
|
||||
}
|
||||
|
||||
// 注销云证书
|
||||
cloudCertRequestData := &ca.RemoveCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书吊销告知",
|
||||
}
|
||||
|
||||
_, err = ca.RemoveCloudCert(cloudCertRequestData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表-注销
|
||||
err = userCaCertDao.DeleteUserCaCertById(tx, userCaCert.CertId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("注销失败")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddUserSignConfig 添加用户签章配置
|
||||
// func (r *UserCaCertService) AddUserSignConfig(tx *gorm.DB, req requests.AddUserSignConfig) (bool, error) {
|
||||
// userCaCertDao := dao.UserCaCert{}
|
||||
//
|
||||
// var entityId string // 唯一标识
|
||||
// var cardNum string // 身份证号/信用代码
|
||||
//
|
||||
// // 医院-固定
|
||||
// if req.Type == 1 {
|
||||
// entityId = "5345345461"
|
||||
// cardNum = "91510106MABTJY4K9R"
|
||||
// }
|
||||
//
|
||||
// // 医生
|
||||
// if req.Type == 2 {
|
||||
// if req.UserId == "" {
|
||||
// return false, errors.New("缺少用户标识")
|
||||
// }
|
||||
//
|
||||
// entityId = req.UserId
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
// if err != nil {
|
||||
// return false, errors.New("用户标识错误")
|
||||
// }
|
||||
//
|
||||
// // 获取医生数据
|
||||
// userDoctorDao := dao.UserDoctorDao{}
|
||||
// userDoctor, err := userDoctorDao.GetUserDoctorByUserId(userId)
|
||||
// if err != nil || userDoctor == nil {
|
||||
// return false, errors.New("医生数据错误")
|
||||
// }
|
||||
//
|
||||
// // 获取医生详情数据
|
||||
// userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
// userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
// if err != nil || userDoctorInfo == nil {
|
||||
// return false, errors.New("医生详情数据错误")
|
||||
// }
|
||||
//
|
||||
// if userDoctor.IdenAuthStatus != 1 {
|
||||
// return false, errors.New("请先通过身份认证")
|
||||
// }
|
||||
//
|
||||
// if userDoctor.MultiPointStatus != 1 {
|
||||
// return false, errors.New("请先完成多点执业认证")
|
||||
// }
|
||||
//
|
||||
// cardNum = userDoctorInfo.CardNum
|
||||
// }
|
||||
//
|
||||
// // 药师
|
||||
// if req.Type == 3 {
|
||||
// if req.UserId == "" {
|
||||
// return false, errors.New("缺少用户标识")
|
||||
// }
|
||||
//
|
||||
// entityId = req.UserId
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
// if err != nil {
|
||||
// return false, errors.New("用户标识错误")
|
||||
// }
|
||||
//
|
||||
// // 获取药师详情数据
|
||||
// userPharmacistInfoDao := dao.UserPharmacistInfoDao{}
|
||||
// userPharmacistInfo, err := userPharmacistInfoDao.GetUserPharmacistInfoByUserId(userId)
|
||||
// if err != nil || userPharmacistInfo == nil {
|
||||
// return false, errors.New("药师详情数据错误")
|
||||
// }
|
||||
//
|
||||
// cardNum = userPharmacistInfo.CardNum
|
||||
// }
|
||||
//
|
||||
// // 检测是否存在云证书
|
||||
// maps := make(map[string]interface{})
|
||||
// maps["ca_pin"] = entityId
|
||||
// maps["type"] = 2
|
||||
// userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
// if userCaCert == nil {
|
||||
// return false, errors.New("医生未申请云证书,请申请后添加签章配置")
|
||||
// }
|
||||
//
|
||||
// // 处理签章图片
|
||||
// var signImage string // 签章图片,base64格式
|
||||
//
|
||||
// // 处理签章配置
|
||||
// var signParam string // 签章配置,JSON
|
||||
// fmt.Println(signParam)
|
||||
// var signParams []map[string]interface{}
|
||||
// if req.Type == 1 {
|
||||
// // 医院
|
||||
// signParam := map[string]interface{}{
|
||||
// "llx": "370",
|
||||
// "lly": "210",
|
||||
// "urx": "520",
|
||||
// "ury": "360",
|
||||
// "pageList": []int{1},
|
||||
// "sealImg": signImage, // 请替换为你的签名图像路径
|
||||
// }
|
||||
// signParams = append(signParams, signParam)
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // 申请云证书
|
||||
// cloudCertRequestData := &ca.AddUserSignConfigRequest{
|
||||
// UserId: entityId,
|
||||
// ConfigKey: entityId,
|
||||
// KeypairType: "3",
|
||||
// CertSn: cardNum,
|
||||
// SignType: "4",
|
||||
// SignParam: "",
|
||||
// SealImg: "",
|
||||
// SealType: "4",
|
||||
// SignTemplate: "0",
|
||||
// }
|
||||
//
|
||||
// cloudCertResponse, err := ca.AddCloudCert(cloudCertRequestData)
|
||||
// if err != nil || cloudCertResponse == nil {
|
||||
// return false, errors.New(err.Error())
|
||||
// }
|
||||
//
|
||||
// // 新增ca监管证书表
|
||||
// userCaCert = &model.UserCaCert{
|
||||
// UserId: &userId,
|
||||
// IsSystem: 0,
|
||||
// IsLatest: 1,
|
||||
// Type: 2,
|
||||
// CertBase64: cloudCertResponse.CertBase64,
|
||||
// CertChainP7: cloudCertResponse.CertP7,
|
||||
// CertSerialNumber: cloudCertResponse.CertSerialnumber,
|
||||
// CaPin: fmt.Sprintf("%d", userId),
|
||||
// IsSignConfig: 0,
|
||||
// SignConfig: "",
|
||||
// CertApplicationTime: model.LocalTime(time.Now()),
|
||||
// CertExpireTime: model.LocalTime(time.Now().AddDate(0, 0, 180)), // 180天以后的时间
|
||||
// }
|
||||
//
|
||||
// userCaCert, err = userCaCertDao.AddUserCaCert(tx, userCaCert)
|
||||
// if err != nil || userCaCert == nil {
|
||||
// return false, errors.New(err.Error())
|
||||
// }
|
||||
//
|
||||
// return true, nil
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user