瀏覽代碼

fix: 报告审批相关问题

hsun 1 年之前
父節點
當前提交
7912838275

+ 13 - 1
controllers/business_conf.go

@@ -157,7 +157,6 @@ func (this *BusinessConfController) Save() {
 		// 仅校验有审批->无审批, 或是有审批->切换审批方式的情况
 		if openApprove == "false" && confOpenApprove.ConfVal == "true" || (openApprove == "true" && openApprove == confOpenApprove.ConfVal && confApproveType.ConfVal != approveType) {
 			ok, e := services.CheckCloseReportApproveConf()
-			fmt.Println(ok)
 			if e != nil {
 				br.Msg = "保存失败"
 				br.ErrMsg = "校验是否可以关闭报告审批失败, Err: " + e.Error()
@@ -168,6 +167,19 @@ func (this *BusinessConfController) Save() {
 				return
 			}
 		}
+		// 审批设置切换对未发布/待提交报告状态的重置
+		needReset := false
+		changeType := ""
+		if openApprove == "false" && confOpenApprove.ConfVal == "true" {
+			needReset = true
+		}
+		if openApprove == "true" && openApprove == confOpenApprove.ConfVal && confApproveType.ConfVal != approveType {
+			needReset = false
+			changeType = approveType
+		}
+		if needReset {
+			go services.ConfigChangeResetReportState(changeType)
+		}
 	}
 
 	if len(updates) > 0 {

+ 5 - 5
controllers/english_report/report.go

@@ -1436,11 +1436,11 @@ func (this *EnglishReportController) CancelApprove() {
 		br.Msg = "操作成功"
 		return
 	}
-	if reportItem.ApproveId <= 0 {
-		br.Msg = "报告审批不存在"
-		br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
-		return
-	}
+	//if reportItem.ApproveId <= 0 {
+	//	br.Msg = "报告审批不存在"
+	//	br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
+	//	return
+	//}
 
 	// 撤销审批
 	e = services.CancelReportApprove(report_approve.FlowReportTypeEnglish, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)

+ 5 - 5
controllers/report.go

@@ -3551,11 +3551,11 @@ func (this *ReportController) CancelApprove() {
 		br.Msg = "操作成功"
 		return
 	}
-	if reportItem.ApproveId <= 0 {
-		br.Msg = "报告审批不存在"
-		br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
-		return
-	}
+	//if reportItem.ApproveId <= 0 {
+	//	br.Msg = "报告审批不存在"
+	//	br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
+	//	return
+	//}
 
 	// 撤销审批
 	e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)

+ 27 - 2
models/english_report.go

@@ -862,7 +862,32 @@ func GetEnglishReportStateCount(state int) (count int, err error) {
 // UpdateEnglishReportsStateByCond 批量更新报告状态
 func UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE english_report SET state = ? WHERE classify_id_first = ? AND classify_id_second = ? AND state = ?`
-	_, err = o.Raw(sql, newState, classifyFirstId, classifySecondId, oldState).Exec()
+	cond := ``
+	if classifyFirstId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
+	}
+	if classifySecondId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
+	}
+	sql := fmt.Sprintf(`UPDATE english_report SET state = ? WHERE state = ? %s`, cond)
+	_, err = o.Raw(sql, newState, oldState).Exec()
+	return
+}
+
+// UpdateEnglishReportsStateBySecondIds 批量更新二级分类报告状态
+func UpdateEnglishReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
+	if len(secondIds) <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	// (有审批流的)未发布->待提交
+	sql := fmt.Sprintf(`UPDATE english_report SET state = ? WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, newState, oldState, secondIds).Exec()
+	if err != nil {
+		return
+	}
+	// (无审批流的)待提交->未发布
+	sql = fmt.Sprintf(`UPDATE english_report SET state = ? WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, oldState, newState, secondIds).Exec()
 	return
 }

+ 28 - 2
models/report.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"eta/eta_api/utils"
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"strings"
@@ -1111,7 +1112,32 @@ func GetReportStateCount(state int) (count int, err error) {
 // UpdateReportsStateByCond 批量更新报告状态
 func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE report SET state = ? WHERE classify_id_first = ? AND classify_id_second = ? AND state = ?`
-	_, err = o.Raw(sql, newState, classifyFirstId, classifySecondId, oldState).Exec()
+	cond := ``
+	if classifyFirstId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
+	}
+	if classifySecondId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
+	}
+	sql := fmt.Sprintf(`UPDATE report SET state = ? WHERE state = ? %s`, cond)
+	_, err = o.Raw(sql, newState, oldState).Exec()
+	return
+}
+
+// UpdateReportsStateBySecondIds 批量更新二级分类报告状态
+func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
+	if len(secondIds) <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	// (有审批流的)未发布->待提交
+	sql := fmt.Sprintf(`UPDATE report SET state = ? WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, newState, oldState, secondIds).Exec()
+	if err != nil {
+		return
+	}
+	// (无审批流的)待提交->未发布
+	sql = fmt.Sprintf(`UPDATE report SET state = ? WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, oldState, newState, secondIds).Exec()
 	return
 }

+ 27 - 2
models/smart_report/smart_report.go

