Files
cas_tt_cloud_backend/app/api/admin/model/manage_company.go

77 lines
2.1 KiB
Go
Raw Normal View History

2021-11-01 11:19:49 +08:00
package model
2021-11-24 09:59:29 +08:00
import (
"SciencesServer/app/common/model"
2022-01-19 10:59:43 +08:00
"SciencesServer/serve/orm"
"fmt"
"time"
2021-11-24 09:59:29 +08:00
)
2021-11-01 11:19:49 +08:00
type ManageCompany struct {
*model.ManageCompany
}
2022-01-19 10:59:43 +08:00
type (
// ManageCompanyInfo 公司企业信息
ManageCompanyInfo struct {
model.Model
Kind model.ManageCompanyKind `json:"kind"`
Name string `json:"name"`
Code string `json:"code"`
2022-01-19 16:03:47 +08:00
Industry string `json:"-"`
2022-01-19 10:59:43 +08:00
Address string `json:"address"`
*model.Examine
CreatedAt time.Time `json:"created_at"`
model.Area
2022-01-19 16:03:47 +08:00
TenantProvince string `json:"-"`
TenantCity string `json:"-"`
}
// ManageCompanyDetail 公司企业信息
ManageCompanyDetail struct {
*model.ManageCompany
2022-01-27 14:50:52 +08:00
//model.Area
2022-01-19 10:59:43 +08:00
}
)
// Company 公司企业信息
2022-01-19 16:03:47 +08:00
func (m *ManageCompany) Company(id uint64) (*ManageCompanyDetail, error) {
2022-01-19 10:59:43 +08:00
db := orm.GetDB().Table(m.TableName()+" AS c").
2022-01-20 09:43:26 +08:00
Select("c.*").
2022-01-27 14:50:52 +08:00
//Joins(fmt.Sprintf("LEFT JOIN %s AS t ON c.tenant_id = t.id", model.NewSysTenant().TableName())).
2022-01-19 10:59:43 +08:00
Where("c.id = ?", id)
2022-01-19 16:03:47 +08:00
out := new(ManageCompanyDetail)
2022-01-19 10:59:43 +08:00
err := db.Scan(out).Error
return out, err
}
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageCompanyInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS c").
2022-01-19 16:03:47 +08:00
Select("c.id", "c.kind", "c.name", "c.code", "c.industry", "c.address", "c.examine_status",
"c.created_at", "c.province", "c.city",
"t.province AS tenant_province", "t.city AS tenant_city").
2022-01-19 10:59:43 +08:00
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON c.tenant_id = t.id", model.NewSysTenant().TableName())).
Where("c.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*ManageCompanyInfo, 0)
2021-11-24 09:59:29 +08:00
2022-01-19 10:59:43 +08:00
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("c.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
2021-11-24 09:59:29 +08:00
}
2021-11-01 11:19:49 +08:00
func NewManageCompany() *ManageCompany {
2022-01-19 10:59:43 +08:00
return &ManageCompany{model.NewManageCompany()}
2021-11-01 11:19:49 +08:00
}