123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package supply_analysis
- import (
- "eta/eta_mobile/models/data_manage/supply_analysis"
- "eta/eta_mobile/models/system"
- "eta/eta_mobile/utils"
- "time"
- )
- func IsVarietySuperAdmin(sysUser *system.Admin) (isSuperAdmin bool) {
-
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- isSuperAdmin = true
- }
- return
- }
- func HasVarietyPlantPermission(sysUser *system.Admin, varietyId int) (hasPermission bool, err error) {
- hasPermission = IsVarietySuperAdmin(sysUser)
- if hasPermission {
- return
- }
- tmp, err := supply_analysis.GetVarietyPermissionByVarietyIdAndUserId(varietyId, sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- if tmp != nil {
- hasPermission = true
- }
- return
- }
- func CalculateByDay(varietyInfo *supply_analysis.Variety) (dataMap map[time.Time]float64, startDate, lastDate time.Time, err error) {
-
- plantList, err := supply_analysis.GetAllVarietyPlantByVarietyId(varietyInfo.VarietyId)
- if err != nil {
- return
- }
-
- {
- currDate := time.Now()
- currHour := currDate.Hour()
- if currHour < 22 {
- lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.Format(utils.FormatDate), time.Local)
- } else {
- lastDate, _ = time.ParseInLocation(utils.FormatDate, currDate.AddDate(0, 0, 1).Format(utils.FormatDate), time.Local)
- }
- lastDate = lastDate.AddDate(0, 0, 365)
- }
-
-
- maintenanceDataMap := make(map[time.Time][]float64)
- for _, plantInfo := range plantList {
- if plantInfo.IsStop == 1 {
- plantInfo.ResumptionDate = lastDate.Format(utils.FormatDate)
- }
-
- if plantInfo.MaintenanceDate == `` || plantInfo.ResumptionDate == `` {
- continue
- }
-
- if plantInfo.AverageDailyCapacityReduction == 0 {
- continue
- }
-
- maintenanceDate, _ := time.ParseInLocation(utils.FormatDate, plantInfo.MaintenanceDate, time.Local)
- if startDate.IsZero() || maintenanceDate.Before(startDate) {
- startDate = maintenanceDate
- }
-
- resumptionDate, _ := time.ParseInLocation(utils.FormatDate, plantInfo.ResumptionDate, time.Local)
- for tmpDate := maintenanceDate; !tmpDate.After(resumptionDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
- dataList, ok := maintenanceDataMap[tmpDate]
- if !ok {
- dataList = make([]float64, 0)
- }
- dataList = append(dataList, plantInfo.AverageDailyCapacityReduction)
- maintenanceDataMap[tmpDate] = dataList
- }
- }
-
- if len(maintenanceDataMap) <= 0 {
- return
- }
-
- dataMap = make(map[time.Time]float64)
- for tmpDate := startDate; !tmpDate.After(lastDate); tmpDate = tmpDate.AddDate(0, 0, 1) {
- var calculateVal float64
- tmpDataList, ok := maintenanceDataMap[tmpDate]
-
- if !ok {
- calculateVal = 0
- } else {
- for _, tmpVal := range tmpDataList {
- calculateVal += tmpVal
- }
- }
- dataMap[tmpDate] = calculateVal
- }
- return
- }
|