@@ -352,7 +352,32 @@ type Report2ImgQueueReq struct {
 // UpdateSmartReportsStateByCond 批量更新报告状态
 func UpdateSmartReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE smart_report SET state = ? WHERE classify_id_first = ? AND classify_id_second = ? AND state = ?`
-	_, err = o.Raw(sql, newState, classifyFirstId, classifySecondId, oldState).Exec()
+	cond := ``
+	if classifyFirstId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
+	}
+	if classifySecondId > 0 {
+		cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
+	}
+	sql := fmt.Sprintf(`UPDATE smart_report SET state = ? WHERE state = ? %s`, cond)
+	_, err = o.Raw(sql, newState, oldState).Exec()
+	return
+}
+
+// UpdateSmartReportsStateBySecondIds 批量更新二级分类报告状态
+func UpdateSmartReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
+	if len(secondIds) <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	// (有审批流的)未发布->待提交
+	sql := fmt.Sprintf(`UPDATE smart_report SET state = ? WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, newState, oldState, secondIds).Exec()
+	if err != nil {
+		return
+	}
+	// (无审批流的)待提交->未发布
+	sql = fmt.Sprintf(`UPDATE smart_report SET state = ? WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+	_, err = o.Raw(sql, oldState, newState, secondIds).Exec()
 	return
 }

+ 95 - 5
services/report_approve.go

@@ -254,10 +254,8 @@ func CancelReportApprove(reportType, reportId, approveId, sysAdminId int, sysAdm
 	if confApproveType == "" {
 		confApproveType = models.BusinessConfReportApproveTypeEta
 	}
+	// 第三方审批仅修改报告状态
 	if confApproveType == models.BusinessConfReportApproveTypeOther {
-		return
-	}
-	if openApprove && confApproveType == models.BusinessConfReportApproveTypeOther {
 		e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
 		if e != nil {
 			err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
@@ -871,11 +869,11 @@ func CheckCloseReportApproveConf() (yes bool, err error) {
 	return
 }
 
-// FlowOperateResetReportState 重置报告的初始状态
+// FlowOperateResetReportState 审批流变化-重置报告的初始状态
 func FlowOperateResetReportState(reportType, classifyFirstId, classifySecondId, oldState, State int) (err error) {
 	defer func() {
 		if err != nil {
-			tips := fmt.Sprintf("重置报告初始状态失败, ErrMsg: %s", err.Error())
+			tips := fmt.Sprintf("审批流变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
 			utils.FileLog.Info(tips)
 			go alarm_msg.SendAlarmMsg(tips, 2)
 		}
@@ -909,3 +907,95 @@ func FlowOperateResetReportState(reportType, classifyFirstId, classifySecondId,
 	}
 	return
 }
+
+// ConfigChangeResetReportState 审批配置变化-重置报告的初始状态
+func ConfigChangeResetReportState(changeType string) (err error) {
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("审批配置变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
+			utils.FileLog.Info(tips)
+			go alarm_msg.SendAlarmMsg(tips, 2)
+		}
+	}()
+
+	// 关闭审批-待提交->未发布
+	if changeType == "" {
+		e := models.UpdateReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
+		if e != nil {
+			err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
+		}
+		e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
+		if e != nil {
+			err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
+		}
+		e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
+		if e != nil {
+			err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
+		}
+		return
+	}
+
+	// 开启内部审批-未发布->部分待提交
+	if changeType == models.BusinessConfReportApproveTypeEta {
+		flowOb := new(report_approve.ReportApproveFlow)
+		flows, e := flowOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
+		if e != nil {
+			err = fmt.Errorf("GetApproveFlows err: %s", e.Error())
+			return
+		}
+		reportSecondIds, englishSecondIds, smartSecondIds := make([]int, 0), make([]int, 0), make([]int, 0)
+		for _, v := range flows {
+			if v.ReportType == report_approve.FlowReportTypeChinese {
+				reportSecondIds = append(reportSecondIds, v.ClassifySecondId)
+				continue
+			}
+			if v.ReportType == report_approve.FlowReportTypeEnglish {
+				englishSecondIds = append(englishSecondIds, v.ClassifySecondId)
+				continue
+			}
+			if v.ReportType == report_approve.FlowReportTypeSmart {
+				smartSecondIds = append(smartSecondIds, v.ClassifySecondId)
+			}
+		}
+		if len(reportSecondIds) > 0 {
+			e = models.UpdateReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, reportSecondIds)
+			if e != nil {
+				err = fmt.Errorf("UpdateReportsStateBySecondIds err: %s", e.Error())
+				return
+			}
+		}
+		if len(englishSecondIds) > 0 {
+			e = models.UpdateEnglishReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, englishSecondIds)
+			if e != nil {
+				err = fmt.Errorf("UpdateEnglishReportsStateBySecondIds err: %s", e.Error())
+				return
+			}
+		}
+		if len(smartSecondIds) > 0 {
+			e = smart_report.UpdateSmartReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, smartSecondIds)
+			if e != nil {
+				err = fmt.Errorf("UpdateSmartReportsStateBySecondIds err: %s", e.Error())
+				return
+			}
+		}
+		return
+	}
+
+	// 开启第三方审批->未发布->待提交
+	if changeType == models.BusinessConfReportApproveTypeOther {
+		e := models.UpdateReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
+		if e != nil {
+			err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
+		}
+		e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
+		if e != nil {
+			err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
+		}
+		e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
+		if e != nil {
+			err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
+		}
+		return
+	}
+	return
+}