123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "smart-site-management-gateway/errors"
- param_v1 "smart-site-management-gateway/param/v1"
- "smart-site-management-gateway/pb"
- "smart-site-management-gateway/pb/v1"
- "smart-site-management-gateway/utils"
- "github.com/gin-gonic/gin"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "go.uber.org/zap"
- )
- //
- // @Summary 最近考勤数据
- // @Description 最近考勤数据
- // @Tags 人员管理前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.LatestStaffDataResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/last [get]
- func (c *Controller) LatestStaffData(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.LatestStaffDataRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.LatestStaffDataQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.LatestStaffDataResponse{}
- rpcReq := &v1.LatestStaffDataRequest{
- ProjectId: projectId,
- }
- rpcRsp, err := pb.Project.LatestStaffData(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.LatestStaffData"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 工种统计
- // @Description 工种统计
- // @Tags 人员管理前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.StaffWorkTypeStatisticsResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/work_type_statistics [get]
- func (c *Controller) StaffWorkTypeStatistics(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.StaffWorkTypeStatisticsRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.StaffWorkTypeStatisticsResponse{}
- rpcReq := &v1.StaffWorkTypeStatisticsRequest{
- ProjectId: projectId,
- }
- rpcRsp, err := pb.Project.StaffWorkTypeStatistics(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.StaffWorkTypeStatistics"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.WorkTypeStatistics{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 员工类型统计
- // @Description 员工类型统计
- // @Tags 人员管理前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.StaffTypeStatisticsResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/type_statistics [get]
- func (c *Controller) StaffTypeStatistics(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.StaffTypeStatisticsRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.StaffTypeStatisticsResponse{}
- rpcReq := &v1.StaffTypeStatisticsRequest{
- ProjectId: projectId,
- }
- rpcRsp, err := pb.Project.StaffTypeStatistics(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.StaffTypeStatistics"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.StaffTypeStatistics{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 员工按劳务公司统计
- // @Description 员工按劳务公司统计
- // @Tags 人员管理前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Success 200 {object} v1.LaborCompanyStatisticsResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/company_statistics [get]
- func (c *Controller) LaborCompanyStatistics(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.LaborCompanyStatisticsRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.LaborCompanyStatisticsResponse{}
- rpcReq := &v1.LaborCompanyStatisticsRequest{
- ProjectId: projectId,
- }
- rpcRsp, err := pb.Project.LaborCompanyStatistics(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.LaborCompanyStatistics"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.LaborCompanyStatistics{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 员工列表
- // @Description 员工列表
- // @Tags staff
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param filter query string false " 员工姓名或工种或员工类型"
- // @Success 200 {object} v1.StaffListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/list [get]
- func (c *Controller) StaffList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.StaffListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.StaffListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.StaffListResponse{}
- rpcReq := &v1.StaffListRequest{
- ProjectId: projectId,
- Page:req.Page,
- Filter:req.Filter,
- }
- rpcRsp, err := pb.Project.StaffList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.StaffList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.StaffListItem{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 员工考勤
- // @Description 员工考勤
- // @Tags staff
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param start query int64 false " "
- // @Param end query int64 false " "
- // @Param filter query string false " 员工姓名或工种或员工类型"
- // @Success 200 {object} v1.StaffAttendanceResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/staff/attendance [get]
- func (c *Controller) StaffAttendance(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.StaffAttendanceRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.StaffAttendanceQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.StaffAttendanceResponse{}
- rpcReq := &v1.StaffAttendanceRequest{
- ProjectId: projectId,
- Page:req.Page,
- Filter:req.Filter,
- Start:req.Start,
- End:req.End,
- }
- rpcRsp, err := pb.Project.StaffAttendance(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.StaffAttendance"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.StaffAttendanceItem{}
- }
- for i, _ := range resp.Data.List {
- if resp.Data.List[i].List == nil {
- resp.Data.List[i].List = []*v1.StaffAttendanceDesc{}
- }
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|