作者 Your Name

更新事故管理

@@ -2,13 +2,14 @@ package command @@ -2,13 +2,14 @@ package command
2 2
3 //创建事故记录 3 //创建事故记录
4 type SaveProductTroubleCommand struct { 4 type SaveProductTroubleCommand struct {
5 - Id int `json:"id"` //id  
6 - WorkshopId int `json:"workshopId" valid:"Required"` //车间id  
7 - LineId int `json:"lineId" valid:"Required"` //生产线ID  
8 - SectionId int `json:"sectionId" valid:"Required"` //工段ID  
9 - WorkerId int `json:"workerId"` //员工id  
10 - Remark string `json:"remark"` //备注  
11 - AmountLoss float64 `json:"amountLoss"` // 损失的金额  
12 - Types int `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故  
13 - RecordDate string `json:"recordDate"` // 事故发生的日期 5 + Id int `json:"id"` //id
  6 + WorkshopId int `json:"workshopId" valid:"Required"` //车间id
  7 + LineId int `json:"lineId" valid:"Required"` //生产线ID
  8 + SectionId int `json:"sectionId" valid:"Required"` //工段ID
  9 + WorkerId int `json:"workerId"` //员工id
  10 + Remark string `json:"remark"` //备注
  11 + AmountLoss float64 `json:"amountLoss"` // 损失的金额
  12 + Types int `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
  13 + RecordDate string `json:"recordDate"` // 事故发生的日期
  14 + SaveAndApprove bool `json:"saveAndApprove"` //保存并审核
14 } 15 }
@@ -89,6 +89,18 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI @@ -89,6 +89,18 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI
89 if err != nil { 89 if err != nil {
90 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 90 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
91 } 91 }
  92 + if param.SaveAndApprove {
  93 + var approveUser *domain.User
  94 + userService := domainService.NewUserService()
  95 + approveUser, err = userService.User(operateInfo.UserId)
  96 + if err != nil {
  97 + return nil, application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
  98 + }
  99 + err = troubleData.Approve(approveUser)
  100 + if err != nil {
  101 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  102 + }
  103 + }
92 _, err = productTroubleRepo.Save(troubleData) 104 _, err = productTroubleRepo.Save(troubleData)
93 if err != nil { 105 if err != nil {
94 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 106 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -174,6 +186,10 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { @@ -174,6 +186,10 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error {
174 return nil 186 return nil
175 } 187 }
176 188
  189 +// func (srv ProductTroubleService) approveProductTrouble(operateInfo *domain.OperateInfo, param *domain.ProductTrouble) error {
  190 +// return nil
  191 +// }
  192 +
177 func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error { 193 func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
178 transactionContext, err := factory.CreateTransactionContext(nil) 194 transactionContext, err := factory.CreateTransactionContext(nil)
179 if err != nil { 195 if err != nil {
@@ -62,3 +62,13 @@ func (c *ProductTroubleController) ListProductTrouble() { @@ -62,3 +62,13 @@ func (c *ProductTroubleController) ListProductTrouble() {
62 total, data, err := srv.ListProductTrouble(&getQuery) 62 total, data, err := srv.ListProductTrouble(&getQuery)
63 ResponseGrid(c.BaseController, total, data, err) 63 ResponseGrid(c.BaseController, total, data, err)
64 } 64 }
  65 +
  66 +// 审核事故记录
  67 +func (c *ProductTroubleController) ApproveProductTrouble() {
  68 + srv := service.NewProductTroubleService(nil)
  69 + getQuery := &query.GetProductTroubleQuery{}
  70 + Must(c.Unmarshal(getQuery))
  71 + operater := ParseOperateInfo(c.BaseController)
  72 + err := srv.ApproveProductTrouble(operater, int64(getQuery.Id))
  73 + c.Response(nil, err)
  74 +}
@@ -11,4 +11,6 @@ func init() { @@ -11,4 +11,6 @@ func init() {
11 web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Get:GetProductTrouble") 11 web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Get:GetProductTrouble")
12 web.Router("/product_trouble/remove", &controllers.ProductTroubleController{}, "Post:DeleteProductTrouble") 12 web.Router("/product_trouble/remove", &controllers.ProductTroubleController{}, "Post:DeleteProductTrouble")
13 web.Router("/product_trouble/search", &controllers.ProductTroubleController{}, "Post:ListProductTrouble") 13 web.Router("/product_trouble/search", &controllers.ProductTroubleController{}, "Post:ListProductTrouble")
  14 + web.Router("/product_trouble/approve", &controllers.ProductTroubleController{}, "Post:ApproveProductTrouble")
  15 +
14 } 16 }