product_group_controller.go 3.9 KB
package controllers

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

type ProductGroupController struct {
	beego.BaseController
}

func (controller *ProductGroupController) CreateProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	createProductGroupCommand := &command.CreateProductGroupCommand{}
	Must(controller.Unmarshal(createProductGroupCommand))
	data, err := productGroupService.CreateProductGroup(ParseOperateInfo(controller.BaseController), createProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) UpdateProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	updateProductGroupCommand := &command.UpdateProductGroupCommand{}
	Must(controller.Unmarshal(updateProductGroupCommand))
	productGroupId, _ := controller.GetInt(":productGroupId")
	updateProductGroupCommand.ProductGroupId = productGroupId
	data, err := productGroupService.UpdateProductGroup(updateProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) GetProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	getProductGroupQuery := &query.GetProductGroupQuery{}
	productGroupId, _ := controller.GetInt(":productGroupId")
	getProductGroupQuery.ProductGroupId = productGroupId
	data, err := productGroupService.GetProductGroup(getProductGroupQuery)
	controller.Response(data, err)
}

func (controller *ProductGroupController) RemoveProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	removeProductGroupCommand := &command.RemoveProductGroupCommand{}
	controller.Unmarshal(removeProductGroupCommand)
	productGroupId, _ := controller.GetInt(":productGroupId")
	removeProductGroupCommand.ProductGroupId = productGroupId
	data, err := productGroupService.RemoveProductGroup(removeProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) BatchRemoveProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	removeProductGroupCommand := &command.BatchRemoveProductGroupCommand{}
	Must(controller.Unmarshal(removeProductGroupCommand))
	data, err := productGroupService.BatchRemoveProductGroup(removeProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) ListProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	listProductGroupQuery := &query.ListProductGroupQuery{}
	offset, _ := controller.GetInt("offset")
	listProductGroupQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductGroupQuery.Limit = limit
	data, err := productGroupService.ListProductGroup(listProductGroupQuery)
	controller.Response(data, err)
}

func (controller *ProductGroupController) SearchProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	cmd := &query.SearchProductGroupQuery{}
	Must(controller.Unmarshal(cmd))
	operateInfo := ParseOperateInfo(controller.BaseController)
	//cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := productGroupService.SearchProductGroup(ParseOperateInfo(controller.BaseController), cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *ProductGroupController) SearchProductGroupEmployees() {
	productGroupService := service.NewProductGroupService(nil)
	cmd := &query.SearchProductGroupEmployeesQuery{}
	Must(controller.Unmarshal(cmd))
	operateInfo := ParseOperateInfo(controller.BaseController)
	cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	_, data, err := productGroupService.SearchProductGroupEmployees(operateInfo, cmd)
	controller.Response(data, err)
}