123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package models
- import (
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "gorm.io/gorm"
- "strings"
- "time"
- )
- const (
- AssessmentResearcherDisabled = 0
- AssessmentResearcherEnabled = 1
- )
- // AssessmentResearcher 考核研究员表
- type AssessmentResearcher struct {
- AssessmentResearcherId int `gorm:"column:assessment_researcher_id;primaryKey;autoIncrement"`
- AdminId int `description:"系统用户ID"`
- RealName string `description:"用户姓名"`
- Enabled int `description:"状态:0-禁用;1-正常"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- func (m *AssessmentResearcher) TableName() string {
- return "assessment_researcher"
- }
- type AssessmentResearcherCols struct {
- PrimaryId string
- AdminId string
- RealName string
- Enabled string
- CreateTime string
- ModifyTime string
- }
- func (m *AssessmentResearcher) Cols() AssessmentResearcherCols {
- return AssessmentResearcherCols{
- PrimaryId: "assessment_researcher_id",
- AdminId: "admin_id",
- RealName: "real_name",
- Enabled: "enabled",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- }
- func (m *AssessmentResearcher) Create() (err error) {
- err = global.DEFAULT_DB.Create(m).Error
- return
- }
- func (m *AssessmentResearcher) CreateMulti(items []*AssessmentResearcher) (err error) {
- if len(items) == 0 {
- return
- }
- err = global.DEFAULT_DB.CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- func (m *AssessmentResearcher) Update(cols []string) (err error) {
- err = global.DEFAULT_DB.Select(cols).Updates(m).Error
- return
- }
- func (m *AssessmentResearcher) Remove() (err error) {
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
- err = global.DEFAULT_DB.Exec(sql, m.AssessmentResearcherId).Error
- return
- }
- func (m *AssessmentResearcher) MultiRemove(ids []int) (err error) {
- if len(ids) == 0 {
- return
- }
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
- err = global.DEFAULT_DB.Exec(sql, ids).Error
- return
- }
- func (m *AssessmentResearcher) RemoveByCondition(condition string, pars []interface{}) (err error) {
- if condition == "" {
- return
- }
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
- err = global.DEFAULT_DB.Exec(sql, pars...).Error
- return
- }
- func (m *AssessmentResearcher) GetItemById(primaryId int) (item *AssessmentResearcher, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
- err = global.DEFAULT_DB.Raw(sql, primaryId).First(&item).Error
- return
- }
- func (m *AssessmentResearcher) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *AssessmentResearcher, err error) {
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
- err = global.DEFAULT_DB.Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *AssessmentResearcher) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *AssessmentResearcher) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*AssessmentResearcher, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *AssessmentResearcher) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*AssessmentResearcher, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
- pars = append(pars, startSize, pageSize)
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
- return
- }
- // AfterUpdate 同步更新其他表冗余
- func (m *AssessmentResearcher) AfterUpdate(tx *gorm.DB) (err error) {
- if tx.Statement.Changed(m.Cols().RealName) {
- fmt.Println(111)
- formOb := new(AssessmentForm)
- err = tx.Model(formOb).Where(fmt.Sprintf("%s = ?", formOb.Cols().ResearcherId), m.AssessmentResearcherId).Update(formOb.Cols().ResearcherName, m.RealName).Error
- fmt.Println("AfterUpdate", err)
- }
- return
- }
- // AssessmentResearcherAddReq 新增研究员请求
- type AssessmentResearcherAddReq struct {
- AdminId int `description:"用户ID"`
- ViewAdminIds []int `description:"查看权限用户IDs"`
- AssessmentAdminIds []int `description:"统计权限用户IDs"`
- }
- // AssessmentResearcherEditReq 编辑研究员请求
- type AssessmentResearcherEditReq struct {
- AssessmentResearcherId int `description:"研究员ID"`
- AssessmentResearcherAddReq
- }
- // AssessmentResearcherRemoveReq 删除研究员请求
- type AssessmentResearcherRemoveReq struct {
- AssessmentResearcherId int `description:"研究员ID"`
- }
- // AssessmentResearcherPageListReq 研究员列表
- type AssessmentResearcherPageListReq struct {
- PageSize int `form:"PageSize"`
- CurrentIndex int `form:"CurrentIndex"`
- RealName string `form:"RealName" description:"用户姓名"`
- AssessmentResearcherIds string `form:"AssessmentResearcherIds" description:"研究员IDs"`
- OnlyEnabled bool `form:"OnlyEnabled" description:"是否仅显示启用:true-是"`
- ResearcherAuthType int `form:"ResearcherAuthType" description:"权限类型:0-全部;1-当前用户有查看权限的;2-当前用户有统计权限的"`
- }
- // AssessmentResearcherPageListResp 研究员列表响应
- type AssessmentResearcherPageListResp struct {
- List []*AssessmentResearcherDetail
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type AssessmentResearcherDetail struct {
- AssessmentResearcherId int `description:"研究员ID"`
- AdminId int `description:"用户ID"`
- RealName string `description:"用户姓名"`
- Enabled int `description:"状态:0-禁用;1-正常"`
- ViewAdmins []AssessmentResearcherDetail `description:"查看权限用户"`
- AssessmentAdmins []AssessmentResearcherDetail `description:"统计权限用户"`
- }
- func (m *AssessmentResearcher) Format2Detail() (item *AssessmentResearcherDetail) {
- item = new(AssessmentResearcherDetail)
- item.AssessmentResearcherId = m.AssessmentResearcherId
- item.AdminId = m.AdminId
- item.RealName = m.RealName
- item.Enabled = m.Enabled
- return
- }
|