data_source_longzhong.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hongze_task/models"
  9. "hongze/hongze_task/utils"
  10. "net/url"
  11. "os"
  12. "path/filepath"
  13. "rdluck_tools/http"
  14. "strconv"
  15. "time"
  16. )
  17. //获取隆众信息表中指标
  18. func GetLongZhongTargetInfoByExcel() {
  19. var err error
  20. defer func() {
  21. if err != nil {
  22. fmt.Println("err:" + err.Error())
  23. go utils.SendEmail("获取隆众指标信息失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  24. return
  25. }
  26. }()
  27. excelPath := `./static/longzhong_0824.xlsx`
  28. file, err := xlsx.OpenFile(excelPath)
  29. if err != nil {
  30. fmt.Println("err:", err.Error())
  31. return
  32. }
  33. sheets := file.Sheets
  34. for k, v := range sheets {
  35. fmt.Println(k, v.Name)
  36. classify, err := models.GetEdbdataClassifyByClassifyName(v.Name)
  37. if err != nil {
  38. if err.Error() == utils.ErrNoRow() {
  39. err = errors.New("分类不存在:Err:" + err.Error())
  40. } else {
  41. err = err
  42. }
  43. return
  44. }
  45. if classify == nil {
  46. err = errors.New("分类不存在,请重新核对")
  47. return
  48. }
  49. classifyId := classify.ClassifyId
  50. classifyName := classify.ClassifyName
  51. fmt.Println(classifyId, classifyName)
  52. maxRow := v.MaxRow
  53. //maxCol := v.MaxCol
  54. fmt.Println(classifyName, maxRow)
  55. for i := 0; i < maxRow; i++ {
  56. row := v.Row(i)
  57. longzhongClassify := ""
  58. if i > 0 {
  59. cells := row.Cells
  60. longzhongClassifyNew := cells[0].String()
  61. if longzhongClassifyNew != "" {
  62. longzhongClassify = longzhongClassifyNew
  63. }
  64. secName := cells[1].Value
  65. frequency := cells[2].Value
  66. LongzhongId := cells[3].Value
  67. remark := cells[4].String()
  68. item := new(models.DataSourceLongzhong)
  69. item.ClassifyId = classifyId
  70. item.ClassifyName = classifyName
  71. item.SecName = secName
  72. item.Frequency = frequency
  73. item.LongzhongId = LongzhongId
  74. item.Remark = remark
  75. item.LongzhongClassify = longzhongClassify
  76. _, err = models.AddDataSourceLongzhong(item)
  77. if err != nil {
  78. fmt.Println("Err:", err.Error())
  79. return
  80. }
  81. }
  82. }
  83. }
  84. }
  85. func GetLzProductList(cont context.Context) (err error) {
  86. utils.FileLog.Info("start GetLzProductList")
  87. var bodyStr string
  88. defer func() {
  89. if err != nil {
  90. fmt.Println("Err:" + err.Error())
  91. go utils.SendEmail("获取隆众指标数据失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error()+";body:"+bodyStr, utils.EmailSendToUsers)
  92. }
  93. }()
  94. postUrl := `http://info.oilchem.net/cust/interfacenew/getProductUnitListNew`
  95. username := "hzmd"
  96. password := "HZMD2020"
  97. timestamp := fmt.Sprintf("%d", time.Now().Unix())
  98. fmt.Println(timestamp)
  99. token := utils.MD5(username + timestamp + utils.MD5(password))
  100. fmt.Println("token:", token)
  101. param := url.Values{}
  102. param.Add("username", username)
  103. param.Add("password", password)
  104. param.Add("timestamp", timestamp)
  105. param.Add("token", token)
  106. utils.FileLog.Info("%s", param.Encode())
  107. body, err := http.Post(postUrl, param.Encode())
  108. if err != nil {
  109. fmt.Println("err:", err.Error())
  110. return
  111. }
  112. result := string(body)
  113. if result == "" {
  114. err = errors.New("返回内容为空")
  115. return
  116. }
  117. resp := new(models.LzProductInfoResp)
  118. err = json.Unmarshal(body, &resp)
  119. if err != nil {
  120. bodyStr = string(body)
  121. fmt.Println("json.Unmarshal Err:" + err.Error())
  122. return
  123. }
  124. if resp.Code != "1" {
  125. fmt.Println("获取信息失败")
  126. err = errors.New("Code:" + resp.Code + ";Msg:" + resp.Msg)
  127. return
  128. }
  129. fmt.Println("len")
  130. fmt.Println(len(resp.Data))
  131. utils.FileLog.Info("%s", string(body))
  132. for _, v := range resp.Data {
  133. fmt.Println(v.Unitid, v.ProName, v.ProUnitName)
  134. var classifyId int
  135. var classifyName string
  136. classify, err := models.GetEdbdataClassifyByClassifyName(v.ProName)
  137. if err != nil && err.Error() != utils.ErrNoRow() {
  138. fmt.Println("获取分类失败,Err:" + err.Error())
  139. return err
  140. }
  141. if classify == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  142. classifyItem := new(models.EdbdataClassify)
  143. classifyItem.ClassifyName = v.ProName
  144. classifyItem.ParentId = 4
  145. classifyItem.CreateTime = time.Now()
  146. newId, err := models.AddEdbdataClassify(classifyItem)
  147. if err != nil {
  148. fmt.Println("新增分类失败,Err:" + err.Error())
  149. return err
  150. }
  151. classifyId = int(newId)
  152. classifyName = v.ProName
  153. } else {
  154. classifyId = classify.ClassifyId
  155. classifyName = classify.ClassifyName
  156. }
  157. count, err := models.GetLongzhonginfoCount(classifyId, v.Unitid)
  158. if err != nil {
  159. fmt.Println("判断指标是否存在失败,Err:" + err.Error())
  160. return err
  161. }
  162. secNameCount, _ := models.GetLongzhonginfoBySecNameCount(v.ProUnitName)
  163. if count > 0 || secNameCount > 0 { //修改
  164. lzProduct := new(models.Longzhonginfo)
  165. lzProduct.SecName = v.ProUnitName
  166. lzProduct.Frequency = v.LzType
  167. lzProduct.ClassifyId = classifyId
  168. lzProduct.ClassifyName = classifyName
  169. lzProduct.Unit = v.Unit
  170. lzProduct.CreateTime = time.Now()
  171. lzProduct.IsNormal = v.IsNormal
  172. lzProduct.LastModifyDate = v.Maxdate
  173. lzProduct.Unitid = v.Unitid
  174. lzProduct.TempId = v.Tempid
  175. lzProduct.TempName = v.TempName
  176. lzProduct.ModifyTime = time.Now()
  177. err = models.ModifyLongzhonginfo(lzProduct)
  178. if err != nil {
  179. fmt.Println("修改失败,Err:" + err.Error())
  180. return err
  181. }
  182. } else { //新增
  183. maxId, err := models.GetLongzhonginfoMaxId()
  184. if err != nil {
  185. fmt.Println("获取编码失败,err:" + err.Error())
  186. return err
  187. }
  188. tradeCode := fmt.Sprintf("L%06d", maxId+1)
  189. lzProduct := new(models.Longzhonginfo)
  190. lzProduct.TradeCode = tradeCode
  191. lzProduct.SecName = v.ProUnitName
  192. lzProduct.Frequency = v.LzType
  193. lzProduct.ClassifyId = classifyId
  194. lzProduct.ClassifyName = classifyName
  195. lzProduct.Unit = v.Unit
  196. lzProduct.CreateTime = time.Now()
  197. if v.IsNormal == "" {
  198. v.IsNormal = "1"
  199. }
  200. lzProduct.IsNormal = v.IsNormal
  201. lzProduct.LastModifyDate = v.Maxdate
  202. lzProduct.Unitid = v.Unitid
  203. lzProduct.TempId = v.Tempid
  204. lzProduct.TempName = v.TempName
  205. lzProduct.ModifyTime = time.Now()
  206. _, err = models.AddLongzhonginfo(lzProduct)
  207. if err != nil {
  208. fmt.Println("新增指标信息失败")
  209. return err
  210. }
  211. }
  212. }
  213. return
  214. }
  215. func GetLzProductDetail(cont context.Context) (err error) {
  216. utils.FileLogLz.Info("start GetLzProductDetail")
  217. defer func() {
  218. if err != nil {
  219. utils.FileLogLz.Info("Err:" + err.Error())
  220. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"GetLzProductDetail:失败提醒", "ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  221. }
  222. }()
  223. startDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  224. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  225. time.Sleep(5 * time.Second)
  226. pageSize := 30
  227. postUrl := `http://info.oilchem.net/cust/interfacenew/getProductUnitDetailNew`
  228. username := "hzmd"
  229. password := "HZMD2020"
  230. infoList, err := models.GetLongzhonginfoList()
  231. if err != nil {
  232. return
  233. }
  234. for _, v := range infoList {
  235. totalPage := 10
  236. for i := 1; i <= totalPage; i++ {
  237. displayTime, _ := models.GetDisplayTime(v.LongzhonginfoId)
  238. if displayTime != "" {
  239. startDate = displayTime
  240. }
  241. fmt.Println("page:", i, totalPage)
  242. utils.FileLogLz.Info("Page:%s", strconv.Itoa(i))
  243. timestamp := fmt.Sprintf("%d", time.Now().Unix())
  244. token := utils.MD5(username + timestamp + utils.MD5(password))
  245. param := url.Values{}
  246. param.Add("username", username)
  247. param.Add("password", password)
  248. param.Add("timestamp", timestamp)
  249. param.Add("token", token)
  250. param.Add("id", strconv.Itoa(v.Unitid))
  251. param.Add("startDate", startDate)
  252. param.Add("endDate", endDate)
  253. param.Add("pagesize", strconv.Itoa(pageSize))
  254. param.Add("page", strconv.Itoa(i))
  255. utils.FileLogLz.Info("GetLzProductDetail Param: %s", param.Encode())
  256. body, err := http.Post(postUrl, param.Encode())
  257. if err != nil {
  258. utils.FileLogLz.Info("Post Err:%s", err.Error())
  259. return err
  260. }
  261. utils.FileLogLz.Info("GetLzProductDetail Result: %s", string(body))
  262. resp := new(models.LzProductInfoDetailResp)
  263. err = json.Unmarshal(body, &resp)
  264. if err != nil {
  265. utils.FileLogLz.Info("Unmarshal Err:%s", err.Error())
  266. return err
  267. }
  268. if resp.Code != "1" {
  269. fmt.Println("获取信息失败")
  270. err = errors.New("Code:" + resp.Code + ";Msg:" + resp.Msg)
  271. return err
  272. }
  273. for k, v := range resp.Data {
  274. fmt.Println(k, v.UnitId, v.ProCnName)
  275. target, err := models.GetLongzhonginfoByUnitId(v.ProCnName, v.UnitId)
  276. if err != nil {
  277. if err.Error() != utils.ErrNoRow() {
  278. fmt.Println("获取target失败,err:" + err.Error())
  279. continue
  280. }
  281. fmt.Println("err:" + err.Error())
  282. return err
  283. }
  284. if target == nil {
  285. fmt.Println("target is empty:"+v.ProCnName, v.UnitId)
  286. continue
  287. }
  288. count, err := models.GetLongzhongdataCount(target.LongzhonginfoId, v.DataTime)
  289. if err != nil {
  290. fmt.Println("GetLongzhongdataCount Err:" + err.Error())
  291. return err
  292. }
  293. if count > 0 {
  294. lzdetail := new(models.Longzhongdata)
  295. lzdetail.CreateTime = time.Now()
  296. lzdetail.ModifyTime = time.Now()
  297. lzdetail.TradeCode = target.TradeCode
  298. lzdetail.LongzhonginfoId = target.LongzhonginfoId
  299. lzdetail.Dt = v.DataTime
  300. lzdetail.Close = v.UnitValue
  301. lzdetail.UnitDesc = v.UnitDesc
  302. lzdetail.UpdTime = v.UpdTime
  303. lzdetail.AddTime = v.AddTime
  304. lzdetail.DisplayTime = v.DisplayTime
  305. err = models.ModifyLongzhongdata(lzdetail)
  306. if err != nil {
  307. utils.FileLogLz.Info("ModifyLongzhongdata Err:" + err.Error())
  308. continue
  309. }
  310. } else {
  311. lzdetail := new(models.Longzhongdata)
  312. lzdetail.CreateTime = time.Now()
  313. lzdetail.ModifyTime = time.Now()
  314. lzdetail.TradeCode = target.TradeCode
  315. lzdetail.LongzhonginfoId = target.LongzhonginfoId
  316. lzdetail.Dt = v.DataTime
  317. lzdetail.Close = v.UnitValue
  318. lzdetail.UnitDesc = v.UnitDesc
  319. lzdetail.UpdTime = v.UpdTime
  320. lzdetail.AddTime = v.AddTime
  321. lzdetail.DisplayTime = v.DisplayTime
  322. err = models.AddLongzhongdata(lzdetail)
  323. if err != nil {
  324. utils.FileLogLz.Info("AddLongzhongdata Err:" + err.Error())
  325. continue
  326. }
  327. }
  328. }
  329. totalPage = resp.Page
  330. //time.Sleep(1 * time.Second)
  331. }
  332. }
  333. utils.FileLogLz.Info("end GetLzProductDetail")
  334. return
  335. }
  336. //获取历史隆众石化数据
  337. func GetHistoryLzProductDetail() (err error) {
  338. utils.FileLog.Info("start GetHistoryLzProductDetail")
  339. var msg string
  340. defer func() {
  341. if err != nil {
  342. fmt.Println("Err:" + err.Error())
  343. }
  344. if msg != "" {
  345. fmt.Println("msg:" + msg)
  346. }
  347. }()
  348. infoList, err := models.GetLongzhonginfoList()
  349. if err != nil {
  350. msg = "获取指标列表失败,Err:" + err.Error()
  351. return
  352. }
  353. for ik, iv := range infoList {
  354. fmt.Println(ik, iv.SecName, iv.LongzhonginfoId)
  355. startDate := "2020-01-01" //time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  356. endDate := "2020-12-31" //time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  357. //time.Sleep(1 * time.Second)
  358. pageSize := 30
  359. postUrl := `http://info.oilchem.net/cust/interfacenew/getProductUnitDetailNew`
  360. username := "hzmd"
  361. password := "HZMD2020"
  362. totalPage := 10
  363. for i := 1; i <= totalPage; i++ {
  364. fmt.Println("page:", i)
  365. timestamp := fmt.Sprintf("%d", time.Now().Unix())
  366. token := utils.MD5(username + timestamp + utils.MD5(password))
  367. param := url.Values{}
  368. param.Add("username", username)
  369. param.Add("password", password)
  370. param.Add("timestamp", timestamp)
  371. param.Add("token", token)
  372. param.Add("id", strconv.Itoa(iv.Unitid))
  373. param.Add("startDate", startDate)
  374. param.Add("endDate", endDate)
  375. if i > 1 {
  376. param.Add("page", strconv.Itoa(i))
  377. }
  378. param.Add("pagesize", strconv.Itoa(pageSize))
  379. utils.FileLog.Info("%s", param.Encode())
  380. fmt.Println("post url:", postUrl)
  381. fmt.Println("post params:", param.Encode())
  382. body, err := http.Post(postUrl, param.Encode())
  383. if err != nil {
  384. fmt.Println("err:", err.Error())
  385. return err
  386. }
  387. utils.FileLog.Info("%s", string(body))
  388. fmt.Println("body:", string(body))
  389. resp := new(models.LzProductInfoDetailResp)
  390. err = json.Unmarshal(body, &resp)
  391. if err != nil {
  392. fmt.Println("Unmarshal Err:" + err.Error())
  393. fmt.Println("body:", string(body))
  394. return err
  395. }
  396. if resp.Code != "1" {
  397. fmt.Println("获取信息失败")
  398. err = errors.New("Code:" + resp.Code + ";Msg:" + resp.Msg)
  399. return err
  400. }
  401. if i == totalPage && resp.Pagesize >= pageSize {
  402. totalPage = totalPage + 5
  403. }
  404. for k, v := range resp.Data {
  405. fmt.Println(k, v.UnitId, v.ProCnName)
  406. target, err := models.GetLongzhonginfoByUnitId(v.ProCnName, v.UnitId)
  407. if err != nil {
  408. if err.Error() != utils.ErrNoRow() {
  409. fmt.Println("获取target失败,err:" + err.Error())
  410. continue
  411. }
  412. fmt.Println("err:" + err.Error())
  413. return err
  414. }
  415. if target == nil {
  416. fmt.Println("target is empty:"+v.ProCnName, v.UnitId)
  417. continue
  418. }
  419. count, err := models.GetLongzhongdataCount(target.LongzhonginfoId, v.DataTime)
  420. if err != nil {
  421. fmt.Println("GetLongzhongdataCount Err:" + err.Error())
  422. return err
  423. }
  424. if count > 0 {
  425. fmt.Println("数据已存在:", iv.Unitid, iv.SecName, v.UnitValue, v.DataTime)
  426. lzdetail := new(models.Longzhongdata)
  427. lzdetail.CreateTime = time.Now()
  428. lzdetail.ModifyTime = time.Now()
  429. lzdetail.TradeCode = target.TradeCode
  430. lzdetail.LongzhonginfoId = target.LongzhonginfoId
  431. lzdetail.Dt = v.DataTime
  432. lzdetail.Close = v.UnitValue
  433. lzdetail.UnitDesc = v.UnitDesc
  434. lzdetail.UpdTime = v.UpdTime
  435. lzdetail.AddTime = v.AddTime
  436. lzdetail.DisplayTime = v.DisplayTime
  437. err = models.ModifyLongzhongdata(lzdetail)
  438. if err != nil {
  439. fmt.Println("ModifyLongzhongdata Err:" + err.Error())
  440. return err
  441. }
  442. } else {
  443. lzdetail := new(models.Longzhongdata)
  444. lzdetail.CreateTime = time.Now()
  445. lzdetail.ModifyTime = time.Now()
  446. lzdetail.TradeCode = target.TradeCode
  447. lzdetail.LongzhonginfoId = target.LongzhonginfoId
  448. lzdetail.Dt = v.DataTime
  449. lzdetail.Close = v.UnitValue
  450. lzdetail.UnitDesc = v.UnitDesc
  451. lzdetail.UpdTime = v.UpdTime
  452. lzdetail.AddTime = v.AddTime
  453. lzdetail.DisplayTime = v.DisplayTime
  454. err = models.AddLongzhongdata(lzdetail)
  455. if err != nil {
  456. fmt.Println("AddLongzhongdata Err:" + err.Error())
  457. return err
  458. }
  459. }
  460. }
  461. if i == 1 && len(resp.Data) == 0 {
  462. utils.FileLog.Info("%d", iv.Unitid)
  463. }
  464. if resp.Pagesize < pageSize || len(resp.Data) == 0 {
  465. break
  466. }
  467. //time.Sleep(1 * time.Second)
  468. }
  469. err = models.ModifyLongzhonginfoIsNormal(iv.LongzhonginfoId)
  470. if err != nil {
  471. fmt.Println("ModifyLongzhonginfoIsNormal:Err" + err.Error())
  472. }
  473. fmt.Println("sleep", iv.SecName)
  474. time.Sleep(1 * time.Second)
  475. }
  476. return
  477. }
  478. func GetLzPrice() {
  479. fmt.Println("start")
  480. /*getUrl:=`https://openapi.oilchem.net/price/getProduct?password=HZMD2020&type=guoji&username=hzmd`
  481. result,err:=http.Get(getUrl)
  482. fmt.Println(string(result),err)
  483. utils.FileLog.Info("%s",string(result))*/
  484. getUrl := `https://openapi.oilchem.net/price/getPrice?password=HZMD2020&type=guoji&username=hzmd&inStartDate=2020-08-20&inEndDate=2020-08-26`
  485. result, err := http.Get(getUrl)
  486. fmt.Println(string(result), err)
  487. utils.FileLog.Info("%s", string(result))
  488. fmt.Println("end")
  489. }
  490. func LzExportExcel() {
  491. var err error
  492. defer func() {
  493. if err != nil {
  494. fmt.Println("err:" + err.Error())
  495. }
  496. }()
  497. parentId := 4
  498. classifyList, err := models.GetEdbdataClassifyByParentId(parentId)
  499. if err != nil {
  500. return
  501. }
  502. xlsxFile := xlsx.NewFile()
  503. if err != nil {
  504. fmt.Println("生成文件失败" + err.Error())
  505. return
  506. }
  507. dir, _ := os.Executable()
  508. exPath := filepath.Dir(dir)
  509. downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  510. fmt.Println("downLoadnFilePath")
  511. fmt.Println(downLoadnFilePath)
  512. for _, v := range classifyList {
  513. fmt.Println(v.ClassifyId, v.ClassifyName)
  514. //获取指标
  515. secNameList, err := models.GetLongzhonginfoByClassifyId(v.ClassifyId)
  516. if err != nil {
  517. fmt.Println("获取数据失败,Err:" + err.Error())
  518. return
  519. }
  520. if len(secNameList) <= 0 {
  521. continue
  522. }
  523. sheetNew, err := xlsxFile.AddSheet(v.ClassifyName)
  524. if err != nil {
  525. fmt.Println("新增Sheet失败", err.Error())
  526. return
  527. }
  528. //获取指标数据
  529. windRow := sheetNew.AddRow()
  530. secNameRow := sheetNew.AddRow()
  531. frequencyRow := sheetNew.AddRow()
  532. unitRow := sheetNew.AddRow()
  533. lastModifyDateRow := sheetNew.AddRow()
  534. //获取分类下指标最大数据量
  535. dataMax, err := models.GetLongzhongDataMaxCount(v.ClassifyId)
  536. if err != nil {
  537. fmt.Println("获取指标最大数据量失败", err.Error())
  538. return
  539. }
  540. for _, sv := range secNameList {
  541. fmt.Println("line 399:", v.ClassifyId, v.ClassifyName, sv.SecName, sv.Frequency)
  542. windRow.AddCell().SetValue("Wind")
  543. secNameRow.AddCell().SetValue("指标名称")
  544. frequencyRow.AddCell().SetValue("频率")
  545. unitRow.AddCell().SetValue("单位")
  546. lastModifyDateRow.AddCell().SetValue("更新时间")
  547. secNameRow.AddCell().SetValue(sv.SecName)
  548. frequencyRow.AddCell().SetValue(sv.Frequency)
  549. unitRow.AddCell().SetValue(sv.Unit)
  550. lastModifyDateRow.AddCell().SetValue(sv.LastModifyDate)
  551. windRow.AddCell()
  552. windRow.AddCell()
  553. secNameRow.AddCell()
  554. frequencyRow.AddCell()
  555. unitRow.AddCell()
  556. lastModifyDateRow.AddCell()
  557. //获取数据
  558. dataList, err := models.GetLongzhongDataById(sv.LongzhonginfoId)
  559. if err != nil {
  560. fmt.Println("GetLongzhongDataById Err:" + err.Error())
  561. return
  562. }
  563. if len(dataList) <= 0 {
  564. for n := 0; n < dataMax; n++ {
  565. rowIndex := 5 + n
  566. row := sheetNew.Row(rowIndex)
  567. row.AddCell()
  568. row.AddCell()
  569. row.AddCell()
  570. }
  571. } else {
  572. endRowIndex := 0
  573. for rk, dv := range dataList {
  574. rowIndex := 5 + rk
  575. row := sheetNew.Row(rowIndex)
  576. row.AddCell().SetValue(dv.Dt)
  577. row.AddCell().SetFloat(dv.Close)
  578. row.AddCell()
  579. endRowIndex = rowIndex
  580. }
  581. if len(dataList) < dataMax {
  582. dataLen := dataMax - len(dataList)
  583. for n := 0; n < dataLen; n++ {
  584. rowIndex := (endRowIndex + 1) + n
  585. row := sheetNew.Row(rowIndex)
  586. row.AddCell()
  587. row.AddCell()
  588. row.AddCell()
  589. }
  590. }
  591. }
  592. }
  593. }
  594. err = xlsxFile.Save(downLoadnFilePath)
  595. fmt.Print("downLoadnFilePath:", downLoadnFilePath)
  596. if err != nil {
  597. return
  598. }
  599. }
  600. func GetLzProductPriceProduct(cont context.Context) (err error) {
  601. var msg string
  602. defer func() {
  603. if err != nil {
  604. fmt.Println("Err:" + err.Error())
  605. go utils.SendEmail("获取隆众价格指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  606. }
  607. if msg != "" {
  608. fmt.Println("msg:", msg)
  609. go utils.SendEmail("获取隆众价格指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";msg:"+msg, utils.EmailSendToUsers)
  610. }
  611. }()
  612. //chuchang, guonei, guoji, oil ,lingshou,guojioil,base,国内出厂,国内市场,国际市场,国内成品油批发价,国内成品油零售价,国际原油,基准价
  613. typeMap := make(map[string]string)
  614. typeMap["chuchang"] = "国内出厂"
  615. typeMap["guonei"] = "国内市场"
  616. typeMap["guoji"] = "国际市场"
  617. typeMap["oil"] = "国内成品油批发价"
  618. typeMap["lingshou"] = "国内成品油零售价"
  619. typeMap["guojioil"] = "国际原油"
  620. typeMap["base"] = "基准价"
  621. username := "hzmd"
  622. password := "HZMD2020"
  623. for k, v := range typeMap {
  624. fmt.Println(k, v)
  625. getUrl := `https://openapi.oilchem.net/price/getProduct?password=` + password + `&type=` + k + `&username=` + username + ``
  626. body, err := http.Get(getUrl)
  627. if err != nil {
  628. msg = "获取隆众价格指标失败:Err" + err.Error()
  629. return err
  630. }
  631. fmt.Println("getUrl:", getUrl)
  632. fmt.Println("body", string(body))
  633. utils.FileLog.Info("%s", string(body))
  634. infoList := new(models.LzPriceInfoResp)
  635. err = json.Unmarshal(body, &infoList)
  636. if err != nil {
  637. msg = "获取隆众价格指标失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
  638. return err
  639. }
  640. if infoList.Code != 1 {
  641. msg = "获取隆众价格指标失败:body " + string(body)
  642. return nil
  643. }
  644. for _, n := range infoList.Data {
  645. count, err := models.GetLongzhongpriceinfoCount(n.Id)
  646. if err != nil {
  647. msg = "判断隆众价格指标是否存在失败:err " + err.Error()
  648. return err
  649. }
  650. item := new(models.Longzhongpriceinfo)
  651. item.Standard = n.Standard
  652. item.ModelName = n.ModelName
  653. item.Unit = n.Unit
  654. item.AreaName = n.AreaName
  655. item.PriceType = n.PriceType
  656. item.Memo = n.Memo
  657. item.PriceId = n.Id
  658. item.ProductName = n.ProductName
  659. item.InfoType = k
  660. item.InfoTypeRemark = v
  661. item.MarketName = n.MarketName
  662. item.ManufactureName = n.ManufactureName
  663. if count > 0 {
  664. fmt.Println("存在", n.ProductName, n.Id)
  665. //修改
  666. err = models.ModifyLongzhongpriceinfo(item)
  667. if err != nil {
  668. msg = "修改隆众价格指标失败:err " + err.Error()
  669. return err
  670. }
  671. } else {
  672. _, err = models.AddLongzhongpriceinfo(item)
  673. if err != nil {
  674. msg = "新增隆众价格指标失败:err " + err.Error()
  675. return err
  676. }
  677. }
  678. }
  679. time.Sleep(31 * time.Second)
  680. }
  681. return
  682. }
  683. func GetLzProductPriceData(cont context.Context) (err error) {
  684. var msg string
  685. defer func() {
  686. if err != nil {
  687. fmt.Println("Err:" + err.Error())
  688. go utils.SendEmail("获取隆众价格指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  689. }
  690. if msg != "" {
  691. fmt.Println("msg:", msg)
  692. go utils.SendEmail("获取隆众价格指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";msg:"+msg, utils.EmailSendToUsers)
  693. utils.FileLog.Info("%s", msg)
  694. }
  695. }()
  696. priceInfoList, err := models.GetLongzhongpriceinfo()
  697. if err != nil {
  698. msg = "获取价格指标失败,Err:" + err.Error()
  699. return
  700. }
  701. username := "hzmd"
  702. password := "HZMD2020"
  703. startDate := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
  704. endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
  705. for k, v := range priceInfoList {
  706. fmt.Println(k, v)
  707. getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + v.InfoType + `&username=` + username + `&inStartDate=` + startDate + `&inEndDate=` + endDate + `&id=` + v.PriceId
  708. body, err := http.Get(getUrl)
  709. if err != nil {
  710. msg = "获取隆众价格数据失败:Err" + err.Error()
  711. return err
  712. }
  713. fmt.Println("getUrl:", getUrl)
  714. fmt.Println("body", string(body))
  715. utils.FileLog.Info("%s", string(body))
  716. infoList := new(models.LzPriceDataResp)
  717. err = json.Unmarshal(body, &infoList)
  718. if err != nil {
  719. msg = "获取隆众价格数据失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
  720. return err
  721. }
  722. if infoList.Code != 1 {
  723. msg = "获取隆众价格数据失败:body " + string(body)
  724. return nil
  725. }
  726. for _, n := range infoList.Data {
  727. count, err := models.GetLongzhongpricedataCount(v.LongzhongpriceinfoId, n.PriceDate)
  728. if err != nil {
  729. msg = "获取隆众价格数据失败:err " + err.Error()
  730. return err
  731. }
  732. if count > 0 {
  733. fmt.Println("存在", n.PriceDate, n.Id)
  734. } else {
  735. item := new(models.Longzhongpricedata)
  736. item.LongzhongpriceinfoId = v.LongzhongpriceinfoId
  737. item.PriceDate = n.PriceDate
  738. item.Memo = n.Memo
  739. item.Price = n.Price
  740. item.CnyPrice = n.CnyPrice
  741. item.ZsyPrice = n.ZsyPrice
  742. item.ZshPrice = n.ZshPrice
  743. item.LowPrice = n.LowPrice
  744. item.HighPrice = n.HighPrice
  745. item.RisePrice = n.RisePrice
  746. item.TonPrice = n.TonPrice
  747. item.PriceType = n.PriceType
  748. item.UpdateDate = n.UpdateDate
  749. _, err = models.AddLongzhongpricedata(item)
  750. if err != nil {
  751. msg = "新增隆众价格数据失败:err " + err.Error()
  752. return err
  753. }
  754. }
  755. }
  756. }
  757. return
  758. }
  759. func LzPriceExportExcel() {
  760. var err error
  761. defer func() {
  762. if err != nil {
  763. fmt.Println("err:" + err.Error())
  764. }
  765. }()
  766. classifyList, err := models.GetLzPriceClassify()
  767. if err != nil {
  768. return
  769. }
  770. xlsxFile := xlsx.NewFile()
  771. if err != nil {
  772. fmt.Println("生成文件失败" + err.Error())
  773. return
  774. }
  775. dir, _ := os.Executable()
  776. exPath := filepath.Dir(dir)
  777. downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  778. fmt.Println("downLoadnFilePath")
  779. fmt.Println(downLoadnFilePath)
  780. for _, v := range classifyList {
  781. fmt.Println(v.ProductName)
  782. //获取指标
  783. secNameList, err := models.GetLongzhongpriceinfoByClassifyName(v.ProductName)
  784. if err != nil {
  785. fmt.Println("获取数据失败,Err:" + err.Error())
  786. return
  787. }
  788. if len(secNameList) <= 0 {
  789. continue
  790. }
  791. sheetNew, err := xlsxFile.AddSheet(v.ProductName)
  792. if err != nil {
  793. fmt.Println("新增Sheet失败", err.Error())
  794. return
  795. }
  796. //获取指标数据
  797. windRow := sheetNew.AddRow()
  798. secNameRow := sheetNew.AddRow()
  799. frequencyRow := sheetNew.AddRow()
  800. unitRow := sheetNew.AddRow()
  801. lastModifyDateRow := sheetNew.AddRow()
  802. marketRow := sheetNew.AddRow()
  803. manufactureRow := sheetNew.AddRow()
  804. titleRow := sheetNew.AddRow()
  805. //获取分类下指标最大数据量
  806. dataMax, err := models.GetLongzhongPriceDataMaxCount(v.ProductName)
  807. if err != nil {
  808. fmt.Println("获取指标最大数据量失败", err.Error())
  809. return
  810. }
  811. for _, sv := range secNameList {
  812. fmt.Println("line 399:", v.ProductName, sv.InfoTypeRemark, sv.AreaName)
  813. windRow.AddCell().SetString("Wind")
  814. secNameRow.AddCell().SetValue("分类")
  815. frequencyRow.AddCell().SetValue("价格类型")
  816. unitRow.AddCell().SetValue("单位")
  817. lastModifyDateRow.AddCell().SetValue("地区")
  818. marketRow.AddCell().SetValue("市场名称")
  819. manufactureRow.AddCell().SetValue("厂家名称")
  820. secNameRow.AddCell().SetValue(sv.InfoTypeRemark)
  821. frequencyRow.AddCell().SetValue(sv.PriceType)
  822. unitRow.AddCell().SetValue(sv.Unit)
  823. lastModifyDateRow.AddCell().SetValue(sv.AreaName)
  824. marketRow.AddCell().SetValue(sv.MarketName)
  825. manufactureRow.AddCell().SetValue(sv.ManufactureName)
  826. windRow.AddCell()
  827. windRow.AddCell()
  828. windRow.AddCell()
  829. windRow.AddCell()
  830. secNameRow.AddCell()
  831. frequencyRow.AddCell()
  832. unitRow.AddCell()
  833. lastModifyDateRow.AddCell()
  834. marketRow.AddCell()
  835. manufactureRow.AddCell()
  836. secNameRow.AddCell()
  837. frequencyRow.AddCell()
  838. unitRow.AddCell()
  839. lastModifyDateRow.AddCell()
  840. marketRow.AddCell()
  841. manufactureRow.AddCell()
  842. secNameRow.AddCell()
  843. frequencyRow.AddCell()
  844. unitRow.AddCell()
  845. lastModifyDateRow.AddCell()
  846. marketRow.AddCell()
  847. manufactureRow.AddCell()
  848. titleRow.AddCell().SetValue("价格日期")
  849. titleRow.AddCell().SetValue("价格")
  850. titleRow.AddCell().SetValue("低端价格")
  851. titleRow.AddCell().SetValue("高端价格")
  852. titleRow.AddCell()
  853. //获取数据
  854. dataList, err := models.GetLongzhongPriceDataById(sv.LongzhongpriceinfoId)
  855. if err != nil {
  856. fmt.Println("GetLongzhongDataById Err:" + err.Error())
  857. return
  858. }
  859. if len(dataList) <= 0 {
  860. for n := 0; n < dataMax; n++ {
  861. rowIndex := 8 + n
  862. row := sheetNew.Row(rowIndex)
  863. row.AddCell()
  864. row.AddCell()
  865. row.AddCell()
  866. row.AddCell()
  867. row.AddCell()
  868. }
  869. } else {
  870. endRowIndex := 0
  871. for rk, dv := range dataList {
  872. rowIndex := 8 + rk
  873. row := sheetNew.Row(rowIndex)
  874. row.AddCell().SetValue(dv.PriceDate)
  875. row.AddCell().SetFloat(dv.Price)
  876. row.AddCell().SetFloat(dv.LowPrice)
  877. row.AddCell().SetFloat(dv.HighPrice)
  878. row.AddCell()
  879. endRowIndex = rowIndex
  880. }
  881. if len(dataList) < dataMax {
  882. dataLen := dataMax - len(dataList)
  883. for n := 0; n < dataLen; n++ {
  884. rowIndex := (endRowIndex + 1) + n
  885. row := sheetNew.Row(rowIndex)
  886. row.AddCell()
  887. row.AddCell()
  888. row.AddCell()
  889. row.AddCell()
  890. row.AddCell()
  891. }
  892. }
  893. }
  894. }
  895. }
  896. err = xlsxFile.Save(downLoadnFilePath)
  897. fmt.Print("downLoadnFilePath:", downLoadnFilePath)
  898. if err != nil {
  899. return
  900. }
  901. }
  902. //隆众-调研指标
  903. func GetLzSurveyProduct(cont context.Context) (err error) {
  904. utils.FileLogLz.Info("GetLzSurveyProduct start:" + time.Now().Format(utils.FormatDateTime))
  905. var msg string
  906. defer func() {
  907. if err != nil {
  908. fmt.Println("Err:" + err.Error())
  909. go utils.SendEmail("获取隆众调研指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  910. }
  911. if msg != "" {
  912. fmt.Println("msg:", msg)
  913. go utils.SendEmail("获取隆众调研指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";msg:"+msg, utils.EmailSendToUsers)
  914. }
  915. }()
  916. username := "hzmd"
  917. password := "HZMD2020"
  918. pageIndex := 0
  919. for {
  920. pageIndex++
  921. getUrl := `https://openapi.oilchem.net/research/getProduct?passWord=` + password + `&userName=` + username + `&pageSize=100&pageNum=` + strconv.Itoa(pageIndex)
  922. utils.FileLogLz.Info("GetLzSurveyProduct getUrl:" + getUrl)
  923. body, err := http.Get(getUrl)
  924. if err != nil {
  925. msg = "获取隆众调研指标失败:Err" + err.Error()
  926. return err
  927. }
  928. utils.FileLogLz.Info("GetLzSurveyProduct:" + string(body))
  929. infoItem := new(models.SurveyProduct)
  930. err = json.Unmarshal(body, &infoItem)
  931. if err != nil {
  932. msg = "获取隆众调研指标失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
  933. return err
  934. }
  935. if infoItem.Status != "200" {
  936. msg = "获取隆众调研指标失败:body " + string(body)
  937. return nil
  938. }
  939. for _, n := range infoItem.Response.List {
  940. count, err := models.GetLongzhongSurveyProductCount(n.QuotaSampleID)
  941. if err != nil {
  942. msg = "判断隆众调研指标是否存在失败:err " + err.Error()
  943. return err
  944. }
  945. item := new(models.LongzhongSurveyProduct)
  946. item.ProjectQuotaId = n.ProjectQuotaID
  947. item.BreedId = n.BreedID
  948. item.BreedName = n.BreedName
  949. item.QuotaId = n.QuotaID
  950. item.QuotaName = n.QuotaName
  951. item.UnitId = n.UnitID
  952. item.UnitName = n.UnitName
  953. item.SampleType = n.SampleType
  954. item.SampleId = n.SampleID
  955. item.SampleName = n.SampleName
  956. item.DeviceId = n.DeviceID
  957. item.Device = n.Device
  958. item.ProductCraftId = n.ProductCraftID
  959. item.ProductCraft = n.ProductCraft
  960. item.ProductLine = n.ProductLine
  961. item.InputMode = n.InputMode
  962. item.Frequency = n.Frequency
  963. item.CustomId = n.CustomID
  964. item.CustomType = n.CustomType
  965. item.Custom = n.Custom
  966. item.QuotaSampleId = n.QuotaSampleID
  967. if count > 0 {
  968. fmt.Println("存在", n.QuotaName, n.QuotaSampleID)
  969. //修改
  970. err = models.ModifLongzhongSurveyProduct(item)
  971. if err != nil {
  972. msg = "修改隆众价格指标失败:err " + err.Error()
  973. return err
  974. }
  975. } else {
  976. err = models.AddLongzhongSurveyProduct(item)
  977. if err != nil {
  978. msg = "新增隆众价格指标失败:err " + err.Error()
  979. return err
  980. }
  981. }
  982. }
  983. totalPage := utils.PageCount(int(infoItem.Response.Total), 100)
  984. if pageIndex > totalPage {
  985. break
  986. }
  987. }
  988. return
  989. }
  990. //隆众-调研指标数据
  991. func GetLzSurveyProductData(cont context.Context) (err error) {
  992. utils.FileLogLz.Info("GetLzSurveyProductData start:" + time.Now().Format(utils.FormatDateTime))
  993. var msg string
  994. defer func() {
  995. if err != nil {
  996. fmt.Println("Err:" + err.Error())
  997. go utils.SendEmail("获取隆众调研指标数据失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  998. }
  999. if msg != "" {
  1000. fmt.Println("msg:", msg)
  1001. go utils.SendEmail("获取隆众调研指标数据失败"+time.Now().Format("2006-01-02 15:04:05"), ";msg:"+msg, utils.EmailSendToUsers)
  1002. utils.FileLog.Info("%s", msg)
  1003. }
  1004. }()
  1005. priceInfoList, err := models.GetLongzhongSurveyList()
  1006. if err != nil {
  1007. msg = "获取隆众调研指标数据失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. username := "hzmd"
  1011. password := "HZMD2020"
  1012. paramMap := make(map[string]interface{})
  1013. paramMap["userName"] = username
  1014. paramMap["passWord"] = password
  1015. paramMap["pageSize"] = 100
  1016. startDate := time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
  1017. endDate := time.Now().UnixNano() / 1e6
  1018. for k, v := range priceInfoList {
  1019. pageIndex := 1
  1020. if v.EndDate != "" {
  1021. endDateTime, _ := time.Parse(utils.FormatDate, v.EndDate)
  1022. startDate = endDateTime.UnixNano() / 1e6
  1023. }
  1024. if startDate < 0 {
  1025. startDate = time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
  1026. }
  1027. for {
  1028. paramMap["pageNum"] = pageIndex
  1029. paramMap["projectQuotaId"] = v.ProjectQuotaId
  1030. paramMap["quotaSampleId"] = v.QuotaSampleId
  1031. paramMap["researchStartDateTime"] = startDate
  1032. paramMap["researchEndDateTime"] = endDate
  1033. fmt.Println(k, v)
  1034. getUrl := `https://openapi.oilchem.net/research/productPage`
  1035. postData, err := json.Marshal(paramMap)
  1036. if err != nil {
  1037. fmt.Println("postData Err:", err.Error())
  1038. }
  1039. utils.FileLogLz.Info("GetLzSurveyProductData postData:" + string(postData))
  1040. body, err := http.Post(getUrl, string(postData), "application/json")
  1041. if err != nil {
  1042. msg = "获取隆众调研指标数据失败:Err" + err.Error()
  1043. return err
  1044. }
  1045. utils.FileLogLz.Info("GetLzSurveyProductData:" + string(body))
  1046. dataList := new(models.LzSurveyData)
  1047. err = json.Unmarshal(body, &dataList)
  1048. if err != nil {
  1049. msg = "获取隆众调研指标数据失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
  1050. return err
  1051. }
  1052. if dataList.Status != "200" {
  1053. msg = "获取隆众调研指标数据失败:body " + string(body)
  1054. return nil
  1055. }
  1056. for _, n := range dataList.Response.List {
  1057. //dateTime := time.Unix(n.TaskActualFinishTime/1000, 0)
  1058. //dateTimeStr := dateTime.Format(utils.FormatDate)
  1059. shouldDateTime := time.Unix(n.TaskShouldFinishTime/1000, 0)
  1060. shouldDateTimeStr := shouldDateTime.Format(utils.FormatDate)
  1061. //fmt.Println("QuotaSampleID:", n.QuotaSampleID, "taskActualFinishTime:", dateTimeStr, "taskShouldFinishTime:", shouldDateTimeStr)
  1062. count, err := models.GetLzSurveyDataCount(v.SurveyProductId, int(v.QuotaSampleId), shouldDateTimeStr)
  1063. if err != nil {
  1064. msg = "获取隆众调研指标数据失败:err " + err.Error()
  1065. return err
  1066. }
  1067. if count <= 0 {
  1068. item := new(models.LongzhongSurveyData)
  1069. item.SurveyProductId = v.SurveyProductId
  1070. item.ProjectQuotaId = n.ProjectQuotaID
  1071. item.BreedId = n.BreedID
  1072. item.BreedName = n.BreedName
  1073. item.QuotaId = n.QuotaID
  1074. item.QuotaName = n.QuotaName
  1075. item.UnitId = n.UnitID
  1076. item.UnitName = n.UnitName
  1077. item.SampleType = n.SampleType
  1078. item.SampleId = n.SampleID
  1079. item.SampleName = n.SampleName
  1080. item.DeviceId = n.DeviceID
  1081. item.Device = n.Device
  1082. item.ProductCraftId = n.ProductCraftID
  1083. item.ProductCraft = n.ProductCraft
  1084. item.ProductLine = n.ProductLine
  1085. item.InputMode = n.InputMode
  1086. item.Frequency = n.Frequency
  1087. item.InputValue = n.InputValue
  1088. item.TaskShouldFinishTime = n.TaskShouldFinishTime
  1089. item.CustomId = n.CustomID
  1090. item.CustomType = n.CustomType
  1091. item.Custom = n.Custom
  1092. item.QuotaSampleId = n.QuotaSampleID
  1093. item.TaskActualFinishTime = n.TaskActualFinishTime
  1094. //item.AreaName = n.AreaName.(string)
  1095. //item.ProvinceName = n.ProvinceName.(string)
  1096. item.ResearchStartData = n.ResearchStartDate
  1097. item.ResearchStopData = n.ResearchStopDate
  1098. item.DataTime = shouldDateTimeStr
  1099. err = models.AddLongzhongSurveyData(item)
  1100. if err != nil {
  1101. msg = "新增调研指标数据失败:err " + err.Error()
  1102. return err
  1103. }
  1104. }
  1105. }
  1106. pageIndex = pageIndex + 1
  1107. totalPage := utils.PageCount(int(dataList.Response.Total), 100)
  1108. if pageIndex > totalPage {
  1109. break
  1110. }
  1111. }
  1112. item, err := models.GetLzSurveyMaxAndMinInfo(v.SurveyProductId, int(v.QuotaSampleId))
  1113. if err != nil {
  1114. return err
  1115. }
  1116. if item != nil && item.MaxDate != "" && item.MinDate != "" {
  1117. err = models.ModifyLzSurveyMaxAndMinInfo(item, v.SurveyProductId)
  1118. if err != nil {
  1119. return err
  1120. }
  1121. }
  1122. time.Sleep(2 * time.Second)
  1123. }
  1124. return
  1125. }