|
@@ -12,6 +12,8 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-xorm/xorm"
|
|
|
+ "go.mod/comm"
|
|
|
+ "go.mod/conf"
|
|
|
"go.mod/models"
|
|
|
"go.mod/web/viewmodels"
|
|
|
)
|
|
@@ -48,8 +50,15 @@ func (d *SafeAuditDao) GetNewOrder(safeId int, times int) int {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 根据当前times,获取审批人
|
|
|
+func (d *SafeAuditDao) GetAuditors(id int, times int) []viewmodels.Auditors {
|
|
|
+ auditors := make([]viewmodels.Auditors, 0)
|
|
|
+ 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)
|
|
|
+ return auditors
|
|
|
+}
|
|
|
+
|
|
|
// 根据当前times,获取审批人(包括原报)
|
|
|
-func (d *SafeAuditDao) GetAuditors(id int, times int, cur_uid int) []viewmodels.Auditors {
|
|
|
+func (d *SafeAuditDao) GetAuditorsWithOwner(id int, times int, cur_uid int) []viewmodels.Auditors {
|
|
|
auditors := make([]viewmodels.Auditors, 0)
|
|
|
|
|
|
// 原报
|
|
@@ -71,8 +80,74 @@ func (d *SafeAuditDao) GetAuditHistory(id int, times int) map[int][]viewmodels.H
|
|
|
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
|
|
|
+ d.engine.Sql("select ca.`id`, 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)
|
|
|
+ auditorsArr := make([]viewmodels.HistorySafeAudit, 0)
|
|
|
+ for _, auditor := range auditors {
|
|
|
+ auditorVM := viewmodels.HistorySafeAudit{}
|
|
|
+ id, _ := comm.AesEncrypt(auditor.Id, conf.SignSecret)
|
|
|
+ auditorVM.Id = id
|
|
|
+ auditorVM.Createtime = auditor.Createtime
|
|
|
+ auditorVM.EndTime = auditor.EndTime
|
|
|
+ auditorVM.Name = auditor.Name
|
|
|
+ auditorVM.Position = auditor.Position
|
|
|
+ auditorVM.Status = auditor.Status
|
|
|
+ auditorVM.Opinion = auditor.Opinion
|
|
|
+ auditorsArr = append(auditorsArr, auditorVM)
|
|
|
+ }
|
|
|
+ auditorHistory[i] = auditorsArr
|
|
|
}
|
|
|
return auditorHistory
|
|
|
}
|
|
|
+
|
|
|
+// 根据id获取记录
|
|
|
+func (d *SafeAuditDao) FindById(id int) (*models.CmSafeAudit, error) {
|
|
|
+ data := &models.CmSafeAudit{Id: id}
|
|
|
+ _, err := d.engine.Get(data)
|
|
|
+ return data, err
|
|
|
+}
|
|
|
+
|
|
|
+// 改变审批记录状态
|
|
|
+func (d *SafeAuditDao) ChangeStatusById(id int, opinion string, status int) error {
|
|
|
+ data := &models.CmSafeAudit{EndTime: time.Now(), Opinion: opinion, Status: status}
|
|
|
+ _, err := d.engine.ID(id).Cols("end_time", "opinion", "status").Update(data)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+// 拷贝新的审批流程
|
|
|
+func (d *SafeAuditDao) CopyAuditors(safeId int, times int, auditType string, uid int) error {
|
|
|
+ oldAuditors := make([]models.CmSafeAudit, 0)
|
|
|
+ err := d.engine.Where("safe_id = ? and times = ?", safeId, times).Find(&oldAuditors)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ var copyStatus = true
|
|
|
+ fmt.Println("auditType", auditType)
|
|
|
+ newAuditors := make([]models.CmSafeAudit, 0)
|
|
|
+ for _, auditor := range oldAuditors {
|
|
|
+ auditorVM := models.CmSafeAudit{}
|
|
|
+ auditorVM.SafeId = auditor.SafeId
|
|
|
+ auditorVM.BidsectionId = auditor.BidsectionId
|
|
|
+ auditorVM.Times = auditor.Times + 1
|
|
|
+ auditorVM.AuditId = auditor.AuditId
|
|
|
+ auditorVM.AuditOrder = auditor.AuditOrder
|
|
|
+ auditorVM.Progress = auditor.Progress
|
|
|
+ auditorVM.CreateTime = time.Now()
|
|
|
+ auditorVM.Status = auditor.Status
|
|
|
+ // 上报人
|
|
|
+ if auditType == "uncheck" {
|
|
|
+ auditorVM.Status = 0
|
|
|
+ } else {
|
|
|
+ if auditor.AuditId == uid {
|
|
|
+ auditorVM.Status = 0
|
|
|
+ copyStatus = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !copyStatus {
|
|
|
+ auditorVM.Status = 0
|
|
|
+ }
|
|
|
+ newAuditors = append(newAuditors, auditorVM)
|
|
|
+ }
|
|
|
+ _, err = d.engine.Insert(&newAuditors)
|
|
|
+ return err
|
|
|
+}
|