product_plan_controller.go 4.0 KB
package controllers

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

type ProductPlanController struct {
	beego.BaseController
}

func (controller *ProductPlanController) CreateProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	createProductPlanCommand := &command.CreateProductPlanCommand{}
	controller.Unmarshal(createProductPlanCommand)
	data, err := productPlanService.CreateProductPlan(createProductPlanCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) UpdateProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	updateProductPlanCommand := &command.UpdateProductPlanCommand{}
	controller.Unmarshal(updateProductPlanCommand)
	productPlanId, _ := controller.GetInt(":productPlanId")
	updateProductPlanCommand.ProductPlanId = productPlanId
	data, err := productPlanService.UpdateProductPlan(updateProductPlanCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) GetProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	getProductPlanQuery := &query.GetProductPlanQuery{}
	productPlanId, _ := controller.GetInt(":productPlanId")
	getProductPlanQuery.ProductPlanId = productPlanId
	data, err := productPlanService.GetProductPlan(getProductPlanQuery)
	controller.Response(data, err)
}

func (controller *ProductPlanController) RemoveProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	removeProductPlanCommand := &command.RemoveProductPlanCommand{}
	controller.Unmarshal(removeProductPlanCommand)
	productPlanId, _ := controller.GetInt(":productPlanId")
	removeProductPlanCommand.ProductPlanId = productPlanId
	data, err := productPlanService.RemoveProductPlan(removeProductPlanCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ListProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	listProductPlanQuery := &query.ListProductPlanQuery{}
	offset, _ := controller.GetInt("offset")
	listProductPlanQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductPlanQuery.Limit = limit
	data, err := productPlanService.ListProductPlan(listProductPlanQuery)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ReceiveMaterial() {
	productPlanService := service.NewProductPlanService(nil)
	receiveMaterialCommand := &command.ReceiveMaterialCommand{}
	controller.Unmarshal(receiveMaterialCommand)
	data, err := productPlanService.ReceiveMaterial(receiveMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ReturnMaterial() {
	productPlanService := service.NewProductPlanService(nil)
	returnMaterialCommand := &command.ReturnMaterialCommand{}
	controller.Unmarshal(returnMaterialCommand)
	data, err := productPlanService.ReturnMaterial(returnMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SetOnline() {
	productPlanService := service.NewProductPlanService(nil)
	setOnlineCommand := &command.SetOnlineCommand{}
	controller.Unmarshal(setOnlineCommand)
	data, err := productPlanService.SetOnline(setOnlineCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) Switch() {
	productPlanService := service.NewProductPlanService(nil)
	switchCommand := &command.SwitchCommand{}
	controller.Unmarshal(switchCommand)
	data, err := productPlanService.Switch(switchCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SubmitProductRecord() {
	productPlanService := service.NewProductPlanService(nil)
	submitProductRecordCommand := &command.SubmitProductRecordCommand{}
	controller.Unmarshal(submitProductRecordCommand)
	data, err := productPlanService.SubmitProductRecord(submitProductRecordCommand)
	controller.Response(data, err)
}