1
This commit is contained in:
parent
6438942e18
commit
cb7807801e
@ -47,6 +47,28 @@ func (r *UserCaCert) GetUserCloudCert(c *gin.Context) {
|
|||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHospitalCloudCert 申请云证书-医院
|
||||||
|
func (r *UserCaCert) GetHospitalCloudCert(c *gin.Context) {
|
||||||
|
// 业务处理
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
userCaCertService := service.UserCaCertService{}
|
||||||
|
_, err := userCaCertService.GetHospitalCloudCert(tx)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
// RenewUserCloudCert 更新云证书-个人-续约
|
// RenewUserCloudCert 更新云证书-个人-续约
|
||||||
func (r *UserCaCert) RenewUserCloudCert(c *gin.Context) {
|
func (r *UserCaCert) RenewUserCloudCert(c *gin.Context) {
|
||||||
id := c.Param("user_id")
|
id := c.Param("user_id")
|
||||||
@ -82,6 +104,28 @@ func (r *UserCaCert) RenewUserCloudCert(c *gin.Context) {
|
|||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenewHospitalCloudCert 更新云证书-医院-续约
|
||||||
|
func (r *UserCaCert) RenewHospitalCloudCert(c *gin.Context) {
|
||||||
|
// 业务处理
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
userCaCertService := service.UserCaCertService{}
|
||||||
|
_, err := userCaCertService.RenewHospitalCloudCert(tx)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveUserCloudCert 注销云证书-个人
|
// RemoveUserCloudCert 注销云证书-个人
|
||||||
func (r *UserCaCert) RemoveUserCloudCert(c *gin.Context) {
|
func (r *UserCaCert) RemoveUserCloudCert(c *gin.Context) {
|
||||||
id := c.Param("user_id")
|
id := c.Param("user_id")
|
||||||
|
|||||||
@ -560,14 +560,11 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 医院
|
// 医院
|
||||||
hospitalGroup := certGroup.Group("/hospital")
|
hospitalGroup := certGroup.Group("/hospital")
|
||||||
{
|
{
|
||||||
// 更新云证书-个人
|
// 更新云证书-医院-续约
|
||||||
hospitalGroup.GET("/renew/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
hospitalGroup.GET("/renew", api.UserCaCert.RenewHospitalCloudCert)
|
||||||
|
|
||||||
// 注销云证书-个人
|
// 申请云证书-医院
|
||||||
hospitalGroup.PUT("/remove/:user_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
hospitalGroup.POST("", api.UserCaCert.GetHospitalCloudCert)
|
||||||
|
|
||||||
// 申请云证书-个人
|
|
||||||
hospitalGroup.GET("/:user_id", api.UserCaCert.GetUserCloudCert)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -135,6 +135,65 @@ func (r *UserCaCertService) GetUserCloudCert(tx *gorm.DB, userId int64) (bool, e
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHospitalCloudCert 申请云证书-医院
|
||||||
|
func (r *UserCaCertService) GetHospitalCloudCert(tx *gorm.DB) (bool, error) {
|
||||||
|
var userId int64 = 5345345461
|
||||||
|
userCaCertDao := dao.UserCaCert{}
|
||||||
|
|
||||||
|
// 检测是否存在云证书
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
maps["ca_pin"] = userId
|
||||||
|
maps["type"] = 2
|
||||||
|
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||||
|
if userCaCert != nil {
|
||||||
|
return false, errors.New("医院存在正常使用的云证书,请注销后重新申请")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 申请云证书
|
||||||
|
cloudCertRequestData := &ca.AddCloudCertRequest{
|
||||||
|
EntityId: fmt.Sprintf("%d", userId),
|
||||||
|
EntityType: "Organizational",
|
||||||
|
PersonalPhone: "18221234167",
|
||||||
|
OrgName: "成都金牛欣欣相照互联网医院有限公司",
|
||||||
|
OrgNumber: "91510106MABTJY4K9R",
|
||||||
|
Pin: fmt.Sprintf("%d", userId),
|
||||||
|
Province: "四川省",
|
||||||
|
Locality: "成都市",
|
||||||
|
AuthType: "实人认证",
|
||||||
|
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||||
|
AuthResult: "认证通过",
|
||||||
|
AuthNoticeType: "数字证书申请告知",
|
||||||
|
}
|
||||||
|
|
||||||
|
cloudCertResponse, err := ca.AddCloudCert(cloudCertRequestData)
|
||||||
|
if err != nil || cloudCertResponse == nil {
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增ca监管证书表
|
||||||
|
userCaCert = &model.UserCaCert{
|
||||||
|
UserId: &userId,
|
||||||
|
IsSystem: 1,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// EditUserCloudCert 修改云证书-个人
|
// EditUserCloudCert 修改云证书-个人
|
||||||
func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
userCaCertDao := dao.UserCaCert{}
|
userCaCertDao := dao.UserCaCert{}
|
||||||
@ -259,7 +318,7 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenewUserCloudCert 更新云证书-个人
|
// RenewUserCloudCert 更新云证书-个人-续约
|
||||||
func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
userCaCertDao := dao.UserCaCert{}
|
userCaCertDao := dao.UserCaCert{}
|
||||||
|
|
||||||
@ -344,6 +403,61 @@ func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenewHospitalCloudCert 更新云证书-医院-续约
|
||||||
|
func (r *UserCaCertService) RenewHospitalCloudCert(tx *gorm.DB) (bool, error) {
|
||||||
|
var userId int64 = 5345345461
|
||||||
|
|
||||||
|
userCaCertDao := dao.UserCaCert{}
|
||||||
|
|
||||||
|
// 检测是否存在云证书
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
maps["ca_pin"] = 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天,无法更新")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改云证书
|
||||||
|
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 {
|
||||||
|
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 {
|
||||||
|
return false, errors.New("更新失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveUserCloudCert 注销云证书-个人
|
// RemoveUserCloudCert 注销云证书-个人
|
||||||
func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
userCaCertDao := dao.UserCaCert{}
|
userCaCertDao := dao.UserCaCert{}
|
||||||
|
|||||||
@ -1434,8 +1434,8 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 云证书处理
|
// 云证书处理-此处去掉了环境判断
|
||||||
if req.MultiPointStatus == 1 && config.C.Env == "prod" {
|
if req.MultiPointStatus == 1 {
|
||||||
userCaCertService := UserCaCertService{}
|
userCaCertService := UserCaCertService{}
|
||||||
|
|
||||||
// 检测是否存在云证书
|
// 检测是否存在云证书
|
||||||
@ -1444,7 +1444,6 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo
|
|||||||
maps := make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
maps["user_id"] = userDoctor.UserId
|
maps["user_id"] = userDoctor.UserId
|
||||||
maps["type"] = 2
|
maps["type"] = 2
|
||||||
maps["is_latest"] = 1
|
|
||||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||||
if userCaCert == nil {
|
if userCaCert == nil {
|
||||||
// 申请云证书
|
// 申请云证书
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user