|
@@ -7,12 +7,14 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"hongze/hongze_task/models"
|
|
|
+ "hongze/hongze_task/models/data_manage"
|
|
|
"hongze/hongze_task/utils"
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"rdluck_tools/http"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -1077,18 +1079,29 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
|
|
|
paramMap["passWord"] = password
|
|
|
paramMap["pageSize"] = 100
|
|
|
|
|
|
- startDate := time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
|
|
|
+ //startDate := time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
|
|
|
+ startDateTime,_ := time.Parse(utils.FormatDate,"2018-01-01")
|
|
|
+ startDate := startDateTime.UnixNano()/1e6
|
|
|
endDate := time.Now().UnixNano() / 1e6
|
|
|
|
|
|
for k, v := range priceInfoList {
|
|
|
- pageIndex := 1
|
|
|
- if v.EndDate != "" {
|
|
|
- endDateTime, _ := time.Parse(utils.FormatDate, v.EndDate)
|
|
|
- startDate = endDateTime.UnixNano() / 1e6
|
|
|
+ existList, err := data_manage.GetLzSurveyDataExistByTradeCode(v.SurveyProductId)
|
|
|
+ existMap := make(map[string]string)
|
|
|
+ for _, v := range existList {
|
|
|
+ existMap[v.DataTime] = v.InputValue
|
|
|
}
|
|
|
+ fmt.Println(existMap)
|
|
|
+ pageIndex := 1
|
|
|
+ //if v.EndDate != "" {
|
|
|
+ // endDateTime, _ := time.Parse(utils.FormatDate, v.EndDate)
|
|
|
+ // startDate = endDateTime.UnixNano() / 1e6
|
|
|
+ //}
|
|
|
if startDate < 0 {
|
|
|
startDate = time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
|
|
|
}
|
|
|
+ fmt.Println("startDate:" + time.Now().AddDate(-4, 0, 0).Format(utils.FormatDate))
|
|
|
+ fmt.Println("endDate:" + time.Now().Format(utils.FormatDate))
|
|
|
+
|
|
|
for {
|
|
|
paramMap["pageNum"] = pageIndex
|
|
|
paramMap["projectQuotaId"] = v.ProjectQuotaId
|
|
@@ -1102,79 +1115,84 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
|
|
|
if err != nil {
|
|
|
fmt.Println("postData Err:", err.Error())
|
|
|
}
|
|
|
+ fmt.Println("getUrl:" + getUrl)
|
|
|
utils.FileLogLz.Info("GetLzSurveyProductData postData:" + string(postData))
|
|
|
body, err := http.Post(getUrl, string(postData), "application/json")
|
|
|
if err != nil {
|
|
|
msg = "获取隆众调研指标数据失败:Err" + err.Error()
|
|
|
return err
|
|
|
}
|
|
|
- utils.FileLogLz.Info("GetLzSurveyProductData:" + string(body))
|
|
|
- dataList := new(models.LzSurveyData)
|
|
|
- err = json.Unmarshal(body, &dataList)
|
|
|
- if err != nil {
|
|
|
- msg = "获取隆众调研指标数据失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
|
|
|
- return err
|
|
|
- }
|
|
|
- if dataList.Status != "200" {
|
|
|
- msg = "获取隆众调研指标数据失败:body " + string(body)
|
|
|
- return nil
|
|
|
- }
|
|
|
- for _, n := range dataList.Response.List {
|
|
|
- //dateTime := time.Unix(n.TaskActualFinishTime/1000, 0)
|
|
|
- //dateTimeStr := dateTime.Format(utils.FormatDate)
|
|
|
-
|
|
|
- shouldDateTime := time.Unix(n.TaskShouldFinishTime/1000, 0)
|
|
|
- shouldDateTimeStr := shouldDateTime.Format(utils.FormatDate)
|
|
|
-
|
|
|
- //fmt.Println("QuotaSampleID:", n.QuotaSampleID, "taskActualFinishTime:", dateTimeStr, "taskShouldFinishTime:", shouldDateTimeStr)
|
|
|
- count, err := models.GetLzSurveyDataCount(v.SurveyProductId, int(v.QuotaSampleId), shouldDateTimeStr)
|
|
|
+ if !strings.Contains(string(body), "<html>") {
|
|
|
+ utils.FileLogLz.Info("GetLzSurveyProductData:" + string(body))
|
|
|
+ dataList := new(models.LzSurveyData)
|
|
|
+ err = json.Unmarshal(body, &dataList)
|
|
|
if err != nil {
|
|
|
- msg = "获取隆众调研指标数据失败:err " + err.Error()
|
|
|
+ msg = "获取隆众调研指标数据失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
|
|
|
return err
|
|
|
}
|
|
|
- if count <= 0 {
|
|
|
- item := new(models.LongzhongSurveyData)
|
|
|
- item.SurveyProductId = v.SurveyProductId
|
|
|
- item.ProjectQuotaId = n.ProjectQuotaID
|
|
|
- item.BreedId = n.BreedID
|
|
|
- item.BreedName = n.BreedName
|
|
|
- item.QuotaId = n.QuotaID
|
|
|
- item.QuotaName = n.QuotaName
|
|
|
- item.UnitId = n.UnitID
|
|
|
- item.UnitName = n.UnitName
|
|
|
- item.SampleType = n.SampleType
|
|
|
- item.SampleId = n.SampleID
|
|
|
- item.SampleName = n.SampleName
|
|
|
- item.DeviceId = n.DeviceID
|
|
|
- item.Device = n.Device
|
|
|
- item.ProductCraftId = n.ProductCraftID
|
|
|
- item.ProductCraft = n.ProductCraft
|
|
|
- item.ProductLine = n.ProductLine
|
|
|
- item.InputMode = n.InputMode
|
|
|
- item.Frequency = n.Frequency
|
|
|
- item.InputValue = n.InputValue
|
|
|
- item.TaskShouldFinishTime = n.TaskShouldFinishTime
|
|
|
- item.CustomId = n.CustomID
|
|
|
- item.CustomType = n.CustomType
|
|
|
- item.Custom = n.Custom
|
|
|
- item.QuotaSampleId = n.QuotaSampleID
|
|
|
- item.TaskActualFinishTime = n.TaskActualFinishTime
|
|
|
- //item.AreaName = n.AreaName.(string)
|
|
|
- //item.ProvinceName = n.ProvinceName.(string)
|
|
|
- item.ResearchStartData = n.ResearchStartDate
|
|
|
- item.ResearchStopData = n.ResearchStopDate
|
|
|
- item.DataTime = shouldDateTimeStr
|
|
|
- err = models.AddLongzhongSurveyData(item)
|
|
|
- if err != nil {
|
|
|
- msg = "新增调研指标数据失败:err " + err.Error()
|
|
|
- return err
|
|
|
+ if dataList.Status != "200" {
|
|
|
+ msg = "获取隆众调研指标数据失败:body " + string(body)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for _, n := range dataList.Response.List {
|
|
|
+ //dateTime := time.Unix(n.TaskActualFinishTime/1000, 0)
|
|
|
+ //dateTimeStr := dateTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ shouldDateTime := time.Unix(n.TaskShouldFinishTime/1000, 0)
|
|
|
+ shouldDateTimeStr := shouldDateTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ //fmt.Println("QuotaSampleID:", n.QuotaSampleID, "taskActualFinishTime:", dateTimeStr, "taskShouldFinishTime:", shouldDateTimeStr)
|
|
|
+ //count, err := models.GetLzSurveyDataCount(v.SurveyProductId, int(v.QuotaSampleId), shouldDateTimeStr)
|
|
|
+ //if err != nil {
|
|
|
+ // msg = "获取隆众调研指标数据失败:err " + err.Error()
|
|
|
+ // return err
|
|
|
+ //}
|
|
|
+ if _, ok := existMap[shouldDateTimeStr]; !ok {
|
|
|
+ item := new(models.LongzhongSurveyData)
|
|
|
+ item.SurveyProductId = v.SurveyProductId
|
|
|
+ item.ProjectQuotaId = n.ProjectQuotaID
|
|
|
+ item.BreedId = n.BreedID
|
|
|
+ item.BreedName = n.BreedName
|
|
|
+ item.QuotaId = n.QuotaID
|
|
|
+ item.QuotaName = n.QuotaName
|
|
|
+ item.UnitId = n.UnitID
|
|
|
+ item.UnitName = n.UnitName
|
|
|
+ item.SampleType = n.SampleType
|
|
|
+ item.SampleId = n.SampleID
|
|
|
+ item.SampleName = n.SampleName
|
|
|
+ item.DeviceId = n.DeviceID
|
|
|
+ item.Device = n.Device
|
|
|
+ item.ProductCraftId = n.ProductCraftID
|
|
|
+ item.ProductCraft = n.ProductCraft
|
|
|
+ item.ProductLine = n.ProductLine
|
|
|
+ item.InputMode = n.InputMode
|
|
|
+ item.Frequency = n.Frequency
|
|
|
+ item.InputValue = n.InputValue
|
|
|
+ item.TaskShouldFinishTime = n.TaskShouldFinishTime
|
|
|
+ item.CustomId = n.CustomID
|
|
|
+ item.CustomType = n.CustomType
|
|
|
+ item.Custom = n.Custom
|
|
|
+ item.QuotaSampleId = n.QuotaSampleID
|
|
|
+ item.TaskActualFinishTime = n.TaskActualFinishTime
|
|
|
+ //item.AreaName = n.AreaName.(string)
|
|
|
+ //item.ProvinceName = n.ProvinceName.(string)
|
|
|
+ item.ResearchStartData = n.ResearchStartDate
|
|
|
+ item.ResearchStopData = n.ResearchStopDate
|
|
|
+ item.DataTime = shouldDateTimeStr
|
|
|
+ err = models.AddLongzhongSurveyData(item)
|
|
|
+ if err != nil {
|
|
|
+ msg = "新增调研指标数据失败:err " + err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("exist:", shouldDateTimeStr)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- pageIndex = pageIndex + 1
|
|
|
- totalPage := utils.PageCount(int(dataList.Response.Total), 100)
|
|
|
- if pageIndex > totalPage {
|
|
|
- break
|
|
|
+ pageIndex = pageIndex + 1
|
|
|
+ totalPage := utils.PageCount(int(dataList.Response.Total), 100)
|
|
|
+ if pageIndex > totalPage {
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|