guochantang_edb.go 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. package base_from_hisugar
  2. import (
  3. "context"
  4. "encoding/json"
  5. "eta/eta_data_analysis/models"
  6. "eta/eta_data_analysis/utils"
  7. "fmt"
  8. "io/ioutil"
  9. "log"
  10. "net/http"
  11. "net/url"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 国产糖
  17. var GuochantangList = []string{
  18. "国内食糖月度累计销售均价",
  19. "国内食糖月度销售均价",
  20. "全国食糖累计产销率",
  21. "全国单月产糖量",
  22. "全国单月销糖量",
  23. "国内月度工业库存",
  24. "全国月度累计糖产量",
  25. "全国月度累计糖销量",
  26. "国内白糖产区现货价格",
  27. "国内制糖集团报价",
  28. "国内加工糖集团报价",
  29. "全国单月甘蔗糖产量",
  30. "全国单月甘蔗糖销量",
  31. "全国单月甜菜产糖量",
  32. "全国单月甜菜糖销量",
  33. "广西单月产糖量",
  34. "广西单月销糖量",
  35. "广西月度库存",
  36. "云南单月产糖量",
  37. "云南单月销糖量",
  38. "云南月度库存",
  39. "海南单月产糖量",
  40. "海南单月销糖量",
  41. "海南月度库存",
  42. "广东单月产糖量",
  43. "广东单月销糖量",
  44. "广东月度库存",
  45. "新疆单月产糖量",
  46. "新疆单月销糖量",
  47. "新疆月度库存",
  48. "内蒙单月产糖量",
  49. "内蒙单月销糖量",
  50. "内蒙月度库存",
  51. "食糖月度进口量",
  52. "巴西港口等待船只数量",
  53. "巴西港口最大等待天数",
  54. "巴西港口待装运食糖数量",
  55. "周度含水乙醇折糖价",
  56. "巴西双周累计产糖量",
  57. "巴西双周食糖库存",
  58. "巴西食糖月度出口量",
  59. "中南部双周累计产糖量",
  60. "中南部双周糖库存",
  61. "中南部双周乙醇产量",
  62. "巴西双周甘蔗累计入榨量",
  63. "中南部双周甘蔗压榨量",
  64. "中南部双周制糖比",
  65. "巴西双周甘蔗入榨量",
  66. "巴西中南部乙醇月度销售情况",
  67. "巴西中南部乙醇国内销售情况",
  68. "巴西双周无水乙醇库存",
  69. "巴西双周水合乙醇库存",
  70. "印度食糖月度出口量",
  71. "印度双周累计产糖量",
  72. "泰国双周糖累计产量",
  73. "泛糖副产品平台桔水成交价格指数",
  74. }
  75. var HisugarGuoChanTangParmsMap = map[string]string{
  76. "国内食糖月度累计销售均价": shiTangYueDuLeiJiXiaoShouJunJia,
  77. "国内食糖月度销售均价": shiTangYueDuXiaoShouJunJia,
  78. "全国食糖累计产销率": shiTangLeiJiChanXiaoLv,
  79. "全国单月产糖量": quanGuoDanYueChanTangLiang,
  80. "全国单月销糖量": quanGuoDanYueXiaoTangLiang,
  81. "国内月度工业库存": guoNeiYueDuGongYeKuCun,
  82. "全国月度累计糖产量": quanGuoYueDuLeiJiTangChanLiang,
  83. "全国月度累计糖销量": quanGuoYueDuLeiJiTangXiaoLiang,
  84. "国内白糖产区现货价格": guoNeiBaiTangChanQuXianHuoJiaGe,
  85. "国内制糖集团报价": guoNeiZhiTangJiTuanBaoJia,
  86. "国内加工糖集团报价": guoNeiJiaGongTangJiTuanBaoJia,
  87. "广西单月产糖量": guangXiDanYueChanTangLiang,
  88. "广西单月销糖量": guangXiDanYueXiaoTangLiang,
  89. "广西月度库存": guangXiYueDuKuCun,
  90. "云南单月产糖量": yunNanDanYueChanTangLiang,
  91. "云南单月销糖量": yunNanDanYueXiaoTangLiang,
  92. "云南月度库存": yunNanYueDukuCun,
  93. "海南单月产糖量": haiNanDanYueChanTangLiang,
  94. "海南单月销糖量": haiNanDanyueXiaoTangliang,
  95. "海南月度库存": haiNanYueduKuCun,
  96. "广东单月产糖量": guangDongDanYueChanTangLiang,
  97. "广东单月销糖量": guangDongDanYueXiaoTangLiang,
  98. "广东月度库存": guangDongYueDuKuCun,
  99. "新疆单月产糖量": xinJiangDanYueChanTangLiang,
  100. "新疆单月销糖量": xinJiangDanYueXiaoTangLiang,
  101. "新疆月度库存": xinJiangYueDuKuCun,
  102. "内蒙单月产糖量": neiMengDanYueChanTangLiang,
  103. "内蒙单月销糖量": neiMengDanYueXiaoTangLiang,
  104. "内蒙月度库存": neiMengYueDuKuCun,
  105. "食糖月度进口量": shiTangYueDuJinKouLiang,
  106. "巴西港口等待船只数量": baXiGangKouDengDaiChuanZhiShuLiang,
  107. "巴西港口最大等待天数": baXiGangKouZuiDaDengDaiTianShu,
  108. "巴西港口待装运食糖数量": baXiGangKouDaiZhuangYunShiTiaoShangShuLiang,
  109. "周度含水乙醇折糖价": zhouDuHanShuiYiChunZheTangJia,
  110. "巴西双周累计产糖量": baXiShuangZhouLeiJiChanTangLiang,
  111. "巴西双周食糖库存": baXiShuangZhouShiTangKuCun,
  112. "巴西食糖月度出口量": baXiShiTangYueDuChuKouLiang,
  113. "中南部双周累计产糖量": zhongNanShuangZhouLiJiChanTangLiang,
  114. "中南部双周糖库存": zhongNanShuangZhouTangKuCun,
  115. "中南部双周乙醇产量": zhongNanShuangZhouXianHuoChanLiang,
  116. "巴西双周甘蔗累计入榨量": baXiShuangZhouGanZheLeiJiRuZhaLiang,
  117. "中南部双周甘蔗压榨量": zhongNanBuShuangZhouGanZheYaZhaLiang,
  118. "中南部双周制糖比": zhongNanBuShuangZhouZHiTangBi,
  119. "巴西双周甘蔗入榨量": baXiShuangZhouGanZheRuZhaLiang,
  120. "巴西中南部乙醇月度销售情况": baXiZhongNanBuYiChunYueDuXiaoShouQingKuang,
  121. "巴西中南部乙醇国内销售情况": baXiZhongNanBuYiChunGuoNeiXiaoShouQingKuang,
  122. "巴西双周无水乙醇库存": baXiShuangZhouWuShuiYiChunKuCun,
  123. "巴西双周水合乙醇库存": baXiShuangZhouShuiHeYiChunKuCun,
  124. "印度食糖月度出口量": yinDuShiTangYueDuChuKouLiang,
  125. "印度双周累计产糖量": yinDuShuangZhouLeiJiChanTangLiang,
  126. "泰国双周糖累计产量": taiGuoShuangZhouTangLeiJiChanLiang,
  127. "泛糖副产品平台桔水成交价格指数": JuShuiChengJIaoJiaGeZhiShu,
  128. "全国单月甘蔗糖产量": quanGuoDanYueGanZheTangChanLiang,
  129. "全国单月甘蔗糖销量": quanGuoDanYueGanZheTangXiaoLiang,
  130. "全国单月甜菜产糖量": quanGuoDanYueTianCaiChanLiang,
  131. "全国单月甜菜糖销量": quanGuoDanYueTianCaiXiaoLiang,
  132. }
  133. var HisugarGuoChanTangUnitMap = map[string]string{
  134. "国内食糖月度累计销售均价": "元/吨",
  135. "国内食糖月度销售均价": "元/吨",
  136. "全国食糖累计产销率": "%",
  137. "全国单月产糖量": "万吨",
  138. "全国单月销糖量": "万吨",
  139. "国内月度工业库存": "万吨",
  140. "全国月度累计糖产量": "万吨",
  141. "全国月度累计糖销量": "万吨",
  142. "国内白糖产区现货价格": "元/吨",
  143. "国内制糖集团报价": "元/吨",
  144. "国内加工糖集团报价": "元/吨",
  145. "广西单月产糖量": "万吨",
  146. "广西单月销糖量": "万吨",
  147. "广西月度库存": "万吨",
  148. "云南单月产糖量": "万吨",
  149. "云南单月销糖量": "万吨",
  150. "云南月度库存": "万吨",
  151. "海南单月产糖量": "万吨",
  152. "海南单月销糖量": "万吨",
  153. "海南月度库存": "万吨",
  154. "广东单月产糖量": "万吨",
  155. "广东单月销糖量": "万吨",
  156. "广东月度库存": "万吨",
  157. "新疆单月产糖量": "万吨",
  158. "新疆单月销糖量": "万吨",
  159. "新疆月度库存": "万吨",
  160. "内蒙单月产糖量": "万吨",
  161. "内蒙单月销糖量": "万吨",
  162. "内蒙月度库存": "万吨",
  163. "食糖月度进口量": "万吨",
  164. "巴西港口等待船只数量": "艘",
  165. "巴西港口最大等待天数": "天",
  166. "巴西港口待装运食糖数量": "万吨",
  167. "周度含水乙醇折糖价": "美分/磅",
  168. "巴西双周累计产糖量": "万吨",
  169. "巴西双周食糖库存": "万吨",
  170. "巴西食糖月度出口量": "万吨",
  171. "中南部双周累计产糖量": "万吨",
  172. "中南部双周糖库存": "万吨",
  173. "中南部双周乙醇产量": "立方米",
  174. "巴西双周甘蔗累计入榨量": "万吨",
  175. "中南部双周甘蔗压榨量": "吨",
  176. "中南部双周制糖比": "%",
  177. "巴西双周甘蔗入榨量": "万吨",
  178. "巴西中南部乙醇月度销售情况": "万立方米",
  179. "巴西中南部乙醇国内销售情况": "万立方米",
  180. "巴西双周无水乙醇库存": "万立方米",
  181. "巴西双周水合乙醇库存": "万立方米",
  182. "印度食糖月度出口量": "万吨",
  183. "印度双周累计产糖量": "万吨",
  184. "泰国双周糖累计产量": "万吨",
  185. "全国单月甘蔗糖产量": "万吨",
  186. "全国单月甘蔗糖销量": "万吨",
  187. "全国单月甜菜产糖量": "万吨",
  188. "全国单月甜菜糖销量": "万吨",
  189. }
  190. var HisugarTaskAnalysisHandlers = map[string]func(name, reqParam, body string) (err error){
  191. "国内食糖月度累计销售均价": AnalysisHiSugar,
  192. "国内食糖月度销售均价": AnalysisHiSugar,
  193. "全国食糖累计产销率": AnalysisHiSugar3,
  194. "全国单月产糖量": AnalysisHiSugar3,
  195. "全国单月销糖量": AnalysisHiSugar3,
  196. "国内月度工业库存": AnalysisHiSugar3,
  197. "全国月度累计糖产量": AnalysisHiSugar4,
  198. "全国月度累计糖销量": AnalysisHiSugar4,
  199. "国内白糖产区现货价格": AnalysisHiSugar5,
  200. "国内制糖集团报价": AnalysisHiSugar5,
  201. "国内加工糖集团报价": AnalysisHiSugar5,
  202. "全国单月甘蔗糖产量": AnalysisHiSugar3,
  203. "全国单月甘蔗糖销量": AnalysisHiSugar3,
  204. "全国单月甜菜产糖量": AnalysisHiSugar3,
  205. "全国单月甜菜糖销量": AnalysisHiSugar3,
  206. "广西单月产糖量": AnalysisHiSugar,
  207. "广西单月销糖量": AnalysisHiSugar,
  208. "广西月度库存": AnalysisHiSugar,
  209. "云南单月产糖量": AnalysisHiSugar,
  210. "云南单月销糖量": AnalysisHiSugar,
  211. "云南月度库存": AnalysisHiSugar,
  212. "海南单月产糖量": AnalysisHiSugar,
  213. "海南单月销糖量": AnalysisHiSugar,
  214. "海南月度库存": AnalysisHiSugar,
  215. "广东单月产糖量": AnalysisHiSugar,
  216. "广东单月销糖量": AnalysisHiSugar,
  217. "广东月度库存": AnalysisHiSugar,
  218. "新疆单月产糖量": AnalysisHiSugar,
  219. "新疆单月销糖量": AnalysisHiSugar,
  220. "新疆月度库存": AnalysisHiSugar,
  221. "内蒙单月产糖量": AnalysisHiSugar,
  222. "内蒙单月销糖量": AnalysisHiSugar,
  223. "内蒙月度库存": AnalysisHiSugar,
  224. "食糖月度进口量": AnalysisHiSugar6,
  225. "巴西港口等待船只数量": AnalysisHiSugar7,
  226. "巴西港口最大等待天数": AnalysisHiSugar7,
  227. "巴西港口待装运食糖数量": AnalysisHiSugar7,
  228. "周度含水乙醇折糖价": AnalysisHiSugar5,
  229. "巴西双周累计产糖量": AnalysisHiSugar11,
  230. "巴西双周食糖库存": AnalysisHiSugar12,
  231. "巴西食糖月度出口量": AnalysisHiSugar6,
  232. "中南部双周累计产糖量": AnalysisHiSugar12,
  233. "中南部双周糖库存": AnalysisHiSugar12,
  234. "中南部双周乙醇产量": AnalysisHiSugar12,
  235. "巴西双周甘蔗累计入榨量": AnalysisHiSugar12,
  236. "中南部双周甘蔗压榨量": AnalysisHiSugar12,
  237. "中南部双周制糖比": AnalysisHiSugar12,
  238. "巴西双周甘蔗入榨量": AnalysisHiSugar12,
  239. "巴西中南部乙醇月度销售情况": AnalysisHiSugar13,
  240. "巴西中南部乙醇国内销售情况": AnalysisHiSugar13,
  241. "巴西双周无水乙醇库存": AnalysisHiSugar12,
  242. "巴西双周水合乙醇库存": AnalysisHiSugar12,
  243. "印度食糖月度出口量": AnalysisHiSugar8,
  244. "印度双周累计产糖量": AnalysisHiSugar10,
  245. "泰国双周糖累计产量": AnalysisHiSugar9,
  246. "泛糖副产品平台桔水成交价格指数": AnalysisHiSugar3,
  247. }
  248. var HisugarGuoChanTangClassifyMap = map[string]uint{
  249. "国内食糖月度累计销售均价": 5,
  250. "国内食糖月度销售均价": 5,
  251. "全国食糖累计产销率": 5,
  252. "全国单月产糖量": 5,
  253. "全国单月销糖量": 5,
  254. "国内月度工业库存": 5,
  255. "全国月度累计糖产量": 5,
  256. "全国月度累计糖销量": 5,
  257. "国内白糖产区现货价格": 5,
  258. "国内制糖集团报价": 5,
  259. "国内加工糖集团报价": 5,
  260. "全国单月甘蔗糖产量": 5,
  261. "全国单月甘蔗糖销量": 5,
  262. "全国单月甜菜产糖量": 5,
  263. "全国单月甜菜糖销量": 5,
  264. "广西单月产糖量": 6,
  265. "广西单月销糖量": 6,
  266. "广西月度库存": 6,
  267. "云南单月产糖量": 8,
  268. "云南单月销糖量": 8,
  269. "云南月度库存": 8,
  270. "海南单月产糖量": 9,
  271. "海南单月销糖量": 9,
  272. "海南月度库存": 9,
  273. "广东单月产糖量": 7,
  274. "广东单月销糖量": 7,
  275. "广东月度库存": 7,
  276. "新疆单月产糖量": 10,
  277. "新疆单月销糖量": 10,
  278. "新疆月度库存": 10,
  279. "内蒙单月产糖量": 11,
  280. "内蒙单月销糖量": 11,
  281. "内蒙月度库存": 11,
  282. "食糖月度进口量": 12,
  283. "印度食糖月度出口量": 14,
  284. "印度双周累计产糖量": 14,
  285. "泰国双周糖累计产量": 15,
  286. "泛糖副产品平台桔水成交价格指数": 16,
  287. "巴西食糖月度出口量": 13,
  288. "巴西中南部乙醇月度销售情况": 13,
  289. "巴西中南部乙醇国内销售情况": 13,
  290. }
  291. var DescribeMap = map[string]string{
  292. "国内食糖月度累计销售均价": "中国糖业协会",
  293. "国内食糖月度销售均价": "中国糖业协会",
  294. "全国食糖累计产销率": "中国糖业协会",
  295. "全国单月产糖量": "中国糖业协会",
  296. "全国单月销糖量": "中国糖业协会",
  297. "国内月度工业库存": "中国糖业协会",
  298. "全国月度累计糖产量": "中国糖业协会",
  299. "全国月度累计糖销量": "中国糖业协会",
  300. "广西单月产糖量": "广西糖业协会",
  301. "广西单月销糖量": "广西糖业协会",
  302. "广西月度库存": "广西糖业协会",
  303. "云南单月产糖量": "云南省糖业协会",
  304. "云南单月销糖量": "云南省糖业协会",
  305. "云南月度库存": "云南省糖业协会",
  306. "海南单月产糖量": "海南省糖业协会",
  307. "海南单月销糖量": "海南省糖业协会",
  308. "海南月度库存": "海南省糖业协会",
  309. "广东单月产糖量": "广东省单月产糖量",
  310. "广东单月销糖量": "广东省单月产糖量",
  311. "广东月度库存": "广东省单月产糖量",
  312. "新疆单月产糖量": "中国糖业协会",
  313. "新疆单月销糖量": "中国糖业协会",
  314. "新疆月度库存": "中国糖业协会",
  315. "内蒙单月产糖量": "内蒙古糖业协会",
  316. "内蒙单月销糖量": "内蒙古糖业协会",
  317. "内蒙月度库存": "内蒙古糖业协会",
  318. "食糖月度进口量": "海关总署",
  319. "巴西港口等待船只数量": "泛糖科技",
  320. "巴西港口最大等待天数": "泛糖科技",
  321. "巴西港口待装运食糖数量": "泛糖科技",
  322. "周度含水乙醇折糖价": "泛糖科技",
  323. "巴西双周累计产糖量": "巴西农业部",
  324. "巴西双周食糖库存": "巴西农业部",
  325. "巴西食糖月度出口量": "巴西农业部",
  326. "中南部双周累计产糖量": "巴西农业部",
  327. "中南部双周糖库存": "巴西农业部",
  328. "中南部双周乙醇产量": "Unica",
  329. "巴西双周甘蔗累计入榨量": "巴西农业部",
  330. "中南部双周甘蔗压榨量": "Unica",
  331. "中南部双周制糖比": "Unica",
  332. "巴西双周甘蔗入榨量": "巴西农业部",
  333. "巴西中南部乙醇月度销售情况": "巴西农业部",
  334. "巴西中南部乙醇国内销售情况": "巴西农业部",
  335. "巴西双周无水乙醇库存": "巴西农业部",
  336. "巴西双周水合乙醇库存": "巴西农业部",
  337. "印度食糖月度出口量": "印度商务部",
  338. "印度双周累计产糖量": "ISMA",
  339. "泰国双周糖累计产量": "OCSB",
  340. "全国单月甘蔗糖产量": "中国糖业协会",
  341. "全国单月甘蔗糖销量": "中国糖业协会",
  342. "全国单月甜菜产糖量": "中国糖业协会",
  343. "全国单月甜菜糖销量": "中国糖业协会",
  344. "泛糖副产品平台桔水成交价格指数": "泛糖科技",
  345. }
  346. // 爬虫主体
  347. func HiugarCrawler(context.Context) (err error) {
  348. // 模拟登陆获取cookie
  349. cookie, err := HisugarLogin()
  350. if err != nil {
  351. return
  352. }
  353. // 目标 URL
  354. urlStr := "http://222.84.157.44:12880/tempo/gridController/loadData"
  355. for _, name := range GuochantangList {
  356. reqParam := HisugarGuoChanTangParmsMap[name]
  357. // 构建表单数据
  358. formData := url.Values{
  359. "chartParams": {reqParam},
  360. "isPager": {"true"},
  361. "isFooterrow": {"false"},
  362. "subTotal": {"false"},
  363. //"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}"},
  364. "colToRow": {"false"},
  365. "subTotalTop": {"false"},
  366. "dataLimit": {"{\"enable\":false,\"max\":\"10000\"}"},
  367. "_isSqlTrace": {"false"},
  368. "_search": {"false"},
  369. "nd": {"1723802570612"},
  370. "rows": {"1000"},
  371. "page": {"1"},
  372. "sord": {"desc}"},
  373. }
  374. // 创建请求
  375. req, e := http.NewRequest("POST", urlStr, strings.NewReader(formData.Encode()))
  376. if e != nil {
  377. err = e
  378. log.Fatal(err)
  379. }
  380. // 设置 Content-Type 为 application/x-www-form-urlencoded
  381. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  382. req.Header.Add("Cookie", cookie)
  383. // 发送请求
  384. client := &http.Client{}
  385. resp, e := client.Do(req)
  386. if e != nil {
  387. err = e
  388. log.Fatal(err)
  389. }
  390. defer resp.Body.Close()
  391. // 读取响应
  392. body, e := ioutil.ReadAll(resp.Body)
  393. if e != nil {
  394. err = e
  395. log.Fatal(err)
  396. }
  397. // 打印响应体
  398. //fmt.Println(string(body))
  399. handler, ok := HisugarTaskAnalysisHandlers[name]
  400. if !ok {
  401. utils.FileLog.Info(fmt.Sprintf("%s无解析函数\n", name))
  402. err = fmt.Errorf("%s无解析函数", name)
  403. return
  404. }
  405. err = handler(name, reqParam, string(body))
  406. if err != nil {
  407. utils.FileLog.Error(fmt.Sprintf("%s解析失败\n", name))
  408. return
  409. }
  410. time.Sleep(5 * time.Second)
  411. }
  412. return
  413. }
  414. // 11,12是上一年的
  415. func AnalysisHiSugar(name, reqParam, body string) (err error) {
  416. secName := ""
  417. columMap := make(map[string]string)
  418. var req ChartRequestSimple
  419. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  420. err = e
  421. log.Println(err)
  422. return
  423. } else {
  424. secName = req.SceneName
  425. fmt.Println(secName)
  426. for _, column := range req.Columns {
  427. columMap[column.AliasName] = column.Title
  428. }
  429. }
  430. var resp HisugarResponseDataSimple
  431. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  432. err = e
  433. log.Println(err)
  434. return
  435. } else {
  436. indexList := make([]*models.BaseFromHisugarIndex, 0)
  437. for _, row := range resp.Rows {
  438. monthValueMap := make(map[int]string)
  439. yearStrSlice := make([]string, 0)
  440. year := 0
  441. dataTime := time.Time{}
  442. for k, v := range row {
  443. columTitle := columMap[k]
  444. yearSlice := strings.Split(v, "/")
  445. monthStr := ""
  446. month := 0
  447. //value := ""
  448. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
  449. // 年份
  450. for _, s := range yearSlice {
  451. yearStrSlice = append(yearStrSlice, "20"+s)
  452. }
  453. } else if strings.Contains(columTitle, "月") {
  454. monthStr = strings.TrimRight(columTitle, "月")
  455. month, _ = strconv.Atoi(monthStr)
  456. monthValueMap[month] = v
  457. }
  458. }
  459. for month, value := range monthValueMap {
  460. if value == "<NULL>" || value == "<Blank>" {
  461. continue
  462. }
  463. if month == 11 || month == 12 {
  464. year, _ = strconv.Atoi(yearStrSlice[0])
  465. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  466. dataTime = dataTime.AddDate(0, 1, -1)
  467. } else {
  468. year, _ = strconv.Atoi(yearStrSlice[1])
  469. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  470. dataTime = dataTime.AddDate(0, 1, -1)
  471. }
  472. item := models.BaseFromHisugarIndex{
  473. DataTime: dataTime.Format(utils.FormatDate),
  474. Value: value,
  475. IndexName: secName,
  476. Unit: HisugarGuoChanTangUnitMap[name],
  477. CreateTime: time.Now(),
  478. ModifyTime: time.Now(),
  479. ClassifyId: HisugarGuoChanTangClassifyMap[name],
  480. Frequency: "月度",
  481. }
  482. fmt.Println(item.DataTime, value)
  483. indexList = append(indexList, &item)
  484. }
  485. }
  486. // 写入数据库
  487. err = PostHandleHisugar(indexList)
  488. if err != nil {
  489. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  490. fmt.Println("PostHandleHisugar err", err)
  491. return
  492. }
  493. }
  494. return
  495. }
  496. // 10,11,12月是上一年的
  497. // 全国食糖累计产销率,全国单月产糖量,全国单月销糖量
  498. func AnalysisHiSugar3(name, reqParam, body string) (err error) {
  499. secName := ""
  500. columMap := make(map[string]string)
  501. var req ChartRequestSimple
  502. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  503. err = e
  504. log.Println(err)
  505. return
  506. } else {
  507. secName = req.SceneName
  508. fmt.Println(secName)
  509. for _, column := range req.Columns {
  510. columMap[column.AliasName] = column.Title
  511. }
  512. }
  513. var resp HisugarResponseDataSimple
  514. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  515. err = e
  516. log.Println(err)
  517. return
  518. } else {
  519. indexList := make([]*models.BaseFromHisugarIndex, 0)
  520. for _, row := range resp.Rows {
  521. monthValueMap := make(map[int]string)
  522. yearStrSlice := make([]string, 0)
  523. year := 0
  524. dataTime := time.Time{}
  525. for k, v := range row {
  526. columTitle := columMap[k]
  527. yearSlice := strings.Split(v, "/")
  528. monthStr := ""
  529. month := 0
  530. //value := ""
  531. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
  532. // 年份
  533. for _, s := range yearSlice {
  534. yearStrSlice = append(yearStrSlice, "20"+s)
  535. }
  536. } else if strings.Contains(columTitle, "月") {
  537. monthStr = strings.TrimRight(columTitle, "月")
  538. month, _ = strconv.Atoi(monthStr)
  539. monthValueMap[month] = v
  540. }
  541. }
  542. for month, value := range monthValueMap {
  543. if value == "<NULL>" || value == "<Blank>" || value == "-" {
  544. continue
  545. }
  546. value = strings.ReplaceAll(value, "%", "")
  547. if month > 9 && month < 13 {
  548. year, _ = strconv.Atoi(yearStrSlice[0])
  549. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  550. dataTime = dataTime.AddDate(0, 1, -1)
  551. } else {
  552. year, _ = strconv.Atoi(yearStrSlice[1])
  553. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  554. dataTime = dataTime.AddDate(0, 1, -1)
  555. }
  556. item := models.BaseFromHisugarIndex{
  557. IndexName: secName,
  558. ClassifyId: HisugarGuoChanTangClassifyMap[name],
  559. Unit: HisugarGuoChanTangUnitMap[name],
  560. Frequency: "月度",
  561. DataTime: dataTime.Format(utils.FormatDate),
  562. CreateTime: time.Now(),
  563. ModifyTime: time.Now(),
  564. Value: value,
  565. Describe: DescribeMap[name],
  566. }
  567. fmt.Println(item.DataTime, value)
  568. indexList = append(indexList, &item)
  569. }
  570. }
  571. // 写入数据库
  572. err = PostHandleHisugar(indexList)
  573. if err != nil {
  574. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  575. fmt.Println("PostHandleHisugar err", err)
  576. return
  577. }
  578. }
  579. return
  580. }
  581. // 分产地
  582. // 全国月度累计糖产量,全国月度累计糖销量
  583. func AnalysisHiSugar4(name, reqParam, body string) (err error) {
  584. secName := ""
  585. columMap := make(map[string]string)
  586. dateColum := ""
  587. var req ChartRequestSimple
  588. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  589. err = e
  590. log.Println(err)
  591. return
  592. } else {
  593. secName = req.SceneName
  594. fmt.Println(secName)
  595. for _, column := range req.Columns {
  596. if column.AliasTitle == "" {
  597. columMap[column.AliasName] = column.Title
  598. } else {
  599. columMap[column.AliasName] = column.AliasTitle
  600. }
  601. if columMap[column.AliasName] == "月份" {
  602. dateColum = column.AliasName
  603. }
  604. //fmt.Println(columMap[column.AliasName])
  605. }
  606. }
  607. var resp HisugarResponseDataSimple
  608. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  609. err = e
  610. log.Println(err)
  611. return
  612. } else {
  613. indexList := make([]*models.BaseFromHisugarIndex, 0)
  614. for _, row := range resp.Rows {
  615. //columTitleMap := make(map[string]string)
  616. dataTime := time.Time{}
  617. if date, ok := row[dateColum]; ok {
  618. dataTime, err = time.Parse("200601", date)
  619. if err != nil {
  620. fmt.Println(err)
  621. utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
  622. return
  623. }
  624. }
  625. for k, v := range row {
  626. columTitle := columMap[k]
  627. //value := ""
  628. if columTitle != "月份" && strings.Contains(columTitle, "量") {
  629. if v == "<NULL>" || v == "<Blank>" || v == "-" {
  630. continue
  631. }
  632. value := strings.ReplaceAll(v, "%", "")
  633. item := models.BaseFromHisugarIndex{
  634. IndexName: "全国月度累计" + columTitle,
  635. ClassifyId: 5,
  636. Unit: HisugarGuoChanTangUnitMap[name],
  637. Frequency: "月度",
  638. Describe: DescribeMap[name],
  639. DataTime: dataTime.AddDate(0, 1, -1).Format(utils.FormatDate),
  640. CreateTime: time.Now(),
  641. ModifyTime: time.Now(),
  642. Value: value,
  643. IndexNameStr: "全国月度累计" + columTitle,
  644. MarketName: columTitle,
  645. }
  646. fmt.Println(item.DataTime, "全国月度累计"+columTitle, value)
  647. indexList = append(indexList, &item)
  648. }
  649. }
  650. }
  651. //写入数据库
  652. err = PostHandleHisugar(indexList)
  653. if err != nil {
  654. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  655. fmt.Println("PostHandleHisugar err", err)
  656. return
  657. }
  658. }
  659. return
  660. }
  661. // 分产地
  662. // 国内白糖产区现货价格5000条,国内制糖集团报价1000条,国内加工糖集团报价1000条,周度含水乙醇折糖价400条
  663. func AnalysisHiSugar5(name, reqParam, body string) (err error) {
  664. secName := ""
  665. columMap := make(map[string]string)
  666. dateColum := ""
  667. var req ChartRequestSimple
  668. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  669. err = e
  670. log.Println(err)
  671. return
  672. } else {
  673. secName = req.SceneName
  674. fmt.Println(secName)
  675. for _, column := range req.Columns {
  676. if column.AliasTitle == "" {
  677. columMap[column.AliasName] = column.Title
  678. } else {
  679. columMap[column.AliasName] = column.AliasTitle
  680. }
  681. if columMap[column.AliasName] == "日期" {
  682. dateColum = column.AliasName
  683. }
  684. //fmt.Println(columMap[column.AliasName])
  685. }
  686. }
  687. var resp HisugarResponseDataSimple
  688. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  689. err = e
  690. log.Println(e)
  691. return
  692. } else {
  693. indexList := make([]*models.BaseFromHisugarIndex, 0)
  694. for _, row := range resp.Rows {
  695. //columTitleMap := make(map[string]string)
  696. dataTime := time.Time{}
  697. classifyId := 5
  698. frequency := "日度"
  699. if date, ok := row[dateColum]; ok {
  700. date = strings.ReplaceAll(date, " ", "")
  701. if name == "周度含水乙醇折糖价" {
  702. dataTime, err = time.Parse("2006/1/2", date)
  703. if err != nil {
  704. fmt.Println(err)
  705. utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
  706. continue
  707. }
  708. classifyId = 13
  709. frequency = "周度"
  710. } else {
  711. dataTime, err = time.Parse("20060102", date)
  712. if err != nil {
  713. fmt.Println(err)
  714. utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
  715. continue
  716. }
  717. }
  718. }
  719. for k, v := range row {
  720. columTitle := columMap[k]
  721. //value := ""
  722. indexName := secName + columTitle
  723. if columTitle != "日期" {
  724. if v == "<NULL>" || v == "<Blank>" || v == "-" {
  725. continue
  726. }
  727. if strings.Contains(indexName, "日照凌云海") {
  728. continue
  729. }
  730. value := strings.ReplaceAll(v, "%", "")
  731. item := models.BaseFromHisugarIndex{
  732. CreateTime: time.Now(),
  733. DataTime: dataTime.Format(utils.FormatDate),
  734. ModifyTime: time.Now(),
  735. Value: value,
  736. IndexName: indexName,
  737. Unit: HisugarGuoChanTangUnitMap[name],
  738. Frequency: frequency,
  739. ClassifyId: uint(classifyId),
  740. IndexNameStr: secName,
  741. MarketName: columTitle,
  742. Describe: DescribeMap[name],
  743. }
  744. if name == "周度含水乙醇折糖价" {
  745. item.IndexName = secName
  746. item.MarketName = ""
  747. }
  748. fmt.Println(item.DataTime, item.IndexName, value)
  749. indexList = append(indexList, &item)
  750. }
  751. }
  752. }
  753. // 写入数据库
  754. err = PostHandleHisugar(indexList)
  755. if err != nil {
  756. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  757. fmt.Println("PostHandleHisugar err", err)
  758. return
  759. }
  760. }
  761. return
  762. }
  763. // 一年一行,1-12月
  764. // 食糖月度进口量
  765. func AnalysisHiSugar6(name, reqParam, body string) (err error) {
  766. secName := ""
  767. columMap := make(map[string]string)
  768. var req ChartRequestSimple
  769. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  770. err = e
  771. log.Println(err)
  772. return
  773. } else {
  774. secName = req.SceneName
  775. fmt.Println(secName)
  776. for _, column := range req.Columns {
  777. columMap[column.AliasName] = column.Title
  778. }
  779. }
  780. var resp HisugarResponseDataSimple
  781. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  782. err = e
  783. log.Println(err)
  784. return
  785. } else {
  786. indexList := make([]*models.BaseFromHisugarIndex, 0)
  787. for _, row := range resp.Rows {
  788. monthValueMap := make(map[int]string)
  789. year := 0
  790. dataTime := time.Time{}
  791. for k, v := range row {
  792. columTitle := columMap[k]
  793. monthStr := ""
  794. month := 0
  795. //value := ""
  796. if strings.Contains(columTitle, "年份") {
  797. // 年份
  798. year, _ = strconv.Atoi(v)
  799. } else if strings.Contains(columTitle, "月") {
  800. monthStr = strings.TrimRight(columTitle, "月")
  801. month, _ = strconv.Atoi(monthStr)
  802. monthValueMap[month] = v
  803. }
  804. }
  805. for month, value := range monthValueMap {
  806. if value == "<NULL>" || value == "<Blank>" {
  807. continue
  808. }
  809. value = strings.ReplaceAll(value, "%", "")
  810. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  811. dataTime = dataTime.AddDate(0, 1, -1)
  812. item := models.BaseFromHisugarIndex{
  813. IndexName: secName,
  814. ClassifyId: 12,
  815. Unit: HisugarGuoChanTangUnitMap[name],
  816. Frequency: "月度",
  817. DataTime: dataTime.Format(utils.FormatDate),
  818. CreateTime: time.Now(),
  819. ModifyTime: time.Now(),
  820. Value: value,
  821. Describe: DescribeMap[name],
  822. }
  823. if name == "巴西食糖月度出口量" {
  824. item.ClassifyId = 13
  825. }
  826. fmt.Println(item.DataTime, secName, value)
  827. indexList = append(indexList, &item)
  828. }
  829. }
  830. // 写入数据库
  831. //err = PostHandleHisugar(indexList)
  832. //if err != nil {
  833. // utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  834. // fmt.Println("PostHandleHisugar err", err)
  835. // return
  836. //}
  837. }
  838. return
  839. }
  840. // 第一列月日,后面每一列是年份
  841. // 巴西港口等待船只数量
  842. func AnalysisHiSugar7(name, reqParam, body string) (err error) {
  843. secName := ""
  844. columMap := make(map[string]string)
  845. var req ChartRequestSimple
  846. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  847. err = e
  848. log.Println(err)
  849. return
  850. } else {
  851. secName = req.SceneName
  852. fmt.Println(secName)
  853. for _, column := range req.Columns {
  854. columMap[column.AliasName] = column.Title
  855. }
  856. }
  857. var resp HisugarResponseDataSimple
  858. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  859. err = e
  860. log.Println(err)
  861. return
  862. } else {
  863. indexList := make([]*models.BaseFromHisugarIndex, 0)
  864. for _, row := range resp.Rows {
  865. yeareMap := make(map[int]string)
  866. year := 0
  867. monthDay := time.Time{}
  868. for k, v := range row {
  869. columTitle := columMap[k]
  870. yearStr := ""
  871. //month := 0
  872. //day := 0
  873. //value := ""
  874. if strings.Contains(columTitle, "日期") {
  875. // 日期
  876. //year, _ = strconv.Atoi(v)
  877. v = strings.ReplaceAll(v, " ", "")
  878. monthDay, err = utils.ParseTimeShort(v)
  879. if err != nil {
  880. fmt.Println(err)
  881. utils.FileLog.Error(fmt.Sprintf("时间解析错误:%v", err))
  882. return
  883. }
  884. //month = int(dataTime.Month())
  885. //day = dataTime.Day()
  886. } else if strings.Contains(columTitle, "年") {
  887. yearStr = strings.TrimRight(columTitle, "年")
  888. year, _ = strconv.Atoi(yearStr)
  889. yeareMap[year] = v
  890. }
  891. }
  892. for year, value := range yeareMap {
  893. if value == "<NULL>" || value == "<Blank>" {
  894. continue
  895. }
  896. value = strings.ReplaceAll(value, "%", "")
  897. dataTime := time.Date(year, monthDay.Month(), monthDay.Day(), 0, 0, 0, 0, time.Local)
  898. //dataTime = dataTime.AddDate(0, 1, -1)
  899. item := models.BaseFromHisugarIndex{
  900. IndexName: secName,
  901. ClassifyId: 13,
  902. Unit: HisugarGuoChanTangUnitMap[name],
  903. Frequency: "周度",
  904. DataTime: dataTime.Format(utils.FormatDate),
  905. CreateTime: time.Now(),
  906. ModifyTime: time.Now(),
  907. Value: value,
  908. Describe: DescribeMap[name],
  909. }
  910. fmt.Println(item.DataTime, secName, value)
  911. indexList = append(indexList, &item)
  912. }
  913. }
  914. // 写入数据库
  915. err = PostHandleHisugar(indexList)
  916. if err != nil {
  917. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  918. fmt.Println("PostHandleHisugar err", err)
  919. return
  920. }
  921. }
  922. return
  923. }
  924. // 10,11,12月是上一年的,年份格式2023/24
  925. // 印度食糖月度出口量
  926. func AnalysisHiSugar8(name, reqParam, body string) (err error) {
  927. secName := ""
  928. columMap := make(map[string]string)
  929. var req ChartRequestSimple
  930. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  931. err = e
  932. log.Println(err)
  933. return
  934. } else {
  935. secName = req.SceneName
  936. fmt.Println(secName)
  937. for _, column := range req.Columns {
  938. columMap[column.AliasName] = column.Title
  939. }
  940. }
  941. var resp HisugarResponseDataSimple
  942. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  943. err = e
  944. log.Println(err)
  945. return
  946. } else {
  947. indexList := make([]*models.BaseFromHisugarIndex, 0)
  948. for _, row := range resp.Rows {
  949. monthValueMap := make(map[int]string)
  950. yearStrSlice := make([]string, 0)
  951. year := 0
  952. dataTime := time.Time{}
  953. for k, v := range row {
  954. columTitle := columMap[k]
  955. yearSlice := strings.Split(v, "/")
  956. monthStr := ""
  957. month := 0
  958. //value := ""
  959. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
  960. // 年份
  961. for i, s := range yearSlice {
  962. if i == 1 {
  963. yearStrSlice = append(yearStrSlice, "20"+s)
  964. } else {
  965. yearStrSlice = append(yearStrSlice, s)
  966. }
  967. }
  968. } else if strings.Contains(columTitle, "月") {
  969. monthStr = strings.TrimRight(columTitle, "月")
  970. month, _ = strconv.Atoi(monthStr)
  971. monthValueMap[month] = v
  972. }
  973. }
  974. for month, value := range monthValueMap {
  975. if value == "<NULL>" || value == "<Blank>" {
  976. continue
  977. }
  978. value = strings.ReplaceAll(value, "%", "")
  979. if month > 9 && month < 13 {
  980. year, _ = strconv.Atoi(yearStrSlice[0])
  981. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  982. dataTime = dataTime.AddDate(0, 1, -1)
  983. } else {
  984. year, _ = strconv.Atoi(yearStrSlice[1])
  985. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  986. dataTime = dataTime.AddDate(0, 1, -1)
  987. }
  988. item := models.BaseFromHisugarIndex{
  989. IndexName: secName,
  990. ClassifyId: 14,
  991. Unit: HisugarGuoChanTangUnitMap[name],
  992. Frequency: "月度",
  993. DataTime: dataTime.Format(utils.FormatDate),
  994. CreateTime: time.Now(),
  995. ModifyTime: time.Now(),
  996. Value: value,
  997. Describe: DescribeMap[name],
  998. }
  999. fmt.Println(item.DataTime, secName, value)
  1000. indexList = append(indexList, &item)
  1001. }
  1002. }
  1003. // 写入数据库
  1004. err = PostHandleHisugar(indexList)
  1005. if err != nil {
  1006. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1007. fmt.Println("PostHandleHisugar err", err)
  1008. return
  1009. }
  1010. }
  1011. return
  1012. }
  1013. // 10,11,12月是上一年的,年份格式23/24,旬度
  1014. // 泰国双周糖累计产量
  1015. func AnalysisHiSugar9(name, reqParam, body string) (err error) {
  1016. secName := ""
  1017. columMap := make(map[string]string)
  1018. var req ChartRequestSimple
  1019. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  1020. err = e
  1021. log.Println(err)
  1022. return
  1023. } else {
  1024. secName = req.SceneName
  1025. fmt.Println(secName)
  1026. for _, column := range req.Columns {
  1027. columMap[column.AliasName] = column.Title
  1028. }
  1029. }
  1030. var resp HisugarResponseDataSimple
  1031. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  1032. err = e
  1033. log.Println(err)
  1034. return
  1035. } else {
  1036. indexList := make([]*models.BaseFromHisugarIndex, 0)
  1037. for _, row := range resp.Rows {
  1038. monthValueMap := make(map[int]string)
  1039. dayValueMap := make(map[int]int)
  1040. yearStrSlice := make([]string, 0)
  1041. year := 0
  1042. dataTime := time.Time{}
  1043. for k, v := range row {
  1044. columTitle := columMap[k]
  1045. yearSlice := strings.Split(v, "/")
  1046. monthStr := ""
  1047. month := 0
  1048. //value := ""
  1049. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_吨") {
  1050. // 年份
  1051. for _, s := range yearSlice {
  1052. yearStrSlice = append(yearStrSlice, "20"+s)
  1053. }
  1054. } else if strings.Contains(columTitle, "月") {
  1055. if strings.Contains(columTitle, "月上半月") {
  1056. monthStr = strings.TrimRight(columTitle, "月上半月")
  1057. month, _ = strconv.Atoi(monthStr)
  1058. dayValueMap[month] = 15
  1059. } else if strings.Contains(columTitle, "月下半月") {
  1060. monthStr = strings.TrimRight(columTitle, "月下半月")
  1061. month, _ = strconv.Atoi(monthStr)
  1062. dayValueMap[month] = 25
  1063. }
  1064. monthValueMap[month] = v
  1065. }
  1066. }
  1067. for month, value := range monthValueMap {
  1068. if value == "<NULL>" || value == "<Blank>" {
  1069. continue
  1070. }
  1071. value = strings.ReplaceAll(value, "%", "")
  1072. if month > 11 {
  1073. year, _ = strconv.Atoi(yearStrSlice[0])
  1074. } else {
  1075. year, _ = strconv.Atoi(yearStrSlice[1])
  1076. }
  1077. if dayValueMap[month] > 20 {
  1078. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  1079. dataTime = dataTime.AddDate(0, 1, -1)
  1080. } else {
  1081. dataTime = time.Date(year, time.Month(month), 15, 0, 0, 0, 0, time.Local)
  1082. }
  1083. item := models.BaseFromHisugarIndex{
  1084. IndexName: secName,
  1085. ClassifyId: 15,
  1086. Unit: HisugarGuoChanTangUnitMap[name],
  1087. Frequency: "月度",
  1088. DataTime: dataTime.Format(utils.FormatDate),
  1089. CreateTime: time.Now(),
  1090. ModifyTime: time.Now(),
  1091. Value: value,
  1092. Describe: DescribeMap[name],
  1093. }
  1094. fmt.Println(item.DataTime, secName, value)
  1095. indexList = append(indexList, &item)
  1096. }
  1097. }
  1098. // 写入数据库
  1099. err = PostHandleHisugar(indexList)
  1100. if err != nil {
  1101. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1102. fmt.Println("PostHandleHisugar err", err)
  1103. return
  1104. }
  1105. }
  1106. return
  1107. }
  1108. // 11,12是上一年的,年份23/24,横轴日期11月15,11月30
  1109. // 印度双周累计产糖量
  1110. func AnalysisHiSugar10(name, reqParam, body string) (err error) {
  1111. secName := ""
  1112. columMap := make(map[string]string)
  1113. var req ChartRequestSimple
  1114. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  1115. err = e
  1116. log.Println(err)
  1117. return
  1118. } else {
  1119. secName = req.SceneName
  1120. fmt.Println(secName)
  1121. for _, column := range req.Columns {
  1122. columMap[column.AliasName] = column.Title
  1123. }
  1124. }
  1125. var resp HisugarResponseDataSimple
  1126. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  1127. err = e
  1128. log.Println(err)
  1129. return
  1130. } else {
  1131. indexList := make([]*models.BaseFromHisugarIndex, 0)
  1132. for _, row := range resp.Rows {
  1133. //monthValueMap := make(map[int]string)
  1134. //dayValueMap := make(map[int]int)
  1135. dateValueMap := make(map[time.Time]string)
  1136. yearStrSlice := make([]string, 0)
  1137. year := 0
  1138. dataTime := time.Time{}
  1139. for k, v := range row {
  1140. columTitle := columMap[k]
  1141. yearSlice := strings.Split(v, "/")
  1142. //monthStr := ""
  1143. month := 0
  1144. day := 0
  1145. //value := ""
  1146. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
  1147. // 年份
  1148. for _, s := range yearSlice {
  1149. yearStrSlice = append(yearStrSlice, "20"+s)
  1150. }
  1151. } else if strings.Contains(columTitle, "月") {
  1152. dateSlice := strings.Split(columTitle, "月")
  1153. if len(dateSlice) == 2 {
  1154. month, _ = strconv.Atoi(dateSlice[0])
  1155. day, _ = strconv.Atoi(dateSlice[1])
  1156. }
  1157. // 这个时候不一定有年份,所以先搞个假的年份,后面赋值真年份
  1158. dataTime = time.Date(2000, time.Month(month), day, 0, 0, 0, 0, time.Local)
  1159. dateValueMap[dataTime] = v
  1160. }
  1161. }
  1162. for date, value := range dateValueMap {
  1163. if value == "<NULL>" || value == "<Blank>" || value == "-" {
  1164. continue
  1165. }
  1166. if date.Month() == 11 || date.Month() == 12 {
  1167. year, _ = strconv.Atoi(yearStrSlice[0])
  1168. //dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  1169. //dataTime = dataTime.AddDate(0, 1, -1)
  1170. } else {
  1171. year, _ = strconv.Atoi(yearStrSlice[1])
  1172. //dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  1173. //dataTime = dataTime.AddDate(0, 1, -1)
  1174. }
  1175. date = time.Date(year, date.Month(), date.Day(), 0, 0, 0, 0, time.Local)
  1176. item := models.BaseFromHisugarIndex{
  1177. DataTime: date.Format(utils.FormatDate),
  1178. Value: value,
  1179. IndexName: secName,
  1180. Unit: HisugarGuoChanTangUnitMap[name],
  1181. CreateTime: time.Now(),
  1182. ModifyTime: time.Now(),
  1183. ClassifyId: HisugarGuoChanTangClassifyMap[name],
  1184. Frequency: "旬度",
  1185. Describe: DescribeMap[name],
  1186. }
  1187. fmt.Println(item.DataTime, value)
  1188. indexList = append(indexList, &item)
  1189. }
  1190. }
  1191. // 写入数据库
  1192. err = PostHandleHisugar(indexList)
  1193. if err != nil {
  1194. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1195. fmt.Println("PostHandleHisugar err", err)
  1196. return
  1197. }
  1198. }
  1199. return
  1200. }
  1201. // 4月16到12月是上一年的,年份格式23/24,旬度
  1202. // 巴西双周累计产糖量
  1203. func AnalysisHiSugar11(name, reqParam, body string) (err error) {
  1204. secName := ""
  1205. columMap := make(map[string]string)
  1206. var req ChartRequestSimple
  1207. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  1208. err = e
  1209. log.Println(err)
  1210. return
  1211. } else {
  1212. secName = req.SceneName
  1213. fmt.Println(secName)
  1214. for _, column := range req.Columns {
  1215. columMap[column.AliasName] = column.Title
  1216. }
  1217. }
  1218. var resp HisugarResponseDataSimple
  1219. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  1220. err = e
  1221. log.Println(err)
  1222. return
  1223. } else {
  1224. indexList := make([]*models.BaseFromHisugarIndex, 0)
  1225. for _, row := range resp.Rows {
  1226. monthValueMap := make(map[int]string)
  1227. dayValueMap := make(map[int]int)
  1228. yearStrSlice := make([]string, 0)
  1229. year := 0
  1230. dataTime := time.Time{}
  1231. for k, v := range row {
  1232. columTitle := columMap[k]
  1233. yearSlice := strings.Split(v, "/")
  1234. monthStr := ""
  1235. month := 0
  1236. //value := ""
  1237. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_吨") {
  1238. // 年份
  1239. for _, s := range yearSlice {
  1240. yearStrSlice = append(yearStrSlice, "20"+s)
  1241. }
  1242. } else if strings.Contains(columTitle, "月") {
  1243. if strings.Contains(columTitle, "月16日") {
  1244. monthStr = strings.TrimRight(columTitle, "月16日")
  1245. month, _ = strconv.Atoi(monthStr)
  1246. dayValueMap[month] = 16
  1247. } else if strings.Contains(columTitle, "月1日") {
  1248. monthStr = strings.TrimRight(columTitle, "月1日")
  1249. month, _ = strconv.Atoi(monthStr)
  1250. dayValueMap[month] = 1
  1251. }
  1252. monthValueMap[month] = v
  1253. }
  1254. }
  1255. for month, value := range monthValueMap {
  1256. if value == "<NULL>" || value == "<Blank>" {
  1257. continue
  1258. }
  1259. value = strings.ReplaceAll(value, "%", "")
  1260. if month > 4 && dayValueMap[month] > 15 {
  1261. year, _ = strconv.Atoi(yearStrSlice[0])
  1262. } else {
  1263. year, _ = strconv.Atoi(yearStrSlice[1])
  1264. }
  1265. dataTime = time.Date(year, time.Month(month), dayValueMap[month], 0, 0, 0, 0, time.Local)
  1266. item := models.BaseFromHisugarIndex{
  1267. IndexName: secName,
  1268. ClassifyId: 13,
  1269. Unit: HisugarGuoChanTangUnitMap[name],
  1270. Frequency: "旬度",
  1271. DataTime: dataTime.Format(utils.FormatDate),
  1272. CreateTime: time.Now(),
  1273. ModifyTime: time.Now(),
  1274. Value: value,
  1275. Describe: DescribeMap[name],
  1276. }
  1277. fmt.Println(item.DataTime, secName, value)
  1278. indexList = append(indexList, &item)
  1279. }
  1280. }
  1281. //写入数据库
  1282. err = PostHandleHisugar(indexList)
  1283. if err != nil {
  1284. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1285. fmt.Println("PostHandleHisugar err", err)
  1286. return
  1287. }
  1288. }
  1289. return
  1290. }
  1291. // 4月16到12月是上一年的,年份格式23/24,旬度
  1292. // 巴西双周食糖库存,中南部双周累计产糖量,中南部双周糖库存,中南部双周乙醇产量
  1293. func AnalysisHiSugar12(name, reqParam, body string) (err error) {
  1294. secName := ""
  1295. columMap := make(map[string]string)
  1296. var req ChartRequestSimple
  1297. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  1298. err = e
  1299. log.Println(err)
  1300. return
  1301. } else {
  1302. secName = req.SceneName
  1303. fmt.Println(secName)
  1304. for _, column := range req.Columns {
  1305. columMap[column.AliasName] = column.Title
  1306. }
  1307. }
  1308. var resp HisugarResponseDataSimple
  1309. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  1310. err = e
  1311. log.Println(err)
  1312. return
  1313. } else {
  1314. indexList := make([]*models.BaseFromHisugarIndex, 0)
  1315. for _, row := range resp.Rows {
  1316. monthValueMap := make(map[int]string)
  1317. dayValueMap := make(map[int]int)
  1318. yearStrSlice := make([]string, 0)
  1319. year := 0
  1320. dataTime := time.Time{}
  1321. for k, v := range row {
  1322. columTitle := columMap[k]
  1323. yearSlice := strings.Split(v, "/")
  1324. //monthStr := ""
  1325. month := 0
  1326. //value := ""
  1327. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨" ||
  1328. columTitle == "榨季_立方米" || columTitle == "榨季_吨" || columTitle == "榨季_百分比") {
  1329. // 年份
  1330. for _, s := range yearSlice {
  1331. yearStrSlice = append(yearStrSlice, "20"+s)
  1332. }
  1333. } else if strings.Contains(columTitle, "月") {
  1334. date, _ := time.Parse("1月2日", columTitle)
  1335. month = int(date.Month())
  1336. dayValueMap[month] = date.Day()
  1337. monthValueMap[month] = v
  1338. //if strings.Contains(columTitle, "月16日") {
  1339. // monthStr = strings.TrimRight(columTitle, "月16日")
  1340. // month, _ = strconv.Atoi(monthStr)
  1341. // dayValueMap[month] = 16
  1342. //} else if strings.Contains(columTitle, "月1日") {
  1343. // monthStr = strings.TrimRight(columTitle, "月1日")
  1344. // month, _ = strconv.Atoi(monthStr)
  1345. // dayValueMap[month] = 1
  1346. //}
  1347. //monthValueMap[month] = v
  1348. }
  1349. }
  1350. for month, value := range monthValueMap {
  1351. if value == "<NULL>" || value == "<Blank>" {
  1352. continue
  1353. }
  1354. value = strings.ReplaceAll(value, "%", "")
  1355. if month > 3 {
  1356. year, _ = strconv.Atoi(yearStrSlice[0])
  1357. } else {
  1358. year, _ = strconv.Atoi(yearStrSlice[1])
  1359. }
  1360. dataTime = time.Date(year, time.Month(month), dayValueMap[month], 0, 0, 0, 0, time.Local)
  1361. item := models.BaseFromHisugarIndex{
  1362. IndexName: secName,
  1363. ClassifyId: 13,
  1364. Unit: HisugarGuoChanTangUnitMap[name],
  1365. Frequency: "旬度",
  1366. DataTime: dataTime.Format(utils.FormatDate),
  1367. CreateTime: time.Now(),
  1368. ModifyTime: time.Now(),
  1369. Value: value,
  1370. Describe: DescribeMap[name],
  1371. }
  1372. fmt.Println(item.DataTime, secName, value)
  1373. indexList = append(indexList, &item)
  1374. }
  1375. }
  1376. //写入数据库
  1377. err = PostHandleHisugar(indexList)
  1378. if err != nil {
  1379. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1380. fmt.Println("PostHandleHisugar err", err)
  1381. return
  1382. }
  1383. }
  1384. return
  1385. }
  1386. // 4-12月是上一年的
  1387. // 巴西中南部乙醇月度销售情况,巴西中南部乙醇国内销售情况
  1388. func AnalysisHiSugar13(name, reqParam, body string) (err error) {
  1389. secName := ""
  1390. columMap := make(map[string]string)
  1391. var req ChartRequestSimple
  1392. if e := json.Unmarshal([]byte(reqParam), &req); e != nil {
  1393. err = e
  1394. log.Println(err)
  1395. return
  1396. } else {
  1397. secName = req.SceneName
  1398. fmt.Println(secName)
  1399. for _, column := range req.Columns {
  1400. columMap[column.AliasName] = column.Title
  1401. }
  1402. }
  1403. var resp HisugarResponseDataSimple
  1404. if e := json.Unmarshal([]byte(body), &resp); e != nil {
  1405. err = e
  1406. log.Println(err)
  1407. return
  1408. } else {
  1409. indexList := make([]*models.BaseFromHisugarIndex, 0)
  1410. for _, row := range resp.Rows {
  1411. monthValueMap := make(map[int]string)
  1412. yearStrSlice := make([]string, 0)
  1413. year := 0
  1414. dataTime := time.Time{}
  1415. for k, v := range row {
  1416. columTitle := columMap[k]
  1417. yearSlice := strings.Split(v, "/")
  1418. monthStr := ""
  1419. month := 0
  1420. //value := ""
  1421. if strings.Contains(v, "/") && (columTitle == "榨季" || columTitle == "榨季_万吨") {
  1422. // 年份
  1423. for _, s := range yearSlice {
  1424. yearStrSlice = append(yearStrSlice, "20"+s)
  1425. }
  1426. } else if strings.Contains(columTitle, "月") {
  1427. monthStr = strings.TrimRight(columTitle, "月")
  1428. month, _ = strconv.Atoi(monthStr)
  1429. monthValueMap[month] = v
  1430. }
  1431. }
  1432. for month, value := range monthValueMap {
  1433. if value == "<NULL>" || value == "<Blank>" || value == "-" {
  1434. continue
  1435. }
  1436. value = strings.ReplaceAll(value, "%", "")
  1437. if month > 3 && month < 13 {
  1438. year, _ = strconv.Atoi(yearStrSlice[0])
  1439. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  1440. dataTime = dataTime.AddDate(0, 1, -1)
  1441. } else {
  1442. year, _ = strconv.Atoi(yearStrSlice[1])
  1443. dataTime = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  1444. dataTime = dataTime.AddDate(0, 1, -1)
  1445. }
  1446. item := models.BaseFromHisugarIndex{
  1447. IndexName: secName,
  1448. ClassifyId: HisugarGuoChanTangClassifyMap[name],
  1449. Unit: HisugarGuoChanTangUnitMap[name],
  1450. Frequency: "月度",
  1451. DataTime: dataTime.Format(utils.FormatDate),
  1452. CreateTime: time.Now(),
  1453. ModifyTime: time.Now(),
  1454. Value: value,
  1455. Describe: DescribeMap[name],
  1456. }
  1457. fmt.Println(item.DataTime, value)
  1458. indexList = append(indexList, &item)
  1459. }
  1460. }
  1461. // 写入数据库
  1462. err = PostHandleHisugar(indexList)
  1463. if err != nil {
  1464. utils.FileLog.Error(fmt.Sprintf("PostHandleHisugar err:%v", err))
  1465. fmt.Println("PostHandleHisugar err", err)
  1466. return
  1467. }
  1468. }
  1469. return
  1470. }