Bläddra i källkod

refactor: 审批重构

lanjianrong 4 år sedan
förälder
incheckning
884947456d

+ 78 - 26
dao/approver_dao.go

@@ -8,7 +8,10 @@
 package dao
 package dao
 
 
 import (
 import (
+	"errors"
 	"fmt"
 	"fmt"
+	"strconv"
+	"time"
 
 
 	"github.com/go-xorm/xorm"
 	"github.com/go-xorm/xorm"
 	"go.mod/comm"
 	"go.mod/comm"
@@ -30,7 +33,7 @@ func NewApproverDao(engine *xorm.Engine) *ApproverDao {
 }
 }
 
 
 // 批量插入数据
 // 批量插入数据
-func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error {
+func (d *ApproverDao) InsertData(bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error {
 	data := make([]models.CmApprover, 0)
 	data := make([]models.CmApprover, 0)
 	for i, item := range auditors {
 	for i, item := range auditors {
 		approverVM := models.CmApprover{}
 		approverVM := models.CmApprover{}
@@ -42,7 +45,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data
 		approverVM.DataType = dataType
 		approverVM.DataType = dataType
 		approverVM.DataId = dataId
 		approverVM.DataId = dataId
 		approverVM.Status = 0
 		approverVM.Status = 0
-		approverVM.Times = times
 		if i == 0 {
 		if i == 0 {
 			approverVM.Status = 1
 			approverVM.Status = 1
 		}
 		}
@@ -55,7 +57,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data
 	checkVM.ProjectId = pid
 	checkVM.ProjectId = pid
 	checkVM.DataType = dataType
 	checkVM.DataType = dataType
 	checkVM.DataId = dataId
 	checkVM.DataId = dataId
-	checkVM.Times = times
 	data = append(data, checkVM)
 	data = append(data, checkVM)
 	for i, item := range reAuditors {
 	for i, item := range reAuditors {
 		approverVM := models.CmApprover{}
 		approverVM := models.CmApprover{}
@@ -66,7 +67,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data
 		approverVM.ProjectId = pid
 		approverVM.ProjectId = pid
 		approverVM.DataType = dataType
 		approverVM.DataType = dataType
 		approverVM.DataId = dataId
 		approverVM.DataId = dataId
-		approverVM.Times = times
 		data = append(data, approverVM)
 		data = append(data, approverVM)
 	}
 	}
 	_, err := d.engine.Insert(data)
 	_, err := d.engine.Insert(data)
@@ -91,14 +91,15 @@ func (d *ApproverDao) ChangeAuditId(bid int, dataType int, dataId int, auditOrde
 func (d *ApproverDao) ChangeNextStatus(id int, status int) error {
 func (d *ApproverDao) ChangeNextStatus(id int, status int) error {
 	data := &models.CmApprover{Id: id}
 	data := &models.CmApprover{Id: id}
 	_, err := d.engine.Get(data)
 	_, err := d.engine.Get(data)
-	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order = ?", data.BidsectionId, data.DataType, data.DataId, data.AuditOrder+1).Cols("status").Update(data)
+	newData := &models.CmApprover{Status: status}
+	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order = ?", data.BidsectionId, data.DataType, data.DataId, data.AuditOrder+1).Cols("status").Update(newData)
 	return err
 	return err
 }
 }
 
 
 // 根据当前times,获取审批流程(包括原报)
 // 根据当前times,获取审批流程(包括原报)
-func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, times int, cur_uid int) []viewmodels.Auditors {
+func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, cur_uid int) []viewmodels.Auditors {
 	auditors := make([]viewmodels.Auditors, 0)
 	auditors := make([]viewmodels.Auditors, 0)
-	auditor := viewmodels.Auditors{Progress: "", Id: ""}
+	auditor := viewmodels.Auditors{Progress: "", Id: "", Status: 2}
 
 
 	_, err := d.engine.Sql("select name, company, position, mobile, id as `audit_id` from `cm_project_account` where id = ?", cur_uid).Get(&auditor)
 	_, err := d.engine.Sql("select name, company, position, mobile, id as `audit_id` from `cm_project_account` where id = ?", cur_uid).Get(&auditor)
 
 
@@ -107,7 +108,7 @@ func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, ti
 	}
 	}
 	auditors = append(auditors, auditor)
 	auditors = append(auditors, auditor)
 
 
-	d.engine.Sql("select pa.`company`, pa.`name`, pa.`account_group`,pa.`mobile`, pa.`position`,ca.`audit_id` as `audit_id`, ca.`id`, ca.`status`, ca.`audit_order`, ca.`progress` from `cm_project_account` as pa, `cm_approver` as ca where ca.`bidsection_id` = ? and ca.`data_type` = ? and ca.`data_id` = ? and ca.`times` = ? and ca.audit_id = pa.id order by `audit_order`", bid, dataType, dataId, times).Find(&auditors)
+	d.engine.Sql("select pa.`company`, pa.`name`, pa.`account_group`,pa.`mobile`, pa.`position`,ca.`audit_id` as `audit_id`, ca.`id`, ca.`status`, ca.`audit_order`, ca.`progress` from `cm_project_account` as pa, `cm_approver` as ca where ca.`bidsection_id` = ? and ca.`data_type` = ? and ca.`data_id` = ? and ca.audit_id = pa.id order by `audit_order`", bid, dataType, dataId).Find(&auditors)
 	// 原报
 	// 原报
 	return auditors
 	return auditors
 }
 }
@@ -120,21 +121,26 @@ func (d *ApproverDao) FindApproverById(id int) (*models.CmApprover, error) {
 
 
 // 获取最新的审核人
 // 获取最新的审核人
 func (d *ApproverDao) GetLastedAuditor(bid int, dataType int, dataId int) *viewmodels.Approver {
 func (d *ApproverDao) GetLastedAuditor(bid int, dataType int, dataId int) *viewmodels.Approver {
-	data := &viewmodels.Approver{BidsectionId: string(bid), DataType: dataType, DataId: string(dataId), Status: 1}
+	data := &models.CmApprover{BidsectionId: bid, DataType: dataType, DataId: dataId, Status: 1}
 	has, _ := d.engine.Get(data)
 	has, _ := d.engine.Get(data)
+	approverVM := &viewmodels.Approver{}
 	if has == true {
 	if has == true {
-		id, _ := comm.AesEncrypt(data.Id, conf.SignSecret)
-		data.Id = id
-		pid, _ := comm.AesEncrypt(data.ProjectId, conf.SignSecret)
-		data.Id = pid
-		bid, _ := comm.AesEncrypt(data.BidsectionId, conf.SignSecret)
-		data.Id = bid
-		dataId, _ := comm.AesEncrypt(data.DataId, conf.SignSecret)
-		data.DataId = dataId
-		auditId, _ := comm.AesEncrypt(data.AuditId, conf.SignSecret)
-		data.AuditId = auditId
+		id, _ := comm.AesEncrypt(strconv.Itoa(data.Id), conf.SignSecret)
+		approverVM.Id = id
+		pid, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
+		approverVM.ProjectId = pid
+		bid, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
+		approverVM.BidsectionId = bid
+		dataId, _ := comm.AesEncrypt(strconv.Itoa(data.DataId), conf.SignSecret)
+		approverVM.DataId = dataId
+		auditId, _ := comm.AesEncrypt(strconv.Itoa(data.AuditId), conf.SignSecret)
+		approverVM.AuditId = auditId
+		approverVM.AuditOrder = data.AuditOrder
+		approverVM.DataType = data.DataType
+		approverVM.Progress = strconv.Itoa(data.Progress)
+		approverVM.Status = data.Status
 	}
 	}
-	return data
+	return approverVM
 }
 }
 
 
 // 获取最后一个审批人
 // 获取最后一个审批人
@@ -145,21 +151,67 @@ func (d *ApproverDao) GetLastAuditor(bid int, dataType int, dataId int) (*models
 }
 }
 
 
 // 初始化审批流程状态
 // 初始化审批流程状态
-func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int) error {
+func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int, auditId int, times int, progress int, opinion string) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("操作失败-db")
+	}
+
 	data := &models.CmApprover{Status: 0}
 	data := &models.CmApprover{Status: 0}
-	_, err := d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ?").Cols("status").Update(data)
-	return err
+	_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ?", bid, dataType, dataId).Cols("status").Update(data)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	_, err = session.Exec("update cm_safe set status = ? where id = ?", 0, 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}
+	_, err = session.Insert(safeAudit)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
+	err = session.Commit()
+	if err != nil {
+		return err
+	}
+	return nil
 }
 }
 
 
 // 审批流程-退回
 // 审批流程-退回
