KwaiJSTController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.ruixuan.isc.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruixuan.common.utils.Check;
  4. import com.ruixuan.isc.service.IKwaiJSTService;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import io.swagger.annotations.ApiParam;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. import java.util.List;
  11. import java.util.concurrent.ExecutorService;
  12. import java.util.concurrent.Executors;
  13. @RestController
  14. @Api(tags = "聚水潭")
  15. @RequestMapping("/kwaixiaodian/jst")
  16. public class KwaiJSTController {
  17. @Autowired
  18. private IKwaiJSTService kwaiJSTService;
  19. static ExecutorService cleanService = Executors.newFixedThreadPool(2);
  20. static ExecutorService cleanCostService = Executors.newFixedThreadPool(2);
  21. @GetMapping(value = "/refreshToken")
  22. @ApiOperation(value = "refreshToken")
  23. public JSONObject refreshToken() {
  24. return kwaiJSTService.refreshToken();
  25. }
  26. @PostMapping(value = "/costDetail")
  27. public JSONObject costDetail(@RequestBody JSONObject requestJson) {
  28. JSONObject returnJson = new JSONObject();
  29. try {
  30. if (Check.isNull(requestJson)) {
  31. throw new Exception("请输入参数");
  32. }
  33. String skuNick = requestJson.getString("skuNick");
  34. if (Check.isNull(skuNick)) {
  35. throw new Exception("请输入sku");
  36. }
  37. Integer dataType = requestJson.getInteger("dataType");
  38. if (Check.isNull(dataType)) {
  39. throw new Exception("请输入dataType");
  40. }
  41. Long date = requestJson.getLong("date");
  42. if (Check.isNull(date)) {
  43. throw new Exception("请输入date");
  44. }
  45. cleanService.submit(new Runnable() {
  46. @Override
  47. public void run() {
  48. try {
  49. kwaiJSTService.costDetail(skuNick, dataType, date);
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. });
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. returnJson.put("code", 200);
  58. returnJson.put("message", e.getMessage());
  59. }
  60. return returnJson;
  61. }
  62. @PostMapping(value = "/cleanCost")
  63. public JSONObject cleanCost(@RequestBody JSONObject requestJson) {
  64. JSONObject returnJson = new JSONObject();
  65. try {
  66. if (Check.isNull(requestJson)) {
  67. throw new Exception("请输入参数");
  68. }
  69. String skuNick = requestJson.getString("skuNick");
  70. if (Check.isNull(skuNick)) {
  71. throw new Exception("请输入sku");
  72. }
  73. cleanCostService.submit(new Runnable() {
  74. @Override
  75. public void run() {
  76. try {
  77. kwaiJSTService.cleanCost(skuNick);
  78. } catch (Exception e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. });
  83. } catch (Exception e) {
  84. e.printStackTrace();
  85. returnJson.put("code", 200);
  86. returnJson.put("message", e.getMessage());
  87. }
  88. return returnJson;
  89. }
  90. /**
  91. * https://openweb.jushuitan.com/dev-doc?docType=2&docId=14
  92. * 普通商品资料查询(按sku查询) + 组合装商品查询
  93. * 对应数据表:ruixuan.kwaixiaodian_jst
  94. */
  95. @GetMapping(value = "/queryAndInsertSku")
  96. @ApiOperation(value = "普通商品资料查询(按sku查询)+组合装商品查询")
  97. public void queryAndInsertSku(@ApiParam("时间") @RequestParam(value = "date", required = false) String date) {
  98. // List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes("2024-01-01", "2024-11-25");
  99. // allDatesOfTwoTimes.forEach(dates -> dateService.submit(() -> {
  100. try {
  101. // Thread.sleep(5000L);
  102. kwaiJSTService.queryAndInsertSku(date);
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. }
  106. // }));
  107. }
  108. /**
  109. * https://openweb.jushuitan.com/dev-doc?docType=6&docId=26
  110. * 采购单查询
  111. * 对应数据表:ruixuan.kwaixiaodian_jst_purchase、kwaixiaodian_jst_purchase_item
  112. */
  113. @GetMapping(value = "/queryAndInsertPurchase")
  114. @ApiOperation(value = "采购单查询")
  115. public void queryAndInsertPurchase(@ApiParam("时间") @RequestParam(value = "date", required = false) String date) {
  116. try {
  117. kwaiJSTService.queryAndInsertPurchase(date);
  118. } catch (Exception e) {
  119. e.printStackTrace();
  120. }
  121. }
  122. }