|
@@ -33,8 +33,11 @@ func NewApproverDao(engine *xorm.Engine) *ApproverDao {
|
|
|
}
|
|
|
|
|
|
// 批量插入数据
|
|
|
-func (d *ApproverDao) InsertData(bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error {
|
|
|
+func (d *ApproverDao) InsertData(cur_uid int, bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error {
|
|
|
data := make([]models.CmApprover, 0)
|
|
|
+ msg := make([]models.CmProjectMessage, 0)
|
|
|
+
|
|
|
+ _, err := d.engine.Exec("delete from project_message where data_type = ? and data_id = ?", dataType, dataId)
|
|
|
for i, item := range auditors {
|
|
|
approverVM := models.CmApprover{}
|
|
|
approverVM.AuditId = item
|
|
@@ -49,6 +52,17 @@ func (d *ApproverDao) InsertData(bid int, pid int, dataType int, dataId int, aud
|
|
|
approverVM.Status = 1
|
|
|
}
|
|
|
data = append(data, approverVM)
|
|
|
+
|
|
|
+ // 消息推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item
|
|
|
+ msgVM.BidsectionId = bid
|
|
|
+ msgVM.ProjectId = pid
|
|
|
+ msgVM.DataId = dataId
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "已上报,审批中"
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msg = append(msg, msgVM)
|
|
|
}
|
|
|
checkVM := models.CmApprover{}
|
|
|
checkVM.AuditOrder = len(auditors) + 1
|
|
@@ -68,8 +82,31 @@ func (d *ApproverDao) InsertData(bid int, pid int, dataType int, dataId int, aud
|
|
|
approverVM.DataType = dataType
|
|
|
approverVM.DataId = dataId
|
|
|
data = append(data, approverVM)
|
|
|
+
|
|
|
+ // 消息推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item
|
|
|
+ msgVM.BidsectionId = bid
|
|
|
+ msgVM.ProjectId = pid
|
|
|
+ msgVM.DataId = dataId
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "已上报,审批中"
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msg = append(msg, msgVM)
|
|
|
}
|
|
|
- _, err := d.engine.Insert(data)
|
|
|
+ // 再推送自己
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = cur_uid
|
|
|
+ msgVM.BidsectionId = bid
|
|
|
+ msgVM.ProjectId = pid
|
|
|
+ msgVM.DataId = dataId
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "已上报,审批中"
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+ _, err = d.engine.Insert(data)
|
|
|
+ _, err = d.engine.Insert(msg)
|
|
|
+
|
|
|
return err
|
|
|
}
|
|
|
|
|
@@ -159,6 +196,31 @@ func (d *ApproverDao) InitStatus(auditType string, bid int, dataType int, dataId
|
|
|
return errors.New("操作失败-db")
|
|
|
}
|
|
|
|
|
|
+ // 消息推送,先删除旧的推送
|
|
|
+ _, err = session.Exec("delete from cm_project_message where data_type = ? and data_id = ?", auditType, dataId)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ approvers := make([]models.CmApprover, 0)
|
|
|
+ err = session.Where("data_type = ? and data_id = ? and audit_id != 0", dataType, dataId).Find(&approvers)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ msg := make([]models.CmProjectMessage, 0)
|
|
|
+ for _, item := range approvers {
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item.AuditId
|
|
|
+ msgVM.BidsectionId = item.BidsectionId
|
|
|
+ msgVM.ProjectId = item.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = item.DataId
|
|
|
+ msgVM.DataType = item.DataType
|
|
|
+ msgVM.Content = "审批退回到上报人"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+ }
|
|
|
+
|
|
|
data := &models.CmApprover{Status: 0}
|
|
|
_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ?", bid, dataType, dataId).Cols("status").Update(data)
|
|
|
if err != nil {
|
|
@@ -166,6 +228,24 @@ func (d *ApproverDao) InitStatus(auditType string, bid int, dataType int, dataId
|
|
|
return err
|
|
|
}
|
|
|
if auditType == "safe" {
|
|
|
+ safe := &models.CmSafe{}
|
|
|
+ _, err = session.ID(dataId).Get(safe)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = safe.Uid
|
|
|
+ msgVM.BidsectionId = safe.BidsectionId
|
|
|
+ msgVM.ProjectId = safe.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = safe.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "审批退回到上报人"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
_, err = session.Exec("update cm_safe set status = ?, times = ? where id = ?", 0, times+1, dataId)
|
|
|
if err != nil {
|
|
|
session.Rollback()
|
|
@@ -183,6 +263,24 @@ func (d *ApproverDao) InitStatus(auditType string, bid int, dataType int, dataId
|
|
|
_, err = session.Exec("update cm_tree set safe_rectification = safe_rectification + 1, safe_rectification_in = if(safe_rectification_in >= 1, safe_rectification_in - 1, 0) where bidsection_id = ?", bid)
|
|
|
}
|
|
|
} else {
|
|
|
+ quality := &models.CmQuality{}
|
|
|
+ _, err = session.ID(dataId).Get(quality)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = quality.Uid
|
|
|
+ msgVM.BidsectionId = quality.BidsectionId
|
|
|
+ msgVM.ProjectId = quality.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = quality.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "审批退回到上报人"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
_, err = session.Exec("update cm_quality set status = ?, times = ? where id = ?", 0, times+1, dataId)
|
|
|
if err != nil {
|
|
|
session.Rollback()
|
|
@@ -199,6 +297,13 @@ func (d *ApproverDao) InitStatus(auditType string, bid int, dataType int, dataId
|
|
|
_, err = session.Exec("update cm_tree set quality_rectification = quality_rectification + 1, quality_rectification_in = if(quality_rectification_in >= 1, quality_rectification_in - 1, 0) where bidsection_id = ?", bid)
|
|
|
}
|
|
|
}
|
|
|
+ // 插入消息
|
|
|
+ _, err = session.Insert(msg)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
err = session.Commit()
|
|
|
return err
|
|
|
}
|
|
@@ -216,6 +321,41 @@ func (d *ApproverDao) PassHandler(auditType string, id int, uid int, auditId int
|
|
|
if auditor.AuditId != uid {
|
|
|
return errors.New("该用户没有审批权限!")
|
|
|
}
|
|
|
+
|
|
|
+ var msgContent string
|
|
|
+ switch auditor.Progress {
|
|
|
+ case 0:
|
|
|
+ msgContent = "审批完成,待整改"
|
|
|
+ case 1:
|
|
|
+ msgContent = "整改完成,待复查"
|
|
|
+ case 2:
|
|
|
+ msgContent = "复查完成"
|
|
|
+ }
|
|
|
+ // 消息推送,先删除旧的推送
|
|
|
+ _, err = session.Exec("delete from cm_project_message where data_type = ? and data_id = ?", auditor.DataType, auditor.DataId)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ approvers := make([]models.CmApprover, 0)
|
|
|
+ err = session.Where("data_type = ? and data_id = ? and audit_id != 0", auditor.DataType, auditor.DataId).Find(&approvers)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ msg := make([]models.CmProjectMessage, 0)
|
|
|
+ for _, item := range approvers {
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item.AuditId
|
|
|
+ msgVM.BidsectionId = item.BidsectionId
|
|
|
+ msgVM.ProjectId = item.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = item.DataId
|
|
|
+ msgVM.DataType = item.DataType
|
|
|
+ msgVM.Content = msgContent
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+ }
|
|
|
+
|
|
|
// 安全巡检
|
|
|
if auditType == "safe" {
|
|
|
safe := &models.CmSafe{}
|
|
@@ -224,6 +364,17 @@ func (d *ApproverDao) PassHandler(auditType string, id int, uid int, auditId int
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = safe.Uid
|
|
|
+ msgVM.BidsectionId = safe.BidsectionId
|
|
|
+ msgVM.ProjectId = safe.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = safe.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = msgContent
|
|
|
+ msg = append(msg, msgVM)
|
|
|
// 增加审批日志
|
|
|
auditReacord := &models.CmSafeAudit{BidsectionId: auditor.BidsectionId, SafeId: auditor.DataId, AuditId: auditor.AuditId, Times: safe.Times, CreateTime: time.Now(), Status: 0, Progress: auditor.Progress + 1, Opinion: opinion, Rectifiedinfo: rectifiedInfo}
|
|
|
_, err = session.Insert(auditReacord)
|
|
@@ -307,6 +458,18 @@ func (d *ApproverDao) PassHandler(auditType string, id int, uid int, auditId int
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = quality.Uid
|
|
|
+ msgVM.BidsectionId = quality.BidsectionId
|
|
|
+ msgVM.ProjectId = quality.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = quality.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = msgContent
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
// 增加审批日志
|
|
|
auditReacord := &models.CmQualityAudit{BidsectionId: auditor.BidsectionId, QualityId: auditor.DataId, AuditId: auditor.AuditId, Times: quality.Times, CreateTime: time.Now(), Status: 0, Progress: auditor.Progress + 1, Opinion: opinion, Rectifiedinfo: rectifiedInfo}
|
|
|
_, err = session.Insert(auditReacord)
|
|
@@ -384,6 +547,12 @@ func (d *ApproverDao) PassHandler(auditType string, id int, uid int, auditId int
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 插入消息
|
|
|
+ _, err = session.Insert(msg)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
err = session.Commit()
|
|
|
return err
|
|
|
}
|
|
@@ -409,8 +578,58 @@ func (d *ApproverDao) BackHandlerWithId(auditType string, id int, uid int, times
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 消息推送,先删除旧的推送
|
|
|
+ _, err = session.Exec("delete from cm_project_message where data_type = ? and data_id = ?", auditor.DataType, auditor.DataId)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ approvers := make([]models.CmApprover, 0)
|
|
|
+ err = session.Where("data_type = ? and data_id = ? and audit_id != 0", auditor.DataType, auditor.DataId).Find(&approvers)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ msg := make([]models.CmProjectMessage, 0)
|
|
|
+ account := &models.CmProjectAccount{Id: auditor.AuditId}
|
|
|
+ _, err = session.Get(account)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, item := range approvers {
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item.AuditId
|
|
|
+ msgVM.BidsectionId = item.BidsectionId
|
|
|
+ msgVM.ProjectId = item.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = item.DataId
|
|
|
+ msgVM.DataType = item.DataType
|
|
|
+ msgVM.Content = "审批退回,退回至" + account.Name
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+ }
|
|
|
+
|
|
|
// 增加审批日志
|
|
|
if auditType == "safe" {
|
|
|
+ safe := &models.CmSafe{}
|
|
|
+ _, err = session.ID(auditor.DataId).Get(safe)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = safe.Uid
|
|
|
+ msgVM.BidsectionId = safe.BidsectionId
|
|
|
+ msgVM.ProjectId = safe.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = safe.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "审批退回,退回至" + account.Name
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
safeAudit := &models.CmSafeAudit{BidsectionId: auditor.BidsectionId, SafeId: auditor.DataId, Times: times, AuditId: uid, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion}
|
|
|
_, err = session.Insert(safeAudit)
|
|
|
if err != nil {
|
|
@@ -418,6 +637,23 @@ func (d *ApproverDao) BackHandlerWithId(auditType string, id int, uid int, times
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
+ quality := &models.CmQuality{}
|
|
|
+ _, err = session.ID(auditor.DataId).Get(quality)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = quality.Uid
|
|
|
+ msgVM.BidsectionId = quality.BidsectionId
|
|
|
+ msgVM.ProjectId = quality.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = quality.Id
|
|
|
+ msgVM.DataType = 2
|
|
|
+ msgVM.Content = "审批退回,退回至" + account.Name
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
qualityAudit := &models.CmQualityAudit{BidsectionId: auditor.BidsectionId, QualityId: auditor.DataId, Times: times, AuditId: uid, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion}
|
|
|
_, err = session.Insert(qualityAudit)
|
|
|
if err != nil {
|
|
@@ -445,6 +681,12 @@ func (d *ApproverDao) BackHandlerWithId(auditType string, id int, uid int, times
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
+ // 插入消息
|
|
|
+ _, err = session.Insert(msg)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
err = session.Commit()
|
|
|
return err
|
|
|
}
|
|
@@ -458,6 +700,32 @@ func (d *ApproverDao) CloseHandler(auditType string, id int, opinion string, cur
|
|
|
if auditor.AuditId != curUid {
|
|
|
return errors.New("该用户没有审批权限!")
|
|
|
}
|
|
|
+
|
|
|
+ // 消息推送,先删除旧的推送
|
|
|
+ _, err = session.Exec("delete from cm_project_message where data_type = ? and data_id = ?", auditor.DataType, auditor.DataId)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ approvers := make([]models.CmApprover, 0)
|
|
|
+ err = session.Where("data_type = ? and data_id = ? and audit_id != 0", auditor.DataType, auditor.DataId).Find(&approvers)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ msg := make([]models.CmProjectMessage, 0)
|
|
|
+ for _, item := range approvers {
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = item.AuditId
|
|
|
+ msgVM.BidsectionId = item.BidsectionId
|
|
|
+ msgVM.ProjectId = item.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = item.DataId
|
|
|
+ msgVM.DataType = item.DataType
|
|
|
+ msgVM.Content = "已关闭,停止审批流程"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+ }
|
|
|
+
|
|
|
if auditType == "safe" {
|
|
|
safe := &models.CmSafe{}
|
|
|
_, err = session.ID(saveId).Get(safe)
|
|
@@ -465,6 +733,18 @@ func (d *ApproverDao) CloseHandler(auditType string, id int, opinion string, cur
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = safe.Uid
|
|
|
+ msgVM.BidsectionId = safe.BidsectionId
|
|
|
+ msgVM.ProjectId = safe.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = safe.Id
|
|
|
+ msgVM.DataType = 1
|
|
|
+ msgVM.Content = "已关闭,停止审批流程"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
// 增加审批日志
|
|
|
safeAudit := &models.CmSafeAudit{BidsectionId: auditor.BidsectionId, SafeId: auditor.DataId, Times: safe.Times, AuditId: auditor.AuditId, Status: 2, Progress: auditor.Progress, CreateTime: time.Now(), Opinion: opinion}
|
|
|
_, err = session.Insert(safeAudit)
|
|
@@ -485,6 +765,18 @@ func (d *ApproverDao) CloseHandler(auditType string, id int, opinion string, cur
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 添加巡检拥有者的推送
|
|
|
+ msgVM := models.CmProjectMessage{}
|
|
|
+ msgVM.AccountId = quality.Uid
|
|
|
+ msgVM.BidsectionId = quality.BidsectionId
|
|
|
+ msgVM.ProjectId = quality.ProjectId
|
|
|
+ msgVM.CreateTime = time.Now()
|
|
|
+ msgVM.DataId = quality.Id
|
|
|
+ msgVM.DataType = 2
|
|
|
+ msgVM.Content = "已关闭,停止审批流程"
|
|
|
+ msg = append(msg, msgVM)
|
|
|
+
|
|
|
// 增加审批日志
|
|
|
qualityAudit := &models.CmQualityAudit{BidsectionId: auditor.BidsectionId, QualityId: auditor.DataId, Times: quality.Times, AuditId: auditor.AuditId, Status: 2, Progress: auditor.Progress, CreateTime: time.Now(), Opinion: opinion}
|
|
|
_, err = session.Insert(qualityAudit)
|
|
@@ -505,6 +797,14 @@ func (d *ApproverDao) CloseHandler(auditType string, id int, opinion string, cur
|
|
|
session.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+ // 插入消息
|
|
|
+ _, err = session.Insert(msg)
|
|
|
+ if err != nil {
|
|
|
+ session.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = session.Commit()
|
|
|
return err
|
|
|
}
|
|
|
|