Ver Fonte

车辆运转率

baishaojie há 9 meses atrás
pai
commit
e6f9c836fe

+ 2 - 2
apiserver/model/http/asset.go

@@ -38,8 +38,8 @@ type Asset struct {
 	Segment string `json:"SEGMENT"` //细分	段
 	ORD42   string `json:"ORD42"`   //资产变动方式	出售/购入/其他/其他减少/其他增加/调拨/在建工程转入
 	RAUMN   string `json:"RAUMN"`   //房间	存储资产的位置
-	ZUSAGE  string `json:"ZUSAGE"`  // 用途
-	ZSELFNB string `json:"ZSELFNB"` // 自编号
+	ZUSAGE  string `json:"EXT02"`   // 用途
+	ZSELFNB string `json:"EXT03"`   // 自编号
 }
 
 type AssetReq struct {

+ 20 - 17
apiserver/model/liugong/vehicle.go

@@ -1,23 +1,26 @@
 package liugong
 
 type VehicleInfo struct {
-	OperationName  string `json:"operateCenterCode"` //运营中心
-	AreaName       string `json:"areaCode"`          //大区
-	RancheName     string `json:"ranchCode"`         //牧场
-	VehicleType    string `json:"vehicleType"`       //设备类别
-	VehicleName    string `json:"vehicleName"`
-	VehicleLicense string `json:"vehicleLicense"` //设备内部编号
-	DeviceLicense  string `json:"deviceCode"`     //物联网编码
-	Specification  string `json:"specification"`  //规格
-	Brand          string `json:"vehicleBrand"`   //品牌
-	Usage          string `json:"vehicleUsage"`   //用途
-	DeptName       string `json:"ranchDeptName"`  //部门
-	PurchaseDate   string `json:"purchaseDate"`   //购置日期
-	EnterDate      string `json:"enterDate"`      //入场时间
-	ScrapDate      string `json:"scrapDate"`      //报废时间
-	StandardHour   int    `json:"standardHour"`   //标准工作时长
-	Status         int    `json:"vehicleStatus"`  //状态
-	WorkClass      string `json:"workClass"`      //工作类别
+	OperationCode     string `json:"operateCenterCode"` //运营中心
+	AreaCode          string `json:"areaCode"`          //大区
+	RancheCode        string `json:"ranchCode"`         //牧场
+	OperateCenterName string `json:"operateCenterName"` //运营中心
+	AreaName          string `json:"areaName"`          //大区
+	RanchName         string `json:"ranchName"`         //牧场
+	VehicleType       string `json:"vehicleType"`       //设备类别
+	VehicleName       string `json:"vehicleName"`
+	VehicleLicense    string `json:"vehicleLicense"` //设备内部编号
+	DeviceLicense     string `json:"deviceCode"`     //物联网编码
+	Specification     string `json:"specification"`  //规格
+	Brand             string `json:"vehicleBrand"`   //品牌
+	Usage             string `json:"vehicleUsage"`   //用途
+	DeptName          string `json:"ranchDeptName"`  //部门
+	PurchaseDate      string `json:"purchaseDate"`   //购置日期
+	EnterDate         string `json:"enterDate"`      //入场时间
+	ScrapDate         string `json:"scrapDate"`      //报废时间
+	StandardHour      int    `json:"standardHour"`   //标准工作时长
+	Status            int    `json:"vehicleStatus"`  //状态
+	WorkClass         string `json:"workClass"`      //工作类别
 }
 
 type Vehicle struct {

+ 2 - 0
apiserver/model/maintain.go

@@ -39,4 +39,6 @@ type Maintain struct {
 	ShutdownDate   time.Time `gorm:"column:shutdownDate" json:"shutdownDate"`
 	ShutdownPerson int64     `gorm:"column:shutdownPerson" json:"shutdownPerson"`
 	ShutdownReason string    `gorm:"column:shutdownReason" json:"shutdownReason"`
+
+	CreatDate string `gorm:"column:creatDate" json:"creatDate"`
 }

+ 19 - 0
apiserver/routers/liugong.go

@@ -133,3 +133,22 @@ func GetWorkClass(c *gin.Context) {
 		"颗粒撒料车", "其他车辆"}
 	appG.Response(200, e.SUCCESS, dataList)
 }
+
+func GetRunningRateDetail(c *gin.Context) {
+	appG := app.Gin{C: c}
+	pastureId := c.Query("pastureId")
+	offsetStr := c.Query("offset")
+	pagecountStr := c.Query("pagecount")
+	date := c.Query("date")
+	eqCode := c.Query("eqCode")
+	offset, _ := strconv.Atoi(offsetStr)
+	pagecount, _ := strconv.Atoi(pagecountStr)
+
+	data, err := svc.GetRunningRateDetail(date, pastureId, eqCode, offset, pagecount)
+	if err != nil {
+		appG.Response(500, e.ERROR, err)
+		return
+	}
+
+	appG.Response(200, e.SUCCESS, data)
+}

+ 2 - 0
apiserver/routers/router.go

@@ -211,6 +211,8 @@ func InitRouter() *gin.Engine {
 		//工作分类下拉,目前写死
 		apiV1.GET("/work/class", GetWorkClass)
 		apiV1.GET("/ensiling", GetEnsiling)
+		//车辆运转率明细
+		apiV1.GET("/running/rate/detail", GetRunningRateDetail)
 
 	}
 

+ 16 - 13
apiserver/service/job.go

@@ -25,13 +25,14 @@ func SapJobInit() {
 	//c.Start()
 
 	//t := time.Now()
-	//i := 60
+	//i := 25
 	//pastureList := make([]*model.Pasture, 0)
-	//s.d.DB.Table("pasture").Where("id in(1768,1769,1770,1771,1772)").Find(&pastureList)
+	//s.d.DB.Table("pasture").Find(&pastureList)
 	//
 	//for {
 	//	//for _, pasture := range pastureList {
-	//	s.SapAsset(t.AddDate(0, 0, -i), "", "1020")
+	//	//1029
+	//	s.SapAsset(t.AddDate(0, 0, -i), "", "1029")
 	//	//}
 	//
 	//	if i == 0 {
@@ -39,16 +40,16 @@ func SapJobInit() {
 	//	}
 	//	i--
 	//}
-	var t time.Time
-	t = time.Now()
-	s.SapMaterial(t.AddDate(0, 0, -1), "")
-	s.SapMaterial(t.AddDate(0, 0, -2), "")
-	s.SapMaterial(t.AddDate(0, 0, -3), "")
-	s.SapMaterial(t.AddDate(0, 0, -4), "")
-	s.SapMaterial(t.AddDate(0, 0, -5), "")
-	s.SapMaterial(t.AddDate(0, 0, -6), "")
-	s.SapMaterial(t.AddDate(0, 0, -7), "")
-	s.SapMaterial(t.AddDate(0, 0, -8), "")
+	//var t time.Time
+	//t = time.Now()
+	//s.SapMaterial(t.AddDate(0, 0, -1), "")
+	//s.SapMaterial(t.AddDate(0, 0, -2), "")
+	//s.SapMaterial(t.AddDate(0, 0, -3), "")
+	//s.SapMaterial(t.AddDate(0, 0, -4), "")
+	//s.SapMaterial(t.AddDate(0, 0, -5), "")
+	//s.SapMaterial(t.AddDate(0, 0, -6), "")
+	//s.SapMaterial(t.AddDate(0, 0, -7), "")
+	//s.SapMaterial(t.AddDate(0, 0, -8), "")
 	//s.SapMaterial(t.AddDate(0, 0, -9), "")
 	//s.SapMaterial(t.AddDate(0, 0, -10), "")
 	//s.SapMaterial(t.AddDate(0, 0, -11), "")
@@ -128,6 +129,8 @@ func SapJobInit() {
 	//AutoContractToASP()
 	//c1.Start()
 	//s.SyncEquipmentDate()
+	//s.SyncPasture()
+	//s.SyncEquipmentDate()
 }
 
 func jobMaterial() {

+ 117 - 18
apiserver/service/liugong.go

@@ -7,6 +7,7 @@ import (
 	"kpt.xdmy/apiserver/model"
 	"kpt.xdmy/apiserver/model/liugong"
 	"kpt.xdmy/pkg/util"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -180,7 +181,7 @@ import (
 func (s *Service) SyncEquipmentDate() {
 	eqList := make([]*model.EquipmentAndDepartment, 0)
 	err := s.d.DB.Raw(`select * from equipment e  join eqclass ec on ec.id = e.eqClassId  
-    join department d on d.id = e.departmentId where e.license is not null  and  e.license != ''  and e.pushStatus in(0,1,2) `).Find(&eqList).Error
+    join department d on d.id = e.departmentId where e.license is not null  and  e.license != ''  and e.pushStatus in(0,1,2)   `).Find(&eqList).Error
 	if err != nil {
 		logs.Error(err)
 		return
@@ -199,9 +200,15 @@ from pasture  p join  department d on  d.id = p.id join department d1 on d1.id =
 	vehicleList := make([]*liugong.VehicleInfo, 0)
 	for _, eq := range eqList {
 		arg := new(liugong.VehicleInfo)
+
+		//OperateCenterName string `json:"operateCenterName"` //运营中心
+		//AreaName          string `json:"areaName"`          //大区
+		//RanchName         string `json:"ranchName"`         //牧场
 		for _, pasture := range pastureList {
 			if pasture.ID == eq.PastureId {
-				arg.AreaName = fmt.Sprintf("%d", pasture.RegionID)
+				arg.RanchName = pasture.Name
+				arg.AreaCode = fmt.Sprintf("%d", pasture.RegionID)
+				arg.AreaName = pasture.Region
 				center := 0
 				if pasture.Center == "一中心" {
 					center = 1
@@ -210,11 +217,13 @@ from pasture  p join  department d on  d.id = p.id join department d1 on d1.id =
 				} else if pasture.Center == "三中心" {
 					center = 3
 				}
-				arg.OperationName = fmt.Sprintf("%d", center)
+				arg.OperationCode = fmt.Sprintf("%d", center)
+				arg.OperateCenterName = pasture.Center
 				break
 			}
 		}
-		arg.RancheName = fmt.Sprintf("%d", eq.Equipment.PastureId)
+
+		arg.RancheCode = fmt.Sprintf("%d", eq.Equipment.PastureId)
 		arg.VehicleType = eq.EqClass.TypeName
 		arg.VehicleLicense = eq.EqCode
 		arg.DeviceLicense = eq.License
@@ -244,9 +253,20 @@ from pasture  p join  department d on  d.id = p.id join department d1 on d1.id =
 
 		arg.ScrapDate = eq.LeaveDate.Format("2006-01-02")
 		arg.StandardHour = eq.Duration
+
 		arg.Status = eq.PushStatus
+		if eq.Statue == 19 {
+			arg.Status = 0
+		} else if strings.Index(eq.License, "-") >= 0 {
+			arg.Status = 3
+			fmt.Println(strings.Index(eq.License, "-"))
+			eq.License = strings.Replace(eq.License, "-", "", -1)
+			fmt.Println(eq.License)
+		}
+
 		arg.VehicleName = eq.EqName
 		arg.WorkClass = eq.WorkClass
+
 		vehicleList = append(vehicleList, arg)
 	}
 
@@ -276,13 +296,13 @@ from pasture  p join  department d on  d.id = p.id join department d1 on d1.id =
 			}
 			fmt.Println(string(dataByte))
 			if vientianeResp.Code == 200 {
-				for _, eq := range eqList {
-					err := s.d.DB.Exec(` update equipment set pushStatus = 3  where id = ? `, eq.Equipment.Id).Error
-					if err != nil {
-						logs.Error(err)
-						return
-					}
-				}
+				//for _, eq := range eqList {
+				//	err := s.d.DB.Exec(` update equipment set pushStatus = 3  where id = ? `, eq.Equipment.Id).Error
+				//	if err != nil {
+				//		logs.Error(err)
+				//		return
+				//	}
+				//}
 				vientianeResp.Status = vientianeResp.Code
 			}
 			err = s.d.DB.Exec(` insert into vehiclelog(url,param,status,msgtext,resp)values(?,?,?,?,?) `, url, string(dataByte), vientianeResp.Status, vientianeResp.Msg, string(respByte)).Error
@@ -316,13 +336,13 @@ from pasture  p join  department d on  d.id = p.id join department d1 on d1.id =
 		}
 		fmt.Println(string(dataByte))
 		if vientianeResp.Code == 200 {
-			for _, eq := range eqList {
-				err := s.d.DB.Exec(` update equipment set pushStatus = 3  where id = ? `, eq.Equipment.Id).Error
-				if err != nil {
-					logs.Error(err)
-					return
-				}
-			}
+			//for _, eq := range eqList {
+			//	err := s.d.DB.Exec(` update equipment set pushStatus = 3  where id = ? `, eq.Equipment.Id).Error
+			//	if err != nil {
+			//		logs.Error(err)
+			//		return
+			//	}
+			//}
 			vientianeResp.Status = vientianeResp.Code
 		}
 
@@ -550,3 +570,82 @@ func (s *Service) GetVehicle(pastureId, startdate, enddate, eqCode, eqName, depa
 	resp.Count = count
 	return resp, err
 }
+
+func (s *Service) GetRunningRateDetail(date, pastureId, eqCode string, offset, pagecount int) ([]map[string]interface{}, error) {
+	dataList := make([]map[string]interface{}, 0)
+	eqList := make([]*model.EquipmentAndDepartment, 0)
+
+	err := s.d.DB.Raw(`select * from equipment e  join eqclass ec on ec.id = e.eqClassId  
+    join department d on d.id = e.departmentId where e.license is not null  and  e.license != ''  and e.pushStatus in(0,1,2)
+     and (e.pastureId = ? or ? = 18) and ( eqCode like concat('%',?,'%') or ? ='' ) limit ?,? `,
+		pastureId, pastureId, eqCode, eqCode, offset, pagecount).Find(&eqList).Error
+	if err != nil {
+		logs.Error(err)
+		return dataList, nil
+	}
+
+	vehicleList := make([]*liugong.Vehicle, 0)
+	var eqIdList []int
+	for _, eq := range eqList {
+		eqIdList = append(eqIdList, eq.Id)
+	}
+
+	err = s.d.DB.Debug().Table(new(liugong.Vehicle).TableName()).Select("pastureName,eqId,license,date_format(date ,'%Y-%m-%d') date,hour,duration").
+		Where(" date_format(date ,'%Y-%m') = ? ", date).Where(" eqId in (?) ", eqIdList).Find(&vehicleList).Error
+	if err != nil {
+		logs.Error(err)
+		return dataList, nil
+	}
+
+	now := time.Now()
+	var dateList []string
+
+	firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
+	nextMonthFirstDay := firstDay.AddDate(0, 1, 0)
+	lastDay := nextMonthFirstDay.Add(-24 * time.Hour)
+	for t := firstDay; !t.After(lastDay); t = t.AddDate(0, 0, 1) {
+		fmt.Println(t.Format("2006-01-02"))
+		dateList = append(dateList, t.Format("2006-01-02"))
+	}
+
+	num, err := strconv.Atoi(now.Format("02"))
+	if err != nil {
+		fmt.Printf("转换出错: %v\n", err)
+		return dataList, nil
+	}
+
+	for _, eq := range eqList {
+		data := make(map[string]interface{}, 0)
+		data["id"] = eq.Id
+		data["eqName"] = eq.EqName
+		data["eqCode"] = eq.EqCode
+		data["eqClassName"] = eq.EqClassName
+		data["duration"] = eq.Duration
+		data["license"] = eq.License
+		var hour float64
+		for i, date := range dateList {
+			data[fmt.Sprintf("%d", i+1)] = 0
+			for _, vehicle := range vehicleList {
+				if vehicle.EqId == fmt.Sprintf("%d", eq.Id) && vehicle.Date == date {
+					data["pastureName"] = vehicle.PastureName
+					data["license"] = vehicle.License
+					data[fmt.Sprintf("%d", i+1)] = vehicle.Hour
+					float64Value, err := strconv.ParseFloat(vehicle.Hour, 64)
+					if err != nil {
+						return nil, err
+					}
+					hour += float64Value
+				}
+			}
+		}
+
+		if hour > 0 && num > 0 && eq.Duration > 0 {
+			data["runningRate"] = util.Round(hour/float64(num*eq.Duration)*100, 2)
+		} else {
+			data["runningRate"] = 0
+		}
+		dataList = append(dataList, data)
+	}
+
+	return dataList, nil
+}

+ 124 - 18
apiserver/service/report.go

@@ -40,7 +40,8 @@ func MaintainList(pastureName, eqClassIdStr string, startTime, endTime time.Time
 
 	for _, eq := range eqList {
 		pastureMaintainList := make([]*model.Maintain, 0)
-		err := s.d.DB.Raw(` 	SELECT m.* FROM maintain m JOIN equipment e on e.id = m.eqId WHERE (e.eqClassId = ? or   ? = '')
+		err := s.d.DB.Raw(` 	SELECT m.*,(select DATE_FORMAT(bpu.creatDate,'%Y-%m-%d %H:%i:%s')  from bigpartapply  bp  join  bigpartuse bpu on bpu.oddCode = bp.applyCode     
+ where bp.RUCode =m.repairCode   order by bpu.creatDate desc  limit 1) creatDate  FROM maintain m JOIN equipment e on e.id = m.eqId WHERE (e.eqClassId = ? or   ? = '')
  and m.stopTime is not null and (m.pastureid = (select id from pasture where name = ? and name != '现代牧业') or ? = '现代牧业' ) 
   and m.stopTime between ? and ? 	and TIMESTAMPDIFF(hour, m.orderTime, m.stopTime) < 1000 order by requestTime,m.pastureid  `,
 			eq.EqClass.ID, eq.EqClass.ID, eq.Pasture.Name, eq.Pasture.Name, startTime, endTime).Find(&pastureMaintainList).Error
@@ -84,21 +85,56 @@ func MaintainList(pastureName, eqClassIdStr string, startTime, endTime time.Time
 						//记录下维修结束时间方便下次计算t1
 						stopTime = main.StopTime
 						orderTime = main.OrderTime
-						requestTime = main.RequestTime
+						//requestTime = main.RequestTime
 						//每个资产第一次都根据筛选开始时间计算出t1
 						t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-						t3 += main.StopTime.Sub(main.OrderTime).Hours()
+						if main.CreatDate == "" {
+							t3 += main.StopTime.Sub(main.OrderTime).Hours()
+							requestTime = main.RequestTime
+						} else {
+							layout := "2006-01-02 15:04:05"
+							t, err := time.Parse(layout, main.CreatDate)
+							if err != nil {
+								fmt.Println(err)
+								continue
+							}
+							tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+							if err != nil {
+								fmt.Println(err)
+								continue
+							}
+							t3 += tStop.Sub(t).Hours()
+							requestTime = t
+						}
+
 						//fmt.Println(main.StopTime, main.OrderTime, "111111")
 						//t1 += main.RequestTime.Sub(startTime).Minutes()
 					} else {
 						//t1 += main.RequestTime.Sub(stopTime).Minutes()
 						t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-						t3 += main.StopTime.Sub(main.OrderTime).Hours()
+						if main.CreatDate == "" {
+							t3 += main.StopTime.Sub(main.OrderTime).Hours()
+							requestTime = main.RequestTime
+						} else {
+							layout := "2006-01-02 15:04:05"
+							t, err := time.Parse(layout, main.CreatDate)
+							if err != nil {
+								fmt.Println(err)
+								continue
+							}
+							tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+							if err != nil {
+								fmt.Println(err)
+								continue
+							}
+							t3 += tStop.Sub(t).Hours()
+							requestTime = t
+						}
 						//fmt.Println(main.StopTime, main.OrderTime, "22222222")
 						//记录下维修结束时间方便下次计算t1
 						stopTime = main.StopTime
 						orderTime = main.OrderTime
-						requestTime = main.RequestTime
+
 					}
 				}
 				if stopTime.Format("2006") == "0001" {
@@ -436,7 +472,8 @@ func MaintainListPid(pastureName, eqClassId string, startTime, endTime time.Time
 			for _, eq := range eqClassList {
 
 				pastureMaintainList := make([]*model.Maintain, 0)
-				err = s.d.DB.Raw(` 	SELECT m.eqId,m.pastureId,m.requestTime,m.orderTime,m.stopTime FROM maintain m JOIN equipment e on e.id = m.eqId WHERE e.eqClassid = ? 
+				err = s.d.DB.Raw(` 	SELECT m.eqId,m.pastureId,m.requestTime,m.orderTime,m.stopTime,(select DATE_FORMAT(bpu.creatDate,'%Y-%m-%d %H:%i:%s')  from bigpartapply  bp  join  bigpartuse bpu on bpu.oddCode = bp.applyCode     
+ where bp.RUCode =m.repairCode   order by bpu.creatDate desc  limit 1) creatDate  FROM maintain m JOIN equipment e on e.id = m.eqId WHERE e.eqClassid = ? 
  and m.stopTime is not null and (m.pastureid = (select id from pasture where name = ? and name != '现代牧业') or ? = '现代牧业' or ?= '' ) 
   and m.stopTime between ? and ? 	and TIMESTAMPDIFF(hour, m.orderTime, m.stopTime) < 1000 order by requestTime,m.pastureid  `,
 					eq.ID, pastureName, pastureName, pastureName, startTime, endTime).Find(&pastureMaintainList).Error
@@ -474,21 +511,52 @@ func MaintainListPid(pastureName, eqClassId string, startTime, endTime time.Time
 								//记录下维修结束时间方便下次计算t1
 								stopTime = main.StopTime
 								orderTime = main.OrderTime
-								requestTime = main.RequestTime
-								//每个资产第一次都根据筛选开始时间计算出t1
 								t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-								t3 += main.StopTime.Sub(main.OrderTime).Hours()
+								if main.CreatDate == "" {
+									t3 += main.StopTime.Sub(main.OrderTime).Hours()
+									requestTime = main.RequestTime
+								} else {
+									layout := "2006-01-02 15:04:05"
+									t, err := time.Parse(layout, main.CreatDate)
+									if err != nil {
+										fmt.Println(err)
+										continue
+									}
+									tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+									if err != nil {
+										fmt.Println(err)
+										continue
+									}
+									t3 += tStop.Sub(t).Hours()
+									requestTime = t
+								}
 								//fmt.Println(main.StopTime, main.OrderTime, "111111")
 								//t1 += main.RequestTime.Sub(startTime).Minutes()
 							} else {
 								//t1 += main.RequestTime.Sub(stopTime).Minutes()
 								t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-								t3 += main.StopTime.Sub(main.OrderTime).Hours()
-								//fmt.Println(main.StopTime, main.OrderTime, "22222222")
+								if main.CreatDate == "" {
+									t3 += main.StopTime.Sub(main.OrderTime).Hours()
+									requestTime = main.RequestTime
+								} else {
+									layout := "2006-01-02 15:04:05"
+									t, err := time.Parse(layout, main.CreatDate)
+									if err != nil {
+										fmt.Println(err)
+										continue
+									}
+									tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+									if err != nil {
+										fmt.Println(err)
+										continue
+									}
+									t3 += tStop.Sub(t).Hours()
+									requestTime = t
+								}
 								//记录下维修结束时间方便下次计算t1
 								stopTime = main.StopTime
 								orderTime = main.OrderTime
-								requestTime = main.RequestTime
+								//requestTime = main.RequestTime
 							}
 						}
 						if stopTime.Format("2006") == "0001" {
@@ -666,7 +734,8 @@ func MaintainListPid(pastureName, eqClassId string, startTime, endTime time.Time
 
 func MaintainListEquipment(pastureName, eqClassId string, startTime, endTime time.Time, offset, pageSize int, eqName string) (int64, []map[string]interface{}, error) {
 	pastureMaintainList := make([]*model.Maintain, 0)
-	err := s.d.DB.Raw(` 	SELECT m.* FROM maintain m JOIN equipment e on e.id = m.eqId WHERE e.eqClassId = ? 
+	err := s.d.DB.Raw(` 	SELECT m.*,(select DATE_FORMAT(bpu.creatDate,'%Y-%m-%d %H:%i:%s')  from bigpartapply  bp  join  bigpartuse bpu on bpu.oddCode = bp.applyCode     
+ where bp.RUCode =m.repairCode   order by bpu.creatDate desc  limit 1) creatDate FROM maintain m JOIN equipment e on e.id = m.eqId WHERE e.eqClassId = ? 
  and m.stopTime is not null and (m.pastureid = (select id from pasture where name = ? and name != '现代牧业') or ? = '现代牧业' ) 
   and m.stopTime between ? and ? 	and TIMESTAMPDIFF(hour, m.orderTime, m.stopTime) < 1000 order by requestTime,m.pastureid  `,
 		eqClassId, pastureName, pastureName, startTime, endTime).Find(&pastureMaintainList).Error
@@ -704,7 +773,6 @@ func MaintainListEquipment(pastureName, eqClassId string, startTime, endTime tim
 		pastureId := strconv.Itoa(p.ID)
 		maintainList := maintainMap[pastureId]
 		//count := float64(len(maintainList))
-		var t2, t3 float64
 
 		mainMap := make(map[int64][]*model.Maintain, 0)
 		//将每个不同的资产分类放进map
@@ -719,6 +787,7 @@ func MaintainListEquipment(pastureName, eqClassId string, startTime, endTime tim
 		//for _, k := range eqIdList {
 
 		for _, eq := range eqList {
+			var t2, t3 float64
 			var stopTime, orderTime, requestTime time.Time
 			mainList := make([]*model.Maintain, 0)
 			if _, ok := mainMap[int64(eq.Id)]; ok {
@@ -730,21 +799,58 @@ func MaintainListEquipment(pastureName, eqClassId string, startTime, endTime tim
 					//记录下维修结束时间方便下次计算t1
 					stopTime = main.StopTime
 					orderTime = main.OrderTime
-					requestTime = main.RequestTime
+					//requestTime = main.RequestTime
 					//每个资产第一次都根据筛选开始时间计算出t1
 					t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-					t3 += main.StopTime.Sub(main.OrderTime).Hours()
+					if main.CreatDate == "" {
+						t3 += main.StopTime.Sub(main.OrderTime).Hours()
+						requestTime = main.RequestTime
+					} else {
+						layout := "2006-01-02 15:04:05"
+						t, err := time.Parse(layout, main.CreatDate)
+						if err != nil {
+							fmt.Println(err)
+							continue
+						}
+
+						tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+						if err != nil {
+							fmt.Println(err)
+							continue
+						}
+						t3 += tStop.Sub(t).Hours()
+						requestTime = t
+					}
 					//fmt.Println(main.StopTime, main.OrderTime, "111111")
 					//t1 += main.RequestTime.Sub(startTime).Minutes()
 				} else {
 					//t1 += main.RequestTime.Sub(stopTime).Minutes()
 					t2 += main.OrderTime.Sub(main.RequestTime).Hours()
-					t3 += main.StopTime.Sub(main.OrderTime).Hours()
+					if main.CreatDate == "" {
+						t3 += main.StopTime.Sub(main.OrderTime).Hours()
+						fmt.Println(main.StopTime.Sub(main.OrderTime).Hours())
+						requestTime = main.RequestTime
+					} else {
+						layout := "2006-01-02 15:04:05"
+						t, err := time.Parse(layout, main.CreatDate)
+						if err != nil {
+							fmt.Println(err)
+							continue
+						}
+						tStop, err := time.Parse(layout, main.StopTime.Format("2006-01-02 15:04:05"))
+						if err != nil {
+							fmt.Println(err)
+							continue
+						}
+						t3 += tStop.Sub(t).Hours()
+						fmt.Println(tStop.Sub(t).Hours())
+						requestTime = t
+					}
 					//fmt.Println(main.StopTime, main.OrderTime, "22222222")
 					//记录下维修结束时间方便下次计算t1
 					stopTime = main.StopTime
 					orderTime = main.OrderTime
-					requestTime = main.RequestTime
+					//requestTime = main.RequestTime
 				}
 			}
 			data := make(map[string]interface{}, 0)