瀏覽代碼

修改隆众数据同步bug

longyu 2 年之前
父節點
當前提交
5bf9a0c1a3
共有 2 個文件被更改,包括 67 次插入10 次删除
  1. 7 0
      models/data_source_longzhong.go
  2. 60 10
      services/data_source_longzhong.go

+ 7 - 0
models/data_source_longzhong.go

@@ -635,3 +635,10 @@ func ModifyLzSurveyData(inputValue string, surveyDataId int) (err error) {
 	_, err = o.Raw(sql, inputValue, surveyDataId).Exec()
 	return
 }
+
+func ModifyLzSurveyDataV1(inputValue string, quotaSampleId int,shouldDateTimeStr string) (err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := ` UPDATE longzhong_survey_data SET input_value=? WHERE quota_sample_id=? AND data_time=? `
+	_, err = o.Raw(sql, inputValue, quotaSampleId,shouldDateTimeStr).Exec()
+	return
+}

+ 60 - 10
services/data_source_longzhong.go

@@ -1096,7 +1096,8 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
 		existList, err := data_manage.GetLzSurveyDataExistByTradeCode(v.SurveyProductId)
 		existMap := make(map[string]*data_manage.LongzhongSurveyData)
 		for _, v := range existList {
-			existMap[v.DataTime] = v
+			key := strconv.Itoa(int(v.QuotaSampleId)) + v.DataTime
+			existMap[key] = v
 		}
 		fmt.Println(existMap)
 		pageIndex := 1
@@ -1156,12 +1157,14 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
 					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 findItem, ok := existMap[shouldDateTimeStr]; !ok && n.InputValue != "0" {
+					count, err := models.GetLzSurveyDataCount(v.SurveyProductId, int(v.QuotaSampleId), shouldDateTimeStr)
+					if err != nil {
+						msg = "获取隆众调研指标数据失败:err " + err.Error()
+						return err
+					}
+					key := strconv.Itoa(int(v.QuotaSampleId)) + shouldDateTimeStr
+					if count <= 0 {
+						fmt.Println("not exist:" + key)
 						item := new(models.LongzhongSurveyData)
 						item.SurveyProductId = v.SurveyProductId
 						item.ProjectQuotaId = n.ProjectQuotaID
@@ -1199,11 +1202,58 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
 							return err
 						}
 					} else {
-						if findItem != nil && findItem.InputValue != n.InputValue && n.InputValue != "0" {
-							models.ModifyLzSurveyData(n.InputValue, findItem.SurveyDataId)
+						fmt.Println("exist:" + key)
+						err = models.ModifyLzSurveyDataV1(n.InputValue, int(n.QuotaSampleID), shouldDateTimeStr)
+						if err != nil {
+							fmt.Println("ModifyLzSurveyDataV1 Err:" + err.Error())
 						}
-						fmt.Println("exist:", shouldDateTimeStr)
 					}
+					//key:=strconv.Itoa(int(v.QuotaSampleId))+shouldDateTimeStr
+					//if findItem, ok := existMap[key]; !ok && n.InputValue != "0" {
+					//	fmt.Println("not exist:"+key)
+					//	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:"+key)
+					//	if findItem != nil && findItem.InputValue != n.InputValue && n.InputValue != "0" {
+					//		models.ModifyLzSurveyData(n.InputValue, findItem.SurveyDataId)
+					//	}
+					//	fmt.Println("exist:", shouldDateTimeStr)
+					//}
 				}
 				pageIndex = pageIndex + 1
 				totalPage := utils.PageCount(int(dataList.Response.Total), 100)