|
|
@ -8,6 +8,7 @@ import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"xorm.io/core" |
|
|
@ -231,10 +232,20 @@ func (t *PmWo) SelectPmWoAll(nowdate string) ([]PmWoDate, error) { |
|
|
|
} |
|
|
|
|
|
|
|
//分页
|
|
|
|
func (t *PmWo) GetPage(pageSize int, pageIndex int, searchtime string, mainttype string) ([]PmWoService, int, error) { |
|
|
|
func (t *PmWo) GetPage(pageSize int, pageIndex int, searchtime string, mainttype string, userId string) ([]PmWoService, int, error) { |
|
|
|
data := make([]PmWoService, 0) |
|
|
|
|
|
|
|
e := db.Eloquent.Master() |
|
|
|
assetIdLi := make([]int, 0) |
|
|
|
err := e.Table("PM_UserAssetLst").Where("UserId = ?", userId).Cols("AssetId").Find(&assetIdLi) |
|
|
|
if err != nil { |
|
|
|
return data, 0, err |
|
|
|
} |
|
|
|
serviceIdLi := make([]int, 0) |
|
|
|
err = e.Table("PM_UserServiceLst").Where("UserId = ?", userId).Cols("MainServiceId").Find(&serviceIdLi) |
|
|
|
if err != nil { |
|
|
|
return data, 0, err |
|
|
|
} |
|
|
|
where := `from pm_wo left join pm_service on pm_wo.finr = pm_service.finr and pm_wo.mainservicenr = pm_service.mainserviceid` |
|
|
|
where += " where pm_wo.finr = ? " |
|
|
|
parameters := []interface{}{t.Finr} |
|
|
@ -242,7 +253,6 @@ func (t *PmWo) GetPage(pageSize int, pageIndex int, searchtime string, mainttype |
|
|
|
query := e.Table(t.TableName()) |
|
|
|
table = table.Join("LEFT", "pm_service", "pm_wo.finr = pm_service.finr and pm_wo.mainservicenr = pm_service.mainserviceid") |
|
|
|
|
|
|
|
|
|
|
|
if !utils.ValueIsEmpty(searchtime) { |
|
|
|
searchtimes := strings.Split(searchtime, "-") |
|
|
|
table = table.And("pm_wo.credatuz >= ?", searchtimes[0]) |
|
|
@ -270,11 +280,41 @@ func (t *PmWo) GetPage(pageSize int, pageIndex int, searchtime string, mainttype |
|
|
|
where += " and pm_wo.mainttype = ? " |
|
|
|
parameters = append(parameters, mainttype) |
|
|
|
} |
|
|
|
table = table.In("pm_wo.assetid", assetIdLi) |
|
|
|
table = table.In("pm_wo.mainservicenr", serviceIdLi) |
|
|
|
if len(assetIdLi) > 0{ |
|
|
|
inAssetStr := "(" |
|
|
|
for index, assetId := range assetIdLi { |
|
|
|
inAssetStr += strconv.Itoa(assetId) |
|
|
|
if index != len(assetIdLi)-1 { |
|
|
|
inAssetStr += "," |
|
|
|
} |
|
|
|
} |
|
|
|
inAssetStr += ")" |
|
|
|
where = where + " and pm_wo.assetid in " + inAssetStr + " " |
|
|
|
} else { |
|
|
|
where += " and 1 = 2 " |
|
|
|
} |
|
|
|
if len(serviceIdLi) > 0 { |
|
|
|
inServiceStr := "(" |
|
|
|
for index, serviceId := range serviceIdLi { |
|
|
|
inServiceStr += strconv.Itoa(serviceId) |
|
|
|
if index != len(serviceIdLi)-1 { |
|
|
|
inServiceStr += "," |
|
|
|
} |
|
|
|
} |
|
|
|
inServiceStr += ")" |
|
|
|
where = where + " and pm_wo.mainservicenr in " + inServiceStr + " " |
|
|
|
} else { |
|
|
|
where += " and 1 = 2 " |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
orderBy := " order by pm_wo.finr " |
|
|
|
offset := (pageIndex - 1) * pageSize |
|
|
|
querySql := `select pm_wo.*,pm_service.* ` + where + orderBy +" offset ? row fetch next ? row only" |
|
|
|
querySql := `select pm_wo.*,pm_service.* ` + where + orderBy + " offset ? row fetch next ? row only" |
|
|
|
parameters = append(parameters, offset, pageSize) |
|
|
|
err := query.SQL(querySql, parameters...).Find(&data) |
|
|
|
err = query.SQL(querySql, parameters...).Find(&data) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("err:", err) |
|
|
|
return data, 0, err |
|
|
@ -437,12 +477,12 @@ func doSth(ctx context.Context) { |
|
|
|
time2, _ := utils.TimeParseyyyyMMdd(t2) |
|
|
|
timelen := int(time1.Unix()) - int(time2.Unix()) |
|
|
|
timeunit := task.PmService.Duedateinterval |
|
|
|
glog.InfoExtln("维护工单A","Mainservicenr:", task.PmService.Mainserviceid) |
|
|
|
glog.InfoExtln("维护工单A","t1:", t1) |
|
|
|
glog.InfoExtln("维护工单A","t2:", task.PmService.Duedateon) |
|
|
|
glog.InfoExtln("维护工单A","timelen:", timelen) |
|
|
|
glog.InfoExtln("维护工单A","timeunit:", timeunit) |
|
|
|
glog.InfoExtln("维护工单A","res:", ((timelen / 86400) % timeunit)) |
|
|
|
glog.InfoExtln("维护工单A", "Mainservicenr:", task.PmService.Mainserviceid) |
|
|
|
glog.InfoExtln("维护工单A", "t1:", t1) |
|
|
|
glog.InfoExtln("维护工单A", "t2:", task.PmService.Duedateon) |
|
|
|
glog.InfoExtln("维护工单A", "timelen:", timelen) |
|
|
|
glog.InfoExtln("维护工单A", "timeunit:", timeunit) |
|
|
|
glog.InfoExtln("维护工单A", "res:", ((timelen / 86400) % timeunit)) |
|
|
|
if res := ((timelen / 86400) % timeunit); res == 0 { |
|
|
|
|
|
|
|
//判断是否已经生成了维护工单,如果生成了,跳过
|
|
|
@ -451,7 +491,7 @@ func doSth(ctx context.Context) { |
|
|
|
pms.Mainservicenr = task.PmService.Mainserviceid |
|
|
|
tem, err := pms.SelectPmWoOne() |
|
|
|
if err != nil { |
|
|
|
glog.InfoExtln("维护工单A","tem.Mainservicenr:", tem.Mainservicenr) |
|
|
|
glog.InfoExtln("维护工单A", "tem.Mainservicenr:", tem.Mainservicenr) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
@ -463,8 +503,8 @@ func doSth(ctx context.Context) { |
|
|
|
|
|
|
|
if nowtime.Before(endtime) { |
|
|
|
//处理逻辑
|
|
|
|
glog.InfoExtln("维护工单A","nowtime:", nowtime) |
|
|
|
glog.InfoExtln("维护工单A","endtime:", endtime) |
|
|
|
glog.InfoExtln("维护工单A", "nowtime:", nowtime) |
|
|
|
glog.InfoExtln("维护工单A", "endtime:", endtime) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
@ -837,4 +877,3 @@ func doSth(ctx context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|