新增申请云证书接口
This commit is contained in:
@@ -0,0 +1,257 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/extend/ca"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserCaCertService struct {
|
||||
}
|
||||
|
||||
// GetUserCloudCert 申请云证书-个人
|
||||
func (r *UserCaCertService) GetUserCloudCert(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("用户数据错误")
|
||||
}
|
||||
|
||||
// 定义所需变量
|
||||
var departmentCustomId int64 // 自定义科室id
|
||||
var cardName string // 身份证名称
|
||||
var cardNum string // 身份证号码
|
||||
|
||||
// 医生
|
||||
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("请先完成多点执业认证")
|
||||
}
|
||||
|
||||
departmentCustomId = userDoctor.DepartmentCustomId // 自定义科室id
|
||||
cardName = userDoctorInfo.CardName // 身份证名称
|
||||
cardNum = userDoctorInfo.CardNum // 身份证号码
|
||||
}
|
||||
|
||||
// 获取自定义科室数据
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||||
if err != nil || hospitalDepartmentCustom == nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
// 获取标准科室数据
|
||||
hospitalDepartmentDao := dao.HospitalDepartment{}
|
||||
hospitalDepartment, err := hospitalDepartmentDao.GetHospitalDepartmentById(hospitalDepartmentCustom.DepartmentId)
|
||||
if err != nil || hospitalDepartment == nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
// 申请云证书
|
||||
cloudCertRequestData := &ca.AddCloudCertRequest{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
EntityType: "Personal",
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: cardName,
|
||||
PersonalIdNumber: cardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
Pin: fmt.Sprintf("%d", 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 {
|
||||
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
|
||||
}
|
||||
|
||||
// EditUserCloudCert 修改云证书-个人
|
||||
func (r *UserCaCertService) EditUserCloudCert(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 == 1 {
|
||||
return false, errors.New("用户云证书为最新证书,无法修改")
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 定义所需变量
|
||||
var departmentCustomId int64 // 自定义科室id
|
||||
var cardName string // 身份证名称
|
||||
var cardNum string // 身份证号码
|
||||
|
||||
// 医生
|
||||
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("请先完成多点执业认证")
|
||||
}
|
||||
|
||||
// 检测是否存在正在审核中的处方
|
||||
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = userDoctor.DoctorId
|
||||
maps["prescription_status"] = 1
|
||||
orderPrescription, err := orderPrescriptionDao.GetList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("更新云证书失败")
|
||||
}
|
||||
|
||||
if len(orderPrescription) > 0 {
|
||||
return false, errors.New("存在审核中的处方,请勿更新云证书")
|
||||
}
|
||||
|
||||
departmentCustomId = userDoctor.DepartmentCustomId // 自定义科室id
|
||||
cardName = userDoctorInfo.CardName // 身份证名称
|
||||
cardNum = userDoctorInfo.CardNum // 身份证号码
|
||||
}
|
||||
|
||||
// 获取自定义科室数据
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||||
if err != nil || hospitalDepartmentCustom == nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
// 获取标准科室数据
|
||||
hospitalDepartmentDao := dao.HospitalDepartment{}
|
||||
hospitalDepartment, err := hospitalDepartmentDao.GetHospitalDepartmentById(hospitalDepartmentCustom.DepartmentId)
|
||||
if err != nil || hospitalDepartment == nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
// 修改云证书
|
||||
cloudCertRequestData := &ca.EditCloudCertRequestData{
|
||||
EntityId: fmt.Sprintf("%d", userId),
|
||||
EntityType: "Personal",
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: cardName,
|
||||
PersonalIdNumber: cardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
OrgDept: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||||
Province: "四川省",
|
||||
Locality: "成都市",
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书变更告知",
|
||||
}
|
||||
|
||||
cloudCertResponse, err := ca.EditCloudCert(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
|
||||
}
|
||||
+50
-119
@@ -90,9 +90,19 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||||
doctorBankCard, _ := doctorBankCardDao.GetDoctorBankCardByDoctorId(doctorId)
|
||||
|
||||
// 获取医生云证书
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userDoctor.UserId
|
||||
maps["type"] = 2
|
||||
maps["is_latest"] = 1
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
|
||||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||||
userDoctorInfoData := make(map[string]interface{}) // 医生详情数据
|
||||
userData := make(map[string]interface{}) // 用户数据
|
||||
userCaCertData := make(map[string]interface{}) // 用户云证书
|
||||
|
||||
// 处理头像
|
||||
avatar := utils.RemoveOssDomain(req.Avatar)
|
||||
@@ -317,13 +327,16 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
if err != nil {
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
if len(orderPrescription) > 0 {
|
||||
return false, errors.New("存在审核中的处方,请勿修改科室数据")
|
||||
}
|
||||
|
||||
if userCaCert != nil {
|
||||
userCaCertData["is_latest"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
// 审核失败、未审核情况下,如果数据存在修改,进入待审核
|
||||
// 审核失败、未审核情况下,如果数据存在修改,重新进入待审核
|
||||
if userDoctor.MultiPointStatus == 0 || userDoctor.MultiPointStatus == 3 {
|
||||
if signImage != userDoctorInfo.SignImage || idCardBack != userDoctorInfo.IdCardBack || idCardFront != userDoctorInfo.IdCardFront {
|
||||
userDoctorData["multi_point_status"] = 2
|
||||
@@ -341,7 +354,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
}
|
||||
|
||||
if len(orderPrescription) > 0 {
|
||||
return false, errors.New("存在审核中的处方,请勿修改科室数据")
|
||||
return false, errors.New("存在审核中的处方,请勿修改签名及身份证数据")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -551,7 +564,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
}
|
||||
}
|
||||
|
||||
// 修改医生银行卡数据
|
||||
// 修改医生银行卡数据-新增
|
||||
if doctorBankCard == nil {
|
||||
if provinceId != 0 && cityId != 0 && countyId != 0 && bankId != 0 && bankCardCode != "" {
|
||||
// 新增医生银行卡表
|
||||
@@ -582,6 +595,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
}
|
||||
}
|
||||
|
||||
// 修改医生银行卡数据-修改
|
||||
if doctorBankCard != nil {
|
||||
// 修改
|
||||
doctorBankCardData := make(map[string]interface{}) // 医生银行卡数据
|
||||
@@ -618,6 +632,15 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
||||
}
|
||||
}
|
||||
|
||||
// 修改医生云证书状态
|
||||
if len(userCaCertData) > 0 && userCaCert != nil {
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, userCaCertData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("用户云证书修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 判断头像是否修改,同步修改im
|
||||
if userDoctor.Avatar != avatar {
|
||||
profileItem := []tencentIm.ProfileItem{
|
||||
@@ -1391,20 +1414,6 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
// 获取医生详情数据
|
||||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(doctorId)
|
||||
if err != nil {
|
||||
return false, errors.New("医生详情数据错误")
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||||
if err != nil || user == nil {
|
||||
return false, errors.New("医生数据错误")
|
||||
}
|
||||
|
||||
if userDoctor.MultiPointStatus == 1 {
|
||||
return false, errors.New("已审核成功,无法进行操作")
|
||||
}
|
||||
@@ -1413,8 +1422,6 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo
|
||||
return false, errors.New("请先通过身份认证")
|
||||
}
|
||||
|
||||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||||
|
||||
if userDoctor.MultiPointStatus == req.MultiPointStatus {
|
||||
return false, errors.New("请勿重复操作")
|
||||
}
|
||||
@@ -1427,114 +1434,38 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo
|
||||
}
|
||||
}()
|
||||
|
||||
// 检测是否存在云证书
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCertByUserId(userDoctor.UserId)
|
||||
// 云证书处理
|
||||
if req.MultiPointStatus == 1 && config.C.Env == "prod" {
|
||||
userCaCertService := UserCaCertService{}
|
||||
|
||||
// 获取自定义科室数据
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(userDoctor.DepartmentCustomId)
|
||||
if err != nil || hospitalDepartmentCustom == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
// 检测是否存在云证书
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
// 获取标准科室数据
|
||||
hospitalDepartmentDao := dao.HospitalDepartment{}
|
||||
hospitalDepartment, err := hospitalDepartmentDao.GetHospitalDepartmentById(hospitalDepartmentCustom.DepartmentId)
|
||||
if err != nil || hospitalDepartment == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
// 处理审核通过的情况
|
||||
if config.C.Env == "prod" {
|
||||
if req.MultiPointStatus == 1 {
|
||||
if userCaCert == nil {
|
||||
// 申请云证书
|
||||
cloudCertRequestData := &ca.AddCloudCertRequest{
|
||||
EntityId: strconv.FormatInt(userDoctor.UserId, 10),
|
||||
EntityType: "Personal",
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: userDoctorInfo.CardName,
|
||||
PersonalIdNumber: userDoctorInfo.CardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
Pin: strconv.FormatInt(userDoctor.UserId, 10),
|
||||
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 {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 新增ca监管证书表
|
||||
userCaCert := &model.UserCaCert{
|
||||
UserId: &userDoctor.UserId,
|
||||
IsSystem: 0,
|
||||
Type: 2,
|
||||
CertBase64: cloudCertResponse.CertBase64,
|
||||
CertChainP7: cloudCertResponse.CertP7,
|
||||
CertSerialNumber: cloudCertResponse.CertSerialnumber,
|
||||
CaPin: strconv.FormatInt(userDoctor.UserId, 10),
|
||||
IsSignConfig: 0,
|
||||
SignConfig: "",
|
||||
}
|
||||
|
||||
userCaCert, err = userCaCertDao.AddUserCaCert(tx, userCaCert)
|
||||
if err != nil || userCaCert == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
} else {
|
||||
// 修改云证书
|
||||
cloudCertRequestData := &ca.EditCloudCertRequestData{
|
||||
EntityId: strconv.FormatInt(userDoctor.UserId, 10),
|
||||
EntityType: "Personal",
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: userDoctorInfo.CardName,
|
||||
PersonalIdNumber: userDoctorInfo.CardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
Pin: strconv.FormatInt(userDoctor.UserId, 10),
|
||||
OrgDept: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||||
Province: "四川省",
|
||||
Locality: "成都市",
|
||||
AuthType: "实人认证",
|
||||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
AuthResult: "认证通过",
|
||||
AuthNoticeType: "数字证书变更告知",
|
||||
}
|
||||
|
||||
cloudCertResponse, err := ca.EditCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
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)
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userDoctor.UserId
|
||||
maps["type"] = 2
|
||||
maps["is_latest"] = 1
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
// 申请云证书
|
||||
_, err = userCaCertService.GetUserCloudCert(tx, userDoctor.UserId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
} else {
|
||||
if userCaCert.IsLatest == 0 {
|
||||
_, err = userCaCertService.EditUserCloudCert(tx, userDoctor.UserId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("审核失败")
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 医生修改数据
|
||||
userDoctorData := make(map[string]interface{})
|
||||
userDoctorData["multi_point_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
// 审核不通过
|
||||
|
||||
Reference in New Issue
Block a user