-func (d *ApproverDao) BackHandlerWithId(id int) error {
+func (d *ApproverDao) BackHandlerWithId(id int, cur_audit 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, err := d.FindApproverById(id)
 	data := &models.CmApprover{Status: 0}
 	data := &models.CmApprover{Status: 0}
 	// 将往后的所有记录的status改为0
 	// 将往后的所有记录的status改为0
-	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order > ?", auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder).Cols("status").Update(data)
+	_, 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)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
 	// 将当前的记录改为1-待审批
 	// 将当前的记录改为1-待审批
 	data.Status = 1
 	data.Status = 1
-	_, err = d.engine.ID(id).Cols("status").Update(data)
+	_, err = session.ID(id).Cols("status").Update(data)
+	if err != nil {
+		session.Rollback()
+		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}
+	_, err = session.Insert(safeAudit)
+	if err != nil {
+		session.Rollback()
+		return err
+	}
 	return err
 	return err
 }
 }
 
 

+ 3 - 91
dao/safe_audit_dao.go

@@ -31,9 +31,8 @@ func NewSafeAuditDao(engine *xorm.Engine) *SafeAuditDao {
 }
 }
 
 
 // 添加审批记录
 // 添加审批记录
-func (d *SafeAuditDao) AddAuditRecord(safeId int, bId int, auditId int, times int, status int, progress int, rectifiedInfo string) error {
-	auditOrder := d.GetNewOrder(safeId, times)
-	auditor := &models.CmSafeAudit{SafeId: safeId, BidsectionId: bId, AuditId: auditId, Times: times, AuditOrder: auditOrder, CreateTime: time.Now(), Status: status, Progress: progress, Rectifiedinfo: rectifiedInfo}
+func (d *SafeAuditDao) AddAuditRecord(safeId int, bId int, auditId int, times int, status int, progress int, opinion string, rectifiedInfo string) error {
+	auditor := &models.CmSafeAudit{SafeId: safeId, BidsectionId: bId, AuditId: auditId, Times: times, CreateTime: time.Now(), Status: status, Progress: progress, Opinion: opinion, Rectifiedinfo: rectifiedInfo}
 	_, err := d.engine.InsertOne(auditor)
 	_, err := d.engine.InsertOne(auditor)
 	return err
 	return err
 }
 }
