作者 Your Name

更新产能

1 package command 1 package command
2 2
3 -type SaveEmployeeProductRecordCmd struct { 3 +type SaveProductRecordCmd struct {
  4 + //id
  5 + ProductRecordId int `json:"productRecordId"`
4 // 车间ID 6 // 车间ID
5 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 7 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
6 // 生产线ID 8 // 生产线ID
@@ -15,7 +15,7 @@ import ( @@ -15,7 +15,7 @@ import (
15 //产能管理 15 //产能管理
16 16
17 // 产能管理 页面上手动创建员工生产记录 17 // 产能管理 页面上手动创建员工生产记录
18 -func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.SaveEmployeeProductRecordCmd) (map[string]interface{}, error) { 18 +func (productRecordService *ProductRecordService) SaveProductCapacities(operateInfo *domain.OperateInfo, param *command.SaveProductRecordCmd) (map[string]interface{}, error) {
19 transactionContext, err := factory.CreateTransactionContext(nil) 19 transactionContext, err := factory.CreateTransactionContext(nil)
20 if err != nil { 20 if err != nil {
21 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 21 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -81,8 +81,21 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat @@ -81,8 +81,21 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat
81 productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{ 81 productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
82 "transactionContext": transactionContext, 82 "transactionContext": transactionContext,
83 }) 83 })
  84 +
84 nowTime := time.Now() 85 nowTime := time.Now()
  86 + if param.ProductRecordId > 0 {
  87 + productRecord, err := productRecordRepo.FindOne(map[string]interface{}{
  88 + "productRecordId": param.ProductRecordId,
  89 + })
  90 + if err != nil {
  91 + return nil, application.ThrowError(application.ARG_ERROR, "获取生产记录数据失败"+err.Error())
  92 + }
  93 + if productRecord.ProductRecordInfo.ApproveStatus != domain.ProductRecordNotApprove {
  94 + return nil, application.ThrowError(application.ARG_ERROR, "生产记录不可再被编辑")
  95 + }
  96 + }
85 epRecord := &domain.ProductRecord{ 97 epRecord := &domain.ProductRecord{
  98 + ProductRecordId: param.ProductRecordId,
86 UpdatedAt: nowTime, 99 UpdatedAt: nowTime,
87 OrgId: operateInfo.OrgId, 100 OrgId: operateInfo.OrgId,
88 CompanyId: operateInfo.CompanyId, 101 CompanyId: operateInfo.CompanyId,
@@ -112,7 +125,6 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat @@ -112,7 +125,6 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat
112 epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved 125 epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
113 epRecord.ProductRecordInfo.ApproveUser = user 126 epRecord.ProductRecordInfo.ApproveUser = user
114 } 127 }
115 - // epRecord.ParticipateType = param.ParticipateType //参与类型  
116 _, err = productRecordRepo.Save(epRecord) 128 _, err = productRecordRepo.Save(epRecord)
117 if err != nil { 129 if err != nil {
118 return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error()) 130 return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
@@ -161,7 +173,7 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI @@ -161,7 +173,7 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI
161 condition["limit"] = limit 173 condition["limit"] = limit
162 } 174 }
163 if offset >= 0 { 175 if offset >= 0 {
164 - condition["offset"] = limit 176 + condition["offset"] = offset
165 } 177 }
166 count, productRecords, err := productRecordRepo.Find(condition) 178 count, productRecords, err := productRecordRepo.Find(condition)
167 if err != nil { 179 if err != nil {
@@ -132,10 +132,22 @@ func (controller *ProductRecordController) SearchWorkshopProductRecord() { @@ -132,10 +132,22 @@ 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.SaveEmployeeProductRecordCmd{} 135 + saveCommand := &command.SaveProductRecordCmd{}
136 controller.Unmarshal(saveCommand) 136 controller.Unmarshal(saveCommand)
137 operateInfo := ParseOperateInfo(controller.BaseController) 137 operateInfo := ParseOperateInfo(controller.BaseController)
138 - data, err := productRecordService.CreateProductCapacities(operateInfo, saveCommand) 138 + data, err := productRecordService.SaveProductCapacities(operateInfo, saveCommand)
  139 + controller.Response(data, err)
  140 +}
  141 +
  142 +// 产能管理 编辑产能
  143 +func (controller *ProductRecordController) UpdateProductCapacities() {
  144 + productRecordService := service.NewProductRecordService(nil)
  145 + saveCommand := &command.SaveProductRecordCmd{}
  146 + controller.Unmarshal(saveCommand)
  147 + productRecordId, _ := controller.GetInt(":productRecordId")
  148 + saveCommand.ProductRecordId = productRecordId
  149 + operateInfo := ParseOperateInfo(controller.BaseController)
  150 + data, err := productRecordService.SaveProductCapacities(operateInfo, saveCommand)
139 controller.Response(data, err) 151 controller.Response(data, err)
140 } 152 }
141 153
@@ -23,6 +23,8 @@ func init() { @@ -23,6 +23,8 @@ func init() {
23 web.Router("/product-records/product-capacities/search", &controllers.ProductRecordController{}, "Post:ListProductCapacities") 23 web.Router("/product-records/product-capacities/search", &controllers.ProductRecordController{}, "Post:ListProductCapacities")
24 //产能管理 添加产能 24 //产能管理 添加产能
25 web.Router("/product-records/product-capacities", &controllers.ProductRecordController{}, "Post:CreateProductCapacities") 25 web.Router("/product-records/product-capacities", &controllers.ProductRecordController{}, "Post:CreateProductCapacities")
  26 + //产能管理 编辑产能
  27 + web.Router("/product-records/product-capacities/:productRecordId", &controllers.ProductRecordController{}, "Put:UpdateProductCapacities")
26 //产能管理 列表-产能详情 28 //产能管理 列表-产能详情
27 web.Router("/product-records/product-capacities/:productRecordId", &controllers.ProductRecordController{}, "Get:GetProductCapacities") 29 web.Router("/product-records/product-capacities/:productRecordId", &controllers.ProductRecordController{}, "Get:GetProductCapacities")
28 //产能管理 列表 -删除产能 30 //产能管理 列表 -删除产能