作者 Your Name

Merge branch 'dev' into test

  1 +package command
  2 +
  3 +type CreateProductCapacitiesCmd struct {
  4 + // 车间ID
  5 + WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
  6 + // 生产线ID
  7 + LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
  8 + // 工段ID
  9 + SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  10 + //员工
  11 + WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
  12 + //产量重量
  13 + Weigh float64 `cname:"重量" json:"weigh" valid:"Required" `
  14 + //计划id
  15 + ProductPlanId int `json:"productPlanId"`
  16 + //日期
  17 + RecordDate string `json:"recordDate"`
  18 + //上班班次 1:全天 2:白班 4:中班 8:夜班
  19 + WorkOn int `json:"workOn"`
  20 + //保存并审核
  21 + SaveAndApprove bool `json:"saveAndApprove"`
  22 +}
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 ) 9 )
10 10
11 type CreateProductRecordCommand struct { 11 type CreateProductRecordCommand struct {
12 - ProductRecordId int `json:"productRecordId"` 12 +
13 // 车间ID 13 // 车间ID
14 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 14 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
15 // 生产线ID 15 // 生产线ID
@@ -17,7 +17,7 @@ type CreateProductRecordCommand struct { @@ -17,7 +17,7 @@ type CreateProductRecordCommand struct {
17 // 工段ID 17 // 工段ID
18 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 18 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
19 19
20 - WorkerId int `cname:"工人ID" json:"workerId" valid:"Required"` 20 + WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
21 21
22 //生气计划id 22 //生气计划id
23 ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"` 23 ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
@@ -30,7 +30,7 @@ func (productRecordService *ProductRecordService) SaveProductCapacities(operateI @@ -30,7 +30,7 @@ func (productRecordService *ProductRecordService) SaveProductCapacities(operateI
30 }() 30 }()
31 31
32 //日期 32 //日期
33 - recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local) 33 + recordDate, err := time.Parse("2006-01-02", param.RecordDate)
34 if err != nil { 34 if err != nil {
35 return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误") 35 return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
36 } 36 }
@@ -156,12 +156,12 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI @@ -156,12 +156,12 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI
156 "transactionContext": transactionContext, 156 "transactionContext": transactionContext,
157 }) 157 })
158 158
159 - productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)  
160 - productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local) 159 + productBeginTime, _ := time.Parse("2006-01-02", param.ProductBeginTime)
  160 + productEndTime, _ := time.Parse("2006-01-02", param.ProductEndTime)
