正在显示
12 个修改的文件
包含
617 行增加
和
0 行删除
| @@ -36,3 +36,8 @@ func (attendanceService *AttendanceService) WorkshopWorkTimeRecordStatics(cmd *c | @@ -36,3 +36,8 @@ func (attendanceService *AttendanceService) WorkshopWorkTimeRecordStatics(cmd *c | ||
| 36 | } | 36 | } |
| 37 | return struct{}{}, nil | 37 | return struct{}{}, nil |
| 38 | } | 38 | } |
| 39 | + | ||
| 40 | +//导入工时数据 | ||
| 41 | +func (attendanceService *AttendanceService) ImportDataAttendance() error { | ||
| 42 | + return nil | ||
| 43 | +} |
| @@ -157,3 +157,11 @@ func CreateProductMaterialRepository(options map[string]interface{}) (domain.Pro | @@ -157,3 +157,11 @@ func CreateProductMaterialRepository(options map[string]interface{}) (domain.Pro | ||
| 157 | } | 157 | } |
| 158 | return repository.NewProductMaterialRepository(transactionContext) | 158 | return repository.NewProductMaterialRepository(transactionContext) |
| 159 | } | 159 | } |
| 160 | + | ||
| 161 | +func CreateRewardStandardRepository(options map[string]interface{}) (domain.RewardStandardRepository, error) { | ||
| 162 | + var transactionContext *pg.TransactionContext | ||
| 163 | + if value, ok := options["transactionContext"]; ok { | ||
| 164 | + transactionContext = value.(*pg.TransactionContext) | ||
| 165 | + } | ||
| 166 | + return repository.NewRewardStandardRepository(transactionContext) | ||
| 167 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type SaveRewardStandardCommand struct { | ||
| 12 | + Id int `json:"id"` //奖惩标准 id | ||
| 13 | + WorkshopId int `json:"workshopId" valid:"Required"` //车间id | ||
| 14 | + LineId int `json:"lineId" valid:"Required"` //生产线ID | ||
| 15 | + SectionId int `json:"sectionId" valid:"Required"` //工段ID | ||
| 16 | + Remark string `json:"remark"` //备注 | ||
| 17 | + TargetType int `json:"targetType" valid:"Required"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
| 18 | + TargeVal1 string `json:"targeVal1"` //填写的指标值1 | ||
| 19 | + TargeVal2 string `json:"targeVal2"` //填写的指标值2 | ||
| 20 | + TargeVal3 string `json:"targeVal3"` //填写的指标值3 | ||
| 21 | + TargeVal4 string `json:"targeVal4"` //填写的指标值4 | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (removeProductCommand *SaveRewardStandardCommand) Valid(validation *validation.Validation) { | ||
| 25 | + | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (removeProductCommand *SaveRewardStandardCommand) ValidateCommand() error { | ||
| 29 | + valid := validation.Validation{} | ||
| 30 | + b, err := valid.Valid(removeProductCommand) | ||
| 31 | + if err != nil { | ||
| 32 | + return err | ||
| 33 | + } | ||
| 34 | + if !b { | ||
| 35 | + elem := reflect.TypeOf(removeProductCommand).Elem() | ||
| 36 | + for _, validErr := range valid.Errors { | ||
| 37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 38 | + if isExist { | ||
| 39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 40 | + } else { | ||
| 41 | + return fmt.Errorf(validErr.Message) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + return nil | ||
| 46 | +} |
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +type RewardStandardInfo struct { | ||
| 4 | + Id int `json:"id"` //奖惩标准id | ||
| 5 | + CompanyId int `json:"companyId"` //企业id | ||
| 6 | + OrgId int `json:"orgId"` //组织ID | ||
| 7 | + WorkshopId int `json:"workshopId"` //车间id | ||
| 8 | + WorkshopName string `json:"workshopName"` // | ||
| 9 | + LineId int `json:"lineId"` //生产线ID | ||
| 10 | + LineName string `json:"lineName"` // | ||
| 11 | + SectionId int `json:"sectionId"` //工段ID | ||
| 12 | + SectionName string `json:"sectionName"` // | ||
| 13 | + Remark string `json:"remark"` //备注 | ||
| 14 | + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
| 15 | + TargeVal1 string `json:"targeVal1"` //填写的指标值1 | ||
| 16 | + TargeVal2 string `json:"targeVal2"` //填写的指标值2 | ||
| 17 | + TargeVal3 string `json:"targeVal3"` //填写的指标值3 | ||
| 18 | + TargeVal4 string `json:"targeVal4"` //填写的指标值4 | ||
| 19 | + | ||
| 20 | +} |
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "github.com/linmadan/egglib-go/core/application" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/command" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/dto" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/query" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type RewardStandardService struct{} | ||
| 15 | + | ||
| 16 | +func NewProductService(options map[string]interface{}) *RewardStandardService { | ||
| 17 | + newService := &RewardStandardService{} | ||
| 18 | + return newService | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +//SaveRewardStandard 保存奖惩标准数据 | ||
| 22 | +func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) { | ||
| 23 | + if err := param.ValidateCommand(); err != nil { | ||
| 24 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 25 | + } | ||
| 26 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 27 | + if err != nil { | ||
| 28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 29 | + } | ||
| 30 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 31 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 32 | + } | ||
| 33 | + defer func() { | ||
| 34 | + transactionContext.RollbackTransaction() | ||
| 35 | + }() | ||
| 36 | + | ||
| 37 | + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{ | ||
| 38 | + "transactionContext": transactionContext, | ||
| 39 | + }) | ||
| 40 | + | ||
| 41 | + _, dataList, err := rewardStandardRepo.Find(map[string]interface{}{ | ||
| 42 | + "limit": 1, | ||
| 43 | + "workshopId": param.WorkshopId, | ||
| 44 | + "lineId": param.LineId, | ||
| 45 | + "sectionId": param.SectionId, | ||
| 46 | + "targetType": param.TargetType, | ||
| 47 | + }) | ||
| 48 | + if err != nil { | ||
| 49 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 50 | + } | ||
| 51 | + if len(dataList) > 0 { | ||
| 52 | + if dataList[0].Id != param.Id { | ||
| 53 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "当前指标已存在") | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + var rewardStandardData *domain.RewardStandard | ||
| 57 | + if param.Id > 0 { | ||
| 58 | + rewardStandardData, err = rewardStandardRepo.FindOne(map[string]interface{}{ | ||
| 59 | + "id": param.Id, | ||
| 60 | + }) | ||
| 61 | + if err != nil { | ||
| 62 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error()) | ||
| 63 | + } | ||
| 64 | + if rewardStandardData.CompanyId != operateInfo.CompanyId { | ||
| 65 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据填写错误") | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + } else { | ||
| 69 | + rewardStandardData = &domain.RewardStandard{ | ||
| 70 | + CreatedAt: time.Now(), | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{ | ||
| 75 | + "transactionContext": transactionContext, | ||
| 76 | + }) | ||
| 77 | + //获取车间数据 | ||
| 78 | + workShopData, err := workShopRepo.FindOne(map[string]interface{}{ | ||
| 79 | + "workshopId": param.WorkshopId, | ||
| 80 | + }) | ||
| 81 | + if err != nil { | ||
| 82 | + return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error()) | ||
| 83 | + } | ||
| 84 | + if workShopData.CompanyId != operateInfo.CompanyId { | ||
| 85 | + return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误") | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + productLineData, err := workShopData.FindLine(param.LineId) | ||
| 89 | + if err != nil { | ||
| 90 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 91 | + } | ||
| 92 | + productSection, err := productLineData.FindSection(param.SectionId) | ||
| 93 | + if err != nil { | ||
| 94 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 95 | + } | ||
| 96 | + rewardStandardData.UpdatedAt = time.Now() | ||
| 97 | + rewardStandardData.ProductSection = *productSection | ||
| 98 | + rewardStandardData.ProductLine = productLineData.SimpleProductLine() | ||
| 99 | + rewardStandardData.Workshop = workShopData.SimpleWorkshop() | ||
| 100 | + rewardStandardData.Remark = param.Remark | ||
| 101 | + err = rewardStandardData.UpdateTarge( | ||
| 102 | + param.TargetType, | ||
| 103 | + param.TargeVal1, | ||
| 104 | + param.TargeVal2, | ||
| 105 | + param.TargeVal3, | ||
| 106 | + param.TargeVal4) | ||
| 107 | + if err != nil { | ||
| 108 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 109 | + } | ||
| 110 | + _, err = rewardStandardRepo.Save(rewardStandardData) | ||
| 111 | + if err != nil { | ||
| 112 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 113 | + } | ||
| 114 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 115 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 116 | + } | ||
| 117 | + return nil, nil | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +//GetRewardStandard 根据id获取奖惩标准数据 | ||
| 121 | +func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) { | ||
| 122 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 123 | + if err != nil { | ||
| 124 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 125 | + } | ||
| 126 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 127 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 128 | + } | ||
| 129 | + defer func() { | ||
| 130 | + transactionContext.RollbackTransaction() | ||
| 131 | + }() | ||
| 132 | + | ||
| 133 | + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{ | ||
| 134 | + "transactionContext": transactionContext, | ||
| 135 | + }) | ||
| 136 | + rewardStandardData, err := rewardStandardRepo.FindOne(map[string]interface{}{ | ||
| 137 | + "id": param.Id, | ||
| 138 | + }) | ||
| 139 | + if err != nil { | ||
| 140 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error()) | ||
| 141 | + } | ||
| 142 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 143 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + result := dto.RewardStandardInfo{ | ||
| 147 | + Id: rewardStandardData.Id, | ||
| 148 | + WorkshopId: rewardStandardData.Workshop.WorkshopId, | ||
| 149 | + WorkshopName: rewardStandardData.Workshop.WorkshopName, | ||
| 150 | + LineId: rewardStandardData.ProductLine.LineId, | ||
| 151 | + LineName: rewardStandardData.ProductLine.LineName, | ||
| 152 | + SectionId: rewardStandardData.ProductSection.SectionId, | ||
| 153 | + SectionName: rewardStandardData.ProductSection.SectionName, | ||
| 154 | + Remark: rewardStandardData.Remark, | ||
| 155 | + TargetType: rewardStandardData.TargetType, | ||
| 156 | + TargeVal1: rewardStandardData.TargeVal1, | ||
| 157 | + TargeVal2: rewardStandardData.TargeVal2, | ||
| 158 | + TargeVal3: rewardStandardData.TargeVal3, | ||
| 159 | + TargeVal4: rewardStandardData.TargeVal4, | ||
| 160 | + } | ||
| 161 | + return &result, nil | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +//DeleteRewardStandard 根据id删除奖惩标准 | ||
| 165 | +func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStandard) (*domain.RewardStandard, error) { | ||
| 166 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 167 | + if err != nil { | ||
| 168 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 169 | + } | ||
| 170 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 171 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 172 | + } | ||
| 173 | + defer func() { | ||
| 174 | + transactionContext.RollbackTransaction() | ||
| 175 | + }() | ||
| 176 | + | ||
| 177 | + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{ | ||
| 178 | + "transactionContext": transactionContext, | ||
| 179 | + }) | ||
| 180 | + rewardStandardData, err := rewardStandardRepo.FindOne(map[string]interface{}{ | ||
| 181 | + "id": param.Id, | ||
| 182 | + }) | ||
| 183 | + if err != nil { | ||
| 184 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error()) | ||
| 185 | + } | ||
| 186 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 187 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 188 | + } | ||
| 189 | + return rewardStandardData, nil | ||
| 190 | +} |
| @@ -14,6 +14,12 @@ type ProductLine struct { | @@ -14,6 +14,12 @@ type ProductLine struct { | ||
| 14 | Removed int `json:"removed,omitempty"` | 14 | Removed int `json:"removed,omitempty"` |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | +//输出简化的模型 | ||
| 18 | +type SimpleProductLine struct { | ||
| 19 | + LineId int `json:"lineId"` // 生产线ID | ||
| 20 | + LineName string `json:"lineName"` // 生产线名称 | ||
| 21 | +} | ||
| 22 | + | ||
| 17 | // 查询生产线 | 23 | // 查询生产线 |
| 18 | func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) { | 24 | func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) { |
| 19 | for i := range productLine.ProductSections { | 25 | for i := range productLine.ProductSections { |
| @@ -37,3 +43,11 @@ func (productLine *ProductLine) GetProductSections(removed int) []*ProductSectio | @@ -37,3 +43,11 @@ func (productLine *ProductLine) GetProductSections(removed int) []*ProductSectio | ||
| 37 | } | 43 | } |
| 38 | return result | 44 | return result |
| 39 | } | 45 | } |
| 46 | + | ||
| 47 | +//SimpleProductLine 输出简化的模型 | ||
| 48 | +func (productLine *ProductLine) SimpleProductLine() SimpleProductLine { | ||
| 49 | + return SimpleProductLine{ | ||
| 50 | + LineId: productLine.LineId, | ||
| 51 | + LineName: productLine.LineName, | ||
| 52 | + } | ||
| 53 | +} |
pkg/domain/reward_rule.go
0 → 100644
pkg/domain/reward_standard.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "strconv" | ||
| 6 | + "time" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +//RewardStandard 奖惩标准 | ||
| 10 | +type RewardStandard struct { | ||
| 11 | + Id int `json:"id"` //奖惩标准id | ||
| 12 | + CompanyId int `json:"companyId"` //企业id | ||
| 13 | + OrgId int `json:"orgId"` //组织ID | ||
| 14 | + Workshop SimpleWorkshop `json:"workshop"` //车间id | ||
| 15 | + ProductLine SimpleProductLine `json:"productLine"` //生产线 | ||
| 16 | + ProductSection ProductSection `json:"ProductSection"` //工段 | ||
| 17 | + Remark string `json:"remark"` //备注 | ||
| 18 | + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
| 19 | + TargeVal1 string `json:"targeVal1"` //填写的指标值1 | ||
| 20 | + TargeVal2 string `json:"targeVal2"` //填写的指标值2 | ||
| 21 | + TargeVal3 string `json:"targeVal3"` //填写的指标值3 | ||
| 22 | + TargeVal4 string `json:"targeVal4"` //填写的指标值4 | ||
| 23 | + CreatedAt time.Time `json:"createdAt"` //创建时间 | ||
| 24 | + UpdatedAt time.Time `json:"updatedAt"` //更新时间 | ||
| 25 | + DeletedAt *time.Time `json:"-"` //删除时间 | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +/* | ||
| 29 | +填写的指标值描述 | ||
| 30 | +产效=> 功: 大于等于 x kg/小时;过:小于 x kg/小时 | ||
| 31 | +合格率=> 功:大于等于 x% ;过:小于 x% | ||
| 32 | +安全事故 => 功:小于等于 x 次 或者 损失小于等于 x 元;过:大于 x 次 或 损失大于 x 元 | ||
| 33 | +质量事故 => 功:小于等于 x 次 或者 损失 小于等于 x 元;过:大于 x 次 或者 损失大于 x 元 | ||
| 34 | +异物次数 => 功:发现金属小于等于 x 次 或者 发现非金属小于等于 x 次 | ||
| 35 | + 过:发现金属大于 x 次 或 发现非金数大于 x 次 | ||
| 36 | + | ||
| 37 | +*/ | ||
| 38 | + | ||
| 39 | +type RewardStandardRepository interface { | ||
| 40 | + Save(param *RewardStandard) (*RewardStandard, error) | ||
| 41 | + Remove(param *RewardStandard) (*RewardStandard, error) | ||
| 42 | + FindOne(queryOptions map[string]interface{}) (*RewardStandard, error) | ||
| 43 | + Find(queryOptions map[string]interface{}) (int64, []*RewardStandard, error) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +//指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
| 47 | +const ( | ||
| 48 | + TargetType1 int = 1 | ||
| 49 | + TargetType2 int = 2 | ||
| 50 | + TargetType3 int = 3 | ||
| 51 | + TargetType4 int = 4 | ||
| 52 | + TargetType5 int = 5 | ||
| 53 | +) | ||
| 54 | + | ||
| 55 | +//UpdateTarge 更新指标内容 | ||
| 56 | +func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 string, targeVal3 string, targeVal4 string) error { | ||
| 57 | + switch targetType { | ||
| 58 | + case TargetType1, TargetType2: | ||
| 59 | + if len(targeVal1) == 0 || len(targeVal2) == 0 { | ||
| 60 | + return errors.New("功过指标内容不能为空") | ||
| 61 | + } | ||
| 62 | + _, err := strconv.Atoi(targeVal1) | ||
| 63 | + if err != nil { | ||
| 64 | + return errors.New("功过指标内容需要为整数") | ||
| 65 | + } | ||
| 66 | + _, err = strconv.Atoi(targeVal2) | ||
| 67 | + if err != nil { | ||
| 68 | + return errors.New("功过指标内容需要为整数") | ||
| 69 | + } | ||
| 70 | + m.TargetType = targetType | ||
| 71 | + m.TargeVal1 = targeVal1 | ||
| 72 | + m.TargeVal2 = targeVal2 | ||
| 73 | + m.TargeVal3 = "" | ||
| 74 | + m.TargeVal4 = "" | ||
| 75 | + case TargetType3, TargetType4, TargetType5: | ||
| 76 | + if len(targeVal1) == 0 || len(targeVal2) == 0 || len(targeVal3) == 0 || len(targeVal4) == 0 { | ||
| 77 | + return errors.New("功过指标内容不能为空") | ||
| 78 | + } | ||
| 79 | + _, err := strconv.Atoi(targeVal1) | ||
| 80 | + if err != nil { | ||
| 81 | + return errors.New("功过指标内容需要为整数") | ||
| 82 | + } | ||
| 83 | + _, err = strconv.Atoi(targeVal2) | ||
| 84 | + if err != nil { | ||
| 85 | + return errors.New("功过指标内容需要为整数") | ||
| 86 | + } | ||
| 87 | + _, err = strconv.Atoi(targeVal3) | ||
| 88 | + if err != nil { | ||
| 89 | + return errors.New("功过指标内容需要为整数") | ||
| 90 | + } | ||
| 91 | + _, err = strconv.Atoi(targeVal4) | ||
| 92 | + if err != nil { | ||
| 93 | + return errors.New("功过指标内容需要为整数") | ||
| 94 | + } | ||
| 95 | + m.TargetType = targetType | ||
| 96 | + m.TargeVal1 = targeVal1 | ||
| 97 | + m.TargeVal2 = targeVal2 | ||
| 98 | + m.TargeVal3 = targeVal3 | ||
| 99 | + m.TargeVal4 = targeVal4 | ||
| 100 | + default: | ||
| 101 | + return errors.New("指标类型填写错误") | ||
| 102 | + | ||
| 103 | + } | ||
| 104 | + return nil | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +func (m *RewardStandard) TargetTypeName() string { | ||
| 108 | + switch m.TargetType { | ||
| 109 | + case TargetType1: | ||
| 110 | + return "产效" | ||
| 111 | + case TargetType2: | ||
| 112 | + return "合格率" | ||
| 113 | + case TargetType3: | ||
| 114 | + return "安全事故" | ||
| 115 | + case TargetType4: | ||
| 116 | + return "质量事故" | ||
| 117 | + case TargetType5: | ||
| 118 | + return "异物次数" | ||
| 119 | + } | ||
| 120 | + return "" | ||
| 121 | +} |
| @@ -39,6 +39,13 @@ type Workshop struct { | @@ -39,6 +39,13 @@ type Workshop struct { | ||
| 39 | Ext *Ext `json:"ext,omitempty"` | 39 | Ext *Ext `json:"ext,omitempty"` |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | +type SimpleWorkshop struct { | ||
| 43 | + // 车间ID | ||
| 44 | + WorkshopId int `json:"workshopId"` | ||
| 45 | + // 车间名称 | ||
| 46 | + WorkshopName string `json:"workshopName"` | ||
| 47 | +} | ||
| 48 | + | ||
| 42 | type WorkshopRepository interface { | 49 | type WorkshopRepository interface { |
| 43 | Save(workshop *Workshop) (*Workshop, error) | 50 | Save(workshop *Workshop) (*Workshop, error) |
| 44 | Remove(workshop *Workshop) (*Workshop, error) | 51 | Remove(workshop *Workshop) (*Workshop, error) |
| @@ -301,3 +308,11 @@ func (workshop *Workshop) CloneSample() *Workshop { | @@ -301,3 +308,11 @@ func (workshop *Workshop) CloneSample() *Workshop { | ||
| 301 | WorkshopName: workshop.WorkshopName, | 308 | WorkshopName: workshop.WorkshopName, |
| 302 | } | 309 | } |
| 303 | } | 310 | } |
| 311 | + | ||
| 312 | +//SimpleWorkshop 输出简化的模型 | ||
| 313 | +func (workShop *Workshop) SimpleWorkshop() SimpleWorkshop { | ||
| 314 | + return SimpleWorkshop{ | ||
| 315 | + WorkshopId: workShop.WorkshopId, | ||
| 316 | + WorkshopName: workShop.WorkshopName, | ||
| 317 | + } | ||
| 318 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +//RewardStandard 奖惩标准 | ||
| 10 | +type RewardStandard struct { | ||
| 11 | + tableName string `pg:"manufacture.reward_standard,alias:reward_standard"` | ||
| 12 | + Id int `pg:"pk:id"` //奖惩标准 id | ||
| 13 | + Workshop domain.SimpleWorkshop //车间id | ||
| 14 | + ProductLine domain.SimpleProductLine //生产线 | ||
| 15 | + ProductSection domain.ProductSection //工段 | ||
| 16 | + Remark string //备注 | ||
| 17 | + TargetType int //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
| 18 | + TargeVal1 string //填写的指标值1 | ||
| 19 | + TargeVal2 string //填写的指标值2 | ||
| 20 | + TargeVal3 string //填写的指标值3 | ||
| 21 | + TargeVal4 string //填写的指标值4 | ||
| 22 | + CreatedAt time.Time //创建时间 | ||
| 23 | + UpdatedAt time.Time //更新时间 | ||
| 24 | + DeletedAt *time.Time //删除时间 | ||
| 25 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "time" | ||
| 6 | + | ||
| 7 | + "github.com/go-pg/pg/v10" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type RewardStandardRepository struct { | ||
| 14 | + transactionContext *pgTransaction.TransactionContext | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +var _ domain.RewardStandardRepository = (*RewardStandardRepository)(nil) | ||
| 18 | + | ||
| 19 | +func NewRewardStandardRepository(transactionContext *pgTransaction.TransactionContext) (*RewardStandardRepository, error) { | ||
| 20 | + if transactionContext == nil { | ||
| 21 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 22 | + } else { | ||
| 23 | + return &RewardStandardRepository{ | ||
| 24 | + transactionContext: transactionContext, | ||
| 25 | + }, nil | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// func (repo *RewardStandardRepository) nextIdentify() (int64, error) { | ||
| 30 | +// IdWorker, err := snowflake.NewIdWorker(1) | ||
| 31 | +// if err != nil { | ||
| 32 | +// return 0, err | ||
| 33 | +// } | ||
| 34 | +// id, err := IdWorker.NextId() | ||
| 35 | +// return id, err | ||
| 36 | +// } | ||
| 37 | + | ||
| 38 | +func (repo *RewardStandardRepository) Save(param *domain.RewardStandard) (*domain.RewardStandard, error) { | ||
| 39 | + m := models.RewardStandard{ | ||
| 40 | + Id: param.Id, | ||
| 41 | + Workshop: param.Workshop, | ||
| 42 | + ProductLine: param.ProductLine, | ||
| 43 | + ProductSection: param.ProductSection, | ||
| 44 | + Remark: param.Remark, | ||
| 45 | + TargetType: param.TargetType, | ||
| 46 | + TargeVal1: param.TargeVal1, | ||
| 47 | + TargeVal2: param.TargeVal2, | ||
| 48 | + TargeVal3: param.TargeVal3, | ||
| 49 | + TargeVal4: param.TargeVal4, | ||
| 50 | + CreatedAt: param.CreatedAt, | ||
| 51 | + UpdatedAt: param.UpdatedAt, | ||
| 52 | + DeletedAt: param.DeletedAt, | ||
| 53 | + } | ||
| 54 | + tx := repo.transactionContext.PgTx | ||
| 55 | + if param.Id == 0 { | ||
| 56 | + _, err := tx.Model(&m).Insert() | ||
| 57 | + if err != nil { | ||
| 58 | + return nil, err | ||
| 59 | + } | ||
| 60 | + param.Id = m.Id | ||
| 61 | + } else { | ||
| 62 | + _, err := tx.Model(&m).WherePK().Update() | ||
| 63 | + if err != nil { | ||
| 64 | + return nil, err | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + return param, nil | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +func (repo *RewardStandardRepository) Remove(param *domain.RewardStandard) (*domain.RewardStandard, error) { | ||
| 72 | + tx := repo.transactionContext.PgTx | ||
| 73 | + m := new(models.RewardStandard) | ||
| 74 | + m.Id = param.Id | ||
| 75 | + nowTime := time.Now() | ||
| 76 | + param.DeletedAt = &nowTime | ||
| 77 | + _, err := tx.Model(m). | ||
| 78 | + WherePK().Set("deleted_at=?", nowTime). | ||
| 79 | + Update() | ||
| 80 | + if err != nil { | ||
| 81 | + return param, err | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + return nil, nil | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +func (repo *RewardStandardRepository) FindOne(queryOptions map[string]interface{}) (*domain.RewardStandard, error) { | ||
| 88 | + tx := repo.transactionContext.PgTx | ||
| 89 | + m := new(models.RewardStandard) | ||
| 90 | + query := tx.Model(m).Where("deleted_at isnull") | ||
| 91 | + if v, ok := queryOptions["id"]; ok { | ||
| 92 | + query.Where("id=?", v) | ||
| 93 | + } | ||
| 94 | + err := query.First() | ||
| 95 | + if err != nil { | ||
| 96 | + if err == pg.ErrNoRows { | ||
| 97 | + return nil, domain.ErrorNotFound | ||
| 98 | + } else { | ||
| 99 | + return nil, err | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + result := repo.TransformToDomain(m) | ||
| 103 | + return result, nil | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.RewardStandard, error) { | ||
| 107 | + tx := repo.transactionContext.PgTx | ||
| 108 | + m := []models.RewardStandard{} | ||
| 109 | + query := tx.Model(&m). | ||
| 110 | + Where("deleted_at isnull"). | ||
| 111 | + Limit(20) | ||
| 112 | + if v, ok := queryOptions["limit"].(int); ok { | ||
| 113 | + query.Limit(v) | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + if v, ok := queryOptions["offset"].(int); ok { | ||
| 117 | + query.Offset(v) | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + if v, ok := queryOptions["workshopId"]; ok { | ||
| 121 | + query.Where("work_shop->>'workshopId'='?'", v) | ||
| 122 | + } | ||
| 123 | + if v, ok := queryOptions["lineId"]; ok { | ||
| 124 | + query.Where("product_line->>lineId='?'", v) | ||
| 125 | + } | ||
| 126 | + if v, ok := queryOptions["sectionId"]; ok { | ||
| 127 | + query.Where("product_section->>sectionId='?'", v) | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + if v, ok := queryOptions["targetType"]; ok { | ||
| 131 | + query.Where("target_type=?", v) | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + cnt, err := query.SelectAndCount() | ||
| 135 | + if err != nil { | ||
| 136 | + return 0, nil, err | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + var listData []*domain.RewardStandard | ||
| 140 | + for i := range m { | ||
| 141 | + temp := repo.TransformToDomain(&m[i]) | ||
| 142 | + listData = append(listData, temp) | ||
| 143 | + } | ||
| 144 | + return int64(cnt), listData, nil | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +func (repo *RewardStandardRepository) TransformToDomain(param *models.RewardStandard) *domain.RewardStandard { | ||
| 148 | + return &domain.RewardStandard{ | ||
| 149 | + Id: param.Id, | ||
| 150 | + Workshop: param.Workshop, | ||
| 151 | + ProductLine: param.ProductLine, | ||
| 152 | + ProductSection: param.ProductSection, | ||
| 153 | + Remark: param.Remark, | ||
| 154 | + TargetType: param.TargetType, | ||
| 155 | + TargeVal1: param.TargeVal1, | ||
| 156 | + TargeVal2: param.TargeVal2, | ||
| 157 | + TargeVal3: param.TargeVal3, | ||
| 158 | + TargeVal4: param.TargeVal4, | ||
| 159 | + CreatedAt: param.CreatedAt, | ||
| 160 | + UpdatedAt: param.UpdatedAt, | ||
| 161 | + DeletedAt: param.DeletedAt, | ||
| 162 | + } | ||
| 163 | +} |
-
请 注册 或 登录 后发表评论