新增了接口

This commit is contained in:
wucongxing8150 2024-12-30 16:34:26 +08:00
parent e6e78ad658
commit 60850d98da
153 changed files with 10293 additions and 5 deletions

6
.gitignore vendored
View File

@ -11,7 +11,11 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.log
# Dependency directories (remove the comment below to include it)
# vendor/
.idea/
.git/
.DS_Store/
.tmp/

View File

@ -1,4 +0,0 @@
# case-open-api
互动病例
开放平台接口

10
api/controller/Base.go Normal file
View File

@ -0,0 +1,10 @@
package controller
// Api api接口
type Api struct {
Project // 项目
ResProject // 项目-佳动例
Case // 病例
ResCase // 病例-佳动例
Res // 佳动例
}

64
api/controller/Case.go Normal file
View File

@ -0,0 +1,64 @@
package controller
import (
"case-open-api/api/dao"
"case-open-api/api/dto"
"case-open-api/api/requests"
"case-open-api/api/responses"
"case-open-api/global"
"case-open-api/utils"
"github.com/gin-gonic/gin"
)
type Case struct {
}
// GetCasePage 获取列表-分页
func (b *Case) GetCasePage(c *gin.Context) {
caseRequest := requests.CaseRequest{}
req := caseRequest.GetCasePage
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
if req.Page == 0 {
req.Page = 1
}
if req.PageSize == 0 {
req.PageSize = 20
}
platformId := c.GetInt64("platformId") // 平台id
if platformId == 0 {
responses.FailWithMessage("非法请求", c)
return
}
req.PlatformId = platformId
// 获取数据
caseDao := dao.CaseDao{}
cases, total, err := caseDao.GetCasePageSearch(req, req.Page, req.PageSize)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
g := dto.GetCaseResListDto(cases)
result := make(map[string]interface{})
result["page"] = req.Page
result["page_size"] = req.PageSize
result["total"] = total
result["data"] = g
responses.OkWithData(result, c)
}

91
api/controller/Project.go Normal file
View File

@ -0,0 +1,91 @@
package controller
import (
"case-open-api/api/dao"
"case-open-api/api/dto"
"case-open-api/api/requests"
"case-open-api/api/responses"
"case-open-api/global"
"case-open-api/utils"
"github.com/gin-gonic/gin"
"time"
)
type Project struct {
}
// GetProjectPage 获取列表-分页
func (b *Project) GetProjectPage(c *gin.Context) {
ProjectRequest := requests.ProjectRequest{}
req := ProjectRequest.GetProjectPage
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
if req.Page == 0 {
req.Page = 1
}
if req.PageSize == 0 {
req.PageSize = 20
}
platformId := c.GetInt64("platformId") // 平台id
if platformId == 0 {
responses.FailWithMessage("非法请求", c)
return
}
req.PlatformId = platformId
// 获取数据
ProjectDao := dao.ProjectDao{}
projects, total, err := ProjectDao.GetProjectPageSearch(req, req.Page, req.PageSize)
if err != nil {
responses.FailWithMessage("获取数据失败", c)
return
}
// 处理返回值
g := dto.GetProjectListDto(projects)
projectPlatformDao := dao.ProjectPlatformDao{}
caseDao := dao.CaseDao{}
for _, projectDto := range g {
// 获取项目关联平台
maps := make(map[string]interface{})
maps["project_id"] = projectDto.ProjectId
maps["platform_id"] = platformId
projectPlatform, _ := projectPlatformDao.GetProjectPlatform(maps)
if projectPlatform != nil {
// 加载是否存在福利
projectDto.LoadIsWelfare(projectPlatform)
}
// 获取最近7天的病例
now := time.Now()
t := now.AddDate(0, 0, -7)
maps = make(map[string]interface{})
maps["project_id"] = projectDto.ProjectId
result, _ := caseDao.GetCaseFormPastDay(maps, t)
if result != nil {
// 加载最近更新情况
projectDto.LoadIsRecentlyUpdate(result)
}
}
result := make(map[string]interface{})
result["page"] = req.Page
result["page_size"] = req.PageSize
result["total"] = total
result["data"] = g
responses.OkWithData(result, c)
}

308
api/controller/Res.go Normal file
View File

@ -0,0 +1,308 @@
package controller
import (
"case-open-api/api/dao"
"case-open-api/api/dto"
"case-open-api/api/requests"
"case-open-api/api/responses"
"case-open-api/api/service"
"case-open-api/global"
"case-open-api/utils"
"fmt"
"github.com/gin-gonic/gin"
"math"
"time"
)
type Res struct {
}
// GetResProjectList 获取项目列表
func (b *Res) GetResProjectList(c *gin.Context) {
resRequest := requests.ResRequest{}
req := resRequest.GetResProjectList
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
platformId := c.GetInt64("platformId") // 平台id
if platformId == 0 {
responses.FailWithMessage("非法请求", c)
return
}
req.PlatformId = platformId
// 获取数据
ProjectDao := dao.ProjectDao{}
projects, err := ProjectDao.GetResProjectListSearch(req)
if err != nil {
responses.FailWithMessage("获取数据失败", c)
return
}
// 处理返回值
g := dto.GetResProjectListDto(projects)
projectPlatformDao := dao.ProjectPlatformDao{}
caseDao := dao.CaseDao{}
for _, projectDto := range g {
// 获取项目关联平台
maps := make(map[string]interface{})
maps["project_id"] = projectDto.ProjectId
maps["platform_id"] = platformId
projectPlatform, _ := projectPlatformDao.GetProjectPlatform(maps)
if projectPlatform != nil {
// 加载是否存在福利
projectDto.LoadIsWelfare(projectPlatform)
}
// 获取最近7天的病例
now := time.Now()
t := now.AddDate(0, 0, -7)
maps = make(map[string]interface{})
maps["project_id"] = projectDto.ProjectId
result, _ := caseDao.GetCaseFormPastDay(maps, t)
if result != nil {
// 加载最近更新情况
projectDto.LoadIsRecentlyUpdate(result)
}
}
responses.OkWithData(g, c)
}
// GetResCaseList 获取病例列表
func (b *Res) GetResCaseList(c *gin.Context) {
resRequest := requests.ResRequest{}
req := resRequest.GetResCaseList
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
platformId := c.GetInt64("platformId") // 平台id
if platformId == 0 {
responses.FailWithMessage("非法请求", c)
return
}
req.PlatformId = platformId
// 获取数据
caseDao := dao.CaseDao{}
cases, err := caseDao.GetResCaseList(req)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
g := dto.GetCaseResListDto(cases)
responses.OkWithData(g, c)
}
// GetResCaseRecordList 病例领取记录
func (b *Res) GetResCaseRecordList(c *gin.Context) {
resRequest := requests.ResRequest{}
req := resRequest.GetResCaseRecordList
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
platformId := c.GetInt64("platformId") // 平台id
if platformId == 0 {
responses.FailWithMessage("非法请求", c)
return
}
req.PlatformId = platformId
if req.StartTime != "" {
if req.EndTime == "" {
responses.FailWithMessage("参数错误", c)
return
}
}
page := 1
if req.Pindex != 0 {
page = req.Pindex
}
pageSize := 100
// 获取数据
caseUserDao := dao.CaseUserDao{}
caseUsers, total, err := caseUserDao.GetCaseUserRecordList(req, page, pageSize)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
g := make([]*dto.ResCaseRecordDto, len(caseUsers))
if len(caseUsers) > 0 {
recordScoreDao := dao.RecordScoreDao{}
caseCommentDao := dao.CaseCommentDao{}
userAnswerRecordsDao := dao.UserAnswerRecordsDao{}
userDao := dao.UserDao{}
projectPlatformWhiteService := service.ProjectPlatformWhiteService{}
for i, v := range caseUsers {
// 获取积分发放记录
maps := make(map[string]interface{})
maps["project_id"] = req.ProjectId
maps["case_id"] = v.CaseId
maps["platform_id"] = v.PlatformId
maps["user_id"] = v.UserId
recordScores, _ := recordScoreDao.GetRecordScoreList(maps)
// 获取用户评论
maps = make(map[string]interface{})
maps["case_id"] = v.CaseId
maps["platform_id"] = v.PlatformId
maps["user_id"] = v.UserId
maps["status"] = 1
caseComments, _ := caseCommentDao.GetCaseCommentList(maps)
// 获取用户答题记录
maps = make(map[string]interface{})
maps["case_id"] = v.CaseId
maps["platform_id"] = v.PlatformId
maps["user_id"] = v.UserId
userAnswerRecordss, _ := userAnswerRecordsDao.GetUserAnswerRecordsPreloadList(maps)
// 用时
minutes := v.ReadDuration / 60
remainingSeconds := v.ReadDuration % 60
residenceTime := fmt.Sprintf("%02d:%02d", minutes, remainingSeconds)
response := &dto.ResCaseRecordDto{
CaseUserId: fmt.Sprintf("%d", v.CaseUserId),
Sid: fmt.Sprintf("%d", v.CaseId),
Beizhu: "",
OpenId: "",
Title: v.Case.CaseName,
NickName: v.User.UserName,
RealName: v.User.UserName,
Mobile: v.User.MobileEncryption,
Hos2: v.User.DepartmentName, // 科室
Job: utils.DoctorTitleToString(v.User.Title),
HospitalName: v.User.Hospital.HospitalName,
ResideProvince: v.User.Hospital.Province,
ResideCity: v.User.Hospital.City,
CreateDate: time.Time(v.CreatedAt).Format("2006-01-02"),
CreateTimes: time.Time(v.CreatedAt).Format("15:04:05"),
ResidenceTime: residenceTime,
QuestionAnswer: nil,
TslUid: v.User.UserIden,
TslShareUserId: v.ShareUserIden,
IsVip: 0,
Credit1: 0,
Credit2: 0,
Credit3: 0,
Credit4: 0,
CreditTotal: v.TotalScore,
HasRemark: 0,
Remark: nil,
}
// 积分
for _, v3 := range recordScores {
if v3.Type == 1 {
response.Credit1 = v3.Score
}
if v3.Type == 2 {
response.Credit2 = v3.Score
}
if v3.Type == 3 {
response.Credit3 = v3.Score
}
if v3.Type == 4 {
response.Credit4 = v3.Score
}
}
// 评论
if len(caseComments) > 0 {
response.Remark = make([]*dto.RemarkDto, len(caseComments))
response.HasRemark = 1
for i2, comment := range caseComments {
remarkDto := &dto.RemarkDto{
Remark: comment.Content,
CreateTime: time.Time(comment.CreatedAt).Format("2006-01-02 15:04:05"),
}
response.Remark[i2] = remarkDto
}
}
// 题目
if len(userAnswerRecordss) > 0 {
response.QuestionAnswer = make([]*dto.QuestionAnswerDto, len(userAnswerRecordss))
for i2, recordss := range userAnswerRecordss {
questionAnswerDto := &dto.QuestionAnswerDto{
Question: recordss.CaseItemQuestion.QuestionName,
Answer: recordss.Answer,
Correct: false,
Order: i2 + 1,
}
if recordss.IsTrue == 1 {
questionAnswerDto.Correct = true
}
response.QuestionAnswer[i2] = questionAnswerDto
}
}
// 获取用户数据
user, _ := userDao.GetUserById(v.UserId)
if user != nil {
// 检测用户是否白名单
isWhite, _ := projectPlatformWhiteService.CheckProjectPlatformWhiteByUser(user, v.PlatformId)
if isWhite {
response.IsVip = 1
}
}
// 将转换后的结构体添加到新切片中
g[i] = response
}
}
result := make(map[string]interface{})
result["pindex"] = page
result["psize"] = pageSize
result["ptotal"] = int(math.Ceil(float64(total) / float64(pageSize)))
result["ctotal"] = total
result["data"] = g
responses.OkWithData(result, c)
}

View File

@ -0,0 +1,4 @@
package controller
type ResCase struct {
}

View File

@ -0,0 +1,4 @@
package controller
type ResProject struct {
}

