board.go 10.8 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
)

//车间看板(生产)

// 车间描述
func (svr *CommonStatisticsService) WorkshopDesc() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	workshopDesc, err := boardShowData.WorkshopDesc(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	//在岗人数
	onDuty, err := boardShowData.OnDutyCount(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	result := map[string]interface{}{
		"lines":        workshopDesc.Lines,
		"uname":        workshopDesc.Uname,
		"workon":       workshopDesc.Workon,
		"workshopName": workshopDesc.WorkshopName,
		"onDuty":       onDuty,
	}
	return result, nil
}

// 员工效率排名
func (svr *CommonStatisticsService) EmployeeWorkpieceRatio() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.EmployeeWorkpieceRatio(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}

// TimeSectionProductRecord 时段产能
func (svr *CommonStatisticsService) TimeSectionProductRecord() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	// todo
	result, err := boardShowData.TimeSectionProductRecord(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
		7, 8,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}

// TopShow 今日昨日历史最佳
func (svr *CommonStatisticsService) TopShow() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.TopShow(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return result, nil
}

// ProportionOfSecondLevel 二级品占比
func (svr *CommonStatisticsService) ProportionOfSecondLevel() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.ProportionOfSecondLevel(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}

// SectionProductInfo 工段生产信息
func (svr *CommonStatisticsService) SectionProductInfo() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.SectionProductInfo(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}

// WorkshopPlanCompletionCurrent 当前计划达成率
func (svr *CommonStatisticsService) WorkshopPlanCompletionCurrent() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.WorkshopPlanCompletionCurrent(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"rate": result,
	}
	return listData, nil
}

// WorkshopPlanCompletion5Day 近5天计划达成率
func (svr *CommonStatisticsService) WorkshopPlanCompletion5Day() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.WorkshopPlanCompletion5Day(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}

// 批次产能
func (svr *CommonStatisticsService) ProductPlan() (interface{}, error) {
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
	boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
	result, err := boardShowData.ProductPlan(
		constant.MANUFACTURE_DEFAULT_COMPANYID,
		constant.MANUFACTURE_DEFAULT_ORGID,
		constant.MANUFACTURE_DEFAULT_WORKSHOPID,
	)
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.CommitTransaction(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := map[string]interface{}{
		"list": result,
	}
	return listData, nil
}