Browse Source

fix:基本设置保存看报审批增加校验

zqbao 6 months ago
parent
commit
e7c7c0cd37
3 changed files with 40 additions and 1 deletions
  1. 22 1
      controllers/business_conf.go
  2. 7 0
      models/bi_approve/bi_approve.go
  3. 11 0
      services/bi_approve/bi_approve.go

+ 22 - 1
controllers/business_conf.go

@@ -4,13 +4,15 @@ import (
 	"encoding/json"
 	"eta_gn/eta_api/models"
 	"eta_gn/eta_api/services"
+	biapprove "eta_gn/eta_api/services/bi_approve"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/shopspring/decimal"
 	"html"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/shopspring/decimal"
 )
 
 // BusinessConfController 商家配置
@@ -66,6 +68,7 @@ func (this *BusinessConfController) Save() {
 
 	openApprove := ""
 	approveType := ""
+	curBiAprrove := ""
 
 	// 根据配置类型取值
 	updates := make([]models.BusinessConfUpdate, 0)
@@ -103,6 +106,9 @@ func (this *BusinessConfController) Save() {
 				}
 				approveType = str
 			}
+			if k == models.BusinessConfIsBIApprove {
+				curBiAprrove = str
+			}
 		case 2: // 数值
 			vDeci, err := decimal.NewFromString(fmt.Sprint(v))
 			if err != nil {
@@ -191,6 +197,21 @@ func (this *BusinessConfController) Save() {
 			go services.ConfigChangeResetReportState(changeType)
 		}
 	}
+	if curBiAprrove != "" {
+		oldBiApprove := confMap[models.BusinessConfIsBIApprove]
+		if oldBiApprove != nil && oldBiApprove.ConfVal != curBiAprrove && oldBiApprove.ConfVal == "true" && curBiAprrove == "false" {
+			ok, err := biapprove.CheckHasApprovingBi()
+			if err != nil {
+				br.Msg = "保存失败"
+				br.ErrMsg = "校验是否有正在审批的BI失败, Err: " + err.Error()
+				return
+			}
+			if ok {
+				br.Msg = "当前有未走完流程的看板,请走完流程后再做变更"
+				return
+			}
+		}
+	}
 
 	if len(updates) > 0 {
 		if e = models.UpdateBusinessConfMulti(updates); e != nil {

+ 7 - 0
models/bi_approve/bi_approve.go

@@ -188,3 +188,10 @@ func GetBiApproveByBoardId(biApproveId int) (item *BiApprove, err error) {
 	err = db.Where("bi_id = ?", biApproveId).Order("create_time DESC").First(&item).Error
 	return
 }
+
+func GetBiApproveCountByState(state int) (count int, err error) {
+	db := global.DmSQL["rddp"]
+	sql := `SELECT COUNT(*) FROM bi_approve WHERE state = ?`
+	err = db.Raw(sql, state).Scan(&count).Error
+	return
+}

+ 11 - 0
services/bi_approve/bi_approve.go

@@ -1125,3 +1125,14 @@ func GetBiClassifyAll() (list []*bi_dashboard.BiDashboardClassify, msg string, e
 	list = ClassifyList
 	return
 }
+
+func CheckHasApprovingBi() (ok bool, err error) {
+	count, err := biapprove.GetBiApproveCountByState(BiApproveStateApproving)
+	if err != nil {
+		return
+	}
+	if count > 0 {
+		ok = true
+	}
+	return
+}