161 condition := map[string]interface{}{ 161 condition := map[string]interface{}{
162 "companyId": param.CompanyId, 162 "companyId": param.CompanyId,
163 "orgId": param.OrgId, 163 "orgId": param.OrgId,
164 - "workerName": param.WorkerName, 164 + "userName": param.WorkerName,
165 "workshopName": param.WorkshopName, 165 "workshopName": param.WorkshopName,
166 "lineName": param.LineName, 166 "lineName": param.LineName,
167 "sectionName": param.SectionName, 167 "sectionName": param.SectionName,
@@ -540,3 +540,117 @@ func (srv *ProductRecordService) BatchAddProductCapacities(operate *domain.Opera @@ -540,3 +540,117 @@ func (srv *ProductRecordService) BatchAddProductCapacities(operate *domain.Opera
540 } 540 }
541 return failRows, nil 541 return failRows, nil
542 } 542 }
  543 +
  544 +// 产能管理 页面上手动创建员工生产记录
  545 +func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.CreateProductCapacitiesCmd) (map[string]interface{}, error) {
  546 + transactionContext, err := factory.CreateTransactionContext(nil)
  547 + if err != nil {
  548 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  549 + }
  550 + if err := transactionContext.StartTransaction(); err != nil {
  551 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  552 + }
  553 + defer func() {
  554 + transactionContext.RollbackTransaction()
  555 + }()
  556 +
  557 + //日期
  558 + recordDate, err := time.Parse("2006-01-02", param.RecordDate)
  559 + if err != nil {
  560 + return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  561 + }
  562 + userService := domainService.NewUserService()
  563 + //操作人数据
  564 + var user *domain.User
  565 + user, err = userService.User(operateInfo.UserId)
  566 + if err != nil {
  567 + return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
  568 + }
  569 + //组织数据
  570 + var org *domain.Org
  571 + org, err = userService.Organization(operateInfo.OrgId)
  572 + if err != nil {
  573 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  574 + }
  575 + //车间数据
  576 + workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
  577 + "transactionContext": transactionContext,
  578 + })
  579 + workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
  580 + if err != nil {
  581 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
  582 + }
  583 + workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
  584 + if err != nil {
  585 + return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
  586 + }
  587 +
  588 + //获取生产记录
  589 + productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
  590 + "transactionContext": transactionContext,
  591 + })
  592 +
  593 + planData, err := productPlanRepo.FindOne(map[string]interface{}{
  594 + "productPlanId": param.ProductPlanId,
  595 + })
  596 +
  597 + if err != nil {
  598 + return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
  599 + }
  600 +
  601 + //员工生产记录
  602 + productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
  603 + "transactionContext": transactionContext,
  604 + })
  605 +
  606 + nowTime := time.Now()
  607 + productRecordIds := []int{}
  608 + for _, workerId := range param.WorkerId {
  609 + //员工数据
  610 + worker, err := userService.User(workerId)
  611 + if err != nil {
  612 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
  613 + }
  614 + epRecord := &domain.ProductRecord{
  615 + UpdatedAt: nowTime,
  616 + OrgId: operateInfo.OrgId,
  617 + CompanyId: operateInfo.CompanyId,
  618 + WorkStation: workstation,
  619 + ProductWorker: worker,
  620 + CreatedAt: recordDate,
  621 + Ext: &domain.Ext{
  622 + Operator: user,
  623 + OrgName: org.OrgName,
  624 + },
  625 + ProductRecordType: domain.RecordTypeReceiveMaterial,
  626 + ProductRecordInfo: &domain.ProductRecordInfo{
  627 + WorkOn: param.WorkOn,
  628 + ProductDate: param.RecordDate,
  629 + Weigh: param.Weigh,
  630 + WeighBefore: param.Weigh,
  631 + ApproveStatus: domain.ProductRecordNotApprove,
  632 + ApproveAt: 0,
  633 + ApproveUser: nil,
  634 + ProductPlanId: planData.ProductPlanId,
  635 + PlanProductName: planData.PlanProductName,
  636 + BatchNumber: planData.BatchNumber,
  637 + },
  638 + }
  639 + if param.SaveAndApprove {
  640 + epRecord.ProductRecordInfo.ApproveAt = nowTime.Unix()
  641 + epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
  642 + epRecord.ProductRecordInfo.ApproveUser = user
  643 + }
  644 + _, err = productRecordRepo.Save(epRecord)
  645 + if err != nil {
  646 + return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
  647 + }
  648 + productRecordIds = append(productRecordIds, epRecord.ProductRecordId)
  649 + }
  650 + if err := transactionContext.CommitTransaction(); err != nil {
  651 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  652 + }
  653 + return map[string]interface{}{
  654 + "productRecordIds": productRecordIds,
  655 + }, nil
  656 +}
