新增云证书操作
This commit is contained in:
@@ -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