作者 Your Name

更新事故管理

@@ -8,6 +8,8 @@ type ProductTroubleInfo struct { @@ -8,6 +8,8 @@ type ProductTroubleInfo struct {
8 LineName string `json:"lineName"` // 8 LineName string `json:"lineName"` //
9 SectionId int `json:"sectionId"` //工段ID 9 SectionId int `json:"sectionId"` //工段ID
10 SectionName string `json:"sectionName"` // 10 SectionName string `json:"sectionName"` //
  11 + WorkerId int `json:"workerId"` //员工id
  12 + WorkerName string `json:"workerName"` //员工名称
11 Remark string `json:"remark"` //备注 13 Remark string `json:"remark"` //备注
12 ProductDate string `json:"productDate"` //日期 14 ProductDate string `json:"productDate"` //日期
13 AmountLoss float64 `json:"amountLoss"` //损失的金额 15 AmountLoss float64 `json:"amountLoss"` //损失的金额
  1 +package dto
  2 +
  3 +type ProductTroubleList struct {
  4 + Id int `json:"id"` //id
  5 + WorkshopId int `json:"workshopId"` //车间id
  6 + WorkshopName string `json:"workshopName"` //
  7 + LineId int `json:"lineId"` //生产线ID
  8 + LineName string `json:"lineName"` //
  9 + SectionId int `json:"sectionId"` //工段ID
  10 + SectionName string `json:"sectionName"` //
  11 + Remark string `json:"remark"` //备注
  12 + ProductDate string `json:"productDate"` //日期
  13 + AmountLoss float64 `json:"amountLoss"` //损失的金额
  14 + Types string `json:"types"` //事故类型
  15 + WorkerId int `json:"workerId"` //员工
  16 + WorkerName string `json:"workerName"` //员工名称
  17 + ApproveStatus int `json:"approveStatus"` //审核状态
  18 + ApproveStatusName string `json:"approveStatusName"` //审核状态
  19 +}
  1 +package query
  2 +
  3 +type ListProductTrouble struct {
  4 + // 当前公司
  5 + CompanyId int `cname:"当前公司" json:"companyId"`
  6 + // 当前登录的组织
  7 + OrgId int `cname:"当前登录的组织" json:"orgId"`
  8 + // 页码
  9 + PageNumber int `cname:"页码" json:"pageNumber"`
  10 + // 页数
  11 + PageSize int `cname:"页数" json:"pageSize"`
  12 + // 车间名称
  13 + WorkshopName string `cname:"车间名称" json:"workshopName"`
  14 + //员工名称
  15 + WorkerName string `cname:"员工名称" json:"workerName"`
  16 +}
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/dto" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/dto"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/query"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
12 ) 13 )
@@ -137,6 +138,8 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI @@ -137,6 +138,8 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI
137 ProductDate: troubleData.RecordData.Format("2006-01-02"), 138 ProductDate: troubleData.RecordData.Format("2006-01-02"),
138 AmountLoss: troubleData.AmountLoss, 139 AmountLoss: troubleData.AmountLoss,
139 Types: int(troubleData.Types), 140 Types: int(troubleData.Types),
  141 + WorkerId: troubleData.ProductWorker.UserId,
  142 + WorkerName: troubleData.ProductWorker.UserName,