108
api/dao/AdminUser.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type AdminUserDao struct {
}
// GetAdminUserById 获取数据-id
func (r *AdminUserDao) GetAdminUserById(AdminUserId int64) (m *model.AdminUser, err error) {
err = global.Db.First(&m, AdminUserId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetAdminUserPreloadById 获取数据-加载全部关联-id
func (r *AdminUserDao) GetAdminUserPreloadById(AdminUserId int64) (m *model.AdminUser, err error) {
err = global.Db.Preload(clause.Associations).First(&m, AdminUserId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteAdminUser 删除
func (r *AdminUserDao) DeleteAdminUser(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.AdminUser{}).Error
if err != nil {
return err
}
return nil
}
// DeleteAdminUserById 删除-id
func (r *AdminUserDao) DeleteAdminUserById(tx *gorm.DB, AdminUserId int64) error {
if err := tx.Delete(&model.AdminUser{}, AdminUserId).Error; err != nil {
return err
}
return nil
}
// EditAdminUser 修改
func (r *AdminUserDao) EditAdminUser(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.AdminUser{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditAdminUserById 修改-id
func (r *AdminUserDao) EditAdminUserById(tx *gorm.DB, AdminUserId int64, data interface{}) error {
err := tx.Model(&model.AdminUser{}).Where("user_id = ?", AdminUserId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetAdminUserList 获取列表
func (r *AdminUserDao) GetAdminUserList(maps interface{}) (m []*model.AdminUser, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetAdminUserCount 获取数量
func (r *AdminUserDao) GetAdminUserCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.AdminUser{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetAdminUserListRand 获取列表-随机
func (r *AdminUserDao) GetAdminUserListRand(maps interface{}, limit int) (m []*model.AdminUser, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddAdminUser 新增
func (r *AdminUserDao) AddAdminUser(tx *gorm.DB, model *model.AdminUser) (*model.AdminUser, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetAdminUser 获取
func (r *AdminUserDao) GetAdminUser(maps interface{}) (m *model.AdminUser, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

126
api/dao/BasicHospital.go Normal file
View File

@ -0,0 +1,126 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type BasicHospitalDao struct {
}
// GetBasicHospitalById 获取数据-id
func (r *BasicHospitalDao) GetBasicHospitalById(hospitalId int64) (m *model.BasicHospital, err error) {
err = global.Db.First(&m, hospitalId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetBasicHospitalPreloadById 获取数据-加载全部关联-id
func (r *BasicHospitalDao) GetBasicHospitalPreloadById(hospitalId int64) (m *model.BasicHospital, err error) {
err = global.Db.Preload(clause.Associations).First(&m, hospitalId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteBasicHospital 删除
func (r *BasicHospitalDao) DeleteBasicHospital(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.BasicHospital{}).Error
if err != nil {
return err
}
return nil
}
// DeleteBasicHospitalById 删除-id
func (r *BasicHospitalDao) DeleteBasicHospitalById(tx *gorm.DB, hospitalId int64) error {
if err := tx.Delete(&model.BasicHospital{}, hospitalId).Error; err != nil {
return err
}
return nil
}
// EditBasicHospital 修改
func (r *BasicHospitalDao) EditBasicHospital(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.BasicHospital{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditBasicHospitalById 修改-id
func (r *BasicHospitalDao) EditBasicHospitalById(tx *gorm.DB, hospitalId int64, data interface{}) error {
err := tx.Model(&model.BasicHospital{}).Where("hospital_id = ?", hospitalId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetBasicHospitalList 获取列表
func (r *BasicHospitalDao) GetBasicHospitalList(maps interface{}) (m []*model.BasicHospital, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetBasicHospitalCount 获取数量
func (r *BasicHospitalDao) GetBasicHospitalCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.BasicHospital{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetBasicHospitalListRand 获取列表-随机
func (r *BasicHospitalDao) GetBasicHospitalListRand(maps interface{}, limit int) (m []*model.BasicHospital, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddBasicHospital 新增
func (r *BasicHospitalDao) AddBasicHospital(tx *gorm.DB, model *model.BasicHospital) (*model.BasicHospital, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetBasicHospital 获取
func (r *BasicHospitalDao) GetBasicHospital(maps interface{}) (m *model.BasicHospital, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// Inc 自增
func (r *BasicHospitalDao) Inc(tx *gorm.DB, hospitalId int64, field string, numeral int) error {
err := tx.Model(&model.BasicHospital{}).Where("hospital_id = ?", hospitalId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
if err != nil {
return err
}
return nil
}
// Dec 自减
func (r *BasicHospitalDao) Dec(tx *gorm.DB, hospitalId int64, field string, numeral int) error {
err := tx.Model(&model.BasicHospital{}).Where("hospital_id = ?", hospitalId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
if err != nil {
return err
}
return nil
}

224
api/dao/Case.go Normal file
View File

@ -0,0 +1,224 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/api/requests"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"time"
)
type CaseDao struct {
}
// GetCaseById 获取数据-id
func (r *CaseDao) GetCaseById(caseId int64) (m *model.Case, err error) {
err = global.Db.First(&m, caseId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCasePreloadById 获取数据-加载全部关联-id
func (r *CaseDao) GetCasePreloadById(caseId int64) (m *model.Case, err error) {
err = global.Db.Preload(clause.Associations).First(&m, caseId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCase 删除
func (r *CaseDao) DeleteCase(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.Case{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseById 删除-id
func (r *CaseDao) DeleteCaseById(tx *gorm.DB, caseId int64) error {
if err := tx.Delete(&model.Case{}, caseId).Error; err != nil {
return err
}
return nil
}
// EditCase 修改
func (r *CaseDao) EditCase(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.Case{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseById 修改-id
func (r *CaseDao) EditCaseById(tx *gorm.DB, caseId int64, data interface{}) error {
err := tx.Model(&model.Case{}).Where("case_id = ?", caseId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseList 获取列表
func (r *CaseDao) GetCaseList(maps interface{}) (m []*model.Case, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCount 获取数量
func (r *CaseDao) GetCaseCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.Case{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseListRand 获取列表-随机
func (r *CaseDao) GetCaseListRand(maps interface{}, limit int) (m []*model.Case, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCase 新增
func (r *CaseDao) AddCase(tx *gorm.DB, model *model.Case) (*model.Case, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCase 获取
func (r *CaseDao) GetCase(maps interface{}) (m *model.Case, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseFormPastDay 获取过去天数是否有更新
func (r *CaseDao) GetCaseFormPastDay(maps interface{}, createdAt time.Time) (m *model.Case, err error) {
err = global.Db.Where(maps).
Where("created_at > ?", createdAt.Format("2006-01-02 15:04:05")).
First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCasePageSearch 获取列表-分页
func (r *CaseDao) GetCasePageSearch(req requests.GetCasePage, page, pageSize int) (m []*model.Case, total int64, err error) {
var totalRecords int64
// 构建查询条件
query := global.Db.Model(&model.Case{})
// 项目
projectSubQuery := global.Db.Model(&model.ProjectPlatform{}).
Where("project_platform.project_id = case.project_id").
Where("project_platform.platform_id = ?", req.PlatformId).
Where("project_platform.status = ?", 1)
query = query.Where("EXISTS (?)", projectSubQuery)
query = query.Where("case_status = ?", 1)
// 搜索关键字
if req.Keyword != "" {
keyword := "%" + req.Keyword + "%" //
// 病例名称
orQuery := global.Db.Model(&model.Case{}).Or("case_name LIKE ?", keyword)
// 作者
orQuery = orQuery.Or("case_author LIKE ?", keyword)
// 执行
query = query.Where(orQuery)
}
// 排序
query = query.Order("created_at desc")
// 查询总数量
if err = query.Count(&totalRecords).Error; err != nil {
return nil, 0, err
}
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
if err != nil {
return nil, 0, err
}
return m, totalRecords, nil
}
// Inc 自增
func (r *CaseDao) Inc(tx *gorm.DB, caseId int64, field string, numeral int) error {
err := tx.Model(&model.Case{}).Where("case_id = ?", caseId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
if err != nil {
return err
}
return nil
}
// Dec 自减
func (r *CaseDao) Dec(tx *gorm.DB, caseId int64, field string, numeral int) error {
err := tx.Model(&model.Case{}).Where("case_id = ?", caseId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
if err != nil {
return err
}
return nil
}
// GetResCaseList 获取列表
func (r *CaseDao) GetResCaseList(req requests.GetResCaseList) (m []*model.Case, err error) {
// 构建查询条件
query := global.Db.Model(&model.Case{})
// 项目
projectSubQuery := global.Db.Model(&model.ProjectPlatform{}).
Where("project_platform.project_id = case.project_id").
Where("project_platform.platform_id = ?", req.PlatformId).
Where("project_platform.status = ?", 1)
query = query.Where("EXISTS (?)", projectSubQuery)
query = query.Where("case_status = ?", 1)
// 搜索关键字
if req.Keyword != "" {
keyword := "%" + req.Keyword + "%" //
// 病例名称
orQuery := global.Db.Model(&model.Case{}).Or("case_name LIKE ?", keyword)
// 作者
orQuery = orQuery.Or("case_author LIKE ?", keyword)
// 执行
query = query.Where(orQuery)
}
// 排序
query = query.Order("created_at desc")
err = query.Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

117
api/dao/CaseComment.go Normal file
View File

@ -0,0 +1,117 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseCommentDao struct {
}
// GetCaseCommentById 获取数据-id
func (r *CaseCommentDao) GetCaseCommentById(commentId int64) (m *model.CaseComment, err error) {
err = global.Db.First(&m, commentId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCommentPreloadById 获取数据-加载全部关联-id
func (r *CaseCommentDao) GetCaseCommentPreloadById(commentId int64) (m *model.CaseComment, err error) {
err = global.Db.Preload(clause.Associations).First(&m, commentId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseComment 删除
func (r *CaseCommentDao) DeleteCaseComment(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseComment{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseCommentById 删除-id
func (r *CaseCommentDao) DeleteCaseCommentById(tx *gorm.DB, commentId int64) error {
if err := tx.Delete(&model.CaseComment{}, commentId).Error; err != nil {
return err
}
return nil
}
// EditCaseComment 修改
func (r *CaseCommentDao) EditCaseComment(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseComment{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseCommentById 修改-id
func (r *CaseCommentDao) EditCaseCommentById(tx *gorm.DB, commentId int64, data interface{}) error {
err := tx.Model(&model.CaseComment{}).Where("comment_id = ?", commentId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseCommentList 获取列表
func (r *CaseCommentDao) GetCaseCommentList(maps interface{}) (m []*model.CaseComment, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCommentListLimit 获取列表-限制数量
func (r *CaseCommentDao) GetCaseCommentListLimit(maps interface{}, limit int) (m []*model.CaseComment, err error) {
err = global.Db.Where(maps).Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCommentCount 获取数量
func (r *CaseCommentDao) GetCaseCommentCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseComment{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseCommentListRand 获取列表-随机
func (r *CaseCommentDao) GetCaseCommentListRand(maps interface{}, limit int) (m []*model.CaseComment, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseComment 新增
func (r *CaseCommentDao) AddCaseComment(tx *gorm.DB, model *model.CaseComment) (*model.CaseComment, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseComment 获取
func (r *CaseCommentDao) GetCaseComment(maps interface{}) (m *model.CaseComment, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/CaseCommentLike.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseCommentLikeDao struct {
}
// GetCaseCommentLikeById 获取数据-id
func (r *CaseCommentLikeDao) GetCaseCommentLikeById(LikeId int64) (m *model.CaseCommentLike, err error) {
err = global.Db.First(&m, LikeId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCommentLikePreloadById 获取数据-加载全部关联-id
func (r *CaseCommentLikeDao) GetCaseCommentLikePreloadById(LikeId int64) (m *model.CaseCommentLike, err error) {
err = global.Db.Preload(clause.Associations).First(&m, LikeId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseCommentLike 删除
func (r *CaseCommentLikeDao) DeleteCaseCommentLike(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseCommentLike{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseCommentLikeById 删除-id
func (r *CaseCommentLikeDao) DeleteCaseCommentLikeById(tx *gorm.DB, LikeId int64) error {
if err := tx.Delete(&model.CaseCommentLike{}, LikeId).Error; err != nil {
return err
}
return nil
}
// EditCaseCommentLike 修改
func (r *CaseCommentLikeDao) EditCaseCommentLike(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseCommentLike{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseCommentLikeById 修改-id
func (r *CaseCommentLikeDao) EditCaseCommentLikeById(tx *gorm.DB, LikeId int64, data interface{}) error {
err := tx.Model(&model.CaseCommentLike{}).Where("like_id = ?", LikeId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseCommentLikeList 获取列表
func (r *CaseCommentLikeDao) GetCaseCommentLikeList(maps interface{}) (m []*model.CaseCommentLike, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseCommentLikeCount 获取数量
func (r *CaseCommentLikeDao) GetCaseCommentLikeCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseCommentLike{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseCommentLikeListRand 获取列表-随机
func (r *CaseCommentLikeDao) GetCaseCommentLikeListRand(maps interface{}, limit int) (m []*model.CaseCommentLike, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseCommentLike 新增
func (r *CaseCommentLikeDao) AddCaseCommentLike(tx *gorm.DB, model *model.CaseCommentLike) (*model.CaseCommentLike, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseCommentLike 获取
func (r *CaseCommentLikeDao) GetCaseCommentLike(maps interface{}) (m *model.CaseCommentLike, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/CaseItem.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseItemDao struct {
}
// GetCaseItemById 获取数据-id
func (r *CaseItemDao) GetCaseItemById(caseItemId int64) (m *model.CaseItem, err error) {
err = global.Db.First(&m, caseItemId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemPreloadById 获取数据-加载全部关联-id
func (r *CaseItemDao) GetCaseItemPreloadById(caseItemId int64) (m *model.CaseItem, err error) {
err = global.Db.Preload(clause.Associations).First(&m, caseItemId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseItem 删除
func (r *CaseItemDao) DeleteCaseItem(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseItem{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseItemById 删除-id
func (r *CaseItemDao) DeleteCaseItemById(tx *gorm.DB, caseItemId int64) error {
if err := tx.Delete(&model.CaseItem{}, caseItemId).Error; err != nil {
return err
}
return nil
}
// EditCaseItem 修改
func (r *CaseItemDao) EditCaseItem(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseItem{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseItemById 修改-id
func (r *CaseItemDao) EditCaseItemById(tx *gorm.DB, caseItemId int64, data interface{}) error {
err := tx.Model(&model.CaseItem{}).Where("case_item_id = ?", caseItemId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseItemList 获取列表
func (r *CaseItemDao) GetCaseItemList(maps interface{}) (m []*model.CaseItem, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemCount 获取数量
func (r *CaseItemDao) GetCaseItemCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseItem{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseItemListRand 获取列表-随机
func (r *CaseItemDao) GetCaseItemListRand(maps interface{}, limit int) (m []*model.CaseItem, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseItem 新增
func (r *CaseItemDao) AddCaseItem(tx *gorm.DB, model *model.CaseItem) (*model.CaseItem, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseItem 获取
func (r *CaseItemDao) GetCaseItem(maps interface{}) (m *model.CaseItem, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/CaseItemQuestion.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseItemQuestionDao struct {
}
// GetCaseItemQuestionById 获取数据-id
func (r *CaseItemQuestionDao) GetCaseItemQuestionById(questionId int64) (m *model.CaseItemQuestion, err error) {
err = global.Db.First(&m, questionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemQuestionPreloadById 获取数据-加载全部关联-id
func (r *CaseItemQuestionDao) GetCaseItemQuestionPreloadById(questionId int64) (m *model.CaseItemQuestion, err error) {
err = global.Db.Preload(clause.Associations).First(&m, questionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseItemQuestion 删除
func (r *CaseItemQuestionDao) DeleteCaseItemQuestion(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseItemQuestion{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseItemQuestionById 删除-id
func (r *CaseItemQuestionDao) DeleteCaseItemQuestionById(tx *gorm.DB, questionId int64) error {
if err := tx.Delete(&model.CaseItemQuestion{}, questionId).Error; err != nil {
return err
}
return nil
}
// EditCaseItemQuestion 修改
func (r *CaseItemQuestionDao) EditCaseItemQuestion(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseItemQuestion{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseItemQuestionById 修改-id
func (r *CaseItemQuestionDao) EditCaseItemQuestionById(tx *gorm.DB, questionId int64, data interface{}) error {
err := tx.Model(&model.CaseItemQuestion{}).Where("question_id = ?", questionId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseItemQuestionList 获取列表
func (r *CaseItemQuestionDao) GetCaseItemQuestionList(maps interface{}) (m []*model.CaseItemQuestion, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemQuestionCount 获取数量
func (r *CaseItemQuestionDao) GetCaseItemQuestionCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseItemQuestion{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseItemQuestionListRand 获取列表-随机
func (r *CaseItemQuestionDao) GetCaseItemQuestionListRand(maps interface{}, limit int) (m []*model.CaseItemQuestion, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseItemQuestion 新增
func (r *CaseItemQuestionDao) AddCaseItemQuestion(tx *gorm.DB, model *model.CaseItemQuestion) (*model.CaseItemQuestion, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseItemQuestion 获取
func (r *CaseItemQuestionDao) GetCaseItemQuestion(maps interface{}) (m *model.CaseItemQuestion, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseItemQuestionOptionDao struct {
}
// GetCaseItemQuestionOptionById 获取数据-id
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOptionById(optionId int64) (m *model.CaseItemQuestionOption, err error) {
err = global.Db.First(&m, optionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemQuestionOptionPreloadById 获取数据-加载全部关联-id
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOptionPreloadById(optionId int64) (m *model.CaseItemQuestionOption, err error) {
err = global.Db.Preload(clause.Associations).First(&m, optionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseItemQuestionOption 删除
func (r *CaseItemQuestionOptionDao) DeleteCaseItemQuestionOption(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseItemQuestionOption{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseItemQuestionOptionById 删除-id
func (r *CaseItemQuestionOptionDao) DeleteCaseItemQuestionOptionById(tx *gorm.DB, optionId int64) error {
if err := tx.Delete(&model.CaseItemQuestionOption{}, optionId).Error; err != nil {
return err
}
return nil
}
// EditCaseItemQuestionOption 修改
func (r *CaseItemQuestionOptionDao) EditCaseItemQuestionOption(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseItemQuestionOption{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseItemQuestionOptionById 修改-id
func (r *CaseItemQuestionOptionDao) EditCaseItemQuestionOptionById(tx *gorm.DB, optionId int64, data interface{}) error {
err := tx.Model(&model.CaseItemQuestionOption{}).Where("option_id = ?", optionId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseItemQuestionOptionList 获取列表
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOptionList(maps interface{}) (m []*model.CaseItemQuestionOption, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseItemQuestionOptionCount 获取数量
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOptionCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseItemQuestionOption{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseItemQuestionOptionListRand 获取列表-随机
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOptionListRand(maps interface{}, limit int) (m []*model.CaseItemQuestionOption, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseItemQuestionOption 新增
func (r *CaseItemQuestionOptionDao) AddCaseItemQuestionOption(tx *gorm.DB, model *model.CaseItemQuestionOption) (*model.CaseItemQuestionOption, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseItemQuestionOption 获取
func (r *CaseItemQuestionOptionDao) GetCaseItemQuestionOption(maps interface{}) (m *model.CaseItemQuestionOption, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

126
api/dao/CasePlatform.go Normal file
View File

@ -0,0 +1,126 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CasePlatformDao struct {
}
// GetCasePlatformById 获取数据-id
func (r *CasePlatformDao) GetCasePlatformById(casePlatformId int64) (m *model.CasePlatform, err error) {
err = global.Db.First(&m, casePlatformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCasePlatformPreloadById 获取数据-加载全部关联-id
func (r *CasePlatformDao) GetCasePlatformPreloadById(casePlatformId int64) (m *model.CasePlatform, err error) {
err = global.Db.Preload(clause.Associations).First(&m, casePlatformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCasePlatform 删除
func (r *CasePlatformDao) DeleteCasePlatform(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CasePlatform{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCasePlatformById 删除-id
func (r *CasePlatformDao) DeleteCasePlatformById(tx *gorm.DB, casePlatformId int64) error {
if err := tx.Delete(&model.CasePlatform{}, casePlatformId).Error; err != nil {
return err
}
return nil
}
// EditCasePlatform 修改
func (r *CasePlatformDao) EditCasePlatform(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CasePlatform{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCasePlatformById 修改-id
func (r *CasePlatformDao) EditCasePlatformById(tx *gorm.DB, casePlatformId int64, data interface{}) error {
err := tx.Model(&model.CasePlatform{}).Where("case_platform_id = ?", casePlatformId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCasePlatformList 获取列表
func (r *CasePlatformDao) GetCasePlatformList(maps interface{}) (m []*model.CasePlatform, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCasePlatformCount 获取数量
func (r *CasePlatformDao) GetCasePlatformCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CasePlatform{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCasePlatformListRand 获取列表-随机
func (r *CasePlatformDao) GetCasePlatformListRand(maps interface{}, limit int) (m []*model.CasePlatform, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCasePlatform 新增
func (r *CasePlatformDao) AddCasePlatform(tx *gorm.DB, model *model.CasePlatform) (*model.CasePlatform, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCasePlatform 获取
func (r *CasePlatformDao) GetCasePlatform(maps interface{}) (m *model.CasePlatform, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// Inc 自增
func (r *CasePlatformDao) Inc(tx *gorm.DB, caseId int64, field string, numeral int) error {
err := tx.Model(&model.CasePlatform{}).Where("case_platform_id = ?", caseId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
if err != nil {
return err
}
return nil
}
// Dec 自减
func (r *CasePlatformDao) Dec(tx *gorm.DB, caseId int64, field string, numeral int) error {
err := tx.Model(&model.CasePlatform{}).Where("case_platform_id = ?", caseId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
if err != nil {
return err
}
return nil
}

146
api/dao/CaseUser.go Normal file
View File

@ -0,0 +1,146 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/api/requests"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CaseUserDao struct {
}
// GetCaseUserById 获取数据-id
func (r *CaseUserDao) GetCaseUserById(caseUserId int64) (m *model.CaseUser, err error) {
err = global.Db.First(&m, caseUserId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseUserPreloadById 获取数据-加载全部关联-id
func (r *CaseUserDao) GetCaseUserPreloadById(caseUserId int64) (m *model.CaseUser, err error) {
err = global.Db.Preload(clause.Associations).First(&m, caseUserId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteCaseUser 删除
func (r *CaseUserDao) DeleteCaseUser(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.CaseUser{}).Error
if err != nil {
return err
}
return nil
}
// DeleteCaseUserById 删除-id
func (r *CaseUserDao) DeleteCaseUserById(tx *gorm.DB, caseUserId int64) error {
if err := tx.Delete(&model.CaseUser{}, caseUserId).Error; err != nil {
return err
}
return nil
}
// EditCaseUser 修改
func (r *CaseUserDao) EditCaseUser(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.CaseUser{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditCaseUserById 修改-id
func (r *CaseUserDao) EditCaseUserById(tx *gorm.DB, caseUserId int64, data interface{}) error {
err := tx.Model(&model.CaseUser{}).Where("case_user_id = ?", caseUserId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetCaseUserList 获取列表
func (r *CaseUserDao) GetCaseUserList(maps interface{}) (m []*model.CaseUser, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseUserCount 获取数量
func (r *CaseUserDao) GetCaseUserCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.CaseUser{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetCaseUserListRand 获取列表-随机
func (r *CaseUserDao) GetCaseUserListRand(maps interface{}, limit int) (m []*model.CaseUser, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddCaseUser 新增
func (r *CaseUserDao) AddCaseUser(tx *gorm.DB, model *model.CaseUser) (*model.CaseUser, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetCaseUser 获取
func (r *CaseUserDao) GetCaseUser(maps interface{}) (m *model.CaseUser, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetCaseUserRecordList 病例领取记录
func (r *CaseUserDao) GetCaseUserRecordList(req requests.GetResCaseRecordList, page, pageSize int) (m []*model.CaseUser, total int64, err error) {
var totalRecords int64
// 构建查询条件
query := global.Db.Model(&model.CaseUser{})
query = query.Preload("Case")
query = query.Preload("User")
query = query.Preload("User.Hospital")
// 项目id
subQuery := global.Db.Model(&model.Case{}).
Select("case_id").
Where("project_id = ?", req.ProjectId)
query = query.Where(gorm.Expr("case_id IN (?)", subQuery))
// 时间
if req.StartTime != "" && req.EndTime != "" {
query = query.Where("created_at BETWEEN ? AND ?", req.StartTime, req.EndTime)
}
// 排序
query = query.Order("created_at desc")
// 查询总数量
if err := query.Count(&totalRecords).Error; err != nil {
return nil, 0, err
}
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
if err != nil {
return nil, 0, err
}
return m, totalRecords, nil
}

108
api/dao/Platform.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type PlatformDao struct {
}
// GetPlatformById 获取数据-id
func (r *PlatformDao) GetPlatformById(platformId int64) (m *model.Platform, err error) {
err = global.Db.First(&m, platformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetPlatformPreloadById 获取数据-加载全部关联-id
func (r *PlatformDao) GetPlatformPreloadById(platformId int64) (m *model.Platform, err error) {
err = global.Db.Preload(clause.Associations).First(&m, platformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeletePlatform 删除
func (r *PlatformDao) DeletePlatform(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.Platform{}).Error
if err != nil {
return err
}
return nil
}
// DeletePlatformById 删除-id
func (r *PlatformDao) DeletePlatformById(tx *gorm.DB, platformId int64) error {
if err := tx.Delete(&model.Platform{}, platformId).Error; err != nil {
return err
}
return nil
}
// EditPlatform 修改
func (r *PlatformDao) EditPlatform(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.Platform{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditPlatformById 修改-id
func (r *PlatformDao) EditPlatformById(tx *gorm.DB, platformId int64, data interface{}) error {
err := tx.Model(&model.Platform{}).Where("platform_id = ?", platformId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetPlatformList 获取列表
func (r *PlatformDao) GetPlatformList(maps interface{}) (m []*model.Platform, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetPlatformCount 获取数量
func (r *PlatformDao) GetPlatformCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.Platform{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetPlatformListRand 获取列表-随机
func (r *PlatformDao) GetPlatformListRand(maps interface{}, limit int) (m []*model.Platform, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddPlatform 新增
func (r *PlatformDao) AddPlatform(tx *gorm.DB, model *model.Platform) (*model.Platform, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetPlatform 获取
func (r *PlatformDao) GetPlatform(maps interface{}) (m *model.Platform, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

174
api/dao/Project.go Normal file
View File

@ -0,0 +1,174 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/api/requests"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectDao struct {
}
// GetProjectById 获取数据-id
func (r *ProjectDao) GetProjectById(projectId int64) (m *model.Project, err error) {
err = global.Db.First(&m, projectId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPreloadById 获取数据-加载全部关联-id
func (r *ProjectDao) GetProjectPreloadById(projectId int64) (m *model.Project, err error) {
err = global.Db.Preload(clause.Associations).First(&m, projectId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProject 删除
func (r *ProjectDao) DeleteProject(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.Project{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectById 删除-id
func (r *ProjectDao) DeleteProjectById(tx *gorm.DB, projectId int64) error {
if err := tx.Delete(&model.Project{}, projectId).Error; err != nil {
return err
}
return nil
}
// EditProject 修改
func (r *ProjectDao) EditProject(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.Project{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectById 修改-id
func (r *ProjectDao) EditProjectById(tx *gorm.DB, projectId int64, data interface{}) error {
err := tx.Model(&model.Project{}).Where("project_id = ?", projectId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectList 获取列表
func (r *ProjectDao) GetProjectList(maps interface{}) (m []*model.Project, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectCount 获取数量
func (r *ProjectDao) GetProjectCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.Project{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectListRand 获取列表-随机
func (r *ProjectDao) GetProjectListRand(maps interface{}, limit int) (m []*model.Project, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProject 新增
func (r *ProjectDao) AddProject(tx *gorm.DB, model *model.Project) (*model.Project, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProject 获取
func (r *ProjectDao) GetProject(maps interface{}) (m *model.Project, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPageSearch 获取列表-分页
func (r *ProjectDao) GetProjectPageSearch(req requests.GetProjectPage, page, pageSize int) (m []*model.Project, total int64, err error) {
var totalRecords int64
// 构建查询条件
query := global.Db.Model(&model.Project{})
// 状态固定为1
query = query.Where("project_status = ?", 1)
query = query.Preload("Case")
if req.PlatformId != 0 {
subQuery := global.Db.Model(&model.ProjectPlatform{}).
Where("project_platform.project_id = project.project_id").
Where("project_platform.platform_id = ?", req.PlatformId).
Where("project_platform.status = ?", 1)
query = query.Where("EXISTS (?)", subQuery)
}
// 排序
query = query.Order("created_at desc")
// 查询总数量
if err := query.Count(&totalRecords).Error; err != nil {
return nil, 0, err
}
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
if err != nil {
return nil, 0, err
}
return m, totalRecords, nil
}
// GetResProjectListSearch 获取列表
func (r *ProjectDao) GetResProjectListSearch(req requests.GetResProjectList) (m []*model.Project, err error) {
// 构建查询条件
query := global.Db.Model(&model.Project{})
// 状态固定为1
query = query.Where("project_status = ?", 1)
query = query.Preload("Case")
if req.PlatformId != 0 {
subQuery := global.Db.Model(&model.ProjectPlatform{}).
Where("project_platform.project_id = project.project_id").
Where("project_platform.platform_id = ?", req.PlatformId).
Where("project_platform.status = ?", 1)
query = query.Where("EXISTS (?)", subQuery)
}
// 排序
query = query.Order("created_at desc")
err = query.Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/ProjectPlatform.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformDao struct {
}
// GetProjectPlatformById 获取数据-id
func (r *ProjectPlatformDao) GetProjectPlatformById(ProjectPlatformId int64) (m *model.ProjectPlatform, err error) {
err = global.Db.First(&m, ProjectPlatformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformDao) GetProjectPlatformPreloadById(ProjectPlatformId int64) (m *model.ProjectPlatform, err error) {
err = global.Db.Preload(clause.Associations).First(&m, ProjectPlatformId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatform 删除
func (r *ProjectPlatformDao) DeleteProjectPlatform(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatform{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformById 删除-id
func (r *ProjectPlatformDao) DeleteProjectPlatformById(tx *gorm.DB, ProjectPlatformId int64) error {
if err := tx.Delete(&model.ProjectPlatform{}, ProjectPlatformId).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatform 修改
func (r *ProjectPlatformDao) EditProjectPlatform(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatform{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformById 修改-id
func (r *ProjectPlatformDao) EditProjectPlatformById(tx *gorm.DB, ProjectPlatformId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatform{}).Where("project_platform_id = ?", ProjectPlatformId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformList 获取列表
func (r *ProjectPlatformDao) GetProjectPlatformList(maps interface{}) (m []*model.ProjectPlatform, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformCount 获取数量
func (r *ProjectPlatformDao) GetProjectPlatformCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatform{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformListRand 获取列表-随机
func (r *ProjectPlatformDao) GetProjectPlatformListRand(maps interface{}, limit int) (m []*model.ProjectPlatform, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatform 新增
func (r *ProjectPlatformDao) AddProjectPlatform(tx *gorm.DB, model *model.ProjectPlatform) (*model.ProjectPlatform, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatform 获取
func (r *ProjectPlatformDao) GetProjectPlatform(maps interface{}) (m *model.ProjectPlatform, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformAreaDao struct {
}
// GetProjectPlatformAreaById 获取数据-id
func (r *ProjectPlatformAreaDao) GetProjectPlatformAreaById(whiteAreaId int64) (m *model.ProjectPlatformArea, err error) {
err = global.Db.First(&m, whiteAreaId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformAreaPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformAreaDao) GetProjectPlatformAreaPreloadById(whiteAreaId int64) (m *model.ProjectPlatformArea, err error) {
err = global.Db.Preload(clause.Associations).First(&m, whiteAreaId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformArea 删除
func (r *ProjectPlatformAreaDao) DeleteProjectPlatformArea(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformArea{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformAreaById 删除-id
func (r *ProjectPlatformAreaDao) DeleteProjectPlatformAreaById(tx *gorm.DB, whiteAreaId int64) error {
if err := tx.Delete(&model.ProjectPlatformArea{}, whiteAreaId).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformArea 修改
func (r *ProjectPlatformAreaDao) EditProjectPlatformArea(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformArea{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformAreaById 修改-id
func (r *ProjectPlatformAreaDao) EditProjectPlatformAreaById(tx *gorm.DB, whiteAreaId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformArea{}).Where("white_area_id = ?", whiteAreaId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformAreaList 获取列表
func (r *ProjectPlatformAreaDao) GetProjectPlatformAreaList(maps interface{}) (m []*model.ProjectPlatformArea, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformAreaCount 获取数量
func (r *ProjectPlatformAreaDao) GetProjectPlatformAreaCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformArea{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformAreaListRand 获取列表-随机
func (r *ProjectPlatformAreaDao) GetProjectPlatformAreaListRand(maps interface{}, limit int) (m []*model.ProjectPlatformArea, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformArea 新增
func (r *ProjectPlatformAreaDao) AddProjectPlatformArea(tx *gorm.DB, model *model.ProjectPlatformArea) (*model.ProjectPlatformArea, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformArea 获取
func (r *ProjectPlatformAreaDao) GetProjectPlatformArea(maps interface{}) (m *model.ProjectPlatformArea, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,116 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformDoctorDao struct {
}
// GetProjectPlatformDoctorById 获取数据-id
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctorById(whiteDoctorId int64) (m *model.ProjectPlatformDoctor, err error) {
err = global.Db.First(&m, whiteDoctorId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDoctorPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctorPreloadById(whiteDoctorId int64) (m *model.ProjectPlatformDoctor, err error) {
err = global.Db.Preload(clause.Associations).First(&m, whiteDoctorId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformDoctor 删除
func (r *ProjectPlatformDoctorDao) DeleteProjectPlatformDoctor(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformDoctor{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDoctorById 删除-id
func (r *ProjectPlatformDoctorDao) DeleteProjectPlatformDoctorById(tx *gorm.DB, whiteDoctorId int64) error {
if err := tx.Delete(&model.ProjectPlatformDoctor{}, whiteDoctorId).Error; err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDoctorByPlatformId 删除-id
func (r *ProjectPlatformDoctorDao) DeleteProjectPlatformDoctorByPlatformId(tx *gorm.DB, platformId int64) error {
if err := tx.Where("platform_id = ?", platformId).Delete(&model.ProjectPlatformDoctor{}).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformDoctor 修改
func (r *ProjectPlatformDoctorDao) EditProjectPlatformDoctor(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDoctor{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformDoctorById 修改-id
func (r *ProjectPlatformDoctorDao) EditProjectPlatformDoctorById(tx *gorm.DB, whiteDoctorId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDoctor{}).Where("white_doctor_id = ?", whiteDoctorId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformDoctorList 获取列表
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctorList(maps interface{}) (m []*model.ProjectPlatformDoctor, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDoctorCount 获取数量
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctorCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformDoctor{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformDoctorListRand 获取列表-随机
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctorListRand(maps interface{}, limit int) (m []*model.ProjectPlatformDoctor, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformDoctor 新增
func (r *ProjectPlatformDoctorDao) AddProjectPlatformDoctor(tx *gorm.DB, model *model.ProjectPlatformDoctor) (*model.ProjectPlatformDoctor, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformDoctor 获取
func (r *ProjectPlatformDoctorDao) GetProjectPlatformDoctor(maps interface{}) (m *model.ProjectPlatformDoctor, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,134 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformDynamicDao struct {
}
// GetProjectPlatformDynamicById 获取数据-id
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicById(whiteDynamicId int64) (m *model.ProjectPlatformDynamic, err error) {
err = global.Db.First(&m, whiteDynamicId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicPreloadById(whiteDynamicId int64) (m *model.ProjectPlatformDynamic, err error) {
err = global.Db.Preload(clause.Associations).First(&m, whiteDynamicId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicListByWhiteDynamicId 获取数据-whiteDynamicId
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicListByWhiteDynamicId(platformId int64) (m []*model.ProjectPlatformDynamic, err error) {
err = global.Db.Where("platform_id = ?", platformId).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformDynamic 删除
func (r *ProjectPlatformDynamicDao) DeleteProjectPlatformDynamic(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformDynamic{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDynamicById 删除-id
func (r *ProjectPlatformDynamicDao) DeleteProjectPlatformDynamicById(tx *gorm.DB, whiteDynamicId int64) error {
if err := tx.Delete(&model.ProjectPlatformDynamic{}, whiteDynamicId).Error; err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDynamicByPlatformId 删除-id
func (r *ProjectPlatformDynamicDao) DeleteProjectPlatformDynamicByPlatformId(tx *gorm.DB, platformId int64) error {
if err := tx.Where("platform_id = ?", platformId).Delete(&model.ProjectPlatformDynamic{}).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformDynamic 修改
func (r *ProjectPlatformDynamicDao) EditProjectPlatformDynamic(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDynamic{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformDynamicById 修改-id
func (r *ProjectPlatformDynamicDao) EditProjectPlatformDynamicById(tx *gorm.DB, whiteDynamicId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDynamic{}).Where("white_dynamic_id = ?", whiteDynamicId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformDynamicList 获取列表
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicList(maps interface{}) (m []*model.ProjectPlatformDynamic, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicPreloadList 获取列表
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicPreloadList(maps interface{}) (m []*model.ProjectPlatformDynamic, err error) {
err = global.Db.Preload(clause.Associations).Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicCount 获取数量
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformDynamic{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformDynamicListRand 获取列表-随机
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamicListRand(maps interface{}, limit int) (m []*model.ProjectPlatformDynamic, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformDynamic 新增
func (r *ProjectPlatformDynamicDao) AddProjectPlatformDynamic(tx *gorm.DB, model *model.ProjectPlatformDynamic) (*model.ProjectPlatformDynamic, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformDynamic 获取
func (r *ProjectPlatformDynamicDao) GetProjectPlatformDynamic(maps interface{}) (m *model.ProjectPlatformDynamic, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,125 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformDynamicItemDao struct {
}
// GetProjectPlatformDynamicItemById 获取数据-id
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemById(itemId int64) (m *model.ProjectPlatformDynamicItem, err error) {
err = global.Db.First(&m, itemId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicItemPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemPreloadById(itemId int64) (m *model.ProjectPlatformDynamicItem, err error) {
err = global.Db.Preload(clause.Associations).First(&m, itemId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicItemListByWhiteDynamicId 获取数据-whiteDynamicId
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemListByWhiteDynamicId(whiteDynamicId int64) (m []*model.ProjectPlatformDynamicItem, err error) {
err = global.Db.Where("white_dynamic_id = ?", whiteDynamicId).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformDynamicItem 删除
func (r *ProjectPlatformDynamicItemDao) DeleteProjectPlatformDynamicItem(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformDynamicItem{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDynamicItemById 删除-id
func (r *ProjectPlatformDynamicItemDao) DeleteProjectPlatformDynamicItemById(tx *gorm.DB, whiteGradeId int64) error {
if err := tx.Delete(&model.ProjectPlatformDynamicItem{}, whiteGradeId).Error; err != nil {
return err
}
return nil
}
// DeleteProjectPlatformDynamicItemByWhiteDynamicId 删除-id
func (r *ProjectPlatformDynamicItemDao) DeleteProjectPlatformDynamicItemByWhiteDynamicId(tx *gorm.DB, whiteDynamicId int64) error {
if err := tx.Where("white_dynamic_id = ?", whiteDynamicId).Delete(&model.ProjectPlatformDynamicItem{}).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformDynamicItem 修改
func (r *ProjectPlatformDynamicItemDao) EditProjectPlatformDynamicItem(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDynamicItem{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformDynamicItemById 修改-id
func (r *ProjectPlatformDynamicItemDao) EditProjectPlatformDynamicItemById(tx *gorm.DB, itemId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformDynamicItem{}).Where("item_id = ?", itemId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformDynamicItemList 获取列表
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemList(maps interface{}) (m []*model.ProjectPlatformDynamicItem, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformDynamicItemCount 获取数量
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformDynamicItem{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformDynamicItemListRand 获取列表-随机
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItemListRand(maps interface{}, limit int) (m []*model.ProjectPlatformDynamicItem, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformDynamicItem 新增
func (r *ProjectPlatformDynamicItemDao) AddProjectPlatformDynamicItem(tx *gorm.DB, model *model.ProjectPlatformDynamicItem) (*model.ProjectPlatformDynamicItem, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformDynamicItem 获取
func (r *ProjectPlatformDynamicItemDao) GetProjectPlatformDynamicItem(maps interface{}) (m *model.ProjectPlatformDynamicItem, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformGradeDao struct {
}
// GetProjectPlatformGradeById 获取数据-id
func (r *ProjectPlatformGradeDao) GetProjectPlatformGradeById(whiteGradeId int64) (m *model.ProjectPlatformGrade, err error) {
err = global.Db.First(&m, whiteGradeId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformGradePreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformGradeDao) GetProjectPlatformGradePreloadById(whiteGradeId int64) (m *model.ProjectPlatformGrade, err error) {
err = global.Db.Preload(clause.Associations).First(&m, whiteGradeId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformGrade 删除
func (r *ProjectPlatformGradeDao) DeleteProjectPlatformGrade(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformGrade{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformGradeById 删除-id
func (r *ProjectPlatformGradeDao) DeleteProjectPlatformGradeById(tx *gorm.DB, whiteGradeId int64) error {
if err := tx.Delete(&model.ProjectPlatformGrade{}, whiteGradeId).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformGrade 修改
func (r *ProjectPlatformGradeDao) EditProjectPlatformGrade(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformGrade{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformGradeById 修改-id
func (r *ProjectPlatformGradeDao) EditProjectPlatformGradeById(tx *gorm.DB, whiteGradeId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformGrade{}).Where("white_grade_id = ?", whiteGradeId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformGradeList 获取列表
func (r *ProjectPlatformGradeDao) GetProjectPlatformGradeList(maps interface{}) (m []*model.ProjectPlatformGrade, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformGradeCount 获取数量
func (r *ProjectPlatformGradeDao) GetProjectPlatformGradeCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformGrade{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformGradeListRand 获取列表-随机
func (r *ProjectPlatformGradeDao) GetProjectPlatformGradeListRand(maps interface{}, limit int) (m []*model.ProjectPlatformGrade, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformGrade 新增
func (r *ProjectPlatformGradeDao) AddProjectPlatformGrade(tx *gorm.DB, model *model.ProjectPlatformGrade) (*model.ProjectPlatformGrade, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformGrade 获取
func (r *ProjectPlatformGradeDao) GetProjectPlatformGrade(maps interface{}) (m *model.ProjectPlatformGrade, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,116 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type ProjectPlatformHospitalDao struct {
}
// GetProjectPlatformHospitalById 获取数据-id
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospitalById(whiteHospitalId int64) (m *model.ProjectPlatformHospital, err error) {
err = global.Db.First(&m, whiteHospitalId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformHospitalPreloadById 获取数据-加载全部关联-id
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospitalPreloadById(whiteHospitalId int64) (m *model.ProjectPlatformHospital, err error) {
err = global.Db.Preload(clause.Associations).First(&m, whiteHospitalId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteProjectPlatformHospital 删除
func (r *ProjectPlatformHospitalDao) DeleteProjectPlatformHospital(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.ProjectPlatformHospital{}).Error
if err != nil {
return err
}
return nil
}
// DeleteProjectPlatformHospitalById 删除-id
func (r *ProjectPlatformHospitalDao) DeleteProjectPlatformHospitalById(tx *gorm.DB, whiteHospitalId int64) error {
if err := tx.Delete(&model.ProjectPlatformHospital{}, whiteHospitalId).Error; err != nil {
return err
}
return nil
}
// DeleteProjectPlatformHospitalByPlatformId 删除-id
func (r *ProjectPlatformHospitalDao) DeleteProjectPlatformHospitalByPlatformId(tx *gorm.DB, platformId int64) error {
if err := tx.Where("platform_id = ?", platformId).Delete(&model.ProjectPlatformHospital{}).Error; err != nil {
return err
}
return nil
}
// EditProjectPlatformHospital 修改
func (r *ProjectPlatformHospitalDao) EditProjectPlatformHospital(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.ProjectPlatformHospital{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditProjectPlatformHospitalById 修改-id
func (r *ProjectPlatformHospitalDao) EditProjectPlatformHospitalById(tx *gorm.DB, whiteHospitalId int64, data interface{}) error {
err := tx.Model(&model.ProjectPlatformHospital{}).Where("white_hospital_id = ?", whiteHospitalId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetProjectPlatformHospitalList 获取列表
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospitalList(maps interface{}) (m []*model.ProjectPlatformHospital, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetProjectPlatformHospitalCount 获取数量
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospitalCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.ProjectPlatformHospital{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetProjectPlatformHospitalListRand 获取列表-随机
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospitalListRand(maps interface{}, limit int) (m []*model.ProjectPlatformHospital, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddProjectPlatformHospital 新增
func (r *ProjectPlatformHospitalDao) AddProjectPlatformHospital(tx *gorm.DB, model *model.ProjectPlatformHospital) (*model.ProjectPlatformHospital, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetProjectPlatformHospital 获取
func (r *ProjectPlatformHospitalDao) GetProjectPlatformHospital(maps interface{}) (m *model.ProjectPlatformHospital, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/RecordScore.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type RecordScoreDao struct {
}
// GetRecordScoreById 获取数据-id
func (r *RecordScoreDao) GetRecordScoreById(scoreId int64) (m *model.RecordScore, err error) {
err = global.Db.First(&m, scoreId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetRecordScorePreloadById 获取数据-加载全部关联-id
func (r *RecordScoreDao) GetRecordScorePreloadById(scoreId int64) (m *model.RecordScore, err error) {
err = global.Db.Preload(clause.Associations).First(&m, scoreId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteRecordScore 删除
func (r *RecordScoreDao) DeleteRecordScore(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.RecordScore{}).Error
if err != nil {
return err
}
return nil
}
// DeleteRecordScoreById 删除-id
func (r *RecordScoreDao) DeleteRecordScoreById(tx *gorm.DB, scoreId int64) error {
if err := tx.Delete(&model.RecordScore{}, scoreId).Error; err != nil {
return err
}
return nil
}
// EditRecordScore 修改
func (r *RecordScoreDao) EditRecordScore(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.RecordScore{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditRecordScoreById 修改-id
func (r *RecordScoreDao) EditRecordScoreById(tx *gorm.DB, scoreId int64, data interface{}) error {
err := tx.Model(&model.RecordScore{}).Where("score_id = ?", scoreId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetRecordScoreList 获取列表
func (r *RecordScoreDao) GetRecordScoreList(maps interface{}) (m []*model.RecordScore, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetRecordScoreCount 获取数量
func (r *RecordScoreDao) GetRecordScoreCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.RecordScore{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetRecordScoreListRand 获取列表-随机
func (r *RecordScoreDao) GetRecordScoreListRand(maps interface{}, limit int) (m []*model.RecordScore, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddRecordScore 新增
func (r *RecordScoreDao) AddRecordScore(tx *gorm.DB, model *model.RecordScore) (*model.RecordScore, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetRecordScore 获取
func (r *RecordScoreDao) GetRecordScore(maps interface{}) (m *model.RecordScore, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

108
api/dao/User.go Normal file
View File

@ -0,0 +1,108 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type UserDao struct {
}
// GetUserById 获取数据-id
func (r *UserDao) GetUserById(userId int64) (m *model.User, err error) {
err = global.Db.First(&m, userId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetUserPreloadById 获取数据-加载全部关联-id
func (r *UserDao) GetUserPreloadById(userId int64) (m *model.User, err error) {
err = global.Db.Preload(clause.Associations).First(&m, userId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteUser 删除
func (r *UserDao) DeleteUser(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.User{}).Error
if err != nil {
return err
}
return nil
}
// DeleteUserById 删除-id
func (r *UserDao) DeleteUserById(tx *gorm.DB, userId int64) error {
if err := tx.Delete(&model.User{}, userId).Error; err != nil {
return err
}
return nil
}
// EditUser 修改
func (r *UserDao) EditUser(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.User{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditUserById 修改-id
func (r *UserDao) EditUserById(tx *gorm.DB, userId int64, data interface{}) error {
err := tx.Model(&model.User{}).Where("user_id = ?", userId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetUserList 获取列表
func (r *UserDao) GetUserList(maps interface{}) (m []*model.User, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetUserCount 获取数量
func (r *UserDao) GetUserCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.User{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetUserListRand 获取列表-随机
func (r *UserDao) GetUserListRand(maps interface{}, limit int) (m []*model.User, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddUser 新增
func (r *UserDao) AddUser(tx *gorm.DB, model *model.User) (*model.User, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetUser 获取
func (r *UserDao) GetUser(maps interface{}) (m *model.User, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -0,0 +1,117 @@
package dao
import (
"case-open-api/api/model"
"case-open-api/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type UserAnswerRecordsDao struct {
}
// GetUserAnswerRecordsById 获取数据-id
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsById(CaseUserQuestionId int64) (m *model.UserAnswerRecords, err error) {
err = global.Db.First(&m, CaseUserQuestionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetUserAnswerRecordsPreloadById 获取数据-加载全部关联-id
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsPreloadById(CaseUserQuestionId int64) (m *model.UserAnswerRecords, err error) {
err = global.Db.Preload(clause.Associations).First(&m, CaseUserQuestionId).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteUserAnswerRecords 删除
func (r *UserAnswerRecordsDao) DeleteUserAnswerRecords(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.UserAnswerRecords{}).Error
if err != nil {
return err
}
return nil
}
// DeleteUserAnswerRecordsById 删除-id
func (r *UserAnswerRecordsDao) DeleteUserAnswerRecordsById(tx *gorm.DB, CaseUserQuestionId int64) error {
if err := tx.Delete(&model.UserAnswerRecords{}, CaseUserQuestionId).Error; err != nil {
return err
}
return nil
}
// EditUserAnswerRecords 修改
func (r *UserAnswerRecordsDao) EditUserAnswerRecords(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.UserAnswerRecords{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditUserAnswerRecordsById 修改-id
func (r *UserAnswerRecordsDao) EditUserAnswerRecordsById(tx *gorm.DB, CaseUserQuestionId int64, data interface{}) error {
err := tx.Model(&model.UserAnswerRecords{}).Where("case_user_question_id = ?", CaseUserQuestionId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetUserAnswerRecordsList 获取列表
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsList(maps interface{}) (m []*model.UserAnswerRecords, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetUserAnswerRecordsPreloadList 获取列表
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsPreloadList(maps interface{}) (m []*model.UserAnswerRecords, err error) {
err = global.Db.Preload(clause.Associations).Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetUserAnswerRecordsCount 获取数量
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsCount(maps interface{}) (total int64, err error) {
err = global.Db.Model(&model.UserAnswerRecords{}).Where(maps).Count(&total).Error
if err != nil {
return 0, err
}
return total, nil
}
// GetUserAnswerRecordsListRand 获取列表-随机
func (r *UserAnswerRecordsDao) GetUserAnswerRecordsListRand(maps interface{}, limit int) (m []*model.UserAnswerRecords, err error) {
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddUserAnswerRecords 新增
func (r *UserAnswerRecordsDao) AddUserAnswerRecords(tx *gorm.DB, model *model.UserAnswerRecords) (*model.UserAnswerRecords, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetUserAnswerRecords 获取
func (r *UserAnswerRecordsDao) GetUserAnswerRecords(maps interface{}) (m *model.UserAnswerRecords, err error) {
err = global.Db.Where(maps).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

75
api/dto/AdminUser.go Normal file
View File

@ -0,0 +1,75 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/utils"
"fmt"
)
// AdminUserDto 后台-用户表
type AdminUserDto struct {
UserId string `json:"user_id"` // 主键id
Access string `json:"access"` // 账号
Password string `json:"password"` // 密码
Salt string `json:"salt"` // 密码掩码
NickName string `json:"nick_name"` // 昵称
IsAdmin int `json:"is_admin"` // 是否管理员0:否 1:是)
Status int `json:"status"` // 状态1:正常 2:审核中 3:审核失败)
IsDeleted int `json:"is_deleted"` // 是否被删除0:否 1:是)
IsDisabled int `json:"is_disabled"` // 是否被禁用0:否 1:是)
Phone string `json:"phone"` // 手机号
Avatar string `json:"avatar"` // 头像
Sex int `json:"sex"` // 性别1:男 2:女)
Email string `json:"email"` // 邮箱
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
Token string `json:"token"` // token
}
// GetAdminUserListDto 列表
func GetAdminUserListDto(m []*model.AdminUser) []*AdminUserDto {
// 处理返回值
responses := make([]*AdminUserDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &AdminUserDto{
UserId: fmt.Sprintf("%d", v.UserId),
Access: v.Access,
NickName: v.NickName,
IsAdmin: v.IsAdmin,
Status: v.Status,
IsDeleted: v.IsDeleted,
IsDisabled: v.IsDisabled,
Phone: v.Phone,
Avatar: utils.AddOssDomain(v.Avatar),
Sex: v.Sex,
Email: v.Email,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
func GetAdminUserDto(m *model.AdminUser) *AdminUserDto {
return &AdminUserDto{
UserId: fmt.Sprintf("%d", m.UserId),
Access: m.Access,
Status: m.Status,
IsDeleted: m.IsDeleted,
IsDisabled: m.IsDisabled,
NickName: m.NickName,
Phone: m.Phone,
Avatar: utils.AddOssDomain(m.Avatar),
Sex: m.Sex,
Email: m.Email,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}

48
api/dto/BasicHospital.go Normal file
View File

@ -0,0 +1,48 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// BasicHospitalDto 基础数据-医院
type BasicHospitalDto struct {
HospitalId string `json:"hospital_id"` // 主键id
HospitalName string `json:"hospital_name"` // 医院名称
HospitalLevel string `json:"hospital_level"` // 医院等级
DoctorNumber int `json:"doctor_number"` // 医生数量
Province string `json:"province"` // 省份
City string `json:"city"` // 城市
County string `json:"county"` // 区县
Address string `json:"address"` // 地址
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetBasicHospitalListDto 列表
func GetBasicHospitalListDto(m []*model.BasicHospital) []*BasicHospitalDto {
// 处理返回值
responses := make([]*BasicHospitalDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &BasicHospitalDto{
HospitalId: fmt.Sprintf("%d", v.HospitalId),
HospitalName: v.HospitalName,
HospitalLevel: v.HospitalLevel,
DoctorNumber: v.DoctorNumber,
Province: v.Province,
City: v.City,
County: v.County,
Address: v.Address,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}

107
api/dto/Case.go Normal file
View File

@ -0,0 +1,107 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/config"
"fmt"
"time"
)
// CaseDto 病历表
type CaseDto struct {
CaseId string `json:"case_id"` // 主键id
ProjectId string `json:"project_id"` // 所属项目id
CaseStatus int `json:"case_status"` // 病例状态1:正常 2:禁用)
CaseName string `json:"case_name"` // 病例名称
CaseAuthor string `json:"case_author"` // 病例作者
IssuedScore int `json:"issued_score"` // 多平台已发放积分
JoinNum int `json:"join_num"` // 多平台参加总人数
JoinWhiteNum int `json:"join_white_num"` // 多平台白名单参加总人数
MessageNum int `json:"message_num"` // 多平台留言人数
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseItem []*CaseItemDto `json:"case_item"` // 病例明细
IsNew int `json:"is_new"` // 是否为新病例(最近7天)
IsJoin int `json:"is_join"` // 是否参与过(区分平台)
Link string `json:"link"` // 链接
}
// GetCaseListDto 列表
func GetCaseListDto(m []*model.Case) []*CaseDto {
// 处理返回值
responses := make([]*CaseDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &CaseDto{
CaseId: fmt.Sprintf("%d", v.CaseId),
ProjectId: fmt.Sprintf("%d", v.ProjectId),
CaseStatus: v.CaseStatus,
CaseName: v.CaseName,
CaseAuthor: v.CaseAuthor,
IssuedScore: v.IssuedScore,
JoinNum: v.JoinNum,
JoinWhiteNum: v.JoinWhiteNum,
MessageNum: v.MessageNum,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载访问链接
response.LoadLink(v)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetCaseDto 详情
func GetCaseDto(m *model.Case) *CaseDto {
return &CaseDto{
CaseId: fmt.Sprintf("%d", m.CaseId),
ProjectId: fmt.Sprintf("%d", m.ProjectId),
CaseStatus: m.CaseStatus,
CaseName: m.CaseName,
CaseAuthor: m.CaseAuthor,
IssuedScore: m.IssuedScore,
JoinNum: m.JoinNum,
JoinWhiteNum: m.JoinWhiteNum,
MessageNum: m.MessageNum,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// LoadCaseItem 加载数据-病例明细
func (r *CaseDto) LoadCaseItem(m []*model.CaseItem) *CaseDto {
if len(m) > 0 {
r.CaseItem = GetCaseItemListDto(m)
}
return r
}
// LoadIsNew 加载是否为新病例(最近7天)
func (r *CaseDto) LoadIsNew(t model.LocalTime) *CaseDto {
now := time.Now()
createdAt := time.Time(t)
diffTime := createdAt.Sub(now)
if diffTime <= 7*24*time.Hour {
r.IsNew = 1
}
return r
}
// LoadLink 加载访问链接
func (r *CaseDto) LoadLink(m *model.Case) *CaseDto {
if m != nil {
link := config.C.DomainName + "?source=3" + "&platform_key=654321" + "&case_id=" + fmt.Sprintf("%d", m.CaseId)
r.Link = link
}
return r
}

127
api/dto/CaseComment.go Normal file
View File

@ -0,0 +1,127 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/utils"
"fmt"
)
// CaseCommentDto 病历表-评论
type CaseCommentDto struct {
CommentId string `json:"comment_id"` // 主键id
CaseId string `json:"case_id"` // 所属病例id
PlatformId string `json:"platform_id"` // 来源平台id
ParentId *string `json:"parent_id,omitempty"` // 父级id一级评论为null
RootId *string `json:"root_id,omitempty"` // 根评论id一级评论时为null。其余为一级评论id
Level int `json:"level"` // 级别1:留言 2:回复 3:评论)
UserId string `json:"user_id"` // 用户id
Status int `json:"status"` // 评论状态0:禁用 1:正常)
UserName string `json:"user_name"` // 用户名称
AreaName string `json:"area_name"` // 地址名称
HospitalName string `json:"hospital_name"` // 医院名称
DepartmentName string `json:"department_name"` // 科室名称
Title string `json:"title"` // 职称
IsHighQuality int `json:"is_high_quality"` // 是否优质留言0:否 1:是)
IsGrantHighQuality int `json:"is_grant_high_quality"` // 优质留言积分是否已发放0:否 1:是)
LikeNum int `json:"like_num"` // 点赞数量
Content string `json:"content"` // 评论内容
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseComment []*CaseCommentDto `json:"case_comment"` // 次级评论
IsLike bool `json:"is_like"` // 点赞状态0:否 1:是)
TotalAmount int64 `json:"total_amount"` // 剩余评论数量
}
// GetCaseCommentListDto 列表
func GetCaseCommentListDto(m []*model.CaseComment) []*CaseCommentDto {
// 处理返回值
responses := make([]*CaseCommentDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &CaseCommentDto{
CommentId: fmt.Sprintf("%d", v.CommentId),
CaseId: fmt.Sprintf("%d", v.CaseId),
PlatformId: fmt.Sprintf("%d", v.PlatformId),
Level: v.Level,
UserId: fmt.Sprintf("%d", v.UserId),
Status: v.Status,
IsHighQuality: v.IsHighQuality,
LikeNum: v.LikeNum,
Content: v.Content,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载数据-用户字段
if v.User != nil {
response = response.LoadUser(v.User)
// 加载数据-医院字段
if v.User.Hospital != nil {
response = response.LoadHospital(v.User.Hospital)
}
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadCaseComment 加载数据-次级评论
func (r *CaseCommentDto) LoadCaseComment(m []*model.CaseComment) *CaseCommentDto {
if len(m) > 0 {
r.CaseComment = GetCaseCommentListDto(m)
}
return r
}
// LoadIsLike 加载数据-点赞
func (r *CaseCommentDto) LoadIsLike(m int64) *CaseCommentDto {
if m > 0 {
r.IsLike = true
}
return r
}
// LoadTotalAmount 加载数据-剩余数量
func (r *CaseCommentDto) LoadTotalAmount(m int64) *CaseCommentDto {
if m > 0 {
r.TotalAmount = m
}
return r
}
// LoadUser 加载数据-用户字段
func (r *CaseCommentDto) LoadUser(m *model.User) *CaseCommentDto {
if m != nil {
r.UserName = m.UserName
r.DepartmentName = m.DepartmentName
r.Title = utils.DoctorTitleToString(m.Title)
if m.Address != "" {
r.AreaName = m.Address
}
}
return r
}
// LoadHospital 加载数据-医院字段
func (r *CaseCommentDto) LoadHospital(m *model.BasicHospital) *CaseCommentDto {
if m != nil {
r.HospitalName = m.HospitalName
if m.Address == "" {
r.AreaName = m.Province
}
}
return r
}

54
api/dto/CaseItem.go Normal file
View File

@ -0,0 +1,54 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// CaseItemDto 病历表-明细
type CaseItemDto struct {
CaseItemId string `json:"case_item_id"` // 主键id
CaseId string `json:"case_id"` // 所属病例id
Page int `json:"page"` // 页码
Content string `json:"content"` // 详情内容
IsRightNext int `json:"is_right_next"` // 是否答对后允许下一步0:否 1:是)
ErrorTips string `json:"error_tips"` // 答错提示
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseItemQuestion []*CaseItemQuestionDto `json:"case_item_question"` // 病例明细-题目
}
// GetCaseItemListDto 列表
func GetCaseItemListDto(m []*model.CaseItem) []*CaseItemDto {
// 处理返回值
responses := make([]*CaseItemDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &CaseItemDto{
CaseItemId: fmt.Sprintf("%d", v.CaseItemId),
CaseId: fmt.Sprintf("%d", v.CaseId),
Page: v.Page,
Content: v.Content,
IsRightNext: v.IsRightNext,
ErrorTips: v.ErrorTips,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadCaseItemQuestion 加载数据-病例明细-题目
func (r *CaseItemDto) LoadCaseItemQuestion(m []*model.CaseItemQuestion) *CaseItemDto {
if len(m) > 0 {
r.CaseItemQuestion = GetCaseItemQuestionListDto(m)
}
return r
}

View File

@ -0,0 +1,57 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// CaseItemQuestionDto 病历表-明细-题目
type CaseItemQuestionDto struct {
QuestionId string `json:"question_id"` // 主键id
CaseItemId string `json:"case_item_id"` // 病例明细id
QuestionName string `json:"question_name"` // 题目名称
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
QuestionAnswer string `json:"question_answer"` // 答案
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseItemQuestionOption []*CaseItemQuestionOptionDto `json:"case_item_question_option"` // 题目选项列表
}
// GetCaseItemQuestionListDto 列表
func GetCaseItemQuestionListDto(m []*model.CaseItemQuestion) []*CaseItemQuestionDto {
// 处理返回值
responses := make([]*CaseItemQuestionDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &CaseItemQuestionDto{
QuestionId: fmt.Sprintf("%d", v.QuestionId),
CaseItemId: fmt.Sprintf("%d", v.CaseItemId),
QuestionName: v.QuestionName,
QuestionType: v.QuestionType,
QuestionAnswer: v.QuestionAnswer,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载数据-病例明细-题目-选项
if v.CaseItemQuestionOption != nil {
response = response.LoadCaseItemQuestionOption(v.CaseItemQuestionOption)
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadCaseItemQuestionOption 加载数据-病例明细-题目-选项
func (r *CaseItemQuestionDto) LoadCaseItemQuestionOption(m []*model.CaseItemQuestionOption) *CaseItemQuestionDto {
if len(m) > 0 {
r.CaseItemQuestionOption = GetCaseItemQuestionOptionListDto(m)
}
return r
}

View File

@ -0,0 +1,38 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// CaseItemQuestionOptionDto 病历表-明细-题目-选项
type CaseItemQuestionOptionDto struct {
OptionId string `json:"option_id"` //主键id
QuestionId string `json:"question_id"` // 题目id
OptionValue string `json:"option_value"` // 选项内容
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetCaseItemQuestionOptionListDto 列表
func GetCaseItemQuestionOptionListDto(m []*model.CaseItemQuestionOption) []*CaseItemQuestionOptionDto {
// 处理返回值
responses := make([]*CaseItemQuestionOptionDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &CaseItemQuestionOptionDto{
OptionId: fmt.Sprintf("%d", v.OptionId),
QuestionId: fmt.Sprintf("%d", v.QuestionId),
OptionValue: v.OptionValue,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}

37
api/dto/CaseUser.go Normal file
View File

@ -0,0 +1,37 @@
package dto
import (
"case-open-api/api/model"
"fmt"
"strings"
)
// CaseUserDto 统计数据-病例-用户
type CaseUserDto struct {
CaseUserId string `json:"case_user_id"` // 主键id
TotalScore int `json:"total_score"` // 单个病例领取总积分
Describe string `json:"describe"` // 描述
}
// GetCaseUserDto 详情
func GetCaseUserDto(m *model.CaseUser) *CaseUserDto {
return &CaseUserDto{
CaseUserId: fmt.Sprintf("%d", m.CaseUserId),
TotalScore: m.TotalScore,
}
}
// LoadDescribe 加载数据-描述
func (r *CaseUserDto) LoadDescribe(m []*model.RecordScore) *CaseUserDto {
if len(m) > 0 {
var describe []string
for _, score := range m {
d := score.NodeName + ":" + fmt.Sprintf("%d", score.Score)
describe = append(describe, d)
}
r.Describe = strings.Join(describe, ", ")
}
return r
}

55
api/dto/Platform.go Normal file
View File

@ -0,0 +1,55 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// PlatformDto 平台表
type PlatformDto struct {
PlatformId string `json:"platform_id"` // 主键id
PlatformName string `json:"platform_name"` // 平台名称
PlatformStatus int `json:"platform_status"` // 平台状态1:正常 2:禁用)
PlatformKey string `json:"platform_key"` // 平台标识(用于鉴权)
PlatformSecret string `json:"platform_secret"` // 平台密钥(用于鉴权)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetPlatformListDto 列表
func GetPlatformListDto(m []*model.Platform) []*PlatformDto {
// 处理返回值
responses := make([]*PlatformDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &PlatformDto{
PlatformId: fmt.Sprintf("%d", v.PlatformId),
PlatformStatus: v.PlatformStatus,
PlatformName: v.PlatformName,
PlatformKey: v.PlatformKey,
PlatformSecret: v.PlatformSecret,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetPlatformDto 详情
func GetPlatformDto(m *model.Platform) *PlatformDto {
return &PlatformDto{
PlatformId: fmt.Sprintf("%d", m.PlatformId),
PlatformStatus: m.PlatformStatus,
PlatformName: m.PlatformName,
PlatformKey: m.PlatformKey,
PlatformSecret: m.PlatformSecret,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}

88
api/dto/Project.go Normal file
View File

@ -0,0 +1,88 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/utils"
"fmt"
)
type ProjectDto struct {
ProjectId string `json:"project_id"` // 主键id
ProjectName string `json:"project_name"` // 项目名称
ProjectStatus int `json:"project_status"` // 项目状态0:无效 1:正常)
ProjectImage string `json:"project_image"` // 项目背景图
IsLimitNum int `json:"is_limit_num"` // 是否限制参加数量0:否 1:是)
MaxJoinNum int `json:"max_join_num"` // 医生最多可参加数量
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseCount int `json:"case_count"` // 关联病例数量
IsRecentlyUpdate int `json:"is_recently_update"` // 是否最近有更新(最近7天)
IsWelfare int `json:"is_welfare"` // 是否存在福利(区分平台)
}
// GetProjectListDto 列表
func GetProjectListDto(m []*model.Project) []*ProjectDto {
// 处理返回值
responses := make([]*ProjectDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectDto{
ProjectId: fmt.Sprintf("%d", v.ProjectId),
ProjectName: v.ProjectName,
ProjectStatus: v.ProjectStatus,
IsLimitNum: v.IsLimitNum,
MaxJoinNum: v.MaxJoinNum,
ProjectImage: utils.AddOssDomain(v.ProjectImage),
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载关联病例数量
response = response.LoadCaseCount(v.Case)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetProjectDto 详情
func GetProjectDto(m *model.Project) *ProjectDto {
return &ProjectDto{
ProjectId: fmt.Sprintf("%d", m.ProjectId),
ProjectName: m.ProjectName,
ProjectStatus: m.ProjectStatus,
ProjectImage: utils.AddOssDomain(m.ProjectImage),
IsLimitNum: m.IsLimitNum,
MaxJoinNum: m.MaxJoinNum,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// LoadCaseCount 加载关联病例数量
func (r *ProjectDto) LoadCaseCount(m []*model.Case) *ProjectDto {
if len(m) > 0 {
r.CaseCount = len(m)
}
return r
}
// LoadIsWelfare 加载是否存在福利
func (r *ProjectDto) LoadIsWelfare(m *model.ProjectPlatform) *ProjectDto {
if m != nil {
r.IsWelfare = m.IsWelfare
}
return r
}
// LoadIsRecentlyUpdate 加载最近更新情况
func (r *ProjectDto) LoadIsRecentlyUpdate(m *model.Case) *ProjectDto {
if m != nil {
r.IsRecentlyUpdate = 1
}
return r
}

View File

@ -0,0 +1,91 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// ProjectPlatformDto 项目表-关联平台
type ProjectPlatformDto struct {
PlatformId string `json:"platform_id"` // 主键id
ProjectId string `json:"project_id"` // 项目id
Status int `json:"status"` // 状态1:正常 2:禁用)
IsWelfare int `json:"is_welfare"` // 是否开启福利0:否 1:是)
ReadDuration int `json:"read_duration"` // 阅读时长(秒)
SingleCaseScore int `json:"single_case_score"` // 单个病例总积分
CompleteRead int `json:"complete_read"` // 完成阅读积分
CompleteReadTime int `json:"complete_read_time"` // 完成阅读时间积分
FirstHighQuality int `json:"first_high_quality"` // 首次优质留言积分
OnceMoreHighQuality int `json:"once_more_high_quality"` // 再次优质留言积分
IsWhite int `json:"is_white"` // 是否开启白名单0:否 1:是)
WhiteType int `json:"white_type"` // 白名单类型1:医院 2:医生 3:动态)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
PlatformName string `json:"platform_name"` // 平台名称
}
// GetProjectPlatformListDto 列表
func GetProjectPlatformListDto(m []*model.ProjectPlatform) []*ProjectPlatformDto {
// 处理返回值
responses := make([]*ProjectPlatformDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectPlatformDto{
PlatformId: fmt.Sprintf("%d", v.PlatformId),
ProjectId: fmt.Sprintf("%d", v.ProjectId),
Status: v.Status,
IsWelfare: v.IsWelfare,
ReadDuration: v.ReadDuration,
SingleCaseScore: v.SingleCaseScore,
CompleteRead: v.CompleteRead,
CompleteReadTime: v.CompleteReadTime,
FirstHighQuality: v.FirstHighQuality,
OnceMoreHighQuality: v.OnceMoreHighQuality,
IsWhite: v.IsWhite,
WhiteType: v.WhiteType,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载数据-平台名称
if v.Platform != nil {
response = response.LoadPlatFormName(v.Platform)
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetProjectPlatformDto 详情
func GetProjectPlatformDto(m *model.ProjectPlatform) *ProjectPlatformDto {
return &ProjectPlatformDto{
PlatformId: fmt.Sprintf("%d", m.PlatformId),
ProjectId: fmt.Sprintf("%d", m.ProjectId),
Status: m.Status,
IsWelfare: m.IsWelfare,
ReadDuration: m.ReadDuration,
SingleCaseScore: m.SingleCaseScore,
CompleteRead: m.CompleteRead,
CompleteReadTime: m.CompleteReadTime,
FirstHighQuality: m.FirstHighQuality,
OnceMoreHighQuality: m.OnceMoreHighQuality,
IsWhite: m.IsWhite,
WhiteType: m.WhiteType,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// LoadPlatFormName 加载数据-平台名称
func (r *ProjectPlatformDto) LoadPlatFormName(m *model.Platform) *ProjectPlatformDto {
if m != nil {
r.PlatformName = m.PlatformName
}
return r
}

View File

@ -0,0 +1,53 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// ProjectPlatformDoctorDto 关联平台-白名单-医生
type ProjectPlatformDoctorDto struct {
WhiteDoctorId string `json:"white_doctor_id"` // 主键id
PlatformId string `json:"platform_id"` // 关联平台id
UserId string `json:"user_id"` // 关联用户id
Status int `json:"status"` // 状态1:正常 2:禁用)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
User []*UserDto `json:"user"` //
}
// GetProjectPlatformDoctorListDto 列表
func GetProjectPlatformDoctorListDto(m []*model.ProjectPlatformDoctor) []*ProjectPlatformDoctorDto {
// 处理返回值
responses := make([]*ProjectPlatformDoctorDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectPlatformDoctorDto{
WhiteDoctorId: fmt.Sprintf("%d", v.WhiteDoctorId),
PlatformId: fmt.Sprintf("%d", v.PlatformId),
UserId: fmt.Sprintf("%d", v.UserId),
Status: v.Status,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载数据-医院列表
response = response.LoadUser(v.User)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadUser 加载数据-用户列表
func (r *ProjectPlatformDoctorDto) LoadUser(m []*model.User) *ProjectPlatformDoctorDto {
if len(m) > 0 {
r.User = GetUserListDto(m)
}
return r
}

View File

@ -0,0 +1,50 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// ProjectPlatformDynamicDto 关联平台-白名单-动态
type ProjectPlatformDynamicDto struct {
WhiteDynamicId string `gorm:"column:white_dynamic_id;type:bigint(19);primary_key;comment:主键id" json:"white_dynamic_id"`
PlatformId string `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
DynamicType string `gorm:"column:dynamic_type;type:varchar(50);comment:动态类型area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"dynamic_type"`
Status int `gorm:"column:status;type:tinyint(1);comment:状态1:正常 2:禁用)" json:"status"`
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
ProjectPlatformDynamicItemDto []*ProjectPlatformDynamicItemDto `json:"project_platform_dynamic_item"`
}
// GetProjectPlatformDynamicListDto 列表
func GetProjectPlatformDynamicListDto(m []*model.ProjectPlatformDynamic) []*ProjectPlatformDynamicDto {
// 处理返回值
responses := make([]*ProjectPlatformDynamicDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectPlatformDynamicDto{
WhiteDynamicId: fmt.Sprintf("%d", v.WhiteDynamicId),
PlatformId: fmt.Sprintf("%d", v.PlatformId),
DynamicType: v.DynamicType,
Status: v.Status,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadItem 加载数据-明细
func (r *ProjectPlatformDynamicDto) LoadItem(m []*model.ProjectPlatformDynamicItem) *ProjectPlatformDynamicDto {
if len(m) > 0 {
r.ProjectPlatformDynamicItemDto = GetProjectPlatformDynamicItemListDto(m)
}
return r
}

View File

@ -0,0 +1,38 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// ProjectPlatformDynamicItemDto 关联平台-白名单-动态-明细
type ProjectPlatformDynamicItemDto struct {
ItemId string `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
WhiteDynamicId string `gorm:"column:white_dynamic_id;type:bigint(19);comment:关联动态白名单id;NOT NULL" json:"white_dynamic_id"`
ItemValue string `gorm:"column:item_value;type:varchar(255);comment:明细值area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"item_value"`
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetProjectPlatformDynamicItemListDto 列表
func GetProjectPlatformDynamicItemListDto(m []*model.ProjectPlatformDynamicItem) []*ProjectPlatformDynamicItemDto {
// 处理返回值
responses := make([]*ProjectPlatformDynamicItemDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectPlatformDynamicItemDto{
ItemId: fmt.Sprintf("%d", v.ItemId),
WhiteDynamicId: fmt.Sprintf("%d", v.WhiteDynamicId),
ItemValue: v.ItemValue,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}

View File

@ -0,0 +1,53 @@
package dto
import (
"case-open-api/api/model"
"fmt"
)
// ProjectPlatformHospitalDto 关联平台-白名单-医院
type ProjectPlatformHospitalDto struct {
WhiteHospitalId string `json:"white_hospital_id"` // 主键id
PlatformId string `json:"platform_id"` // 关联平台id
HospitalId string `json:"hospital_id"` // 医院id
Status int `json:"status"` // 状态1:正常 2:禁用)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
BasicHospital []*BasicHospitalDto `json:"basic_hospital"` // 基础数据-医院
}
// GetProjectPlatformHospitalListDto 列表
func GetProjectPlatformHospitalListDto(m []*model.ProjectPlatformHospital) []*ProjectPlatformHospitalDto {
// 处理返回值
responses := make([]*ProjectPlatformHospitalDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ProjectPlatformHospitalDto{
WhiteHospitalId: fmt.Sprintf("%d", v.WhiteHospitalId),
PlatformId: fmt.Sprintf("%d", v.PlatformId),
HospitalId: fmt.Sprintf("%d", v.HospitalId),
Status: v.Status,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载数据-医院列表
response = response.LoadBasicHospital(v.BasicHospital)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadBasicHospital 加载数据-医院列表
func (r *ProjectPlatformHospitalDto) LoadBasicHospital(m []*model.BasicHospital) *ProjectPlatformHospitalDto {
if len(m) > 0 {
r.BasicHospital = GetBasicHospitalListDto(m)
}
return r
}

30
api/dto/Public.go Normal file
View File

@ -0,0 +1,30 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/utils"
"fmt"
)
// LoginDto 登陆
type LoginDto struct {
UserId string `json:"user_id"` // 用户id
UserName string `json:"user_name"` // 用户名称
Avatar string `json:"avatar"` // 头像
Token string `json:"token"` // token
}
// UserLoginDto 微信登陆
func UserLoginDto(m *model.User) *LoginDto {
return &LoginDto{
UserId: fmt.Sprintf("%d", m.UserId),
UserName: m.UserName,
Avatar: utils.AddOssDomain(m.Avatar),
}
}
// LoadToken 加载token
func (r *LoginDto) LoadToken(token string) *LoginDto {
r.Token = token
return r
}

167
api/dto/Res.go Normal file
View File

@ -0,0 +1,167 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/config"
"case-open-api/utils"
"fmt"
)
// ResProjectDto 项目
type ResProjectDto struct {
ProjectId string `json:"project_id"` // 主键id
ProjectName string `json:"project_name"` // 项目名称
ProjectStatus int `json:"project_status"` // 项目状态0:无效 1:正常)
ProjectImage string `json:"project_image"` // 项目背景图
IsLimitNum int `json:"is_limit_num"` // 是否限制参加数量0:否 1:是)
MaxJoinNum int `json:"max_join_num"` // 医生最多可参加数量
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
CaseCount int `json:"case_count"` // 关联病例数量
IsRecentlyUpdate int `json:"is_recently_update"` // 是否最近有更新(最近7天)
IsWelfare int `json:"is_welfare"` // 是否存在福利(区分平台)
}
// ResCaseDto 病历
type ResCaseDto struct {
SId string `json:"sid"` // 主键id
ProjectId string `json:"project_id"` // 项目标识
Titel string `json:"titel"` // 病例名称
Thumb string `json:"thumb"` // 封面图片
StarTime model.LocalTime `json:"startime"` // 创建时间
Url string `json:"url"` // 链接
}
// ResCaseRecordDto 病例领取记录
type ResCaseRecordDto struct {
CaseUserId string `json:"id"` // 主键id
Sid string `json:"sid"` // 病例id
Beizhu string `json:"beizhu"` // 备注
OpenId string `json:"openid"` // openid
Title string `json:"title"` // 问卷标题
NickName string `json:"nickname"` // 昵称
RealName string `json:"realname"` // 真实姓名
Mobile string `json:"mobile"` // 手机号
Hos2 string `json:"hos2"` // 科室
Job string `json:"job"` // 职称
HospitalName string `json:"hospital_name"` // 医院
ResideProvince string `json:"resideprovince"` // 省份
ResideCity string `json:"residecity"` // 城市
CreateDate string `json:"createdate"` // 日期
CreateTimes string `json:"createtimes"` // 时间
ResidenceTime string `json:"residencetime"` // 用时
QuestionAnswer []*QuestionAnswerDto `json:"question_answer"` // 问题和答案数组
TslUid string `json:"tsl_uid"` // 天士力系统uid
TslShareUserId string `json:"tsl_share_user_id"` // 天士力系统分享人uid
IsVip int `json:"is_vip"` // 是否把白名单 0:否 1:是
Credit1 int `json:"credit1"` // 阅读完成积分
Credit2 int `json:"credit2"` // 调研奖励(阅读质量) 阅读时长
Credit3 int `json:"credit3"` // 调研奖励(留言)—评论奖励
Credit4 int `json:"credit4"` // 调研奖励(社区贡献) 优质提问或者优质解答
CreditTotal int `json:"credit_total"` // 总获得积分
HasRemark int `json:"has_remark"` // 是否有评论 1是0否
Remark []*RemarkDto `json:"remark"` // 评论
}
// QuestionAnswerDto 病例领取记录-问题
type QuestionAnswerDto struct {
Question string `json:"question"` // 问题标题
Answer string `json:"answer"` // 答案
Correct bool `json:"correct"` //
Order int `json:"order"` // 排序
}
// RemarkDto 病例领取记录-评论
type RemarkDto struct {
Remark string `json:"remark"` // 评论
CreateTime string `json:"createtime"` // 时间
}
// GetResProjectListDto 获取项目列表
func GetResProjectListDto(m []*model.Project) []*ResProjectDto {
// 处理返回值
responses := make([]*ResProjectDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ResProjectDto{
ProjectId: fmt.Sprintf("%d", v.ProjectId),
ProjectName: v.ProjectName,
ProjectStatus: v.ProjectStatus,
IsLimitNum: v.IsLimitNum,
MaxJoinNum: v.MaxJoinNum,
ProjectImage: utils.AddOssDomain(v.ProjectImage),
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载关联病例数量
response = response.LoadCaseCount(v.Case)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetCaseResListDto 获取病例列表
func GetCaseResListDto(m []*model.Case) []*ResCaseDto {
// 处理返回值
responses := make([]*ResCaseDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &ResCaseDto{
SId: fmt.Sprintf("%d", v.CaseId),
ProjectId: fmt.Sprintf("%d", v.ProjectId),
Titel: v.CaseName,
Thumb: "",
StarTime: v.CreatedAt,
}
// 加载访问链接
response.LoadLink(v)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadCaseCount 加载关联病例数量
func (r *ResProjectDto) LoadCaseCount(m []*model.Case) *ResProjectDto {
if len(m) > 0 {
r.CaseCount = len(m)
}
return r
}
// LoadIsWelfare 加载是否存在福利
func (r *ResProjectDto) LoadIsWelfare(m *model.ProjectPlatform) *ResProjectDto {
if m != nil {
r.IsWelfare = m.IsWelfare
}
return r
}
// LoadIsRecentlyUpdate 加载最近更新情况
func (r *ResProjectDto) LoadIsRecentlyUpdate(m *model.Case) *ResProjectDto {
if m != nil {
r.IsRecentlyUpdate = 1
}
return r
}
// LoadLink 加载访问链接
func (r *ResCaseDto) LoadLink(m *model.Case) *ResCaseDto {
if m != nil {
link := config.C.DomainName + "?source=3" + "&platform_key=654321" + "&case_id=" + fmt.Sprintf("%d", m.CaseId)
r.Url = link
}
return r
}

59
api/dto/User.go Normal file
View File

@ -0,0 +1,59 @@
package dto
import (
"case-open-api/api/model"
"case-open-api/utils"
"fmt"
)
// UserDto 用户表
type UserDto struct {
UserId string `json:"user_id"` // 主键id
UserIden string `json:"user_iden"` // 第三方平台唯一标识
UserName string `json:"user_name"` // 用户名称
UserMobile string `json:"user_mobile"` // 手机号
Status int `json:"status"` // 状态0:禁用 1:正常 2:删除)
RegisterSource int `json:"register_source"` // 注册来源1:未知 2:app用户 3:佳动例)
OpenId string `json:"open_id"` // 用户微信标识
UnionId string `json:"union_id"` // 微信开放平台标识
Sex int `json:"sex"` // 性别0:未知 1:男 2:女)
Avatar string `json:"avatar"` // 头像
Title int `json:"title"` // 医生职称1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)
DepartmentName string `json:"department_name"` // 科室名称
HospitalId string `json:"hospital_id"` // 所属医院id
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
// GetUserListDto 列表
func GetUserListDto(m []*model.User) []*UserDto {
// 处理返回值
responses := make([]*UserDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &UserDto{
UserId: fmt.Sprintf("%d", v.UserId),
UserIden: v.UserIden,
UserName: v.UserName,
UserMobile: v.UserMobile,
Status: v.Status,
RegisterSource: v.RegisterSource,
OpenId: v.OpenId,
UnionId: v.UnionId,
Sex: v.Sex,
Avatar: utils.AddOssDomain(v.Avatar),
Title: v.Title,
DepartmentName: v.DepartmentName,
HospitalId: fmt.Sprintf("%d", v.HospitalId),
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}

View File

@ -0,0 +1,43 @@
package exception
import (
"case-open-api/consts"
"github.com/gin-gonic/gin"
"log"
"net/http"
"runtime/debug"
)
// Recover
// @Description: 处理全局异常
// @return gin.HandlerFunc
func Recover() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if r := recover(); r != nil {
// 打印错误堆栈信息
log.Printf("panic: %v\n", r)
debug.PrintStack()
c.JSON(http.StatusInternalServerError, gin.H{
"code": consts.ServerError,
"message": errorToString(r),
"data": "",
})
// 终止后续接口调用不加的话recover到异常后还会继续执行接口里后续代码
c.Abort()
}
}()
// 加载完 defer recover继续后续接口调用
c.Next()
}
}
// recover错误转string
func errorToString(r interface{}) string {
switch v := r.(type) {
case error:
return v.Error()
default:
return r.(string)
}
}

93
api/middlewares/auth.go Normal file
View File

@ -0,0 +1,93 @@
package middlewares
import (
"case-open-api/api/dao"
"case-open-api/api/responses"
"case-open-api/consts"
"case-open-api/utils"
"encoding/json"
"github.com/gin-gonic/gin"
"net/http"
)
// Auth Auth认证
func Auth() gin.HandlerFunc {
return func(c *gin.Context) {
platformKey := c.Request.Header.Get("platformKey")
sign := c.Request.Header.Get("sign")
timestamp := c.Request.Header.Get("timestamp")
if platformKey == "" || sign == "" || timestamp == "" {
c.JSON(http.StatusOK, gin.H{
"message": "非法请求",
"code": consts.ClientHttpError,
"data": "",
})
c.Abort()
return
}
// 获取平台数据
platformDao := dao.PlatformDao{}
maps := make(map[string]interface{})
maps["platform_key"] = platformKey
platform, err := platformDao.GetPlatform(maps)
if err != nil || platform == nil {
responses.FailWithMessage("非法请求", c)
c.Abort()
return
}
if platform.PlatformStatus != 1 {
responses.FailWithMessage("非法请求", c)
c.Abort()
return
}
// 获取请求参数
paramsRaw, ok := c.Get("params")
if !ok {
c.JSON(http.StatusOK, gin.H{
"message": "Invalid params",
"code": consts.ClientHttpError,
"data": "",
})
c.Abort()
return
}
paramsJsonData, err := json.Marshal(paramsRaw)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"message": "Invalid params",
"code": consts.ClientHttpError,
"data": "",
})
c.Abort()
return
}
paramsMap := make(map[string]interface{})
err = json.Unmarshal(paramsJsonData, &paramsMap)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"message": "Invalid params",
"code": consts.ClientHttpError,
"data": "",
})
c.Abort()
return
}
// 验证签名
err = utils.VerifySignature(paramsMap, timestamp, sign, platform.PlatformSecret)
if err != nil {
responses.FailWithMessage(err.Error(), c)
c.Abort()
return
}
c.Set("platformId", platform.PlatformId) // 平台id
c.Next()
}
}

29
api/middlewares/cors.go Normal file
View File

@ -0,0 +1,29 @@
package middlewares
import (
"github.com/gin-gonic/gin"
"net/http"
)
// Cors
// @Description: 跨域中间件
// @return gin.HandlerFunc
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
origin := c.Request.Header.Get("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
c.Header("Access-Control-Allow-Credentials", "false")
c.Set("content-type", "application/json")
}
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}
}

60
api/middlewares/logrus.go Normal file
View File

@ -0,0 +1,60 @@
package middlewares
import (
"case-open-api/global"
"fmt"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"time"
)
// Logrus 日志中间件
func Logrus() gin.HandlerFunc {
return func(c *gin.Context) {
// 开始时间
startTime := time.Now()
// 处理请求
c.Next()
// 获取 请求 参数
params := make(map[string]string)
paramsRaw, ok := c.Get("params")
if ok {
requestParams, ok := paramsRaw.(map[string]string)
if ok || len(requestParams) > 0 {
params = requestParams
}
}
// 结束时间
endTime := time.Now()
// 执行时间
latencyTime := fmt.Sprintf("%6v", endTime.Sub(startTime))
// 请求方式
reqMethod := c.Request.Method
// 请求路由
reqUri := c.Request.RequestURI
// 状态码
statusCode := c.Writer.Status()
// 请求IP
clientIP := c.ClientIP()
// 日志格式
global.Logger.WithFields(logrus.Fields{
"http_status": statusCode,
"total_time": latencyTime,
"ip": clientIP,
"method": reqMethod,
"uri": reqUri,
"params": params,
}).Info("access")
}
}

View File

@ -0,0 +1,92 @@
package middlewares
import (
"bytes"
"case-open-api/consts"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"io"
"net/http"
)
// RequestParamsMiddleware 获取请求参数中间件
func RequestParamsMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
contentType := c.Request.Header.Get("Content-Type")
params := make(map[string]string)
// 判断请求参数类型
switch contentType {
case "application/json":
// 解析 application/json 请求体
bodyBytes, err := io.ReadAll(c.Request.Body)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
c.Abort()
return
}
// 创建新的请求对象,并设置请求体数据
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
var jsonParams map[string]interface{}
err = json.Unmarshal(bodyBytes, &jsonParams)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "Invalid JSON data",
"code": consts.HttpError,
"data": "",
})
c.Abort()
return
}
for key, value := range jsonParams {
params[key] = fmt.Sprintf("%v", value)
}
// 存储参数到上下文
c.Set("params", params)
case "multipart/form-data", "application/form-data", "application/x-www-form-urlencoded":
// 解析 Form 表单参数
err := c.Request.ParseForm()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "Invalid form data",
"code": consts.HttpError,
"data": "",
})
c.Abort()
return
}
for key, values := range c.Request.Form {
if len(values) > 0 {
params[key] = fmt.Sprintf("%v", values[0])
}
}
// 存储参数到上下文
c.Set("params", params)
default:
// 解析 URL 参数
queryParams := c.Request.URL.Query()
for key, values := range queryParams {
if len(values) > 0 {
params[key] = fmt.Sprintf("%v", values[0])
}
}
// 存储参数到上下文
c.Set("params", params)
}
// 继续处理请求
c.Next()
}
}

43
api/model/AdminUser.go Normal file
View File

@ -0,0 +1,43 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// 后台-用户表
type AdminUser struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员0:否 1:是)" json:"is_admin"`
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态1:正常 2:审核中 3:审核失败)" json:"status"`
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除0:否 1:是)" json:"is_deleted"`
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用0:否 1:是)" json:"is_disabled"`
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别1:男 2:女)" json:"sex"`
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
Model
}
func (m *AdminUser) TableName() string {
return "admin_user"
}
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// BasicHospital 基础数据-医院
type BasicHospital struct {
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);primary_key;comment:主键id" json:"hospital_id"`
HospitalName string `gorm:"column:hospital_name;type:varchar(100);comment:医院名称" json:"hospital_name"`
Source int `gorm:"column:source;type:tinyint(1);comment:来源2:肝胆相照 3:佳动例);NOT NULL" json:"source"`
HospitalLevel string `gorm:"column:hospital_level;type:varchar(20);comment:医院等级" json:"hospital_level"`
DoctorNumber int `gorm:"column:doctor_number;type:int(5);default:0;comment:医生数量" json:"doctor_number"`
Province string `gorm:"column:province;type:varchar(50);comment:省份" json:"province"`
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
County string `gorm:"column:county;type:varchar(50);comment:区县" json:"county"`
Address string `gorm:"column:address;type:varchar(255);comment:地址" json:"address"`
Model
}
func (m *BasicHospital) TableName() string {
return "basic_hospital"
}
func (m *BasicHospital) BeforeCreate(tx *gorm.DB) error {
if m.HospitalId == 0 {
m.HospitalId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

39
api/model/Case.go Normal file
View File

@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Case 病历表
type Case struct {
CaseId int64 `gorm:"column:case_id;type:bigint(19);primary_key;comment:主键id" json:"case_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"`
CaseStatus int `gorm:"column:case_status;type:tinyint(1);default:1;comment:病例状态1:正常 2:禁用)" json:"case_status"`
CaseName string `gorm:"column:case_name;type:varchar(100);comment:病例名称" json:"case_name"`
CaseAuthor string `gorm:"column:case_author;type:varchar(100);comment:病例作者" json:"case_author"`
IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:多平台已发放积分" json:"issued_score"`
JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:多平台参加总人数" json:"join_num"`
JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:多平台白名单参加总人数" json:"join_white_num"`
MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:多平台留言人数" json:"message_num"`
Model
}
func (m *Case) TableName() string {
return "case"
}
func (m *Case) BeforeCreate(tx *gorm.DB) error {
if m.CaseId == 0 {
m.CaseId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

43
api/model/CaseComment.go Normal file
View File

@ -0,0 +1,43 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseComment 病历表-评论
type CaseComment struct {
CommentId int64 `gorm:"column:comment_id;type:bigint(19);primary_key;comment:主键id" json:"comment_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:来源平台id;NOT NULL" json:"platform_id"`
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:父级id一级评论为null" json:"parent_id"`
RootId int64 `gorm:"column:root_id;type:bigint(19);comment:根评论id一级评论时为null。其余为一级评论id" json:"root_id"`
Level int `gorm:"column:level;type:tinyint(1);default:1;comment:级别1:留言 2:回复 3:评论)" json:"level"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:评论状态0:禁用 1:正常)" json:"status"`
IsHighQuality int `gorm:"column:is_high_quality;type:tinyint(1);default:0;comment:是否优质留言0:否 1:是)" json:"is_high_quality"`
IsGrantHighQuality int `gorm:"column:is_grant_high_quality;type:tinyint(1);default:0;comment:优质留言积分是否已发放0:否 1:是)" json:"is_grant_high_quality"`
LikeNum int `gorm:"column:like_num;type:int(5);default:0;comment:点赞数量" json:"like_num"`
Content string `gorm:"column:content;type:varchar(500);comment:评论内容" json:"content"`
Model
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *CaseComment) TableName() string {
return "case_comment"
}
func (m *CaseComment) BeforeCreate(tx *gorm.DB) error {
if m.CommentId == 0 {
m.CommentId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseCommentLike 病历-评论-点赞
type CaseCommentLike struct {
LikeId int64 `gorm:"column:like_id;type:bigint(19);primary_key;comment:主键id" json:"like_id"`
CommentId int64 `gorm:"column:comment_id;type:bigint(19);comment:评论id" json:"comment_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
Model
}
func (m *CaseCommentLike) TableName() string {
return "case_comment_like"
}
func (m *CaseCommentLike) BeforeCreate(tx *gorm.DB) error {
if m.LikeId == 0 {
m.LikeId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

36
api/model/CaseItem.go Normal file
View File

@ -0,0 +1,36 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItem 病历表-明细
type CaseItem struct {
CaseItemId int64 `gorm:"column:case_item_id;type:bigint(19);primary_key;comment:主键id" json:"case_item_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
Page int `gorm:"column:page;type:int(1);default:1;comment:页码" json:"page"`
Content string `gorm:"column:content;type:text;comment:详情内容" json:"content"`
IsRightNext int `gorm:"column:is_right_next;type:tinyint(1);default:1;comment:是否答对后允许下一步0:否 1:是)" json:"is_right_next"`
ErrorTips string `gorm:"column:error_tips;type:varchar(200);comment:答错提示" json:"error_tips"`
Model
}
func (m *CaseItem) TableName() string {
return "case_item"
}
func (m *CaseItem) BeforeCreate(tx *gorm.DB) error {
if m.CaseItemId == 0 {
m.CaseItemId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,37 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItemQuestion 病历表-明细-题目
type CaseItemQuestion struct {
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id" json:"case_id"`
CaseItemId int64 `gorm:"column:case_item_id;type:bigint(19);comment:病例明细id;NOT NULL" json:"case_item_id"`
QuestionName string `gorm:"column:question_name;type:varchar(1000);comment:题目名称" json:"question_name"`
QuestionType int `gorm:"column:question_type;type:tinyint(1);comment:题目类型(1:单选 2:多选 3:问答 4:判断)" json:"question_type"`
QuestionAnswer string `gorm:"column:question_answer;type:varchar(255);comment:答案" json:"question_answer"`
Model
CaseItemQuestionOption []*CaseItemQuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question_option"`
}
func (m *CaseItemQuestion) TableName() string {
return "case_item_question"
}
func (m *CaseItemQuestion) BeforeCreate(tx *gorm.DB) error {
if m.QuestionId == 0 {
m.QuestionId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItemQuestionOption 病历表-明细-题目-选项
type CaseItemQuestionOption struct {
OptionId int64 `gorm:"column:option_id;type:bigint(19);primary_key;comment:主键id" json:"option_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
OptionValue string `gorm:"column:option_value;type:varchar(255);comment:选项内容" json:"option_value"`
Model
}
func (m *CaseItemQuestionOption) TableName() string {
return "case_item_question_option"
}
func (m *CaseItemQuestionOption) BeforeCreate(tx *gorm.DB) error {
if m.OptionId == 0 {
m.OptionId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

38
api/model/CasePlatform.go Normal file
View File

@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CasePlatform 统计数据-病例-平台
type CasePlatform struct {
CasePlatformId int64 `gorm:"column:case_platform_id;type:bigint(19);primary_key;comment:主键id" json:"case_platform_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:已发放积分" json:"issued_score"`
JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:参加人数" json:"join_num"`
JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:白名单参加人数" json:"join_white_num"`
MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:留言人数" json:"message_num"`
Model
ProjectPlatform *ProjectPlatform `gorm:"foreignKey:PlatformId;references:platform_id" json:"project_platform"`
}
func (m *CasePlatform) TableName() string {
return "case_platform"
}
func (m *CasePlatform) BeforeCreate(tx *gorm.DB) error {
if m.CasePlatformId == 0 {
m.CasePlatformId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

40
api/model/CaseUser.go Normal file
View File

@ -0,0 +1,40 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseUser 统计数据-病例-用户
type CaseUser struct {
CaseUserId int64 `gorm:"column:case_user_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
ShareUserIden string `gorm:"column:share_user_iden;type:varchar(100);comment:分享人标识" json:"share_user_iden"`
ReadDuration int `gorm:"column:read_duration;type:int(5);default:0;comment:阅读时长(秒)" json:"read_duration"`
TotalScore int `gorm:"column:total_score;type:int(5);default:0;comment:单个病例领取总积分" json:"total_score"`
Model
Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"`
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
Case *Case `gorm:"foreignKey:CaseId;references:case_id" json:"case"`
}
func (m *CaseUser) TableName() string {
return "case_user"
}
func (m *CaseUser) BeforeCreate(tx *gorm.DB) error {
if m.CaseUserId == 0 {
m.CaseUserId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

35
api/model/Platform.go Normal file
View File

@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Platform 项目表-关联平台
type Platform struct {
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);primary_key;comment:主键id" json:"platform_id"`
PlatformName string `gorm:"column:platform_name;type:varchar(100);comment:平台名称;NOT NULL" json:"platform_name"`
PlatformStatus int `gorm:"column:platform_status;type:tinyint(1);default:1;comment:平台状态1:正常 2:禁用);NOT NULL" json:"platform_status"`
PlatformKey string `gorm:"column:platform_key;type:varchar(100);comment:平台标识(用于鉴权);NOT NULL" json:"platform_key"`
PlatformSecret string `gorm:"column:platform_secret;type:varchar(100);comment:平台密钥(用于鉴权)" json:"platform_secret"`
Model
}
func (m *Platform) TableName() string {
return "platform"
}
func (m *Platform) BeforeCreate(tx *gorm.DB) error {
if m.PlatformId == 0 {
m.PlatformId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

38
api/model/Project.go Normal file
View File

@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Project 项目表
type Project struct {
ProjectId int64 `gorm:"column:project_id;type:bigint(19);primary_key;comment:主键id" json:"project_id"`
ProjectName string `gorm:"column:project_name;type:varchar(255);comment:项目名称" json:"project_name"`
ProjectStatus int `gorm:"column:project_status;type:tinyint(1);comment:项目状态0:无效 1:正常)" json:"project_status"`
ProjectImage string `gorm:"column:project_image;type:varchar(255);comment:项目背景图" json:"project_image"`
IsLimitNum int `gorm:"column:is_limit_num;type:tinyint(1);default:0;comment:是否限制参加数量0:否 1:是)" json:"is_limit_num"`
MaxJoinNum int `gorm:"column:max_join_num;type:int(5);default:0;comment:医生最多可参加数量" json:"max_join_num"`
Model
Case []*Case `gorm:"foreignKey:ProjectId;references:project_id" json:"case"`
ProjectPlatform []*ProjectPlatform `gorm:"foreignKey:ProjectId;references:project_id" json:"project_platform"`
}
func (m *Project) TableName() string {
return "project"
}
func (m *Project) BeforeCreate(tx *gorm.DB) error {
if m.ProjectId == 0 {
m.ProjectId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,44 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatform 项目表-关联平台
type ProjectPlatform struct {
ProjectPlatformId int64 `gorm:"column:project_platform_id;type:bigint(19);primary_key;comment:主键id" json:"project_platform_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:主键id;NOT NULL" json:"platform_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:项目id;NOT NULL" json:"project_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"status"`
IsWelfare int `gorm:"column:is_welfare;type:tinyint(1);default:1;comment:是否开启福利0:否 1:是)" json:"is_welfare"`
ReadDuration int `gorm:"column:read_duration;type:int(10);comment:阅读时长(秒)" json:"read_duration"`
SingleCaseScore int `gorm:"column:single_case_score;type:int(10);comment:单个病例总积分" json:"single_case_score"`
CompleteRead int `gorm:"column:complete_read;type:int(10);comment:完成阅读积分" json:"complete_read"`
CompleteReadTime int `gorm:"column:complete_read_time;type:int(10);comment:完成阅读时间积分" json:"complete_read_time"`
FirstHighQuality int `gorm:"column:first_high_quality;type:int(10);comment:首次优质留言积分" json:"first_high_quality"`
OnceMoreHighQuality int `gorm:"column:once_more_high_quality;type:int(10);comment:再次优质留言积分" json:"once_more_high_quality"`
IsWhite int `gorm:"column:is_white;type:tinyint(1);default:0;comment:是否开启白名单0:否 1:是)" json:"is_white"`
WhiteType int `gorm:"column:white_type;type:tinyint(1);comment:白名单类型1:医院 2:医生 3:动态)" json:"white_type"`
Model
Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"`
}
func (m *ProjectPlatform) TableName() string {
return "project_platform"
}
func (m *ProjectPlatform) BeforeCreate(tx *gorm.DB) error {
if m.ProjectPlatformId == 0 {
m.ProjectPlatformId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,34 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformArea 关联平台-白名单-省份
type ProjectPlatformArea struct {
WhiteAreaId int64 `gorm:"column:white_area_id;type:bigint(19);primary_key;comment:主键id" json:"white_area_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
AreaName string `gorm:"column:area_name;type:varchar(100);comment:地址名称;NOT NULL" json:"area_name"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"status"`
Model
}
func (m *ProjectPlatformArea) TableName() string {
return "project_platform_area"
}
func (m *ProjectPlatformArea) BeforeCreate(tx *gorm.DB) error {
if m.WhiteAreaId == 0 {
m.WhiteAreaId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDoctor 关联平台-白名单-医生
type ProjectPlatformDoctor struct {
WhiteDoctorId int64 `gorm:"column:white_doctor_id;type:bigint(19);primary_key;comment:主键id" json:"white_doctor_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:关联用户id" json:"user_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"status"`
Model
User []*User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *ProjectPlatformDoctor) TableName() string {
return "project_platform_doctor"
}
func (m *ProjectPlatformDoctor) BeforeCreate(tx *gorm.DB) error {
if m.WhiteDoctorId == 0 {
m.WhiteDoctorId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDynamic 关联平台-白名单-动态
type ProjectPlatformDynamic struct {
WhiteDynamicId int64 `gorm:"column:white_dynamic_id;type:bigint(19);primary_key;comment:主键id" json:"white_dynamic_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
DynamicType string `gorm:"column:dynamic_type;type:varchar(50);comment:动态类型area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"dynamic_type"`
Status int `gorm:"column:status;type:tinyint(1);comment:状态1:正常 2:禁用)" json:"status"`
Model
ProjectPlatformDynamicItem []*ProjectPlatformDynamicItem `gorm:"foreignKey:WhiteDynamicId;references:white_dynamic_id" json:"project_platform_dynamic_item"`
}
func (m *ProjectPlatformDynamic) TableName() string {
return "project_platform_dynamic"
}
func (m *ProjectPlatformDynamic) BeforeCreate(tx *gorm.DB) error {
if m.WhiteDynamicId == 0 {
m.WhiteDynamicId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDynamicItem 关联平台-白名单-动态-明细
type ProjectPlatformDynamicItem struct {
ItemId int64 `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
WhiteDynamicId int64 `gorm:"column:white_dynamic_id;type:bigint(19);comment:关联动态白名单id;NOT NULL" json:"white_dynamic_id"`
ItemValue string `gorm:"column:item_value;type:varchar(255);comment:明细值area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"item_value"`
Model
}
func (m *ProjectPlatformDynamicItem) TableName() string {
return "project_platform_dynamic_item"
}
func (m *ProjectPlatformDynamicItem) BeforeCreate(tx *gorm.DB) error {
if m.ItemId == 0 {
m.ItemId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,34 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformGrade 关联平台-白名单-医院等级
type ProjectPlatformGrade struct {
WhiteGradeId int64 `gorm:"column:white_grade_id;type:bigint(19);primary_key;comment:主键id" json:"white_grade_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
Grade string `gorm:"column:grade;type:varchar(100);comment:等级(次字段存疑,等确定医院等级后修改);NOT NULL" json:"grade"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"status"`
Model
}
func (m *ProjectPlatformGrade) TableName() string {
return "project_platform_grade"
}
func (m *ProjectPlatformGrade) BeforeCreate(tx *gorm.DB) error {
if m.WhiteGradeId == 0 {
m.WhiteGradeId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformHospital 关联平台-白名单-医院
type ProjectPlatformHospital struct {
WhiteHospitalId int64 `gorm:"column:white_hospital_id;type:bigint(19);primary_key;comment:主键id" json:"white_hospital_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:医院id;NOT NULL" json:"hospital_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态1:正常 2:禁用)" json:"status"`
Model
BasicHospital []*BasicHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"basic_hospital"`
}
func (m *ProjectPlatformHospital) TableName() string {
return "project_platform_hospital"
}
func (m *ProjectPlatformHospital) BeforeCreate(tx *gorm.DB) error {
if m.WhiteHospitalId == 0 {
m.WhiteHospitalId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

39
api/model/RecordScore.go Normal file
View File

@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// RecordScore 积分发放记录
type RecordScore struct {
ScoreId int64 `gorm:"column:score_id;type:bigint(19);primary_key;comment:主键id" json:"score_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id" json:"platform_id"`
UserIden string `gorm:"column:user_iden;type:varchar(100);comment:用户标识(用于区分不同平台用户)" json:"user_iden"`
UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"`
Type int `gorm:"column:type;type:tinyint(1);default:1;comment:积分类型1:完成阅读 2:阅读时间满足 3:优质留言 4:再次优质留言 " json:"type"`
NodeName string `gorm:"column:node_name;type:varchar(50);comment:获取积分节点名称(如:阅读时间足够)" json:"node_name"`
Score int `gorm:"column:score;type:int(5);comment:积分" json:"score"`
Model
}
func (m *RecordScore) TableName() string {
return "record_score"
}
func (m *RecordScore) BeforeCreate(tx *gorm.DB) error {
if m.ScoreId == 0 {
m.ScoreId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

46
api/model/User.go Normal file
View File

@ -0,0 +1,46 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// User 用户表
type User struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
UserIden string `gorm:"column:user_iden;type:varchar(50);comment:第三方平台唯一标识" json:"user_iden"`
UserName string `gorm:"column:user_name;type:varchar(200);comment:用户名称" json:"user_name"`
UserMobile string `gorm:"column:user_mobile;type:varchar(20);comment:手机号" json:"user_mobile"`
MobileEncryption string `gorm:"column:mobile_encryption;type:varchar(100);comment:手机号加密" json:"mobile_encryption"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态0:禁用 1:正常 2:删除)" json:"status"`
RegisterSource int `gorm:"column:register_source;type:tinyint(1);default:1;comment:注册来源1:未知 2:app用户 3:佳动例)" json:"register_source"`
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台标识" json:"union_id"`
Sex int `gorm:"column:sex;type:tinyint(1);default:0;comment:性别0:未知 1:男 2:女)" json:"sex"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Title int `gorm:"column:title;type:tinyint(1);comment:医生职称1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)" json:"title"`
DepartmentName string `gorm:"column:department_name;type:varchar(100);comment:科室名称" json:"department_name"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:所属医院id" json:"hospital_id"`
Address string `gorm:"column:address;type:varchar(255);comment:医生地址" json:"address"`
Model
Hospital *BasicHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"hospital"`
}
func (m *User) TableName() string {
return "user"
}
func (m *User) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// UserAnswerRecords 用户答题记录表
type UserAnswerRecords struct {
CaseUserQuestionId int64 `gorm:"column:case_user_question_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_question_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Answer string `gorm:"column:answer;type:varchar(255);comment:答案" json:"answer"`
IsTrue int `gorm:"column:is_true;type:tinyint(1);comment:是否正确0:否 1:是)" json:"is_true"`
Model
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
}
func (m *UserAnswerRecords) TableName() string {
return "user_answer_records"
}
func (m *UserAnswerRecords) BeforeCreate(tx *gorm.DB) error {
if m.CaseUserQuestionId == 0 {
m.CaseUserQuestionId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

87
api/model/model.go Normal file
View File

@ -0,0 +1,87 @@
package model
import (
"database/sql/driver"
"errors"
"fmt"
"gorm.io/gorm"
"strings"
"time"
)
type Model struct {
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
}
// LocalTime 自定义数据类型
type LocalTime time.Time
func (t *LocalTime) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
return nil
}
var err error
// 前端接收的时间字符串
str := string(data)
// 去除接收的str收尾多余的"
timeStr := strings.Trim(str, "\"")
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
*t = LocalTime(t1)
return err
}
func (t LocalTime) MarshalJSON() ([]byte, error) {
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
return []byte(formatted), nil
}
func (t LocalTime) Value() (driver.Value, error) {
// MyTime 转换成 time.Time 类型
tTime := time.Time(t)
return tTime.Format("2006-01-02 15:04:05"), nil
}
func (t *LocalTime) Scan(v interface{}) error {
switch vt := v.(type) {
case time.Time:
// 字符串转成 time.Time 类型
*t = LocalTime(vt)
default:
return errors.New("类型处理错误")
}
return nil
}
func (t *LocalTime) String() string {
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
}
func (t *LocalTime) IsEmpty() bool {
return time.Time(*t).IsZero()
}
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
if page <= 0 {
page = 1
}
switch {
case pageSize > 100:
pageSize = 100
case pageSize <= 0:
pageSize = 10
}
offset := (page - 1) * pageSize
return db.Offset(offset).Limit(pageSize)
}
}

13
api/requests/Case.go Normal file
View File

@ -0,0 +1,13 @@
package requests
type CaseRequest struct {
GetCasePage // 获取列表-分页
}
// GetCasePage 获取列表-分页
type GetCasePage struct {
Page int `json:"page" form:"page" label:"页码"`
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
PlatformId int64 `json:"platform_id" form:"platform_id" label:"平台id"`
Keyword string `json:"keyword" form:"keyword" label:"关键词"`
}

12
api/requests/Project.go Normal file
View File

@ -0,0 +1,12 @@
package requests
type ProjectRequest struct {
GetProjectPage // 获取列表-分页
}
// GetProjectPage 获取列表-分页
type GetProjectPage struct {
Page int `json:"page" form:"page" label:"页码"`
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
PlatformId int64 `json:"platform_id" form:"platform_id" label:"平台id"`
}

27
api/requests/Res.go Normal file
View File

@ -0,0 +1,27 @@
package requests
type ResRequest struct {
GetResProjectList // 获取项目列表
GetResCaseList // 获取病例列表
GetResCaseRecordList // 病例领取记录
}
// GetResProjectList 获取项目列表
type GetResProjectList struct {
PlatformId int64 `json:"platform_id" form:"platform_id" label:"平台id"`
}
// GetResCaseList 获取列表
type GetResCaseList struct {
PlatformId int64 `json:"platform_id" form:"platform_id" label:"平台id"`
Keyword string `json:"keyword" form:"keyword" label:"关键词"`
}
// GetResCaseRecordList 病例领取记录
type GetResCaseRecordList struct {
PlatformId int64 `json:"platform_id" form:"platform_id" label:"平台id"`
ProjectId string `json:"project_id" form:"project_id" label:"项目标识" validate:"required"`
Pindex int `json:"pindex" form:"pindex" label:"页码"`
StartTime string `json:"starttime" form:"starttime" label:"开始时间"`
EndTime string `json:"endtime" form:"endtime" label:"结束时间"`
}

1
api/requests/ResCase.go Normal file
View File

@ -0,0 +1 @@
package requests

View File

@ -0,0 +1 @@
package requests

4
api/requests/base.go Normal file
View File

@ -0,0 +1,4 @@
package requests
type Requests struct {
}

View File

@ -0,0 +1,52 @@
package responses
import (
"case-open-api/consts"
"github.com/gin-gonic/gin"
"net/http"
)
type res struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Message string `json:"message"`
}
func result(code int, data interface{}, msg string, c *gin.Context) {
//if data == nil {
// data = gin.H{}
//}
c.JSON(http.StatusOK, res{
code,
data,
msg,
})
}
func Ok(c *gin.Context) {
result(consts.HttpSuccess, map[string]interface{}{}, "成功", c)
}
func OkWithMessage(message string, c *gin.Context) {
result(consts.HttpSuccess, map[string]interface{}{}, message, c)
}
func OkWithData(data interface{}, c *gin.Context) {
result(consts.HttpSuccess, data, "成功", c)
}
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
result(consts.HttpSuccess, data, message, c)
}
func Fail(c *gin.Context) {
result(consts.HttpError, map[string]interface{}{}, "失败", c)
}
func FailWithMessage(message string, c *gin.Context) {
result(consts.HttpError, map[string]interface{}{}, message, c)
}
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
result(consts.HttpError, data, message, c)
}

120
api/router/router.go Normal file
View File

@ -0,0 +1,120 @@
package router
import (
"case-open-api/api/controller"
"case-open-api/api/exception"
"case-open-api/api/middlewares"
"case-open-api/config"
"case-open-api/consts"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
// Init 初始化路由
func Init() *gin.Engine {
r := gin.New()
// 环境设置
if config.C.Env == "prod" {
gin.SetMode(gin.ReleaseMode)
}
// 获取请求参数中间件-json格式下会导致接口获取不到请求数据
r.Use(middlewares.RequestParamsMiddleware())
// 日志中间件
r.Use(middlewares.Logrus())
// 异常
r.Use(gin.Recovery())
// 404处理
r.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
method := c.Request.Method
c.JSON(http.StatusNotFound, gin.H{
"msg": fmt.Sprintf("%s %s not found", method, path),
"code": consts.ClientHttpNotFound,
"data": "",
})
})
// 异常处理
r.Use(exception.Recover())
// 跨域处理
r.Use(middlewares.Cors())
// 加载基础路由
api := controller.Api{}
// 公开路由-不验证权限
publicRouter(r, api)
// 验证权限
r.Use(middlewares.Auth())
// 私有路由-验证权限
privateRouter(r, api)
// 公共路由-验证权限
adminRouter(r, api)
// 基础数据-验证权限
basicRouter(r, api)
return r
}
// publicRouter 公开路由-不验证权限
func publicRouter(r *gin.Engine, api controller.Api) {
}
// adminRouter 公共路由-验证权限
func adminRouter(r *gin.Engine, api controller.Api) {
}
// basicRouter 基础数据-验证权限
func basicRouter(r *gin.Engine, api controller.Api) {
}
// privateRouter 私有路由-验证权限
func privateRouter(r *gin.Engine, api controller.Api) {
// 佳动例
resGroup := r.Group("/res")
{
// 项目
resProjectGroup := resGroup.Group("/project")
{
// 获取列表
resProjectGroup.GET("/list", api.Res.GetResProjectList)
}
// 病例
resCaseGroup := resGroup.Group("/case")
{
// 获取列表
resCaseGroup.GET("/list", api.Res.GetResCaseList)
// 病例领取记录
resCaseGroup.GET("/record", api.Res.GetResCaseRecordList)
}
}
// 项目
projectGroup := r.Group("/project")
{
// 获取列表-分页
projectGroup.GET("/page", api.Project.GetProjectPage)
}
// 病例
caseGroup := r.Group("/case")
{
// 获取列表-分页
caseGroup.GET("/page", api.Case.GetCasePage)
}
}

22
api/service/Case.go Normal file
View File

@ -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
}

4
api/service/Project.go Normal file
View File

@ -0,0 +1,4 @@
package service
type ProjectService struct {
}

View File

@ -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
}

35
api/service/Public.go Normal file
View File

@ -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
}

57
api/service/User.go Normal file
View File

@ -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
}

73
config.yaml Normal file
View File

@ -0,0 +1,73 @@
port: 8513 # 启动端口
env: dev # 环境配置
snowflake: 1 # 雪花算法机器id
domain-name: "https://dev-caseplatform.igandan.com/web"
# [数据库配置]
mysql:
host: '42.193.16.243'
username: root
password: 'gdxz123456^%$d'
port: 30001
db-name: case
max-idle-cons: 5
max-open-cons: 20
debug: true
log:
file-path: "./log/"
file-name: "case-open-api.log"
# [redis]
redis:
host: '139.155.127.177'
port: 30002
password: gdxz2022&dj.
pool-size: 100
db: 9
# [jwt]
jwt:
sign-key: 123456899 # 私钥
ttl : 72 # 过期时间 小时
algo : HS256 # 加密方式
oss:
oss-access-key: LTAI5tKmFrVCghcxX7yHyGhm
oss-access-key-secret: q1aiIZCJJuf92YbKk2cSXnPES4zx26
oss-bucket: dev-hepa
oss-endpoint: oss-cn-beijing.aliyuncs.com
oss-custom-domain-name: https://dev-hepa.oss-cn-beijing.aliyuncs.com
# [阿里大鱼短信]
dysms:
dysms-access-key: LTAI4GGygjsKhyBwvvC3CghV
dysms-access-secret: rcx7lO9kQxG10m8NqNPEfEtT9IS8EI
# [微信]
wechat:
app-id: wx68affaa9d23528f8
app-secret: 2963c90242ddb2421c939591ad9e903d
test-pay-app-id: wxa4132ef4701ac5e4
single-pay-notify-url: callback/wxpay/single # 单项支付回调地址
single-refund-notify-url: callback/wxpay/single/refund # 单项退款回调地址
member-pay-notify-url: callback/wxpay/member # 会员支付回调地址
member-refund-notify-url: callback/wxpay/member/refund # 会员退款回调地址
notify-domain: https://dev-hepa.igandan.com/api/
pay-1281030301:
mch-id: 1281030301
v3-api-secret: sB2tCkT70uwEy7cQCu1llA6nilTbek6F
mch-certificate-serial-number: 3D1685894CEDD41753A470211F975D40AE1375F5
platform-certs: extend/weChat/certs/1281030301/wechatpay_5B5C8A69CC86D1127F6B6AA06AAAF10531EEFE90.pem
private-key: extend/weChat/certs/1281030301/apiclient_key.pem
certificate: extend/weChat/certs/1281030301/apiclient_cert.pem
# [app]
app:
apiUrl: https://dev-wx.igandan.com
secretKey: RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^
imagePrefix: https://dev-doc.igandan.com/app
platform: suanyisuan

9
config/amqp.go Normal file
View File

@ -0,0 +1,9 @@
package config
type Amqp struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 服务器端口
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
User string `mapstructure:"user" json:"user" yaml:"user"`
Vhost string `mapstructure:"vhost" json:"vhost" yaml:"vhost"`
}

8
config/app.go Normal file
View File

@ -0,0 +1,8 @@
package config
type App struct {
ApiUrl string `mapstructure:"apiUrl" json:"apiUrl" yaml:"apiUrl"`
SecretKey string `mapstructure:"secretKey" json:"secretKey" yaml:"secretKey"`
ImagePrefix string `mapstructure:"imagePrefix" json:"imagePrefix" yaml:"imagePrefix"`
Platform string `mapstructure:"platform" json:"platform" yaml:"platform"`
}

18
config/config.go Normal file
View File

@ -0,0 +1,18 @@
package config
var C Config
type Config struct {
Port int `mapstructure:"port" json:"port" yaml:"port"`
Env string `mapstructure:"env" json:"Env" yaml:"Env"`
DomainName string `mapstructure:"domain-name" json:"domain-name" yaml:"domain-name"`
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Log Log `mapstructure:"log" json:"log" yaml:"log"`
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
Jwt Jwt `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Oss Oss `mapstructure:"oss" json:"oss" yaml:"oss"`
Snowflake int64 `mapstructure:"snowflake" json:"snowflake" yaml:"snowflake"`
Dysms Dysms `mapstructure:"dysms" json:"dysms" yaml:"dysms"`
Wechat Wechat `mapstructure:"wechat" json:"wechat" yaml:"wechat"`
App App `mapstructure:"app" json:"app" yaml:"app"`
}

6
config/dysms.go Normal file
View File

@ -0,0 +1,6 @@
package config
type Dysms struct {
DysmsAccessKey string `mapstructure:"dysms-access-key" json:"dysms-access-key" yaml:"dysms-access-key"`
DysmsAccessSecret string `mapstructure:"dysms-access-secret" json:"dysms-access-secret" yaml:"dysms-access-secret"`
}

7
config/jwt.go Normal file
View File

@ -0,0 +1,7 @@
package config
type Jwt struct {
SignKey string `mapstructure:"sign-key" json:"sign-key" yaml:"sign-key"` // 私钥
Ttl int `mapstructure:"ttl" json:"ttl" yaml:"ttl"` // 过期时间 小时
Algo string `mapstructure:"algo" json:"algo" yaml:"algo"` // 加密方式
}

6
config/log.go Normal file
View File

@ -0,0 +1,6 @@
package config
type Log struct {
FilePath string `mapstructure:"file-path" json:"file-path" yaml:"file-path"` // 日志目录
FileName string `mapstructure:"file-name" json:"file-name" yaml:"file-name"` // 日志名称
}

12
config/mysql.go Normal file
View File

@ -0,0 +1,12 @@
package config
type Mysql struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
DbName string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
MaxIdleConns int `mapstructure:"max-idle-cons" json:"MaxIdleConns" yaml:"max-idle-cons"` // 空闲中的最大连接数
MaxOpenConns int `mapstructure:"max-open-cons" json:"MaxOpenConns" yaml:"max-open-cons"` // 打开到数据库的最大连接数
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"` // 是否开启Gorm全局日志
}

9
config/oss.go Normal file
View File

@ -0,0 +1,9 @@
package config
type Oss struct {
OssAccessKey string `mapstructure:"oss-access-key" json:"oss-access-key" yaml:"oss-access-key"`
OssAccessKeySecret string `mapstructure:"oss-access-key-secret" json:"oss-access-key-secret" yaml:"oss-access-key-secret"`
OssBucket string `mapstructure:"oss-bucket" json:"oss-bucket" yaml:"oss-bucket"`
OssEndpoint string `mapstructure:"oss-endpoint" json:"oss-endpoint" yaml:"oss-endpoint"`
OssCustomDomainName string `mapstructure:"oss-custom-domain-name" json:"oss-custom-domain-name" yaml:"oss-custom-domain-name"`
}

9
config/redis.go Normal file
View File

@ -0,0 +1,9 @@
package config
type Redis struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 服务器端口
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
PoolSize int `mapstructure:"pool-size" json:"pool-size" yaml:"pool-size"` // 连接池大小
Db int `mapstructure:"db" json:"db" yaml:"db"` // 数据库
}

23
config/wechat.go Normal file
View File

@ -0,0 +1,23 @@
package config
type Wechat struct {
AppId string `mapstructure:"app-id" json:"app-id" yaml:"app-id"`
AppSecret string `mapstructure:"app-secret" json:"app-secret" yaml:"app-secret"`
TestPayAppId string `mapstructure:"test-pay-app-id" json:"test-pay-app-id" yaml:"test-pay-app-id"`
SinglePayNotifyUrl string `mapstructure:"single-pay-notify-url" json:"single-pay-notify-url" yaml:"single-pay-notify-url"` // 单项支付回调地址
SingleRefundNotifyUrl string `mapstructure:"single-refund-notify-url" json:"single-refund-notify-url" yaml:"single-refund-notify-url"` // 单项退款回调地址
MemberPayNotifyUrl string `mapstructure:"member-pay-notify-url" json:"member-pay-notify-url" yaml:"member-pay-notify-url"` // 会员支付回调地址
MemberRefundNotifyUrl string `mapstructure:"member-refund-notify-url" json:"member-refund-notify-url" yaml:"member-refund-notify-url"` // 会员退款回调地址
NotifyDomain string `mapstructure:"notify-domain" json:"notify-domain" yaml:"notify-domain"`
Pay1281030301 Pay1281030301 `mapstructure:"pay-1281030301" json:"pay-1281030301" yaml:"pay-1281030301"`
}
// Pay1281030301 app
type Pay1281030301 struct {
MchId string `mapstructure:"mch-id" json:"mch-id" yaml:"mch-id"` // 商户号
V3ApiSecret string `mapstructure:"v3-api-secret" json:"v3-api-secret" yaml:"v3-api-secret"` // 商户APIv3密钥
MchCertificateSerialNumber string `mapstructure:"mch-certificate-serial-number" json:"mch-certificate-serial-number" yaml:"mch-certificate-serial-number"` // 商户证书序列号
PlatformCerts string `mapstructure:"platform-certs" json:"platform-certs" yaml:"platform-certs"` // 平台证书
PrivateKey string `mapstructure:"private-key" json:"private-key" yaml:"private-key"`
Certificate string `mapstructure:"certificate" json:"certificate" yaml:"certificate"`
}

Some files were not shown because too many files have changed in this diff Show More