作者 Your Name

更新 奖惩汇总

@@ -181,3 +181,11 @@ func CreateProductTroubleRepository(options map[string]interface{}) (domain.Prod @@ -181,3 +181,11 @@ func CreateProductTroubleRepository(options map[string]interface{}) (domain.Prod
181 } 181 }
182 return repository.NewProductTroubleRepository(transactionContext) 182 return repository.NewProductTroubleRepository(transactionContext)
183 } 183 }
  184 +
  185 +func CreateRewardSummaryRepository(options map[string]interface{}) (domain.RewardSummaryRepository, error) {
  186 + var transactionContext *pg.TransactionContext
  187 + if value, ok := options["transactionContext"]; ok {
  188 + transactionContext = value.(*pg.TransactionContext)
  189 + }
  190 + return repository.NewRewardSummaryRepository(transactionContext)
  191 +}
  1 +package dto
  2 +
  3 +type RewardSummaryList struct {
  4 + Id int `json:"id"`
  5 + RecordDate string `json:"recordDate"` //日期
  6 + WorkshopName string `json:"workshopName"` //车间名称
  7 + LineName string `json:"lineName"` //线别名称
  8 + SectionName string `json:"sectionName"` //工段
  9 + Yield string `json:"yield"` //产效
  10 + UpToStandard string `json:"upToStandard"` //合格率
  11 + Accident1 string `json:"accident1"` //质量事故
  12 + Accident2 string `json:"accident2"` //安全事故
  13 + Accident3 string `json:"accident3"` //异物事故
  14 + SummaryResult string `json:"summaryResult"` //奖惩结果
  15 + ResultDesc string `json:"resultDesc"` //产效结果
  16 +}
  1 +package query
  2 +
  3 +type ListRewardSummaryQuery 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 + LineName string `cname:"线别名称" json:"workerName"`
  16 +
  17 + BeginDate string `cname:"开始的日期" json:"beginDate"`
  18 +
  19 + EndDate string `cname:"结束的日期" json:"endDate"`
  20 +}
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "strconv" 5 "strconv"
5 "strings" 6 "strings"
6 "time" 7 "time"
@@ -83,7 +84,7 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI @@ -83,7 +84,7 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI
83 84
84 troubleData.AmountLoss = param.AmountLoss 85 troubleData.AmountLoss = param.AmountLoss
85 troubleData.ProductWorker = *workerUser 86 troubleData.ProductWorker = *workerUser
86 - troubleData.RecordData = recordDate 87 + troubleData.RecordDate = recordDate
87 troubleData.Remark = param.Remark 88 troubleData.Remark = param.Remark
88 troubleData.UpdatedAt = time.Now() 89 troubleData.UpdatedAt = time.Now()
89 troubleData.WorkStation = *workStation 90 troubleData.WorkStation = *workStation
@@ -149,7 +150,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI @@ -149,7 +150,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI
149 SectionId: troubleData.WorkStation.SectionId, 150 SectionId: troubleData.WorkStation.SectionId,
150 SectionName: troubleData.WorkStation.SectionName, 151 SectionName: troubleData.WorkStation.SectionName,
151 Remark: troubleData.Remark, 152 Remark: troubleData.Remark,
152 - ProductDate: troubleData.RecordData.Format("2006-01-02"), 153 + ProductDate: troubleData.RecordDate.Format("2006-01-02"),
153 AmountLoss: troubleData.AmountLoss, 154 AmountLoss: troubleData.AmountLoss,
154 Types: string(troubleData.Types), 155 Types: string(troubleData.Types),
155 WorkerId: troubleData.ProductWorker.UserId, 156 WorkerId: troubleData.ProductWorker.UserId,
@@ -188,10 +189,7 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { @@ -188,10 +189,7 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error {
188 return nil 189 return nil
189 } 190 }
190 191
191 -// func (srv ProductTroubleService) approveProductTrouble(operateInfo *domain.OperateInfo, param *domain.ProductTrouble) error {  
192 -// return nil  
193 -// }  
194 - 192 +// 审核事故
195 func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error { 193 func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
196 transactionContext, err := factory.CreateTransactionContext(nil) 194 transactionContext, err := factory.CreateTransactionContext(nil)
197 if err != nil { 195 if err != nil {
@@ -228,6 +226,11 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera @@ -228,6 +226,11 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera
228 if err != nil { 226 if err != nil {
229 return application.ThrowError(application.ARG_ERROR, err.Error()) 227 return application.ThrowError(application.ARG_ERROR, err.Error())
230 } 228 }
  229 + //汇总奖惩明细
  230 + err = srv.CreateRewardSummaryByProductTrouble(troubleData)
  231 + if err != nil {
  232 + return application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
  233 + }
231 if err := transactionContext.CommitTransaction(); err != nil { 234 if err := transactionContext.CommitTransaction(); err != nil {
232 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 235 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
233 } 236 }
@@ -286,7 +289,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou @@ -286,7 +289,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou
286 SectionId: v.WorkStation.SectionId, 289 SectionId: v.WorkStation.SectionId,
287 SectionName: v.WorkStation.SectionName, 290 SectionName: v.WorkStation.SectionName,
288 Remark: v.Remark, 291 Remark: v.Remark,
289 - ProductDate: v.RecordData.Format("2006-01-02"), 292 + ProductDate: v.RecordDate.Format("2006-01-02"),
290 AmountLoss: v.AmountLoss, 293 AmountLoss: v.AmountLoss,
291 Types: v.GetTypesName(), 294 Types: v.GetTypesName(),
292 WorkerId: v.ProductWorker.UserId, 295 WorkerId: v.ProductWorker.UserId,
@@ -415,7 +418,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper @@ -415,7 +418,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper
415 ProductWorker: *worker, 418 ProductWorker: *worker,
416 AmountLoss: amountLoss, 419 AmountLoss: amountLoss,
417 Types: "", 420 Types: "",
418 - RecordData: recordDate, 421 + RecordDate: recordDate,
419 Remark: "", 422 Remark: "",
420 ApproveStatus: domain.TroubleIsApprove, 423 ApproveStatus: domain.TroubleIsApprove,
421 ApproveAt: &nowTime, 424 ApproveAt: &nowTime,
@@ -439,15 +442,180 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper @@ -439,15 +442,180 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper
439 productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{ 442 productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
440 "transactionContext": transactionContext, 443 "transactionContext": transactionContext,
441 }) 444 })
442 - //添加事故数据 445 +
443 for i := range troubleDataList { 446 for i := range troubleDataList {
  447 + //添加事故数据
444 _, err = productTroubleRepo.Save(troubleDataList[i]) 448 _, err = productTroubleRepo.Save(troubleDataList[i])
445 if err != nil { 449 if err != nil {
446 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 450 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
447 } 451 }
  452 + //汇总奖惩明细
  453 + err = srv.CreateRewardSummaryByProductTrouble(troubleDataList[i])
  454 + if err != nil {
  455 + return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
  456 + }
448 } 457 }
  458 +
