product_job_controller.go 3.3 KB
package controllers

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

type ProductJobController struct {
	beego.BaseController
}

func (controller *ProductJobController) CreateProductJob() {
	productJobService := service.NewProductJobService(nil)
	createProductJobCommand := &command.CreateProductJobCommand{}
	Must(controller.Unmarshal(createProductJobCommand))
	data, err := productJobService.CreateProductJob(ParseOperateInfo(controller.BaseController), createProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) UpdateProductJob() {
	productJobService := service.NewProductJobService(nil)
	updateProductJobCommand := &command.UpdateProductJobCommand{}
	Must(controller.Unmarshal(updateProductJobCommand))
	productJobId, _ := controller.GetInt(":productJobId")
	updateProductJobCommand.ProductJobId = productJobId
	data, err := productJobService.UpdateProductJob(updateProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) GetProductJob() {
	productJobService := service.NewProductJobService(nil)
	getProductJobQuery := &query.GetProductJobQuery{}
	productJobId, _ := controller.GetInt(":productJobId")
	getProductJobQuery.ProductJobId = productJobId
	data, err := productJobService.GetProductJob(getProductJobQuery)
	controller.Response(data, err)
}

func (controller *ProductJobController) RemoveProductJob() {
	productJobService := service.NewProductJobService(nil)
	removeProductJobCommand := &command.RemoveProductJobCommand{}
	controller.Unmarshal(removeProductJobCommand)
	productJobId, _ := controller.GetInt(":productJobId")
	removeProductJobCommand.ProductJobId = productJobId
	data, err := productJobService.RemoveProductJob(removeProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) BatchRemoveProductJob() {
	productJobService := service.NewProductJobService(nil)
	removeProductJobCommand := &command.BatchRemoveProductJobCommand{}
	Must(controller.Unmarshal(removeProductJobCommand))
	data, err := productJobService.BatchRemoveProductJob(removeProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) ListProductJob() {
	productJobService := service.NewProductJobService(nil)
	listProductJobQuery := &query.ListProductJobQuery{}
	offset, _ := controller.GetInt("offset")
	listProductJobQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductJobQuery.Limit = limit
	data, err := productJobService.ListProductJob(listProductJobQuery)
	controller.Response(data, err)
}

func (controller *ProductJobController) SearchProductJob() {
	productJobService := service.NewProductJobService(nil)
	cmd := &query.SearchProductJobQuery{}
	Must(controller.Unmarshal(cmd))
	operateInfo := ParseOperateInfo(controller.BaseController)
	cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	//cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := productJobService.SearchProductJob(operateInfo, cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}