1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package staff
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "smart-site-management/errors"
- "smart-site-management/model"
- "smart-site-management/pb/v1"
- "smart-site-management/utils"
- )
- func StaffList(ctx context.Context, req *v1.StaffListRequest) (reply *v1.StaffListReply, err error) {
- reply = &v1.StaffListReply{}
- if req.ProjectId == 0 {
- return nil,errors.ParamsError
- }
- if req.Page < 1 {
- req.Page =1
- }
- if req.PageSize == 0 {
- req.PageSize = 10
- }
- p := &model.TStaff{}
- list, total, err := p.List(database.DB(), req.Filter, req.ProjectId, req.Page, req.PageSize)
- if err != nil {
- return nil, errors.DataBaseError
- }
- reply.Total = total
- reply.PageSize = req.PageSize
- reply.Page = req.Page
- if total == 0 {
- return reply, nil
- }
- workTypeMap, err := model.GetWorkTypeMap(database.DB())
- if err != nil {
- return nil, errors.DataBaseError
- }
- staffTypeMap, err := model.GetStaffTypeMap(database.DB())
- if err != nil {
- return nil, errors.DataBaseError
- }
- reply.List = make([]*v1.StaffListItem, len(list))
- for i, v := range list {
- item := &v1.StaffListItem{}
- utils.StructCopy(item, &list[i], "")
- item.Id = v.Id
- item.CreatedAt = v.CreatedAt.Format("2006-01-02 15:04:05")
- item.WorkType = workTypeMap[v.WorkType]
- item.StaffType = staffTypeMap[v.StaffType]
- item.Gender = "男"
- if v.Gender == 2 {
- item.Gender = "女"
- }
- reply.List[i] = item
- }
- return reply, nil
- }
|