Beispiel #1
0
func (jv *JobValidForm) validFinishTime() error {
	//如果审核不通过, 则不作判断
	if jv.Result != 1 {
		return nil
	}

	finishTime, err := utils.FormatTime(jv.FinishTime)
	if err != nil {
		return fmt.Errorf("finisht_time数据错误, %s", jv.FinishTime)
	}

	requiredFinishTime, err := utils.FormatTime(jv.RequiredFinishTime)
	if err != nil {
		return fmt.Errorf("job_required_finisht_time数据错误, %s", jv.RequiredFinishTime)
	}

	if finishTime.After(requiredFinishTime) {
		return fmt.Errorf("要求完成时间必须小于作业完成时间, %s, %s", jv.FinishTime, jv.RequiredFinishTime)
	}

	if finishTime.Before(time.Now()) {
		return fmt.Errorf("要求完成时间必须大于当前时间, %s", jv.FinishTime)
	}

	return nil
}
Beispiel #2
0
func (self *PiDownloader) formatOutput(tasks []map[string]interface{}) (string, error) {
	if tasks == nil || len(tasks) == 0 {
		return "no records", nil
	}

	var buffer bytes.Buffer
	buffer.WriteString("\n")
	for _, task := range tasks {
		gid := task["gid"].(string)
		buffer.WriteString(fmt.Sprintf("gid: %s\n", gid))

		title := self.getTitle(task)
		buffer.WriteString(fmt.Sprintf("title: %s\n", title))

		dSpd := task["downloadSpeed"]
		if dSpd != nil {
			speed := utils.FormatSizeString(dSpd.(string))
			buffer.WriteString(fmt.Sprintf("spd: %s\n", speed))
		}

		total, _ := strconv.ParseFloat(task["totalLength"].(string), 64)
		totalFmt := utils.FormatSize(int64(total))
		buffer.WriteString(fmt.Sprintf("total: %s\n", totalFmt))

		completed, _ := strconv.ParseFloat(task["completedLength"].(string), 64)
		buffer.WriteString(fmt.Sprintf("prog: %.2f%%\n", completed*100/total))

		if dSpd != nil {
			spd, _ := strconv.Atoi(dSpd.(string))
			var timeLeftFmt string
			if spd == 0 {
				timeLeftFmt = "N/A"
			} else {
				timeLeft := int64(total-completed) / int64(spd)
				timeLeftFmt = utils.FormatTime(timeLeft)
			}
			buffer.WriteString(fmt.Sprintf("tiemleft: %s\n", timeLeftFmt))
		}

		status := task["status"]
		if status != nil {
			buffer.WriteString(fmt.Sprintf("status: %s\n", status.(string)))
		}

		errorCode := task["errorCode"]
		if status != nil {
			buffer.WriteString(fmt.Sprintf("statusCode: %s\n", errorCode.(string)))
		}
		buffer.WriteString("==================\n")
	}
	return buffer.String(), nil
}
Beispiel #3
0
func (self *PiDownloader) getCurrentDownloadInfo() (string, error) {
	globalStat, getStatErr := aria2rpc.GetGlobalStat()
	if getStatErr != nil {
		return "", getStatErr
	}
	// total active download task
	numActive, _ := strconv.Atoi(globalStat["numActive"].(string))
	if numActive == 0 {
		return "no active task", nil
	}

	// total speed
	speed := utils.FormatSizeString(globalStat["downloadSpeed"].(string))

	// the longest left time in active download task
	var longestTimeLeft int64 = -1
	keys := []string{"gid", "totalLength", "completedLength", "downloadSpeed"}
	tasks, getActErr := aria2rpc.GetActive(keys)
	if getActErr != nil {
		return "", getActErr
	}
	for _, task := range tasks {
		dSpd := task["downloadSpeed"]
		if dSpd != nil {
			total, _ := strconv.ParseInt(task["totalLength"].(string), 10, 64)
			completed, _ := strconv.ParseInt(task["completedLength"].(string), 10, 64)
			spd, _ := strconv.ParseInt(dSpd.(string), 10, 64)
			if spd > 0 {
				timeLeft := (total - completed) / spd
				if timeLeft > longestTimeLeft {
					longestTimeLeft = timeLeft
				}
			}
		}
	}

	var timeLeftFmt string
	if longestTimeLeft > 0 {
		timeLeftFmt = utils.FormatTime(longestTimeLeft)
	} else {
		timeLeftFmt = "N/A"
	}
	return fmt.Sprintf("spd: %s ; act: %d ; left: %s", speed, numActive, timeLeftFmt), nil
}
Beispiel #4
0
func (jv *JobModify) update() (modifyId uint, err error) {
	if jv.getJob() != nil {
		return
	}

	q := models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", jv.jobId)

	newData := orm.Params{"claim_status": models.Job_Claim_None}

	// 审核未通过,编辑修改
	if jv.job.ValidStatus == models.Job_Valid_Refuse {
		newData["valid_status"] = models.Job_Valid_None
	}

	for k, v := range jv.mapJob {
		if k == "FinishTime" {
			finishTime, _ := utils.FormatTime(jv.mapJob["FinishTime"].(string))
			newData[utils.SepSplitName(k, "")] = finishTime
		} else {
			newData[utils.SepSplitName(k, "")] = v
		}
	}
	newData["Code"] = NewJobCode(jv.job.Code, jv.user.Company.Code, jv.codeType).GetCode()
	_, err = q.Update(newData)

	if err != nil {
		return
	}

	err = jv.getJob()
	if err == nil {

		modifyId, _ = AddHistory(jv.job, jv.user, false)
	}
	return
}
Beispiel #5
0
func (p *Project) Update(data map[string]interface{}) (err error) {
	defer func() {
		if err != nil {
			utils.GetLog().Error("project.Project.Update : error : %s", err.Error())

		} else {
			utils.GetLog().Debug("project.Project.Update : debug : %s", utils.Sdump(p))
		}
	}()

	Orm := orm.NewOrm()
	err = Orm.Begin()
	if err != nil {
		return

	}

	var projectLogs []models.ProjectLog
	//project_id, _ := strconv.Atoi(data["id"].(string))
	//p.project.Id = uint(project_id)

	p.project.Registrant = &models.User{Id: data["registrant"].(uint)}

	if p.project.Name != data["name"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.NAME, p.project.Name, data["name"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.Name = data["name"].(string)

	}

	scale, _ := strconv.Atoi(data["scale"].(string))
	if p.project.Scale != uint(scale) {

		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.SCALE, strconv.Itoa(int(p.project.Scale)), data["scale"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.Scale = uint(scale)

	}

	priority, _ := strconv.Atoi(data["priority"].(string))

	if p.project.Priority != uint(priority) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.PRIORITY, strconv.Itoa(int(p.project.Priority)), data["priority"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.Priority = uint(priority)

	}

	if p.project.ClientName != data["clientName"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.CLIENT_NAME, p.project.ClientName, data["clientName"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.ClientName = data["clientName"].(string)

	}
	if p.project.ContractNo != data["contractNo"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.CONRACT_NO, p.project.ContractNo, data["contractNo"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.ContractNo = data["contractNo"].(string)
	}
	if p.project.ServiceItem != data["serviceItem"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.SERVICE_ITEM, p.project.ServiceItem, data["serviceItem"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.ServiceItem = data["serviceItem"].(string)
	}

	gameDate, err := utils.FormatTime(data["gameDate"].(string))
	if p.project.GameDate.Format("2006-01-02 15:04") != data["gameDate"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.GAME_DATE, p.project.GameDate.Format("2006-01-02 15:04"), data["gameDate"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.GameDate = gameDate

	}

	regStartDate, err := utils.FormatTime(data["regStartDate"].(string))
	if p.project.RegStartDate.Format("2006-01-02 15:04") != data["regStartDate"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.REG_START_DATE, p.project.RegStartDate.Format("2006-01-02 15:04"), data["regStartDate"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.RegStartDate = regStartDate

	}

	regCloseDate, err := utils.FormatTime(data["regCloseDate"].(string))
	if p.project.RegCloseDate.Format("2006-01-02 15:04") != data["regCloseDate"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.REG_CLOSE_DATA, p.project.RegCloseDate.Format("2006-01-02 15:04"), data["regCloseDate"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.RegCloseDate = regCloseDate

	}

	progress, _ := strconv.Atoi(data["progress"].(string))
	if p.project.Progress.Id != uint(progress) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.PROGRESS, strconv.Itoa(int(p.project.Progress.Id)), data["progress"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.Progress = &models.Progress{Id: uint(progress)}

	}

	bussinessUserId, _ := strconv.Atoi(data["bussinessUser"].(string))
	if p.project.BussinessUser.Id != uint(bussinessUserId) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.BUSSINESS_USER, strconv.Itoa(int(p.project.BussinessUser.Id)), data["bussinessUser"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.BussinessUser = &models.User{Id: uint(bussinessUserId)}

	}

	artUserId, _ := strconv.Atoi(data["artUser"].(string))
	if p.project.ArtUser.Id != uint(artUserId) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.ART_USER_ID, strconv.Itoa(int(p.project.ArtUser.Id)), data["artUser"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.ArtUser = &models.User{Id: uint(artUserId)}

	}

	techUserId, _ := strconv.Atoi(data["techUser"].(string))
	if p.project.TechUser.Id != uint(techUserId) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.TECH_USER_ID, strconv.Itoa(int(p.project.TechUser.Id)), data["techUser"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.TechUser = &models.User{Id: uint(techUserId)}

	}

	started, err := utils.FormatTime(data["started"].(string))
	if p.project.Started.Format("2006-01-02 15:04") != data["started"].(string) {
		projectLog := models.GetProjectLogForEdit(p.project.Id, data["registrant"].(uint)).SetColumn(models.STARTED, p.project.Started.Format("2006-01-02 15:04"), data["started"].(string))
		projectLogs = append(projectLogs, *projectLog)
		p.project.Started = started

	}

	p.project.Updated = time.Now().Local()
	utils.GetLog().Debug("p.project= %s", utils.Sdump(p.project))
	err = p.CheckData()
	if err != nil {
		return

	}
	_, err = Orm.Update(p.project)
	if err != nil {
		err1 := Orm.Rollback()
		if err1 != nil {
			return err1

		}
		return err

	}

	_, err = Orm.InsertMulti(1, projectLogs)
	if err != nil {
		err1 := Orm.Rollback()
		if err1 != nil {
			return err1

		}
		return err

	}

	err = Orm.Commit()
	if err != nil {
		return

	}

	return

}
Beispiel #6
0
func (p *Project) Create(data map[string]interface{}) (err error, projectId int64) {
	defer func() {
		if err != nil {
			utils.GetLog().Error("project.Project.Create : error : %s", err.Error())
		} else {
			utils.GetLog().Debug("project.Project.Create : debug : %s", utils.Sdump(p))
		}

	}()

	Orm := orm.NewOrm()
	err = Orm.Begin()
	if err != nil {
		return
	}

	p.project.Name = data["name"].(string)

	priority, _ := strconv.Atoi(data["priority"].(string))
	p.project.Priority = uint(priority)

	progress, _ := strconv.Atoi(data["progress"].(string))
	p.project.Progress = &models.Progress{Id: uint(progress)}

	scale, _ := strconv.Atoi(data["scale"].(string))
	p.project.Scale = uint(scale)

	p.project.ClientName = data["clientName"].(string)
	p.project.ContractNo = data["contractNo"].(string)
	p.project.ServiceItem = data["serviceItem"].(string)

	p.project.GameDate, err = utils.FormatTime(data["gameDate"].(string))

	p.project.RegStartDate, err = utils.FormatTime(data["regStartDate"].(string))
	p.project.RegCloseDate, err = utils.FormatTime(data["regCloseDate"].(string))
	bussinessUserId, _ := strconv.Atoi(data["bussinessUser"].(string))
	p.project.BussinessUser = &models.User{Id: uint(bussinessUserId)}

	//registrant, _ := strconv.Atoi(data["registrant"].(string))
	p.project.Registrant = &models.User{Id: data["registrant"].(uint)}

	artUserId, _ := strconv.Atoi(data["artUser"].(string))
	p.project.ArtUser = &models.User{Id: uint(artUserId)}
	techUserId, _ := strconv.Atoi(data["techUser"].(string))
	p.project.TechUser = &models.User{Id: uint(techUserId)}

	p.project.Started, err = utils.FormatTime(data["started"].(string))

	p.project.Created = time.Now().Local()

	err = p.CheckData()
	if err != nil {
		return
	}

	projectId, err = Orm.Insert(p.project)
	if err != nil {
		err1 := Orm.Rollback()
		if err1 != nil {
			return err1, projectId
		}
		return err, projectId
	}

	var projectLog models.ProjectLog
	projectLog.Project = &models.Project{Id: uint(projectId)}
	projectLog.User = &models.User{Id: data["registrant"].(uint)}
	projectLog.Operation = models.CREATE

	_, err = Orm.Insert(&projectLog)
	if err != nil {
		fmt.Println(err)
		err1 := Orm.Rollback()
		if err1 != nil {
			return err1, projectId
		}
		return err, projectId
	}

	err = Orm.Commit()
	if err != nil {
		return
	}

	//emial notifier
	if err = p.sendEmailNotifier(); err != nil {
		return
	}

	return
}
Beispiel #7
0
func (jv *JobValidation) getFinishTime() (time.Time, error) {
	return utils.FormatTime(jv.finishTime)
}