lanjianrong 4 éve
szülő
commit
e9fe82bd64

+ 130 - 5
dao/approver_dao.go

@@ -165,13 +165,13 @@ func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int, auditId int,
 		session.Rollback()
 		return err
 	}
-	_, err = session.Exec("update cm_safe set status = ? where id = ?", 0, dataId)
+	_, err = session.Exec("update cm_safe set status = ?, times = ? where id = ?", 0, times+1, dataId)
 	if err != nil {
 		session.Rollback()
 		return err
 	}
 	// 增加审批日志
-	safeAudit := &models.CmSafeAudit{BidsectionId: bid, SafeId: dataId, Times: times, AuditId: auditId, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion}
+	safeAudit := &models.CmSafeAudit{BidsectionId: bid, SafeId: dataId, Times: times, AuditId: auditId, Status: 1, Progress: 0, CreateTime: time.Now(), Opinion: opinion}
 	_, err = session.Insert(safeAudit)
 	if err != nil {
 		session.Rollback()
@@ -184,13 +184,100 @@ func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int, auditId int,
 	return nil
 }
 
-// 审批流程-退回
-func (d *ApproverDao) BackHandlerWithId(id int, cur_audit int, times int, progress int, opinion string) error {
+// 审批通过
+func (d *ApproverDao) PassHandler(id int, uid int, auditId int, opinion string, rectifiedInfo string) error {
 	session := d.engine.NewSession()
 	defer session.Close()
 	// add Begin() before any action
 	err := session.Begin()
 	auditor, err := d.FindApproverById(id)
+	if err != nil {
+		return err
+	}
+	if auditor.AuditId != uid {
+		return errors.New("该用户没有审批权限!")
+	}
+	safe := &models.CmSafe{}
+	_, err = session.ID(auditor.DataId).Get(safe)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	// 增加审批日志
+	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)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	// 改变审批流程中当前审批人以及下一个审批人的审批流程状态
+	curData := &models.CmApprover{Status: 2}
+	_, err = session.ID(id).Cols("status").Update(curData)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	nextData := &models.CmApprover{Status: 1}
+	_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order = ?", auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder+1).Cols("status").Update(nextData)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	if auditId != 0 {
+		// 审批人选择了整改人
+		// 修改cm_safe表的status状态为待整改
+		_, err = session.Exec("update `cm_safe` set status = ? where id = ?", 2, auditor.DataId)
+		if err != nil {
+			session.Rollback()
+			return err
+		}
+		// 改变审批流程中的整改人id
+		_, err = session.Exec("update `cm_approver` set `audit_id` = ? where `bidsection_id` = ? and `data_type` = ? and `data_id` = ? and `audit_order` = ?", auditId, auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder+1)
+		if err != nil {
+			session.Rollback()
+			return err
+		}
+	} else {
+		if auditor.Progress == 1 {
+			// 整改人审批流程
+			// 修改cm_safe表的status状态为待复查
+			_, err = session.Exec("update `cm_safe` set status = ? where id = ?", 3, auditor.DataId)
+			if err != nil {
+				session.Rollback()
+				return err
+			}
+		} else {
+			// 复查流程
+			// 查找最后一个审批人
+			lastAuditor := &models.CmApprover{BidsectionId: auditor.BidsectionId, DataType: auditor.DataType, DataId: auditor.DataId}
+			_, err = session.Desc("audit_order").Limit(1).Get(lastAuditor)
+			if err != nil {
+				session.Rollback()
+				return err
+			}
+			if lastAuditor.AuditId == auditor.AuditId {
+				// 说明审批流程已经走完
+				_, err = session.Exec("update `cm_safe` set status = ? where id = ?", 4, auditor.DataId)
+				if err != nil {
+					session.Rollback()
+					return err
+				}
+			}
+		}
+	}
+	err = session.Commit()
+	return err
+}
+
+// 审批流程-退回
+func (d *ApproverDao) BackHandlerWithId(id int, uid int, times int, progress int, opinion string) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	// add Begin() before any action
+	err := session.Begin()
+	// auditor, err := d.FindApproverById(id)
+	auditor := &models.CmApprover{}
+	_, err = session.ID(id).Get(auditor)
 	data := &models.CmApprover{Status: 0}
 	// 将往后的所有记录的status改为0
 	_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order > ?", auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder).Cols("status").Update(data)
@@ -206,12 +293,50 @@ func (d *ApproverDao) BackHandlerWithId(id int, cur_audit int, times int, progre
 		return err
 	}
 	// 增加审批日志
-	safeAudit := &models.CmSafeAudit{BidsectionId: auditor.BidsectionId, SafeId: auditor.DataId, Times: times, AuditId: cur_audit, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion}
+	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 {
 		session.Rollback()
 		return err
 	}
