|  | @@ -185,7 +185,7 @@ func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int, auditId int,
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 审批通过
 | 
	
		
			
				|  |  | -func (d *ApproverDao) PassHandler(id int, uid int, auditId int, opinion string, rectifiedInfo string) error {
 | 
	
		
			
				|  |  | +func (d *ApproverDao) PassHandler(auditType string, id int, uid int, auditId int, opinion string, rectifiedInfo string) error {
 | 
	
		
			
				|  |  |  	session := d.engine.NewSession()
 | 
	
		
			
				|  |  |  	defer session.Close()
 | 
	
		
			
				|  |  |  	// add Begin() before any action
 | 
	
	
		
			
				|  | @@ -197,74 +197,174 @@ func (d *ApproverDao) PassHandler(id int, uid int, auditId int, opinion string,
 | 
	
		
			
				|  |  |  	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 auditType == "safe" {
 | 
	
		
			
				|  |  | +		safe := &models.CmSafe{}
 | 
	
		
			
				|  |  | +		_, err = session.ID(auditor.DataId).Get(safe)
 | 
	
		
			
				|  |  |  		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)
 | 
	
		
			
				|  |  | +		// 增加审批日志
 | 
	
		
			
				|  |  | +		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
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -	} else {
 | 
	
		
			
				|  |  | -		if auditor.Progress == 1 {
 | 
	
		
			
				|  |  | -			// 整改人审批流程
 | 
	
		
			
				|  |  | -			// 修改cm_safe表的status状态为待复查
 | 
	
		
			
				|  |  | -			_, err = session.Exec("update `cm_safe` set status = ? where id = ?", 3, auditor.DataId)
 | 
	
		
			
				|  |  | +		// 改变审批流程中当前审批人以及下一个审批人的审批流程状态
 | 
	
		
			
				|  |  | +		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
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			// 将cm_tree的safe_rectification待整改+1
 | 
	
		
			
				|  |  | +			_, err := session.Exec("update cm_tree set safe_rectification_in = safe_rectification_in + 1, safe_rectification = if(safe_rectification >= 1, safe_rectification - 1, 0) where bidsection_id = ?", auditor.BidsectionId)
 | 
	
		
			
				|  |  | +			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 {
 | 
	
		
			
				|  |  | -			// 复查流程
 | 
	
		
			
				|  |  | -			// 查找最后一个审批人
 | 
	
		
			
				|  |  | -			lastAuditor := &models.CmApprover{BidsectionId: auditor.BidsectionId, DataType: auditor.DataType, DataId: auditor.DataId}
 | 
	
		
			
				|  |  | -			_, err = session.Desc("audit_order").Limit(1).Get(lastAuditor)
 | 
	
		
			
				|  |  | +			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
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +					// 将cm_tree的safe_rectification_finish待整改+1
 | 
	
		
			
				|  |  | +					_, err := session.Exec("update cm_tree set safe_rectification_finish = safe_rectification_finish + 1,  safe_rectification_finish = if(safe_rectification_finish >= 1, safe_rectification_finish - 1, 0)where bidsection_id = ?", auditor.BidsectionId)
 | 
	
		
			
				|  |  | +					if err != nil {
 | 
	
		
			
				|  |  | +						session.Rollback()
 | 
	
		
			
				|  |  | +						return err
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	} else {
 | 
	
		
			
				|  |  | +		// 质量巡检
 | 
	
		
			
				|  |  | +		quality := &models.CmQuality{}
 | 
	
		
			
				|  |  | +		_, err = session.ID(auditor.DataId).Get(quality)
 | 
	
		
			
				|  |  | +		if err != nil {
 | 
	
		
			
				|  |  | +			session.Rollback()
 | 
	
		
			
				|  |  | +			return err
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		// 增加审批日志
 | 
	
		
			
				|  |  | +		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)
 | 
	
		
			
				|  |  | +		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_quality表的status状态为待整改
 | 
	
		
			
				|  |  | +			_, err = session.Exec("update `cm_quality` set status = ? where id = ?", 2, auditor.DataId)
 | 
	
		
			
				|  |  | +			if err != nil {
 | 
	
		
			
				|  |  | +				session.Rollback()
 | 
	
		
			
				|  |  | +				return err
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			// 将cm_tree的quality_rectification待整改+1
 | 
	
		
			
				|  |  | +			_, err := session.Exec("update cm_tree set quality_rectification_in = quality_rectification_in + 1, quality_rectification = if(quality_rectification >= 1, quality_rectification - 1, 0) where bidsection_id = ?", auditor.BidsectionId)
 | 
	
		
			
				|  |  | +			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
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -			if lastAuditor.AuditId == auditor.AuditId {
 | 
	
		
			
				|  |  | -				// 说明审批流程已经走完
 | 
	
		
			
				|  |  | -				_, err = session.Exec("update `cm_safe` set status = ? where id = ?", 4, auditor.DataId)
 | 
	
		
			
				|  |  | +		} else {
 | 
	
		
			
				|  |  | +			if auditor.Progress == 1 {
 | 
	
		
			
				|  |  | +				// 整改人审批流程
 | 
	
		
			
				|  |  | +				// 修改cm_quality表的status状态为待复查
 | 
	
		
			
				|  |  | +				_, err = session.Exec("update `cm_quality` 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_quality` set status = ? where id = ?", 4, auditor.DataId)
 | 
	
		
			
				|  |  | +					if err != nil {
 | 
	
		
			
				|  |  | +						session.Rollback()
 | 
	
		
			
				|  |  | +						return err
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +					// 将cm_tree的quality_rectification_finish待整改+1
 | 
	
		
			
				|  |  | +					_, err := session.Exec("update cm_tree set quality_rectification_finish = quality_rectification_finish + 1, quality_rectification_finish = if(quality_rectification_finish >= 1, quality_rectification_finish - 1, 0) where bidsection_id = ?", auditor.BidsectionId)
 | 
	
		
			
				|  |  | +					if err != nil {
 | 
	
		
			
				|  |  | +						session.Rollback()
 | 
	
		
			
				|  |  | +						return err
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	err = session.Commit()
 | 
	
		
			
				|  |  |  	return err
 | 
	
		
			
				|  |  |  }
 |