作者 13655977079

增删改查列表批量删

package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchRemoveProductMaterialCommand struct {
// 物料ID们
ProductMaterialIds []int `cname:"物料ID" json:"productMaterialIds" valid:"Required"`
}
func (batchRemoveProductMaterialCommand *BatchRemoveProductMaterialCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchRemoveProductMaterialCommand *BatchRemoveProductMaterialCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchRemoveProductMaterialCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchRemoveProductMaterialCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -9,8 +9,30 @@ import (
)
type UpdateProductMaterialCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId"`
// 物料ID
ProductMaterialId int `cname:"物料ID" json:"productMaterialId" valid:"Required"`
// 物料分组ID
ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"`
//// 物料编码
//MaterialNumber string `cname:"物料编码" json:"materialNumber" valid:"Required"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
// 物料属性
MaterialAttribute string `cname:"物料属性" json:"materialAttribute" valid:"Required"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
// 规格
Specification string `cname:"规格" json:"specification" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 保质期 单位:天
ExpiredDay int `cname:"保质期 单位:天" json:"expiredDay"`
// 备注
Remark string `cname:"备注" json:"remark"`
}
func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) {
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type DtoMaterial struct {
ProductMaterialId int `json:"productMaterialId"` // 物料ID
MaterialNumber string `json:"materialNumber"` //物料编码
MaterialName string `json:"materialName"` //物料名称
Specification string `json:"specification"` //规格型号
MaterialCategory string `json:"materialCategory"` //物料类别
Unit string `json:"unit"` //单位
MaterialAttribute string `json:"materialAttribute"` //物料属性
ProductMaterialGroupId int `json:"productMaterialGroupId"` //物料分组 string/string/string
ExpiredDay int `json:"expiredDay"` //保质期
Remark string `json:"remark"` //备注
ProductMaterialGroupIdName []*domain.ProductMaterialGroup
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
func DtoProductMaterial(productMaterialModel *domain.ProductMaterial) *DtoMaterial {
return &DtoMaterial{
ProductMaterialId: productMaterialModel.ProductMaterialId,
ProductMaterialGroupId: productMaterialModel.ProductMaterialGroupId,
MaterialNumber: productMaterialModel.MaterialNumber,
MaterialName: productMaterialModel.MaterialName,
MaterialAttribute: productMaterialModel.MaterialAttribute.Attribute,
MaterialCategory: productMaterialModel.MaterialCategory.Category,
Specification: productMaterialModel.ProductMaterialExt.Specification,
Remark: productMaterialModel.ProductMaterialExt.Remark,
Unit: productMaterialModel.ProductMaterialExt.Unit,
ExpiredDay: productMaterialModel.ProductMaterialExt.ExpiredDay,
}
}
... ...
... ... @@ -9,16 +9,17 @@ import (
)
type ListProductMaterialQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
PageNumber int64 `json:"pageNumber"`
PageSize int64 `json:"pageSize"`
// 物料分组ID
ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"`
ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId"`
// 物料分组ID数组
ProductMaterialGroupIds []int
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
MaterialName string `cname:"物料名称" json:"materialName"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
MaterialCategory string `cname:"物料类别" json:"materialCategory"`
CompanyId int
}
func (listProductMaterialQuery *ListProductMaterialQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -7,6 +7,7 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
... ... @@ -49,7 +50,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper
}
//var productMaterial *domain.ProductMaterial
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = materialService.AddMaterial(operateInfo, newProductMaterial); err != nil {
if _, err := materialService.AddMaterial(operateInfo, newProductMaterial); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -58,8 +59,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper
return struct{}{}, nil
}
// 返回生产物料服务
func (productMaterialService *ProductMaterialService) GetProductMaterial(getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) {
// 返回生产物料服务单个
func (productMaterialService *ProductMaterialService) GetProductMaterial(operateInfo *domain.OperateInfo, getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) {
if err := getProductMaterialQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -88,15 +89,25 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd
if productMaterial == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId)))
} else {
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
ProductMaterialGroupIdName, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(ProductMaterialGroupIdName) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
one := dto.DtoProductMaterial(productMaterial)
one.ProductMaterialGroupIdName = ProductMaterialGroupIdName
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productMaterial, nil
return one, nil
}
}
// 返回生产物料服务列表
func (productMaterialService *ProductMaterialService) ListProductMaterial(listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) {
// 返回生产物料服务列表,未用
func (productMaterialService *ProductMaterialService) ListProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) {
if err := listProductMaterialQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -118,21 +129,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr
} else {
productMaterialRepository = value
}
var results []*dto.DtoMaterial
if listProductMaterialQuery.ProductMaterialGroupId != 0 {
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
_, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds
}
listProductMaterialQuery.CompanyId = operateInfo.CompanyId
if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, productMaterial := range productMaterials {
results = append(results, dto.DtoProductMaterial(productMaterial))
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"productMaterials": productMaterials,
"productMaterials": results,
}, nil
}
}
// 返回生产物料服务列表
func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (int64, []*dto.DtoMaterial, error) {
if err := listProductMaterialQuery.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productMaterialRepository domain.ProductMaterialRepository
if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productMaterialRepository = value
}
var results []*dto.DtoMaterial
if listProductMaterialQuery.ProductMaterialGroupId != 0 {
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
_, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds
}
listProductMaterialQuery.CompanyId = operateInfo.CompanyId
count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for _, productMaterial := range productMaterials {
results = append(results, dto.DtoProductMaterial(productMaterial))
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, results, err
}
// 移除生产物料服务
func (productMaterialService *ProductMaterialService) RemoveProductMaterial(removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) {
func (productMaterialService *ProductMaterialService) RemoveProductMaterial(operateInfo *domain.OperateInfo, removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) {
if err := removeProductMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -154,7 +224,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo
} else {
productMaterialRepository = value
}
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": removeProductMaterialCommand.ProductMaterialId})
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": removeProductMaterialCommand.ProductMaterialId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -172,8 +242,8 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo
}
// 更新生产物料服务
func (productMaterialService *ProductMaterialService) UpdateProductMaterial(updateProductMaterialCommand *command.UpdateProductMaterialCommand) (interface{}, error) {
if err := updateProductMaterialCommand.ValidateCommand(); err != nil {
func (productMaterialService *ProductMaterialService) UpdateProductMaterial(operateInfo *domain.OperateInfo, cmd *command.UpdateProductMaterialCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -194,24 +264,80 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda
} else {
productMaterialRepository = value
}
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": updateProductMaterialCommand.ProductMaterialId})
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": cmd.ProductMaterialId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productMaterial == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductMaterialCommand.ProductMaterialId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(cmd.ProductMaterialId)))
}
if err := productMaterial.Update(tool_funs.SimpleStructToMap(updateProductMaterialCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
newProductMaterial := &domain.ProductMaterial{ //赋值
ProductMaterialId: cmd.ProductMaterialId,
ProductMaterialGroupId: cmd.ProductMaterialGroupId,
MaterialName: cmd.MaterialName,
MaterialNumber: productMaterial.MaterialNumber,
MaterialAttribute: &domain.MaterialAttribute{Attribute: cmd.MaterialAttribute},
MaterialCategory: &domain.MaterialCategory{Category: cmd.MaterialCategory},
ProductMaterialExt: &domain.MaterialExt{
Specification: cmd.Specification,
Unit: cmd.Unit,
ExpiredDay: cmd.ExpiredDay,
Remark: cmd.Remark,
},
CreatedAt: productMaterial.CreatedAt,
}
if productMaterial, err := productMaterialRepository.Save(productMaterial); err != nil {
materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext))
data, err := materialService.UpdateMaterial(operateInfo, newProductMaterial)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productMaterial, nil
return data, nil
}
// 批量移除生产物料服务
func (productMaterialService *ProductMaterialService) BatchRemoveProductMaterial(operateInfo *domain.OperateInfo, batchRemoveProductMaterialCommand *command.BatchRemoveProductMaterialCommand) (interface{}, error) {
if err := batchRemoveProductMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.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()
}()
var productMaterialRepository domain.ProductMaterialRepository
if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productMaterialRepository = value
}
for i := range batchRemoveProductMaterialCommand.ProductMaterialIds {
ProductMaterialId := batchRemoveProductMaterialCommand.ProductMaterialIds[i]
productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": ProductMaterialId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productMaterial == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(ProductMaterialId)))
}
if _, err := productMaterialRepository.Remove(productMaterial); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService {
... ...
... ... @@ -23,7 +23,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.
err error
newProductMaterial *domain.ProductMaterial
productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext)
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
)
if user, err = NewUserService().User(opt.UserId); err != nil {
return nil, err
... ... @@ -31,7 +31,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.
if org, err = NewUserService().Organization(opt.OrgId); err != nil {
return nil, err
}
_, err = productGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productGroupId": item.ProductMaterialGroupId})
_, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId})
if err != nil {
return nil, err
}
... ... @@ -52,8 +52,41 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithOperator(user),
}
newProductMaterial, err = productMaterialRepository.Save(newProductMaterial)
return newProductMaterial, err
aaa, err := productMaterialRepository.Save(newProductMaterial)
return aaa, err
}
func (ptr *PGMaterialService) UpdateMaterial(opt *domain.OperateInfo, item *domain.ProductMaterial) (*domain.ProductMaterial, error) {
var (
user *domain.User
org *domain.Org
err error
newProductMaterial *domain.ProductMaterial
productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext)
//productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext)
)
if user, err = NewUserService().User(opt.UserId); err != nil {
return nil, err
}
if org, err = NewUserService().Organization(opt.OrgId); err != nil {
return nil, err
}
newProductMaterial = &domain.ProductMaterial{
CompanyId: opt.CompanyId,
OrgId: opt.OrgId,
ProductMaterialId: item.ProductMaterialId,
ProductMaterialGroupId: item.ProductMaterialGroupId,
MaterialName: item.MaterialName,
MaterialNumber: item.MaterialNumber,
MaterialAttribute: item.MaterialAttribute,
MaterialCategory: item.MaterialCategory,
ProductMaterialExt: item.ProductMaterialExt,
CreatedAt: item.CreatedAt,
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithOperator(user),
}
aaa, err := productMaterialRepository.Save(newProductMaterial)
return aaa, err
}
// 物料分组
... ...
... ... @@ -157,6 +157,15 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf
if v, ok := queryOptions["productMaterialIds"]; ok && len(v.([]int)) > 0 {
query.Where("product_material_id in (?)", pg.In(v))
}
if v, ok := queryOptions["productMaterialGroupIds"]; ok && len(v.([]int)) > 0 {
query.Where("product_material_group_id in (?)", pg.In(v))
}
if v, ok := queryOptions["materialName"]; ok && v != "" {
query.Where("material_name like ?", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["materialCategory"]; ok && v != "" {
query.Where("material_category like ?", fmt.Sprintf("%%%v%%", v))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_material_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -28,7 +28,10 @@ func (controller *ProductMaterialController) UpdateProductMaterial() {
controller.Unmarshal(updateProductMaterialCommand)
productMaterialId, _ := controller.GetInt(":productMaterialId")
updateProductMaterialCommand.ProductMaterialId = productMaterialId
data, err := productMaterialService.UpdateProductMaterial(updateProductMaterialCommand)
operateInfo := ParseOperateInfo(controller.BaseController)
updateProductMaterialCommand.CompanyId = operateInfo.CompanyId
updateProductMaterialCommand.OrgId = operateInfo.OrgId
data, err := productMaterialService.UpdateProductMaterial(operateInfo, updateProductMaterialCommand)
controller.Response(data, err)
}
... ... @@ -37,7 +40,8 @@ func (controller *ProductMaterialController) GetProductMaterial() {
getProductMaterialQuery := &query.GetProductMaterialQuery{}
productMaterialId, _ := controller.GetInt(":productMaterialId")
getProductMaterialQuery.ProductMaterialId = productMaterialId
data, err := productMaterialService.GetProductMaterial(getProductMaterialQuery)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productMaterialService.GetProductMaterial(operateInfo, getProductMaterialQuery)
controller.Response(data, err)
}
... ... @@ -47,17 +51,34 @@ func (controller *ProductMaterialController) RemoveProductMaterial() {
controller.Unmarshal(removeProductMaterialCommand)
productMaterialId, _ := controller.GetInt(":productMaterialId")
removeProductMaterialCommand.ProductMaterialId = productMaterialId
data, err := productMaterialService.RemoveProductMaterial(removeProductMaterialCommand)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productMaterialService.RemoveProductMaterial(operateInfo, removeProductMaterialCommand)
controller.Response(data, err)
}
//没用到
func (controller *ProductMaterialController) ListProductMaterial() {
productMaterialService := service.NewProductMaterialService(nil)
listProductMaterialQuery := &query.ListProductMaterialQuery{}
offset, _ := controller.GetInt("offset")
listProductMaterialQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProductMaterialQuery.Limit = limit
data, err := productMaterialService.ListProductMaterial(listProductMaterialQuery)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productMaterialService.ListProductMaterial(operateInfo, listProductMaterialQuery)
controller.Response(data, err)
}
func (controller *ProductMaterialController) SearchProductMaterial() {
productMaterialService := service.NewProductMaterialService(nil)
listProductMaterialQuery := &query.ListProductMaterialQuery{}
controller.Unmarshal(listProductMaterialQuery)
operateInfo := ParseOperateInfo(controller.BaseController)
total, data, err := productMaterialService.SearchProductMaterial(operateInfo, listProductMaterialQuery)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *ProductMaterialController) BatchRemoveProductMaterial() {
productMaterialService := service.NewProductMaterialService(nil)
batchremoveProductMaterialCommand := &command.BatchRemoveProductMaterialCommand{}
controller.Unmarshal(batchremoveProductMaterialCommand)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productMaterialService.BatchRemoveProductMaterial(operateInfo, batchremoveProductMaterialCommand)
controller.Response(data, err)
}
... ...
... ... @@ -6,9 +6,11 @@ import (
)
func init() {
web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Post:CreateProductMaterial")
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Put:UpdateProductMaterial")
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Get:GetProductMaterial")
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Delete:RemoveProductMaterial")
web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Post:CreateProductMaterial") //新增单个物料
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Put:UpdateProductMaterial") //更新单个物料
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Get:GetProductMaterial") //获取单个物料
web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Delete:RemoveProductMaterial") //删除单个物料
web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Get:ListProductMaterial")
web.Router("/product-materials/search", &controllers.ProductMaterialController{}, "Post:SearchProductMaterial") //搜索返回列表
web.Router("/product-materials/batch-remove", &controllers.ProductMaterialController{}, "Post:BatchRemoveProductMaterial") //批量删除物料
}
... ...