| | |
| | | type BadFinenessGrade string |
| | | |
| | | const ( |
| | | BadFinenessGradeA = "badA" |
| | | BadFinenessGradeB = "badB" |
| | | BadFinenessGradeC = "badC" |
| | | BadFinenessGradeA = "野纤" |
| | | BadFinenessGradeB = "大野" |
| | | BadFinenessGradeC = "特野" |
| | | ) |
| | | |
| | | const ( |
| | |
| | | // @Tags 纤度检验 |
| | | // @Summary 纤度检验修改 |
| | | // @Produce application/json |
| | | // @Param object body response.FinenessCheckInfo true "字典信息" |
| | | // @Param object body response.FinenessCheckInfo true "参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/fineness/check [post] |
| | | // @Router /api-jl/v1/fineness/check [PUT] |
| | | func (slf FinenessController) CheckEdit(c *gin.Context) { |
| | | var params response.FinenessCheckInfo |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "summary": "纤度检验修改", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/response.FinenessCheckInfo" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "summary": "纤度检验修改", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/response.FinenessCheckInfo" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | summary: 纤度检验列表 |
| | | tags: |
| | | - 纤度检验 |
| | | post: |
| | | put: |
| | | parameters: |
| | | - description: 字典信息 |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/response.FinenessCheckInfo' |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | var carCheckNumber = 0 //单个car已检查样本数 |
| | | |
| | | var item *models.FinenessCheckItem |
| | | var deviation decimal.Decimal |
| | | var deviation, totalDeviation decimal.Decimal |
| | | var finenessGrade string |
| | | var roundingItemMap = make(map[float32]*models.FinenessRoundingItem, 0) |
| | | lastCarNo = finenessRegister.FinenessList[0].Position |
| | |
| | | fineness := decimal.NewFromFloat32(roundedHalfFineness) |
| | | for i := 0; i < finenessItem.Quantity; i++ { |
| | | allFinenessList = append(allFinenessList, fineness) |
| | | personFinenessList = append(personFinenessList, fineness) |
| | | } |
| | | personFinenessList = append(personFinenessList, fineness) |
| | | |
| | | if roundingItemMap[roundedHalfFineness] == nil { |
| | | roundingItemMap[roundedHalfFineness] = &models.FinenessRoundingItem{ |
| | | Fineness: fineness, |
| | |
| | | carCheckNumber = 0 |
| | | if endCarMap[finenessItem.Position] { //走到了某个人最后的车号,每人算一次偏差和等级 |
| | | deviation = utils.Deviation(personFinenessList) |
| | | finenessGrade = CalcFinenessGrade(item.Deviation, item.TotalDeviation, item.Cleanliness, item.Purity, item.TwiceChange, standardMap) |
| | | totalDeviation = TotalDeviation(personFinenessList, utils.Average(personFinenessList)) |
| | | finenessGrade = CalcFinenessGrade(deviation, totalDeviation, decimal.Zero, decimal.Zero, decimal.Zero, standardMap) |
| | | personFinenessList = personFinenessList[:0] |
| | | } else { |
| | | deviation = decimal.Zero |
| | | totalDeviation = decimal.Zero |
| | | finenessGrade = "" |
| | | } |
| | | item = MakeFinenessCheckItem(roundingItemMap, finenessRegister.ID, lastCarNo, deviation, finenessGrade) |
| | | item = MakeFinenessCheckItem(roundingItemMap, finenessRegister.ID, lastCarNo, deviation, totalDeviation, finenessGrade) |
| | | finenessCheckItems = append(finenessCheckItems, item) |
| | | roundingItemMap = make(map[float32]*models.FinenessRoundingItem, 0) //重置 |
| | | } |
| | |
| | | return err |
| | | } |
| | | |
| | | func MakeFinenessCheckItem(roundingItemMap map[float32]*models.FinenessRoundingItem, finenessRegisterID uint, position int, deviation decimal.Decimal, finenessGrade string) *models.FinenessCheckItem { |
| | | func MakeFinenessCheckItem(roundingItemMap map[float32]*models.FinenessRoundingItem, finenessRegisterID uint, position int, deviation, totalDeviation decimal.Decimal, finenessGrade string) *models.FinenessCheckItem { |
| | | roundingItems := make([]*models.FinenessRoundingItem, 0, len(roundingItemMap)) |
| | | for _, v := range roundingItemMap { |
| | | roundingItems = append(roundingItems, &models.FinenessRoundingItem{ |
| | |
| | | Position: position, |
| | | FinenessRoundingItems: roundingItems, |
| | | Deviation: deviation, |
| | | TotalDeviation: totalDeviation, |
| | | FinenessGrade: finenessGrade, |
| | | Remark: "", |
| | | } |
| | |
| | | for _, pair := range st.ValueList { |
| | | switch st.CheckItem { |
| | | case constvar.CheckItemDeviation: |
| | | if st.SortType == SortTypeAsc { |
| | | if st.SortType == ValueTypeSmallerBetter { |
| | | if deviation.LessThanOrEqual(pair.RankValue) { |
| | | grade = pair.RankName |
| | | } |
| | |
| | | } |
| | | } |
| | | case constvar.CheckItemMaxDeviation: |
| | | if st.SortType == SortTypeAsc { |
| | | if st.SortType == ValueTypeSmallerBetter { |
| | | if totalDeviation.LessThanOrEqual(pair.RankValue) { |
| | | grade = pair.RankName |
| | | } |
| | |
| | | } |
| | | } |
| | | case constvar.CheckItemTwiceChange: |
| | | if st.SortType == SortTypeAsc { |
| | | if st.SortType == ValueTypeSmallerBetter { |
| | | if twiceChange.LessThanOrEqual(pair.RankValue) { |
| | | grade = pair.RankName |
| | | } |
| | |
| | | } |
| | | } |
| | | case constvar.CheckItemCleanliness: |
| | | if st.SortType == SortTypeAsc { |
| | | if st.SortType == ValueTypeSmallerBetter { |
| | | if cleanliness.LessThanOrEqual(pair.RankValue) { |
| | | grade = pair.RankName |
| | | } |
| | |
| | | } |
| | | } |
| | | case constvar.CheckItemPurity: |
| | | if st.SortType == SortTypeAsc { |
| | | if st.SortType == ValueTypeSmallerBetter { |
| | | if purity.LessThanOrEqual(pair.RankValue) { |
| | | grade = pair.RankName |
| | | } |
| | |
| | | break |
| | | } |
| | | } |
| | | if grade != "" { |
| | | checkItemGradeMap[st.CheckItem] = grade |
| | | gradeRanks = append(gradeRanks, gradeRank{ |
| | | gradeName: grade, |
| | | gradeRank: st.GradeRank[grade], |
| | | }) |
| | | if grade == "" { |
| | | grade = constvar.BadFinenessGradeC |
| | | } |
| | | checkItemGradeMap[st.CheckItem] = grade |
| | | gradeRanks = append(gradeRanks, gradeRank{ |
| | | gradeName: grade, |
| | | gradeRank: st.GradeRank[grade], |
| | | }) |
| | | } |
| | | if len(gradeRanks) == 0 { |
| | | return "" |
| | |
| | | EndFineness decimal.Decimal |
| | | GradeMap map[string]struct{} |
| | | ValueList []*Pair |
| | | SortType SortType |
| | | SortType ValueType |
| | | GradeRank map[string]int |
| | | } |
| | | |
| | |
| | | RankValue decimal.Decimal |
| | | } |
| | | |
| | | type SortType int |
| | | type ValueType int |
| | | |
| | | const ( |
| | | SortTypeAsc SortType = 0 |
| | | SortTypeDesc SortType = 1 |
| | | ValueTypeSmallerBetter ValueType = 0 //值按升序排名(值越大,等级越高) |
| | | ValueTypeGreaterBetter ValueType = 1 //值按降序排名(值越小,等级越低) |
| | | ) |
| | | |
| | | var sortTypeMap = map[constvar.CheckItem]SortType{ |
| | | constvar.CheckItemDeviation: SortTypeAsc, |
| | | constvar.CheckItemTwiceChange: SortTypeAsc, |
| | | constvar.CheckItemCleanliness: SortTypeDesc, |
| | | constvar.CheckItemPurity: SortTypeDesc, |
| | | constvar.CheckItemMaxDeviation: SortTypeAsc, |
| | | var sortTypeMap = map[constvar.CheckItem]ValueType{ |
| | | constvar.CheckItemDeviation: ValueTypeSmallerBetter, |
| | | constvar.CheckItemTwiceChange: ValueTypeSmallerBetter, |
| | | constvar.CheckItemCleanliness: ValueTypeGreaterBetter, |
| | | constvar.CheckItemPurity: ValueTypeGreaterBetter, |
| | | constvar.CheckItemMaxDeviation: ValueTypeSmallerBetter, |
| | | } |
| | | |
| | | func GetSilkRankStandard(startFineness, endFineness decimal.Decimal) (map[string]*Standard, error) { |
| | |
| | | } |
| | | } |
| | | //value排序 |
| | | for k := range standardMap { |
| | | for k := range standardMap { //等级降序排列 |
| | | sort.Slice(standardMap[k].ValueList, func(i, j int) bool { |
| | | sortType := sortTypeMap[standardMap[k].CheckItem] |
| | | standardMap[k].SortType = sortType |
| | | if sortType == SortTypeAsc { |
| | | if sortType == ValueTypeSmallerBetter { |
| | | return standardMap[k].ValueList[i].RankValue.LessThan(standardMap[k].ValueList[j].RankValue) |
| | | } else { |
| | | return standardMap[k].ValueList[i].RankValue.GreaterThan(standardMap[k].ValueList[j].RankValue) |
| | | } |
| | | }) |
| | | } |
| | | //等级排名 |
| | | //等级排名 GradeRank越大,等级越高 |
| | | for lineId, standard := range standardMap { |
| | | for k, pair := range standard.ValueList { |
| | | if standardMap[lineId].GradeRank == nil { |
| | | standardMap[lineId].GradeRank = make(map[string]int, 0) |
| | | } |
| | | if standard.SortType == SortTypeAsc { |
| | | standardMap[lineId].GradeRank[pair.RankName] = k + 1 |
| | | } else { |
| | | standardMap[lineId].GradeRank[pair.RankName] = len(standard.ValueList) - k |
| | | } |
| | | standardMap[lineId].GradeRank[pair.RankName] = len(standard.ValueList) - k |
| | | } |
| | | } |
| | | return standardMap, nil |