449 if err := transactionContext.CommitTransaction(); err != nil { 459 if err := transactionContext.CommitTransaction(); err != nil {
450 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 460 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
451 } 461 }
452 return nil, nil 462 return nil, nil
453 } 463 }
  464 +
  465 +// 奖惩汇总数据列表
  466 +func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
  467 +
  468 + transactionContext, err := factory.CreateTransactionContext(nil)
  469 + if err != nil {
  470 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  471 + }
  472 + if err := transactionContext.StartTransaction(); err != nil {
  473 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  474 + }
  475 + defer func() {
  476 + transactionContext.RollbackTransaction()
  477 + }()
  478 +
  479 + rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
  480 + "transactionContext": transactionContext,
  481 + })
  482 + limit := param.PageSize
  483 + offset := param.PageSize * (param.PageNumber - 1)
  484 + condition := map[string]interface{}{
  485 + "orgId": param.OrgId,
  486 + "companyId": param.CompanyId,
  487 + "offset": offset,
  488 + "limit": limit,
  489 + }
  490 + //搜索条件日期
  491 + if len(param.BeginDate) > 0 {
  492 + _, err = time.Parse("2006-01-02", param.BeginDate)
  493 + if err != nil {
  494 + return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  495 + }
  496 + condition["beginDate"] = param.BeginDate
  497 + }
  498 + //搜索条件日期
  499 + if len(param.EndDate) > 0 {
  500 + _, err = time.Parse("2006-01-02", param.EndDate)
  501 + if err != nil {
  502 + return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
  503 + }
  504 + condition["endDate"] = param.EndDate
  505 + }
  506 + //搜索条件 车间名称
  507 + if len(param.WorkshopName) > 0 {
  508 + condition["workshopName"] = param.WorkshopName
  509 + }
  510 + //搜索条件 线别名称
  511 + if len(param.LineName) > 0 {
  512 + condition["lineName"] = param.LineName
  513 + }
  514 +
  515 + cnt, rewardSummaryList, err := rewardSummaryRepo.Find(condition)
  516 + if err != nil {
  517 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  518 + }
  519 + if err := transactionContext.CommitTransaction(); err != nil {
  520 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  521 + }
  522 +
  523 + result := []dto.RewardSummaryList{}
  524 + for _, v := range rewardSummaryList {
  525 + item := dto.RewardSummaryList{
  526 + Id: v.Id,
  527 + RecordDate: v.RecordDate.Format("2006-01-02"),
  528 + WorkshopName: v.WorkStation.WorkshopName,
  529 + LineName: v.WorkStation.LineName,
  530 + SectionName: v.WorkStation.SectionName,
  531 + Yield: fmt.Sprintf("%.2f", v.Yield),
  532 + UpToStandard: fmt.Sprintf("%.2f%%", v.UpToStandard),
  533 + Accident1: fmt.Sprintf("%d次%.2f元", v.AccidentNum1, v.AccidentAmount1),
  534 + Accident2: fmt.Sprintf("%d次%.2f元", v.AccidentNum2, v.AccidentAmount2),
  535 + Accident3: fmt.Sprintf("金属%d次,非金属%d次", v.AccidentNum3, v.AccidentNum4),
  536 + SummaryResult: fmt.Sprintf("%v", v.SummaryResult),
  537 + ResultDesc: "",
  538 + }
  539 + if v.SummaryResult == 0 {
  540 + item.ResultDesc = "不奖不惩"
  541 + } else if v.SummaryResult > 0 {
  542 + item.ResultDesc = "奖"
  543 + } else {
  544 + item.ResultDesc = "惩"
  545 + }
  546 + result = append(result, item)
  547 + }
  548 + return cnt, result, nil
  549 +}
  550 +
  551 +// 根据事故数据创建奖惩汇总数据
  552 +func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
  553 + transactionContext, err := factory.CreateTransactionContext(nil)
  554 + if err != nil {
  555 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  556 + }
  557 + if err := transactionContext.StartTransaction(); err != nil {
  558 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  559 + }
  560 + defer func() {
  561 + transactionContext.RollbackTransaction()
  562 + }()
  563 +
  564 + rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
  565 + "transactionContext": transactionContext,
  566 + })
  567 +
  568 + //查询是否已经有汇总数据
  569 + condtion := map[string]interface{}{
  570 + "orgId": param.OrgId,
  571 + "companyId": param.CompanyId,
  572 + "lineId": param.WorkStation.LineId,
  573 + "sectionId": param.WorkStation.SectionId,
  574 + "workshopId": param.WorkStation.WorkshopId,
  575 + "workerId": param.ProductWorker.UserId,
  576 + "recordDateStr": param.RecordDate.Format("200-01-02"),
  577 + }
  578 +
  579 + _, summaryList, err := rewardSummaryRepo.Find(condtion)
  580 + if err != nil {
  581 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  582 + }
  583 +
  584 + var summaryData *domain.RewardSummary
  585 + nowTime := time.Now()
  586 + if len(summaryList) > 0 {
  587 + summaryData = summaryList[0]
  588 + } else {
  589 + summaryData = &domain.RewardSummary{
  590 + Id: 0,
  591 + CompanyId: param.CompanyId,
  592 + OrgId: param.OrgId,
  593 + WorkStation: param.WorkStation,
  594 + Worker: param.ProductWorker,
  595 + RecordDate: param.RecordDate,
  596 + RecordDateStr: param.RecordDate.Format("2006-01-02"),
  597 + UpToStandard: 0.0,
  598 + Yield: 0.0,
  599 + AccidentNum1: 0,
  600 + AccidentAmount1: 0.0,
  601 + AccidentNum2: 0,
  602 + AccidentAmount2: 0.0,
  603 + AccidentNum3: 0,
  604 + AccidentNum4: 0,
  605 + SummaryResult: 0.0,
  606 + CreatedAt: nowTime,
  607 + UpdatedAt: nowTime,
  608 + }
  609 + }
  610 + // 将审核过的事故放入汇总数据计算
  611 + summaryData.SummaryAccident(param)
  612 + summaryData.UpdatedAt = nowTime
  613 + _, err = rewardSummaryRepo.Save(summaryData)
  614 + if err != nil {
  615 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  616 + }
  617 + if err := transactionContext.CommitTransaction(); err != nil {
  618 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  619 + }
  620 + return nil
  621 +}