@@ -50,43 +49,18 @@ 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) GetAuditorsWithOwner(id int, times int, cur_uid int) []viewmodels.Auditors {
-// 	auditors := make([]viewmodels.Auditors, 0)
-// 	auditor := viewmodels.Auditors{Progress: ""}
-
-// 	_, err := d.engine.Sql("select name, company, position, mobile, id as `audit_id` from `cm_project_account` where id = ?", cur_uid).Get(&auditor)
-
-// 	if err != nil {
-// 		fmt.Println(err)
-// 	}
-// 	auditors = append(auditors, auditor)
-
-// 	d.engine.Sql("select pa.`company`, pa.`name`, pa.`account_group`,pa.`mobile`, pa.`position`,ca.`audit_id` as `audit_id`, ca.`id`, ca.`status`, ca.`audit_order`, ca.`progress` 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从1开始循环,往history里面push
 // times从1开始循环,往history里面push
 func (d *SafeAuditDao) GetAuditHistory(id int, times int) map[int][]viewmodels.HistorySafeAudit {
 func (d *SafeAuditDao) GetAuditHistory(id int, times int) map[int][]viewmodels.HistorySafeAudit {
 	auditorHistory := make(map[int][]viewmodels.HistorySafeAudit, 0)
 	auditorHistory := make(map[int][]viewmodels.HistorySafeAudit, 0)
 	for i := 1; i <= times; i++ {
 	for i := 1; i <= times; i++ {
 		auditors := make([]viewmodels.HistorySafeAudit, 0)
 		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 `audit_order`", id, i).Find(&auditors)
+		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)
 		auditorsArr := make([]viewmodels.HistorySafeAudit, 0)
 		auditorsArr := make([]viewmodels.HistorySafeAudit, 0)
 		for _, auditor := range auditors {
 		for _, auditor := range auditors {
 			auditorVM := viewmodels.HistorySafeAudit{}
 			auditorVM := viewmodels.HistorySafeAudit{}
 			id, _ := comm.AesEncrypt(auditor.Id, conf.SignSecret)
 			id, _ := comm.AesEncrypt(auditor.Id, conf.SignSecret)
 			auditorVM.Id = id
 			auditorVM.Id = id
 			auditorVM.CreateTime = auditor.CreateTime
 			auditorVM.CreateTime = auditor.CreateTime
-			auditorVM.EndTime = auditor.EndTime
 			auditorVM.Name = auditor.Name
 			auditorVM.Name = auditor.Name
 			auditorVM.Position = auditor.Position
 			auditorVM.Position = auditor.Position
 			auditorVM.Status = auditor.Status
 			auditorVM.Status = auditor.Status
@@ -106,57 +80,6 @@ func (d *SafeAuditDao) FindById(id int) (*models.CmSafeAudit, error) {
 	return data, err
 	return data, err
 }
 }
 
 
-// 改变审批记录状态
-// func (d *SafeAuditDao) ChangeStatusById(id int, opinion string, status int, rectifiedInfo string) error {
-// 	data := &models.CmSafeAudit{EndTime: time.Now(), Opinion: opinion, Status: status, Rectifiedinfo: rectifiedInfo}
-// 	_, err := d.engine.ID(id).Cols("end_time", "opinion", "status").Update(data)
-// 	return err
-// }
-
-// 拷贝新的审批流程
-func (d *SafeAuditDao) CopyAuditors(safeId int, times int, 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
-	}
-
-	newAuditors := make([]models.CmSafeAudit, 0)
-	for i, 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 = 0
-		// 上报人
-		if i == 0 {
-			auditorVM.Status = 1
-		}
-		newAuditors = append(newAuditors, auditorVM)
-	}
-	_, err = d.engine.Insert(&newAuditors)
-	return err
-}
-
-// 修改整改人id
-func (d *SafeAuditDao) AddCheckWorker(id int, auditId int) error {
-	auditor, err := d.FindById(id)
-	if err != nil {
-		return err
-	}
-	//  _, err = d.engine.Where().Update()
-	data := &models.CmSafeAudit{AuditId: auditId, Status: 1, CreateTime: time.Now()}
-	_, err = d.engine.Where("safe_id = ? and bidsection_id = ? and audit_order = ? and times = ?", auditor.SafeId, auditor.BidsectionId, auditor.AuditOrder+1, auditor.Times).Cols("audit_id", "status", "create_time").Update(data)
-	if err != nil {
-		return err
-	}
-	return nil
-}
-
 // 查找最新的整改单
 // 查找最新的整改单
 func (d *SafeAuditDao) GetLastedOrder(safeId int) ([]viewmodels.CheckOrderVM, error) {
 func (d *SafeAuditDao) GetLastedOrder(safeId int) ([]viewmodels.CheckOrderVM, error) {
 	data := make([]viewmodels.CheckOrderVM, 0)
 	data := make([]viewmodels.CheckOrderVM, 0)
@@ -164,17 +87,6 @@ func (d *SafeAuditDao) GetLastedOrder(safeId int) ([]viewmodels.CheckOrderVM, er
 	return data, err
 	return data, err
 }
 }
 
 
-// 获取当前的审核人
-func (d *SafeAuditDao) GetLastedAuditor(times int, safeId int) (*viewmodels.LatestAuditorVM, error) {
-	data := &viewmodels.LatestAuditorVM{}
-	_, err := d.engine.Sql("select id, audit_id, progress, status from cm_safe_audit where times = ? and safe_id = ? and status = 1 order by `audit_order` limit 1", times, safeId).Get(data)
-	auditId, _ := comm.AesEncrypt(data.AuditId, conf.SignSecret)
-	data.AuditId = auditId
-	Id, _ := comm.AesEncrypt(data.Id, conf.SignSecret)
-	data.Id = Id
-	return data, err
-}
-
 // 插入审批记录
 // 插入审批记录
 func (d *SafeAuditDao) InsertData(data models.CmSafeAudit) error {
 func (d *SafeAuditDao) InsertData(data models.CmSafeAudit) error {
 	_, err := d.engine.Insert(&data)
 	_, err := d.engine.Insert(&data)

+ 11 - 13
services/safe_audit.service.go

@@ -57,7 +57,7 @@ func (s *safeAuditService) CloseAudit(id int, opinion string, curUid int, saveId
 	}
 	}
 	safe := s.daoSafe.FindById(auditor.DataId)
 	safe := s.daoSafe.FindById(auditor.DataId)
 	// 增加审批日志记录
 	// 增加审批日志记录
-	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 2, auditor.Progress, "")
+	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 2, auditor.Progress, opinion, "")
 	// 更改cm_safe的记录
 	// 更改cm_safe的记录
 	err = s.daoSafe.ChangeStatus(saveId, 5)
 	err = s.daoSafe.ChangeStatus(saveId, 5)
 	// 更改cm_approver的记录
 	// 更改cm_approver的记录
@@ -73,21 +73,19 @@ func (s *safeAuditService) BackAudit(id int, opinion string, curUid int, saveId
 	}
 	}
 	safe := s.daoSafe.FindById(saveId)
 	safe := s.daoSafe.FindById(saveId)
 	// 增加审批日志
 	// 增加审批日志
-	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 1, auditor.Progress, "")
-	if err != nil {
-		return err
-	}
+	// err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 1, auditor.Progress, opinion, "")
+	// if err != nil {
+	// 	return err
+	// }
 
 
 	// 退回到了检查人
 	// 退回到了检查人
 	if auditId == 0 {
 	if auditId == 0 {
 		// 初始化审批流程
 		// 初始化审批流程
-		err = s.daoApprover.InitStatus(auditor.BidsectionId, auditor.DataType, auditor.DataId)
+		err = s.daoApprover.InitStatus(auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditId, safe.Times, auditor.Progress+1, opinion)
 	} else {
 	} else {
 		// 退回到审批流程中的某一个人
 		// 退回到审批流程中的某一个人
-		err = s.daoApprover.BackHandlerWithId(auditId)
+		err = s.daoApprover.BackHandlerWithId(auditId, id, safe.Times, auditor.Progress+1, opinion)
 	}
 	}
-	safeData := s.daoSafe.FindById(saveId)
-	err = s.daoSafeAudit.CopyAuditors(saveId, safeData.Times, auditId)
 	return err
 	return err
 
 
 }
 }
