Sfoglia il codice sorgente

Merge branch 'dev/maycur' into debug

hsun 2 anni fa
parent
commit
733e0766ec
3 ha cambiato i file con 86 aggiunte e 8 eliminazioni
  1. 15 5
      services/data/edb_info.go
  2. 61 0
      services/maycur/maycur.go
  3. 10 3
      services/task.go

+ 15 - 5
services/data/edb_info.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hongze_task/models/data_manage"
 	"hongze/hongze_task/services/alarm_msg"
 	"hongze/hongze_task/utils"
+	"strings"
 	"sync"
 )
 
@@ -1484,11 +1485,17 @@ func RefreshDataFromZz(wg *sync.WaitGroup) (err error) {
 
 // RefreshDataFromLt 刷新路透数据
 func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
+	errMsgList := make([]string,0)
 	defer func() {
-		if err != nil {
-			fmt.Println("RefreshDataFromLt Err:" + err.Error())
+		//if err != nil {
+		//	fmt.Println("RefreshDataFromLt Err:" + err.Error())
+		//	//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		//	go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+err.Error(), 3)
+		//}
+		if len(errMsgList)>0{
+			fmt.Println("RefreshDataFromLt Err:" , errMsgList)
 			//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
-			go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+err.Error(), 3)
+			go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+strings.Join(errMsgList,`<br/>`), 3)
 		}
 		wg.Done()
 	}()
@@ -1498,6 +1505,7 @@ func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
 	pars = append(pars, utils.DATA_SOURCE_LT)
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
+		errMsgList = append(errMsgList,"GetEdbInfoByCondition:" + err.Error())
 		return errors.New("GetEdbInfoByCondition:" + err.Error())
 	}
 
@@ -1510,10 +1518,12 @@ func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
 		//}
 		resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
 		if err != nil {
-			return errors.New("RefreshEdbData Err:" + err.Error())
+			errMsgList = append(errMsgList,"RefreshEdbData Err:" + err.Error())
+			continue
 		}
 		if resp.Ret != 200 {
-			return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
+			errMsgList = append(errMsgList,"RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
+			continue
 		}
 		//更新指标的最新数据
 		//item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)

+ 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
+}

+ 10 - 3
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"
@@ -145,10 +146,12 @@ func Task() {
 }
 
 //func Task() {
-//	fmt.Println("start")
+//	fmt.Println("start task")
+//
 //	cont := new(context.Context)
-//	CheckBusinessTripApply(*cont)
-//	fmt.Println("end")
+//	_ = maycur.DailyUpdateCompanyProfile(*cont)
+//
+//	fmt.Println("end task")
 //}
 
 // 生产环境需要走的任务
@@ -218,6 +221,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() {