Эх сурвалжийг харах

新增出差申请过期检测

tuoling805 2 жил өмнө
parent
commit
0d53e6a39a

+ 32 - 0
models/business_apply.go

@@ -0,0 +1,32 @@
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+func BusinessTripApplyStatusOutTime(returnDate string) (err error) {
+	o := orm.NewOrm()
+	tx, err := o.Begin()
+	if err != nil {
+		return err
+	}
+	defer func() {
+		if err != nil {
+			tx.Commit()
+		} else {
+			tx.Rollback()
+		}
+	}()
+	//客户产品状态变更
+	sql := `UPDATE business_apply SET status='已过期',modify_time=NOW()  WHERE status='待审批' AND return_date < ? `
+	_, err = tx.Raw(sql, returnDate).Exec()
+	if err != nil {
+		return
+	}
+
+	// 将历史的任务给标记删除掉
+	sql = `UPDATE business_apply_peer SET status='已过期',modify_time=NOW() WHERE status='待审批' AND return_date < ? `
+	_, err = o.Raw(sql, returnDate).Exec()
+	if err != nil {
+		return
+	}
+	return
+}

+ 14 - 0
services/business_apply.go

@@ -0,0 +1,14 @@
+package services
+
+import (
+	"context"
+	"hongze/hongze_task/models"
+	"hongze/hongze_task/utils"
+	"time"
+)
+
+func CheckBusinessTripApply(cont context.Context) (err error) {
+	endDate := time.Now().Format(utils.FormatDate)
+	err = models.BusinessTripApplyStatusOutTime(endDate)
+	return err
+}

+ 10 - 5
services/task.go

@@ -130,6 +130,11 @@ func Task() {
 	task.AddTask("定时生成上周纪要汇总", cygxLastWeekSummary)
 	//CygxResearchSummary()
 	//CygxLastWeekSummary()
+
+	// 出差申请过期状态检测
+	checkBusinessTripApply := task.NewTask("checkBusinessTripApply", "0 */30 * * * *", CheckBusinessTripApply)
+	task.AddTask("checkBusinessTripApply", checkBusinessTripApply)
+
 	task.StartTask()
 
 	fmt.Println("task end")
@@ -142,7 +147,7 @@ func Task() {
 //	fmt.Println("end")
 //}
 
-//生产环境需要走的任务
+// 生产环境需要走的任务
 func releaseTask() {
 	////隆众调研指标获取
 	//getLzSurveyProduct := task.NewTask("getLzSurveyProduct", "0 5 08-19/1 * * * ", GetLzSurveyProduct)
@@ -329,7 +334,7 @@ func RefreshEicData(cont context.Context) (err error) {
 	return
 }
 
-//刷新基础数据
+// 刷新基础数据
 func RefreshBaseData(cont context.Context) (err error) {
 	now := time.Now()
 	if now.Hour() == 0 || now.Hour() == 19 {
@@ -340,7 +345,7 @@ func RefreshBaseData(cont context.Context) (err error) {
 	return
 }
 
-//刷新基础数据
+// 刷新基础数据
 func SyncBaseData(cont context.Context) (err error) {
 	now := time.Now()
 	if now.Hour() == 0 || now.Hour() == 19 {
@@ -351,7 +356,7 @@ func SyncBaseData(cont context.Context) (err error) {
 	return
 }
 
-//刷新基础数据
+// 刷新基础数据
 func SyncBaseDataExt(cont context.Context) (err error) {
 	now := time.Now()
 	if now.Hour() == 0 || now.Hour() == 19 {
@@ -795,7 +800,7 @@ func deleteTask() {
 	}
 }
 
-//检测数据服务
+// 检测数据服务
 func checkDataServer(cont context.Context) (err error) {
 	//检测wind新服务器
 	go data.CheckWindDataInterface(cont)