瀏覽代碼

新增指标编码

hongze 3 年之前
父節點
當前提交
ef4a05a09f
共有 2 個文件被更改,包括 37 次插入3 次删除
  1. 23 2
      models/data_source_longzhong.go
  2. 14 1
      services/data_source_longzhong.go

+ 23 - 2
models/data_source_longzhong.go

@@ -480,6 +480,8 @@ type LongzhongSurveyProduct struct {
 	QuotaSampleId        int64
 	StartDate            string
 	EndDate              string
+	ModifyTime           time.Time
+	LzCode               string
 }
 
 //判断指标数据是否已经录入
@@ -491,10 +493,10 @@ func GetLongzhongSurveyProductCount(quotaSampleId int64) (count int, err error)
 	return
 }
 
-func AddLongzhongSurveyProduct(item *LongzhongSurveyProduct) (err error) {
+func AddLongzhongSurveyProduct(item *LongzhongSurveyProduct) (lastId int64, err error) {
 	o := orm.NewOrm()
 	o.Using("edb")
-	_, err = o.Insert(item)
+	lastId, err = o.Insert(item)
 	return
 }
 
@@ -640,3 +642,22 @@ func ModifyLzSurveyMaxAndMinInfo(item *LzSurveyMaxAndMinInfo, surveyProductId in
 	_, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, surveyProductId).Exec()
 	return
 }
+
+func ModifLongzhongSurveyProductCode(lzCode string, surveyProductId int) (err error) {
+	o := orm.NewOrm()
+	o.Using("edb")
+	sql := `UPDATE  longzhong_survey_product
+			SET lz_code= ?
+			WHERE survey_product_id = ? `
+	_, err = o.Raw(sql, lzCode, surveyProductId).Exec()
+	return
+}
+
+//判断指标数据是否已经录入
+func GetLongzhongSurveyProductItem(quotaSampleId int64) (item *LongzhongSurveyProduct, err error) {
+	o := orm.NewOrm()
+	o.Using("edb")
+	sql := `SELECT * FROM longzhong_survey_product WHERE quota_sample_id=? `
+	err = o.Raw(sql, quotaSampleId).QueryRow(&item)
+	return
+}

+ 14 - 1
services/data_source_longzhong.go

@@ -1011,6 +1011,7 @@ func GetLzSurveyProduct(cont context.Context) (err error) {
 			item.CustomType = n.CustomType
 			item.Custom = n.Custom
 			item.QuotaSampleId = n.QuotaSampleID
+			item.ModifyTime = time.Now()
 			if count > 0 {
 				fmt.Println("存在", n.QuotaName, n.QuotaSampleID)
 				//修改
@@ -1019,12 +1020,24 @@ func GetLzSurveyProduct(cont context.Context) (err error) {
 					msg = "修改隆众价格指标失败:err " + err.Error()
 					return err
 				}
+				existItem, err := models.GetLongzhongSurveyProductItem(n.QuotaSampleID)
+				if err != nil {
+					msg = "获取已存在隆众指标信息失败:err " + err.Error()
+					return err
+				}
+				if existItem != nil {
+					surveyProductId := existItem.SurveyProductId
+					lzCode := fmt.Sprintf("lz%04d", surveyProductId)
+					models.ModifLongzhongSurveyProductCode(lzCode, surveyProductId)
+				}
 			} else {
-				err = models.AddLongzhongSurveyProduct(item)
+				lastId, err := models.AddLongzhongSurveyProduct(item)
 				if err != nil {
 					msg = "新增隆众价格指标失败:err " + err.Error()
 					return err
 				}
+				lzCode := fmt.Sprintf("lz%04d", lastId)
+				models.ModifLongzhongSurveyProductCode(lzCode, int(lastId))
 			}
 		}
 		totalPage := utils.PageCount(int(infoItem.Response.Total), 100)