| | |
| | | inputMoreValueArr := make([]models.UnitItems, 0, len(product.MoreUnitList)) |
| | | outputMoreValueArr := make([]models.UnitItems, 0, len(product.MoreUnitList)) |
| | | for _, unitItem := range product.MoreUnitList { |
| | | moreValueArr = append(moreValueArr, models.UnitItems{ |
| | | Amount: amount.Mul(unitItem.Amount), |
| | | Unit: unitItem.Unit, |
| | | Floating: unitItem.Floating, |
| | | }) |
| | | bys, _ := json.Marshal(moreValueArr) |
| | | moreUnits = string(bys) |
| | | if !amount.IsZero() { |
| | | moreValueArr = append(moreValueArr, models.UnitItems{ |
| | | Amount: amount.Mul(unitItem.Amount), |
| | | Unit: unitItem.Unit, |
| | | Floating: unitItem.Floating, |
| | | }) |
| | | } |
| | | |
| | | if !inputMap[productId].IsZero() { |
| | | inputMoreValueArr = append(inputMoreValueArr, models.UnitItems{ |
| | |
| | | Unit: unitItem.Unit, |
| | | Floating: unitItem.Floating, |
| | | }) |
| | | bys, _ = json.Marshal(inputMoreValueArr) |
| | | inputMoreUnits = string(bys) |
| | | |
| | | } |
| | | |
| | | if !outputMap[productId].IsZero() { |
| | |
| | | Unit: unitItem.Unit, |
| | | Floating: unitItem.Floating, |
| | | }) |
| | | bys, _ = json.Marshal(outputMoreValueArr) |
| | | outputMoreUnits = string(bys) |
| | | |
| | | } |
| | | } |
| | | bys, _ := json.Marshal(moreValueArr) |
| | | if len(moreValueArr) > 0 { |
| | | fmt.Println(moreValueArr) |
| | | } |
| | | moreUnits = string(bys) |
| | | bys, _ = json.Marshal(inputMoreValueArr) |
| | | inputMoreUnits = string(bys) |
| | | bys, _ = json.Marshal(outputMoreValueArr) |
| | | outputMoreUnits = string(bys) |
| | | } |
| | | |
| | | record.BeginMoreUnits = moreUnits |
| | |
| | | service.SendAlarm("月度统计创建本月失败", fmt.Sprintf("NewMonthStatsSearch Create err:%v, record: %+v", err, record)) |
| | | } |
| | | |
| | | if oldRecordsMap[productId] != nil && (!inputMap[productId].IsZero() || !outputMap[productId].IsZero()) { |
| | | record.InputAmount = inputMap[productId] |
| | | record.InputMoreUnits = inputMoreUnits |
| | | record.OutputAmount = outputMap[productId] |
| | | record.OutputMoreUnits = outputMoreUnits |
| | | if oldRecordsMap[productId] != nil { |
| | | m := map[string]interface{}{ |
| | | "input_amount": inputMap[productId], |
| | | "input_more_units": inputMoreUnits, |
| | | "output_amount": outputMap[productId], |
| | | "output_more_units": outputMoreUnits, |
| | | "end_more_units": moreUnits, |
| | | "end_amount": amount, |
| | | "end_more_units": moreUnits, |
| | | "end_amount": amount, |
| | | } |
| | | if !inputMap[productId].IsZero() || !outputMap[productId].IsZero() { |
| | | record.InputAmount = inputMap[productId] |
| | | record.InputMoreUnits = inputMoreUnits |
| | | record.OutputAmount = outputMap[productId] |
| | | record.OutputMoreUnits = outputMoreUnits |
| | | m["input_amount"] = inputMap[productId] |
| | | m["input_more_units"] = inputMoreUnits |
| | | m["output_amount"] = outputMap[productId] |
| | | m["output_more_units"] = outputMoreUnits |
| | | } |
| | | err = models.NewMonthStatsSearch().SetOrm(db).SetID(oldRecordsMap[productId].Id).UpdateByMap(m) |
| | | if err != nil { |