@@ -14,7 +14,7 @@ type ProductTrouble struct { @@ -14,7 +14,7 @@ type ProductTrouble struct {
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"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 16 Types TroubleType `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
17 - RecordData time.Time `json:"recordData"` // 事故发生的日期 17 + RecordDate time.Time `json:"recordDate"` // 事故发生的日期
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.自动审核
20 ApproveAt *time.Time `json:"approveAt"` // 审核时间 20 ApproveAt *time.Time `json:"approveAt"` // 审核时间
@@ -10,7 +10,8 @@ type RewardSummary struct { @@ -10,7 +10,8 @@ type RewardSummary struct {
10 CompanyId int `json:"companyId"` 10 CompanyId int `json:"companyId"`
11 OrgId int `json:"orgId"` 11 OrgId int `json:"orgId"`
12 RecordDate time.Time `json:"recordDate"` //日期 12 RecordDate time.Time `json:"recordDate"` //日期
13 - WorkStation WorkStation `json:"workStation"` // 工作位置 13 + RecordDateStr string `json:"recordDateStr"` //
  14 + WorkStation WorkStation `json:"workStation"` //工作位置
14 Worker User `json:"user"` //员工 15 Worker User `json:"user"` //员工
15 UpToStandard float64 `json:"upToStandard"` //合格率 16 UpToStandard float64 `json:"upToStandard"` //合格率
16 Yield float64 `json:"yield"` //产能 17 Yield float64 `json:"yield"` //产能
@@ -30,3 +31,19 @@ type RewardSummaryRepository interface { @@ -30,3 +31,19 @@ type RewardSummaryRepository interface {
30 FindOne(queryOptions map[string]interface{}) (*RewardSummary, error) 31 FindOne(queryOptions map[string]interface{}) (*RewardSummary, error)
31 Find(queryOptions map[string]interface{}) (int64, []*RewardSummary, error) 32 Find(queryOptions map[string]interface{}) (int64, []*RewardSummary, error)
32 } 33 }
  34 +
  35 +// SummaryAccident 汇总事故数据
  36 +func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble) {
  37 + switch trouble.Types {
  38 + case TroubleType1:
  39 + c.AccidentNum2 = +1
  40 + c.AccidentAmount2 = +trouble.AmountLoss
  41 + case TroubleType2:
  42 + c.AccidentNum1 = +1
  43 + c.AccidentAmount1 = +trouble.AmountLoss
  44 + case TroubleType3:
  45 + c.AccidentNum3 = +1
  46 + case TroubleType4:
  47 + c.AccidentNum4 = +1
  48 + }
  49 +}
@@ -16,7 +16,7 @@ type ProductTrouble struct { @@ -16,7 +16,7 @@ type ProductTrouble struct {
16 ProductWorker domain.User // 生产工人 16 ProductWorker domain.User // 生产工人
17 AmountLoss float64 // 损失的金额 17 AmountLoss float64 // 损失的金额
18 Types string // 事故类型 18 Types string // 事故类型
19 - RecordData time.Time // 事故发生的日期 19 + RecordDate time.Time // 事故发生的日期
20 Remark string // 备注 20 Remark string // 备注
21 ApproveStatus int // 审核状态 1:未审核 2:已审核 3.自动审核 21 ApproveStatus int // 审核状态 1:未审核 2:已审核 3.自动审核
22 ApproveAt *time.Time // 审核时间 22 ApproveAt *time.Time // 审核时间
@@ -13,6 +13,7 @@ type RewardSummary struct { @@ -13,6 +13,7 @@ type RewardSummary struct {
13 CompanyId int `` 13 CompanyId int ``
14 OrgId int `` 14 OrgId int ``
15 RecordDate time.Time //日期 15 RecordDate time.Time //日期
  16 + RecordDateStr string //
16 WorkStation domain.WorkStation // 工作位置 17 WorkStation domain.WorkStation // 工作位置
17 Worker domain.User //员工 18 Worker domain.User //员工
18 UpToStandard float64 //合格率 19 UpToStandard float64 //合格率
@@ -35,7 +35,7 @@ func (repo *ProductTroubleRepository) Save(param *domain.ProductTrouble) (*domai @@ -35,7 +35,7 @@ func (repo *ProductTroubleRepository) Save(param *domain.ProductTrouble) (*domai
35 ProductWorker: param.ProductWorker, 35 ProductWorker: param.ProductWorker,
36 AmountLoss: param.AmountLoss, 36 AmountLoss: param.AmountLoss,
37 Types: string(param.Types), 37 Types: string(param.Types),
38 - RecordData: param.RecordData, 38 + RecordDate: param.RecordDate,
39 Remark: param.Remark, 39 Remark: param.Remark,
40 ApproveStatus: int(param.ApproveStatus), 40 ApproveStatus: int(param.ApproveStatus),
41 ApproveAt: param.ApproveAt, 41 ApproveAt: param.ApproveAt,
@@ -147,7 +147,7 @@ func (repo *ProductTroubleRepository) TransformToDomain(param *models.ProductTro @@ -147,7 +147,7 @@ func (repo *ProductTroubleRepository) TransformToDomain(param *models.ProductTro
147 ProductWorker: param.ProductWorker, 147 ProductWorker: param.ProductWorker,
148 AmountLoss: param.AmountLoss, 148 AmountLoss: param.AmountLoss,
149 Types: domain.TroubleType(param.Types), 149 Types: domain.TroubleType(param.Types),
150 - RecordData: param.RecordData, 150 + RecordDate: param.RecordDate,
151 Remark: param.Remark, 151 Remark: param.Remark,
152 ApproveStatus: domain.ProductTroubleApprove(param.ApproveStatus), 152 ApproveStatus: domain.ProductTroubleApprove(param.ApproveStatus),
153 ApproveAt: param.ApproveAt, 153 ApproveAt: param.ApproveAt,
@@ -31,6 +31,7 @@ func (repo *RewardSummaryRepository) Save(param *domain.RewardSummary) (*domain. @@ -31,6 +31,7 @@ func (repo *RewardSummaryRepository) Save(param *domain.RewardSummary) (*domain.
31 CompanyId: param.CompanyId, 31 CompanyId: param.CompanyId,
32 OrgId: param.OrgId, 32 OrgId: param.OrgId,
33 RecordDate: param.RecordDate, 33 RecordDate: param.RecordDate,
  34 + RecordDateStr: param.RecordDateStr,
34 WorkStation: param.WorkStation, 35 WorkStation: param.WorkStation,
35 Worker: param.Worker, 36 Worker: param.Worker,
36 UpToStandard: param.UpToStandard, 37 UpToStandard: param.UpToStandard,
@@ -86,10 +87,10 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) ( @@ -86,10 +87,10 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) (
86 m := []models.RewardSummary{} 87 m := []models.RewardSummary{}
87 query := tx.Model(&m). 88 query := tx.Model(&m).
88 Limit(20) 89 Limit(20)
89 - if v, ok := queryOptions["limit"].(int); ok { 90 + if v, ok := queryOptions["limit"].(int); ok && v >= 0 {
90 query.Limit(v) 91 query.Limit(v)
91 } 92 }
92 - if v, ok := queryOptions["offset"].(int); ok { 93 + if v, ok := queryOptions["offset"].(int); ok && v >= 0 {
93 query.Offset(v) 94 query.Offset(v)
94 } 95 }
95 if v, ok := queryOptions["companyId"]; ok { 96 if v, ok := queryOptions["companyId"]; ok {
@@ -98,10 +99,39 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) ( @@ -98,10 +99,39 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) (
98 if v, ok := queryOptions["orgId"]; ok { 99 if v, ok := queryOptions["orgId"]; ok {
99 query.Where("org_id=?", v) 100 query.Where("org_id=?", v)
100 } 101 }
101 - 102 + //车间名称
102 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { 103 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
103 query.Where(`Work_station->>'workshopName' like '%?%'`, v) 104 query.Where(`Work_station->>'workshopName' like '%?%'`, v)
104 } 105 }
  106 + //线别名称
  107 + if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
  108 + query.Where(`Work_station->>'lineName' like '%?%'`, v)
  109 + }
  110 + //工段id
  111 + if v, ok := queryOptions["sectionId"]; ok && len(v.(string)) > 0 {
  112 + query.Where(`Work_station->>'sectionId' = '?'`, v)
  113 + }
  114 + //车间id
  115 + if v, ok := queryOptions["workshopId"]; ok {
  116 + query.Where(`Work_station->>'workshopId'='?'`, v)
  117 + }
  118 + //线别id
  119 + if v, ok := queryOptions["lineId"]; ok {
  120 + query.Where(`Work_station->>'lineId' = '?'`, v)
  121 + }
  122 + //日期开始
  123 + if v, ok := queryOptions["beginDate"]; ok {
  124 + query.Where("record_date>=?", v)
  125 + }
  126 + //日期结束
  127 + if v, ok := queryOptions["endDate"]; ok {
  128 + query.Where("record_date<=?", v)
  129 + }
  130 +
  131 + //指定查询某个日期
  132 + if v, ok := queryOptions["recordDateStr"]; ok {
  133 + query.Where("record_date_str=?", v)
  134 + }
105 cnt, err := query.SelectAndCount() 135 cnt, err := query.SelectAndCount()
106 if err != nil { 136 if err != nil {
107 return 0, nil, err 137 return 0, nil, err
@@ -134,5 +164,6 @@ func (repo *RewardSummaryRepository) TransformToDomain(param *models.RewardSumma @@ -134,5 +164,6 @@ func (repo *RewardSummaryRepository) TransformToDomain(param *models.RewardSumma
134 CreatedAt: param.CreatedAt, 164 CreatedAt: param.CreatedAt,
135 UpdatedAt: param.UpdatedAt, 165 UpdatedAt: param.UpdatedAt,
136 SummaryResult: param.SummaryResult, 166 SummaryResult: param.SummaryResult,
  167 + RecordDateStr: param.RecordDateStr,
137 } 168 }
138 } 169 }