@@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm @@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm
56 return struct{}{}, nil 56 return struct{}{}, nil
57 } 57 }
58 58
59 -// 创建生产记录服务 59 +// 创建生产记录服务,二级品
60 func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) { 60 func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) {
61 if err := param.ValidateCommand(); err != nil { 61 if err := param.ValidateCommand(); err != nil {
62 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 62 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -117,44 +117,50 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf @@ -117,44 +117,50 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf
117 if err != nil { 117 if err != nil {
118 return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error()) 118 return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
119 } 119 }
120 -  
121 - productRecordData := &domain.ProductRecord{  
122 - ProductRecordId: param.ProductRecordId,  
123 - CompanyId: operateInfo.CompanyId,  
124 - OrgId: operateInfo.OrgId,  
125 - ProductRecordType: domain.RecordTypeSecondLevelWeigh,  
126 - ProductWorker: user,  
127 - WorkStation: workstation,  
128 - CreatedAt: dataTime,  
129 - UpdatedAt: time.Now(),  
130 - ProductRecordInfo: &domain.ProductRecordInfo{  
131 - ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),  
132 - Original: param.Weigh,  
133 - Weigh: utils.Round(param.Weigh, 1),  
134 - WeighBefore: utils.Round(param.Weigh, 1),  
135 - UnitConversionId: 0,  
136 - ApproveStatus: domain.ProductRecordNotApprove,  
137 - ProductPlanId: productPlanData.ProductPlanId,  
138 - BatchNumber: productPlanData.BatchNumber,  
139 - PlanProductName: productPlanData.PlanProductName,  
140 - ProductGroupId: 0,  
141 - WorkOn: productPlanData.WorkOn,  
142 - },  
143 - Ext: domain.NewExt(org.OrgName),  
144 - }  
145 - //保存并审核  
146 - if param.SaveAndApprove {  
147 - productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)  
148 - }  
149 - _, err = productRecordRepo.Save(productRecordData)  
150 - if err != nil {  
151 - return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error()) 120 + productRecordIds := []int{}
  121 + for _, workerId := range param.WorkerId {
  122 + workerData, err := userService.User(workerId)
  123 + if err != nil {
  124 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工数据错误,"+err.Error())
  125 + }
  126 + productRecordData := &domain.ProductRecord{
  127 + CompanyId: operateInfo.CompanyId,
  128 + OrgId: operateInfo.OrgId,
  129 + ProductRecordType: domain.RecordTypeSecondLevelWeigh,
  130 + ProductWorker: workerData,
  131 + WorkStation: workstation,
  132 + CreatedAt: dataTime,
  133 + UpdatedAt: time.Now(),
  134 + ProductRecordInfo: &domain.ProductRecordInfo{
  135 + ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
  136 + Original: param.Weigh,
  137 + Weigh: utils.Round(param.Weigh, 1),
  138 + WeighBefore: utils.Round(param.Weigh, 1),
  139 + UnitConversionId: 0,
  140 + ApproveStatus: domain.ProductRecordNotApprove,
  141 + ProductPlanId: productPlanData.ProductPlanId,
  142 + BatchNumber: productPlanData.BatchNumber,
  143 + PlanProductName: productPlanData.PlanProductName,
  144 + ProductGroupId: 0,
  145 + WorkOn: productPlanData.WorkOn,
  146 + },
  147 + Ext: domain.NewExt(org.OrgName),
  148 + }
  149 + //保存并审核
  150 + if param.SaveAndApprove {
  151 + productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
  152 + }
  153 + _, err = productRecordRepo.Save(productRecordData)
  154 + if err != nil {
  155 + return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
  156 + }
  157 + productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
152 } 158 }
153 if err := transactionContext.CommitTransaction(); err != nil { 159 if err := transactionContext.CommitTransaction(); err != nil {
154 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 160 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
155 } 161 }
156 return map[string]interface{}{ 162 return map[string]interface{}{
157 - "productRecordId": productRecordData.ProductRecordId, 163 + "productRecordId": productRecordIds,
158 }, nil 164 }, nil
159 } 165 }
160 166
@@ -2,12 +2,13 @@ package repository @@ -2,12 +2,13 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
  6 +
5 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
10 - "time"  
11 12
12 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 13 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
13 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 14 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -176,7 +177,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac @@ -176,7 +177,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
176 query.Where("created_at>=?", v.(time.Time)) 177 query.Where("created_at>=?", v.(time.Time))
177 } 178 }
178 if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) { 179 if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
179 - query.Where("created_at<?", v.(time.Time)) 180 + query.Where("created_at<=?", v.(time.Time))
180 } 181 }
181 if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 { 182 if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
182 query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v)) 183 query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v))
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -121,11 +122,15 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) ( @@ -121,11 +122,15 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) (
121 } 122 }
122 //日期开始 123 //日期开始
123 if v, ok := queryOptions["beginDate"]; ok { 124 if v, ok := queryOptions["beginDate"]; ok {
124 - query.Where("record_date>=?", v) 125 + if !(v.(time.Time)).IsZero() {
  126 + query.Where("record_date>=?", v)
  127 + }
125 } 128 }
126 //日期结束 129 //日期结束
127 if v, ok := queryOptions["endDate"]; ok { 130 if v, ok := queryOptions["endDate"]; ok {
128 - query.Where("record_date<=?", v) 131 + if !(v.(time.Time)).IsZero() {
  132 + query.Where("record_date<=?", v)
  133 + }
129 } 134 }
130 135
131 //指定查询某个日期 136 //指定查询某个日期
@@ -132,10 +132,10 @@ func (controller *ProductRecordController) SearchWorkshopProductRecord() { @@ -132,10 +132,10 @@ func (controller *ProductRecordController) SearchWorkshopProductRecord() {
132 // 产能管理 添加产能 132 // 产能管理 添加产能
133 func (controller *ProductRecordController) CreateProductCapacities() { 133 func (controller *ProductRecordController) CreateProductCapacities() {
134 productRecordService := service.NewProductRecordService(nil) 134 productRecordService := service.NewProductRecordService(nil)
135 - saveCommand := &command.SaveProductCapacitiesCmd{} 135 + saveCommand := &command.CreateProductCapacitiesCmd{}
136 controller.Unmarshal(saveCommand) 136 controller.Unmarshal(saveCommand)
137 operateInfo := ParseOperateInfo(controller.BaseController) 137 operateInfo := ParseOperateInfo(controller.BaseController)
138 - data, err := productRecordService.SaveProductCapacities(operateInfo, saveCommand) 138 + data, err := productRecordService.CreateProductCapacities(operateInfo, saveCommand)
139 controller.Response(data, err) 139 controller.Response(data, err)
140 } 140 }
141 141