func (requireList *RequireList) Edit(name, newName string) (err error) { o := models.GetDB() err = o.Begin() //事务处理过程 _, SomeError := models.GetDB().QueryTable(models.TABLE_NAME_REQUIRE).Filter("name", name).Update(orm.Params{"name": newName}) _, SomeError = models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("type", name).Update(orm.Params{"type": newName}) _, SomeError = models.GetDB().QueryTable(models.TABLE_NAME_JOBHISTORY).Filter("type", name).Update(orm.Params{"type": newName}) if SomeError != nil { err = o.Rollback() } else { err = o.Commit() } return }
func CreateProgress() { d := []models.Progress{ models.Progress{ Id: 1, Name: "立项", }, models.Progress{ Id: 2, Name: "美术设计", }, models.Progress{ Id: 3, Name: "网站搭建", }, models.Progress{ Id: 4, Name: "制作完毕", }, models.Progress{ Id: 5, Name: "开通报名", }, models.Progress{ Id: 6, Name: "关闭报名", }, models.Progress{ Id: 7, Name: "照片下载(证书下载)", }, } num, err := models.GetDB().InsertMulti(1, d) log.Println("CreateProgress: num=%v, err=%v", num, err) }
//获取投诉列表 func GetComplainList(filter map[string]interface{}) (compalins []*models.JobComplaint, cnt int64, err error) { defer func() { if err != nil { utils.GetLog().Error("services.job.GetList : error : %s", err.Error()) } else { utils.GetLog().Debug("services.job.GetList : debug : filter=%s, compalints=%v", utils.Sdump(filter), utils.Sdump(compalins)) } }() q := models.GetDB().QueryTable("job_complaints").OrderBy("-created").RelatedSel("Job", "User", "Project", "Employee") //按照传入的条件进行过滤查询结果 for k, v := range filter { if k != "limit" && k != "offset" && v != "" { q = q.Filter(k, v) } } cnt, _ = q.Count() if filter["limit"] != nil { q = q.Limit(filter["limit"].(int)) } if filter["offset"] != nil { q = q.Offset(filter["offset"].(int)) } _, err = q.All(&compalins) return }
func (c *Creation) Do() (err error) { defer func() { if err != nil { utils.GetLog().Error("user.Creatin.Do : err = %v , obj = %s ", err, c) } }() if err = c.valid(); err != nil { return } c.password.GenSalt() c.password.GenPwd() u := models.User{ Name: c.name, Email: c.email.EmailAddress(), Password: c.password.Encryped(), Salt: c.password.Salt(), Company: &models.Company{Id: uint(c.companyId)}, Roles: c.roles.String(), LastLoginTime: time.Now(), } models.GetDB().Insert(&u) return }
func (jv *JobClaim) getJob() (err error) { err = models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", jv.jobId).RelatedSel("CreateUser").One(jv.job) if err != nil { return } return }
func (self *QueryFile) GetJobAllFiles() (jobFiles []*models.File, err error) { _, err = models.GetDB().Raw("SELECT f.id, f.url, f.name FROM "+models.TABLE_NAME_FILE+ " f join "+models.TABLE_NAME_JOBHISTORY+" h on f.rel_id=h.id join "+models.TABLE_NAME_JOB+ " j on j.id=h.job_id WHERE j.id = ? and f.type<3", self.conditions["rel_id"]).QueryRows(&jobFiles) return }
func NewUserWithId(id uint) (u *User, err error) { u = &User{ user: &models.User{Id: id}, } err = models.GetDB().QueryTable("users").Filter("id", id).RelatedSel().One(u.user) return }
func AddHistory(j *models.Job, user *models.User, isCreate bool) (jid uint, err error) { defer func() { if err != nil { utils.GetLog().Error("services.job.AddHistory : error : %s, ", err.Error()) } else { utils.GetLog().Debug("services.job.AddHistory : debug : Job=%s", utils.Sdump(j)) } }() var jh models.JobHistory jh.Job = j jh.IsCreate = isCreate jh.Code = j.Code jh.CreateUser = j.CreateUser jh.Project = j.Project jh.Employee = j.Employee jh.Type = j.Type jh.Department = j.Department jh.Target = j.Target jh.TargetUrl = j.TargetUrl jh.Desc = j.Desc jh.Message = j.Message jh.FinishTime = j.FinishTime jh.ValidTime = j.ValidTime jh.ClaimTime = j.ClaimTime jh.ValidStatus = j.ValidStatus jh.ClaimStatus = j.ClaimStatus jh.SubmitStatus = j.SubmitStatus var insertId int64 insertId, err = models.GetDB().Insert(&jh) jid = uint(insertId) return }
func (cp ComplaintCreator) GetToUser() (*models.User, error) { user := &models.User{} err := models.GetDB().QueryTable(models.TABLE_NAME_USER).Filter("id", cp.compliant.Employee.Id).One(user) if err != nil { return nil, err } return user, nil }
func (cp ComplaintCreator) GetComplaint(complaintId uint) (*models.JobComplaint, error) { complain := &models.JobComplaint{} err := models.GetDB().QueryTable(models.TABLE_NAME_JOBCOMPLAINT).Filter("id", complaintId).One(complain) if err != nil { return nil, err } return complain, nil }
func (cpr ComplaintReplytor) GetToUser() (*models.User, error) { user := &models.User{} err := models.GetDB().QueryTable(models.TABLE_NAME_USER).Filter("id", cpr.complain.User.Id).One(user) if err != nil { return nil, err } return user, nil }
func (joblist *JobList) GetUserName(employId uint) (*models.User, error) { user := &models.User{} err := models.GetDB().QueryTable(models.TABLE_NAME_USER).Filter("id", employId).One(user) if err != nil { return nil, err } return user, nil }
func (pl *ProjectList) GetAllProjectNames() ([]*models.Project, error) { _, err := models.GetDB().Raw("SELECT id, name FROM projects").QueryRows(&pl.projectList) if err != nil { return nil, err } return pl.projectList, nil }
func (ja *JobAssignment) getUser(userId uint) (*models.User, error) { user := &models.User{} err := models.GetDB().QueryTable(models.TABLE_NAME_USER).Filter("id", userId).One(user) if err != nil { return nil, err } return user, nil }
//根据 项目进程id ,获取process func (p *Project) GetProgressByID(id uint) (*models.Progress, error) { progress := &models.Progress{} err := models.GetDB().QueryTable(models.TABLE_NAME_PROGRESS).Filter("id", id).One(progress) if err != nil { return nil, err } return progress, nil }
//根据 ID 获取user func (p *Project) GetUserByID(id uint) (*models.User, error) { user := &models.User{} err := models.GetDB().QueryTable(models.TABLE_NAME_USER).Filter("id", id).One(user) if err != nil { return nil, err } return user, nil }
func (cp ComplaintReplytor) GetComplaintReply(replyId uint) (*models.JobComplaintReply, error) { complainReply := &models.JobComplaintReply{} err := models.GetDB().QueryTable(models.TABLE_NAME_JOBCOMPLAINTREPLY).Filter("id", replyId).One(complainReply) if err != nil { return nil, err } return complainReply, nil }
func (self *QueryFile) DelFile() (err error) { q := models.GetDB().QueryTable(models.TABLE_NAME_FILE) for k, v := range self.conditions { q = q.Filter(k, v) } _, err = q.Delete() return }
func (companyList *CompanyList) do() *CompanyList { var err error _, err = models.GetDB().QueryTable("companies").All(&companyList.companies) if err != nil { return companyList } return companyList }
func (pr *PasswordModify) updatePassword() error { pr.user.Salt = pr.newPwd.Salt() pr.user.Password = pr.newPwd.Encryped() affectedRowsNum, err := models.GetDB().Update(pr.user, "password", "salt") if affectedRowsNum < 1 || err != nil { return ErrUpdateNewPassword } return nil }
func (pl *ProjectList) GetList(filter map[string]interface{}) (projects []*models.Project, err error) { qs := models.GetDB().QueryTable("projects").RelatedSel("BussinessUser", "Progress", "ArtUser", "TechUser", "Registrant").OrderBy("-created").Filter("del_status", 0) for k, v := range filter { if !isKeyFitForFilter(k) { continue } if k == "start_date" { start, _ := time.Parse(timeFormat, v.(string)) qs = qs.Filter("started__gte", start) continue } if k == "end_date" { end, _ := time.Parse(timeFormat, v.(string)) qs = qs.Filter("started__lte", end) continue } qs = qs.Filter(k, v) } if filter["user"] != nil { cond := orm.NewCondition() cond1 := cond.And("tech_user_id", filter["user"]).Or("art_user_id", filter["user"]).Or("registrant", filter["user"]).Or("bussiness_user_id", filter["user"]) qs = qs.SetCond(cond1) } count, err := qs.Count() if err != nil { return nil, err } pl.count = count if filter["limit"] != nil { qs = qs.Limit(filter["limit"].(int)) } if filter["offset"] != nil { qs = qs.Offset(filter["offset"].(int)) } _, err = qs.All(&pl.projectList) if err != nil { return nil, err } // err = setProjectListJobsNum(pl.projectList) if err != nil { return nil, err } return pl.projectList, nil }
func createJobProgress(jobid int, pt progress.ProgressType, desc string, tableName string, pk int) { p := models.JobProgress{ JobId: uint(jobid), ProgressType: uint(pt), Desc: desc, EventTableName: tableName, PrimaryKey: uint(pk), } models.GetDB().Insert(&p) }
func (jv *JobClaim) updateJobStatus() (err error) { q := models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", jv.jobId) newData := orm.Params{ "claim_time": time.Now(), "claim_status": jv.jobClaim.Status, "submit_status": models.Job_Submit_None, "Code": job.NewJobCode(jv.job.Code, jv.user.Company.Code, job.JobCode_NoneModify).GetCode(), } _, err = q.Update(newData) return err }
func (js *JobSubmit) submit() (submitId uint, err error) { if js.getJob() != nil { return } var jc models.JobSubmit jc.Job = js.job jc.Status = uint8(js.mapJob["Status"].(int)) jc.Remark = js.mapJob["Remark"].(string) jc.ProduceUser = js.user q := models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", js.jobId) newData := orm.Params{ "submit_status": jc.Status, } var codeType uint8 = job.JobCode_NoneModify if jc.Status == models.Job_Submit_Wait_Acceptance { newData["submit_time"] = time.Now() if js.job.SubmitStatus == models.Job_Submit_Acceptance_Refuse { codeType = job.JobCode_ProduceModify } } else if jc.Status == models.Job_Submit_Acceptance_OK { newData["acceptance_time"] = time.Now() } newData["Code"] = job.NewJobCode(js.job.Code, js.user.Company.Code, codeType).GetCode() _, err = q.Update(newData) var insertId int64 insertId, err = models.GetDB().Insert(&jc) if err != nil { utils.GetLog().Debug("services.job.Submit : debug : jobSubmit=%s", utils.Sdump(jc)) return } submitId = uint(insertId) return }
func (jv *JobModify) getJob() error { switch v := jv.mapJob["Id"].(type) { case int: jv.jobId = uint(v) case string: tmp, _ := strconv.Atoi(v) jv.jobId = uint(tmp) } err := models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", jv.jobId).RelatedSel("Employee", "CreateUser").One(jv.job) return err }
func (jv *JobClaim) insertJobClaim() (err error) { jv.jobClaim.Status = uint8(jv.mapJob["Status"].(int)) jv.jobClaim.Remark = jv.mapJob["Remark"].(string) jv.jobClaim.ClaimUser = jv.user jv.jobClaim.Job = &models.Job{Id: jv.jobId} _, err = models.GetDB().Insert(jv.jobClaim) if err != nil { utils.GetLog().Debug("services.job.Claim : debug : jobClaim=%s", utils.Sdump(jv.jobClaim)) return } return }
func (userList *UserList) do() *UserList { if userList.isDo { return userList } userList.isDo = true var err error defer func() { if err != nil { utils.GetLog().Error("services.user.GetList : error : %s", err.Error()) } else { utils.GetLog().Debug("services.user.GetList : debug : users=%v", utils.Sdump(userList.users)) } }() q := models.GetDB().QueryTable("users").RelatedSel("Company") if !userList.includeDel { q = q.Filter("deleted__isnull", true) } for k, v := range userList.filter { if k != "limit" && k != "offset" && v != "" { q = q.Filter(k, v) } else if k == "limit" { limit := v.(int) if limit < 0 { limit = 10 } q = q.Limit(limit) } else if k == "offset" { limit := userList.filter["limit"].(int) if limit < 0 { limit = 10 } offset := v.(int) if offset > 0 { offset = (offset - 1) * limit } q = q.Offset(offset) } } userList.count, _ = q.Count() _, err = q.All(&userList.users) if err != nil { return userList } return userList }
func (jv *JobValidation) updateJobHistory() (err error) { if jv.jobValidation.Job.ValidStatus != models.Job_Valid_OK { return } finishTime, _ := jv.getFinishTime() params := orm.Params{ "finish_time": finishTime, } _, err = models.GetDB().QueryTable(models.TABLE_NAME_JOBHISTORY).Filter("job_id", jv.jobId).Update(params) return }
func (ja *JobAssignment) getJob() (*models.Job, error) { if ja.job != nil { return ja.job, nil } ja.job = &models.Job{} err := models.GetDB().QueryTable(models.TABLE_NAME_JOB).Filter("id", ja.jobId).RelatedSel("CreateUser").One(ja.job) if err != nil { return nil, err } return ja.job, nil }
func CreateProjects() { d := models.Project{ Name: "宝马项目", Scale: 100, Priority: 1, ClientName: "xh", Started: time.Now(), BussinessUser: &models.User{Id: 2}, ArtUser: &models.User{Id: 5}, TechUser: &models.User{Id: 4}, Registrant: &models.User{Id: 1}, Progress: &models.Progress{Id: 1}, GameDate: time.Now(), RegStartDate: time.Now(), RegCloseDate: time.Now(), } num, err := models.GetDB().Insert(&d) d1 := models.Project{ Name: "官网项目", Scale: 100, Priority: 1, ClientName: "gw", Started: time.Now(), BussinessUser: &models.User{Id: 3}, ArtUser: &models.User{Id: 5}, TechUser: &models.User{Id: 4}, Registrant: &models.User{Id: 1}, Progress: &models.Progress{Id: 1}, GameDate: time.Now(), RegStartDate: time.Now(), RegCloseDate: time.Now(), } num, err = models.GetDB().Insert(&d1) log.Println("CreateProjects: num=%v, err=%v", num, err) }