140 } 143 }
141 return &result, nil 144 return &result, nil
142 } 145 }
@@ -212,3 +215,68 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera @@ -212,3 +215,68 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera
212 } 215 }
213 return nil 216 return nil
214 } 217 }
  218 +
  219 +// ListProductTrouble 事故管理列表
  220 +func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrouble) (int64, []dto.ProductTroubleList, error) {
  221 + transactionContext, err := factory.CreateTransactionContext(nil)
  222 + if err != nil {
  223 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  224 + }
  225 + if err := transactionContext.StartTransaction(); err != nil {
  226 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  227 + }
  228 + defer func() {
  229 + transactionContext.RollbackTransaction()
  230 + }()
  231 +
  232 + productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
  233 + "transactionContext": transactionContext,
  234 + })
  235 + limit := param.PageSize
  236 + offset := param.PageSize * (param.PageNumber - 1)
  237 + condition := map[string]interface{}{
  238 + "limit": limit,
  239 + "offsett": offset,
  240 + "companyId": param.CompanyId,
  241 + "orgId": param.OrgId,
  242 + }
  243 +
  244 + if len(param.WorkerName) > 0 {
  245 + condition["productWorkerName"] = param.WorkerName
  246 + }
  247 +
  248 + if len(param.WorkshopName) > 0 {
  249 + condition["workshopName"] = param.WorkshopName
  250 + }
  251 + cnt, troubleDataList, err := productTroubleRepo.Find(condition)
  252 + if err != nil {
  253 + return 0, nil, application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
  254 + }
  255 + if err := transactionContext.CommitTransaction(); err != nil {
  256 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  257 + }
  258 +
  259 + result := []dto.ProductTroubleList{}
  260 + var item dto.ProductTroubleList
  261 + for _, v := range troubleDataList {
  262 + item = dto.ProductTroubleList{
  263 + Id: v.Id,
  264 + WorkshopId: v.WorkStation.WorkshopId,
  265 + WorkshopName: v.WorkStation.WorkshopName,
  266 + LineId: v.WorkStation.LineId,
  267 + LineName: v.WorkStation.LineName,
  268 + SectionId: v.WorkStation.SectionId,
  269 + SectionName: v.WorkStation.SectionName,
  270 + Remark: v.Remark,
  271 + ProductDate: v.RecordData.Format("2006-01-02"),
  272 + AmountLoss: v.AmountLoss,
  273 + Types: v.GetTypesName(),
  274 + WorkerId: v.ProductWorker.UserId,
  275 + WorkerName: v.ProductWorker.UserName,
  276 + ApproveStatus: int(v.ApproveStatus),
  277 + ApproveStatusName: v.GetApproveStatusName(),
  278 + }
  279 + result = append(result, item)
  280 + }
  281 + return cnt, result, nil
  282 +}
