新增 补充所有用户云证书数据-纯接口,无调用
This commit is contained in:
parent
6e71602f57
commit
fed122e8df
@ -220,3 +220,16 @@ func (r *UserCaCert) GetHospitalCloudCert(c *gin.Context) {
|
||||
|
||||
responses.OkWithData(userCaCert, c)
|
||||
}
|
||||
|
||||
// UserCloudCert 补充所有用户云证书数据-纯接口,无调用
|
||||
func (r *UserCaCert) UserCloudCert(c *gin.Context) {
|
||||
// 业务处理
|
||||
userCaCertService := service.UserCaCertService{}
|
||||
_, err := userCaCertService.UserCloudCert()
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@ -568,6 +568,9 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
// 申请云证书-个人
|
||||
userGroup.POST("/:user_id", api.UserCaCert.AddUserCloudCert)
|
||||
|
||||
// 补充所有用户云证书数据-纯接口,无调用
|
||||
userGroup.POST("", api.UserCaCert.UserCloudCert)
|
||||
}
|
||||
|
||||
// 医院
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/extend/aliyun"
|
||||
"hospital-admin-api/extend/ca"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -671,3 +673,136 @@ func (r *UserCaCertService) GetHospitalCloudCert() (g *dto.UserCaCertDto, err er
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// UserCloudCert 补充所有用户云证书数据-纯接口,无调用
|
||||
func (r *UserCaCertService) UserCloudCert() (bool, error) {
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 获取所有用户
|
||||
userDao := dao.UserDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_type"] = 2
|
||||
maps["user_status"] = 1
|
||||
users, err := userDao.GetUserList(maps)
|
||||
if len(users) == 0 || err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("无用户数据")
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
userCaCertDao := dao.UserCaCertDao{}
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorByUserId(user.UserId)
|
||||
if err != nil || userDoctor == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", userDoctor.UserName+"医生数据错误")
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断医生状态
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
utils.LogJsonInfo("UserCaCertService-UserCloudCert", userDoctor.UserName+"医生未完成身份认证,无需申请")
|
||||
continue
|
||||
}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = user.UserId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert != nil {
|
||||
utils.LogJsonInfo("UserCaCertService-UserCloudCert", userDoctor.UserName+"医生已申请云证书")
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(userDoctor.DoctorId)
|
||||
if err != nil || userDoctorInfo == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", userDoctor.UserName+"医生详情数据错误")
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取自定义科室数据
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(userDoctor.DepartmentCustomId)
|
||||
if err != nil || hospitalDepartmentCustom == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", userDoctor.UserName+"自定义科室数据错误")
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取标准科室数据
|
||||
hospitalDepartmentDao := dao.HospitalDepartment{}
|
||||
hospitalDepartment, err := hospitalDepartmentDao.GetHospitalDepartmentById(hospitalDepartmentCustom.DepartmentId)
|
||||
if err != nil || hospitalDepartment == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", userDoctor.UserName+"标准科室数据错误")
|
||||
continue
|
||||
}
|
||||
|
||||
// 申请云证书
|
||||
cloudCertRequestData := &ca.AddCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", user.UserId),
|
||||
EntityType: "Personal",
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: userDoctorInfo.CardName,
|
||||
PersonalIdNumber: userDoctorInfo.CardNum,
|
||||
OrgName: "成都金牛欣欣相照互联网医院有限公司",
|
||||
OrgNumber: "91510106MABTJY4K9R",
|
||||
Pin: fmt.Sprintf("%d", user.UserId),
|
||||
OrgDept: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||||
Province: "四川省",
|
||||
Locality: "成都市",
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书申请告知",
|
||||
}
|
||||
|
||||
cloudCertResponse, err := ca.AddCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// 到期时间-测试:180,正式:365
|
||||
CertExpireTime := model.LocalTime(time.Now().AddDate(0, 0, 180))
|
||||
if config.C.Env == "prod" {
|
||||
CertExpireTime = model.LocalTime(time.Now().AddDate(0, 0, 365))
|
||||
}
|
||||
|
||||
// 新增ca监管证书表
|
||||
userCaCert = &model.UserCaCert{
|
||||
UserId: &user.UserId,
|
||||
IsSystem: 0,
|
||||
IsLatest: 1,
|
||||
Type: 2,
|
||||
CertBase64: cloudCertResponse.CertBase64,
|
||||
CertChainP7: cloudCertResponse.CertP7,
|
||||
CertSerialNumber: cloudCertResponse.CertSerialnumber,
|
||||
CaPin: fmt.Sprintf("%d", user.UserId),
|
||||
IsSignConfig: 0,
|
||||
SignConfig: "",
|
||||
CertApplicationTime: model.LocalTime(time.Now()),
|
||||
CertExpireTime: CertExpireTime, // 180天以后的时间
|
||||
}
|
||||
|
||||
userCaCert, err = userCaCertDao.AddUserCaCert(tx, userCaCert)
|
||||
if err != nil || userCaCert == nil {
|
||||
utils.LogJsonErr("UserCaCertService-UserCloudCert", userDoctor.UserName+"申请成功,存储失败")
|
||||
continue
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("UserCaCertService-UserCloudCert", userDoctor.UserName+"申请成功")
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
func LogJsonInfo(v interface{}) {
|
||||
func LogJsonInfo(msg string, v interface{}) {
|
||||
jsonData, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling struct to JSON:", err)
|
||||
@ -15,9 +15,14 @@ func LogJsonInfo(v interface{}) {
|
||||
}
|
||||
|
||||
jsonString := string(jsonData)
|
||||
fmt.Println(jsonString)
|
||||
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"data": jsonString,
|
||||
}).Info("info")
|
||||
}).Info(msg)
|
||||
}
|
||||
|
||||
func LogJsonErr(msg string, v interface{}) {
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"data": v,
|
||||
}).Errorf(msg)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user