forked from bullteam/zeus-admin
/
dept.go
66 lines (56 loc) · 1.47 KB
/
dept.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package service
import (
"github.com/CMLiang/zeus-admin/pkg/api/dao"
"github.com/CMLiang/zeus-admin/pkg/api/dto"
"github.com/CMLiang/zeus-admin/pkg/api/log"
"github.com/CMLiang/zeus-admin/pkg/api/model"
)
var deptDao = dao.Dept{}
// DeptService
type DeptService struct {
}
// InfoOfId - get dept info by id
func (us DeptService) InfoOfId(dto dto.GeneralGetDto) model.Department {
return deptDao.Get(dto.Id)
}
// List - users list with pagination
func (us DeptService) List(dto dto.GeneralListDto) ([]model.Department, int64) {
return deptDao.List(dto)
}
// Create - create a new dept
func (us DeptService) Create(dto dto.DeptCreateDto) model.Department {
deptModel := model.Department{
Name: dto.Name,
ParentId: dto.ParentId,
OrderNum: dto.OrderNum,
}
c := deptDao.Create(&deptModel)
if c.Error != nil {
log.Error(c.Error.Error())
}
return deptModel
}
// Update - update dept's information
func (us DeptService) Update(dto dto.DeptEditDto) int64 {
deptModel := model.Department{
Id: dto.Id,
}
c := deptDao.Update(&deptModel, map[string]interface{}{
"name": dto.Name,
//"parentId": dto.ParentId,
"orderNum": dto.OrderNum,
})
return c.RowsAffected
}
// Delete - delete dept
func (us DeptService) Delete(dto dto.GeneralDelDto) int64 {
deptModel := model.Department{
Id: dto.Id,
}
c := deptDao.Delete(&deptModel)
return c.RowsAffected
}
// check - check has member TODO
func (us DeptService) CheckIfPeopleInside(dto dto.GeneralDelDto) int64 {
return 0
}