作者 yangfu

服务初始化

正在显示 67 个修改的文件 包含 4779 行增加1 行删除
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateDeviceCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 设备编号
DeviceCode string `cname:"设备编号" json:"deviceCode" valid:"Required"`
// 设备名称
DeviceName string `cname:"设备名称" json:"deviceName" valid:"Required"`
// 设备型号
DeviceModel string `cname:"设备型号" json:"deviceModel" valid:"Required"`
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 品牌
Brand string `cname:"品牌" json:"brand" valid:"Required"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
}
func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createDeviceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createDeviceCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveDeviceCommand struct {
// 设备Id
DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
}
func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeDeviceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeDeviceCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateDeviceCommand struct {
// 设备Id
DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
// 设备编号
DeviceCode string `cname:"设备编号" json:"deviceCode" valid:"Required"`
// 设备名称
DeviceName string `cname:"设备名称" json:"deviceName" valid:"Required"`
// 设备型号
DeviceModel string `cname:"设备型号" json:"deviceModel" valid:"Required"`
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 品牌
Brand string `cname:"品牌" json:"brand" valid:"Required"`
// 设备状态 1:正常 2:封存 3:报废
DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
// 风险等级 1:高 2:中 3:低
RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
}
func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateDeviceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateDeviceCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetDeviceQuery struct {
// 设备Id
DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
}
func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getDeviceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getDeviceQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListDeviceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDeviceQuery *ListDeviceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listDeviceQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listDeviceQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 设备服务
type DeviceService struct {
}
// 创建设备服务
func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.CreateDeviceCommand) (interface{}, error) {
if err := createDeviceCommand.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()
}()
newDevice := &domain.Device{
CompanyId: createDeviceCommand.CompanyId,
OrgId: createDeviceCommand.OrgId,
DeviceCode: createDeviceCommand.DeviceCode,
DeviceName: createDeviceCommand.DeviceName,
DeviceModel: createDeviceCommand.DeviceModel,
DeviceType: createDeviceCommand.DeviceType,
//WorkshopId: createDeviceCommand.WorkshopId,
//LineId: createDeviceCommand.LineId,
//SectionId: createDeviceCommand.SectionId,
Brand: createDeviceCommand.Brand,
DeviceStatus: createDeviceCommand.DeviceStatus,
RiskLevel: createDeviceCommand.RiskLevel,
}
var deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
if device, err := deviceRepository.Save(newDevice); 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 device, nil
}
}
// 返回设备服务
func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQuery) (interface{}, error) {
if err := getDeviceQuery.ValidateQuery(); 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 deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": getDeviceQuery.DeviceId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDeviceQuery.DeviceId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return device, nil
}
}
// 返回设备服务列表
func (deviceService *DeviceService) ListDevice(listDeviceQuery *query.ListDeviceQuery) (interface{}, error) {
if err := listDeviceQuery.ValidateQuery(); 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 deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
if count, devices, err := deviceRepository.Find(tool_funs.SimpleStructToMap(listDeviceQuery)); 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 map[string]interface{}{
"count": count,
"devices": devices,
}, nil
}
}
// 移除设备服务
func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.RemoveDeviceCommand) (interface{}, error) {
if err := removeDeviceCommand.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 deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": removeDeviceCommand.DeviceId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDeviceCommand.DeviceId)))
}
if device, err := deviceRepository.Remove(device); 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 device, nil
}
}
// 更新设备服务
func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.UpdateDeviceCommand) (interface{}, error) {
if err := updateDeviceCommand.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 deviceRepository domain.DeviceRepository
if value, err := factory.CreateDeviceRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
deviceRepository = value
}
device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": updateDeviceCommand.DeviceId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if device == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCommand.DeviceId)))
}
if err := device.Update(tool_funs.SimpleStructToMap(updateDeviceCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if device, err := deviceRepository.Save(device); 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 device, nil
}
}
func NewDeviceService(options map[string]interface{}) *DeviceService {
newDeviceService := &DeviceService{}
return newDeviceService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"`
// 产品名称
ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
// 产品类别
ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
}
func (createProductCommand *CreateProductCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductCommand *CreateProductCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductCommand struct {
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
}
func (removeProductCommand *RemoveProductCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductCommand *RemoveProductCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductCommand struct {
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"`
// 产品名称
ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
// 产品类别
ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
}
func (updateProductCommand *UpdateProductCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductCommand *UpdateProductCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductQuery struct {
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
}
func (getProductQuery *GetProductQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductQuery *GetProductQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductQuery *ListProductQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductQuery *ListProductQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/product/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 产品服务
type ProductService struct {
}
// 创建产品服务
func (productService *ProductService) CreateProduct(createProductCommand *command.CreateProductCommand) (interface{}, error) {
if err := createProductCommand.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()
}()
newProduct := &domain.Product{
CompanyId: createProductCommand.CompanyId,
OrgId: createProductCommand.OrgId,
ProductCode: createProductCommand.ProductCode,
ProductName: createProductCommand.ProductName,
ProductCategory: createProductCommand.ProductCategory,
//ProductSpec: createProductCommand.ProductSpec,
}
var productRepository domain.ProductRepository
if value, err := factory.CreateProductRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRepository = value
}
if product, err := productRepository.Save(newProduct); 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 product, nil
}
}
// 返回产品服务
func (productService *ProductService) GetProduct(getProductQuery *query.GetProductQuery) (interface{}, error) {
if err := getProductQuery.ValidateQuery(); 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 productRepository domain.ProductRepository
if value, err := factory.CreateProductRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRepository = value
}
product, err := productRepository.FindOne(map[string]interface{}{"productId": getProductQuery.ProductId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if product == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductQuery.ProductId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return product, nil
}
}
// 返回产品服务列表
func (productService *ProductService) ListProduct(listProductQuery *query.ListProductQuery) (interface{}, error) {
if err := listProductQuery.ValidateQuery(); 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 productRepository domain.ProductRepository
if value, err := factory.CreateProductRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRepository = value
}
if count, products, err := productRepository.Find(tool_funs.SimpleStructToMap(listProductQuery)); 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 map[string]interface{}{
"count": count,
"products": products,
}, nil
}
}
// 移除产品服务
func (productService *ProductService) RemoveProduct(removeProductCommand *command.RemoveProductCommand) (interface{}, error) {
if err := removeProductCommand.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 productRepository domain.ProductRepository
if value, err := factory.CreateProductRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRepository = value
}
product, err := productRepository.FindOne(map[string]interface{}{"productId": removeProductCommand.ProductId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if product == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductCommand.ProductId)))
}
if product, err := productRepository.Remove(product); 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 product, nil
}
}
// 更新产品服务
func (productService *ProductService) UpdateProduct(updateProductCommand *command.UpdateProductCommand) (interface{}, error) {
if err := updateProductCommand.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 productRepository domain.ProductRepository
if value, err := factory.CreateProductRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productRepository = value
}
product, err := productRepository.FindOne(map[string]interface{}{"productId": updateProductCommand.ProductId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if product == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCommand.ProductId)))
}
if err := product.Update(tool_funs.SimpleStructToMap(updateProductCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if product, err := productRepository.Save(product); 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 product, nil
}
}
func NewProductService(options map[string]interface{}) *ProductService {
newProductService := &ProductService{}
return newProductService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductCalendarCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 日历选择
CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
// 上岗时间
InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
// 下岗时间
OutWorkAt string `cname:"下岗时间" json:"outWorkAt" valid:"Required"`
// 休息时间 (单位 h)
BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
// 工时 (单位 h)
WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
}
func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductCalendarCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductCalendarCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductCalendarCommand struct {
// 工厂日历ID
ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
}
func (removeProductCalendarCommand *RemoveProductCalendarCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductCalendarCommand *RemoveProductCalendarCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductCalendarCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductCalendarCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductCalendarCommand struct {
// 工厂日历ID
ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 日历选择
CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
// 上岗时间
InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
// 下岗时间
OutWorkAt string `cname:"下岗时间" json:"outWorkAt" valid:"Required"`
// 休息时间 (单位 h)
BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
// 工时 (单位 h)
WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
}
func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductCalendarCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductCalendarCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductCalendarQuery struct {
// 工厂日历ID
ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
}
func (getProductCalendarQuery *GetProductCalendarQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductCalendarQuery *GetProductCalendarQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductCalendarQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductCalendarQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductCalendarQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductCalendarQuery *ListProductCalendarQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductCalendarQuery *ListProductCalendarQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductCalendarQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductCalendarQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/productCalendar/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 工厂日历服务
type ProductCalendarService struct {
}
// 创建工厂日历服务
func (productCalendarService *ProductCalendarService) CreateProductCalendar(createProductCalendarCommand *command.CreateProductCalendarCommand) (interface{}, error) {
if err := createProductCalendarCommand.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()
}()
newProductCalendar := &domain.ProductCalendar{
CompanyId: createProductCalendarCommand.CompanyId,
OrgId: createProductCalendarCommand.OrgId,
//WorkshopId: createProductCalendarCommand.WorkshopId,
//LineId: createProductCalendarCommand.LineId,
//SectionId: createProductCalendarCommand.SectionId,
//WorkOn: createProductCalendarCommand.WorkOn,
CalendarSelected: createProductCalendarCommand.CalendarSelected,
InWorkAt: createProductCalendarCommand.InWorkAt,
OutWorkAt: createProductCalendarCommand.OutWorkAt,
BreakTime: createProductCalendarCommand.BreakTime,
WorkTime: createProductCalendarCommand.WorkTime,
}
var productCalendarRepository domain.ProductCalendarRepository
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productCalendarRepository = value
}
if productCalendar, err := productCalendarRepository.Save(newProductCalendar); 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 productCalendar, nil
}
}
// 返回工厂日历服务
func (productCalendarService *ProductCalendarService) GetProductCalendar(getProductCalendarQuery *query.GetProductCalendarQuery) (interface{}, error) {
if err := getProductCalendarQuery.ValidateQuery(); 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 productCalendarRepository domain.ProductCalendarRepository
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productCalendarRepository = value
}
productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": getProductCalendarQuery.ProductCalendarId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productCalendar == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductCalendarQuery.ProductCalendarId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productCalendar, nil
}
}
// 返回工厂日历服务列表
func (productCalendarService *ProductCalendarService) ListProductCalendar(listProductCalendarQuery *query.ListProductCalendarQuery) (interface{}, error) {
if err := listProductCalendarQuery.ValidateQuery(); 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 productCalendarRepository domain.ProductCalendarRepository
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productCalendarRepository = value
}
if count, productCalendars, err := productCalendarRepository.Find(tool_funs.SimpleStructToMap(listProductCalendarQuery)); 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 map[string]interface{}{
"count": count,
"productCalendars": productCalendars,
}, nil
}
}
// 移除工厂日历服务
func (productCalendarService *ProductCalendarService) RemoveProductCalendar(removeProductCalendarCommand *command.RemoveProductCalendarCommand) (interface{}, error) {
if err := removeProductCalendarCommand.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 productCalendarRepository domain.ProductCalendarRepository
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productCalendarRepository = value
}
productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": removeProductCalendarCommand.ProductCalendarId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productCalendar == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductCalendarCommand.ProductCalendarId)))
}
if productCalendar, err := productCalendarRepository.Remove(productCalendar); 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 productCalendar, nil
}
}
// 更新工厂日历服务
func (productCalendarService *ProductCalendarService) UpdateProductCalendar(updateProductCalendarCommand *command.UpdateProductCalendarCommand) (interface{}, error) {
if err := updateProductCalendarCommand.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 productCalendarRepository domain.ProductCalendarRepository
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productCalendarRepository = value
}
productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": updateProductCalendarCommand.ProductCalendarId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productCalendar == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCalendarCommand.ProductCalendarId)))
}
if err := productCalendar.Update(tool_funs.SimpleStructToMap(updateProductCalendarCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productCalendar, err := productCalendarRepository.Save(productCalendar); 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 productCalendar, nil
}
}
func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService {
newProductCalendarService := &ProductCalendarService{}
return newProductCalendarService
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductGroupCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
// 用户Id 用户唯一标识
UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 帮组成员列表
GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
func (createProductGroupCommand *CreateProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductGroupCommand *CreateProductGroupCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductGroupCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductGroupCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductGroupCommand struct {
// 生产小组ID
ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
}
func (removeProductGroupCommand *RemoveProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductGroupCommand *RemoveProductGroupCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductGroupCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductGroupCommand).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
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductGroupCommand struct {
// 生产小组ID
ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 班组名称
GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
// 用户Id 用户唯一标识
UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
// IC卡号
IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 帮组成员列表
GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
}
func (updateProductGroupCommand *UpdateProductGroupCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductGroupCommand *UpdateProductGroupCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductGroupCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductGroupCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductGroupQuery struct {
// 生产小组ID
ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
}
func (getProductGroupQuery *GetProductGroupQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductGroupQuery *GetProductGroupQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductGroupQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductGroupQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductGroupQuery *ListProductGroupQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductGroupQuery *ListProductGroupQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductGroupQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductGroupQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/productGroup/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 生产班组服务
type ProductGroupService struct {
}
// 创建生产班组服务
func (productGroupService *ProductGroupService) CreateProductGroup(createProductGroupCommand *command.CreateProductGroupCommand) (interface{}, error) {
if err := createProductGroupCommand.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()
}()
newProductGroup := &domain.ProductGroup{
CompanyId: createProductGroupCommand.CompanyId,
OrgId: createProductGroupCommand.OrgId,
//WorkshopId: createProductGroupCommand.WorkshopId,
//LineId: createProductGroupCommand.LineId,
//SectionId: createProductGroupCommand.SectionId,
GroupName: createProductGroupCommand.GroupName,
//GroupLeader: createProductGroupCommand.GroupLeader,
GroupMembers: createProductGroupCommand.GroupMembers,
WorkOn: createProductGroupCommand.WorkOn,
}
var productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
if productGroup, err := productGroupRepository.Save(newProductGroup); 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 productGroup, nil
}
}
// 返回生产班组服务
func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQuery *query.GetProductGroupQuery) (interface{}, error) {
if err := getProductGroupQuery.ValidateQuery(); 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 productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": getProductGroupQuery.ProductGroupId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productGroup, nil
}
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) ListProductGroup(listProductGroupQuery *query.ListProductGroupQuery) (interface{}, error) {
if err := listProductGroupQuery.ValidateQuery(); 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 productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
if count, productGroups, err := productGroupRepository.Find(tool_funs.SimpleStructToMap(listProductGroupQuery)); 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 map[string]interface{}{
"count": count,
"productGroups": productGroups,
}, nil
}
}
// 移除生产班组服务
func (productGroupService *ProductGroupService) RemoveProductGroup(removeProductGroupCommand *command.RemoveProductGroupCommand) (interface{}, error) {
if err := removeProductGroupCommand.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 productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": removeProductGroupCommand.ProductGroupId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductGroupCommand.ProductGroupId)))
}
if productGroup, err := productGroupRepository.Remove(productGroup); 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 productGroup, nil
}
}
// 更新生产班组服务
func (productGroupService *ProductGroupService) UpdateProductGroup(updateProductGroupCommand *command.UpdateProductGroupCommand) (interface{}, error) {
if err := updateProductGroupCommand.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 productGroupRepository domain.ProductGroupRepository
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productGroupRepository = value
}
productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": updateProductGroupCommand.ProductGroupId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductGroupCommand.ProductGroupId)))
}
if err := productGroup.Update(tool_funs.SimpleStructToMap(updateProductGroupCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productGroup, err := productGroupRepository.Save(productGroup); 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 productGroup, nil
}
}
func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
newProductGroupService := &ProductGroupService{}
return newProductGroupService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductJobCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 工位名称
JobName string `cname:"工位名称" json:"jobName" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 关联设备列表
RelatedDevices []int `cname:"关联设备列表" json:"relatedDevices,omitempty"`
}
func (createProductJobCommand *CreateProductJobCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductJobCommand *CreateProductJobCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductJobCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductJobCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductJobCommand struct {
// 工位ID
ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
}
func (removeProductJobCommand *RemoveProductJobCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductJobCommand *RemoveProductJobCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductJobCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductJobCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductJobCommand struct {
// 工位ID
ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
// 工位名称
JobName string `cname:"工位名称" json:"jobName" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 关联设备列表
RelatedDevices []int `cname:"关联设备列表" json:"relatedDevices,omitempty"`
}
func (updateProductJobCommand *UpdateProductJobCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductJobCommand *UpdateProductJobCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductJobCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductJobCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductJobQuery struct {
// 工位ID
ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
}
func (getProductJobQuery *GetProductJobQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductJobQuery *GetProductJobQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductJobQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductJobQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductJobQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductJobQuery *ListProductJobQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductJobQuery *ListProductJobQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductJobQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductJobQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/productJob/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 工位服务
type ProductJobService struct {
}
// 创建工位服务
func (productJobService *ProductJobService) CreateProductJob(createProductJobCommand *command.CreateProductJobCommand) (interface{}, error) {
if err := createProductJobCommand.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()
}()
newProductJob := &domain.ProductJob{
CompanyId: createProductJobCommand.CompanyId,
OrgId: createProductJobCommand.OrgId,
JobName: createProductJobCommand.JobName,
//WorkshopId: createProductJobCommand.WorkshopId,
//LineId: createProductJobCommand.LineId,
//SectionId: createProductJobCommand.SectionId,
RelatedDevices: createProductJobCommand.RelatedDevices,
}
var productJobRepository domain.ProductJobRepository
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productJobRepository = value
}
if productJob, err := productJobRepository.Save(newProductJob); 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 productJob, nil
}
}
// 返回工位服务
func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *query.GetProductJobQuery) (interface{}, error) {
if err := getProductJobQuery.ValidateQuery(); 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 productJobRepository domain.ProductJobRepository
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productJobRepository = value
}
productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": getProductJobQuery.ProductJobId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productJob == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductJobQuery.ProductJobId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productJob, nil
}
}
// 返回工位服务列表
func (productJobService *ProductJobService) ListProductJob(listProductJobQuery *query.ListProductJobQuery) (interface{}, error) {
if err := listProductJobQuery.ValidateQuery(); 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 productJobRepository domain.ProductJobRepository
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productJobRepository = value
}
if count, productJobs, err := productJobRepository.Find(tool_funs.SimpleStructToMap(listProductJobQuery)); 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 map[string]interface{}{
"count": count,
"productJobs": productJobs,
}, nil
}
}
// 移除工位服务
func (productJobService *ProductJobService) RemoveProductJob(removeProductJobCommand *command.RemoveProductJobCommand) (interface{}, error) {
if err := removeProductJobCommand.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 productJobRepository domain.ProductJobRepository
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productJobRepository = value
}
productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": removeProductJobCommand.ProductJobId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productJob == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductJobCommand.ProductJobId)))
}
if productJob, err := productJobRepository.Remove(productJob); 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 productJob, nil
}
}
// 更新工位服务
func (productJobService *ProductJobService) UpdateProductJob(updateProductJobCommand *command.UpdateProductJobCommand) (interface{}, error) {
if err := updateProductJobCommand.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 productJobRepository domain.ProductJobRepository
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productJobRepository = value
}
productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": updateProductJobCommand.ProductJobId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productJob == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductJobCommand.ProductJobId)))
}
if err := productJob.Update(tool_funs.SimpleStructToMap(updateProductJobCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productJob, err := productJobRepository.Save(productJob); 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 productJob, nil
}
}
func NewProductJobService(options map[string]interface{}) *ProductJobService {
newProductJobService := &ProductJobService{}
return newProductJobService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductLineCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName" valid:"Required"`
}
func (createProductLineCommand *CreateProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductLineCommand *CreateProductLineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductLineCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductLineCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductLineCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
}
func (removeProductLineCommand *RemoveProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductLineCommand *RemoveProductLineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductLineCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductLineCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductLineCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName" valid:"Required"`
}
func (updateProductLineCommand *UpdateProductLineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductLineCommand *UpdateProductLineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductLineCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductLineCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductLineQuery struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
}
func (getProductLineQuery *GetProductLineQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductLineQuery *GetProductLineQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductLineQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductLineQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductLineQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductLineQuery *ListProductLineQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductLineQuery *ListProductLineQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductLineQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductLineQuery).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
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 生产线服务
type ProductLineService struct {
}
// 创建生产线
func (productLineService *ProductLineService) CreateProductLine(createProductLineCommand *command.CreateProductLineCommand) (interface{}, error) {
if err := createProductLineCommand.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()
}()
newProductLine := &domain.ProductLine{
//WorkshopId: createProductLineCommand.WorkshopId,
LineName: createProductLineCommand.LineName,
}
//var productLineRepository domain
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//if productLine, err := productLineRepository.Save(newProductLine); 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 productLine, nil
//}
return newProductLine, nil
}
// 返回生产线
func (productLineService *ProductLineService) GetProductLine(getProductLineQuery *query.GetProductLineQuery) (interface{}, error) {
if err := getProductLineQuery.ValidateQuery(); 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 productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": getProductLineQuery.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductLineQuery.ProductLineId)))
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return productLine, nil
//}
return nil, nil
}
// 返回生产线列表
func (productLineService *ProductLineService) ListProductLine(listProductLineQuery *query.ListProductLineQuery) (interface{}, error) {
if err := listProductLineQuery.ValidateQuery(); 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 productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//if count, productLines, err := productLineRepository.Find(tool_funs.SimpleStructToMap(listProductLineQuery)); 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 map[string]interface{}{
// "count": count,
// "productLines": productLines,
// }, nil
//}
return nil, nil
}
// 移除生产线
func (productLineService *ProductLineService) RemoveProductLine(removeProductLineCommand *command.RemoveProductLineCommand) (interface{}, error) {
if err := removeProductLineCommand.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 productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": removeProductLineCommand.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductLineCommand.ProductLineId)))
//}
//if productLine, err := productLineRepository.Remove(productLine); 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 productLine, nil
//}
return nil, nil
}
// 更新生产线
func (productLineService *ProductLineService) UpdateProductLine(updateProductLineCommand *command.UpdateProductLineCommand) (interface{}, error) {
if err := updateProductLineCommand.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 productLineRepository productLine.ProductLineRepository
//if value, err := factory.CreateProductLineRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productLineRepository = value
//}
//productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": updateProductLineCommand.ProductLineId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productLine == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductLineCommand.ProductLineId)))
//}
//if err := productLine.Update(tool_funs.SimpleStructToMap(updateProductLineCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if productLine, err := productLineRepository.Save(productLine); 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 productLine, nil
//}
return nil, nil
}
func NewProductLineService(options map[string]interface{}) *ProductLineService {
newProductLineService := &ProductLineService{}
return newProductLineService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductPlanCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
// 生产日期
ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"`
// 计划的产品名称
PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
}
func (createProductPlanCommand *CreateProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductPlanCommand *CreateProductPlanCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductPlanCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductPlanCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ReceiveMaterialCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (receiveMaterialCommand *ReceiveMaterialCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(receiveMaterialCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(receiveMaterialCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductPlanCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (removeProductPlanCommand *RemoveProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductPlanCommand *RemoveProductPlanCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductPlanCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductPlanCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ReturnMaterialCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (returnMaterialCommand *ReturnMaterialCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(returnMaterialCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(returnMaterialCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SetOfflineCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (setOfflineCommand *SetOfflineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (setOfflineCommand *SetOfflineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(setOfflineCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(setOfflineCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SetOnlineCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
func (setOnlineCommand *SetOnlineCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (setOnlineCommand *SetOnlineCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(setOnlineCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(setOnlineCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SubmitProductRecordCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (submitProductRecordCommand *SubmitProductRecordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (submitProductRecordCommand *SubmitProductRecordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(submitProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(submitProductRecordCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SwitchCommand struct {
// 下线计划ID
FromProductPlanId int `cname:"下线计划ID" json:"fromProductPlanId,omitempty"`
// 上线计划ID
ToProductPlanId int `cname:"上线计划ID" json:"toProductPlanId,omitempty"`
}
func (switchCommand *SwitchCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (switchCommand *SwitchCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(switchCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(switchCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductPlanCommand struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
// 企业id
CompanyId int `cname:"企业id" json:"companyId,omitempty"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId,omitempty"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 批号
BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
// 生产日期
ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"`
// 计划的产品名称
PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
}
func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductPlanCommand *UpdateProductPlanCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductPlanCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductPlanCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductPlanQuery struct {
// 生产计划ID
ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
}
func (getProductPlanQuery *GetProductPlanQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductPlanQuery *GetProductPlanQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductPlanQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductPlanQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductPlanQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductPlanQuery *ListProductPlanQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductPlanQuery *ListProductPlanQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductPlanQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductPlanQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/productPlan/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 生产计划服务
type ProductPlanService struct {
}
// 创建生产计划服务
func (productPlanService *ProductPlanService) CreateProductPlan(createProductPlanCommand *command.CreateProductPlanCommand) (interface{}, error) {
if err := createProductPlanCommand.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()
}()
newProductPlan := &domain.ProductPlan{
CompanyId: createProductPlanCommand.CompanyId,
OrgId: createProductPlanCommand.OrgId,
//WorkshopId: createProductPlanCommand.WorkshopId,
BatchNumber: createProductPlanCommand.BatchNumber,
ProductDate: createProductPlanCommand.ProductDate,
WorkOn: createProductPlanCommand.WorkOn,
Machine: createProductPlanCommand.Machine,
PlanProductName: createProductPlanCommand.PlanProductName,
//PlanDevoted: createProductPlanCommand.PlanDevoted,
Remark: createProductPlanCommand.Remark,
}
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
if productPlan, err := productPlanRepository.Save(newProductPlan); 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 productPlan, nil
}
}
// 返回生产计划服务
func (productPlanService *ProductPlanService) GetProductPlan(getProductPlanQuery *query.GetProductPlanQuery) (interface{}, error) {
if err := getProductPlanQuery.ValidateQuery(); 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 productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": getProductPlanQuery.ProductPlanId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productPlan == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductPlanQuery.ProductPlanId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productPlan, nil
}
}
// 返回生产计划服务列表
func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQuery *query.ListProductPlanQuery) (interface{}, error) {
if err := listProductPlanQuery.ValidateQuery(); 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 productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
if count, productPlans, err := productPlanRepository.Find(tool_funs.SimpleStructToMap(listProductPlanQuery)); 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 map[string]interface{}{
"count": count,
"productPlans": productPlans,
}, nil
}
}
// 领料
func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
if err := receiveMaterialCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 移除生产计划服务
func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) {
if err := removeProductPlanCommand.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 productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": removeProductPlanCommand.ProductPlanId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productPlan == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductPlanCommand.ProductPlanId)))
}
if productPlan, err := productPlanRepository.Remove(productPlan); 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 productPlan, nil
}
}
// 退料
func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
if err := returnMaterialCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 计划下线
func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *command.SetOfflineCommand) (interface{}, error) {
if err := setOfflineCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 计划上线
func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *command.SetOnlineCommand) (interface{}, error) {
if err := setOnlineCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 提交成品记录 (成品 二级品)
func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
if err := submitProductRecordCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 换单
func (productPlanService *ProductPlanService) Switch(switchCommand *command.SwitchCommand) (interface{}, error) {
if err := switchCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 更新生产计划服务
func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPlanCommand *command.UpdateProductPlanCommand) (interface{}, error) {
if err := updateProductPlanCommand.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 productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": updateProductPlanCommand.ProductPlanId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if productPlan == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductPlanCommand.ProductPlanId)))
}
if err := productPlan.Update(tool_funs.SimpleStructToMap(updateProductPlanCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if productPlan, err := productPlanRepository.Save(productPlan); 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 productPlan, nil
}
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
newProductPlanService := &ProductPlanService{}
return newProductPlanService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateProductSectionCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName" valid:"Required"`
}
func (createProductSectionCommand *CreateProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProductSectionCommand *CreateProductSectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProductSectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createProductSectionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveProductSectionCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
func (removeProductSectionCommand *RemoveProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductSectionCommand *RemoveProductSectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductSectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductSectionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateProductSectionCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName" valid:"Required"`
}
func (updateProductSectionCommand *UpdateProductSectionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProductSectionCommand *UpdateProductSectionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProductSectionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateProductSectionCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetProductSectionQuery struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
}
func (getProductSectionQuery *GetProductSectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProductSectionQuery *GetProductSectionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProductSectionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getProductSectionQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListProductSectionQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listProductSectionQuery *ListProductSectionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProductSectionQuery *ListProductSectionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProductSectionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listProductSectionQuery).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
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/query"
)
// 工段服务
type ProductSectionService struct {
}
// 创建工段服务
func (productSectionService *ProductSectionService) CreateProductSection(createProductSectionCommand *command.CreateProductSectionCommand) (interface{}, error) {
if err := createProductSectionCommand.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()
}()
//newProductSection := &productSection.ProductSection{
// WorkshopId: createProductSectionCommand.WorkshopId,
// LineId: createProductSectionCommand.LineId,
// SectionName: createProductSectionCommand.SectionName,
//}
//var productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//if productSection, err := productSectionRepository.Save(newProductSection); 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 productSection, nil
//}
return nil, nil
}
// 返回工段服务
func (productSectionService *ProductSectionService) GetProductSection(getProductSectionQuery *query.GetProductSectionQuery) (interface{}, error) {
if err := getProductSectionQuery.ValidateQuery(); 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 productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": getProductSectionQuery.ProductSectionId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productSection == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductSectionQuery.ProductSectionId)))
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return productSection, nil
//}
return nil, nil
}
// 返回工段服务列表
func (productSectionService *ProductSectionService) ListProductSection(listProductSectionQuery *query.ListProductSectionQuery) (interface{}, error) {
if err := listProductSectionQuery.ValidateQuery(); 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 productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//if count, productSections, err := productSectionRepository.Find(tool_funs.SimpleStructToMap(listProductSectionQuery)); 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 map[string]interface{}{
// "count": count,
// "productSections": productSections,
// }, nil
//}
return nil, nil
}
// 移除工段服务
func (productSectionService *ProductSectionService) RemoveProductSection(removeProductSectionCommand *command.RemoveProductSectionCommand) (interface{}, error) {
if err := removeProductSectionCommand.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 productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": removeProductSectionCommand.ProductSectionId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productSection == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductSectionCommand.ProductSectionId)))
//}
//if productSection, err := productSectionRepository.Remove(productSection); 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 productSection, nil
//}
return nil, nil
}
// 更新工段服务
func (productSectionService *ProductSectionService) UpdateProductSection(updateProductSectionCommand *command.UpdateProductSectionCommand) (interface{}, error) {
if err := updateProductSectionCommand.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 productSectionRepository productSection.ProductSectionRepository
//if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// productSectionRepository = value
//}
//productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": updateProductSectionCommand.ProductSectionId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if productSection == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductSectionCommand.ProductSectionId)))
//}
//if err := productSection.Update(tool_funs.SimpleStructToMap(updateProductSectionCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//if productSection, err := productSectionRepository.Save(productSection); 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 productSection, nil
//}
return nil, nil
}
func NewProductSectionService(options map[string]interface{}) *ProductSectionService {
newProductSectionService := &ProductSectionService{}
return newProductSectionService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateUnitConversionCommand struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 智能称重标识
IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
}
func (createUnitConversionCommand *CreateUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createUnitConversionCommand *CreateUnitConversionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createUnitConversionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createUnitConversionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveUnitConversionCommand struct {
// 单位换算ID
UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
}
func (removeUnitConversionCommand *RemoveUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeUnitConversionCommand *RemoveUnitConversionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeUnitConversionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeUnitConversionCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateUnitConversionCommand struct {
// 单位换算ID
UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
// 企业id
CompanyId int `cname:"企业id" json:"companyId,omitempty"`
// 组织ID
OrgId int `cname:"组织ID" json:"orgId,omitempty"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 物料名称
MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
// 物料类别
MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
Unit string `cname:"单位" json:"unit" valid:"Required"`
// 单份重量(原材料)
UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 智能称重标识
IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
}
func (updateUnitConversionCommand *UpdateUnitConversionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateUnitConversionCommand *UpdateUnitConversionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateUnitConversionCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateUnitConversionCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetUnitConversionQuery struct {
// 单位换算ID
UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
}
func (getUnitConversionQuery *GetUnitConversionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getUnitConversionQuery *GetUnitConversionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getUnitConversionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getUnitConversionQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListUnitConversionQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listUnitConversionQuery *ListUnitConversionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listUnitConversionQuery *ListUnitConversionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listUnitConversionQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listUnitConversionQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/unitConversion/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 单位换算服务
type UnitConversionService struct {
}
// 创建单位换算服务
func (unitConversionService *UnitConversionService) CreateUnitConversion(createUnitConversionCommand *command.CreateUnitConversionCommand) (interface{}, error) {
if err := createUnitConversionCommand.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()
}()
newUnitConversion := &domain.UnitConversion{
CompanyId: createUnitConversionCommand.CompanyId,
OrgId: createUnitConversionCommand.OrgId,
//WorkshopId: createUnitConversionCommand.WorkshopId,
//LineId: createUnitConversionCommand.LineId,
//SectionId: createUnitConversionCommand.SectionId,
//Material: createUnitConversionCommand.Material,
//FromUnitQuantity: createUnitConversionCommand.FromUnitQuantity,
//ToUnitQuantity: createUnitConversionCommand.ToUnitQuantity,
IntelligentWeighingFlag: createUnitConversionCommand.IntelligentWeighingFlag,
}
var unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
if unitConversion, err := unitConversionRepository.Save(newUnitConversion); 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 unitConversion, nil
}
}
// 返回单位换算服务
func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitConversionQuery *query.GetUnitConversionQuery) (interface{}, error) {
if err := getUnitConversionQuery.ValidateQuery(); 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 unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": getUnitConversionQuery.UnitConversionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if unitConversion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUnitConversionQuery.UnitConversionId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return unitConversion, nil
}
}
// 返回单位换算服务列表
func (unitConversionService *UnitConversionService) ListUnitConversion(listUnitConversionQuery *query.ListUnitConversionQuery) (interface{}, error) {
if err := listUnitConversionQuery.ValidateQuery(); 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 unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
if count, unitConversions, err := unitConversionRepository.Find(tool_funs.SimpleStructToMap(listUnitConversionQuery)); 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 map[string]interface{}{
"count": count,
"unitConversions": unitConversions,
}, nil
}
}
// 移除单位换算服务
func (unitConversionService *UnitConversionService) RemoveUnitConversion(removeUnitConversionCommand *command.RemoveUnitConversionCommand) (interface{}, error) {
if err := removeUnitConversionCommand.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 unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": removeUnitConversionCommand.UnitConversionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if unitConversion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeUnitConversionCommand.UnitConversionId)))
}
if unitConversion, err := unitConversionRepository.Remove(unitConversion); 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 unitConversion, nil
}
}
// 更新单位换算服务
func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateUnitConversionCommand *command.UpdateUnitConversionCommand) (interface{}, error) {
if err := updateUnitConversionCommand.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 unitConversionRepository domain.UnitConversionRepository
if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
unitConversionRepository = value
}
unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": updateUnitConversionCommand.UnitConversionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if unitConversion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUnitConversionCommand.UnitConversionId)))
}
if err := unitConversion.Update(tool_funs.SimpleStructToMap(updateUnitConversionCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if unitConversion, err := unitConversionRepository.Save(unitConversion); 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 unitConversion, nil
}
}
func NewUnitConversionService(options map[string]interface{}) *UnitConversionService {
newUnitConversionService := &UnitConversionService{}
return newUnitConversionService
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type CreateWorkshopCommand struct {
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
// 负责人ID
PrincipalId int `cname:"负责人ID" json:"principalId,omitempty"`
}
func (createWorkshopCommand *CreateWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createWorkshopCommand *CreateWorkshopCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createWorkshopCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createWorkshopCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveWorkshopCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
}
func (removeWorkshopCommand *RemoveWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeWorkshopCommand *RemoveWorkshopCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeWorkshopCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeWorkshopCommand).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
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateWorkshopCommand struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
// 负责人ID
PrincipalId int `cname:"负责人ID" json:"principalId" valid:"Required"`
}
func (updateWorkshopCommand *UpdateWorkshopCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateWorkshopCommand *UpdateWorkshopCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateWorkshopCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateWorkshopCommand).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetWorkshopQuery struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
}
func (getWorkshopQuery *GetWorkshopQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getWorkshopQuery *GetWorkshopQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getWorkshopQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getWorkshopQuery).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
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListWorkshopQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listWorkshopQuery *ListWorkshopQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listWorkshopQuery *ListWorkshopQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listWorkshopQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listWorkshopQuery).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
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"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/workshop/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
// 车间服务
type WorkshopService struct {
}
// 创建车间服务
func (workshopService *WorkshopService) CreateWorkshop(createWorkshopCommand *command.CreateWorkshopCommand) (interface{}, error) {
if err := createWorkshopCommand.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()
}()
newWorkshop := &domain.Workshop{
WorkshopName: createWorkshopCommand.WorkshopName,
//PrincipalId: createWorkshopCommand.PrincipalId,
}
var workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
if workshop, err := workshopRepository.Save(newWorkshop); 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 workshop, nil
}
}
// 返回车间服务
func (workshopService *WorkshopService) GetWorkshop(getWorkshopQuery *query.GetWorkshopQuery) (interface{}, error) {
if err := getWorkshopQuery.ValidateQuery(); 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 workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": getWorkshopQuery.WorkshopId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getWorkshopQuery.WorkshopId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return workshop, nil
}
}
// 返回车间服务列表
func (workshopService *WorkshopService) ListWorkshop(listWorkshopQuery *query.ListWorkshopQuery) (interface{}, error) {
if err := listWorkshopQuery.ValidateQuery(); 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 workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
if count, workshops, err := workshopRepository.Find(tool_funs.SimpleStructToMap(listWorkshopQuery)); 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 map[string]interface{}{
"count": count,
"workshops": workshops,
}, nil
}
}
// 移除车间服务
func (workshopService *WorkshopService) RemoveWorkshop(removeWorkshopCommand *command.RemoveWorkshopCommand) (interface{}, error) {
if err := removeWorkshopCommand.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 workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": removeWorkshopCommand.WorkshopId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeWorkshopCommand.WorkshopId)))
}
if workshop, err := workshopRepository.Remove(workshop); 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 workshop, nil
}
}
// 更新车间服务
func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *command.UpdateWorkshopCommand) (interface{}, error) {
if err := updateWorkshopCommand.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 workshopRepository domain.WorkshopRepository
if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
workshopRepository = value
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": updateWorkshopCommand.WorkshopId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if workshop == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateWorkshopCommand.WorkshopId)))
}
if err := workshop.Update(tool_funs.SimpleStructToMap(updateWorkshopCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if workshop, err := workshopRepository.Save(workshop); 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 workshop, nil
}
}
func NewWorkshopService(options map[string]interface{}) *WorkshopService {
newWorkshopService := &WorkshopService{}
return newWorkshopService
}
... ...
... ... @@ -16,7 +16,7 @@ func init() {
web.BConfig.RunMode = "dev"
web.BConfig.Listen.HTTPPort = 8080
web.BConfig.Listen.EnableAdmin = false
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego"
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
if os.Getenv("RUN_MODE") != "" {
web.BConfig.RunMode = os.Getenv("RUN_MODE")
}
... ...