attendance_controller.go 4.5 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service"
)

type AttendanceController struct {
	beego.BaseController
}

func (controller *AttendanceController) CreateAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	createAttendanceCommand := &command.CreateAttendanceCommand{}
	controller.Unmarshal(createAttendanceCommand)
	data, err := attendanceService.CreateAttendance(ParseOperateInfo(controller.BaseController), createAttendanceCommand)
	controller.Response(data, err)
}

func (controller *AttendanceController) UpdateAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	updateAttendanceCommand := &command.UpdateAttendanceCommand{}
	controller.Unmarshal(updateAttendanceCommand)
	productAttendanceId, _ := controller.GetInt(":productAttendanceId")
	updateAttendanceCommand.ProductAttendanceId = productAttendanceId
	data, err := attendanceService.UpdateAttendance(updateAttendanceCommand)
	controller.Response(data, err)
}

func (controller *AttendanceController) GetAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	getAttendanceQuery := &query.GetAttendanceQuery{}
	productAttendanceId, _ := controller.GetInt(":productAttendanceId")
	getAttendanceQuery.ProductAttendanceId = productAttendanceId
	data, err := attendanceService.GetAttendance(getAttendanceQuery)
	controller.Response(data, err)
}

func (controller *AttendanceController) RemoveAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	removeAttendanceCommand := &command.RemoveAttendanceCommand{}
	controller.Unmarshal(removeAttendanceCommand)
	productAttendanceId, _ := controller.GetInt(":productAttendanceId")
	removeAttendanceCommand.ProductAttendanceId = productAttendanceId
	data, err := attendanceService.RemoveAttendance(removeAttendanceCommand)
	controller.Response(data, err)
}

func (controller *AttendanceController) ListAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	listAttendanceQuery := &query.ListAttendanceQuery{}
	offset, _ := controller.GetInt("offset")
	listAttendanceQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listAttendanceQuery.Limit = limit
	data, err := attendanceService.ListAttendance(listAttendanceQuery)
	controller.Response(data, err)
}

func (controller *AttendanceController) ApproveAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	approveAttendanceCommand := &command.ApproveAttendanceCommand{}
	controller.Unmarshal(approveAttendanceCommand)
	if approveAttendanceCommand.ApproveUserId == 0 {
		operateInfo := ParseOperateInfo(controller.BaseController)
		approveAttendanceCommand.ApproveUserId = operateInfo.UserId
	}
	data, err := attendanceService.ApproveAttendance(approveAttendanceCommand)
	controller.Response(data, err)
}

func (controller *AttendanceController) SearchAttendance() {
	attendanceService := service.NewAttendanceService(nil)
	cmd := &query.SearchAttendanceQuery{}
	controller.Unmarshal(cmd)
	operateInfo := ParseOperateInfo(controller.BaseController)
	//cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := attendanceService.SearchAttendance(operateInfo, cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *AttendanceController) SearchEmployeeAttendanceStatics() {
	attendanceService := service.NewAttendanceService(nil)
	cmd := &query.SearchEmployeeAttendanceQuery{}
	controller.Unmarshal(cmd)
	operateInfo := ParseOperateInfo(controller.BaseController)
	//cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := attendanceService.SearchEmployeeAttendanceStatics(operateInfo, cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *AttendanceController) SearchWorkshopWorkTimeStatics() {
	attendanceService := service.NewAttendanceService(nil)
	cmd := &query.SearchEmployeeAttendanceQuery{}
	controller.Unmarshal(cmd)
	operateInfo := ParseOperateInfo(controller.BaseController)
	//cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := attendanceService.SearchWorkshopWorkTimeStatics(operateInfo, cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}