@@ -104,7 +102,7 @@ func (s *safeAuditService) PassAudit(id int, uid int, auditId int, opinion strin
 		return errors.New("该用户没有审批权限!")
 		return errors.New("该用户没有审批权限!")
 	}
 	}
 	// 增加审批日志
 	// 增加审批日志
-	err = s.daoSafeAudit.AddAuditRecord(auditor.DataId, auditor.BidsectionId, auditor.AuditId, safe.Times, 0, auditor.Progress, rectifiedInfo)
+	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.ChangeStatus(id, 2)
 	err = s.daoApprover.ChangeNextStatus(id, 1)
 	err = s.daoApprover.ChangeNextStatus(id, 1)
@@ -126,7 +124,7 @@ func (s *safeAuditService) PassAudit(id int, uid int, auditId int, opinion strin
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}
-			if lastAuditor.AuditId == auditor.Id {
+			if lastAuditor.AuditId == auditor.AuditId {
 				// 说明审批流程已经走完
 				// 说明审批流程已经走完
 				err = s.daoSafe.ChangeStatus(auditor.DataId, 4)
 				err = s.daoSafe.ChangeStatus(auditor.DataId, 4)
 			}
 			}
@@ -143,11 +141,11 @@ func (s *safeAuditService) StartAudit(safeId int, bidsectionId int, auditors []i
 	// 清除可能有的旧的审批流程
 	// 清除可能有的旧的审批流程
 	err := s.daoApprover.DeleteOldAuditors(bidsectionId, 1, safeId)
 	err := s.daoApprover.DeleteOldAuditors(bidsectionId, 1, safeId)
 	// 增加审批日志
 	// 增加审批日志
-	err = s.daoSafeAudit.AddAuditRecord(safeId, bidsectionId, uid, safe.Times, 0, 0, "")
+	err = s.daoSafeAudit.AddAuditRecord(safeId, bidsectionId, uid, safe.Times, 0, 0, "", "")
 	// 改变安全巡检表的状态
 	// 改变安全巡检表的状态
 	err = s.daoSafe.ChangeStatus(safeId, 1)
 	err = s.daoSafe.ChangeStatus(safeId, 1)
 	// 创建审批流程
 	// 创建审批流程
-	err = s.daoApprover.InsertData(safe.Times, bidsectionId, pid, 1, safeId, auditors, reAuditors)
+	err = s.daoApprover.InsertData(bidsectionId, pid, 1, safeId, auditors, reAuditors)
 	return err
 	return err
 }
 }
 
 

