正在显示
19 个修改的文件
包含
214 行增加
和
30 行删除
@@ -16,6 +16,7 @@ require ( | @@ -16,6 +16,7 @@ require ( | ||
16 | github.com/imkira/go-interpol v1.1.0 // indirect | 16 | github.com/imkira/go-interpol v1.1.0 // indirect |
17 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | 17 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 |
18 | github.com/moul/http2curl v1.0.0 // indirect | 18 | github.com/moul/http2curl v1.0.0 // indirect |
19 | + github.com/mozillazg/go-pinyin v0.19.0 | ||
19 | github.com/onsi/ginkgo v1.15.2 | 20 | github.com/onsi/ginkgo v1.15.2 |
20 | github.com/onsi/gomega v1.11.0 | 21 | github.com/onsi/gomega v1.11.0 |
21 | github.com/sergi/go-diff v1.2.0 // indirect | 22 | github.com/sergi/go-diff v1.2.0 // indirect |
@@ -249,6 +249,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 | @@ -249,6 +249,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 | ||
249 | github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= | 249 | github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= |
250 | github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= | 250 | github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= |
251 | github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= | 251 | github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= |
252 | +github.com/mozillazg/go-pinyin v0.19.0 h1:p+J8/kjJ558KPvVGYLvqBhxf8jbZA2exSLCs2uUVN8c= | ||
253 | +github.com/mozillazg/go-pinyin v0.19.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc= | ||
252 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= | 254 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= |
253 | github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= | 255 | github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= |
254 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= | 256 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= |
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 GenProductCodeQuery struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getProductQuery *GenProductCodeQuery) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getProductQuery *GenProductCodeQuery) 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 | +} |
@@ -362,6 +362,23 @@ func (productService *ProductService) BatchAddProduct(opt *domain.OperateInfo, l | @@ -362,6 +362,23 @@ func (productService *ProductService) BatchAddProduct(opt *domain.OperateInfo, l | ||
362 | return failRows, nil | 362 | return failRows, nil |
363 | } | 363 | } |
364 | 364 | ||
365 | +// 创建产品服务 | ||
366 | +func (productService *ProductService) GenProductCode(createProductCommand *query.GenProductCodeQuery) (interface{}, error) { | ||
367 | + if err := createProductCommand.ValidateQuery(); err != nil { | ||
368 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
369 | + } | ||
370 | + | ||
371 | + generator := redis.NewProductCodeCache(createProductCommand.CompanyId) | ||
372 | + code, err := redis.GenCode(generator) | ||
373 | + if err != nil { | ||
374 | + log.Logger.Error(err.Error()) | ||
375 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常") | ||
376 | + } | ||
377 | + return map[string]interface{}{ | ||
378 | + "code": code, | ||
379 | + }, nil | ||
380 | +} | ||
381 | + | ||
365 | func NewProductService(options map[string]interface{}) *ProductService { | 382 | func NewProductService(options map[string]interface{}) *ProductService { |
366 | newProductService := &ProductService{} | 383 | newProductService := &ProductService{} |
367 | return newProductService | 384 | return newProductService |
@@ -13,6 +13,8 @@ type UpdateProductJobCommand struct { | @@ -13,6 +13,8 @@ type UpdateProductJobCommand struct { | ||
13 | ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"` | 13 | ProductJobId int `cname:"工位ID" json:"productJobId" valid:"Required"` |
14 | // 工位名称 | 14 | // 工位名称 |
15 | JobName string `cname:"工位名称" json:"jobName" valid:"Required"` | 15 | JobName string `cname:"工位名称" json:"jobName" valid:"Required"` |
16 | + // 工位名称 | ||
17 | + ProcessName string `cname:"工序名称" json:"processName" valid:"Required"` | ||
16 | // 车间ID | 18 | // 车间ID |
17 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` | 19 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` |
18 | // 生产线ID | 20 | // 生产线ID |
@@ -31,7 +31,9 @@ type ProductJobDto struct { | @@ -31,7 +31,9 @@ type ProductJobDto struct { | ||
31 | // 权限标识 (当前登录组织匹配为true,否则false) | 31 | // 权限标识 (当前登录组织匹配为true,否则false) |
32 | //AuthFlag bool `json:"authFlag"` | 32 | //AuthFlag bool `json:"authFlag"` |
33 | // 关联设备列表 | 33 | // 关联设备列表 |
34 | - RelatedDevices []DeviceDto `json:"relatedDevices,omitempty"` | 34 | + RelatedDevices []int `json:"relatedDevices,omitempty"` |
35 | + // 关联设备列表 | ||
36 | + RelatedDeviceList []DeviceDto `json:"relatedDevicesList,omitempty"` | ||
35 | } | 37 | } |
36 | 38 | ||
37 | type DeviceDto struct { | 39 | type DeviceDto struct { |
@@ -48,15 +50,16 @@ func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) { | @@ -48,15 +50,16 @@ func (d *ProductJobDto) LoadDto(job *domain.ProductJob, orgId int) { | ||
48 | d.JobName = job.JobName | 50 | d.JobName = job.JobName |
49 | d.ProcessName = job.ProcessName | 51 | d.ProcessName = job.ProcessName |
50 | d.WorkStation = job.WorkStation | 52 | d.WorkStation = job.WorkStation |
53 | + d.RelatedDevices = job.RelatedDevices | ||
51 | //d.AuthFlag = domain.CheckOrgAuth(orgId, job.OrgId) | 54 | //d.AuthFlag = domain.CheckOrgAuth(orgId, job.OrgId) |
52 | //if job.Ext != nil { | 55 | //if job.Ext != nil { |
53 | // d.OrgName = job.Ext.OrgName | 56 | // d.OrgName = job.Ext.OrgName |
54 | //} | 57 | //} |
55 | } | 58 | } |
56 | 59 | ||
57 | -func (d *ProductJobDto) WithRelatedDevices(devices []*domain.Device) *ProductJobDto { | 60 | +func (d *ProductJobDto) WithRelatedDevicesList(devices []*domain.Device) *ProductJobDto { |
58 | for i := range devices { | 61 | for i := range devices { |
59 | - d.RelatedDevices = append(d.RelatedDevices, DeviceDto{ | 62 | + d.RelatedDeviceList = append(d.RelatedDeviceList, DeviceDto{ |
60 | DeviceName: devices[i].DeviceName, | 63 | DeviceName: devices[i].DeviceName, |
61 | DeviceId: devices[i].DeviceId, | 64 | DeviceId: devices[i].DeviceId, |
62 | DeviceCode: devices[i].DeviceCode, | 65 | DeviceCode: devices[i].DeviceCode, |
@@ -101,18 +101,18 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu | @@ -101,18 +101,18 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu | ||
101 | newJobDto := &dto.ProductJobDto{} | 101 | newJobDto := &dto.ProductJobDto{} |
102 | newJobDto.LoadDto(productJob, 0) | 102 | newJobDto.LoadDto(productJob, 0) |
103 | 103 | ||
104 | - if len(productJob.RelatedDevices) > 0 { | ||
105 | - deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0) | ||
106 | - _, devices, err := deviceRepository.Find(map[string]interface{}{ | ||
107 | - "companyId": productJob.CompanyId, | ||
108 | - "orgId": productJob.OrgId, | ||
109 | - "inDeviceId": productJob.RelatedDevices, | ||
110 | - }) | ||
111 | - if err != nil { | ||
112 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
113 | - } | ||
114 | - newJobDto.WithRelatedDevices(devices) | ||
115 | - } | 104 | + //if len(productJob.RelatedDevices) > 0 { |
105 | + // deviceRepository, _, _ := factory.FastPgDevice(transactionContext, 0) | ||
106 | + // _, devices, err := deviceRepository.Find(map[string]interface{}{ | ||
107 | + // "companyId": productJob.CompanyId, | ||
108 | + // "orgId": productJob.OrgId, | ||
109 | + // "inDeviceId": productJob.RelatedDevices, | ||
110 | + // }) | ||
111 | + // if err != nil { | ||
112 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
113 | + // } | ||
114 | + // newJobDto.WithRelatedDevicesList(devices) | ||
115 | + //} | ||
116 | 116 | ||
117 | if err := transactionContext.CommitTransaction(); err != nil { | 117 | if err := transactionContext.CommitTransaction(); err != nil { |
118 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 118 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -289,6 +289,7 @@ func (productJobService *ProductJobService) UpdateProductJob(cmd *command.Update | @@ -289,6 +289,7 @@ func (productJobService *ProductJobService) UpdateProductJob(cmd *command.Update | ||
289 | productJob.JobName = cmd.JobName | 289 | productJob.JobName = cmd.JobName |
290 | productJob.RelatedDevices = cmd.RelatedDevices | 290 | productJob.RelatedDevices = cmd.RelatedDevices |
291 | productJob.UpdatedAt = time.Now() | 291 | productJob.UpdatedAt = time.Now() |
292 | + productJob.ProcessName = cmd.ProcessName | ||
292 | 293 | ||
293 | if productJob, err := productJobRepository.Save(productJob); err != nil { | 294 | if productJob, err := productJobRepository.Save(productJob); err != nil { |
294 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 295 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -21,15 +21,17 @@ type CreateProductPlanCommand struct { | @@ -21,15 +21,17 @@ type CreateProductPlanCommand struct { | ||
21 | // 生产日期 | 21 | // 生产日期 |
22 | ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"` | 22 | ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"` |
23 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 23 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
24 | - WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 24 | + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn"` |
25 | // 机台 (A、B、C、D 区分机器大小) | 25 | // 机台 (A、B、C、D 区分机器大小) |
26 | - Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"` | 26 | + Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine"` |
27 | // 计划的产品名称 | 27 | // 计划的产品名称 |
28 | - PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"` | 28 | + //PlanProductName string `cname:"计划的产品名称" json:"planProductName"` |
29 | + // 产品ID | ||
30 | + ProductId int `cname:"产品ID" json:"productId" valid:"Required"` | ||
29 | // 数量(保留两位小数) | 31 | // 数量(保留两位小数) |
30 | Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` | 32 | Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` |
31 | // 单位 | 33 | // 单位 |
32 | - Unit string `cname:"单位" json:"unit" valid:"Required"` | 34 | + //Unit string `cname:"单位" json:"unit" ` |
33 | // 单份重量(原材料) | 35 | // 单份重量(原材料) |
34 | //nitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` | 36 | //nitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` |
35 | // 重量 | 37 | // 重量 |
@@ -23,19 +23,21 @@ type UpdateProductPlanCommand struct { | @@ -23,19 +23,21 @@ type UpdateProductPlanCommand struct { | ||
23 | // 生产日期 | 23 | // 生产日期 |
24 | ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"` | 24 | ProductDate string `cname:"生产日期" json:"productDate" valid:"Required"` |
25 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 25 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
26 | - WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 26 | + WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn"` |
27 | // 机台 (A、B、C、D 区分机器大小) | 27 | // 机台 (A、B、C、D 区分机器大小) |
28 | - Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine" valid:"Required"` | 28 | + Machine string `cname:"机台 (A、B、C、D 区分机器大小)" json:"machine"` |
29 | // 计划的产品名称 | 29 | // 计划的产品名称 |
30 | - PlanProductName string `cname:"计划的产品名称" json:"planProductName" valid:"Required"` | 30 | + PlanProductName string `cname:"计划的产品名称" json:"planProductName"` |
31 | + // 产品ID | ||
32 | + ProductId int `cname:"产品ID" json:"productId" valid:"Required"` | ||
31 | // 数量(保留两位小数) | 33 | // 数量(保留两位小数) |
32 | Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` | 34 | Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` |
33 | // 单位 | 35 | // 单位 |
34 | - Unit string `cname:"单位" json:"unit" valid:"Required"` | 36 | + Unit string `cname:"单位" json:"unit"` |
35 | // 单份重量(原材料) | 37 | // 单份重量(原材料) |
36 | //UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` | 38 | //UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` |
37 | // 重量 | 39 | // 重量 |
38 | - Weight float64 `cname:"重量" json:"weight" valid:"Required"` | 40 | + Weight float64 `cname:"重量" json:"weight"` |
39 | // 备注 | 41 | // 备注 |
40 | Remark string `cname:"备注" json:"remark" valid:"Required"` | 42 | Remark string `cname:"备注" json:"remark" valid:"Required"` |
41 | // 生产日期 | 43 | // 生产日期 |
@@ -53,6 +53,12 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre | @@ -53,6 +53,12 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre | ||
53 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 53 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
54 | } | 54 | } |
55 | 55 | ||
56 | + var product *domain.Product | ||
57 | + _, product, err = factory.FastPgProduct(transactionContext, cmd.ProductId) | ||
58 | + if err != nil { | ||
59 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
60 | + } | ||
61 | + | ||
56 | newProductPlan := &domain.ProductPlan{ | 62 | newProductPlan := &domain.ProductPlan{ |
57 | CompanyId: cmd.CompanyId, | 63 | CompanyId: cmd.CompanyId, |
58 | OrgId: cmd.OrgId, | 64 | OrgId: cmd.OrgId, |
@@ -61,18 +67,27 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre | @@ -61,18 +67,27 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre | ||
61 | Workshop: workshop.CloneSample(), | 67 | Workshop: workshop.CloneSample(), |
62 | WorkOn: cmd.WorkOn, | 68 | WorkOn: cmd.WorkOn, |
63 | Machine: cmd.Machine, | 69 | Machine: cmd.Machine, |
64 | - PlanProductName: cmd.PlanProductName, | 70 | + PlanProductName: product.ProductName, |
65 | PlanDevoted: &domain.UnitQuantity{ | 71 | PlanDevoted: &domain.UnitQuantity{ |
66 | - Unit: cmd.Unit, | ||
67 | - Quantity: cmd.Quantity, | ||
68 | - Weight: cmd.Weight, | 72 | + Unit: product.ProductSpec.Unit, |
73 | + Quantity: cmd.Quantity, | ||
74 | + Weight: product.ProductWeigh(cmd.Quantity), | ||
75 | + UnitWeight: product.ProductSpec.UnitWeight, | ||
69 | }, | 76 | }, |
70 | PlanStatus: domain.PlanOffline, | 77 | PlanStatus: domain.PlanOffline, |
71 | WorkStation: &domain.WorkStation{}, | 78 | WorkStation: &domain.WorkStation{}, |
72 | Remark: cmd.Remark, | 79 | Remark: cmd.Remark, |
73 | CreatedAt: time.Now(), | 80 | CreatedAt: time.Now(), |
74 | UpdatedAt: time.Now(), | 81 | UpdatedAt: time.Now(), |
75 | - Ext: domain.NewExt(org.OrgName), | 82 | + Ext: domain.NewExt(org.OrgName).WithProductPlanExt(&domain.ProductPlanExt{ |
83 | + ProductId: product.ProductId, | ||
84 | + ProductCode: product.ProductCode, | ||
85 | + ProductName: product.ProductName, | ||
86 | + //ProductSpec: product.ProductSpec, | ||
87 | + }), | ||
88 | + } | ||
89 | + if cmd.Weight > 0 { | ||
90 | + newProductPlan.PlanDevoted.Weight = cmd.Weight | ||
76 | } | 91 | } |
77 | if productPlan, err = productPlanRepository.Save(newProductPlan); err != nil { | 92 | if productPlan, err = productPlanRepository.Save(newProductPlan); err != nil { |
78 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 93 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -232,7 +247,26 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd | @@ -232,7 +247,26 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd | ||
232 | if err != nil { | 247 | if err != nil { |
233 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 248 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
234 | } | 249 | } |
250 | + | ||
251 | + var product *domain.Product | ||
252 | + _, product, err = factory.FastPgProduct(transactionContext, cmd.ProductId) | ||
253 | + if err != nil { | ||
254 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
255 | + } | ||
256 | + | ||
235 | productPlan.Workshop = workshop.CloneSample() | 257 | productPlan.Workshop = workshop.CloneSample() |
258 | + productPlan.Ext.WithProductPlanExt(&domain.ProductPlanExt{ | ||
259 | + ProductId: product.ProductId, | ||
260 | + ProductCode: product.ProductCode, | ||
261 | + ProductName: product.ProductName, | ||
262 | + //ProductSpec: product.ProductSpec, | ||
263 | + }) | ||
264 | + productPlan.PlanDevoted.UnitWeight = product.ProductSpec.UnitWeight | ||
265 | + cmd.PlanProductName = product.ProductName | ||
266 | + cmd.Unit = product.ProductSpec.Unit | ||
267 | + if cmd.Weight == 0 { | ||
268 | + cmd.Weight = product.ProductWeigh(cmd.Quantity) | ||
269 | + } | ||
236 | 270 | ||
237 | if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil { | 271 | if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil { |
238 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 272 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
@@ -10,6 +10,9 @@ type Ext struct { | @@ -10,6 +10,9 @@ type Ext struct { | ||
10 | 10 | ||
11 | // 考勤记录扩展 | 11 | // 考勤记录扩展 |
12 | AttendanceExt *ProductAttendanceRecordExt `json:"attendanceExt,omitempty"` | 12 | AttendanceExt *ProductAttendanceRecordExt `json:"attendanceExt,omitempty"` |
13 | + | ||
14 | + // 生产计划扩展 | ||
15 | + ProductPlanExt *ProductPlanExt `json:"productPlanExt,omitempty"` | ||
13 | } | 16 | } |
14 | 17 | ||
15 | func NewExt(orgName string) *Ext { | 18 | func NewExt(orgName string) *Ext { |
@@ -27,3 +30,8 @@ func (e *Ext) WithAttendanceExt(ext *ProductAttendanceRecordExt) *Ext { | @@ -27,3 +30,8 @@ func (e *Ext) WithAttendanceExt(ext *ProductAttendanceRecordExt) *Ext { | ||
27 | e.AttendanceExt = ext | 30 | e.AttendanceExt = ext |
28 | return e | 31 | return e |
29 | } | 32 | } |
33 | + | ||
34 | +func (e *Ext) WithProductPlanExt(ext *ProductPlanExt) *Ext { | ||
35 | + e.ProductPlanExt = ext | ||
36 | + return e | ||
37 | +} |
@@ -75,6 +75,13 @@ func (product *Product) Update(data map[string]interface{}) error { | @@ -75,6 +75,13 @@ func (product *Product) Update(data map[string]interface{}) error { | ||
75 | return nil | 75 | return nil |
76 | } | 76 | } |
77 | 77 | ||
78 | +func (item *Product) ProductWeigh(quality float64) float64 { | ||
79 | + if quality <= 0 { | ||
80 | + return 0 | ||
81 | + } | ||
82 | + return item.ProductSpec.UnitWeight * quality | ||
83 | +} | ||
84 | + | ||
78 | // 导入数据体 | 85 | // 导入数据体 |
79 | type ImportProductItem struct { | 86 | type ImportProductItem struct { |
80 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 | 87 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 |
pkg/domain/product_plan_ext.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 生产计划扩展 | ||
4 | +type ProductPlanExt struct { | ||
5 | + // 产品ID | ||
6 | + ProductId int `json:"productId,omitempty"` | ||
7 | + // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 | ||
8 | + ProductCode string `json:"productCode,omitempty"` | ||
9 | + // 产品名称 | ||
10 | + ProductName string `json:"productName,omitempty"` | ||
11 | + // 产品规格 | ||
12 | + //ProductSpec *UnitQuantity `json:"productSpec,omitempty"` | ||
13 | +} |
@@ -8,4 +8,10 @@ type ProductRecordInfo struct { | @@ -8,4 +8,10 @@ type ProductRecordInfo struct { | ||
8 | Material *UnitConversion `json:"material,omitempty"` | 8 | Material *UnitConversion `json:"material,omitempty"` |
9 | // 生产计划信息(批次) | 9 | // 生产计划信息(批次) |
10 | ProductPlan *ProductPlan `json:"productPlan,omitempty"` | 10 | ProductPlan *ProductPlan `json:"productPlan,omitempty"` |
11 | + | ||
12 | + // 生产计划ID | ||
13 | + ProductPlanId int `json:"productPlanId,omitempty"` | ||
14 | + | ||
15 | + // 生产小组ID | ||
16 | + ProductGroupId int `json:"productGroupId,omitempty"` | ||
11 | } | 17 | } |
pkg/infrastructure/utils/converter/pinyin.go
0 → 100644
1 | +package converter | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/mozillazg/go-pinyin" | ||
5 | + "strings" | ||
6 | +) | ||
7 | + | ||
8 | +func ToPinYin(hans string, sep string) string { | ||
9 | + a := pinyin.NewArgs() | ||
10 | + tmp := pinyin.Pinyin(hans, a) | ||
11 | + result := make([]string, 0) | ||
12 | + for i := range tmp { | ||
13 | + result = append(result, tmp[i]...) | ||
14 | + } | ||
15 | + return strings.Join(result, sep) | ||
16 | +} |
@@ -92,3 +92,13 @@ func (controller *ProductController) BatchAddProduct() { | @@ -92,3 +92,13 @@ func (controller *ProductController) BatchAddProduct() { | ||
92 | data, err := productService.BatchAddProduct(ParseOperateInfo(controller.BaseController), cmd.List) | 92 | data, err := productService.BatchAddProduct(ParseOperateInfo(controller.BaseController), cmd.List) |
93 | controller.Response(data, err) | 93 | controller.Response(data, err) |
94 | } | 94 | } |
95 | + | ||
96 | +func (controller *ProductController) GenProductCode() { | ||
97 | + productService := service.NewProductService(nil) | ||
98 | + cmd := &query.GenProductCodeQuery{} | ||
99 | + Must(controller.Unmarshal(cmd)) | ||
100 | + op := ParseOperateInfo(controller.BaseController) | ||
101 | + cmd.CompanyId = op.CompanyId | ||
102 | + data, err := productService.GenProductCode(cmd) | ||
103 | + controller.Response(data, err) | ||
104 | +} |
@@ -14,4 +14,5 @@ func init() { | @@ -14,4 +14,5 @@ func init() { | ||
14 | web.Router("/products/", &controllers.ProductController{}, "Get:ListProduct") | 14 | web.Router("/products/", &controllers.ProductController{}, "Get:ListProduct") |
15 | web.Router("/products/search", &controllers.ProductController{}, "Post:SearchProduct") | 15 | web.Router("/products/search", &controllers.ProductController{}, "Post:SearchProduct") |
16 | web.Router("/products/batch-add", &controllers.ProductController{}, "Post:BatchAddProduct") | 16 | web.Router("/products/batch-add", &controllers.ProductController{}, "Post:BatchAddProduct") |
17 | + web.Router("/products/generate-code", &controllers.ProductController{}, "Post:GenProductCode") | ||
17 | } | 18 | } |
-
请 注册 或 登录 后发表评论