Browse Source

定时任务-同步每刻报销客户档案

hsun 2 years ago
parent
commit
23ff41e774
2 changed files with 76 additions and 8 deletions
  1. 61 0
      services/maycur/maycur.go
  2. 15 8
      services/task.go

+ 61 - 0
services/maycur/maycur.go

@@ -0,0 +1,61 @@
+package maycur
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"hongze/hongze_task/models"
+	"hongze/hongze_task/services/alarm_msg"
+	"hongze/hongze_task/utils"
+	"io/ioutil"
+	"net/http"
+	"strings"
+)
+
+const (
+	SyncMaycurCompanyProfileUrl = "http://127.0.0.1:8602/adminapi/maycur/company_profile/daily_sync"
+)
+
+// DailyUpdateCompanyProfile 每日更新客户档案-请求hongze_admin同步接口
+func DailyUpdateCompanyProfile(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info("DailyUpdateCompanyProfile ErrMsg: %s", err.Error())
+			alarm_msg.SendAlarmMsg(fmt.Sprintf("每日更新客户档案失败, ErrMsg: %s", err.Error()), 3)
+		}
+	}()
+
+	body := ioutil.NopCloser(strings.NewReader(""))
+	client := &http.Client{}
+	req, e := http.NewRequest("POST", SyncMaycurCompanyProfileUrl, body)
+	if e != nil {
+		err = fmt.Errorf("http create request err: %s", e.Error())
+		return
+	}
+	contentType := "application/json;charset=utf-8"
+	req.Header.Set("Content-Type", contentType)
+	//req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
+	resp, e := client.Do(req)
+	if e != nil {
+		err = fmt.Errorf("http client do err: %s", e.Error())
+		return err
+	}
+	defer func() {
+		_ = resp.Body.Close()
+	}()
+	b, e := ioutil.ReadAll(resp.Body)
+	if e != nil {
+		err = fmt.Errorf("resp body read err: %s", e.Error())
+		return
+	}
+	result := new(models.BaseResponse)
+	if e = json.Unmarshal(b, &result); e != nil {
+		err = fmt.Errorf("result unmarshal err: %s", e.Error())
+		return
+	}
+	if result.Ret != 200 {
+		err = fmt.Errorf("result: %s", string(b))
+		return err
+	}
+	return
+}

+ 15 - 8
services/task.go

@@ -10,6 +10,7 @@ import (
 	"hongze/hongze_task/services/company_contract"
 	"hongze/hongze_task/services/data"
 	"hongze/hongze_task/services/data/future_good"
+	"hongze/hongze_task/services/maycur"
 	"hongze/hongze_task/services/roadshow"
 	"hongze/hongze_task/utils"
 	"strconv"
@@ -139,13 +140,15 @@ func Task() {
 }
 
 //func Task() {
-//	fmt.Println("start")
+//	fmt.Println("start task")
+//
 //	cont := new(context.Context)
-//	roadshow.SetPublicMeetingUnionCode(*cont)
-//	fmt.Println("end")
+//	_ = maycur.DailyUpdateCompanyProfile(*cont)
+//
+//	fmt.Println("end task")
 //}
 
-//生产环境需要走的任务
+// 生产环境需要走的任务
 func releaseTask() {
 	////隆众调研指标获取
 	//getLzSurveyProduct := task.NewTask("getLzSurveyProduct", "0 5 08-19/1 * * * ", GetLzSurveyProduct)
@@ -216,6 +219,10 @@ func releaseTask() {
 	// 定时统计交易所的持仓分析数据
 	InitPositionTask := task.NewTask("checkThsReportList", "0 30 16-20 * * *", data.InitPositionTask)
 	task.AddTask("checkThsReportList", InitPositionTask)
+
+	// 每日2:45更新每刻报销-客户档案
+	syncMaycurCompanyProfile := task.NewTask("syncMaycurCompanyProfile", "0 45 2 * * * ", maycur.DailyUpdateCompanyProfile)
+	task.AddTask("每日更新每刻报销-客户档案", syncMaycurCompanyProfile)
 }
 
 func TaskTest() {
@@ -351,7 +358,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 {
@@ -362,7 +369,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 {
@@ -373,7 +380,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 {
@@ -817,7 +824,7 @@ func deleteTask() {
 	}
 }
 
-//检测数据服务
+// 检测数据服务
 func checkDataServer(cont context.Context) (err error) {
 	//检测wind新服务器
 	go data.CheckWindDataInterface(cont)