作者 yangfu

服务初始化

正在显示 67 个修改的文件 包含 4779 行增加1 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateDeviceCommand struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 设备编号
  17 + DeviceCode string `cname:"设备编号" json:"deviceCode" valid:"Required"`
  18 + // 设备名称
  19 + DeviceName string `cname:"设备名称" json:"deviceName" valid:"Required"`
  20 + // 设备型号
  21 + DeviceModel string `cname:"设备型号" json:"deviceModel" valid:"Required"`
  22 + // 设备类型
  23 + DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
  24 + // 车间ID
  25 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  26 + // 生产线ID
  27 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  28 + // 工段ID
  29 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  30 + // 品牌
  31 + Brand string `cname:"品牌" json:"brand" valid:"Required"`
  32 + // 设备状态 1:正常 2:封存 3:报废
  33 + DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
  34 + // 风险等级 1:高 2:中 3:低
  35 + RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
  36 +}
  37 +
  38 +func (createDeviceCommand *CreateDeviceCommand) Valid(validation *validation.Validation) {
  39 + validation.SetError("CustomValid", "未实现的自定义认证")
  40 +}
  41 +
  42 +func (createDeviceCommand *CreateDeviceCommand) ValidateCommand() error {
  43 + valid := validation.Validation{}
  44 + b, err := valid.Valid(createDeviceCommand)
  45 + if err != nil {
  46 + return err
  47 + }
  48 + if !b {
  49 + elem := reflect.TypeOf(createDeviceCommand).Elem()
  50 + for _, validErr := range valid.Errors {
  51 + field, isExist := elem.FieldByName(validErr.Field)
  52 + if isExist {
  53 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  54 + } else {
  55 + return fmt.Errorf(validErr.Message)
  56 + }
  57 + }
  58 + }
  59 + return nil
  60 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveDeviceCommand struct {
  12 + // 设备Id
  13 + DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeDeviceCommand *RemoveDeviceCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeDeviceCommand *RemoveDeviceCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeDeviceCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeDeviceCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateDeviceCommand struct {
  12 + // 设备Id
  13 + DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
  14 + // 设备编号
  15 + DeviceCode string `cname:"设备编号" json:"deviceCode" valid:"Required"`
  16 + // 设备名称
  17 + DeviceName string `cname:"设备名称" json:"deviceName" valid:"Required"`
  18 + // 设备型号
  19 + DeviceModel string `cname:"设备型号" json:"deviceModel" valid:"Required"`
  20 + // 设备类型
  21 + DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
  22 + // 车间ID
  23 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  24 + // 生产线ID
  25 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  26 + // 工段ID
  27 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  28 + // 品牌
  29 + Brand string `cname:"品牌" json:"brand" valid:"Required"`
  30 + // 设备状态 1:正常 2:封存 3:报废
  31 + DeviceStatus int `cname:"设备状态 1:正常 2:封存 3:报废" json:"deviceStatus" valid:"Required"`
  32 + // 风险等级 1:高 2:中 3:低
  33 + RiskLevel int `cname:"风险等级 1:高 2:中 3:低" json:"riskLevel" valid:"Required"`
  34 +}
  35 +
  36 +func (updateDeviceCommand *UpdateDeviceCommand) Valid(validation *validation.Validation) {
  37 + validation.SetError("CustomValid", "未实现的自定义认证")
  38 +}
  39 +
  40 +func (updateDeviceCommand *UpdateDeviceCommand) ValidateCommand() error {
  41 + valid := validation.Validation{}
  42 + b, err := valid.Valid(updateDeviceCommand)
  43 + if err != nil {
  44 + return err
  45 + }
  46 + if !b {
  47 + elem := reflect.TypeOf(updateDeviceCommand).Elem()
  48 + for _, validErr := range valid.Errors {
  49 + field, isExist := elem.FieldByName(validErr.Field)
  50 + if isExist {
  51 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  52 + } else {
  53 + return fmt.Errorf(validErr.Message)
  54 + }
  55 + }
  56 + }
  57 + return nil
  58 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetDeviceQuery struct {
  12 + // 设备Id
  13 + DeviceId int `cname:"设备Id" json:"deviceId" valid:"Required"`
  14 +}
  15 +
  16 +func (getDeviceQuery *GetDeviceQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getDeviceQuery *GetDeviceQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getDeviceQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getDeviceQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListDeviceQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listDeviceQuery *ListDeviceQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listDeviceQuery *ListDeviceQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listDeviceQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listDeviceQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 设备服务
  14 +type DeviceService struct {
  15 +}
  16 +
  17 +// 创建设备服务
  18 +func (deviceService *DeviceService) CreateDevice(createDeviceCommand *command.CreateDeviceCommand) (interface{}, error) {
  19 + if err := createDeviceCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newDevice := &domain.Device{
  33 + CompanyId: createDeviceCommand.CompanyId,
  34 + OrgId: createDeviceCommand.OrgId,
  35 + DeviceCode: createDeviceCommand.DeviceCode,
  36 + DeviceName: createDeviceCommand.DeviceName,
  37 + DeviceModel: createDeviceCommand.DeviceModel,
  38 + DeviceType: createDeviceCommand.DeviceType,
  39 + //WorkshopId: createDeviceCommand.WorkshopId,
  40 + //LineId: createDeviceCommand.LineId,
  41 + //SectionId: createDeviceCommand.SectionId,
  42 + Brand: createDeviceCommand.Brand,
  43 + DeviceStatus: createDeviceCommand.DeviceStatus,
  44 + RiskLevel: createDeviceCommand.RiskLevel,
  45 + }
  46 + var deviceRepository domain.DeviceRepository
  47 + if value, err := factory.CreateDeviceRepository(map[string]interface{}{
  48 + "transactionContext": transactionContext,
  49 + }); err != nil {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  51 + } else {
  52 + deviceRepository = value
  53 + }
  54 + if device, err := deviceRepository.Save(newDevice); err != nil {
  55 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  56 + } else {
  57 + if err := transactionContext.CommitTransaction(); err != nil {
  58 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  59 + }
  60 + return device, nil
  61 + }
  62 +}
  63 +
  64 +// 返回设备服务
  65 +func (deviceService *DeviceService) GetDevice(getDeviceQuery *query.GetDeviceQuery) (interface{}, error) {
  66 + if err := getDeviceQuery.ValidateQuery(); err != nil {
  67 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  68 + }
  69 + transactionContext, err := factory.CreateTransactionContext(nil)
  70 + if err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + if err := transactionContext.StartTransaction(); err != nil {
  74 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  75 + }
  76 + defer func() {
  77 + transactionContext.RollbackTransaction()
  78 + }()
  79 + var deviceRepository domain.DeviceRepository
  80 + if value, err := factory.CreateDeviceRepository(map[string]interface{}{
  81 + "transactionContext": transactionContext,
  82 + }); err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + } else {
  85 + deviceRepository = value
  86 + }
  87 + device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": getDeviceQuery.DeviceId})
  88 + if err != nil {
  89 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  90 + }
  91 + if device == nil {
  92 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDeviceQuery.DeviceId)))
  93 + } else {
  94 + if err := transactionContext.CommitTransaction(); err != nil {
  95 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  96 + }
  97 + return device, nil
  98 + }
  99 +}
  100 +
  101 +// 返回设备服务列表
  102 +func (deviceService *DeviceService) ListDevice(listDeviceQuery *query.ListDeviceQuery) (interface{}, error) {
  103 + if err := listDeviceQuery.ValidateQuery(); err != nil {
  104 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  105 + }
  106 + transactionContext, err := factory.CreateTransactionContext(nil)
  107 + if err != nil {
  108 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  109 + }
  110 + if err := transactionContext.StartTransaction(); err != nil {
  111 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  112 + }
  113 + defer func() {
  114 + transactionContext.RollbackTransaction()
  115 + }()
  116 + var deviceRepository domain.DeviceRepository
  117 + if value, err := factory.CreateDeviceRepository(map[string]interface{}{
  118 + "transactionContext": transactionContext,
  119 + }); err != nil {
  120 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  121 + } else {
  122 + deviceRepository = value
  123 + }
  124 + if count, devices, err := deviceRepository.Find(tool_funs.SimpleStructToMap(listDeviceQuery)); err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + } else {
  127 + if err := transactionContext.CommitTransaction(); err != nil {
  128 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  129 + }
  130 + return map[string]interface{}{
  131 + "count": count,
  132 + "devices": devices,
  133 + }, nil
  134 + }
  135 +}
  136 +
  137 +// 移除设备服务
  138 +func (deviceService *DeviceService) RemoveDevice(removeDeviceCommand *command.RemoveDeviceCommand) (interface{}, error) {
  139 + if err := removeDeviceCommand.ValidateCommand(); err != nil {
  140 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  141 + }
  142 + transactionContext, err := factory.CreateTransactionContext(nil)
  143 + if err != nil {
  144 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  145 + }
  146 + if err := transactionContext.StartTransaction(); err != nil {
  147 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  148 + }
  149 + defer func() {
  150 + transactionContext.RollbackTransaction()
  151 + }()
  152 + var deviceRepository domain.DeviceRepository
  153 + if value, err := factory.CreateDeviceRepository(map[string]interface{}{
  154 + "transactionContext": transactionContext,
  155 + }); err != nil {
  156 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  157 + } else {
  158 + deviceRepository = value
  159 + }
  160 + device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": removeDeviceCommand.DeviceId})
  161 + if err != nil {
  162 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  163 + }
  164 + if device == nil {
  165 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDeviceCommand.DeviceId)))
  166 + }
  167 + if device, err := deviceRepository.Remove(device); err != nil {
  168 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  169 + } else {
  170 + if err := transactionContext.CommitTransaction(); err != nil {
  171 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  172 + }
  173 + return device, nil
  174 + }
  175 +}
  176 +
  177 +// 更新设备服务
  178 +func (deviceService *DeviceService) UpdateDevice(updateDeviceCommand *command.UpdateDeviceCommand) (interface{}, error) {
  179 + if err := updateDeviceCommand.ValidateCommand(); err != nil {
  180 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  181 + }
  182 + transactionContext, err := factory.CreateTransactionContext(nil)
  183 + if err != nil {
  184 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  185 + }
  186 + if err := transactionContext.StartTransaction(); err != nil {
  187 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  188 + }
  189 + defer func() {
  190 + transactionContext.RollbackTransaction()
  191 + }()
  192 + var deviceRepository domain.DeviceRepository
  193 + if value, err := factory.CreateDeviceRepository(map[string]interface{}{
  194 + "transactionContext": transactionContext,
  195 + }); err != nil {
  196 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  197 + } else {
  198 + deviceRepository = value
  199 + }
  200 + device, err := deviceRepository.FindOne(map[string]interface{}{"deviceId": updateDeviceCommand.DeviceId})
  201 + if err != nil {
  202 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  203 + }
  204 + if device == nil {
  205 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDeviceCommand.DeviceId)))
  206 + }
  207 + if err := device.Update(tool_funs.SimpleStructToMap(updateDeviceCommand)); err != nil {
  208 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  209 + }
  210 + if device, err := deviceRepository.Save(device); err != nil {
  211 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  212 + } else {
  213 + if err := transactionContext.CommitTransaction(); err != nil {
  214 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  215 + }
  216 + return device, nil
  217 + }
  218 +}
  219 +
  220 +func NewDeviceService(options map[string]interface{}) *DeviceService {
  221 + newDeviceService := &DeviceService{}
  222 + return newDeviceService
  223 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateProductCommand struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
  17 + ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"`
  18 + // 产品名称
  19 + ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
  20 + // 产品类别
  21 + ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
  22 + // 数量(保留两位小数)
  23 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  24 + // 单位
  25 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  26 + // 单份重量(原材料)
  27 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  28 + // 重量
  29 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  30 +}
  31 +
  32 +func (createProductCommand *CreateProductCommand) Valid(validation *validation.Validation) {
  33 + validation.SetError("CustomValid", "未实现的自定义认证")
  34 +}
  35 +
  36 +func (createProductCommand *CreateProductCommand) ValidateCommand() error {
  37 + valid := validation.Validation{}
  38 + b, err := valid.Valid(createProductCommand)
  39 + if err != nil {
  40 + return err
  41 + }
  42 + if !b {
  43 + elem := reflect.TypeOf(createProductCommand).Elem()
  44 + for _, validErr := range valid.Errors {
  45 + field, isExist := elem.FieldByName(validErr.Field)
  46 + if isExist {
  47 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  48 + } else {
  49 + return fmt.Errorf(validErr.Message)
  50 + }
  51 + }
  52 + }
  53 + return nil
  54 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductCommand struct {
  12 + // 产品ID
  13 + ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeProductCommand *RemoveProductCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeProductCommand *RemoveProductCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeProductCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeProductCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateProductCommand struct {
  12 + // 产品ID
  13 + ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
  14 + // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
  15 + ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"`
  16 + // 产品名称
  17 + ProductName string `cname:"产品名称" json:"productName" valid:"Required"`
  18 + // 产品类别
  19 + ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"`
  20 + // 数量(保留两位小数)
  21 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  22 + // 单位
  23 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  24 + // 单份重量(原材料)
  25 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  26 + // 重量
  27 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  28 +}
  29 +
  30 +func (updateProductCommand *UpdateProductCommand) Valid(validation *validation.Validation) {
  31 + validation.SetError("CustomValid", "未实现的自定义认证")
  32 +}
  33 +
  34 +func (updateProductCommand *UpdateProductCommand) ValidateCommand() error {
  35 + valid := validation.Validation{}
  36 + b, err := valid.Valid(updateProductCommand)
  37 + if err != nil {
  38 + return err
  39 + }
  40 + if !b {
  41 + elem := reflect.TypeOf(updateProductCommand).Elem()
  42 + for _, validErr := range valid.Errors {
  43 + field, isExist := elem.FieldByName(validErr.Field)
  44 + if isExist {
  45 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  46 + } else {
  47 + return fmt.Errorf(validErr.Message)
  48 + }
  49 + }
  50 + }
  51 + return nil
  52 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductQuery struct {
  12 + // 产品ID
  13 + ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
  14 +}
  15 +
  16 +func (getProductQuery *GetProductQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getProductQuery *GetProductQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getProductQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getProductQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductQuery *ListProductQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductQuery *ListProductQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 产品服务
  14 +type ProductService struct {
  15 +}
  16 +
  17 +// 创建产品服务
  18 +func (productService *ProductService) CreateProduct(createProductCommand *command.CreateProductCommand) (interface{}, error) {
  19 + if err := createProductCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProduct := &domain.Product{
  33 + CompanyId: createProductCommand.CompanyId,
  34 + OrgId: createProductCommand.OrgId,
  35 + ProductCode: createProductCommand.ProductCode,
  36 + ProductName: createProductCommand.ProductName,
  37 + ProductCategory: createProductCommand.ProductCategory,
  38 + //ProductSpec: createProductCommand.ProductSpec,
  39 + }
  40 + var productRepository domain.ProductRepository
  41 + if value, err := factory.CreateProductRepository(map[string]interface{}{
  42 + "transactionContext": transactionContext,
  43 + }); err != nil {
  44 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  45 + } else {
  46 + productRepository = value
  47 + }
  48 + if product, err := productRepository.Save(newProduct); err != nil {
  49 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  50 + } else {
  51 + if err := transactionContext.CommitTransaction(); err != nil {
  52 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  53 + }
  54 + return product, nil
  55 + }
  56 +}
  57 +
  58 +// 返回产品服务
  59 +func (productService *ProductService) GetProduct(getProductQuery *query.GetProductQuery) (interface{}, error) {
  60 + if err := getProductQuery.ValidateQuery(); err != nil {
  61 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  62 + }
  63 + transactionContext, err := factory.CreateTransactionContext(nil)
  64 + if err != nil {
  65 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  66 + }
  67 + if err := transactionContext.StartTransaction(); err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + defer func() {
  71 + transactionContext.RollbackTransaction()
  72 + }()
  73 + var productRepository domain.ProductRepository
  74 + if value, err := factory.CreateProductRepository(map[string]interface{}{
  75 + "transactionContext": transactionContext,
  76 + }); err != nil {
  77 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  78 + } else {
  79 + productRepository = value
  80 + }
  81 + product, err := productRepository.FindOne(map[string]interface{}{"productId": getProductQuery.ProductId})
  82 + if err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + }
  85 + if product == nil {
  86 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductQuery.ProductId)))
  87 + } else {
  88 + if err := transactionContext.CommitTransaction(); err != nil {
  89 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  90 + }
  91 + return product, nil
  92 + }
  93 +}
  94 +
  95 +// 返回产品服务列表
  96 +func (productService *ProductService) ListProduct(listProductQuery *query.ListProductQuery) (interface{}, error) {
  97 + if err := listProductQuery.ValidateQuery(); err != nil {
  98 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  99 + }
  100 + transactionContext, err := factory.CreateTransactionContext(nil)
  101 + if err != nil {
  102 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  103 + }
  104 + if err := transactionContext.StartTransaction(); err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + defer func() {
  108 + transactionContext.RollbackTransaction()
  109 + }()
  110 + var productRepository domain.ProductRepository
  111 + if value, err := factory.CreateProductRepository(map[string]interface{}{
  112 + "transactionContext": transactionContext,
  113 + }); err != nil {
  114 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 + } else {
  116 + productRepository = value
  117 + }
  118 + if count, products, err := productRepository.Find(tool_funs.SimpleStructToMap(listProductQuery)); err != nil {
  119 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  120 + } else {
  121 + if err := transactionContext.CommitTransaction(); err != nil {
  122 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  123 + }
  124 + return map[string]interface{}{
  125 + "count": count,
  126 + "products": products,
  127 + }, nil
  128 + }
  129 +}
  130 +
  131 +// 移除产品服务
  132 +func (productService *ProductService) RemoveProduct(removeProductCommand *command.RemoveProductCommand) (interface{}, error) {
  133 + if err := removeProductCommand.ValidateCommand(); err != nil {
  134 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  135 + }
  136 + transactionContext, err := factory.CreateTransactionContext(nil)
  137 + if err != nil {
  138 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  139 + }
  140 + if err := transactionContext.StartTransaction(); err != nil {
  141 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  142 + }
  143 + defer func() {
  144 + transactionContext.RollbackTransaction()
  145 + }()
  146 + var productRepository domain.ProductRepository
  147 + if value, err := factory.CreateProductRepository(map[string]interface{}{
  148 + "transactionContext": transactionContext,
  149 + }); err != nil {
  150 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  151 + } else {
  152 + productRepository = value
  153 + }
  154 + product, err := productRepository.FindOne(map[string]interface{}{"productId": removeProductCommand.ProductId})
  155 + if err != nil {
  156 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  157 + }
  158 + if product == nil {
  159 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductCommand.ProductId)))
  160 + }
  161 + if product, err := productRepository.Remove(product); err != nil {
  162 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  163 + } else {
  164 + if err := transactionContext.CommitTransaction(); err != nil {
  165 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  166 + }
  167 + return product, nil
  168 + }
  169 +}
  170 +
  171 +// 更新产品服务
  172 +func (productService *ProductService) UpdateProduct(updateProductCommand *command.UpdateProductCommand) (interface{}, error) {
  173 + if err := updateProductCommand.ValidateCommand(); err != nil {
  174 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  175 + }
  176 + transactionContext, err := factory.CreateTransactionContext(nil)
  177 + if err != nil {
  178 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  179 + }
  180 + if err := transactionContext.StartTransaction(); err != nil {
  181 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  182 + }
  183 + defer func() {
  184 + transactionContext.RollbackTransaction()
  185 + }()
  186 + var productRepository domain.ProductRepository
  187 + if value, err := factory.CreateProductRepository(map[string]interface{}{
  188 + "transactionContext": transactionContext,
  189 + }); err != nil {
  190 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  191 + } else {
  192 + productRepository = value
  193 + }
  194 + product, err := productRepository.FindOne(map[string]interface{}{"productId": updateProductCommand.ProductId})
  195 + if err != nil {
  196 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  197 + }
  198 + if product == nil {
  199 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCommand.ProductId)))
  200 + }
  201 + if err := product.Update(tool_funs.SimpleStructToMap(updateProductCommand)); err != nil {
  202 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  203 + }
  204 + if product, err := productRepository.Save(product); err != nil {
  205 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  206 + } else {
  207 + if err := transactionContext.CommitTransaction(); err != nil {
  208 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  209 + }
  210 + return product, nil
  211 + }
  212 +}
  213 +
  214 +func NewProductService(options map[string]interface{}) *ProductService {
  215 + newProductService := &ProductService{}
  216 + return newProductService
  217 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateProductCalendarCommand struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 车间ID
  17 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  18 + // 生产线ID
  19 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  20 + // 工段ID
  21 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  22 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  23 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  24 + // 日历选择
  25 + CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
  26 + // 上岗时间
  27 + InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
  28 + // 下岗时间
  29 + OutWorkAt string `cname:"下岗时间" json:"outWorkAt" valid:"Required"`
  30 + // 休息时间 (单位 h)
  31 + BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
  32 + // 工时 (单位 h)
  33 + WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
  34 +}
  35 +
  36 +func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) {
  37 + validation.SetError("CustomValid", "未实现的自定义认证")
  38 +}
  39 +
  40 +func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error {
  41 + valid := validation.Validation{}
  42 + b, err := valid.Valid(createProductCalendarCommand)
  43 + if err != nil {
  44 + return err
  45 + }
  46 + if !b {
  47 + elem := reflect.TypeOf(createProductCalendarCommand).Elem()
  48 + for _, validErr := range valid.Errors {
  49 + field, isExist := elem.FieldByName(validErr.Field)
  50 + if isExist {
  51 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  52 + } else {
  53 + return fmt.Errorf(validErr.Message)
  54 + }
  55 + }
  56 + }
  57 + return nil
  58 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductCalendarCommand struct {
  12 + // 工厂日历ID
  13 + ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeProductCalendarCommand *RemoveProductCalendarCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeProductCalendarCommand *RemoveProductCalendarCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeProductCalendarCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeProductCalendarCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateProductCalendarCommand struct {
  12 + // 工厂日历ID
  13 + ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
  14 + // 车间ID
  15 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  16 + // 生产线ID
  17 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  18 + // 工段ID
  19 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  20 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  21 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  22 + // 日历选择
  23 + CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
  24 + // 上岗时间
  25 + InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
  26 + // 下岗时间
  27 + OutWorkAt string `cname:"下岗时间" json:"outWorkAt" valid:"Required"`
  28 + // 休息时间 (单位 h)
  29 + BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
  30 + // 工时 (单位 h)
  31 + WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
  32 +}
  33 +
  34 +func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) {
  35 + validation.SetError("CustomValid", "未实现的自定义认证")
  36 +}
  37 +
  38 +func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error {
  39 + valid := validation.Validation{}
  40 + b, err := valid.Valid(updateProductCalendarCommand)
  41 + if err != nil {
  42 + return err
  43 + }
  44 + if !b {
  45 + elem := reflect.TypeOf(updateProductCalendarCommand).Elem()
  46 + for _, validErr := range valid.Errors {
  47 + field, isExist := elem.FieldByName(validErr.Field)
  48 + if isExist {
  49 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  50 + } else {
  51 + return fmt.Errorf(validErr.Message)
  52 + }
  53 + }
  54 + }
  55 + return nil
  56 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductCalendarQuery struct {
  12 + // 工厂日历ID
  13 + ProductCalendarId int `cname:"工厂日历ID" json:"productCalendarId" valid:"Required"`
  14 +}
  15 +
  16 +func (getProductCalendarQuery *GetProductCalendarQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getProductCalendarQuery *GetProductCalendarQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getProductCalendarQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getProductCalendarQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductCalendarQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductCalendarQuery *ListProductCalendarQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductCalendarQuery *ListProductCalendarQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductCalendarQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductCalendarQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 工厂日历服务
  14 +type ProductCalendarService struct {
  15 +}
  16 +
  17 +// 创建工厂日历服务
  18 +func (productCalendarService *ProductCalendarService) CreateProductCalendar(createProductCalendarCommand *command.CreateProductCalendarCommand) (interface{}, error) {
  19 + if err := createProductCalendarCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProductCalendar := &domain.ProductCalendar{
  33 + CompanyId: createProductCalendarCommand.CompanyId,
  34 + OrgId: createProductCalendarCommand.OrgId,
  35 + //WorkshopId: createProductCalendarCommand.WorkshopId,
  36 + //LineId: createProductCalendarCommand.LineId,
  37 + //SectionId: createProductCalendarCommand.SectionId,
  38 + //WorkOn: createProductCalendarCommand.WorkOn,
  39 + CalendarSelected: createProductCalendarCommand.CalendarSelected,
  40 + InWorkAt: createProductCalendarCommand.InWorkAt,
  41 + OutWorkAt: createProductCalendarCommand.OutWorkAt,
  42 + BreakTime: createProductCalendarCommand.BreakTime,
  43 + WorkTime: createProductCalendarCommand.WorkTime,
  44 + }
  45 + var productCalendarRepository domain.ProductCalendarRepository
  46 + if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
  47 + "transactionContext": transactionContext,
  48 + }); err != nil {
  49 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  50 + } else {
  51 + productCalendarRepository = value
  52 + }
  53 + if productCalendar, err := productCalendarRepository.Save(newProductCalendar); err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + } else {
  56 + if err := transactionContext.CommitTransaction(); err != nil {
  57 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  58 + }
  59 + return productCalendar, nil
  60 + }
  61 +}
  62 +
  63 +// 返回工厂日历服务
  64 +func (productCalendarService *ProductCalendarService) GetProductCalendar(getProductCalendarQuery *query.GetProductCalendarQuery) (interface{}, error) {
  65 + if err := getProductCalendarQuery.ValidateQuery(); err != nil {
  66 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  67 + }
  68 + transactionContext, err := factory.CreateTransactionContext(nil)
  69 + if err != nil {
  70 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  71 + }
  72 + if err := transactionContext.StartTransaction(); err != nil {
  73 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  74 + }
  75 + defer func() {
  76 + transactionContext.RollbackTransaction()
  77 + }()
  78 + var productCalendarRepository domain.ProductCalendarRepository
  79 + if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
  80 + "transactionContext": transactionContext,
  81 + }); err != nil {
  82 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  83 + } else {
  84 + productCalendarRepository = value
  85 + }
  86 + productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": getProductCalendarQuery.ProductCalendarId})
  87 + if err != nil {
  88 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  89 + }
  90 + if productCalendar == nil {
  91 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductCalendarQuery.ProductCalendarId)))
  92 + } else {
  93 + if err := transactionContext.CommitTransaction(); err != nil {
  94 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  95 + }
  96 + return productCalendar, nil
  97 + }
  98 +}
  99 +
  100 +// 返回工厂日历服务列表
  101 +func (productCalendarService *ProductCalendarService) ListProductCalendar(listProductCalendarQuery *query.ListProductCalendarQuery) (interface{}, error) {
  102 + if err := listProductCalendarQuery.ValidateQuery(); err != nil {
  103 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  104 + }
  105 + transactionContext, err := factory.CreateTransactionContext(nil)
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.StartTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + defer func() {
  113 + transactionContext.RollbackTransaction()
  114 + }()
  115 + var productCalendarRepository domain.ProductCalendarRepository
  116 + if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
  117 + "transactionContext": transactionContext,
  118 + }); err != nil {
  119 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  120 + } else {
  121 + productCalendarRepository = value
  122 + }
  123 + if count, productCalendars, err := productCalendarRepository.Find(tool_funs.SimpleStructToMap(listProductCalendarQuery)); err != nil {
  124 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  125 + } else {
  126 + if err := transactionContext.CommitTransaction(); err != nil {
  127 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  128 + }
  129 + return map[string]interface{}{
  130 + "count": count,
  131 + "productCalendars": productCalendars,
  132 + }, nil
  133 + }
  134 +}
  135 +
  136 +// 移除工厂日历服务
  137 +func (productCalendarService *ProductCalendarService) RemoveProductCalendar(removeProductCalendarCommand *command.RemoveProductCalendarCommand) (interface{}, error) {
  138 + if err := removeProductCalendarCommand.ValidateCommand(); err != nil {
  139 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  140 + }
  141 + transactionContext, err := factory.CreateTransactionContext(nil)
  142 + if err != nil {
  143 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  144 + }
  145 + if err := transactionContext.StartTransaction(); err != nil {
  146 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  147 + }
  148 + defer func() {
  149 + transactionContext.RollbackTransaction()
  150 + }()
  151 + var productCalendarRepository domain.ProductCalendarRepository
  152 + if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
  153 + "transactionContext": transactionContext,
  154 + }); err != nil {
  155 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  156 + } else {
  157 + productCalendarRepository = value
  158 + }
  159 + productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": removeProductCalendarCommand.ProductCalendarId})
  160 + if err != nil {
  161 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  162 + }
  163 + if productCalendar == nil {
  164 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductCalendarCommand.ProductCalendarId)))
  165 + }
  166 + if productCalendar, err := productCalendarRepository.Remove(productCalendar); err != nil {
  167 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  168 + } else {
  169 + if err := transactionContext.CommitTransaction(); err != nil {
  170 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  171 + }
  172 + return productCalendar, nil
  173 + }
  174 +}
  175 +
  176 +// 更新工厂日历服务
  177 +func (productCalendarService *ProductCalendarService) UpdateProductCalendar(updateProductCalendarCommand *command.UpdateProductCalendarCommand) (interface{}, error) {
  178 + if err := updateProductCalendarCommand.ValidateCommand(); err != nil {
  179 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  180 + }
  181 + transactionContext, err := factory.CreateTransactionContext(nil)
  182 + if err != nil {
  183 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  184 + }
  185 + if err := transactionContext.StartTransaction(); err != nil {
  186 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  187 + }
  188 + defer func() {
  189 + transactionContext.RollbackTransaction()
  190 + }()
  191 + var productCalendarRepository domain.ProductCalendarRepository
  192 + if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
  193 + "transactionContext": transactionContext,
  194 + }); err != nil {
  195 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  196 + } else {
  197 + productCalendarRepository = value
  198 + }
  199 + productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": updateProductCalendarCommand.ProductCalendarId})
  200 + if err != nil {
  201 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  202 + }
  203 + if productCalendar == nil {
  204 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCalendarCommand.ProductCalendarId)))
  205 + }
  206 + if err := productCalendar.Update(tool_funs.SimpleStructToMap(updateProductCalendarCommand)); err != nil {
  207 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  208 + }
  209 + if productCalendar, err := productCalendarRepository.Save(productCalendar); err != nil {
  210 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  211 + } else {
  212 + if err := transactionContext.CommitTransaction(); err != nil {
  213 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  214 + }
  215 + return productCalendar, nil
  216 + }
  217 +}
  218 +
  219 +func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService {
  220 + newProductCalendarService := &ProductCalendarService{}
  221 + return newProductCalendarService
  222 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type CreateProductGroupCommand struct {
  13 + // 企业id
  14 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  15 + // 组织ID
  16 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  17 + // 车间ID
  18 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  19 + // 生产线ID
  20 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  21 + // 工段ID
  22 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  23 + // 班组名称
  24 + GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
  25 + // 用户Id 用户唯一标识
  26 + UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
  27 + // 用户姓名
  28 + UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
  29 + // 员工类型 1:固定 2:派遣 3.临时
  30 + EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
  31 + // IC卡号
  32 + IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
  33 + // 头像
  34 + Avatar string `cname:"头像" json:"avatar" valid:"Required"`
  35 + // 手机号码
  36 + Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  37 + // 帮组成员列表
  38 + GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
  39 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  40 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  41 +}
  42 +
  43 +func (createProductGroupCommand *CreateProductGroupCommand) Valid(validation *validation.Validation) {
  44 + validation.SetError("CustomValid", "未实现的自定义认证")
  45 +}
  46 +
  47 +func (createProductGroupCommand *CreateProductGroupCommand) ValidateCommand() error {
  48 + valid := validation.Validation{}
  49 + b, err := valid.Valid(createProductGroupCommand)
  50 + if err != nil {
  51 + return err
  52 + }
  53 + if !b {
  54 + elem := reflect.TypeOf(createProductGroupCommand).Elem()
  55 + for _, validErr := range valid.Errors {
  56 + field, isExist := elem.FieldByName(validErr.Field)
  57 + if isExist {
  58 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  59 + } else {
  60 + return fmt.Errorf(validErr.Message)
  61 + }
  62 + }
  63 + }
  64 + return nil
  65 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductGroupCommand struct {
  12 + // 生产小组ID
  13 + ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeProductGroupCommand *RemoveProductGroupCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeProductGroupCommand *RemoveProductGroupCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeProductGroupCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeProductGroupCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type UpdateProductGroupCommand struct {
  13 + // 生产小组ID
  14 + ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
  15 + // 车间ID
  16 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  17 + // 生产线ID
  18 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  19 + // 工段ID
  20 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  21 + // 班组名称
  22 + GroupName string `cname:"班组名称" json:"groupName" valid:"Required"`
  23 + // 用户Id 用户唯一标识
  24 + UserId int `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
  25 + // 用户姓名
  26 + UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
  27 + // 员工类型 1:固定 2:派遣 3.临时
  28 + EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType" valid:"Required"`
  29 + // IC卡号
  30 + IcCardNumber string `cname:"IC卡号" json:"icCardNumber" valid:"Required"`
  31 + // 头像
  32 + Avatar string `cname:"头像" json:"avatar" valid:"Required"`
  33 + // 手机号码
  34 + Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  35 + // 帮组成员列表
  36 + GroupMembers []*domain.User `cname:"帮组成员列表" json:"groupMembers" valid:"Required"`
  37 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  38 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  39 +}
  40 +
  41 +func (updateProductGroupCommand *UpdateProductGroupCommand) Valid(validation *validation.Validation) {
  42 + validation.SetError("CustomValid", "未实现的自定义认证")
  43 +}
  44 +
  45 +func (updateProductGroupCommand *UpdateProductGroupCommand) ValidateCommand() error {
  46 + valid := validation.Validation{}
  47 + b, err := valid.Valid(updateProductGroupCommand)
  48 + if err != nil {
  49 + return err
  50 + }
  51 + if !b {
  52 + elem := reflect.TypeOf(updateProductGroupCommand).Elem()
  53 + for _, validErr := range valid.Errors {
  54 + field, isExist := elem.FieldByName(validErr.Field)
  55 + if isExist {
  56 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  57 + } else {
  58 + return fmt.Errorf(validErr.Message)
  59 + }
  60 + }
  61 + }
  62 + return nil
  63 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductGroupQuery struct {
  12 + // 生产小组ID
  13 + ProductGroupId int `cname:"生产小组ID" json:"productGroupId" valid:"Required"`
  14 +}
  15 +
  16 +func (getProductGroupQuery *GetProductGroupQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getProductGroupQuery *GetProductGroupQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getProductGroupQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getProductGroupQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductGroupQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductGroupQuery *ListProductGroupQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductGroupQuery *ListProductGroupQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductGroupQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductGroupQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 生产班组服务
  14 +type ProductGroupService struct {
  15 +}
  16 +
  17 +// 创建生产班组服务
  18 +func (productGroupService *ProductGroupService) CreateProductGroup(createProductGroupCommand *command.CreateProductGroupCommand) (interface{}, error) {
  19 + if err := createProductGroupCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProductGroup := &domain.ProductGroup{
  33 + CompanyId: createProductGroupCommand.CompanyId,
  34 + OrgId: createProductGroupCommand.OrgId,
  35 + //WorkshopId: createProductGroupCommand.WorkshopId,
  36 + //LineId: createProductGroupCommand.LineId,
  37 + //SectionId: createProductGroupCommand.SectionId,
  38 + GroupName: createProductGroupCommand.GroupName,
  39 + //GroupLeader: createProductGroupCommand.GroupLeader,
  40 + GroupMembers: createProductGroupCommand.GroupMembers,
  41 + WorkOn: createProductGroupCommand.WorkOn,
  42 + }
  43 + var productGroupRepository domain.ProductGroupRepository
  44 + if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
  45 + "transactionContext": transactionContext,
  46 + }); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + productGroupRepository = value
  50 + }
  51 + if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil {
  52 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  53 + } else {
  54 + if err := transactionContext.CommitTransaction(); err != nil {
  55 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  56 + }
  57 + return productGroup, nil
  58 + }
  59 +}
  60 +
  61 +// 返回生产班组服务
  62 +func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQuery *query.GetProductGroupQuery) (interface{}, error) {
  63 + if err := getProductGroupQuery.ValidateQuery(); err != nil {
  64 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  65 + }
  66 + transactionContext, err := factory.CreateTransactionContext(nil)
  67 + if err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + if err := transactionContext.StartTransaction(); err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + defer func() {
  74 + transactionContext.RollbackTransaction()
  75 + }()
  76 + var productGroupRepository domain.ProductGroupRepository
  77 + if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
  78 + "transactionContext": transactionContext,
  79 + }); err != nil {
  80 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  81 + } else {
  82 + productGroupRepository = value
  83 + }
  84 + productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": getProductGroupQuery.ProductGroupId})
  85 + if err != nil {
  86 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  87 + }
  88 + if productGroup == nil {
  89 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId)))
  90 + } else {
  91 + if err := transactionContext.CommitTransaction(); err != nil {
  92 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  93 + }
  94 + return productGroup, nil
  95 + }
  96 +}
  97 +
  98 +// 返回生产班组服务列表
  99 +func (productGroupService *ProductGroupService) ListProductGroup(listProductGroupQuery *query.ListProductGroupQuery) (interface{}, error) {
  100 + if err := listProductGroupQuery.ValidateQuery(); err != nil {
  101 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  102 + }
  103 + transactionContext, err := factory.CreateTransactionContext(nil)
  104 + if err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + if err := transactionContext.StartTransaction(); err != nil {
  108 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  109 + }
  110 + defer func() {
  111 + transactionContext.RollbackTransaction()
  112 + }()
  113 + var productGroupRepository domain.ProductGroupRepository
  114 + if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
  115 + "transactionContext": transactionContext,
  116 + }); err != nil {
  117 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  118 + } else {
  119 + productGroupRepository = value
  120 + }
  121 + if count, productGroups, err := productGroupRepository.Find(tool_funs.SimpleStructToMap(listProductGroupQuery)); err != nil {
  122 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  123 + } else {
  124 + if err := transactionContext.CommitTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  126 + }
  127 + return map[string]interface{}{
  128 + "count": count,
  129 + "productGroups": productGroups,
  130 + }, nil
  131 + }
  132 +}
  133 +
  134 +// 移除生产班组服务
  135 +func (productGroupService *ProductGroupService) RemoveProductGroup(removeProductGroupCommand *command.RemoveProductGroupCommand) (interface{}, error) {
  136 + if err := removeProductGroupCommand.ValidateCommand(); err != nil {
  137 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  138 + }
  139 + transactionContext, err := factory.CreateTransactionContext(nil)
  140 + if err != nil {
  141 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  142 + }
  143 + if err := transactionContext.StartTransaction(); err != nil {
  144 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  145 + }
  146 + defer func() {
  147 + transactionContext.RollbackTransaction()
  148 + }()
  149 + var productGroupRepository domain.ProductGroupRepository
  150 + if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
  151 + "transactionContext": transactionContext,
  152 + }); err != nil {
  153 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + } else {
  155 + productGroupRepository = value
  156 + }
  157 + productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": removeProductGroupCommand.ProductGroupId})
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + }
  161 + if productGroup == nil {
  162 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductGroupCommand.ProductGroupId)))
  163 + }
  164 + if productGroup, err := productGroupRepository.Remove(productGroup); err != nil {
  165 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  166 + } else {
  167 + if err := transactionContext.CommitTransaction(); err != nil {
  168 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  169 + }
  170 + return productGroup, nil
  171 + }
  172 +}
  173 +
  174 +// 更新生产班组服务
  175 +func (productGroupService *ProductGroupService) UpdateProductGroup(updateProductGroupCommand *command.UpdateProductGroupCommand) (interface{}, error) {
  176 + if err := updateProductGroupCommand.ValidateCommand(); err != nil {
  177 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  178 + }
  179 + transactionContext, err := factory.CreateTransactionContext(nil)
  180 + if err != nil {
  181 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  182 + }
  183 + if err := transactionContext.StartTransaction(); err != nil {
  184 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  185 + }
  186 + defer func() {
  187 + transactionContext.RollbackTransaction()
  188 + }()
  189 + var productGroupRepository domain.ProductGroupRepository
  190 + if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
  191 + "transactionContext": transactionContext,
  192 + }); err != nil {
  193 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  194 + } else {
  195 + productGroupRepository = value
  196 + }
  197 + productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": updateProductGroupCommand.ProductGroupId})
  198 + if err != nil {
  199 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  200 + }
  201 + if productGroup == nil {
  202 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductGroupCommand.ProductGroupId)))
  203 + }
  204 + if err := productGroup.Update(tool_funs.SimpleStructToMap(updateProductGroupCommand)); err != nil {
  205 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  206 + }
  207 + if productGroup, err := productGroupRepository.Save(productGroup); err != nil {
  208 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  209 + } else {
  210 + if err := transactionContext.CommitTransaction(); err != nil {
  211 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  212 + }
  213 + return productGroup, nil
  214 + }
  215 +}
  216 +
  217 +func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
  218 + newProductGroupService := &ProductGroupService{}
  219 + return newProductGroupService
  220 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateProductJobCommand struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 工位名称
  17 + JobName string `cname:"工位名称" json:"jobName" valid:"Required"`
  18 + // 车间ID
  19 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  20 + // 生产线ID
  21 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  22 + // 工段ID
  23 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  24 + // 关联设备列表
  25 + RelatedDevices []int `cname:"关联设备列表" json:"relatedDevices,omitempty"`
  26 +}
  27 +
  28 +func (createProductJobCommand *CreateProductJobCommand) Valid(validation *validation.Validation) {
  29 + validation.SetError("CustomValid", "未实现的自定义认证")
  30 +}
  31 +
  32 +func (createProductJobCommand *CreateProductJobCommand) ValidateCommand() error {
  33 + valid := validation.Validation{}
  34 + b, err := valid.Valid(createProductJobCommand)
  35 + if err != nil {
  36 + return err
  37 + }
  38 + if !b {
  39 + elem := reflect.TypeOf(createProductJobCommand).Elem()
  40 + for _, validErr := range valid.Errors {
  41 + field, isExist := elem.FieldByName(validErr.Field)
  42 + if isExist {
  43 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  44 + } else {
  45 + return fmt.Errorf(validErr.Message)
  46 + }
  47 + }
  48 + }
  49 + return nil
  50 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductJobCommand struct {
  12 + // 工位ID
  13 + ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeProductJobCommand *RemoveProductJobCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeProductJobCommand *RemoveProductJobCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeProductJobCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeProductJobCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateProductJobCommand struct {
  12 + // 工位ID
  13 + ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
  14 + // 工位名称
  15 + JobName string `cname:"工位名称" json:"jobName" valid:"Required"`
  16 + // 车间ID
  17 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  18 + // 生产线ID
  19 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  20 + // 工段ID
  21 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  22 + // 关联设备列表
  23 + RelatedDevices []int `cname:"关联设备列表" json:"relatedDevices,omitempty"`
  24 +}
  25 +
  26 +func (updateProductJobCommand *UpdateProductJobCommand) Valid(validation *validation.Validation) {
  27 + validation.SetError("CustomValid", "未实现的自定义认证")
  28 +}
  29 +
  30 +func (updateProductJobCommand *UpdateProductJobCommand) ValidateCommand() error {
  31 + valid := validation.Validation{}
  32 + b, err := valid.Valid(updateProductJobCommand)
  33 + if err != nil {
  34 + return err
  35 + }
  36 + if !b {
  37 + elem := reflect.TypeOf(updateProductJobCommand).Elem()
  38 + for _, validErr := range valid.Errors {
  39 + field, isExist := elem.FieldByName(validErr.Field)
  40 + if isExist {
  41 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  42 + } else {
  43 + return fmt.Errorf(validErr.Message)
  44 + }
  45 + }
  46 + }
  47 + return nil
  48 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductJobQuery struct {
  12 + // 工位ID
  13 + ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"`
  14 +}
  15 +
  16 +func (getProductJobQuery *GetProductJobQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getProductJobQuery *GetProductJobQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getProductJobQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getProductJobQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductJobQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductJobQuery *ListProductJobQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductJobQuery *ListProductJobQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductJobQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductJobQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 工位服务
  14 +type ProductJobService struct {
  15 +}
  16 +
  17 +// 创建工位服务
  18 +func (productJobService *ProductJobService) CreateProductJob(createProductJobCommand *command.CreateProductJobCommand) (interface{}, error) {
  19 + if err := createProductJobCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProductJob := &domain.ProductJob{
  33 + CompanyId: createProductJobCommand.CompanyId,
  34 + OrgId: createProductJobCommand.OrgId,
  35 + JobName: createProductJobCommand.JobName,
  36 + //WorkshopId: createProductJobCommand.WorkshopId,
  37 + //LineId: createProductJobCommand.LineId,
  38 + //SectionId: createProductJobCommand.SectionId,
  39 + RelatedDevices: createProductJobCommand.RelatedDevices,
  40 + }
  41 + var productJobRepository domain.ProductJobRepository
  42 + if value, err := factory.CreateProductJobRepository(map[string]interface{}{
  43 + "transactionContext": transactionContext,
  44 + }); err != nil {
  45 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 + } else {
  47 + productJobRepository = value
  48 + }
  49 + if productJob, err := productJobRepository.Save(newProductJob); err != nil {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  51 + } else {
  52 + if err := transactionContext.CommitTransaction(); err != nil {
  53 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  54 + }
  55 + return productJob, nil
  56 + }
  57 +}
  58 +
  59 +// 返回工位服务
  60 +func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *query.GetProductJobQuery) (interface{}, error) {
  61 + if err := getProductJobQuery.ValidateQuery(); err != nil {
  62 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  63 + }
  64 + transactionContext, err := factory.CreateTransactionContext(nil)
  65 + if err != nil {
  66 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  67 + }
  68 + if err := transactionContext.StartTransaction(); err != nil {
  69 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  70 + }
  71 + defer func() {
  72 + transactionContext.RollbackTransaction()
  73 + }()
  74 + var productJobRepository domain.ProductJobRepository
  75 + if value, err := factory.CreateProductJobRepository(map[string]interface{}{
  76 + "transactionContext": transactionContext,
  77 + }); err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + } else {
  80 + productJobRepository = value
  81 + }
  82 + productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": getProductJobQuery.ProductJobId})
  83 + if err != nil {
  84 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  85 + }
  86 + if productJob == nil {
  87 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductJobQuery.ProductJobId)))
  88 + } else {
  89 + if err := transactionContext.CommitTransaction(); err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + return productJob, nil
  93 + }
  94 +}
  95 +
  96 +// 返回工位服务列表
  97 +func (productJobService *ProductJobService) ListProductJob(listProductJobQuery *query.ListProductJobQuery) (interface{}, error) {
  98 + if err := listProductJobQuery.ValidateQuery(); err != nil {
  99 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  100 + }
  101 + transactionContext, err := factory.CreateTransactionContext(nil)
  102 + if err != nil {
  103 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  104 + }
  105 + if err := transactionContext.StartTransaction(); err != nil {
  106 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  107 + }
  108 + defer func() {
  109 + transactionContext.RollbackTransaction()
  110 + }()
  111 + var productJobRepository domain.ProductJobRepository
  112 + if value, err := factory.CreateProductJobRepository(map[string]interface{}{
  113 + "transactionContext": transactionContext,
  114 + }); err != nil {
  115 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + } else {
  117 + productJobRepository = value
  118 + }
  119 + if count, productJobs, err := productJobRepository.Find(tool_funs.SimpleStructToMap(listProductJobQuery)); err != nil {
  120 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  121 + } else {
  122 + if err := transactionContext.CommitTransaction(); err != nil {
  123 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  124 + }
  125 + return map[string]interface{}{
  126 + "count": count,
  127 + "productJobs": productJobs,
  128 + }, nil
  129 + }
  130 +}
  131 +
  132 +// 移除工位服务
  133 +func (productJobService *ProductJobService) RemoveProductJob(removeProductJobCommand *command.RemoveProductJobCommand) (interface{}, error) {
  134 + if err := removeProductJobCommand.ValidateCommand(); err != nil {
  135 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  136 + }
  137 + transactionContext, err := factory.CreateTransactionContext(nil)
  138 + if err != nil {
  139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  140 + }
  141 + if err := transactionContext.StartTransaction(); err != nil {
  142 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  143 + }
  144 + defer func() {
  145 + transactionContext.RollbackTransaction()
  146 + }()
  147 + var productJobRepository domain.ProductJobRepository
  148 + if value, err := factory.CreateProductJobRepository(map[string]interface{}{
  149 + "transactionContext": transactionContext,
  150 + }); err != nil {
  151 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  152 + } else {
  153 + productJobRepository = value
  154 + }
  155 + productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": removeProductJobCommand.ProductJobId})
  156 + if err != nil {
  157 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  158 + }
  159 + if productJob == nil {
  160 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductJobCommand.ProductJobId)))
  161 + }
  162 + if productJob, err := productJobRepository.Remove(productJob); err != nil {
  163 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  164 + } else {
  165 + if err := transactionContext.CommitTransaction(); err != nil {
  166 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  167 + }
  168 + return productJob, nil
  169 + }
  170 +}
  171 +
  172 +// 更新工位服务
  173 +func (productJobService *ProductJobService) UpdateProductJob(updateProductJobCommand *command.UpdateProductJobCommand) (interface{}, error) {
  174 + if err := updateProductJobCommand.ValidateCommand(); err != nil {
  175 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  176 + }
  177 + transactionContext, err := factory.CreateTransactionContext(nil)
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + if err := transactionContext.StartTransaction(); err != nil {
  182 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  183 + }
  184 + defer func() {
  185 + transactionContext.RollbackTransaction()
  186 + }()
  187 + var productJobRepository domain.ProductJobRepository
  188 + if value, err := factory.CreateProductJobRepository(map[string]interface{}{
  189 + "transactionContext": transactionContext,
  190 + }); err != nil {
  191 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  192 + } else {
  193 + productJobRepository = value
  194 + }
  195 + productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": updateProductJobCommand.ProductJobId})
  196 + if err != nil {
  197 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  198 + }
  199 + if productJob == nil {
  200 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductJobCommand.ProductJobId)))
  201 + }
  202 + if err := productJob.Update(tool_funs.SimpleStructToMap(updateProductJobCommand)); err != nil {
  203 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  204 + }
  205 + if productJob, err := productJobRepository.Save(productJob); err != nil {
  206 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  207 + } else {
  208 + if err := transactionContext.CommitTransaction(); err != nil {
  209 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + return productJob, nil
  212 + }
  213 +}
  214 +
  215 +func NewProductJobService(options map[string]interface{}) *ProductJobService {
  216 + newProductJobService := &ProductJobService{}
  217 + return newProductJobService
  218 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateProductLineCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 生产线名称
  15 + LineName string `cname:"生产线名称" json:"lineName" valid:"Required"`
  16 +}
  17 +
  18 +func (createProductLineCommand *CreateProductLineCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (createProductLineCommand *CreateProductLineCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(createProductLineCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(createProductLineCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductLineCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 生产线ID
  15 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  16 +}
  17 +
  18 +func (removeProductLineCommand *RemoveProductLineCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (removeProductLineCommand *RemoveProductLineCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(removeProductLineCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(removeProductLineCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateProductLineCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 生产线ID
  15 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  16 + // 生产线名称
  17 + LineName string `cname:"生产线名称" json:"lineName" valid:"Required"`
  18 +}
  19 +
  20 +func (updateProductLineCommand *UpdateProductLineCommand) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (updateProductLineCommand *UpdateProductLineCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(updateProductLineCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(updateProductLineCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductLineQuery struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 生产线ID
  15 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  16 +}
  17 +
  18 +func (getProductLineQuery *GetProductLineQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (getProductLineQuery *GetProductLineQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(getProductLineQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(getProductLineQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductLineQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductLineQuery *ListProductLineQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductLineQuery *ListProductLineQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductLineQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductLineQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/query"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  9 +)
  10 +
  11 +// 生产线服务
  12 +type ProductLineService struct {
  13 +}
  14 +
  15 +// 创建生产线
  16 +func (productLineService *ProductLineService) CreateProductLine(createProductLineCommand *command.CreateProductLineCommand) (interface{}, error) {
  17 + if err := createProductLineCommand.ValidateCommand(); err != nil {
  18 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  19 + }
  20 + transactionContext, err := factory.CreateTransactionContext(nil)
  21 + if err != nil {
  22 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  23 + }
  24 + if err := transactionContext.StartTransaction(); err != nil {
  25 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 + }
  27 + defer func() {
  28 + transactionContext.RollbackTransaction()
  29 + }()
  30 + newProductLine := &domain.ProductLine{
  31 + //WorkshopId: createProductLineCommand.WorkshopId,
  32 + LineName: createProductLineCommand.LineName,
  33 + }
  34 + //var productLineRepository domain
  35 + //if value, err := factory.CreateProductLineRepository(map[string]interface{}{
  36 + // "transactionContext": transactionContext,
  37 + //}); err != nil {
  38 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  39 + //} else {
  40 + // productLineRepository = value
  41 + //}
  42 + //if productLine, err := productLineRepository.Save(newProductLine); err != nil {
  43 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  44 + //} else {
  45 + // if err := transactionContext.CommitTransaction(); err != nil {
  46 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  47 + // }
  48 + // return productLine, nil
  49 + //}
  50 + return newProductLine, nil
  51 +}
  52 +
  53 +// 返回生产线
  54 +func (productLineService *ProductLineService) GetProductLine(getProductLineQuery *query.GetProductLineQuery) (interface{}, error) {
  55 + if err := getProductLineQuery.ValidateQuery(); err != nil {
  56 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  57 + }
  58 + transactionContext, err := factory.CreateTransactionContext(nil)
  59 + if err != nil {
  60 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  61 + }
  62 + if err := transactionContext.StartTransaction(); err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + defer func() {
  66 + transactionContext.RollbackTransaction()
  67 + }()
  68 + //var productLineRepository productLine.ProductLineRepository
  69 + //if value, err := factory.CreateProductLineRepository(map[string]interface{}{
  70 + // "transactionContext": transactionContext,
  71 + //}); err != nil {
  72 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  73 + //} else {
  74 + // productLineRepository = value
  75 + //}
  76 + //productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": getProductLineQuery.ProductLineId})
  77 + //if err != nil {
  78 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + //}
  80 + //if productLine == nil {
  81 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductLineQuery.ProductLineId)))
  82 + //} else {
  83 + // if err := transactionContext.CommitTransaction(); err != nil {
  84 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  85 + // }
  86 + // return productLine, nil
  87 + //}
  88 + return nil, nil
  89 +}
  90 +
  91 +// 返回生产线列表
  92 +func (productLineService *ProductLineService) ListProductLine(listProductLineQuery *query.ListProductLineQuery) (interface{}, error) {
  93 + if err := listProductLineQuery.ValidateQuery(); err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
  96 + transactionContext, err := factory.CreateTransactionContext(nil)
  97 + if err != nil {
  98 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  99 + }
  100 + if err := transactionContext.StartTransaction(); err != nil {
  101 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  102 + }
  103 + defer func() {
  104 + transactionContext.RollbackTransaction()
  105 + }()
  106 + //var productLineRepository productLine.ProductLineRepository
  107 + //if value, err := factory.CreateProductLineRepository(map[string]interface{}{
  108 + // "transactionContext": transactionContext,
  109 + //}); err != nil {
  110 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  111 + //} else {
  112 + // productLineRepository = value
  113 + //}
  114 + //if count, productLines, err := productLineRepository.Find(tool_funs.SimpleStructToMap(listProductLineQuery)); err != nil {
  115 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + //} else {
  117 + // if err := transactionContext.CommitTransaction(); err != nil {
  118 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  119 + // }
  120 + // return map[string]interface{}{
  121 + // "count": count,
  122 + // "productLines": productLines,
  123 + // }, nil
  124 + //}
  125 + return nil, nil
  126 +}
  127 +
  128 +// 移除生产线
  129 +func (productLineService *ProductLineService) RemoveProductLine(removeProductLineCommand *command.RemoveProductLineCommand) (interface{}, error) {
  130 + if err := removeProductLineCommand.ValidateCommand(); err != nil {
  131 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  132 + }
  133 + transactionContext, err := factory.CreateTransactionContext(nil)
  134 + if err != nil {
  135 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  136 + }
  137 + if err := transactionContext.StartTransaction(); err != nil {
  138 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  139 + }
  140 + defer func() {
  141 + transactionContext.RollbackTransaction()
  142 + }()
  143 + //var productLineRepository productLine.ProductLineRepository
  144 + //if value, err := factory.CreateProductLineRepository(map[string]interface{}{
  145 + // "transactionContext": transactionContext,
  146 + //}); err != nil {
  147 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  148 + //} else {
  149 + // productLineRepository = value
  150 + //}
  151 + //productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": removeProductLineCommand.ProductLineId})
  152 + //if err != nil {
  153 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + //}
  155 + //if productLine == nil {
  156 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductLineCommand.ProductLineId)))
  157 + //}
  158 + //if productLine, err := productLineRepository.Remove(productLine); err != nil {
  159 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + //} else {
  161 + // if err := transactionContext.CommitTransaction(); err != nil {
  162 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + // }
  164 + // return productLine, nil
  165 + //}
  166 + return nil, nil
  167 +}
  168 +
  169 +// 更新生产线
  170 +func (productLineService *ProductLineService) UpdateProductLine(updateProductLineCommand *command.UpdateProductLineCommand) (interface{}, error) {
  171 + if err := updateProductLineCommand.ValidateCommand(); err != nil {
  172 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  173 + }
  174 + transactionContext, err := factory.CreateTransactionContext(nil)
  175 + if err != nil {
  176 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  177 + }
  178 + if err := transactionContext.StartTransaction(); err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + defer func() {
  182 + transactionContext.RollbackTransaction()
  183 + }()
  184 + //var productLineRepository productLine.ProductLineRepository
  185 + //if value, err := factory.CreateProductLineRepository(map[string]interface{}{
  186 + // "transactionContext": transactionContext,
  187 + //}); err != nil {
  188 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  189 + //} else {
  190 + // productLineRepository = value
  191 + //}
  192 + //productLine, err := productLineRepository.FindOne(map[string]interface{}{"productLineId": updateProductLineCommand.ProductLineId})
  193 + //if err != nil {
  194 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  195 + //}
  196 + //if productLine == nil {
  197 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductLineCommand.ProductLineId)))
  198 + //}
  199 + //if err := productLine.Update(tool_funs.SimpleStructToMap(updateProductLineCommand)); err != nil {
  200 + // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  201 + //}
  202 + //if productLine, err := productLineRepository.Save(productLine); err != nil {
  203 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  204 + //} else {
  205 + // if err := transactionContext.CommitTransaction(); err != nil {
  206 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  207 + // }
  208 + // return productLine, nil
  209 + //}
  210 + return nil, nil
  211 +}
  212 +
  213 +func NewProductLineService(options map[string]interface{}) *ProductLineService {
  214 + newProductLineService := &ProductLineService{}
  215 + return newProductLineService
  216 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 + "time"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type CreateProductPlanCommand struct {
  13 + // 企业id
  14 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  15 + // 组织ID
  16 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  17 + // 车间ID
  18 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  19 + // 批号
  20 + BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
  21 + // 生产日期
  22 + ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
  23 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  24 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  25 + // 机台 (A、B、C、D 区分机器大小)
  26 + Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"`
  27 + // 计划的产品名称
  28 + PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"`
  29 + // 数量(保留两位小数)
  30 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  31 + // 单位
  32 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  33 + // 单份重量(原材料)
  34 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  35 + // 重量
  36 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  37 + // 备注
  38 + Remark string `cname:"备注" json:"remark" valid:"Required"`
  39 +}
  40 +
  41 +func (createProductPlanCommand *CreateProductPlanCommand) Valid(validation *validation.Validation) {
  42 + validation.SetError("CustomValid", "未实现的自定义认证")
  43 +}
  44 +
  45 +func (createProductPlanCommand *CreateProductPlanCommand) ValidateCommand() error {
  46 + valid := validation.Validation{}
  47 + b, err := valid.Valid(createProductPlanCommand)
  48 + if err != nil {
  49 + return err
  50 + }
  51 + if !b {
  52 + elem := reflect.TypeOf(createProductPlanCommand).Elem()
  53 + for _, validErr := range valid.Errors {
  54 + field, isExist := elem.FieldByName(validErr.Field)
  55 + if isExist {
  56 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  57 + } else {
  58 + return fmt.Errorf(validErr.Message)
  59 + }
  60 + }
  61 + }
  62 + return nil
  63 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ReceiveMaterialCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (receiveMaterialCommand *ReceiveMaterialCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (receiveMaterialCommand *ReceiveMaterialCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(receiveMaterialCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(receiveMaterialCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductPlanCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeProductPlanCommand *RemoveProductPlanCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeProductPlanCommand *RemoveProductPlanCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeProductPlanCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeProductPlanCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ReturnMaterialCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (returnMaterialCommand *ReturnMaterialCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (returnMaterialCommand *ReturnMaterialCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(returnMaterialCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(returnMaterialCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SetOfflineCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (setOfflineCommand *SetOfflineCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (setOfflineCommand *SetOfflineCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(setOfflineCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(setOfflineCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SetOnlineCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 + // 车间ID
  15 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  16 + // 生产线ID
  17 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  18 + // 工段ID
  19 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  20 +}
  21 +
  22 +func (setOnlineCommand *SetOnlineCommand) Valid(validation *validation.Validation) {
  23 + validation.SetError("CustomValid", "未实现的自定义认证")
  24 +}
  25 +
  26 +func (setOnlineCommand *SetOnlineCommand) ValidateCommand() error {
  27 + valid := validation.Validation{}
  28 + b, err := valid.Valid(setOnlineCommand)
  29 + if err != nil {
  30 + return err
  31 + }
  32 + if !b {
  33 + elem := reflect.TypeOf(setOnlineCommand).Elem()
  34 + for _, validErr := range valid.Errors {
  35 + field, isExist := elem.FieldByName(validErr.Field)
  36 + if isExist {
  37 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  38 + } else {
  39 + return fmt.Errorf(validErr.Message)
  40 + }
  41 + }
  42 + }
  43 + return nil
  44 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SubmitProductRecordCommand struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (submitProductRecordCommand *SubmitProductRecordCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (submitProductRecordCommand *SubmitProductRecordCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(submitProductRecordCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(submitProductRecordCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type SwitchCommand struct {
  12 + // 下线计划ID
  13 + FromProductPlanId int `cname:"下线计划ID" json:"fromProductPlanId,omitempty"`
  14 + // 上线计划ID
  15 + ToProductPlanId int `cname:"上线计划ID" json:"toProductPlanId,omitempty"`
  16 +}
  17 +
  18 +func (switchCommand *SwitchCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (switchCommand *SwitchCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(switchCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(switchCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 + "time"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type UpdateProductPlanCommand struct {
  13 + // 生产计划ID
  14 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  15 + // 企业id
  16 + CompanyId int `cname:"企业id" json:"companyId,omitempty"`
  17 + // 组织ID
  18 + OrgId int `cname:"组织ID" json:"orgId,omitempty"`
  19 + // 车间ID
  20 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  21 + // 批号
  22 + BatchNumber string `cname:"批号" json:"batchNumber" valid:"Required"`
  23 + // 生产日期
  24 + ProductDate time.Time `cname:"生产日期" json:"productDate" valid:"Required"`
  25 + // 上班班次 1:全天 2:白班 4:中班 8:夜班
  26 + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
  27 + // 机台 (A、B、C、D 区分机器大小)
  28 + Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"`
  29 + // 计划的产品名称
  30 + PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"`
  31 + // 数量(保留两位小数)
  32 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  33 + // 单位
  34 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  35 + // 单份重量(原材料)
  36 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  37 + // 重量
  38 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  39 + // 备注
  40 + Remark string `cname:"备注" json:"remark" valid:"Required"`
  41 +}
  42 +
  43 +func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *validation.Validation) {
  44 + validation.SetError("CustomValid", "未实现的自定义认证")
  45 +}
  46 +
  47 +func (updateProductPlanCommand *UpdateProductPlanCommand) ValidateCommand() error {
  48 + valid := validation.Validation{}
  49 + b, err := valid.Valid(updateProductPlanCommand)
  50 + if err != nil {
  51 + return err
  52 + }
  53 + if !b {
  54 + elem := reflect.TypeOf(updateProductPlanCommand).Elem()
  55 + for _, validErr := range valid.Errors {
  56 + field, isExist := elem.FieldByName(validErr.Field)
  57 + if isExist {
  58 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  59 + } else {
  60 + return fmt.Errorf(validErr.Message)
  61 + }
  62 + }
  63 + }
  64 + return nil
  65 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductPlanQuery struct {
  12 + // 生产计划ID
  13 + ProductPlanId int `cname:"生产计划ID" json:"productPlanId" valid:"Required"`
  14 +}
  15 +
  16 +func (getProductPlanQuery *GetProductPlanQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getProductPlanQuery *GetProductPlanQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getProductPlanQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getProductPlanQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductPlanQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductPlanQuery *ListProductPlanQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductPlanQuery *ListProductPlanQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductPlanQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductPlanQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productPlan/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 生产计划服务
  14 +type ProductPlanService struct {
  15 +}
  16 +
  17 +// 创建生产计划服务
  18 +func (productPlanService *ProductPlanService) CreateProductPlan(createProductPlanCommand *command.CreateProductPlanCommand) (interface{}, error) {
  19 + if err := createProductPlanCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProductPlan := &domain.ProductPlan{
  33 + CompanyId: createProductPlanCommand.CompanyId,
  34 + OrgId: createProductPlanCommand.OrgId,
  35 + //WorkshopId: createProductPlanCommand.WorkshopId,
  36 + BatchNumber: createProductPlanCommand.BatchNumber,
  37 + ProductDate: createProductPlanCommand.ProductDate,
  38 + WorkOn: createProductPlanCommand.WorkOn,
  39 + Machine: createProductPlanCommand.Machine,
  40 + PlanProductName: createProductPlanCommand.PlanProductName,
  41 + //PlanDevoted: createProductPlanCommand.PlanDevoted,
  42 + Remark: createProductPlanCommand.Remark,
  43 + }
  44 + var productPlanRepository domain.ProductPlanRepository
  45 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  46 + "transactionContext": transactionContext,
  47 + }); err != nil {
  48 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  49 + } else {
  50 + productPlanRepository = value
  51 + }
  52 + if productPlan, err := productPlanRepository.Save(newProductPlan); err != nil {
  53 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  54 + } else {
  55 + if err := transactionContext.CommitTransaction(); err != nil {
  56 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  57 + }
  58 + return productPlan, nil
  59 + }
  60 +}
  61 +
  62 +// 返回生产计划服务
  63 +func (productPlanService *ProductPlanService) GetProductPlan(getProductPlanQuery *query.GetProductPlanQuery) (interface{}, error) {
  64 + if err := getProductPlanQuery.ValidateQuery(); err != nil {
  65 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  66 + }
  67 + transactionContext, err := factory.CreateTransactionContext(nil)
  68 + if err != nil {
  69 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  70 + }
  71 + if err := transactionContext.StartTransaction(); err != nil {
  72 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  73 + }
  74 + defer func() {
  75 + transactionContext.RollbackTransaction()
  76 + }()
  77 + var productPlanRepository domain.ProductPlanRepository
  78 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  79 + "transactionContext": transactionContext,
  80 + }); err != nil {
  81 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  82 + } else {
  83 + productPlanRepository = value
  84 + }
  85 + productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": getProductPlanQuery.ProductPlanId})
  86 + if err != nil {
  87 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 + if productPlan == nil {
  90 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductPlanQuery.ProductPlanId)))
  91 + } else {
  92 + if err := transactionContext.CommitTransaction(); err != nil {
  93 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  94 + }
  95 + return productPlan, nil
  96 + }
  97 +}
  98 +
  99 +// 返回生产计划服务列表
  100 +func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQuery *query.ListProductPlanQuery) (interface{}, error) {
  101 + if err := listProductPlanQuery.ValidateQuery(); err != nil {
  102 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  103 + }
  104 + transactionContext, err := factory.CreateTransactionContext(nil)
  105 + if err != nil {
  106 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  107 + }
  108 + if err := transactionContext.StartTransaction(); err != nil {
  109 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  110 + }
  111 + defer func() {
  112 + transactionContext.RollbackTransaction()
  113 + }()
  114 + var productPlanRepository domain.ProductPlanRepository
  115 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  116 + "transactionContext": transactionContext,
  117 + }); err != nil {
  118 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  119 + } else {
  120 + productPlanRepository = value
  121 + }
  122 + if count, productPlans, err := productPlanRepository.Find(tool_funs.SimpleStructToMap(listProductPlanQuery)); err != nil {
  123 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  124 + } else {
  125 + if err := transactionContext.CommitTransaction(); err != nil {
  126 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  127 + }
  128 + return map[string]interface{}{
  129 + "count": count,
  130 + "productPlans": productPlans,
  131 + }, nil
  132 + }
  133 +}
  134 +
  135 +// 领料
  136 +func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
  137 + if err := receiveMaterialCommand.ValidateCommand(); err != nil {
  138 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  139 + }
  140 + transactionContext, err := factory.CreateTransactionContext(nil)
  141 + if err != nil {
  142 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  143 + }
  144 + if err := transactionContext.StartTransaction(); err != nil {
  145 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  146 + }
  147 + defer func() {
  148 + transactionContext.RollbackTransaction()
  149 + }()
  150 + if err := transactionContext.CommitTransaction(); err != nil {
  151 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  152 + }
  153 + return nil, nil
  154 +}
  155 +
  156 +// 移除生产计划服务
  157 +func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) {
  158 + if err := removeProductPlanCommand.ValidateCommand(); err != nil {
  159 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  160 + }
  161 + transactionContext, err := factory.CreateTransactionContext(nil)
  162 + if err != nil {
  163 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  164 + }
  165 + if err := transactionContext.StartTransaction(); err != nil {
  166 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  167 + }
  168 + defer func() {
  169 + transactionContext.RollbackTransaction()
  170 + }()
  171 + var productPlanRepository domain.ProductPlanRepository
  172 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  173 + "transactionContext": transactionContext,
  174 + }); err != nil {
  175 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  176 + } else {
  177 + productPlanRepository = value
  178 + }
  179 + productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": removeProductPlanCommand.ProductPlanId})
  180 + if err != nil {
  181 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  182 + }
  183 + if productPlan == nil {
  184 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductPlanCommand.ProductPlanId)))
  185 + }
  186 + if productPlan, err := productPlanRepository.Remove(productPlan); err != nil {
  187 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  188 + } else {
  189 + if err := transactionContext.CommitTransaction(); err != nil {
  190 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  191 + }
  192 + return productPlan, nil
  193 + }
  194 +}
  195 +
  196 +// 退料
  197 +func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
  198 + if err := returnMaterialCommand.ValidateCommand(); err != nil {
  199 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  200 + }
  201 + transactionContext, err := factory.CreateTransactionContext(nil)
  202 + if err != nil {
  203 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  204 + }
  205 + if err := transactionContext.StartTransaction(); err != nil {
  206 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  207 + }
  208 + defer func() {
  209 + transactionContext.RollbackTransaction()
  210 + }()
  211 + if err := transactionContext.CommitTransaction(); err != nil {
  212 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  213 + }
  214 + return nil, nil
  215 +}
  216 +
  217 +// 计划下线
  218 +func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *command.SetOfflineCommand) (interface{}, error) {
  219 + if err := setOfflineCommand.ValidateCommand(); err != nil {
  220 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  221 + }
  222 + transactionContext, err := factory.CreateTransactionContext(nil)
  223 + if err != nil {
  224 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  225 + }
  226 + if err := transactionContext.StartTransaction(); err != nil {
  227 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  228 + }
  229 + defer func() {
  230 + transactionContext.RollbackTransaction()
  231 + }()
  232 + if err := transactionContext.CommitTransaction(); err != nil {
  233 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  234 + }
  235 + return nil, nil
  236 +}
  237 +
  238 +// 计划上线
  239 +func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *command.SetOnlineCommand) (interface{}, error) {
  240 + if err := setOnlineCommand.ValidateCommand(); err != nil {
  241 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  242 + }
  243 + transactionContext, err := factory.CreateTransactionContext(nil)
  244 + if err != nil {
  245 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  246 + }
  247 + if err := transactionContext.StartTransaction(); err != nil {
  248 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  249 + }
  250 + defer func() {
  251 + transactionContext.RollbackTransaction()
  252 + }()
  253 + if err := transactionContext.CommitTransaction(); err != nil {
  254 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  255 + }
  256 + return nil, nil
  257 +}
  258 +
  259 +// 提交成品记录 (成品 二级品)
  260 +func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
  261 + if err := submitProductRecordCommand.ValidateCommand(); err != nil {
  262 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  263 + }
  264 + transactionContext, err := factory.CreateTransactionContext(nil)
  265 + if err != nil {
  266 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  267 + }
  268 + if err := transactionContext.StartTransaction(); err != nil {
  269 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  270 + }
  271 + defer func() {
  272 + transactionContext.RollbackTransaction()
  273 + }()
  274 + if err := transactionContext.CommitTransaction(); err != nil {
  275 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  276 + }
  277 + return nil, nil
  278 +}
  279 +
  280 +// 换单
  281 +func (productPlanService *ProductPlanService) Switch(switchCommand *command.SwitchCommand) (interface{}, error) {
  282 + if err := switchCommand.ValidateCommand(); err != nil {
  283 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  284 + }
  285 + transactionContext, err := factory.CreateTransactionContext(nil)
  286 + if err != nil {
  287 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  288 + }
  289 + if err := transactionContext.StartTransaction(); err != nil {
  290 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  291 + }
  292 + defer func() {
  293 + transactionContext.RollbackTransaction()
  294 + }()
  295 + if err := transactionContext.CommitTransaction(); err != nil {
  296 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  297 + }
  298 + return nil, nil
  299 +}
  300 +
  301 +// 更新生产计划服务
  302 +func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPlanCommand *command.UpdateProductPlanCommand) (interface{}, error) {
  303 + if err := updateProductPlanCommand.ValidateCommand(); err != nil {
  304 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  305 + }
  306 + transactionContext, err := factory.CreateTransactionContext(nil)
  307 + if err != nil {
  308 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  309 + }
  310 + if err := transactionContext.StartTransaction(); err != nil {
  311 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  312 + }
  313 + defer func() {
  314 + transactionContext.RollbackTransaction()
  315 + }()
  316 + var productPlanRepository domain.ProductPlanRepository
  317 + if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
  318 + "transactionContext": transactionContext,
  319 + }); err != nil {
  320 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  321 + } else {
  322 + productPlanRepository = value
  323 + }
  324 + productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": updateProductPlanCommand.ProductPlanId})
  325 + if err != nil {
  326 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  327 + }
  328 + if productPlan == nil {
  329 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductPlanCommand.ProductPlanId)))
  330 + }
  331 + if err := productPlan.Update(tool_funs.SimpleStructToMap(updateProductPlanCommand)); err != nil {
  332 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  333 + }
  334 + if productPlan, err := productPlanRepository.Save(productPlan); err != nil {
  335 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  336 + } else {
  337 + if err := transactionContext.CommitTransaction(); err != nil {
  338 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  339 + }
  340 + return productPlan, nil
  341 + }
  342 +}
  343 +
  344 +func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
  345 + newProductPlanService := &ProductPlanService{}
  346 + return newProductPlanService
  347 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateProductSectionCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 生产线ID
  15 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  16 + // 工段名称
  17 + SectionName string `cname:"工段名称" json:"sectionName" valid:"Required"`
  18 +}
  19 +
  20 +func (createProductSectionCommand *CreateProductSectionCommand) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (createProductSectionCommand *CreateProductSectionCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(createProductSectionCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(createProductSectionCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveProductSectionCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 工段ID
  15 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  16 +}
  17 +
  18 +func (removeProductSectionCommand *RemoveProductSectionCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (removeProductSectionCommand *RemoveProductSectionCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(removeProductSectionCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(removeProductSectionCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateProductSectionCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 工段ID
  15 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  16 + // 工段名称
  17 + SectionName string `cname:"工段名称" json:"sectionName" valid:"Required"`
  18 +}
  19 +
  20 +func (updateProductSectionCommand *UpdateProductSectionCommand) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (updateProductSectionCommand *UpdateProductSectionCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(updateProductSectionCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(updateProductSectionCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetProductSectionQuery struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 工段ID
  15 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  16 +}
  17 +
  18 +func (getProductSectionQuery *GetProductSectionQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (getProductSectionQuery *GetProductSectionQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(getProductSectionQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(getProductSectionQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListProductSectionQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listProductSectionQuery *ListProductSectionQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listProductSectionQuery *ListProductSectionQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listProductSectionQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listProductSectionQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productSection/query"
  8 +)
  9 +
  10 +// 工段服务
  11 +type ProductSectionService struct {
  12 +}
  13 +
  14 +// 创建工段服务
  15 +func (productSectionService *ProductSectionService) CreateProductSection(createProductSectionCommand *command.CreateProductSectionCommand) (interface{}, error) {
  16 + if err := createProductSectionCommand.ValidateCommand(); err != nil {
  17 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  18 + }
  19 + transactionContext, err := factory.CreateTransactionContext(nil)
  20 + if err != nil {
  21 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  22 + }
  23 + if err := transactionContext.StartTransaction(); err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + defer func() {
  27 + transactionContext.RollbackTransaction()
  28 + }()
  29 + //newProductSection := &productSection.ProductSection{
  30 + // WorkshopId: createProductSectionCommand.WorkshopId,
  31 + // LineId: createProductSectionCommand.LineId,
  32 + // SectionName: createProductSectionCommand.SectionName,
  33 + //}
  34 + //var productSectionRepository productSection.ProductSectionRepository
  35 + //if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
  36 + // "transactionContext": transactionContext,
  37 + //}); err != nil {
  38 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  39 + //} else {
  40 + // productSectionRepository = value
  41 + //}
  42 + //if productSection, err := productSectionRepository.Save(newProductSection); err != nil {
  43 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  44 + //} else {
  45 + // if err := transactionContext.CommitTransaction(); err != nil {
  46 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  47 + // }
  48 + // return productSection, nil
  49 + //}
  50 + return nil, nil
  51 +}
  52 +
  53 +// 返回工段服务
  54 +func (productSectionService *ProductSectionService) GetProductSection(getProductSectionQuery *query.GetProductSectionQuery) (interface{}, error) {
  55 + if err := getProductSectionQuery.ValidateQuery(); err != nil {
  56 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  57 + }
  58 + transactionContext, err := factory.CreateTransactionContext(nil)
  59 + if err != nil {
  60 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  61 + }
  62 + if err := transactionContext.StartTransaction(); err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + defer func() {
  66 + transactionContext.RollbackTransaction()
  67 + }()
  68 + //var productSectionRepository productSection.ProductSectionRepository
  69 + //if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
  70 + // "transactionContext": transactionContext,
  71 + //}); err != nil {
  72 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  73 + //} else {
  74 + // productSectionRepository = value
  75 + //}
  76 + //productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": getProductSectionQuery.ProductSectionId})
  77 + //if err != nil {
  78 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + //}
  80 + //if productSection == nil {
  81 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductSectionQuery.ProductSectionId)))
  82 + //} else {
  83 + // if err := transactionContext.CommitTransaction(); err != nil {
  84 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  85 + // }
  86 + // return productSection, nil
  87 + //}
  88 + return nil, nil
  89 +}
  90 +
  91 +// 返回工段服务列表
  92 +func (productSectionService *ProductSectionService) ListProductSection(listProductSectionQuery *query.ListProductSectionQuery) (interface{}, error) {
  93 + if err := listProductSectionQuery.ValidateQuery(); err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
  96 + transactionContext, err := factory.CreateTransactionContext(nil)
  97 + if err != nil {
  98 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  99 + }
  100 + if err := transactionContext.StartTransaction(); err != nil {
  101 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  102 + }
  103 + defer func() {
  104 + transactionContext.RollbackTransaction()
  105 + }()
  106 + //var productSectionRepository productSection.ProductSectionRepository
  107 + //if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
  108 + // "transactionContext": transactionContext,
  109 + //}); err != nil {
  110 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  111 + //} else {
  112 + // productSectionRepository = value
  113 + //}
  114 + //if count, productSections, err := productSectionRepository.Find(tool_funs.SimpleStructToMap(listProductSectionQuery)); err != nil {
  115 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + //} else {
  117 + // if err := transactionContext.CommitTransaction(); err != nil {
  118 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  119 + // }
  120 + // return map[string]interface{}{
  121 + // "count": count,
  122 + // "productSections": productSections,
  123 + // }, nil
  124 + //}
  125 + return nil, nil
  126 +}
  127 +
  128 +// 移除工段服务
  129 +func (productSectionService *ProductSectionService) RemoveProductSection(removeProductSectionCommand *command.RemoveProductSectionCommand) (interface{}, error) {
  130 + if err := removeProductSectionCommand.ValidateCommand(); err != nil {
  131 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  132 + }
  133 + transactionContext, err := factory.CreateTransactionContext(nil)
  134 + if err != nil {
  135 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  136 + }
  137 + if err := transactionContext.StartTransaction(); err != nil {
  138 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  139 + }
  140 + defer func() {
  141 + transactionContext.RollbackTransaction()
  142 + }()
  143 + //var productSectionRepository productSection.ProductSectionRepository
  144 + //if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
  145 + // "transactionContext": transactionContext,
  146 + //}); err != nil {
  147 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  148 + //} else {
  149 + // productSectionRepository = value
  150 + //}
  151 + //productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": removeProductSectionCommand.ProductSectionId})
  152 + //if err != nil {
  153 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + //}
  155 + //if productSection == nil {
  156 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductSectionCommand.ProductSectionId)))
  157 + //}
  158 + //if productSection, err := productSectionRepository.Remove(productSection); err != nil {
  159 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + //} else {
  161 + // if err := transactionContext.CommitTransaction(); err != nil {
  162 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + // }
  164 + // return productSection, nil
  165 + //}
  166 + return nil, nil
  167 +}
  168 +
  169 +// 更新工段服务
  170 +func (productSectionService *ProductSectionService) UpdateProductSection(updateProductSectionCommand *command.UpdateProductSectionCommand) (interface{}, error) {
  171 + if err := updateProductSectionCommand.ValidateCommand(); err != nil {
  172 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  173 + }
  174 + transactionContext, err := factory.CreateTransactionContext(nil)
  175 + if err != nil {
  176 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  177 + }
  178 + if err := transactionContext.StartTransaction(); err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + defer func() {
  182 + transactionContext.RollbackTransaction()
  183 + }()
  184 + //var productSectionRepository productSection.ProductSectionRepository
  185 + //if value, err := factory.CreateProductSectionRepository(map[string]interface{}{
  186 + // "transactionContext": transactionContext,
  187 + //}); err != nil {
  188 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  189 + //} else {
  190 + // productSectionRepository = value
  191 + //}
  192 + //productSection, err := productSectionRepository.FindOne(map[string]interface{}{"productSectionId": updateProductSectionCommand.ProductSectionId})
  193 + //if err != nil {
  194 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  195 + //}
  196 + //if productSection == nil {
  197 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductSectionCommand.ProductSectionId)))
  198 + //}
  199 + //if err := productSection.Update(tool_funs.SimpleStructToMap(updateProductSectionCommand)); err != nil {
  200 + // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  201 + //}
  202 + //if productSection, err := productSectionRepository.Save(productSection); err != nil {
  203 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  204 + //} else {
  205 + // if err := transactionContext.CommitTransaction(); err != nil {
  206 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  207 + // }
  208 + // return productSection, nil
  209 + //}
  210 + return nil, nil
  211 +}
  212 +
  213 +func NewProductSectionService(options map[string]interface{}) *ProductSectionService {
  214 + newProductSectionService := &ProductSectionService{}
  215 + return newProductSectionService
  216 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateUnitConversionCommand struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 组织ID
  15 + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"`
  16 + // 车间ID
  17 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  18 + // 生产线ID
  19 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  20 + // 工段ID
  21 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  22 + // 物料名称
  23 + MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
  24 + // 物料类别
  25 + MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
  26 + // 数量(保留两位小数)
  27 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  28 + // 单位
  29 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  30 + // 单份重量(原材料)
  31 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  32 + // 重量
  33 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  34 + // 智能称重标识
  35 + IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
  36 +}
  37 +
  38 +func (createUnitConversionCommand *CreateUnitConversionCommand) Valid(validation *validation.Validation) {
  39 + validation.SetError("CustomValid", "未实现的自定义认证")
  40 +}
  41 +
  42 +func (createUnitConversionCommand *CreateUnitConversionCommand) ValidateCommand() error {
  43 + valid := validation.Validation{}
  44 + b, err := valid.Valid(createUnitConversionCommand)
  45 + if err != nil {
  46 + return err
  47 + }
  48 + if !b {
  49 + elem := reflect.TypeOf(createUnitConversionCommand).Elem()
  50 + for _, validErr := range valid.Errors {
  51 + field, isExist := elem.FieldByName(validErr.Field)
  52 + if isExist {
  53 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  54 + } else {
  55 + return fmt.Errorf(validErr.Message)
  56 + }
  57 + }
  58 + }
  59 + return nil
  60 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveUnitConversionCommand struct {
  12 + // 单位换算ID
  13 + UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeUnitConversionCommand *RemoveUnitConversionCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeUnitConversionCommand *RemoveUnitConversionCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeUnitConversionCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeUnitConversionCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateUnitConversionCommand struct {
  12 + // 单位换算ID
  13 + UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
  14 + // 企业id
  15 + CompanyId int `cname:"企业id" json:"companyId,omitempty"`
  16 + // 组织ID
  17 + OrgId int `cname:"组织ID" json:"orgId,omitempty"`
  18 + // 车间ID
  19 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  20 + // 生产线ID
  21 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  22 + // 工段ID
  23 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  24 + // 物料名称
  25 + MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"`
  26 + // 物料类别
  27 + MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"`
  28 + // 数量(保留两位小数)
  29 + Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
  30 + // 单位
  31 + Unit string `cname:"单位" json:"unit" valid:"Required"`
  32 + // 单份重量(原材料)
  33 + UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
  34 + // 重量
  35 + Weight float64 `cname:"重量" json:"weight" valid:"Required"`
  36 + // 智能称重标识
  37 + IntelligentWeighingFlag bool `cname:"智能称重标识" json:"intelligentWeighingFlag" valid:"Required"`
  38 +}
  39 +
  40 +func (updateUnitConversionCommand *UpdateUnitConversionCommand) Valid(validation *validation.Validation) {
  41 + validation.SetError("CustomValid", "未实现的自定义认证")
  42 +}
  43 +
  44 +func (updateUnitConversionCommand *UpdateUnitConversionCommand) ValidateCommand() error {
  45 + valid := validation.Validation{}
  46 + b, err := valid.Valid(updateUnitConversionCommand)
  47 + if err != nil {
  48 + return err
  49 + }
  50 + if !b {
  51 + elem := reflect.TypeOf(updateUnitConversionCommand).Elem()
  52 + for _, validErr := range valid.Errors {
  53 + field, isExist := elem.FieldByName(validErr.Field)
  54 + if isExist {
  55 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  56 + } else {
  57 + return fmt.Errorf(validErr.Message)
  58 + }
  59 + }
  60 + }
  61 + return nil
  62 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetUnitConversionQuery struct {
  12 + // 单位换算ID
  13 + UnitConversionId int `cname:"单位换算ID" json:"unitConversionId" valid:"Required"`
  14 +}
  15 +
  16 +func (getUnitConversionQuery *GetUnitConversionQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getUnitConversionQuery *GetUnitConversionQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getUnitConversionQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getUnitConversionQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListUnitConversionQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listUnitConversionQuery *ListUnitConversionQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listUnitConversionQuery *ListUnitConversionQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listUnitConversionQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listUnitConversionQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/unitConversion/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 单位换算服务
  14 +type UnitConversionService struct {
  15 +}
  16 +
  17 +// 创建单位换算服务
  18 +func (unitConversionService *UnitConversionService) CreateUnitConversion(createUnitConversionCommand *command.CreateUnitConversionCommand) (interface{}, error) {
  19 + if err := createUnitConversionCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newUnitConversion := &domain.UnitConversion{
  33 + CompanyId: createUnitConversionCommand.CompanyId,
  34 + OrgId: createUnitConversionCommand.OrgId,
  35 + //WorkshopId: createUnitConversionCommand.WorkshopId,
  36 + //LineId: createUnitConversionCommand.LineId,
  37 + //SectionId: createUnitConversionCommand.SectionId,
  38 + //Material: createUnitConversionCommand.Material,
  39 + //FromUnitQuantity: createUnitConversionCommand.FromUnitQuantity,
  40 + //ToUnitQuantity: createUnitConversionCommand.ToUnitQuantity,
  41 + IntelligentWeighingFlag: createUnitConversionCommand.IntelligentWeighingFlag,
  42 + }
  43 + var unitConversionRepository domain.UnitConversionRepository
  44 + if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
  45 + "transactionContext": transactionContext,
  46 + }); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + unitConversionRepository = value
  50 + }
  51 + if unitConversion, err := unitConversionRepository.Save(newUnitConversion); err != nil {
  52 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  53 + } else {
  54 + if err := transactionContext.CommitTransaction(); err != nil {
  55 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  56 + }
  57 + return unitConversion, nil
  58 + }
  59 +}
  60 +
  61 +// 返回单位换算服务
  62 +func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitConversionQuery *query.GetUnitConversionQuery) (interface{}, error) {
  63 + if err := getUnitConversionQuery.ValidateQuery(); err != nil {
  64 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  65 + }
  66 + transactionContext, err := factory.CreateTransactionContext(nil)
  67 + if err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + if err := transactionContext.StartTransaction(); err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + defer func() {
  74 + transactionContext.RollbackTransaction()
  75 + }()
  76 + var unitConversionRepository domain.UnitConversionRepository
  77 + if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
  78 + "transactionContext": transactionContext,
  79 + }); err != nil {
  80 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  81 + } else {
  82 + unitConversionRepository = value
  83 + }
  84 + unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": getUnitConversionQuery.UnitConversionId})
  85 + if err != nil {
  86 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  87 + }
  88 + if unitConversion == nil {
  89 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUnitConversionQuery.UnitConversionId)))
  90 + } else {
  91 + if err := transactionContext.CommitTransaction(); err != nil {
  92 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  93 + }
  94 + return unitConversion, nil
  95 + }
  96 +}
  97 +
  98 +// 返回单位换算服务列表
  99 +func (unitConversionService *UnitConversionService) ListUnitConversion(listUnitConversionQuery *query.ListUnitConversionQuery) (interface{}, error) {
  100 + if err := listUnitConversionQuery.ValidateQuery(); err != nil {
  101 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  102 + }
  103 + transactionContext, err := factory.CreateTransactionContext(nil)
  104 + if err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + if err := transactionContext.StartTransaction(); err != nil {
  108 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  109 + }
  110 + defer func() {
  111 + transactionContext.RollbackTransaction()
  112 + }()
  113 + var unitConversionRepository domain.UnitConversionRepository
  114 + if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
  115 + "transactionContext": transactionContext,
  116 + }); err != nil {
  117 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  118 + } else {
  119 + unitConversionRepository = value
  120 + }
  121 + if count, unitConversions, err := unitConversionRepository.Find(tool_funs.SimpleStructToMap(listUnitConversionQuery)); err != nil {
  122 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  123 + } else {
  124 + if err := transactionContext.CommitTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  126 + }
  127 + return map[string]interface{}{
  128 + "count": count,
  129 + "unitConversions": unitConversions,
  130 + }, nil
  131 + }
  132 +}
  133 +
  134 +// 移除单位换算服务
  135 +func (unitConversionService *UnitConversionService) RemoveUnitConversion(removeUnitConversionCommand *command.RemoveUnitConversionCommand) (interface{}, error) {
  136 + if err := removeUnitConversionCommand.ValidateCommand(); err != nil {
  137 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  138 + }
  139 + transactionContext, err := factory.CreateTransactionContext(nil)
  140 + if err != nil {
  141 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  142 + }
  143 + if err := transactionContext.StartTransaction(); err != nil {
  144 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  145 + }
  146 + defer func() {
  147 + transactionContext.RollbackTransaction()
  148 + }()
  149 + var unitConversionRepository domain.UnitConversionRepository
  150 + if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
  151 + "transactionContext": transactionContext,
  152 + }); err != nil {
  153 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + } else {
  155 + unitConversionRepository = value
  156 + }
  157 + unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": removeUnitConversionCommand.UnitConversionId})
  158 + if err != nil {
  159 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + }
  161 + if unitConversion == nil {
  162 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeUnitConversionCommand.UnitConversionId)))
  163 + }
  164 + if unitConversion, err := unitConversionRepository.Remove(unitConversion); err != nil {
  165 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  166 + } else {
  167 + if err := transactionContext.CommitTransaction(); err != nil {
  168 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  169 + }
  170 + return unitConversion, nil
  171 + }
  172 +}
  173 +
  174 +// 更新单位换算服务
  175 +func (unitConversionService *UnitConversionService) UpdateUnitConversion(updateUnitConversionCommand *command.UpdateUnitConversionCommand) (interface{}, error) {
  176 + if err := updateUnitConversionCommand.ValidateCommand(); err != nil {
  177 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  178 + }
  179 + transactionContext, err := factory.CreateTransactionContext(nil)
  180 + if err != nil {
  181 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  182 + }
  183 + if err := transactionContext.StartTransaction(); err != nil {
  184 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  185 + }
  186 + defer func() {
  187 + transactionContext.RollbackTransaction()
  188 + }()
  189 + var unitConversionRepository domain.UnitConversionRepository
  190 + if value, err := factory.CreateUnitConversionRepository(map[string]interface{}{
  191 + "transactionContext": transactionContext,
  192 + }); err != nil {
  193 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  194 + } else {
  195 + unitConversionRepository = value
  196 + }
  197 + unitConversion, err := unitConversionRepository.FindOne(map[string]interface{}{"unitConversionId": updateUnitConversionCommand.UnitConversionId})
  198 + if err != nil {
  199 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  200 + }
  201 + if unitConversion == nil {
  202 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUnitConversionCommand.UnitConversionId)))
  203 + }
  204 + if err := unitConversion.Update(tool_funs.SimpleStructToMap(updateUnitConversionCommand)); err != nil {
  205 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  206 + }
  207 + if unitConversion, err := unitConversionRepository.Save(unitConversion); err != nil {
  208 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  209 + } else {
  210 + if err := transactionContext.CommitTransaction(); err != nil {
  211 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  212 + }
  213 + return unitConversion, nil
  214 + }
  215 +}
  216 +
  217 +func NewUnitConversionService(options map[string]interface{}) *UnitConversionService {
  218 + newUnitConversionService := &UnitConversionService{}
  219 + return newUnitConversionService
  220 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CreateWorkshopCommand struct {
  12 + // 车间名称
  13 + WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
  14 + // 负责人ID
  15 + PrincipalId int `cname:"负责人ID" json:"principalId,omitempty"`
  16 +}
  17 +
  18 +func (createWorkshopCommand *CreateWorkshopCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (createWorkshopCommand *CreateWorkshopCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(createWorkshopCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(createWorkshopCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type RemoveWorkshopCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 +}
  15 +
  16 +func (removeWorkshopCommand *RemoveWorkshopCommand) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (removeWorkshopCommand *RemoveWorkshopCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(removeWorkshopCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(removeWorkshopCommand).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type UpdateWorkshopCommand struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 + // 车间名称
  15 + WorkshopName string `cname:"车间名称" json:"workshopName" valid:"Required"`
  16 + // 负责人ID
  17 + PrincipalId int `cname:"负责人ID" json:"principalId" valid:"Required"`
  18 +}
  19 +
  20 +func (updateWorkshopCommand *UpdateWorkshopCommand) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (updateWorkshopCommand *UpdateWorkshopCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(updateWorkshopCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(updateWorkshopCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetWorkshopQuery struct {
  12 + // 车间ID
  13 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  14 +}
  15 +
  16 +func (getWorkshopQuery *GetWorkshopQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getWorkshopQuery *GetWorkshopQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getWorkshopQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getWorkshopQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ListWorkshopQuery struct {
  12 + // 查询偏离量
  13 + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
  14 + // 查询限制
  15 + Limit int `cname:"查询限制" json:"limit" valid:"Required"`
  16 +}
  17 +
  18 +func (listWorkshopQuery *ListWorkshopQuery) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (listWorkshopQuery *ListWorkshopQuery) ValidateQuery() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(listWorkshopQuery)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(listWorkshopQuery).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 +)
  12 +
  13 +// 车间服务
  14 +type WorkshopService struct {
  15 +}
  16 +
  17 +// 创建车间服务
  18 +func (workshopService *WorkshopService) CreateWorkshop(createWorkshopCommand *command.CreateWorkshopCommand) (interface{}, error) {
  19 + if err := createWorkshopCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newWorkshop := &domain.Workshop{
  33 + WorkshopName: createWorkshopCommand.WorkshopName,
  34 + //PrincipalId: createWorkshopCommand.PrincipalId,
  35 + }
  36 + var workshopRepository domain.WorkshopRepository
  37 + if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
  38 + "transactionContext": transactionContext,
  39 + }); err != nil {
  40 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  41 + } else {
  42 + workshopRepository = value
  43 + }
  44 + if workshop, err := workshopRepository.Save(newWorkshop); err != nil {
  45 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 + } else {
  47 + if err := transactionContext.CommitTransaction(); err != nil {
  48 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  49 + }
  50 + return workshop, nil
  51 + }
  52 +}
  53 +
  54 +// 返回车间服务
  55 +func (workshopService *WorkshopService) GetWorkshop(getWorkshopQuery *query.GetWorkshopQuery) (interface{}, error) {
  56 + if err := getWorkshopQuery.ValidateQuery(); err != nil {
  57 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  58 + }
  59 + transactionContext, err := factory.CreateTransactionContext(nil)
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  62 + }
  63 + if err := transactionContext.StartTransaction(); err != nil {
  64 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  65 + }
  66 + defer func() {
  67 + transactionContext.RollbackTransaction()
  68 + }()
  69 + var workshopRepository domain.WorkshopRepository
  70 + if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
  71 + "transactionContext": transactionContext,
  72 + }); err != nil {
  73 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  74 + } else {
  75 + workshopRepository = value
  76 + }
  77 + workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": getWorkshopQuery.WorkshopId})
  78 + if err != nil {
  79 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  80 + }
  81 + if workshop == nil {
  82 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getWorkshopQuery.WorkshopId)))
  83 + } else {
  84 + if err := transactionContext.CommitTransaction(); err != nil {
  85 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  86 + }
  87 + return workshop, nil
  88 + }
  89 +}
  90 +
  91 +// 返回车间服务列表
  92 +func (workshopService *WorkshopService) ListWorkshop(listWorkshopQuery *query.ListWorkshopQuery) (interface{}, error) {
  93 + if err := listWorkshopQuery.ValidateQuery(); err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
  96 + transactionContext, err := factory.CreateTransactionContext(nil)
  97 + if err != nil {
  98 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  99 + }
  100 + if err := transactionContext.StartTransaction(); err != nil {
  101 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  102 + }
  103 + defer func() {
  104 + transactionContext.RollbackTransaction()
  105 + }()
  106 + var workshopRepository domain.WorkshopRepository
  107 + if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
  108 + "transactionContext": transactionContext,
  109 + }); err != nil {
  110 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  111 + } else {
  112 + workshopRepository = value
  113 + }
  114 + if count, workshops, err := workshopRepository.Find(tool_funs.SimpleStructToMap(listWorkshopQuery)); err != nil {
  115 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + } else {
  117 + if err := transactionContext.CommitTransaction(); err != nil {
  118 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  119 + }
  120 + return map[string]interface{}{
  121 + "count": count,
  122 + "workshops": workshops,
  123 + }, nil
  124 + }
  125 +}
  126 +
  127 +// 移除车间服务
  128 +func (workshopService *WorkshopService) RemoveWorkshop(removeWorkshopCommand *command.RemoveWorkshopCommand) (interface{}, error) {
  129 + if err := removeWorkshopCommand.ValidateCommand(); err != nil {
  130 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  131 + }
  132 + transactionContext, err := factory.CreateTransactionContext(nil)
  133 + if err != nil {
  134 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  135 + }
  136 + if err := transactionContext.StartTransaction(); err != nil {
  137 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  138 + }
  139 + defer func() {
  140 + transactionContext.RollbackTransaction()
  141 + }()
  142 + var workshopRepository domain.WorkshopRepository
  143 + if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
  144 + "transactionContext": transactionContext,
  145 + }); err != nil {
  146 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  147 + } else {
  148 + workshopRepository = value
  149 + }
  150 + workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": removeWorkshopCommand.WorkshopId})
  151 + if err != nil {
  152 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  153 + }
  154 + if workshop == nil {
  155 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeWorkshopCommand.WorkshopId)))
  156 + }
  157 + if workshop, err := workshopRepository.Remove(workshop); err != nil {
  158 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  159 + } else {
  160 + if err := transactionContext.CommitTransaction(); err != nil {
  161 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  162 + }
  163 + return workshop, nil
  164 + }
  165 +}
  166 +
  167 +// 更新车间服务
  168 +func (workshopService *WorkshopService) UpdateWorkshop(updateWorkshopCommand *command.UpdateWorkshopCommand) (interface{}, error) {
  169 + if err := updateWorkshopCommand.ValidateCommand(); err != nil {
  170 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  171 + }
  172 + transactionContext, err := factory.CreateTransactionContext(nil)
  173 + if err != nil {
  174 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  175 + }
  176 + if err := transactionContext.StartTransaction(); err != nil {
  177 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + defer func() {
  180 + transactionContext.RollbackTransaction()
  181 + }()
  182 + var workshopRepository domain.WorkshopRepository
  183 + if value, err := factory.CreateWorkshopRepository(map[string]interface{}{
  184 + "transactionContext": transactionContext,
  185 + }); err != nil {
  186 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  187 + } else {
  188 + workshopRepository = value
  189 + }
  190 + workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": updateWorkshopCommand.WorkshopId})
  191 + if err != nil {
  192 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  193 + }
  194 + if workshop == nil {
  195 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateWorkshopCommand.WorkshopId)))
  196 + }
  197 + if err := workshop.Update(tool_funs.SimpleStructToMap(updateWorkshopCommand)); err != nil {
  198 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  199 + }
  200 + if workshop, err := workshopRepository.Save(workshop); err != nil {
  201 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  202 + } else {
  203 + if err := transactionContext.CommitTransaction(); err != nil {
  204 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  205 + }
  206 + return workshop, nil
  207 + }
  208 +}
  209 +
  210 +func NewWorkshopService(options map[string]interface{}) *WorkshopService {
  211 + newWorkshopService := &WorkshopService{}
  212 + return newWorkshopService
  213 +}
@@ -16,7 +16,7 @@ func init() { @@ -16,7 +16,7 @@ func init() {
16 web.BConfig.RunMode = "dev" 16 web.BConfig.RunMode = "dev"
17 web.BConfig.Listen.HTTPPort = 8080 17 web.BConfig.Listen.HTTPPort = 8080
18 web.BConfig.Listen.EnableAdmin = false 18 web.BConfig.Listen.EnableAdmin = false
19 - web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego" 19 + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
20 if os.Getenv("RUN_MODE") != "" { 20 if os.Getenv("RUN_MODE") != "" {
21 web.BConfig.RunMode = os.Getenv("RUN_MODE") 21 web.BConfig.RunMode = os.Getenv("RUN_MODE")
22 } 22 }