@@ -8,12 +8,12 @@ import ( @@ -8,12 +8,12 @@ import (
8 // 事故管理数据结构 8 // 事故管理数据结构
9 type ProductTrouble struct { 9 type ProductTrouble struct {
10 Id int `json:"id"` // id 10 Id int `json:"id"` // id
11 - CompanyId int `json:"companyId"` //企业id  
12 - OrgId int `json:"orgId"` //组织ID 11 + CompanyId int `json:"companyId"` // 企业id
  12 + OrgId int `json:"orgId"` // 组织ID
13 WorkStation WorkStation `json:"workStation"` // 工作位置 13 WorkStation WorkStation `json:"workStation"` // 工作位置
14 ProductWorker User `json:"productWorker,omitempty"` // 生产工人 14 ProductWorker User `json:"productWorker,omitempty"` // 生产工人
15 AmountLoss float64 `json:"amountLoss"` // 损失的金额 15 AmountLoss float64 `json:"amountLoss"` // 损失的金额
16 - Types TroubleType `json:"types"` // 事故类型 16 + Types TroubleType `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
17 RecordData time.Time `json:"recordData"` // 事故发生的日期 17 RecordData time.Time `json:"recordData"` // 事故发生的日期
18 Remark string `json:"remakr"` // 备注 18 Remark string `json:"remakr"` // 备注
19 ApproveStatus ProductTroubleApprove `json:"approveStatus"` // 审核状态 1:未审核 2:已审核 3.自动审核 19 ApproveStatus ProductTroubleApprove `json:"approveStatus"` // 审核状态 1:未审核 2:已审核 3.自动审核
@@ -75,3 +75,27 @@ func (m *ProductTrouble) Approve(approveUser *User) error { @@ -75,3 +75,27 @@ func (m *ProductTrouble) Approve(approveUser *User) error {
75 } 75 }
76 return nil 76 return nil
77 } 77 }
  78 +
  79 +func (m *ProductTrouble) GetApproveStatusName() string {
  80 + switch m.ApproveStatus {
  81 + case TroubleWaitApprove:
  82 + return "未审核"
  83 + case TroubleIsApprove:
  84 + return "已审核"
  85 + }
  86 + return ""
  87 +}
  88 +
  89 +func (m *ProductTrouble) GetTypesName() string {
  90 + switch m.Types {
  91 + case TroubleType1:
  92 + return "安全事故"
  93 + case TroubleType2:
  94 + return "质量事故"
  95 + case TroubleType3:
  96 + return "金属事故"
  97 + case TroubleType4:
  98 + return "非金属事故"
  99 + }
  100 + return ""
  101 +}
@@ -53,6 +53,7 @@ func init() { @@ -53,6 +53,7 @@ func init() {
53 (*models.ProductMaterial)(nil), 53 (*models.ProductMaterial)(nil),
54 (*models.RewardStandard)(nil), 54 (*models.RewardStandard)(nil),
55 (*models.RewardRule)(nil), 55 (*models.RewardRule)(nil),
  56 + (*models.ProductTrouble)(nil),
56 } { 57 } {
57 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ 58 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
58 Temp: false, 59 Temp: false,
@@ -102,14 +102,29 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{}) @@ -102,14 +102,29 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{})
102 query := tx.Model(&m). 102 query := tx.Model(&m).
103 Where("deleted_at isnull"). 103 Where("deleted_at isnull").
104 Limit(20) 104 Limit(20)
105 - if v, ok := queryOptions["limit"].(int); ok { 105 + if v, ok := queryOptions["limit"].(int); ok && v > 0 {
106 query.Limit(v) 106 query.Limit(v)
107 } 107 }
108 108
109 - if v, ok := queryOptions["offset"].(int); ok { 109 + if v, ok := queryOptions["offset"].(int); ok && v >= 0 {
110 query.Offset(v) 110 query.Offset(v)
111 } 111 }
112 112
  113 + if v, ok := queryOptions["companyId"]; ok {
  114 + query.Where("company_id=?", v)
  115 + }
  116 + if v, ok := queryOptions["orgId"]; ok {
  117 + query.Where("org_id=?", v)
  118 + }
  119 +
  120 + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
  121 + query.Where(`Work_station->>'workshopName' like '%?%'`, v)
  122 + }
  123 +
  124 + if v, ok := queryOptions["productWorkerName"]; ok {
  125 + query.Where(`product_worker->>'userName' like '%?%'`, v)
  126 + }
  127 +
113 cnt, err := query.SelectAndCount() 128 cnt, err := query.SelectAndCount()
114 if err != nil { 129 if err != nil {
115 return 0, nil, err 130 return 0, nil, err
@@ -114,6 +114,12 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) @@ -114,6 +114,12 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{})
114 if v, ok := queryOptions["limit"].(int); ok { 114 if v, ok := queryOptions["limit"].(int); ok {
115 query.Limit(v) 115 query.Limit(v)
116 } 116 }
  117 + if v, ok := queryOptions["companyId"]; ok {
  118 + query.Where("company_id=?", v)
  119 + }
  120 + if v, ok := queryOptions["orgId"]; ok {
  121 + query.Where("org_id=?", v)
  122 + }
117 123
118 if v, ok := queryOptions["offset"].(int); ok { 124 if v, ok := queryOptions["offset"].(int); ok {
119 query.Offset(v) 125 query.Offset(v)
@@ -43,10 +43,22 @@ func (c *ProductTroubleController) GetProductTrouble() { @@ -43,10 +43,22 @@ func (c *ProductTroubleController) GetProductTrouble() {
43 } 43 }
44 44
45 // 删除事故记录 45 // 删除事故记录
46 -func (c RewardStandardController) DeleteProductTrouble() { 46 +func (c *ProductTroubleController) DeleteProductTrouble() {
47 srv := service.NewProductTroubleService(nil) 47 srv := service.NewProductTroubleService(nil)
48 getQuery := &query.GetProductTroubleQuery{} 48 getQuery := &query.GetProductTroubleQuery{}
49 Must(c.Unmarshal(getQuery)) 49 Must(c.Unmarshal(getQuery))
50 err := srv.DeleteProductTrouble(int64(getQuery.Id)) 50 err := srv.DeleteProductTrouble(int64(getQuery.Id))
51 c.Response(nil, err) 51 c.Response(nil, err)
52 } 52 }
  53 +
  54 +// 获取事故记录列表
  55 +func (c *ProductTroubleController) ListProductTrouble() {
  56 + srv := service.NewProductTroubleService(nil)
  57 + getQuery := query.ListProductTrouble{}
  58 + Must(c.Unmarshal(&getQuery))
  59 + operater := ParseOperateInfo(c.BaseController)
  60 + getQuery.CompanyId = operater.CompanyId
  61 + getQuery.OrgId = operater.OrgId
  62 + total, data, err := srv.ListProductTrouble(&getQuery)
  63 + ResponseGrid(c.BaseController, total, data, err)
  64 +}
@@ -10,5 +10,5 @@ func init() { @@ -10,5 +10,5 @@ func init() {
10 web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Put:UpdateProductTrouble") 10 web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Put:UpdateProductTrouble")
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("/reward-standard/search", &controllers.RewardStandardController{}, "Post:ListRewardStandard") 13 + web.Router("/product_trouble/search", &controllers.ProductTroubleController{}, "Post:ListProductTrouble")
14 } 14 }