|
@@ -9,8 +9,10 @@ package dao
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/go-xorm/xorm"
|
|
|
+ "go.mod/models"
|
|
|
"go.mod/web/viewmodels"
|
|
|
)
|
|
|
|
|
@@ -26,6 +28,26 @@ func NewSafeAuditDao(engine *xorm.Engine) *SafeAuditDao {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 添加审批人
|
|
|
+func (d *SafeAuditDao) AddAuditor(safeId int, bId int, auditId int, times int) error {
|
|
|
+ auditOrder := d.GetNewOrder(safeId, times)
|
|
|
+ auditor := &models.CmSafeAudit{SafeId: safeId, BidsectionId: bId, AuditId: auditId, Times: times, AuditOrder: auditOrder, CreateTime: time.Now()}
|
|
|
+ _, err := d.engine.InsertOne(auditor)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// 获取最新审批顺序
|
|
|
+func (d *SafeAuditDao) GetNewOrder(safeId int, times int) int {
|
|
|
+ var max_order int
|
|
|
+ _, err := d.engine.Sql("select Max(`audit_order`) as max_order from cm_safe_audit where safe_id = ? and times = ?", safeId, times).Get(&max_order)
|
|
|
+ fmt.Println(err)
|
|
|
+ if max_order == 0 {
|
|
|
+ return 1
|
|
|
+ } else {
|
|
|
+ return max_order + 1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 根据当前times,获取审批人(包括原报)
|
|
|
func (d *SafeAuditDao) GetAuditors(id int, times int, cur_uid int) []viewmodels.Auditors {
|
|
|
auditors := make([]viewmodels.Auditors, 0)
|
|
@@ -44,8 +66,13 @@ func (d *SafeAuditDao) GetAuditors(id int, times int, cur_uid int) []viewmodels.
|
|
|
return auditors
|
|
|
}
|
|
|
|
|
|
-// times从0开始循环,往history里面push
|
|
|
-// func (d *SafeAuditDao) GetAuditHistory(id int, times int) {
|
|
|
-// auditorHistory := make([]models.CmSafeAudit, 0)
|
|
|
-// 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)
|
|
|
-// }
|
|
|
+// times从1开始循环,往history里面push
|
|
|
+func (d *SafeAuditDao) GetAuditHistory(id int, times int) map[int][]viewmodels.HistorySafeAudit {
|
|
|
+ auditorHistory := make(map[int][]viewmodels.HistorySafeAudit, 0)
|
|
|
+ for i := 1; i <= times; i++ {
|
|
|
+ auditors := make([]viewmodels.HistorySafeAudit, 0)
|
|
|
+ d.engine.Sql("select pa.`name`, pa.`position`, ca.`create_time` as createTime, ca.`end_time` as endTime, 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 and times = ? order by `audit_order`", id, times).Find(&auditors)
|
|
|
+ auditorHistory[i] = auditors
|
|
|
+ }
|
|
|
+ return auditorHistory
|
|
|
+}
|