新增添加用户签章配置
This commit is contained in:
+185
-156
@@ -1,13 +1,18 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/extend/aliyun"
|
||||
"hospital-admin-api/extend/ca"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -89,8 +94,8 @@ func (r *UserCaCertService) GetUserCloudCert(tx *gorm.DB, userId int64) (bool, e
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: cardName,
|
||||
PersonalIdNumber: cardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
OrgName: "成都金牛欣欣相照互联网医院有限公司",
|
||||
OrgNumber: "91510106MABTJY4K9R",
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
OrgDept: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||||
Province: "四川省",
|
||||
@@ -224,8 +229,8 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
PersonalPhone: user.Mobile,
|
||||
PersonalName: cardName,
|
||||
PersonalIdNumber: cardNum,
|
||||
OrgName: "",
|
||||
OrgNumber: "",
|
||||
OrgName: "成都金牛欣欣相照互联网医院有限公司",
|
||||
OrgNumber: "91510106MABTJY4K9R",
|
||||
Pin: fmt.Sprintf("%d", userId),
|
||||
OrgDept: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||||
Province: "四川省",
|
||||
@@ -238,7 +243,6 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
|
||||
cloudCertResponse, err := ca.EditCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
@@ -249,7 +253,6 @@ func (r *UserCaCertService) EditUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
data["cert_serial_number"] = cloudCertResponse.CertSerialnumber
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("审核失败")
|
||||
}
|
||||
|
||||
@@ -325,7 +328,6 @@ func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
|
||||
cloudCertResponse, err := ca.RenewCloudCert(cloudCertRequestData)
|
||||
if err != nil || cloudCertResponse == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
@@ -336,7 +338,6 @@ func (r *UserCaCertService) RenewUserCloudCert(tx *gorm.DB, userId int64) (bool,
|
||||
data["cert_serial_number"] = cloudCertResponse.CertSerialnumber
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("审核失败")
|
||||
}
|
||||
|
||||
@@ -400,14 +401,12 @@ func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool
|
||||
|
||||
_, 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("注销失败")
|
||||
}
|
||||
|
||||
@@ -415,149 +414,179 @@ func (r *UserCaCertService) RemoveUserCloudCert(tx *gorm.DB, userId int64) (bool
|
||||
}
|
||||
|
||||
// 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
|
||||
// }
|
||||
func (r *UserCaCertService) AddUserSignConfig(tx *gorm.DB, req requests.AddUserSignConfig) (bool, error) {
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
|
||||
var entityId string // 唯一标识
|
||||
var cardNum string // 身份证号/信用代码
|
||||
var signImagePath string // 签名图片地址
|
||||
|
||||
// 医院-固定
|
||||
if req.Type == 1 {
|
||||
entityId = "5345345461"
|
||||
cardNum = "91510106MABTJY4K9R"
|
||||
signImagePath = "basic/file/hospital_signature.png"
|
||||
}
|
||||
|
||||
// 医生
|
||||
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
|
||||
signImagePath = strings.TrimLeft(userDoctorInfo.SignImage, "/")
|
||||
}
|
||||
|
||||
// 药师
|
||||
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
|
||||
signImagePath = strings.TrimLeft(userPharmacistInfo.SignImage, "/")
|
||||
}
|
||||
|
||||
// 检测是否存在云证书
|
||||
maps := make(map[string]interface{})
|
||||
maps["ca_pin"] = entityId
|
||||
maps["type"] = 2
|
||||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||||
if userCaCert == nil {
|
||||
return false, errors.New("医生未申请云证书,请申请后添加签章配置")
|
||||
}
|
||||
|
||||
if userCaCert.IsSignConfig == 1 {
|
||||
return false, errors.New("医生已存在签章配置,请勿重复添加")
|
||||
}
|
||||
|
||||
// 下载签章图片
|
||||
var style string
|
||||
if req.Type == 1 {
|
||||
style = "image/resize,w_300,h_300"
|
||||
} else {
|
||||
style = "image/resize,m_lfit,w_100,h_350"
|
||||
}
|
||||
|
||||
signImage, err := aliyun.GetCusTomObjectToRAM(signImagePath, style)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
signImage = base64.StdEncoding.EncodeToString([]byte(signImage))
|
||||
|
||||
// 签章配置,JSON
|
||||
var signParam map[string]interface{}
|
||||
var signParams []map[string]interface{}
|
||||
|
||||
// 医院
|
||||
if req.Type == 1 {
|
||||
signParam = map[string]interface{}{
|
||||
"llx": "370",
|
||||
"lly": "210",
|
||||
"urx": "520",
|
||||
"ury": "360",
|
||||
}
|
||||
}
|
||||
|
||||
// 医生
|
||||
if req.Type == 2 {
|
||||
signParam = map[string]interface{}{
|
||||
"llx": "120",
|
||||
"lly": "190",
|
||||
"urx": "190",
|
||||
"ury": "140",
|
||||
}
|
||||
}
|
||||
|
||||
// 药师
|
||||
if req.Type == 2 {
|
||||
signParam = map[string]interface{}{
|
||||
"llx": "350",
|
||||
"lly": "190",
|
||||
"urx": "440",
|
||||
"ury": "140",
|
||||
}
|
||||
}
|
||||
|
||||
signParam["pageList"] = []int{1}
|
||||
signParam["sealImg"] = signImage
|
||||
|
||||
signParams = append(signParams, signParam)
|
||||
|
||||
signParamJson, err := json.Marshal(signParams)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 添加签章配置
|
||||
cloudCertRequestData := &ca.AddUserSignConfigRequest{
|
||||
UserId: fmt.Sprintf("%d", entityId),
|
||||
ConfigKey: fmt.Sprintf("%d", entityId),
|
||||
CertSn: cardNum,
|
||||
SignParam: string(signParamJson),
|
||||
SealImg: signImage,
|
||||
}
|
||||
|
||||
_, err = ca.AddUserSignConfig(cloudCertRequestData)
|
||||
if err != nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 修改ca监管证书表
|
||||
data := make(map[string]interface{})
|
||||
data["is_sign_config"] = 1
|
||||
data["sign_config"] = string(signParamJson)
|
||||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||||
if err != nil {
|
||||
return false, errors.New("修改签证配置失败")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user