+ 5 - 3
services/safe_service.go

@@ -99,9 +99,11 @@ func (s *safeService) GetDetail(id int, pid int) viewmodels.SafeDetail {
 	// fmt.Println(safeData)
 	// fmt.Println(safeData)
 	safeId, _ := comm.AesEncrypt(strconv.Itoa(safeData.Id), conf.SignSecret)
 	safeId, _ := comm.AesEncrypt(strconv.Itoa(safeData.Id), conf.SignSecret)
 	bid, _ := comm.AesEncrypt(strconv.Itoa(safeData.BidsectionId), conf.SignSecret)
 	bid, _ := comm.AesEncrypt(strconv.Itoa(safeData.BidsectionId), conf.SignSecret)
+	uid, _ := comm.AesEncrypt(strconv.Itoa(safeData.Uid), conf.SignSecret)
 	data := viewmodels.SafeDetail{}
 	data := viewmodels.SafeDetail{}
-	data.Id = string(safeId)
-	data.BidsectionId = string(bid)
+	data.Id = safeId
+	data.BidsectionId = bid
+	data.Uid = uid
 	data.Code = safeData.Code
 	data.Code = safeData.Code
 	data.Inspection = safeData.Inspection
 	data.Inspection = safeData.Inspection
 	data.InspectionDetail = safeData.InspectionDetail
 	data.InspectionDetail = safeData.InspectionDetail
@@ -130,7 +132,7 @@ func (s *safeService) GetDetail(id int, pid int) viewmodels.SafeDetail {
 	fileVM.FileList = fileArr
 	fileVM.FileList = fileArr
 	fileVM.Total = total
 	fileVM.Total = total
 	data.File = fileVM
 	data.File = fileVM
-	auditors := s.daoApprover.GetAuditorsWithOwner(safeData.BidsectionId, int(1), safeData.Id, safeData.Times, account.Id)
+	auditors := s.daoApprover.GetAuditorsWithOwner(safeData.BidsectionId, int(1), safeData.Id, account.Id)
 	encryptAuditors := make([]viewmodels.Auditors, 0)
 	encryptAuditors := make([]viewmodels.Auditors, 0)
 	for _, item := range auditors {
 	for _, item := range auditors {
 		auditorVM := viewmodels.Auditors{}
 		auditorVM := viewmodels.Auditors{}

+ 1 - 1
web/api/safe_audit_api.go

@@ -145,7 +145,7 @@ func (c *SafeAuditApi) PostClose() {
 // @Produce  json
 // @Produce  json
 // @Param   id     body    string     true        "审批id"
 // @Param   id     body    string     true        "审批id"
 // @Param   safe_id     body    string     true        "巡检id"
 // @Param   safe_id     body    string     true        "巡检id"
-// @Param   audit_id     body    string     true        "回滚的审批流程id"
+// @Param   audit_id     body    string     false        "回滚的审批流程id, 不传则退回到上报人"
 // @Param   opinion     body    string     true        "审批意见"
 // @Param   opinion     body    string     true        "审批意见"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"

+ 2 - 3
web/viewmodels/approver.go

@@ -7,14 +7,13 @@
 package viewmodels
 package viewmodels
 
 
 type Approver struct {
 type Approver struct {
-	Id           string `from:"id" json:"json`
+	Id           string `from:"id" json:"id"`
 	ProjectId    string `from:"project_id" json:"project_id"`
 	ProjectId    string `from:"project_id" json:"project_id"`
 	BidsectionId string `from:"bidsection_id" json:"bidsection_id"`
 	BidsectionId string `from:"bidsection_id" json:"bidsection_id"`
 	DataType     int    `from:"data_type" json:"data_type"`
 	DataType     int    `from:"data_type" json:"data_type"`
 	DataId       string `from:"data_id" json:"data_id"`
 	DataId       string `from:"data_id" json:"data_id"`
 	Status       int    `from:"status" json:"status"`
 	Status       int    `from:"status" json:"status"`
-	Progress     int    `from:"progress" json:"progress"`
-	Times        int    `from:"times" json:"times"`
+	Progress     string `from:"progress" json:"progress"`
 	AuditOrder   int    `from:"audit_order" json:"audit_order"`
 	AuditOrder   int    `from:"audit_order" json:"audit_order"`
 	AuditId      string `from:"audit_id" json:"audit_id"`
 	AuditId      string `from:"audit_id" json:"audit_id"`
 }
 }

+ 2 - 1
web/viewmodels/safe.go

@@ -45,6 +45,7 @@ type SafeDetail struct {
 	Id           string `form:"id" json:"id" `
 	Id           string `form:"id" json:"id" `
 	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
 	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
 
 
+	Uid              string                     `from:"uid" json:"uid"`
 	Code             string                     `form:"code" json:"code"`
 	Code             string                     `form:"code" json:"code"`
 	CreateTime       time.Time                  `form:"createTime" json:"createTime"`
 	CreateTime       time.Time                  `form:"createTime" json:"createTime"`
 	Position         string                     `form:"position" json:"position"`
 	Position         string                     `form:"position" json:"position"`
@@ -74,7 +75,7 @@ type SafeFile struct {
 	CreateTime  time.Time `from:"create_time" json:"createTime"`
 	CreateTime  time.Time `from:"create_time" json:"createTime"`
 }
 }
 type Auditors struct {
 type Auditors struct {
-	Id           string `from:"id" json:id"`
+	Id           string `from:"id" json:"id"`
 	Name         string `from:"name" json:"name"`
 	Name         string `from:"name" json:"name"`
 	Progress     string `from:"progress" json:"progress"`
 	Progress     string `from:"progress" json:"progress"`
 	AuditId      string `from:"audit_id" json:"audit_id"`
 	AuditId      string `from:"audit_id" json:"audit_id"`

+ 0 - 1
web/viewmodels/safe_audit.go

@@ -73,7 +73,6 @@ func (l SafeAudit) ValidateBack() error {
 	return validation.ValidateStruct(&l,
 	return validation.ValidateStruct(&l,
 		validation.Field(&l.Id, validation.Required.Error("记录id不能为空")),
 		validation.Field(&l.Id, validation.Required.Error("记录id不能为空")),
 		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
 		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
-		validation.Field(&l.AuditId, validation.Required.Error("回滚的记录id不能为空")),
 	)
 	)
 }
 }
 func (l SafeAudit) ValidatePass() error {
 func (l SafeAudit) ValidatePass() error {