新增了接口
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"case-open-api/api/dao"
|
||||
)
|
||||
|
||||
type CaseService struct {
|
||||
}
|
||||
|
||||
// CheckCasePlatform 检测病例平台关系
|
||||
func (r *CaseService) CheckCasePlatform(caseId, platformId int64) (b bool, err error) {
|
||||
casePlatformDao := dao.CasePlatformDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["case_id"] = caseId
|
||||
maps["platform_id"] = platformId
|
||||
_, err = casePlatformDao.GetCasePlatform(maps)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package service
|
||||
|
||||
type ProjectService struct {
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"case-open-api/api/dao"
|
||||
"case-open-api/api/model"
|
||||
"case-open-api/utils"
|
||||
)
|
||||
|
||||
// ProjectPlatformWhiteService 项目关联平台白名单
|
||||
type ProjectPlatformWhiteService struct {
|
||||
}
|
||||
|
||||
// CheckProjectPlatformWhiteByUser 检测用户是否属于白名单
|
||||
func (r *ProjectPlatformWhiteService) CheckProjectPlatformWhiteByUser(user *model.User, platformId int64) (b bool, err error) {
|
||||
// 白名单-医生
|
||||
projectPlatformDoctorDao := dao.ProjectPlatformDoctorDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["platform_id"] = platformId
|
||||
maps["user_id"] = user.UserId
|
||||
projectPlatformDoctor, _ := projectPlatformDoctorDao.GetProjectPlatformDoctor(maps)
|
||||
if projectPlatformDoctor != nil {
|
||||
if projectPlatformDoctor.Status == 1 {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户医院数据
|
||||
basicHospitalDao := dao.BasicHospitalDao{}
|
||||
basicHospital, err := basicHospitalDao.GetBasicHospitalById(user.HospitalId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 白名单-医院
|
||||
projectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
||||
maps = make(map[string]interface{})
|
||||
maps["platform_id"] = platformId
|
||||
maps["hospital_id"] = user.HospitalId
|
||||
projectPlatformHospital, _ := projectPlatformHospitalDao.GetProjectPlatformHospital(maps)
|
||||
if projectPlatformHospital != nil {
|
||||
if projectPlatformHospital.Status == 1 {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
|
||||
// 白名单-动态
|
||||
projectPlatformDynamicDao := dao.ProjectPlatformDynamicDao{}
|
||||
maps = make(map[string]interface{})
|
||||
maps["platform_id"] = platformId
|
||||
projectPlatformDynamics, _ := projectPlatformDynamicDao.GetProjectPlatformDynamicPreloadList(maps)
|
||||
if len(projectPlatformDynamics) > 0 {
|
||||
area := true
|
||||
level := true
|
||||
title := true
|
||||
department := true
|
||||
|
||||
for _, dynamic := range projectPlatformDynamics {
|
||||
if dynamic.Status == 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if dynamic.DynamicType == "area" {
|
||||
area = false
|
||||
}
|
||||
|
||||
if dynamic.DynamicType == "level" {
|
||||
level = false
|
||||
}
|
||||
|
||||
if dynamic.DynamicType == "title" {
|
||||
title = false
|
||||
}
|
||||
|
||||
if dynamic.DynamicType == "department" {
|
||||
department = false
|
||||
}
|
||||
|
||||
for _, item := range dynamic.ProjectPlatformDynamicItem {
|
||||
// 省份
|
||||
if dynamic.DynamicType == "area" {
|
||||
if basicHospital.Province == item.ItemValue {
|
||||
area = true
|
||||
}
|
||||
}
|
||||
|
||||
// 医院等级
|
||||
if dynamic.DynamicType == "level" {
|
||||
if basicHospital.HospitalLevel == item.ItemValue {
|
||||
level = true
|
||||
}
|
||||
}
|
||||
|
||||
// 职称
|
||||
if dynamic.DynamicType == "title" {
|
||||
if utils.DoctorTitleToString(user.Title) == item.ItemValue {
|
||||
title = true
|
||||
}
|
||||
}
|
||||
|
||||
// 科室
|
||||
if dynamic.DynamicType == "department" {
|
||||
if user.DepartmentName == item.ItemValue {
|
||||
department = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if area == true && level == true && title == true && department == true {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"case-open-api/extend/aliyun"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type PublicService struct {
|
||||
}
|
||||
|
||||
// GetUserIP 获取用户ip
|
||||
func (r *PublicService) GetUserIP(h *http.Request) string {
|
||||
forwarded := h.Header.Get("X-FORWARDED-FOR")
|
||||
if forwarded != "" {
|
||||
return forwarded
|
||||
}
|
||||
return h.RemoteAddr
|
||||
}
|
||||
|
||||
// GetOssSign 获取oss签名
|
||||
func (a *PublicService) GetOssSign(scene int) (*aliyun.GetOssSignResponse, error) {
|
||||
var dir string
|
||||
if scene == 1 {
|
||||
dir = dir + "user/avatar/"
|
||||
}
|
||||
|
||||
if dir == "" {
|
||||
return nil, errors.New("获取签名失败")
|
||||
}
|
||||
|
||||
// 生成签名
|
||||
ossSign, _ := aliyun.GetOssSign(dir)
|
||||
return ossSign, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"case-open-api/extend/aliyun"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
// HandleUserImage 处理用户图片
|
||||
func (r *UserService) HandleUserImage(wxAvatar string) (ossPath string, err error) {
|
||||
if wxAvatar == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// 发送GET请求
|
||||
resp, err := http.Get(wxAvatar)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return "", errors.New("请求失败")
|
||||
}
|
||||
|
||||
// 读取响应体
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 设置文件名字
|
||||
now := time.Now()
|
||||
dateTimeString := now.Format("20060102150405") // 当前时间字符串
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数
|
||||
ossPath = "user/avatar/" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".png"
|
||||
|
||||
// 上传oss
|
||||
_, err = aliyun.PutObjectByte(ossPath, respBody)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ossPath = "/" + ossPath
|
||||
|
||||
return ossPath, nil
|
||||
}
|
||||
Reference in New Issue
Block a user