package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type Longzhongdata struct { LongzhongdataId int `orm:"column(longzhongdata_id);pk"` LongzhonginfoId int TradeCode string Dt string Close float64 CreateTime time.Time ModifyTime time.Time UnitDesc string UpdTime string AddTime string DisplayTime string } type Longzhonginfo struct { LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"` TradeCode string SecName string Frequency string ClassifyId int ClassifyName string Unit string CreateTime time.Time Remark string IsNormal string LastModifyDate string Unitid int64 TempId int64 TempName string ModifyTime time.Time } func GetLongzhonginfoBySecName(secName string) (item *Longzhongdata, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhonginfo WHERE sec_name=? ` err = o.Raw(sql, secName).QueryRow(&item) return } //判断指标数据是否已经录入 func GetLongzhongdataCount(longzhonginfoId int, dt string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhongdata WHERE longzhonginfo_id=? AND dt=? ` err = o.Raw(sql, longzhonginfoId, dt).QueryRow(&count) return } func AddLongzhongdata(item *Longzhongdata) (err error) { o := orm.NewOrmUsingDB("edb") _, err = o.Insert(item) return } func ModifyLongzhongdata(item *Longzhongdata) (err error) { o := orm.NewOrmUsingDB("edb") sql := ` UPDATE longzhongdata SET close = ?, modify_time= NOW(), unit_desc= ?, upd_time = ?, add_time=?, display_time=? WHERE longzhonginfo_id = ? AND dt=? ` _, err = o.Raw(sql, item.Close, item.UnitDesc, item.UpdTime, item.AddTime, item.DisplayTime, item.LongzhonginfoId, item.Dt).Exec() return } func AddLongzhonginfo(item *Longzhonginfo) (newId int64, err error) { o := orm.NewOrmUsingDB("edb") newId, err = o.Insert(item) return } func ModifyLongzhonginfo(item *Longzhonginfo) (err error) { o := orm.NewOrmUsingDB("edb") sql := `UPDATE longzhonginfo SET sec_name = ?, unit = ?, frequency = ?, classify_id = ?, classify_name = ?, remark = ?, last_modify_date = ?, temp_name = ?, is_normal = ?, modify_time=NOW() WHERE unitid = ? AND temp_id = ? ` _, err = o.Raw(sql, item.SecName, item.Unit, item.Frequency, item.ClassifyId, item.ClassifyName, item.Remark, item.LastModifyDate, item.TempName, item.IsNormal, item.Unitid, item.TempId).Exec() return } //判断指标数据是否已经录入 func GetLongzhonginfoCount(classifyId int, unitid int64) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhonginfo WHERE classify_id=? AND unitid=? ` err = o.Raw(sql, classifyId, unitid).QueryRow(&count) return } //判断指标数据是否已经录入 func GetLongzhonginfoBySecNameCount(secName string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhonginfo WHERE sec_name=? ` err = o.Raw(sql, secName).QueryRow(&count) return } type LzProductInfoResp struct { Msg string `json:"msg"` Code string `json:"code"` Data []*LzProductInfo `json:"data"` } type LzProductInfo struct { Unitid int64 `json:"unitid"` ProUnitName string `json:"proUnitName"` Tempid int64 `json:"tempid"` TempName string `json:"tempName"` Proid int `json:"proid"` ProName string `json:"proName"` Unit string `json:"unit"` LzType string `json:"type"` Maxdate string `json:"maxdate"` IsNormal string `json:"isNormal"` } func GetLongzhonginfoMaxId() (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT MAX(longzhonginfo_id) AS count FROM longzhonginfo` err = o.Raw(sql).QueryRow(&count) return } type LzProductInfoDetail struct { UnitId int64 `json:"unit_id"` UnitName string `json:"unit_name"` TempId int `json:"temp_id"` TempName string `json:"temp_name"` TempUnit string `json:"temp_unit"` ProId int `json:"pro_id"` ProCnName string `json:"pro_cn_name"` UnitValue float64 `json:"unit_value"` UnitDesc string `json:"unit_desc"` DataTime string `json:"data_time"` UpdTime string `json:"upd_time"` AddTime string `json:"add_time"` DisplayTime string `json:"display_time"` } type LzProductInfoDetailResp struct { Msg string `json:"msg"` Code string `json:"code"` Data []*LzProductInfoDetail `json:"data"` Pagesize int `json:"pagesize"` Page int `json:"page"` } func GetLongzhonginfoByUnitId(classifyName string, unitId int64) (item *Longzhonginfo, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhonginfo WHERE unitid=? AND classify_name=?` err = o.Raw(sql, unitId, classifyName).QueryRow(&item) return } func GetLongzhongDataById(lzInfoId int) (items []*Longzhongdata, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhongdata WHERE longzhonginfo_id=? ORDER BY dt DESC ` _, err = o.Raw(sql, lzInfoId).QueryRows(&items) return } func GetLongzhongDataMaxCount(classifyId int) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num FROM longzhonginfo AS a INNER JOIN longzhongdata AS b ON a.longzhonginfo_id=b.longzhonginfo_id WHERE a.classify_id=? GROUP BY a.longzhonginfo_id )AS t ` err = o.Raw(sql, classifyId).QueryRow(&count) return } type LongzhonginfoList struct { LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"` TradeCode string SecName string Frequency string ClassifyId int ClassifyName string Unit string IsNormal string LastModifyDate string Unitid int } func GetLongzhonginfoList() (items []*LongzhonginfoList, err error) { o := orm.NewOrmUsingDB("edb") sql := ` SELECT * FROM longzhonginfo AS a ` _, err = o.Raw(sql).QueryRows(&items) return } func ModifyLongzhonginfoIsNormal(longzhonginfoId int) (err error) { o := orm.NewOrmUsingDB("edb") sql := ` UPDATE longzhonginfo SET is_normal=0 WHERE longzhonginfo_id=? ` _, err = o.Raw(sql, longzhonginfoId).Exec() return } type LzPriceInfo struct { Standard string `json:"standard"` ModelName string `json:"modelName"` Unit string `json:"unit"` AreaName string `json:"areaName"` PriceType string `json:"priceType"` Memo string `json:"memo"` Id string `json:"id"` ProductName string `json:"productName"` MarketName string `json:"marketName"` ManufactureName string `json:"manufactureName"` } type LzPriceInfoResp struct { Msg string `json:"msg"` Code int `json:"code"` Data []*LzPriceInfo `json:"data"` } type Longzhongpriceinfo struct { LongzhongpriceinfoId int `orm:"column(longzhongpriceinfo_id);pk"` Standard string ModelName string Unit string AreaName string PriceType string Memo string PriceId string ProductName string InfoType string InfoTypeRemark string MarketName string ManufactureName string } func AddLongzhongpriceinfo(item *Longzhongpriceinfo) (newId int64, err error) { o := orm.NewOrmUsingDB("edb") newId, err = o.Insert(item) return } //判断指标数据是否已经录入 func GetLongzhongpriceinfoCount(unitid string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhongpriceinfo WHERE price_id=? ` err = o.Raw(sql, unitid).QueryRow(&count) return } //判断指标数据是否已经录入 func GetLongzhongpriceinfo() (items []*Longzhongpriceinfo, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhongpriceinfo ` _, err = o.Raw(sql).QueryRows(&items) return } type Longzhongpricedata struct { LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"` LongzhongpriceinfoId int PriceDate string Memo string Price string CnyPrice string ZsyPrice string ZshPrice string LowPrice string HighPrice string RisePrice string TonPrice string PriceType string UpdateDate string } func AddLongzhongpricedata(item *Longzhongpricedata) (newId int64, err error) { o := orm.NewOrmUsingDB("edb") newId, err = o.Insert(item) return } //判断指标数据是否已经录入 func GetLongzhongpricedataCount(longzhongpriceinfoId int, priceDate string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhongpricedata WHERE longzhongpriceinfo_id=? AND price_date=? ` err = o.Raw(sql, longzhongpriceinfoId, priceDate).QueryRow(&count) return } type LzPriceData struct { Id string `json:"id"` PriceDate string `json:"priceDate"` Memo string `json:"memo"` Price string `json:"price"` CnyPrice string `json:"cnyPrice"` ZsyPrice string `json:"zsyPrice"` ZshPrice string `json:"zshPrice"` LowPrice string `json:"lowPrice"` HighPrice string `json:"highPrice"` RisePrice string `json:"risePrice"` TonPrice string `json:"tonPrice"` PriceType string `json:"priceType"` UpdateDate string `json:"updateDate"` } type LzPriceDataResp struct { Msg string `json:"msg"` Code int `json:"code"` Data []*LzPriceData `json:"data"` } func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id WHERE a.product_name=? GROUP BY a.product_name )AS t ` err = o.Raw(sql, productName).QueryRow(&count) return } type LongzhongpricedataItems struct { LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"` LongzhongpriceinfoId int PriceDate string Memo string Price float64 CnyPrice float64 ZsyPrice float64 ZshPrice float64 LowPrice float64 HighPrice float64 RisePrice float64 TonPrice float64 PriceType string UpdateDate string } func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhongpricedata WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC ` _, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items) return } func ModifyLongzhongpriceinfo(item *Longzhongpriceinfo) (err error) { o := orm.NewOrmUsingDB("edb") sql := `UPDATE longzhongpriceinfo SET standard = ?, model_name = ?, unit= ?, area_name=?, price_type = ?, memo = ?, market_name = ?, manufacture_name = ? WHERE price_id = ? ` _, err = o.Raw(sql, item.Standard, item.ModelName, item.Unit, item.AreaName, item.PriceType, item.Memo, item.MarketName, item.ManufactureName, item.PriceId).Exec() return } func GetDisplayTime(longzhonginfoId int) (display_time string, err error) { o := orm.NewOrmUsingDB("edb") sql := ` SELECT max(a.display_time) AS display_time FROM longzhongdata AS a WHERE a.longzhonginfo_id=? ` err = o.Raw(sql, longzhonginfoId).QueryRow(&display_time) return } type SurveyProduct struct { Message string `json:"message"` Response struct { List []struct { AreaName interface{} `json:"areaName"` BreedID string `json:"breedId"` BreedName string `json:"breedName"` Custom string `json:"custom"` CustomID string `json:"customId"` CustomType int64 `json:"customType"` Device string `json:"device"` DeviceID string `json:"deviceId"` Frequency int64 `json:"frequency"` InputMode int64 `json:"inputMode"` InputValue interface{} `json:"inputValue"` Labels interface{} `json:"labels"` ProductCraft string `json:"productCraft"` ProductCraftID string `json:"productCraftId"` ProductLine string `json:"productLine"` ProjectQuotaID int64 `json:"projectQuotaId"` ProvinceName interface{} `json:"provinceName"` QuotaID string `json:"quotaId"` QuotaName string `json:"quotaName"` QuotaSampleID int64 `json:"quotaSampleId"` ResearchStartDate interface{} `json:"researchStartDate"` ResearchStopDate interface{} `json:"researchStopDate"` SampleID string `json:"sampleId"` SampleName string `json:"sampleName"` SampleType int64 `json:"sampleType"` TaskActualFinishTime interface{} `json:"taskActualFinishTime"` TaskShouldFinishTime interface{} `json:"taskShouldFinishTime"` UnitID string `json:"unitId"` UnitName string `json:"unitName"` } `json:"list"` PageNum int64 `json:"pageNum"` PageSize int64 `json:"pageSize"` Pages int64 `json:"pages"` Total int64 `json:"total"` } `json:"response"` Status string `json:"status"` } type LongzhongSurveyProduct struct { SurveyProductId int `orm:"column(survey_product_id);pk"` ProjectQuotaId int64 BreedId string BreedName string QuotaId string QuotaName string UnitId string UnitName string SampleType int64 SampleId string SampleName string DeviceId string Device string ProductCraftId string ProductCraft string ProductLine string InputMode int64 Frequency int64 InputValue string TaskShouldFinishTime int CustomId string CustomType int64 Custom string QuotaSampleId int64 StartDate string EndDate string ModifyTime time.Time LzCode string } //判断指标数据是否已经录入 func GetLongzhongSurveyProductCount(quotaSampleId int64) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhong_survey_product WHERE quota_sample_id=? ` err = o.Raw(sql, quotaSampleId).QueryRow(&count) return } func AddLongzhongSurveyProduct(item *LongzhongSurveyProduct) (lastId int64, err error) { o := orm.NewOrmUsingDB("edb") lastId, err = o.Insert(item) return } func ModifLongzhongSurveyProduct(item *LongzhongSurveyProduct) (err error) { o := orm.NewOrmUsingDB("edb") sql := `UPDATE longzhong_survey_product SET breed_id = ?, breed_name = ?, quota_id= ?, quota_name=?, unit_id = ?, unit_name = ?, project_quota_id = ? WHERE quota_sample_id = ? ` _, err = o.Raw(sql, item.BreedId, item.BreedName, item.QuotaId, item.QuotaName, item.UnitId, item.UnitName, item.ProjectQuotaId, item.QuotaSampleId).Exec() return } //判断指标数据是否已经录入 func GetLongzhongSurveyList() (items []*LongzhongSurveyProduct, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhong_survey_product ORDER BY survey_product_id ASC` _, err = o.Raw(sql).QueryRows(&items) return } type LongzhongSurveyData struct { SurveyDataId int `orm:"column(survey_data_id);pk"` SurveyProductId int ProjectQuotaId int64 BreedId string BreedName string QuotaId string QuotaName string UnitId string UnitName string SampleType int64 SampleId string SampleName string DeviceId string Device string ProductCraftId string ProductCraft string ProductLine string InputMode int64 Frequency int64 InputValue string TaskShouldFinishTime int64 CustomId string CustomType int64 Custom string QuotaSampleId int64 TaskActualFinishTime int64 AreaName string ProvinceName string ResearchStartData int64 ResearchStopData int64 DataTime string } func AddLongzhongSurveyData(item *LongzhongSurveyData) (err error) { o := orm.NewOrmUsingDB("edb") _, err = o.Insert(item) return } type LzSurveyData struct { Message string `json:"message"` Response struct { List []struct { AreaName interface{} `json:"areaName"` BreedID string `json:"breedId"` BreedName string `json:"breedName"` Custom string `json:"custom"` CustomID string `json:"customId"` CustomType int64 `json:"customType"` Device string `json:"device"` DeviceID string `json:"deviceId"` Frequency int64 `json:"frequency"` InputMode int64 `json:"inputMode"` InputValue string `json:"inputValue"` Labels interface{} `json:"labels"` ProductCraft string `json:"productCraft"` ProductCraftID string `json:"productCraftId"` ProductLine string `json:"productLine"` ProjectQuotaID int64 `json:"projectQuotaId"` ProvinceName interface{} `json:"provinceName"` QuotaID string `json:"quotaId"` QuotaName string `json:"quotaName"` QuotaSampleID int64 `json:"quotaSampleId"` ResearchStartDate int64 `json:"researchStartDate"` ResearchStopDate int64 `json:"researchStopDate"` SampleID string `json:"sampleId"` SampleName string `json:"sampleName"` SampleType int64 `json:"sampleType"` TaskActualFinishTime int64 `json:"taskActualFinishTime"` TaskShouldFinishTime int64 `json:"taskShouldFinishTime"` UnitID string `json:"unitId"` UnitName string `json:"unitName"` } `json:"list"` PageNum int64 `json:"pageNum"` PageSize int64 `json:"pageSize"` Pages int64 `json:"pages"` Total int64 `json:"total"` } `json:"response"` Status string `json:"status"` } //判断指标数据是否已经录入 func GetLzSurveyDataCount(surveyProductId, quotaSampleId int, dataTime string) (count int, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT COUNT(1) AS count FROM longzhong_survey_data WHERE survey_product_id=? AND quota_sample_id=? AND data_time=? ` err = o.Raw(sql, surveyProductId, quotaSampleId, dataTime).QueryRow(&count) return } type LzSurveyMaxAndMinInfo struct { MinDate string `description:"最小日期"` MaxDate string `description:"最大日期"` MinValue float64 `description:"最小值"` MaxValue float64 `description:"最大值"` } func GetLzSurveyMaxAndMinInfo(surveyProductId, quotaSampleId int) (item *LzSurveyMaxAndMinInfo, err error) { o := orm.NewOrmUsingDB("edb") sql := `` sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(input_value) AS min_value,MAX(input_value) AS max_value FROM longzhong_survey_data WHERE survey_product_id=? AND quota_sample_id=? ` err = o.Raw(sql, surveyProductId, quotaSampleId).QueryRow(&item) return } func ModifyLzSurveyMaxAndMinInfo(item *LzSurveyMaxAndMinInfo, surveyProductId int) (err error) { o := orm.NewOrmUsingDB("edb") sql := ` UPDATE longzhong_survey_product SET start_date=?,end_date=?,min_value=?,max_value=? WHERE survey_product_id=? ` _, 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.NewOrmUsingDB("edb") sql := `UPDATE longzhong_survey_product SET lz_code= ?,modify_time=NOW() WHERE survey_product_id = ? ` _, err = o.Raw(sql, lzCode, surveyProductId).Exec() return } //判断指标数据是否已经录入 func GetLongzhongSurveyProductItem(quotaSampleId int64) (item *LongzhongSurveyProduct, err error) { o := orm.NewOrmUsingDB("edb") sql := `SELECT * FROM longzhong_survey_product WHERE quota_sample_id=? ` err = o.Raw(sql, quotaSampleId).QueryRow(&item) return } func ModifyLzSurveyData(inputValue string, surveyDataId int) (err error) { o := orm.NewOrmUsingDB("edb") sql := ` UPDATE longzhong_survey_data SET input_value=? WHERE survey_data_id=? ` _, 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 }