+	err = session.Commit()
+	return err
+}
+
+func (d *ApproverDao) CloseHandler(id int, opinion string, curUid int, saveId int) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	// add Begin() before any action
+	err := session.Begin()
+	auditor, err := d.FindApproverById(id)
+	if auditor.AuditId != curUid {
+		return errors.New("该用户没有审批权限!")
+	}
+	safe := &models.CmSafe{}
+	_, err = session.ID(saveId).Get(safe)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	// 增加审批日志
+	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)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	// 更改cm_safe的记录
+	_, err = session.Exec("update `cm_safe` set status = ? where id = ? ", 5, saveId)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	// 更改cm_approver的记录
+	_, err = session.Exec("update `cm_approver` set status = ? where id = ? ", 3, id)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
 	return err
 }
 

+ 2 - 2
dao/safe_audit_dao.go

@@ -54,7 +54,7 @@ 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 ca.`id`, pa.`name`, pa.`position`, ca.`create_time`, ca.`end_time`, ca.`progress`, 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 `id` desc", id, i).Find(&auditors)
+		d.engine.Sql("select ca.`id`, pa.`name`, pa.`position`, ca.`create_time`, ca.progress, 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 id desc", id, i).Find(&auditors)
 		auditorsArr := make([]viewmodels.HistorySafeAudit, 0)
 		for _, auditor := range auditors {
 			auditorVM := viewmodels.HistorySafeAudit{}
@@ -83,7 +83,7 @@ func (d *SafeAuditDao) FindById(id int) (*models.CmSafeAudit, error) {
 // 查找最新的整改单
 func (d *SafeAuditDao) GetLastedOrder(safeId int) ([]viewmodels.CheckOrderVM, error) {
 	data := make([]viewmodels.CheckOrderVM, 0)
-	err := d.engine.Sql("select cm.`opinion`, cm.`status`, cm.`end_time`, pa.`name` from `cm_safe_audit` as cm left join `cm_project_account` as pa on pa.`id` = cm.`audit_id` where cm.`safe_id` = ? and cm.`progress` = ?", safeId, 1).Find(&data)
+	err := d.engine.Sql("select cm.`rectifiedInfo` as opinion, cm.`create_time`, pa.`name` from `cm_safe_audit` as cm left join `cm_project_account` as pa on pa.`id` = cm.`audit_id` where cm.`safe_id` = ? and cm.`progress` = ?", safeId, 2).Find(&data)
 	return data, err
 }
 

+ 55 - 55
services/safe_audit.service.go

@@ -51,18 +51,20 @@ func NewSafeAuditService() SafeAuditService {
 
 // 关闭审批流程
 func (s *safeAuditService) CloseAudit(id int, opinion string, curUid int, saveId int) error {
-	auditor, err := s.daoApprover.FindApproverById(id)
-	if auditor.AuditId != curUid {
-		return errors.New("该用户没有审批权限!")
-	}
-	safe := s.daoSafe.FindById(auditor.DataId)
-	// 增加审批日志记录
-	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 2, auditor.Progress, opinion, "")
-	// 更改cm_safe的记录
-	err = s.daoSafe.ChangeStatus(saveId, 5)
-	// 更改cm_approver的记录
-	err = s.daoApprover.ChangeStatus(id, 3)
+	err := s.daoApprover.CloseHandler(id, opinion, curUid, saveId)
 	return err
+	// auditor, err := s.daoApprover.FindApproverById(id)
+	// if auditor.AuditId != curUid {
+	// 	return errors.New("该用户没有审批权限!")
+	// }
+	// safe := s.daoSafe.FindById(auditor.DataId)
+	// // 增加审批日志记录
+	// err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 2, auditor.Progress, opinion, "")
+	// // 更改cm_safe的记录
+	// err = s.daoSafe.ChangeStatus(saveId, 5)
+	// // 更改cm_approver的记录
+	// err = s.daoApprover.ChangeStatus(id, 3)
+	// return err
 }
 
 // 审批退回
@@ -72,11 +74,6 @@ func (s *safeAuditService) BackAudit(id int, opinion string, curUid int, saveId
 		return errors.New("该用户没有审批权限!")
 	}
 	safe := s.daoSafe.FindById(saveId)
-	// 增加审批日志
-	// err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 1, auditor.Progress, opinion, "")
-	// if err != nil {
-	// 	return err
-	// }
 
 	// 退回到了检查人
 	if auditId == 0 {
@@ -84,7 +81,7 @@ func (s *safeAuditService) BackAudit(id int, opinion string, curUid int, saveId
 		err = s.daoApprover.InitStatus(auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditId, safe.Times, auditor.Progress+1, opinion)
 	} else {
 		// 退回到审批流程中的某一个人
-		err = s.daoApprover.BackHandlerWithId(auditId, id, safe.Times, auditor.Progress+1, opinion)
+		err = s.daoApprover.BackHandlerWithId(auditId, auditor.AuditId, safe.Times, auditor.Progress+1, opinion)
 	}
 	return err
 
@@ -92,45 +89,48 @@ func (s *safeAuditService) BackAudit(id int, opinion string, curUid int, saveId
 
 // 审批通过
 func (s *safeAuditService) PassAudit(id int, uid int, auditId int, opinion string, rectifiedInfo string) error {
-	auditor, err := s.daoApprover.FindApproverById(id)
-	if err != nil {
-		return err
-	}
-	// 获取安全巡检记录
-	safe := s.daoSafe.FindById(auditor.DataId)
-	if auditor.AuditId != uid {
-		return errors.New("该用户没有审批权限!")
-	}
-	// 增加审批日志
-	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 0, auditor.Progress+1, opinion, rectifiedInfo)
-	// 改变审批流程中当前审批人以及下一个审批人的审批流程状态
-	err = s.daoApprover.ChangeStatus(id, 2)
-	err = s.daoApprover.ChangeNextStatus(id, 1)
-	// 审批人选择了整改人
-	if auditId != 0 {
-		// 修改cm_safe表的status状态为待整改
-		err = s.daoSafe.ChangeStatus(auditor.DataId, 2)
-		// 改变审批流程中的整改人id
-		err = s.daoApprover.ChangeAuditId(auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder+1, auditId)
-	} else {
-		if auditor.Progress == 1 {
-			// 整改人审批流程
-			// 修改cm_safe表的status状态为待复查
-			err = s.daoSafe.ChangeStatus(auditor.DataId, 3)
-		} else {
-			// 复查流程
-			// 查找最后一个审批人
-			lastAuditor, err := s.daoApprover.GetLastAuditor(auditor.BidsectionId, auditor.DataType, auditor.DataId)
-			if err != nil {
-				return err
-			}
-			if lastAuditor.AuditId == auditor.AuditId {
-				// 说明审批流程已经走完
-				err = s.daoSafe.ChangeStatus(auditor.DataId, 4)
-			}
-		}
-	}
+	err := s.daoApprover.PassHandler(id, uid, auditId, opinion, rectifiedInfo)
 	return err
+	// auditor, err := s.daoApprover.FindApproverById(id)
+	// if err != nil {
+	// 	return err
+	// }
+	// // 获取安全巡检记录
+	// safe := s.daoSafe.FindById(auditor.DataId)
+	// if auditor.AuditId != uid {
+	// 	return errors.New("该用户没有审批权限!")
+	// }
+
+	// err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 0, auditor.Progress+1, opinion, rectifiedInfo)
+
+	// err = s.daoApprover.ChangeStatus(id, 2)
+	// err = s.daoApprover.ChangeNextStatus(id, 1)
+	// // 审批人选择了整改人
+	// if auditId != 0 {
+	// 	// 修改cm_safe表的status状态为待整改
+	// 	err = s.daoSafe.ChangeStatus(auditor.DataId, 2)
+	// 	// 改变审批流程中的整改人id
+	// 	err = s.daoApprover.ChangeAuditId(auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder+1, auditId)
+	// } else {
+	// 	if auditor.Progress == 1 {
+	// 		// 整改人审批流程
+	// 		// 修改cm_safe表的status状态为待复查
+	// 		err = s.daoSafe.ChangeStatus(auditor.DataId, 3)
+	// 	} else {
+	// 		// 复查流程
+	// 		// 查找最后一个审批人
+	// 		lastAuditor, err := s.daoApprover.GetLastAuditor(auditor.BidsectionId, auditor.DataType, auditor.DataId)
+	// 		if err != nil {
+	// 			return err
+	// 		}
+	// 		if lastAuditor.AuditId == auditor.AuditId {
+	// 			// 说明审批流程已经走完
+	// 			err = s.daoSafe.ChangeStatus(auditor.DataId, 4)
+	// 		}
+	// 	}
+	// }
+
+	// return err
 }
 
 func (s *safeAuditService) StartAudit(safeId int, bidsectionId int, auditors []int, reAuditors []int, uid int, pid int) error {

+ 1 - 1
web/api/safe_audit_api.go

@@ -157,7 +157,7 @@ func (c *SafeAuditApi) PostBack() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
-	// 2.获取审批记录id
+	// 2.获取当前审批流程id
 	id, err := utils.GetDecryptId(safeAuditData.Id)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})

+ 3 - 5
web/viewmodels/safe_audit.go

@@ -32,7 +32,6 @@ type HistorySafeAudit struct {
 	Name       string    `from:"name" json:"name"`
 	Position   string    `from:"position" json:"position"`
 	CreateTime time.Time `from:"create_time" json:"create_time"`
-	EndTime    time.Time `from:"end_time" json:"end_time"`
 	Opinion    string    `from:"opinion" json:"opinion"`
 	Status     int       `from:"status" json:"status"`
 	Progress   string    `from:"progress" json:"progress"`
@@ -47,10 +46,9 @@ type LatestAuditorVM struct {
 
 // 整改单
 type CheckOrderVM struct {
-	Name    string    `from:"name" json:"name"`
-	EndTime time.Time `from:"end_time" json:"end_time"`
-	Opinion string    `from:"opinion" json:"opinion"`
-	Status  int       `from:"status" json:"status"`
+	Name       string    `from:"name" json:"name"`
+	CreateTime time.Time `from:"create_time" json:"create_time"`
+	Opinion    string    `from:"opinion" json:"opinion"`
 }
 
 func (l SafeAudit) ValidateAddAuditor() error {