safe_audit_dao.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * @description: 安全巡检数据库操作相关
  3. * @Author: LanJianRong
  4. * @Date: 2020-11-20
  5. * @FilePath: \construction_management\dao\safe_dao.go
  6. */
  7. package dao
  8. import (
  9. "fmt"
  10. "github.com/go-xorm/xorm"
  11. "go.mod/web/viewmodels"
  12. )
  13. //数据库操作引擎
  14. type SafeAuditDao struct {
  15. engine *xorm.Engine
  16. }
  17. //获得一个DAO对象
  18. func NewSafeAuditDao(engine *xorm.Engine) *SafeAuditDao {
  19. return &SafeAuditDao{
  20. engine: engine,
  21. }
  22. }
  23. // 根据当前times,获取审批人(包括原报)
  24. func (d *SafeAuditDao) GetAuditors(id int, times int, cur_uid int) []viewmodels.Auditors {
  25. auditors := make([]viewmodels.Auditors, 0)
  26. // 原报
  27. auditor := viewmodels.Auditors{}
  28. _, err := d.engine.Sql("select `name` from `cm_project_account` where id = ?", cur_uid).Get(&auditor)
  29. if err != nil {
  30. fmt.Println(err)
  31. }
  32. auditors = append(auditors, auditor)
  33. d.engine.Sql("select pa.`name` from `cm_project_account` as pa, `cm_safe_audit` as ca where ca.`safe_id` = ? and ca.`times` = ? and ca.audit_id = pa.id order by `audit_order`", id, times).Find(&auditors)
  34. return auditors
  35. }
  36. // times从0开始循环,往history里面push
  37. // func (d *SafeAuditDao) GetAuditHistory(id int, times int) {
  38. // auditorHistory := make([]models.CmSafeAudit, 0)
  39. // d.engine.Sql("select pa.`name`, pa.`position`,ca.`create_time`, ca.`end_time`, ca.`opinion`, ca.`status`, from `cm_project_account` as pa, `cm_safe_audit` as ca where ca.`safe_id` = ? and ca.audit_id = pa.id order by `audit_order`", id, times).Find(&auditors)
  40. // }