123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542 |
- package base_from_hisugar
- import (
- "context"
- "encoding/json"
- "eta/eta_data_analysis/models"
- "eta/eta_data_analysis/utils"
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
- "net/url"
- "strconv"
- "strings"
- "time"
- )
- // 国产糖
- var GuochantangList = []string{
- "国内食糖月度累计销售均价",
- "国内食糖月度销售均价",
- "全国食糖累计产销率",
- "全国单月产糖量",
- "全国单月销糖量",
- "国内月度工业库存",
- "全国月度累计糖产量",
- "全国月度累计糖销量",
- "国内白糖产区现货价格",
- "国内制糖集团报价",
- "国内加工糖集团报价",
- "全国单月甘蔗糖产量",
- "全国单月甘蔗糖销量",
- "全国单月甜菜产糖量",
- "全国单月甜菜糖销量",
- "广西单月产糖量",
- "广西单月销糖量",
- "广西月度库存",
- "云南单月产糖量",
- "云南单月销糖量",
- "云南月度库存",
- "海南单月产糖量",
- "海南单月销糖量",
- "海南月度库存",
- "广东单月产糖量",
- "广东单月销糖量",
- "广东月度库存",
- "新疆单月产糖量",
- "新疆单月销糖量",
- "新疆月度库存",
- "内蒙单月产糖量",
- "内蒙单月销糖量",
- "内蒙月度库存",
- "食糖月度进口量",
- "巴西港口等待船只数量",
- "巴西港口最大等待天数",
- "巴西港口待装运食糖数量",
- "周度含水乙醇折糖价",
- "巴西双周累计产糖量",
- "巴西双周食糖库存",
- "巴西食糖月度出口量",
- "中南部双周累计产糖量",
- "中南部双周糖库存",
- "中南部双周乙醇产量",
- "巴西双周甘蔗累计入榨量",
- "中南部双周甘蔗压榨量",
- "中南部双周制糖比",
- "巴西双周甘蔗入榨量",
- "巴西中南部乙醇月度销售情况",
- "巴西中南部乙醇国内销售情况",
- "巴西双周无水乙醇库存",
- "巴西双周水合乙醇库存",
- "印度食糖月度出口量",
- "印度双周累计产糖量",
- "泰国双周糖累计产量",
- "泛糖副产品平台桔水成交价格指数",
- }
- var HisugarGuoChanTangParmsMap = map[string]string{
- "国内食糖月度累计销售均价": shiTangYueDuLeiJiXiaoShouJunJia,
- "国内食糖月度销售均价": shiTangYueDuXiaoShouJunJia,
- "全国食糖累计产销率": shiTangLeiJiChanXiaoLv,
- "全国单月产糖量": quanGuoDanYueChanTangLiang,
- "全国单月销糖量": quanGuoDanYueXiaoTangLiang,
- "国内月度工业库存": guoNeiYueDuGongYeKuCun,
- "全国月度累计糖产量": quanGuoYueDuLeiJiTangChanLiang,
- "全国月度累计糖销量": quanGuoYueDuLeiJiTangXiaoLiang,
- "国内白糖产区现货价格": guoNeiBaiTangChanQuXianHuoJiaGe,
- "国内制糖集团报价": guoNeiZhiTangJiTuanBaoJia,
- "国内加工糖集团报价": guoNeiJiaGongTangJiTuanBaoJia,
- "广西单月产糖量": guangXiDanYueChanTangLiang,
- "广西单月销糖量": guangXiDanYueXiaoTangLiang,
- "广西月度库存": guangXiYueDuKuCun,
- "云南单月产糖量": yunNanDanYueChanTangLiang,
- "云南单月销糖量": yunNanDanYueXiaoTangLiang,
- "云南月度库存": yunNanYueDukuCun,
- "海南单月产糖量": haiNanDanYueChanTangLiang,
- "海南单月销糖量": haiNanDanyueXiaoTangliang,
- "海南月度库存": haiNanYueduKuCun,
- "广东单月产糖量": guangDongDanYueChanTangLiang,
- "广东单月销糖量": guangDongDanYueXiaoTangLiang,
- "广东月度库存": guangDongYueDuKuCun,
- "新疆单月产糖量": xinJiangDanYueChanTangLiang,
- "新疆单月销糖量": xinJiangDanYueXiaoTangLiang,
- "新疆月度库存": xinJiangYueDuKuCun,
- "内蒙单月产糖量": neiMengDanYueChanTangLiang,
- "内蒙单月销糖量": neiMengDanYueXiaoTangLiang,
- "内蒙月度库存": neiMengYueDuKuCun,
- "食糖月度进口量": shiTangYueDuJinKouLiang,
- "巴西港口等待船只数量": baXiGangKouDengDaiChuanZhiShuLiang,
- "巴西港口最大等待天数": baXiGangKouZuiDaDengDaiTianShu,
- "巴西港口待装运食糖数量": baXiGangKouDaiZhuangYunShiTiaoShangShuLiang,
- "周度含水乙醇折糖价": zhouDuHanShuiYiChunZheTangJia,
- "巴西双周累计产糖量": baXiShuangZhouLeiJiChanTangLiang,
- "巴西双周食糖库存": baXiShuangZhouShiTangKuCun,
- "巴西食糖月度出口量": baXiShiTangYueDuChuKouLiang,
- "中南部双周累计产糖量": zhongNanShuangZhouLiJiChanTangLiang,
- "中南部双周糖库存": zhongNanShuangZhouTangKuCun,
- "中南部双周乙醇产量": zhongNanShuangZhouXianHuoChanLiang,
- "巴西双周甘蔗累计入榨量": baXiShuangZhouGanZheLeiJiRuZhaLiang,
- "中南部双周甘蔗压榨量": zhongNanBuShuangZhouGanZheYaZhaLiang,
- "中南部双周制糖比": zhongNanBuShuangZhouZHiTangBi,
- "巴西双周甘蔗入榨量": baXiShuangZhouGanZheRuZhaLiang,
- "巴西中南部乙醇月度销售情况": baXiZhongNanBuYiChunYueDuXiaoShouQingKuang,
- "巴西中南部乙醇国内销售情况": baXiZhongNanBuYiChunGuoNeiXiaoShouQingKuang,
- "巴西双周无水乙醇库存": baXiShuangZhouWuShuiYiChunKuCun,
- "巴西双周水合乙醇库存": baXiShuangZhouShuiHeYiChunKuCun,
- "印度食糖月度出口量": yinDuShiTangYueDuChuKouLiang,
- "印度双周累计产糖量": yinDuShuangZhouLeiJiChanTangLiang,
- "泰国双周糖累计产量": taiGuoShuangZhouTangLeiJiChanLiang,
- "泛糖副产品平台桔水成交价格指数": JuShuiChengJIaoJiaGeZhiShu,
- "全国单月甘蔗糖产量": quanGuoDanYueGanZheTangChanLiang,
- "全国单月甘蔗糖销量": quanGuoDanYueGanZheTangXiaoLiang,
- "全国单月甜菜产糖量": quanGuoDanYueTianCaiChanLiang,
- "全国单月甜菜糖销量": quanGuoDanYueTianCaiXiaoLiang,
- }
- var HisugarGuoChanTangUnitMap = map[string]string{
- "国内食糖月度累计销售均价": "元/吨",
- "国内食糖月度销售均价": "元/吨",
- "全国食糖累计产销率": "%",
- "全国单月产糖量": "万吨",
- "全国单月销糖量": "万吨",
- "国内月度工业库存": "万吨",
- "全国月度累计糖产量": "万吨",
- "全国月度累计糖销量": "万吨",
- "国内白糖产区现货价格": "元/吨",
- "国内制糖集团报价": "元/吨",
- "国内加工糖集团报价": "元/吨",
- "广西单月产糖量": "万吨",
- "广西单月销糖量": "万吨",
- "广西月度库存": "万吨",
- "云南单月产糖量": "万吨",
- "云南单月销糖量": "万吨",
- "云南月度库存": "万吨",
- "海南单月产糖量": "万吨",
- "海南单月销糖量": "万吨",
- "海南月度库存": "万吨",
- "广东单月产糖量": "万吨",
- "广东单月销糖量": "万吨",
- "广东月度库存": "万吨",
- "新疆单月产糖量": "万吨",
- "新疆单月销糖量": "万吨",
- "新疆月度库存": "万吨",
- "内蒙单月产糖量": "万吨",
- "内蒙单月销糖量": "万吨",
- "内蒙月度库存": "万吨",
- "食糖月度进口量": "万吨",
- "巴西港口等待船只数量": "艘",
- "巴西港口最大等待天数": "天",
- "巴西港口待装运食糖数量": "万吨",
- "周度含水乙醇折糖价": "美分/磅",
- "巴西双周累计产糖量": "万吨",
- "巴西双周食糖库存": "万吨",
- "巴西食糖月度出口量": "万吨",
- "中南部双周累计产糖量": "万吨",
- "中南部双周糖库存": "万吨",
- "中南部双周乙醇产量": "立方米",
- "巴西双周甘蔗累计入榨量": "万吨",
- "中南部双周甘蔗压榨量": "吨",
- "中南部双周制糖比": "%",
- "巴西双周甘蔗入榨量": "万吨",
- "巴西中南部乙醇月度销售情况": "万立方米",
- "巴西中南部乙醇国内销售情况": "万立方米",
- "巴西双周无水乙醇库存": "万立方米",
- "巴西双周水合乙醇库存": "万立方米",
- "印度食糖月度出口量": "万吨",
- "印度双周累计产糖量": "万吨",
- "泰国双周糖累计产量": "万吨",
- "全国单月甘蔗糖产量": "万吨",
- "全国单月甘蔗糖销量": "万吨",
- "全国单月甜菜产糖量": "万吨",
- "全国单月甜菜糖销量": "万吨",
- }
- var HisugarTaskAnalysisHandlers = map[string]func(name, reqParam, body string) (err error){
- "国内食糖月度累计销售均价": AnalysisHiSugar,
- "国内食糖月度销售均价": AnalysisHiSugar,
- "全国食糖累计产销率": AnalysisHiSugar3,
- "全国单月产糖量": AnalysisHiSugar3,
- "全国单月销糖量": AnalysisHiSugar3,
- "国内月度工业库存": AnalysisHiSugar3,
- "全国月度累计糖产量": AnalysisHiSugar4,
- "全国月度累计糖销量": AnalysisHiSugar4,
- "国内白糖产区现货价格": AnalysisHiSugar5,
- "国内制糖集团报价": AnalysisHiSugar5,
- "国内加工糖集团报价": AnalysisHiSugar5,
- "全国单月甘蔗糖产量": AnalysisHiSugar3,
- "全国单月甘蔗糖销量": AnalysisHiSugar3,
- "全国单月甜菜产糖量": AnalysisHiSugar3,
- "全国单月甜菜糖销量": AnalysisHiSugar3,
- "广西单月产糖量": AnalysisHiSugar,
- "广西单月销糖量": AnalysisHiSugar,
- "广西月度库存": AnalysisHiSugar,
- "云南单月产糖量": AnalysisHiSugar,
- "云南单月销糖量": AnalysisHiSugar,
- "云南月度库存": AnalysisHiSugar,
- "海南单月产糖量": AnalysisHiSugar,
- "海南单月销糖量": AnalysisHiSugar,
- "海南月度库存": AnalysisHiSugar,
- "广东单月产糖量": AnalysisHiSugar,
- "广东单月销糖量": AnalysisHiSugar,
- "广东月度库存": AnalysisHiSugar,
- "新疆单月产糖量": AnalysisHiSugar,
- "新疆单月销糖量": AnalysisHiSugar,
- "新疆月度库存": AnalysisHiSugar,
- "内蒙单月产糖量": AnalysisHiSugar,
- "内蒙单月销糖量": AnalysisHiSugar,
- "内蒙月度库存": AnalysisHiSugar,
- "食糖月度进口量": AnalysisHiSugar6,
- "巴西港口等待船只数量": AnalysisHiSugar7,
- "巴西港口最大等待天数": AnalysisHiSugar7,
- "巴西港口待装运食糖数量": AnalysisHiSugar7,
- "周度含水乙醇折糖价": AnalysisHiSugar5,
- "巴西双周累计产糖量": AnalysisHiSugar11,
- "巴西双周食糖库存": AnalysisHiSugar12,
- "巴西食糖月度出口量": AnalysisHiSugar6,
- "中南部双周累计产糖量": AnalysisHiSugar12,
- "中南部双周糖库存": AnalysisHiSugar12,
- "中南部双周乙醇产量": AnalysisHiSugar12,
- "巴西双周甘蔗累计入榨量": AnalysisHiSugar12,
- "中南部双周甘蔗压榨量": AnalysisHiSugar12,
- "中南部双周制糖比": AnalysisHiSugar12,
- "巴西双周甘蔗入榨量": AnalysisHiSugar12,
- "巴西中南部乙醇月度销售情况": AnalysisHiSugar13,
- "巴西中南部乙醇国内销售情况": AnalysisHiSugar13,
- "巴西双周无水乙醇库存": AnalysisHiSugar12,
- "巴西双周水合乙醇库存": AnalysisHiSugar12,
- "印度食糖月度出口量": AnalysisHiSugar8,
- "印度双周累计产糖量": AnalysisHiSugar10,
- "泰国双周糖累计产量": AnalysisHiSugar9,
- "泛糖副产品平台桔水成交价格指数": AnalysisHiSugar3,
- }
- var HisugarGuoChanTangClassifyMap = map[string]uint{
- "国内食糖月度累计销售均价": 5,
- "国内食糖月度销售均价": 5,
- "全国食糖累计产销率": 5,
- "全国单月产糖量": 5,
- "全国单月销糖量": 5,
- "国内月度工业库存": 5,
- "全国月度累计糖产量": 5,
- "全国月度累计糖销量": 5,
- "国内白糖产区现货价格": 5,
- "国内制糖集团报价": 5,
- "国内加工糖集团报价": 5,
- "全国单月甘蔗糖产量": 5,
- "全国单月甘蔗糖销量": 5,
- "全国单月甜菜产糖量": 5,
- "全国单月甜菜糖销量": 5,
- "广西单月产糖量": 6,
- "广西单月销糖量": 6,
- "广西月度库存": 6,
- "云南单月产糖量": 8,
- "云南单月销糖量": 8,
- "云南月度库存": 8,
- "海南单月产糖量": 9,
- "海南单月销糖量": 9,
- "海南月度库存": 9,
- "广东单月产糖量": 7,
- "广东单月销糖量": 7,
- "广东月度库存": 7,
- "新疆单月产糖量": 10,
- "新疆单月销糖量": 10,
- "新疆月度库存": 10,
- "内蒙单月产糖量": 11,
- "内蒙单月销糖量": 11,
- "内蒙月度库存": 11,
- "食糖月度进口量": 12,
- "印度食糖月度出口量": 14,
- "印度双周累计产糖量": 14,
- "泰国双周糖累计产量": 15,
- "泛糖副产品平台桔水成交价格指数": 16,
- "巴西食糖月度出口量": 13,
- "巴西中南部乙醇月度销售情况": 13,
- "巴西中南部乙醇国内销售情况": 13,
- }
- var DescribeMap = map[string]string{
- "国内食糖月度累计销售均价": "中国糖业协会",
- "国内食糖月度销售均价": "中国糖业协会",
- "全国食糖累计产销率": "中国糖业协会",
- "全国单月产糖量": "中国糖业协会",
- "全国单月销糖量": "中国糖业协会",
- "国内月度工业库存": "中国糖业协会",
- "全国月度累计糖产量": "中国糖业协会",
- "全国月度累计糖销量": "中国糖业协会",
- "广西单月产糖量": "广西糖业协会",
- "广西单月销糖量": "广西糖业协会",
- "广西月度库存": "广西糖业协会",
- "云南单月产糖量": "云南省糖业协会",
- "云南单月销糖量": "云南省糖业协会",
- "云南月度库存": "云南省糖业协会",
- "海南单月产糖量": "海南省糖业协会",
- "海南单月销糖量": "海南省糖业协会",
- "海南月度库存": "海南省糖业协会",
- "广东单月产糖量": "广东省单月产糖量",
- "广东单月销糖量": "广东省单月产糖量",
- "广东月度库存": "广东省单月产糖量",
- "新疆单月产糖量": "中国糖业协会",
- "新疆单月销糖量": "中国糖业协会",
- "新疆月度库存": "中国糖业协会",
- "内蒙单月产糖量": "内蒙古糖业协会",
- "内蒙单月销糖量": "内蒙古糖业协会",
- "内蒙月度库存": "内蒙古糖业协会",
- "食糖月度进口量": "海关总署",
- "巴西港口等待船只数量": "泛糖科技",
- "巴西港口最大等待天数": "泛糖科技",
- "巴西港口待装运食糖数量": "泛糖科技",
- "周度含水乙醇折糖价": "泛糖科技",
- "巴西双周累计产糖量": "巴西农业部",
- "巴西双周食糖库存": "巴西农业部",
- "巴西食糖月度出口量": "巴西农业部",
- "中南部双周累计产糖量": "巴西农业部",
- "中南部双周糖库存": "巴西农业部",
- "中南部双周乙醇产量": "Unica",
- "巴西双周甘蔗累计入榨量": "巴西农业部",
- "中南部双周甘蔗压榨量": "Unica",
- "中南部双周制糖比": "Unica",
- "巴西双周甘蔗入榨量": "巴西农业部",
- "巴西中南部乙醇月度销售情况": "巴西农业部",
- "巴西中南部乙醇国内销售情况": "巴西农业部",
- "巴西双周无水乙醇库存": "巴西农业部",
- "巴西双周水合乙醇库存": "巴西农业部",
- "印度食糖月度出口量": "印度商务部",
- "印度双周累计产糖量": "ISMA",
- "泰国双周糖累计产量": "OCSB",
- "全国单月甘蔗糖产量": "中国糖业协会",
- "全国单月甘蔗糖销量": "中国糖业协会",
- "全国单月甜菜产糖量": "中国糖业协会",
- "全国单月甜菜糖销量": "中国糖业协会",
- "泛糖副产品平台桔水成交价格指数": "泛糖科技",
- }
- // 爬虫主体
- func HiugarCrawler(context.Context) (err error) {
- // 模拟登陆获取cookie
- cookie, err := HisugarLogin()
- if err != nil {
- return
- }
- // 目标 URL
- urlStr := "http://222.84.157.44:12880/tempo/gridController/loadData"
- for _, name := range GuochantangList {
- reqParam := HisugarGuoChanTangParmsMap[name]
- // 构建表单数据
- formData := url.Values{
- "chartParams": {reqParam},
- "isPager": {"true"},
- "isFooterrow": {"false"},
- "subTotal": {"false"},
- //"colSubtotal": {"{\"CC787774162__tablecol_\":false,\"CC787774161__tablecol_\":false,\"CC787774160__tablecol_\":false,\"CC787774159__tablecol_\":false,\"CC787774158__tablecol_\":false,\"CC787774157__tablecol_\":false,\"CC787774156__tablecol_\":false,\"CC787774155__tablecol_\":false,\"CC787774154__tablecol_\":false,\"C1348804802__tablecol_\":false,\"C1348804803__tablecol_\":false,\"C1348804804__tablecol_\":false,\"C1348804805__tablecol_\":false}"},
- "colToRow": {"false"},
- "subTotalTop": {"false"},
- "dataLimit": {"{\"enable\":false,\"max\":\"10000\"}"},
- "_isSqlTrace": {"false"},
- "_search": {"false"},
- "nd": {"1723802570612"},
- "rows": {"1000"},
- "page": {"1"},
- "sord": {"desc}"},
- }
- // 创建请求
- req, e := http.NewRequest("POST", urlStr, strings.NewReader(formData.Encode()))
- if e != nil {
- err = e
- log.Fatal(err)
- }
- // 设置 Content-Type 为 application/x-www-form-urlencoded
- req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
- req.Header.Add("Cookie", cookie)
- // 发送请求
- client := &http.Client{}
- resp, e := client.Do(req)
- if e != nil {
- err = e
- log.Fatal(err)
- }
- defer resp.Body.Close()
- // 读取响应
- body, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = e
- log.Fatal(err)
- }
- // 打印响应体
- //fmt.Println(string(body))
- handler, ok := HisugarTaskAnalysisHandlers[name]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("%s无解析函数\n", name))
- err = fmt.Errorf("%s无解析函数", name)
- return
- }
- err = handler(name, reqParam, string(body))
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("%s解析失败\n", name))
- return
- }
- time.Sleep(5 * time.Second)
- }
- return
- }
- // 11,12是上一年的
- func AnalysisHiSugar(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- monthStr = strings.TrimRight(columTitle, "月")
- month, _ = strconv.Atoi(monthStr)
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- if month == 11 || month == 12 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- }
- item := models.BaseFromHisugarIndex{
- DataTime: dataTime.Format(utils.FormatDate),
- Value: value,
- IndexName: secName,
- Unit: HisugarGuoChanTangUnitMap[name],
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- ClassifyId: HisugarGuoChanTangClassifyMap[name],
- Frequency: "月度",
- }
- fmt.Println(item.DataTime, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 10,11,12月是上一年的
- // 全国食糖累计产销率,全国单月产糖量,全国单月销糖量
- func AnalysisHiSugar3(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- monthStr = strings.TrimRight(columTitle, "月")
- month, _ = strconv.Atoi(monthStr)
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" || value == "-" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 9 && month < 13 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- }
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: HisugarGuoChanTangClassifyMap[name],
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 分产地
- // 全国月度累计糖产量,全国月度累计糖销量
- func AnalysisHiSugar4(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- dateColum := ""
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- if column.AliasTitle == "" {
- columMap[column.AliasName] = column.Title
- } else {
- columMap[column.AliasName] = column.AliasTitle
- }
- if columMap[column.AliasName] == "月份" {
- dateColum = column.AliasName
- }
- //fmt.Println(columMap[column.AliasName])
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- //columTitleMap := make(map[string]string)
- dataTime := time.Time{}
- if date, ok := row[dateColum]; ok {
- dataTime, err = time.Parse("200601", date)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
- return
- }
- }
- for k, v := range row {
- columTitle := columMap[k]
- //value := ""
- if columTitle != "月份" && strings.Contains(columTitle, "量") {
- if v == "<NULL>" || v == "<Blank>" || v == "-" {
- continue
- }
- value := strings.ReplaceAll(v, "%", "")
- item := models.BaseFromHisugarIndex{
- IndexName: "全国月度累计" + columTitle,
- ClassifyId: 5,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- Describe: DescribeMap[name],
- DataTime: dataTime.AddDate(0, 1, -1).Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- IndexNameStr: "全国月度累计" + columTitle,
- MarketName: columTitle,
- }
- fmt.Println(item.DataTime, "全国月度累计"+columTitle, value)
- indexList = append(indexList, &item)
- }
- }
- }
- //写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 分产地
- // 国内白糖产区现货价格5000条,国内制糖集团报价1000条,国内加工糖集团报价1000条,周度含水乙醇折糖价400条
- func AnalysisHiSugar5(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- dateColum := ""
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- if column.AliasTitle == "" {
- columMap[column.AliasName] = column.Title
- } else {
- columMap[column.AliasName] = column.AliasTitle
- }
- if columMap[column.AliasName] == "日期" {
- dateColum = column.AliasName
- }
- //fmt.Println(columMap[column.AliasName])
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(e)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- //columTitleMap := make(map[string]string)
- dataTime := time.Time{}
- classifyId := 5
- frequency := "日度"
- if date, ok := row[dateColum]; ok {
- date = strings.ReplaceAll(date, " ", "")
- if name == "周度含水乙醇折糖价" {
- dataTime, err = time.Parse("2006/1/2", date)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
- continue
- }
- classifyId = 13
- frequency = "周度"
- } else {
- dataTime, err = time.Parse("20060102", date)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
- continue
- }
- }
- }
- for k, v := range row {
- columTitle := columMap[k]
- //value := ""
- indexName := secName + columTitle
- if columTitle != "日期" {
- if v == "<NULL>" || v == "<Blank>" || v == "-" {
- continue
- }
- if strings.Contains(indexName, "日照凌云海") {
- continue
- }
- value := strings.ReplaceAll(v, "%", "")
- item := models.BaseFromHisugarIndex{
- CreateTime: time.Now(),
- DataTime: dataTime.Format(utils.FormatDate),
- ModifyTime: time.Now(),
- Value: value,
- IndexName: indexName,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: frequency,
- ClassifyId: uint(classifyId),
- IndexNameStr: secName,
- MarketName: columTitle,
- Describe: DescribeMap[name],
- }
- if name == "周度含水乙醇折糖价" {
- item.IndexName = secName
- item.MarketName = ""
- }
- fmt.Println(item.DataTime, item.IndexName, value)
- indexList = append(indexList, &item)
- }
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 一年一行,1-12月
- // 食糖月度进口量
- func AnalysisHiSugar6(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(columTitle, "年份") {
- // 年份
- year, _ = strconv.Atoi(v)
- } else if strings.Contains(columTitle, "月") {
- monthStr = strings.TrimRight(columTitle, "月")
- month, _ = strconv.Atoi(monthStr)
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 12,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- if name == "巴西食糖月度出口量" {
- item.ClassifyId = 13
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- //err = PostHandleHisugar(indexList)
- //if err != nil {
- // utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- // fmt.Println("PostHandleHisugar err", err)
- // return
- //}
- }
- return
- }
- // 第一列月日,后面每一列是年份
- // 巴西港口等待船只数量
- func AnalysisHiSugar7(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- yeareMap := make(map[int]string)
- year := 0
- monthDay := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearStr := ""
- //month := 0
- //day := 0
- //value := ""
- if strings.Contains(columTitle, "日期") {
- // 日期
- //year, _ = strconv.Atoi(v)
- v = strings.ReplaceAll(v, " ", "")
- monthDay, err = utils.ParseTimeShort(v)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
- return
- }
- //month = int(dataTime.Month())
- //day = dataTime.Day()
- } else if strings.Contains(columTitle, "年") {
- yearStr = strings.TrimRight(columTitle, "年")
- year, _ = strconv.Atoi(yearStr)
- yeareMap[year] = v
- }
- }
- for year, value := range yeareMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- dataTime := time.Date(year, monthDay.Month(), monthDay.Day(), 0, 0, 0, 0, time.Local)
- //dataTime = dataTime.AddDate(0, 1, -1)
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 13,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "周度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 10,11,12月是上一年的,年份格式2023/24
- // 印度食糖月度出口量
- func AnalysisHiSugar8(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
- // 年份
- for i, s := range yearSlice {
- if i == 1 {
- yearStrSlice = append(yearStrSlice, "20"+s)
- } else {
- yearStrSlice = append(yearStrSlice, s)
- }
- }
- } else if strings.Contains(columTitle, "月") {
- monthStr = strings.TrimRight(columTitle, "月")
- month, _ = strconv.Atoi(monthStr)
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 9 && month < 13 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- }
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 14,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 10,11,12月是上一年的,年份格式23/24,旬度
- // 泰国双周糖累计产量
- func AnalysisHiSugar9(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- dayValueMap := make(map[int]int)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- if strings.Contains(columTitle, "月上半月") {
- monthStr = strings.TrimRight(columTitle, "月上半月")
- month, _ = strconv.Atoi(monthStr)
- dayValueMap[month] = 15
- } else if strings.Contains(columTitle, "月下半月") {
- monthStr = strings.TrimRight(columTitle, "月下半月")
- month, _ = strconv.Atoi(monthStr)
- dayValueMap[month] = 25
- }
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 11 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- }
- if dayValueMap[month] > 20 {
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- dataTime = time.Date(year, time.Month(month), 15, 0, 0, 0, 0, time.Local)
- }
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 15,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 11,12是上一年的,年份23/24,横轴日期11月15,11月30
- // 印度双周累计产糖量
- func AnalysisHiSugar10(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- //monthValueMap := make(map[int]string)
- //dayValueMap := make(map[int]int)
- dateValueMap := make(map[time.Time]string)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- //monthStr := ""
- month := 0
- day := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- dateSlice := strings.Split(columTitle, "月")
- if len(dateSlice) == 2 {
- month, _ = strconv.Atoi(dateSlice[0])
- day, _ = strconv.Atoi(dateSlice[1])
- }
- // 这个时候不一定有年份,所以先搞个假的年份,后面赋值真年份
- dataTime = time.Date(2000, time.Month(month), day, 0, 0, 0, 0, time.Local)
- dateValueMap[dataTime] = v
- }
- }
- for date, value := range dateValueMap {
- if value == "<NULL>" || value == "<Blank>" || value == "-" {
- continue
- }
- if date.Month() == 11 || date.Month() == 12 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- //dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- //dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- //dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- //dataTime = dataTime.AddDate(0, 1, -1)
- }
- date = time.Date(year, date.Month(), date.Day(), 0, 0, 0, 0, time.Local)
- item := models.BaseFromHisugarIndex{
- DataTime: date.Format(utils.FormatDate),
- Value: value,
- IndexName: secName,
- Unit: HisugarGuoChanTangUnitMap[name],
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- ClassifyId: HisugarGuoChanTangClassifyMap[name],
- Frequency: "旬度",
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 4月16到12月是上一年的,年份格式23/24,旬度
- // 巴西双周累计产糖量
- func AnalysisHiSugar11(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- dayValueMap := make(map[int]int)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- if strings.Contains(columTitle, "月16日") {
- monthStr = strings.TrimRight(columTitle, "月16日")
- month, _ = strconv.Atoi(monthStr)
- dayValueMap[month] = 16
- } else if strings.Contains(columTitle, "月1日") {
- monthStr = strings.TrimRight(columTitle, "月1日")
- month, _ = strconv.Atoi(monthStr)
- dayValueMap[month] = 1
- }
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 4 && dayValueMap[month] > 15 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- }
- dataTime = time.Date(year, time.Month(month), dayValueMap[month], 0, 0, 0, 0, time.Local)
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 13,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "旬度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- //写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 4月16到12月是上一年的,年份格式23/24,旬度
- // 巴西双周食糖库存,中南部双周累计产糖量,中南部双周糖库存,中南部双周乙醇产量
- func AnalysisHiSugar12(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- dayValueMap := make(map[int]int)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- //monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨" ||
- columTitle == "榨季_立方米" || columTitle == "榨季_吨" || columTitle == "榨季_百分比") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- date, _ := time.Parse("1月2日", columTitle)
- month = int(date.Month())
- dayValueMap[month] = date.Day()
- monthValueMap[month] = v
- //if strings.Contains(columTitle, "月16日") {
- // monthStr = strings.TrimRight(columTitle, "月16日")
- // month, _ = strconv.Atoi(monthStr)
- // dayValueMap[month] = 16
- //} else if strings.Contains(columTitle, "月1日") {
- // monthStr = strings.TrimRight(columTitle, "月1日")
- // month, _ = strconv.Atoi(monthStr)
- // dayValueMap[month] = 1
- //}
- //monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 3 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- }
- dataTime = time.Date(year, time.Month(month), dayValueMap[month], 0, 0, 0, 0, time.Local)
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: 13,
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "旬度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, secName, value)
- indexList = append(indexList, &item)
- }
- }
- //写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
- // 4-12月是上一年的
- // 巴西中南部乙醇月度销售情况,巴西中南部乙醇国内销售情况
- func AnalysisHiSugar13(name, reqParam, body string) (err error) {
- secName := ""
- columMap := make(map[string]string)
- var req ChartRequestSimple
- if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- secName = req.SceneName
- fmt.Println(secName)
- for _, column := range req.Columns {
- columMap[column.AliasName] = column.Title
- }
- }
- var resp HisugarResponseDataSimple
- if e := json.Unmarshal([]byte(body), &resp); e != nil {
- err = e
- log.Println(err)
- return
- } else {
- indexList := make([]*models.BaseFromHisugarIndex, 0)
- for _, row := range resp.Rows {
- monthValueMap := make(map[int]string)
- yearStrSlice := make([]string, 0)
- year := 0
- dataTime := time.Time{}
- for k, v := range row {
- columTitle := columMap[k]
- yearSlice := strings.Split(v, "/")
- monthStr := ""
- month := 0
- //value := ""
- if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
- // 年份
- for _, s := range yearSlice {
- yearStrSlice = append(yearStrSlice, "20"+s)
- }
- } else if strings.Contains(columTitle, "月") {
- monthStr = strings.TrimRight(columTitle, "月")
- month, _ = strconv.Atoi(monthStr)
- monthValueMap[month] = v
- }
- }
- for month, value := range monthValueMap {
- if value == "<NULL>" || value == "<Blank>" || value == "-" {
- continue
- }
- value = strings.ReplaceAll(value, "%", "")
- if month > 3 && month < 13 {
- year, _ = strconv.Atoi(yearStrSlice[0])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- } else {
- year, _ = strconv.Atoi(yearStrSlice[1])
- dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
- dataTime = dataTime.AddDate(0, 1, -1)
- }
- item := models.BaseFromHisugarIndex{
- IndexName: secName,
- ClassifyId: HisugarGuoChanTangClassifyMap[name],
- Unit: HisugarGuoChanTangUnitMap[name],
- Frequency: "月度",
- DataTime: dataTime.Format(utils.FormatDate),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- Value: value,
- Describe: DescribeMap[name],
- }
- fmt.Println(item.DataTime, value)
- indexList = append(indexList, &item)
- }
- }
- // 写入数据库
- err = PostHandleHisugar(indexList)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
- fmt.Println("PostHandleHisugar err", err)
- return
- }
- }
- return
- }
|