statistics_controller.go 6.1 KB
package controllers

import (
	"encoding/json"
	"fmt"

	"github.com/astaxie/beego"
	"github.com/linmadan/egglib-go/web/beego/utils"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/service"
)

type StatisticsController struct {
	beego.Controller
}

func (controller *StatisticsController) SystemTaskStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	systemTaskStatisticsCommand := &command.SystemTaskStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemTaskStatisticsCommand)
	data, err := statisticsService.SystemTaskStatistics(systemTaskStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *StatisticsController) PersonTaskStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	personTaskStatisticsCommand := &command.PersonTaskStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), personTaskStatisticsCommand)
	data, err := statisticsService.PersonTaskStatistics(personTaskStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *StatisticsController) PersonSuMoneyStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	personSuMoneyStatisticsCommand := &command.PersonSuMoneyStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), personSuMoneyStatisticsCommand)
	data, err := statisticsService.PersonSuMoneyStatistics(personSuMoneyStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *StatisticsController) PersonNotificationStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	personNotificationStatisticsCommand := &command.PersonNotificationStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), personNotificationStatisticsCommand)
	data, err := statisticsService.PersonNotificationStatistics(personNotificationStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *StatisticsController) SystemSuMoneyStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	systemSuMoneyStatisticsCommand := &command.SystemSuMoneyStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemSuMoneyStatisticsCommand)
	data, err := statisticsService.SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *StatisticsController) SystemCashStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	systemCashStatisticsCommand := &command.SystemCashStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemCashStatisticsCommand)
	data, err := statisticsService.SystemCashStatistics(systemCashStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 获取员工财富值
func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesSuMoneyStatisticsCommand)
	fmt.Print(employeesSuMoneyStatisticsCommand, "\n")
	data, err := statisticsService.EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// 获取员工贡献值
func (controller *StatisticsController) EmployeesContributionsStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand)
	data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

// TODO 合并员工财富值、贡献值排行榜
func (controller *StatisticsController) RankingListStatistics() {
	statisticsService := service.NewStatisticsService(nil)
	employeesRankingListStatisticsCommand := &command.EmployeesRankingListStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesRankingListStatisticsCommand)
	data, err := statisticsService.EmployeesRankingListStatistics(employeesRankingListStatisticsCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}