123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package system
- import (
- "context"
- "hongze/hrms_api/global"
- "hongze/hrms_api/models/base"
- )
- // 部门表
- type SysDept struct {
- DeptId int64 `gorm:"primaryKey;column:dept_id" json:"dept_id"`
- ParentId int64 `gorm:"column:parent_id" json:"parent_id"` //父级部门ID
- DeptName string `gorm:"column:dept_name" json:"dept_name"` //部门名称
- RootId int64 `gorm:"column:root_id" json:"root_id"` //顶层部门ID
- Sort int8 `gorm:"column:sort" json:"sort"` //排序序号
- Level int8 `gorm:"column:level" json:"level"` //当前层级
- base.TimeBase
- }
- // TableName get sql table name.获取数据库表名
- func (d *SysDept) TableName() string {
- return "sys_dept"
- }
- // SysDeptColumns get sql column name.获取数据库列名
- var SysDeptColumns = struct {
- DeptID string
- ParentID string
- DeptName string
- CreateTime string
- ModifyTime string
- }{
- DeptID: "dept_id",
- ParentID: "parent_id",
- DeptName: "dept_name",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- // SelectPage 分页查询
- func (d *SysDept) SelectPage(page base.IPage, condition string, pars []interface{}) (count int64, results []SysDept, err error) {
- results = make([]SysDept, 0)
- query := global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(SysDept{}).Where(condition, pars...)
- query.Count(&count)
- if len(page.GetOrderItemsString()) > 0 {
- query = query.Order(page.GetOrderItemsString())
- }
- err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
- return
- }
- func (d *SysDept) GetDeptByName(name string) (list []*SysDept, err error) {
- err = global.DEFAULT_MYSQL.Model(d).Where("dept_name like ?", name).Find(&list).Error
- return
- }
- func (d *SysDept) GetDeptByDeptId(deptId int64) (item *SysDept, err error) {
- err = global.DEFAULT_MYSQL.Model(d).Where("dept_id = ?", deptId).First(&item).Error
- return
- }
- func (d *SysDept) GetDeptListByCondition(condition string, pars []interface{}, orderStr string) (list []*SysDept, err error) {
- list = make([]*SysDept, 0)
- if orderStr == "" {
- orderStr = "sort asc, create_time desc"
- }
- err = global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(d).
- Where(condition, pars...).Order(orderStr).Find(&list).Error
- return
- }
- type SysDeptAddReq struct {
- ParentId int64 `json:"parent_id"` // id
- DeptName string `json:"dept_name" binding:"required"` // 部门名称
- Sort int8 `json:"sort"`
- }
- type SysDeptEditReq struct {
- DeptId int64 `json:"dept_id" binding:"required,gte=1"`
- ParentId int64 `json:"parent_id"` // id
- DeptName string `json:"dept_name" binding:"required"` // 部门名称
- Sort int8 `json:"sort"`
- }
- // 新增
- func (d *SysDept) Add() (err error) {
- err = global.DEFAULT_MYSQL.Create(d).Error
- return
- }
- // 删除
- func (d *SysDept) DeleteByCondition(condition string, pars []interface{}) (err error) {
- err = global.DEFAULT_MYSQL.Where(condition, pars...).Delete(d).Error
- return
- }
- // 修改
- func (d *SysDept) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(d).Select(updateCols).Updates(d).Error
- return
- }
- type DeptListReq struct {
- base.PageReq
- DeptName string `json:"dept_name" form:"dept_name"` //部门名称
- }
- type DeptListItemResp struct {
- DeptId int64 `json:"dept_id"`
- ParentId int64 `json:"parent_id"` // id
- DeptName string `json:"dept_name"` // 部门名称
- Sort int8 `json:"sort"` //排序
- CreateTime string `json:"create_time"` //创建时间
- ModifyTime string `json:"modify_time"` //最后更新时间
- Children []*DeptListItemResp
- }
- type DelSysDeptReq struct {
- DeptId int64 `json:"dept_id" binding:"required,gte=1"`
- }
- type DeptAdminListTmpItem struct {
- AdminId uint64 `json:"admin_id"` //账号id
- RealName string `json:"real_name"` //真实姓名
- DeptId int64 `json:"dept_id"`
- ParentId int64 `json:"parent_id"` // id
- DeptName string `json:"dept_name"` // 部门名称
- Sort int8 `json:"sort"` //排序
- }
- type DeptAdminListItem struct {
- AdminId uint64 `json:"admin_id"` //账号id
- Name string `json:"name"` //账号名
- DeptId int64 `json:"dept_id"`
- ParentId int64 `json:"parent_id"` // id
- Sort int8 `json:"sort"` //排序
- Children []*DeptAdminListItem
- }
|