SupplyChainServiceImpl.java 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. package com.ruixuan.isc.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.common.collect.Lists;
  5. import com.kuaishou.merchant.open.api.KsMerchantApiException;
  6. import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
  7. import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
  8. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionCpsLeaderOrderCursorListRequest;
  9. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityItemDetailRequest;
  10. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenItemListRequest;
  11. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenListRequest;
  12. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionCpsLeaderOrderCursorListResponse;
  13. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityItemDetailResponse;
  14. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenItemListResponse;
  15. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenListResponse;
  16. import com.ruixuan.common.utils.Check;
  17. import com.ruixuan.common.utils.DateUtils;
  18. import com.ruixuan.isc.entity.ItemCheck;
  19. import com.ruixuan.isc.entity.KuaiShouActivityInfo;
  20. import com.ruixuan.isc.entity.KuaiShouActivityOpenItemList;
  21. import com.ruixuan.isc.entity.KuaishouAccessToken;
  22. import com.ruixuan.isc.entity.KuaishouSupplyChain;
  23. import com.ruixuan.isc.mapper.KuaishouItemListMapper;
  24. import com.ruixuan.isc.mapper.SupplyChainMapper;
  25. import com.ruixuan.isc.service.IAccessTokenService;
  26. import com.ruixuan.isc.service.ISupplyChainService;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.beans.factory.annotation.Value;
  30. import org.springframework.data.mongodb.core.MongoTemplate;
  31. import org.springframework.data.mongodb.core.query.Criteria;
  32. import org.springframework.data.mongodb.core.query.Query;
  33. import org.springframework.stereotype.Service;
  34. import java.util.ArrayList;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.Map;
  38. @Slf4j
  39. @Service
  40. public class SupplyChainServiceImpl implements ISupplyChainService {
  41. @Autowired
  42. private SupplyChainMapper supplyChainMapper;
  43. @Autowired
  44. private KuaishouItemListMapper itemListMapper;
  45. @Autowired
  46. private IAccessTokenService accessTokenService;
  47. @Value("${ownership.id}")
  48. private String ownershipId;
  49. @Autowired
  50. private MongoTemplate mongoTemplate;
  51. // 获取订单数据 
  52. @Override
  53. public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
  54. List<JSONObject> list = supplyChainMapper.getOrderList(requestMap);
  55. if (!Check.isNull(list)) {
  56. for (int i = 0; i < list.size(); i++) {
  57. JSONObject jsonObject = list.get(i);
  58. String promoterId = jsonObject.getString("promoterId");
  59. requestMap.put("promoterId", promoterId);
  60. List<JSONObject> topOrders = supplyChainMapper.getTopOrders(requestMap);
  61. jsonObject.put("topOrders", topOrders);
  62. List<JSONObject> tags = supplyChainMapper.getPromoterId(Long.valueOf(promoterId));
  63. jsonObject.put("tags", tags);
  64. }
  65. }
  66. return list;
  67. }
  68. //达人带货详情
  69. @Override
  70. public List<JSONObject> anchorOrderDetail(Map<String, Object> requestMap) {
  71. return supplyChainMapper.anchorOrderDetail(requestMap);
  72. }
  73. //订单统计
  74. @Override
  75. public List<JSONObject> orderStatistics(Map<String, Object> requestMap) {
  76. return supplyChainMapper.orderStatistics(requestMap);
  77. }
  78. //商品列表
  79. @Override
  80. public List<JSONObject> itemList(Map<String, Object> requestMap) {
  81. List<JSONObject> list = supplyChainMapper.itemList(requestMap);
  82. return list;
  83. }
  84. @Override
  85. public List<JSONObject> itemBindList(Map<String, Object> requestMap) {
  86. return supplyChainMapper.itemBindList(requestMap);
  87. }
  88. @Override
  89. public List<JSONObject> itemDetail(Map<String, Object> requestMap) {
  90. return supplyChainMapper.itemDetail(requestMap);
  91. }
  92. @Override
  93. public List<JSONObject> itemServiceCharge(Map<String, Object> requestMap) {
  94. return supplyChainMapper.itemServiceCharge(requestMap);
  95. }
  96. @Override
  97. public JSONObject getOrderTotal(Map<String, Object> requestMap) {
  98. return supplyChainMapper.getOrderTotal(requestMap);
  99. }
  100. @Override
  101. public Double getOrderTotalRatio(Map<String, Object> ratioMap) {
  102. return supplyChainMapper.getOrderTotalRatio(ratioMap);
  103. }
  104. @Override
  105. public JSONObject getAmountTotal(Map<String, Object> requestMap) {
  106. return supplyChainMapper.getAmountTotal(requestMap);
  107. }
  108. @Override
  109. public Double getAmountTotalRatio(Map<String, Object> ratioMap) {
  110. return supplyChainMapper.getAmountTotalRatio(ratioMap);
  111. }
  112. @Override
  113. public JSONObject getServiceAmountTotal(Map<String, Object> requestMap) {
  114. return supplyChainMapper.getServiceAmountTotal(requestMap);
  115. }
  116. @Override
  117. public List<JSONObject> getOrderRankRatioList(Map<String, Object> requestMap) {
  118. return supplyChainMapper.getOrderRankRatioList(requestMap);
  119. }
  120. @Override
  121. public List<JSONObject> getOrderRankList(Map<String, Object> requestMap) {
  122. return supplyChainMapper.getOrderRankList(requestMap);
  123. }
  124. @Override
  125. public List<JSONObject> getPromoterRankRatioList(Map<String, Object> requestMap) {
  126. return supplyChainMapper.getPromoterRankRatioList(requestMap);
  127. }
  128. @Override
  129. public List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap) {
  130. return supplyChainMapper.getPromoterRatioList(requestMap);
  131. }
  132. @Override
  133. public List<JSONObject> exportPromoterTotal(Map<String, Object> requestMap) {
  134. return supplyChainMapper.exportPromoterTotal(requestMap);
  135. }
  136. @Override
  137. public List<JSONObject> exportPromoter(Map<String, Object> requestMap) {
  138. return supplyChainMapper.exportPromoter(requestMap);
  139. }
  140. @Override
  141. public List<JSONObject> exportOrder(Map<String, Object> requestMap) {
  142. return supplyChainMapper.exportOrder(requestMap);
  143. }
  144. @Override
  145. public List<JSONObject> getTopPromoterByItemId(Map<String, Object> requestMap) {
  146. return supplyChainMapper.getTopPromoterByItemId(requestMap);
  147. }
  148. @Override
  149. public List<JSONObject> bindUserItemList(Map<String, Object> requestMap) {
  150. return supplyChainMapper.bindUserItemList(requestMap);
  151. }
  152. @Override
  153. public List<JSONObject> getSupplyChainUserList() {
  154. return supplyChainMapper.getSupplyChainUserList();
  155. }
  156. @Override
  157. public boolean unbindUser(Long itemId) {
  158. return supplyChainMapper.unbindUser(itemId);
  159. }
  160. @Override
  161. public boolean bindUser(Long itemId, Long userId, String nikeName) {
  162. return supplyChainMapper.bindUser(itemId, userId, nikeName);
  163. }
  164. @Override
  165. public List<JSONObject> adminReportList(Map<String, Object> requestMap) {
  166. return supplyChainMapper.adminReportList(requestMap);
  167. }
  168. @Override
  169. public List<JSONObject> userItemDetail(Map<String, Object> requestMap) {
  170. return supplyChainMapper.userItemDetail(requestMap);
  171. }
  172. @Override
  173. public JSONObject getTimeIntervalRatio(Map<String, Object> requestMap) {
  174. return supplyChainMapper.getTimeIntervalRatio(requestMap);
  175. }
  176. @Override
  177. public List<JSONObject> indexStatistics(Map<String, Object> requestMap) {
  178. return supplyChainMapper.indexStatistics(requestMap);
  179. }
  180. @Override
  181. public JSONObject itemBindSummary() {
  182. return supplyChainMapper.itemBindSummary();
  183. }
  184. @Override
  185. public JSONObject userItemTotal(Map<String, Object> requestMap) {
  186. return supplyChainMapper.userItemTotal(requestMap);
  187. }
  188. @Override
  189. public List<JSONObject> exportUserItemDetail(Map<String, Object> requestMap) {
  190. return supplyChainMapper.exportUserItemDetail(requestMap);
  191. }
  192. @Override
  193. public JSONObject selectOrderInfo(Map<String, Object> requestMap) {
  194. return supplyChainMapper.selectOrderInfo(requestMap);
  195. }
  196. @Override
  197. public JSONObject selectOrderRate(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate, int hour) {
  198. return supplyChainMapper.selectOrderRate(promoterIds, itemIds, statDate, endDate, hour);
  199. }
  200. @Override
  201. public JSONObject selectOrderRateBytedance(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate, int hour) {
  202. return supplyChainMapper.selectOrderRateBytedance(promoterIds, itemIds, statDate, endDate, hour);
  203. }
  204. @Override
  205. public List<JSONObject> getMonthOrderAmount(Map<String, Object> map) {
  206. return supplyChainMapper.getMonthOrderAmount(map);
  207. }
  208. @Override
  209. public List<JSONObject> getMonthOrderAmountBytedance(Map<String, Object> map) {
  210. return supplyChainMapper.getMonthOrderAmountBytedance(map);
  211. }
  212. @Override
  213. public JSONObject getMonthOrderAmountTotalBytedance(Map<String, Object> map) {
  214. return supplyChainMapper.getMonthOrderAmountTotalBytedance(map);
  215. }
  216. @Override
  217. public List<JSONObject> getMonthOrderAmountByItemsBytedance(Map<String, Object> map) {
  218. return supplyChainMapper.getMonthOrderAmountByItemsBytedance(map);
  219. }
  220. @Override
  221. public JSONObject getMonthOrderAmountTotalByItemsBytedance(Map<String, Object> map) {
  222. return supplyChainMapper.getMonthOrderAmountTotalByItemsBytedance(map);
  223. }
  224. @Override
  225. public List<JSONObject> getOrderRankRatioListBytedance(Map<String, Object> requestMap) {
  226. return supplyChainMapper.getOrderRankRatioListBytedance(requestMap);
  227. }
  228. @Override
  229. public List<JSONObject> getOrderRankListBytedance(Map<String, Object> requestMap) {
  230. return supplyChainMapper.getOrderRankListBytedance(requestMap);
  231. }
  232. @Override
  233. public List<JSONObject> getPromoterRankRatioListBytedance(Map<String, Object> requestMap) {
  234. return supplyChainMapper.getPromoterRankRatioListBytedance(requestMap);
  235. }
  236. @Override
  237. public List<JSONObject> getPromoterRatioListBytedance(Map<String, Object> requestMap) {
  238. return supplyChainMapper.getPromoterRatioListBytedance(requestMap);
  239. }
  240. @Override
  241. public JSONObject selectOrderInfoBytedance(Map<String, Object> parMap) {
  242. return supplyChainMapper.selectOrderInfoBytedance(parMap);
  243. }
  244. @Override
  245. public List<JSONObject> bdReportListV2ByBind(Map<String, Object> requestMap) {
  246. return supplyChainMapper.bdReportListV2ByBind(requestMap);
  247. }
  248. @Override
  249. public List<JSONObject> exportBindOrder(Map<String, Object> requestMap) {
  250. return supplyChainMapper.exportBindOrder(requestMap);
  251. }
  252. @Override
  253. public JSONObject getMonthOrderAmountTotal(Map<String, Object> map) {
  254. return supplyChainMapper.getMonthOrderAmountTotal(map);
  255. }
  256. @Override
  257. public JSONObject selectOrderInfoByItemIds(Map<String, Object> requestMap) {
  258. return supplyChainMapper.selectOrderInfoByItemIds(requestMap);
  259. }
  260. @Override
  261. public List<JSONObject> getMonthOrderAmountByItems(Map<String, Object> map) {
  262. return supplyChainMapper.getMonthOrderAmountByItems(map);
  263. }
  264. @Override
  265. public JSONObject getMonthOrderAmountTotalByItems(Map<String, Object> map) {
  266. return supplyChainMapper.getMonthOrderAmountTotalByItems(map);
  267. }
  268. @Override
  269. public List<JSONObject> bdReportList(Map<String, Object> requestMap) {
  270. return supplyChainMapper.bdReportList(requestMap);
  271. }
  272. @Override
  273. public List<JSONObject> bdDetailList(Map<String, Object> requestMap) {
  274. return supplyChainMapper.bdDetailList(requestMap);
  275. }
  276. @Override
  277. public List<JSONObject> bdTotal(Map<String, Object> requestMap) {
  278. return supplyChainMapper.bdTotal(requestMap);
  279. }
  280. @Override
  281. public List<JSONObject> exportBdDetail(Map<String, Object> requestMap) {
  282. return supplyChainMapper.exportBdDetail(requestMap);
  283. }
  284. @Override
  285. public String getUserName(Long promoterId) {
  286. return supplyChainMapper.getUserName(promoterId);
  287. }
  288. @Override
  289. public List<JSONObject> exportBdReportList(Map<String, Object> requestMap) {
  290. return supplyChainMapper.exportBdReportList(requestMap);
  291. }
  292. @Override
  293. public List<JSONObject> exportAdminReportList(Map<String, Object> requestMap) {
  294. return supplyChainMapper.exportAdminReportList(requestMap);
  295. }
  296. @Override
  297. public List<JSONObject> getSupplyChainCourtshipUserList() {
  298. return supplyChainMapper.getSupplyChainCourtshipUserList();
  299. }
  300. @Override
  301. public List<JSONObject> adminReportListByBind(Map<String, Object> requestMap) {
  302. return supplyChainMapper.adminReportListByBind(requestMap);
  303. }
  304. @Override
  305. public List<JSONObject> exportAdminReportListByBind(Map<String, Object> requestMap) {
  306. return supplyChainMapper.exportAdminReportListByBind(requestMap);
  307. }
  308. @Override
  309. public List<JSONObject> bdReportListV2(Map<String, Object> requestMap) {
  310. return supplyChainMapper.bdReportListV2(requestMap);
  311. }
  312. @Override
  313. public List<JSONObject> bdTotalV2(Map<String, Object> requestMap) {
  314. return supplyChainMapper.bdTotalV2(requestMap);
  315. }
  316. @Override
  317. public List<JSONObject> bdDetailListV2(Map<String, Object> requestMap) {
  318. List<JSONObject> jsonObjects = supplyChainMapper.bdDetailListV2(requestMap);
  319. if (!Check.isNull(jsonObjects)) {
  320. for (int i = 0; i < jsonObjects.size(); i++) {
  321. JSONObject jsonObject = jsonObjects.get(i);
  322. Long promoterId = jsonObject.getLong("promoterId");
  323. List<JSONObject> tags = supplyChainMapper.getPromoterId(promoterId);
  324. jsonObject.put("tags", tags);
  325. }
  326. }
  327. return jsonObjects;
  328. }
  329. @Override
  330. public JSONObject selectOrderInfoByItemIdsBytedance(Map<String, Object> requestMap) {
  331. return supplyChainMapper.selectOrderInfoByItemIdsBytedance(requestMap);
  332. }
  333. @Override
  334. public void updateOrder(JSONObject eventJSon) {
  335. try {
  336. JSONObject info = eventJSon.getJSONObject("info");
  337. if (!Check.isNull(info)) {
  338. Long oid = info.getLong("oid");
  339. Integer cpsOrderStatus = info.getInteger("cpsOrderStatus");
  340. if (cpsOrderStatus == 30) {
  341. return;
  342. }
  343. if (cpsOrderStatus == 60) {
  344. Integer i = updateOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  345. if (i > 0) {
  346. log.info("订单ID:{},状态:{} 修改成功", oid, cpsOrderStatus);
  347. } else {
  348. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  349. }
  350. } else {
  351. Integer i = this.updateOrderStatus(oid, cpsOrderStatus);
  352. if (i > 0) {
  353. log.info("订单ID:{},状态:{} 修改成功", oid, cpsOrderStatus);
  354. } else {
  355. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  356. }
  357. }
  358. }
  359. } catch (Exception e) {
  360. e.printStackTrace();
  361. }
  362. }
  363. private Integer updateOrderStatus(Long oid, Integer cpsOrderStatus) {
  364. if ("ruixuan".equals(ownershipId)) {
  365. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  366. if (ruixuan > 0) {
  367. return ruixuan;
  368. }
  369. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  370. if (mgs > 0) {
  371. return mgs;
  372. }
  373. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  374. if (rocket > 0) {
  375. return rocket;
  376. }
  377. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  378. if (yufu > 0) {
  379. return yufu;
  380. }
  381. int yuxiu = supplyChainMapper.updateYuxiuOrder(oid, cpsOrderStatus);
  382. if (yuxiu > 0) {
  383. return yuxiu;
  384. }
  385. }
  386. if ("miaogousi".equals(ownershipId)) {
  387. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  388. if (mgs > 0) {
  389. return mgs;
  390. }
  391. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  392. if (ruixuan > 0) {
  393. return ruixuan;
  394. }
  395. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  396. if (rocket > 0) {
  397. return rocket;
  398. }
  399. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  400. if (yufu > 0) {
  401. return yufu;
  402. }
  403. int yuxiu = supplyChainMapper.updateYuxiuOrder(oid, cpsOrderStatus);
  404. if (yuxiu > 0) {
  405. return yuxiu;
  406. }
  407. }
  408. if ("rocket".equals(ownershipId)) {
  409. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  410. if (rocket > 0) {
  411. return rocket;
  412. }
  413. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  414. if (ruixuan > 0) {
  415. return ruixuan;
  416. }
  417. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  418. if (mgs > 0) {
  419. return mgs;
  420. }
  421. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  422. if (yufu > 0) {
  423. return yufu;
  424. }
  425. int yuxiu = supplyChainMapper.updateYuxiuOrder(oid, cpsOrderStatus);
  426. if (yuxiu > 0) {
  427. return yuxiu;
  428. }
  429. }
  430. if ("yufu".equals(ownershipId)) {
  431. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  432. if (yufu > 0) {
  433. return yufu;
  434. }
  435. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  436. if (rocket > 0) {
  437. return rocket;
  438. }
  439. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  440. if (ruixuan > 0) {
  441. return ruixuan;
  442. }
  443. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  444. if (mgs > 0) {
  445. return mgs;
  446. }
  447. int yuxiu = supplyChainMapper.updateYuxiuOrder(oid, cpsOrderStatus);
  448. if (yuxiu > 0) {
  449. return yuxiu;
  450. }
  451. }
  452. if ("yuxiu".equals(ownershipId)) {
  453. int yuxiu = supplyChainMapper.updateYuxiuOrder(oid, cpsOrderStatus);
  454. if (yuxiu > 0) {
  455. return yuxiu;
  456. }
  457. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  458. if (yufu > 0) {
  459. return yufu;
  460. }
  461. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  462. if (rocket > 0) {
  463. return rocket;
  464. }
  465. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  466. if (ruixuan > 0) {
  467. return ruixuan;
  468. }
  469. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  470. if (mgs > 0) {
  471. return mgs;
  472. }
  473. }
  474. return 0;
  475. }
  476. private Integer updateOrderRegimentalSettleAmount(Long oid, Integer cpsOrderStatus) {
  477. if ("ruixuan".equals(ownershipId)) {
  478. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  479. if (ruixuan > 0) {
  480. return ruixuan;
  481. }
  482. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  483. if (mgs > 0) {
  484. return mgs;
  485. }
  486. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  487. if (rocket > 0) {
  488. return rocket;
  489. }
  490. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  491. if (yufu > 0) {
  492. return yufu;
  493. }
  494. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  495. if (yuxiu > 0) {
  496. return yuxiu;
  497. }
  498. }
  499. if ("miaogousi".equals(ownershipId)) {
  500. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  501. if (mgs > 0) {
  502. return mgs;
  503. }
  504. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  505. if (ruixuan > 0) {
  506. return ruixuan;
  507. }
  508. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  509. if (rocket > 0) {
  510. return rocket;
  511. }
  512. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  513. if (yufu > 0) {
  514. return yufu;
  515. }
  516. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  517. if (yuxiu > 0) {
  518. return yuxiu;
  519. }
  520. }
  521. if ("rocket".equals(ownershipId)) {
  522. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  523. if (rocket > 0) {
  524. return rocket;
  525. }
  526. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  527. if (ruixuan > 0) {
  528. return ruixuan;
  529. }
  530. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  531. if (mgs > 0) {
  532. return mgs;
  533. }
  534. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  535. if (yufu > 0) {
  536. return yufu;
  537. }
  538. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  539. if (yuxiu > 0) {
  540. return yuxiu;
  541. }
  542. }
  543. if ("yufu".equals(ownershipId)) {
  544. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  545. if (yufu > 0) {
  546. return yufu;
  547. }
  548. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  549. if (rocket > 0) {
  550. return rocket;
  551. }
  552. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  553. if (ruixuan > 0) {
  554. return ruixuan;
  555. }
  556. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  557. if (mgs > 0) {
  558. return mgs;
  559. }
  560. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  561. if (yuxiu > 0) {
  562. return yuxiu;
  563. }
  564. }
  565. if ("yuxiu".equals(ownershipId)) {
  566. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  567. if (yuxiu > 0) {
  568. return yuxiu;
  569. }
  570. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  571. if (rocket > 0) {
  572. return rocket;
  573. }
  574. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  575. if (ruixuan > 0) {
  576. return ruixuan;
  577. }
  578. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  579. if (mgs > 0) {
  580. return mgs;
  581. }
  582. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  583. if (yufu > 0) {
  584. return yufu;
  585. }
  586. }
  587. return 0;
  588. }
  589. @Override
  590. public void updateItem(JSONObject eventJSon) {
  591. try {
  592. JSONObject info = eventJSon.getJSONObject("info");
  593. if (!Check.isNull(info)) {
  594. Long itemId = info.getLong("itemId");
  595. Integer status = info.getInteger("status");
  596. supplyChainMapper.updateItem(itemId, status);
  597. log.info("商品id:{},状态:{} 修改成功", itemId, status);
  598. }
  599. } catch (Exception e) {
  600. e.printStackTrace();
  601. }
  602. }
  603. @Override
  604. public void addList(String beginDate, String endDate, String pcursor) throws InterruptedException {
  605. String url = "https://openapi.kwaixiaodian.com";
  606. Long beginTime = DateUtils.getStartLongTime(beginDate);
  607. Long endTime = DateUtils.getEndLongTime(endDate);
  608. // Map<Long, Long> itemMap = getItemMap();
  609. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  610. for (KuaishouAccessToken accessToken : tokens) {
  611. getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  612. }
  613. Thread.sleep(30000);
  614. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  615. for (KuaishouAccessToken accessToken : mgsTokens) {
  616. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  617. }
  618. Thread.sleep(30000);
  619. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  620. for (KuaishouAccessToken accessToken : rocketTokens) {
  621. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  622. }
  623. Thread.sleep(30000);
  624. List<KuaishouAccessToken> yufuTokens = accessTokenService.getYufuTokenInfos();
  625. for (KuaishouAccessToken accessToken : yufuTokens) {
  626. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  627. }
  628. Thread.sleep(30000);
  629. List<KuaishouAccessToken> yuxiuTokens = accessTokenService.getYuxiuTokenInfos();
  630. for (KuaishouAccessToken accessToken : yuxiuTokens) {
  631. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  632. }
  633. }
  634. private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  635. List<Long> ruixuanList = new ArrayList<>();
  636. List<Long> mgsList = new ArrayList<>();
  637. List<Long> rocketList = new ArrayList<>();
  638. List<Long> yufuList = new ArrayList<>();
  639. List<Long> yuxiuList = new ArrayList<>();
  640. String appKey = accessToken.getAppKey();
  641. String signSecret = accessToken.getSignSecret();
  642. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  643. return;
  644. }
  645. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  646. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  647. request.setAccessToken(accessToken.getAccessToken());
  648. request.setApiMethodVersion(1L);
  649. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  650. request.setSortType(1);
  651. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  652. request.setQueryType(2);
  653. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  654. request.setCpsOrderStatus(0);
  655. request.setDistributorId(0l);
  656. request.setBeginTime(beginTime);
  657. request.setEndTime(endTime);
  658. request.setPcursor(pcursor);
  659. request.setPageize(100);
  660. request.setFundType(1);
  661. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  662. try {
  663. response = client.execute(request);
  664. } catch (KsMerchantApiException e) {
  665. e.printStackTrace();
  666. }
  667. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  668. String code = obj.getString("code");
  669. if ("1".equals(code)) {
  670. JSONObject data = obj.getJSONObject("data");
  671. pcursor = data.getString("pcursor");
  672. JSONArray orderView = data.getJSONArray("orderView");
  673. for (int i = 0; i < orderView.size(); i++) {
  674. JSONObject info = orderView.getJSONObject(i);
  675. Integer sendStatus = info.getInteger("sendStatus");
  676. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  677. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  678. if (!Check.isNull(cpsOrderProductView)) {
  679. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  680. Long itemId = itemJson.getLong("itemId");
  681. Criteria criteria = new Criteria();
  682. criteria = Criteria.where("_id").is(itemId);
  683. Query query = new Query(criteria);
  684. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  685. if (Check.isNull(itemCheck)) {
  686. ruixuanList.add(info.getLong("oid"));
  687. }
  688. if (!Check.isNull(itemCheck)) {
  689. String ownership = itemCheck.getOwnership();
  690. if ("ruixuan".equals(ownership)) {
  691. ruixuanList.add(info.getLong("oid"));
  692. }
  693. if ("miaogousi".equals(ownership)) {
  694. mgsList.add(info.getLong("oid"));
  695. }
  696. if ("rocket".equals(ownership)) {
  697. rocketList.add(info.getLong("oid"));
  698. }
  699. if ("yufu".equals(ownership)) {
  700. yufuList.add(info.getLong("oid"));
  701. }
  702. if ("yuxiu".equals(ownership)) {
  703. yuxiuList.add(info.getLong("oid"));
  704. }
  705. }
  706. }
  707. }
  708. }
  709. } else {
  710. log.error("===查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("msg"));
  711. log.error("游标:{},执行次数:{}", pcursor, counts);
  712. if (counts <= 3) {
  713. getInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  714. }
  715. }
  716. if (!Check.isNull(ruixuanList)) {
  717. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  718. }
  719. if (!Check.isNull(mgsList)) {
  720. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  721. }
  722. if (!Check.isNull(rocketList)) {
  723. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  724. }
  725. if (!Check.isNull(yufuList)) {
  726. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  727. }
  728. if (!Check.isNull(yuxiuList)) {
  729. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  730. }
  731. if (!"nomore".equals(pcursor)) {
  732. getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  733. }
  734. }
  735. private void getMgsInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  736. List<Long> ruixuanList = new ArrayList<>();
  737. List<Long> mgsList = new ArrayList<>();
  738. List<Long> rocketList = new ArrayList<>();
  739. List<Long> yufuList = new ArrayList<>();
  740. List<Long> yuxiuList = new ArrayList<>();
  741. String appKey = accessToken.getAppKey();
  742. String signSecret = accessToken.getSignSecret();
  743. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  744. return;
  745. }
  746. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  747. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  748. request.setAccessToken(accessToken.getAccessToken());
  749. request.setApiMethodVersion(1L);
  750. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  751. request.setSortType(1);
  752. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  753. request.setQueryType(2);
  754. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  755. request.setCpsOrderStatus(0);
  756. request.setDistributorId(0l);
  757. request.setBeginTime(beginTime);
  758. request.setEndTime(endTime);
  759. request.setPcursor(pcursor);
  760. request.setPageize(100);
  761. request.setFundType(1);
  762. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  763. try {
  764. response = client.execute(request);
  765. } catch (KsMerchantApiException e) {
  766. e.printStackTrace();
  767. }
  768. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  769. String code = obj.getString("code");
  770. if ("1".equals(code)) {
  771. JSONObject data = obj.getJSONObject("data");
  772. pcursor = data.getString("pcursor");
  773. JSONArray orderView = data.getJSONArray("orderView");
  774. for (int i = 0; i < orderView.size(); i++) {
  775. JSONObject info = orderView.getJSONObject(i);
  776. Integer sendStatus = info.getInteger("sendStatus");
  777. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  778. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  779. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  780. Long itemId = itemJson.getLong("itemId");
  781. Criteria criteria = new Criteria();
  782. criteria = Criteria.where("_id").is(itemId);
  783. Query query = new Query(criteria);
  784. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  785. if (Check.isNull(itemCheck)) {
  786. mgsList.add(info.getLong("oid"));
  787. }
  788. if (!Check.isNull(itemCheck)) {
  789. String ownership = itemCheck.getOwnership();
  790. if ("ruixuan".equals(ownership)) {
  791. ruixuanList.add(info.getLong("oid"));
  792. }
  793. if ("miaogousi".equals(ownership)) {
  794. mgsList.add(info.getLong("oid"));
  795. }
  796. if ("rocket".equals(ownership)) {
  797. rocketList.add(info.getLong("oid"));
  798. }
  799. if ("yufu".equals(ownership)) {
  800. yufuList.add(info.getLong("oid"));
  801. }
  802. if ("yuxiu".equals(ownership)) {
  803. yuxiuList.add(info.getLong("oid"));
  804. }
  805. }
  806. }
  807. }
  808. } else {
  809. log.error("===MGS查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  810. log.error("MGS游标:{},执行次数:{}", pcursor, counts);
  811. if (counts <= 3) {
  812. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  813. }
  814. }
  815. if (!Check.isNull(ruixuanList)) {
  816. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  817. }
  818. if (!Check.isNull(mgsList)) {
  819. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  820. }
  821. if (!Check.isNull(rocketList)) {
  822. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  823. }
  824. if (!Check.isNull(yufuList)) {
  825. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  826. }
  827. if (!Check.isNull(yuxiuList)) {
  828. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  829. }
  830. if (!"nomore".equals(pcursor)) {
  831. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  832. }
  833. }
  834. private void getRocketInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  835. List<Long> ruixuanList = new ArrayList<>();
  836. List<Long> mgsList = new ArrayList<>();
  837. List<Long> rocketList = new ArrayList<>();
  838. List<Long> yufuList = new ArrayList<>();
  839. List<Long> yuxiuList = new ArrayList<>();
  840. String appKey = accessToken.getAppKey();
  841. String signSecret = accessToken.getSignSecret();
  842. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  843. return;
  844. }
  845. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  846. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  847. request.setAccessToken(accessToken.getAccessToken());
  848. request.setApiMethodVersion(1L);
  849. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  850. request.setSortType(1);
  851. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  852. request.setQueryType(2);
  853. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  854. request.setCpsOrderStatus(0);
  855. request.setDistributorId(0l);
  856. request.setBeginTime(beginTime);
  857. request.setEndTime(endTime);
  858. request.setPcursor(pcursor);
  859. request.setPageize(100);
  860. request.setFundType(1);
  861. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  862. try {
  863. response = client.execute(request);
  864. } catch (KsMerchantApiException e) {
  865. e.printStackTrace();
  866. }
  867. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  868. String code = obj.getString("code");
  869. if ("1".equals(code)) {
  870. JSONObject data = obj.getJSONObject("data");
  871. pcursor = data.getString("pcursor");
  872. JSONArray orderView = data.getJSONArray("orderView");
  873. for (int i = 0; i < orderView.size(); i++) {
  874. JSONObject info = orderView.getJSONObject(i);
  875. Integer sendStatus = info.getInteger("sendStatus");
  876. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  877. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  878. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  879. Long itemId = itemJson.getLong("itemId");
  880. Criteria criteria = new Criteria();
  881. criteria = Criteria.where("_id").is(itemId);
  882. Query query = new Query(criteria);
  883. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  884. if (Check.isNull(itemCheck)) {
  885. rocketList.add(info.getLong("oid"));
  886. }
  887. if (!Check.isNull(itemCheck)) {
  888. String ownership = itemCheck.getOwnership();
  889. if ("ruixuan".equals(ownership)) {
  890. ruixuanList.add(info.getLong("oid"));
  891. }
  892. if ("miaogousi".equals(ownership)) {
  893. mgsList.add(info.getLong("oid"));
  894. }
  895. if ("rocket".equals(ownership)) {
  896. rocketList.add(info.getLong("oid"));
  897. }
  898. if ("yufu".equals(ownership)) {
  899. yufuList.add(info.getLong("oid"));
  900. }
  901. if ("yuxiu".equals(ownership)) {
  902. yuxiuList.add(info.getLong("oid"));
  903. }
  904. }
  905. }
  906. }
  907. } else {
  908. log.error("===Rocket查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  909. log.error("Rocket游标:{},执行次数:{}", pcursor, counts);
  910. if (counts <= 3) {
  911. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  912. }
  913. }
  914. if (!Check.isNull(ruixuanList)) {
  915. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  916. }
  917. if (!Check.isNull(mgsList)) {
  918. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  919. }
  920. if (!Check.isNull(rocketList)) {
  921. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  922. }
  923. if (!Check.isNull(yufuList)) {
  924. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  925. }
  926. if (!Check.isNull(yuxiuList)) {
  927. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  928. }
  929. if (!"nomore".equals(pcursor)) {
  930. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  931. }
  932. }
  933. private void getYufuInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  934. List<Long> ruixuanList = new ArrayList<>();
  935. List<Long> mgsList = new ArrayList<>();
  936. List<Long> rocketList = new ArrayList<>();
  937. List<Long> yufuList = new ArrayList<>();
  938. List<Long> yuxiuList = new ArrayList<>();
  939. String appKey = accessToken.getAppKey();
  940. String signSecret = accessToken.getSignSecret();
  941. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  942. return;
  943. }
  944. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  945. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  946. request.setAccessToken(accessToken.getAccessToken());
  947. request.setApiMethodVersion(1L);
  948. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  949. request.setSortType(1);
  950. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  951. request.setQueryType(2);
  952. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  953. request.setCpsOrderStatus(0);
  954. request.setDistributorId(0l);
  955. request.setBeginTime(beginTime);
  956. request.setEndTime(endTime);
  957. request.setPcursor(pcursor);
  958. request.setPageize(100);
  959. request.setFundType(1);
  960. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  961. try {
  962. response = client.execute(request);
  963. } catch (KsMerchantApiException e) {
  964. e.printStackTrace();
  965. }
  966. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  967. String code = obj.getString("code");
  968. if ("1".equals(code)) {
  969. JSONObject data = obj.getJSONObject("data");
  970. pcursor = data.getString("pcursor");
  971. JSONArray orderView = data.getJSONArray("orderView");
  972. for (int i = 0; i < orderView.size(); i++) {
  973. JSONObject info = orderView.getJSONObject(i);
  974. Integer sendStatus = info.getInteger("sendStatus");
  975. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  976. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  977. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  978. Long itemId = itemJson.getLong("itemId");
  979. Criteria criteria = new Criteria();
  980. criteria = Criteria.where("_id").is(itemId);
  981. Query query = new Query(criteria);
  982. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  983. if (Check.isNull(itemCheck)) {
  984. yufuList.add(info.getLong("oid"));
  985. }
  986. if (!Check.isNull(itemCheck)) {
  987. String ownership = itemCheck.getOwnership();
  988. if ("ruixuan".equals(ownership)) {
  989. ruixuanList.add(info.getLong("oid"));
  990. }
  991. if ("miaogousi".equals(ownership)) {
  992. mgsList.add(info.getLong("oid"));
  993. }
  994. if ("rocket".equals(ownership)) {
  995. rocketList.add(info.getLong("oid"));
  996. }
  997. if ("yufu".equals(ownership)) {
  998. yufuList.add(info.getLong("oid"));
  999. }
  1000. if ("yuxiu".equals(ownership)) {
  1001. yuxiuList.add(info.getLong("oid"));
  1002. }
  1003. }
  1004. }
  1005. }
  1006. } else {
  1007. log.error("===yufu查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1008. log.error("yufu游标:{},执行次数:{}", pcursor, counts);
  1009. if (counts <= 3) {
  1010. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1011. }
  1012. }
  1013. if (!Check.isNull(ruixuanList)) {
  1014. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1015. }
  1016. if (!Check.isNull(mgsList)) {
  1017. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1018. }
  1019. if (!Check.isNull(rocketList)) {
  1020. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1021. }
  1022. if (!Check.isNull(yufuList)) {
  1023. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1024. }
  1025. if (!Check.isNull(yuxiuList)) {
  1026. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1027. }
  1028. if (!"nomore".equals(pcursor)) {
  1029. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1030. }
  1031. }
  1032. private void getYuxiuInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1033. List<Long> ruixuanList = new ArrayList<>();
  1034. List<Long> mgsList = new ArrayList<>();
  1035. List<Long> rocketList = new ArrayList<>();
  1036. List<Long> yufuList = new ArrayList<>();
  1037. List<Long> yuxiuList = new ArrayList<>();
  1038. String appKey = accessToken.getAppKey();
  1039. String signSecret = accessToken.getSignSecret();
  1040. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1041. return;
  1042. }
  1043. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1044. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1045. request.setAccessToken(accessToken.getAccessToken());
  1046. request.setApiMethodVersion(1L);
  1047. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1048. request.setSortType(1);
  1049. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1050. request.setQueryType(2);
  1051. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1052. request.setCpsOrderStatus(0);
  1053. request.setDistributorId(0l);
  1054. request.setBeginTime(beginTime);
  1055. request.setEndTime(endTime);
  1056. request.setPcursor(pcursor);
  1057. request.setPageize(100);
  1058. request.setFundType(1);
  1059. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1060. try {
  1061. response = client.execute(request);
  1062. } catch (KsMerchantApiException e) {
  1063. e.printStackTrace();
  1064. }
  1065. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1066. String code = obj.getString("code");
  1067. if ("1".equals(code)) {
  1068. JSONObject data = obj.getJSONObject("data");
  1069. pcursor = data.getString("pcursor");
  1070. JSONArray orderView = data.getJSONArray("orderView");
  1071. for (int i = 0; i < orderView.size(); i++) {
  1072. JSONObject info = orderView.getJSONObject(i);
  1073. Integer sendStatus = info.getInteger("sendStatus");
  1074. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1075. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1076. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1077. Long itemId = itemJson.getLong("itemId");
  1078. Criteria criteria = new Criteria();
  1079. criteria = Criteria.where("_id").is(itemId);
  1080. Query query = new Query(criteria);
  1081. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1082. if (Check.isNull(itemCheck)) {
  1083. yuxiuList.add(info.getLong("oid"));
  1084. }
  1085. if (!Check.isNull(itemCheck)) {
  1086. String ownership = itemCheck.getOwnership();
  1087. if ("ruixuan".equals(ownership)) {
  1088. ruixuanList.add(info.getLong("oid"));
  1089. }
  1090. if ("miaogousi".equals(ownership)) {
  1091. mgsList.add(info.getLong("oid"));
  1092. }
  1093. if ("rocket".equals(ownership)) {
  1094. rocketList.add(info.getLong("oid"));
  1095. }
  1096. if ("yufu".equals(ownership)) {
  1097. yufuList.add(info.getLong("oid"));
  1098. }
  1099. if ("yuxiu".equals(ownership)) {
  1100. yuxiuList.add(info.getLong("oid"));
  1101. }
  1102. }
  1103. }
  1104. }
  1105. } else {
  1106. log.error("===yuxiu查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1107. log.error("yuxiu游标:{},执行次数:{}", pcursor, counts);
  1108. if (counts <= 3) {
  1109. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1110. }
  1111. }
  1112. if (!Check.isNull(yuxiuList)) {
  1113. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1114. }
  1115. if (!Check.isNull(ruixuanList)) {
  1116. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1117. }
  1118. if (!Check.isNull(mgsList)) {
  1119. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1120. }
  1121. if (!Check.isNull(rocketList)) {
  1122. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1123. }
  1124. if (!Check.isNull(yufuList)) {
  1125. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1126. }
  1127. if (!"nomore".equals(pcursor)) {
  1128. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1129. }
  1130. }
  1131. private KuaishouSupplyChain organizeData(JSONObject jsonObject, Map<Long, Long> itemMap) {
  1132. KuaishouSupplyChain supplyChain = new KuaishouSupplyChain();
  1133. supplyChain.setOid(jsonObject.getLong("oid"));
  1134. JSONObject item = jsonObject.getJSONArray("cpsOrderProductView").getJSONObject(0);
  1135. if (!Check.isNull(item)) {
  1136. supplyChain.setItemId(item.getLong("itemId"));
  1137. supplyChain.setItemTitle(item.getString("itemTitle"));
  1138. supplyChain.setReservePrice(item.getLong("itemPrice"));
  1139. supplyChain.setImageUrl(itemListMapper.getItemImgUrl(item.getLong("itemId")));
  1140. supplyChain.setSellerId(item.getLong("sellerId"));
  1141. }
  1142. supplyChain.setOrderStatus(jsonObject.getInteger("cpsOrderStatus"));
  1143. supplyChain.setOrderCreateTime(jsonObject.getLong("orderCreateTime"));
  1144. supplyChain.setSendStatus(jsonObject.getInteger("sendStatus"));
  1145. supplyChain.setSettlementBizType(jsonObject.getInteger("settlementBizType"));
  1146. supplyChain.setSettlementBizTypeDesc(getSettlementBizTypeDesc(jsonObject.getInteger("settlementBizType")));
  1147. supplyChain.setSendTime(jsonObject.getLong("sendTime"));
  1148. supplyChain.setRecvTime(jsonObject.getLong("recvTime"));
  1149. supplyChain.setPromoterId(jsonObject.getLong("promotionId"));
  1150. supplyChain.setPromoterNickName(jsonObject.getString("promotionNickName"));
  1151. supplyChain.setActivityId(jsonObject.getLong("activityId"));
  1152. supplyChain.setOrderAmount(jsonObject.getLong("payAmount"));
  1153. supplyChain.setPayAmount(jsonObject.getLong("payAmount"));
  1154. supplyChain.setRegimentalPromotionRate(jsonObject.getLong("regimentalPromotionRate"));
  1155. supplyChain.setShareRate(jsonObject.getLong("shareRateStr"));
  1156. supplyChain.setBaseAmount(jsonObject.getLong("baseAmount"));
  1157. supplyChain.setRegimentalPromotionAmount(jsonObject.getLong("regimentalPromotionAmount") / 1000);
  1158. supplyChain.setTotalRegimentalSettleAmount(jsonObject.getLong("settlementAmount"));
  1159. supplyChain.setStatDate(DateUtils.tempToDate(jsonObject.getLong("orderCreateTime")));
  1160. supplyChain.setItemCommissionRate(itemMap.get(item.getLong("itemId")));
  1161. return supplyChain;
  1162. }
  1163. private String getSettlementBizTypeDesc(Integer settlementBizType) {
  1164. return settlementBizType == 1 ? "快分销" : "聚力计划";
  1165. }
  1166. // 获取订单佣金率
  1167. public Map<Long, Long> getItemMap() {
  1168. Map<Long, Long> returnMap = new HashMap<>();
  1169. List<JSONObject> list = itemListMapper.itemList();
  1170. if (!Check.isNull(list)) {
  1171. for (int i = 0; i < list.size(); i++) {
  1172. JSONObject jsonObject = list.get(i);
  1173. returnMap.put(jsonObject.getLong("itemId"), jsonObject.getLong("itemCommissionRate"));
  1174. }
  1175. }
  1176. return returnMap;
  1177. }
  1178. @Override
  1179. public void addListKuaishouActivityInfo() throws InterruptedException {
  1180. String url = "https://openapi.kwaixiaodian.com";
  1181. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  1182. for (KuaishouAccessToken mgsToken : mgsTokens) {
  1183. getMgsInfoKuaishouActivityInfo(mgsToken, url);
  1184. }
  1185. Thread.sleep(30000);
  1186. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  1187. for (KuaishouAccessToken token : rocketTokens) {
  1188. getRocketInfoKuaishouActivityInfo(token, url);
  1189. }
  1190. Thread.sleep(30000);
  1191. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  1192. for (KuaishouAccessToken accessToken : tokens) {
  1193. getInfoKuaishouActivityInfo(accessToken, url);
  1194. }
  1195. Thread.sleep(30000);
  1196. List<KuaishouAccessToken> yufutokens = accessTokenService.getYufuTokenInfos();
  1197. for (KuaishouAccessToken accessToken : yufutokens) {
  1198. getYufuInfoKuaishouActivityInfo(accessToken, url);
  1199. }
  1200. Thread.sleep(30000);
  1201. List<KuaishouAccessToken> yuxiutokens = accessTokenService.getYuxiuTokenInfos();
  1202. for (KuaishouAccessToken accessToken : yuxiutokens) {
  1203. getYuxiuInfoKuaishouActivityInfo(accessToken, url);
  1204. }
  1205. }
  1206. @Override
  1207. public void addKuaishouActivityOpenItemList() throws InterruptedException {
  1208. String url = "https://openapi.kwaixiaodian.com";
  1209. List<Long> mgsActivityIds = supplyChainMapper.getMgsKuaishouActivityInfoList();
  1210. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  1211. for (KuaishouAccessToken mgsToken : mgsTokens) {
  1212. for (Long activityId : mgsActivityIds) {
  1213. getKuaishouActivityOpenItemList(mgsToken, url, activityId, 1, "miaogousi");
  1214. }
  1215. }
  1216. Thread.sleep(30000);
  1217. List<Long> rocketActivityIds = supplyChainMapper.getRocketKuaishouActivityInfoList();
  1218. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  1219. for (KuaishouAccessToken token : rocketTokens) {
  1220. for (Long activityId : rocketActivityIds) {
  1221. getKuaishouActivityOpenItemList(token, url, activityId, 1, "rocket");
  1222. }
  1223. }
  1224. Thread.sleep(30000);
  1225. List<Long> activityIds = supplyChainMapper.getKuaishouActivityInfoList();
  1226. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  1227. for (KuaishouAccessToken accessToken : tokens) {
  1228. for (Long activityId : activityIds) {
  1229. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "ruixuan");
  1230. }
  1231. }
  1232. Thread.sleep(30000);
  1233. List<Long> yufuActivityIds = supplyChainMapper.getYufuKuaishouActivityInfoList();
  1234. List<KuaishouAccessToken> yufutokens = accessTokenService.getYufuTokenInfos();
  1235. for (KuaishouAccessToken accessToken : yufutokens) {
  1236. for (Long activityId : yufuActivityIds) {
  1237. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "yufu");
  1238. }
  1239. }
  1240. Thread.sleep(30000);
  1241. List<Long> yuxiuActivityIds = supplyChainMapper.getYuxiuKuaishouActivityInfoList();
  1242. List<KuaishouAccessToken> yuxiutokens = accessTokenService.getYuxiuTokenInfos();
  1243. for (KuaishouAccessToken accessToken : yuxiutokens) {
  1244. for (Long activityId : yuxiuActivityIds) {
  1245. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "yuxiu");
  1246. }
  1247. }
  1248. }
  1249. @Override
  1250. public List<JSONObject> getBytedanceOrderHourDataList(Long date) {
  1251. return supplyChainMapper.getBytedanceOrderHourDataList(date);
  1252. }
  1253. @Override
  1254. public List<JSONObject> getKuaishouOrderHourDataList(Long date) {
  1255. return supplyChainMapper.getKuaishouOrderHourDataList(date);
  1256. }
  1257. @Override
  1258. public List<JSONObject> getTopOrders(Map<String, Object> requestMap) {
  1259. return supplyChainMapper.getTopOrders(requestMap);
  1260. }
  1261. @Override
  1262. public List<JSONObject> exportItemDetail(Map<String, Object> requestMap) {
  1263. return supplyChainMapper.exportItemDetail(requestMap);
  1264. }
  1265. @Override
  1266. public List<JSONObject> getKsChannelGmvHourByDate(List<Long> userList, Integer nowDate) {
  1267. return supplyChainMapper.getKsChannelGmvHourByDate(userList, nowDate);
  1268. }
  1269. @Override
  1270. public List<JSONObject> getKsCourtshipGmvHourByDate(List<Long> userList, Integer nowDate) {
  1271. return supplyChainMapper.getKsCourtshipGmvHourByDate(userList, nowDate);
  1272. }
  1273. @Override
  1274. public List<JSONObject> getBytedanceChannelGmvHourByDate(List<Long> userList, Long date) {
  1275. return supplyChainMapper.getBytedanceChannelGmvHourByDate(userList, date);
  1276. }
  1277. @Override
  1278. public List<JSONObject> getBytedanceCourtshipGmvHourByDate(List<Long> userList, Long data) {
  1279. return supplyChainMapper.getBytedanceCourtshipGmvHourByDate(userList, data);
  1280. }
  1281. @Override
  1282. public List<JSONObject> shopList(Map<String, Object> requestMap) {
  1283. return supplyChainMapper.shopList(requestMap);
  1284. }
  1285. @Override
  1286. public List<JSONObject> shopDetail(Map<String, Object> requestMap) {
  1287. return supplyChainMapper.shopDetail(requestMap);
  1288. }
  1289. @Override
  1290. public List<Long> getItemIdsByUserId(Long userId) {
  1291. return supplyChainMapper.getItemIdsByUserId(userId);
  1292. }
  1293. @Override
  1294. public List<Long> getItemIdsByDeptId(Long deptId) {
  1295. return supplyChainMapper.getItemIdsByDeptId(deptId);
  1296. }
  1297. @Override
  1298. public List<JSONObject> getKsChannelGmvHourByDateRoi(List<Long> userList, Integer nowDate) {
  1299. return supplyChainMapper.getKsChannelGmvHourByDateRoi(userList, nowDate);
  1300. }
  1301. @Override
  1302. public List<JSONObject> getKsCourtshipGmvHourByDateRoi(List<Long> userList, Integer nowDate) {
  1303. return supplyChainMapper.getKsCourtshipGmvHourByDateRoi(userList, nowDate);
  1304. }
  1305. @Override
  1306. public List<JSONObject> getBytedanceChannelGmvHourByDateRoi(List<Long> userList, Long dataNow) {
  1307. return supplyChainMapper.getBytedanceChannelGmvHourByDateRoi(userList, dataNow);
  1308. }
  1309. @Override
  1310. public List<JSONObject> getBytedanceCourtshipGmvHourByDateRoi(List<Long> userList, Long dataNow) {
  1311. return supplyChainMapper.getBytedanceCourtshipGmvHourByDateRoi(userList, dataNow);
  1312. }
  1313. private void getInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1314. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1315. String appKey = accessToken.getAppKey();
  1316. String signSecret = accessToken.getSignSecret();
  1317. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1318. return;
  1319. }
  1320. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1321. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1322. request.setAccessToken(accessToken.getAccessToken());
  1323. request.setApiMethodVersion(1L);
  1324. //每页活动数量
  1325. request.setLimit(5000);
  1326. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1327. try {
  1328. response = client.execute(request);
  1329. } catch (KsMerchantApiException e) {
  1330. e.printStackTrace();
  1331. }
  1332. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1333. String code = obj.getString("code");
  1334. if ("1".equals(code)) {
  1335. JSONObject data = obj.getJSONObject("data");
  1336. JSONArray result = data.getJSONArray("result");
  1337. for (int i = 0; i < result.size(); i++) {
  1338. JSONObject info = result.getJSONObject(i);
  1339. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1340. list.add(activityInfo);
  1341. }
  1342. } else {
  1343. log.error("===团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  1344. return;
  1345. }
  1346. if (Check.isNotNull(list) && list.size() > 0) {
  1347. supplyChainMapper.replaceKuaishouActivityInfo(list);
  1348. }
  1349. }
  1350. private void getKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page, String dbtype) {
  1351. String appKey = accessToken.getAppKey();
  1352. String signSecret = accessToken.getSignSecret();
  1353. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1354. return;
  1355. }
  1356. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1357. OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
  1358. request.setAccessToken(accessToken.getAccessToken());
  1359. request.setApiMethodVersion(1L);
  1360. //每页活动数量
  1361. request.setLimit(200);
  1362. Integer offset = (page - 1) * 200;
  1363. request.setOffset(offset);
  1364. request.setActivityId(activityId);
  1365. OpenDistributionInvestmentActivityOpenItemListResponse response = null;
  1366. try {
  1367. response = client.execute(request);
  1368. } catch (KsMerchantApiException e) {
  1369. e.printStackTrace();
  1370. }
  1371. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1372. Integer total = null;
  1373. String code = obj.getString("code");
  1374. if ("1".equals(code)) {
  1375. JSONObject data = obj.getJSONObject("data");
  1376. JSONArray result = data.getJSONArray("activityItemDataList");
  1377. total = data.getInteger("total");
  1378. List<Long> itemIds = new ArrayList<>();
  1379. List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
  1380. for (int i = 0; i < result.size(); i++) {
  1381. JSONObject info = result.getJSONObject(i);
  1382. //商品活动审核状态:1-待审核,2-审核通过,3-审核拒绝,5-已失效
  1383. if (info.getLong("itemAuditStatus") == 1 || info.getLong("itemAuditStatus") == 2) {
  1384. KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
  1385. list.add(activityInfo);
  1386. }
  1387. //2-审核通过
  1388. if (info.getLong("itemAuditStatus") == 2) {
  1389. itemIds.add(info.getLong("itemId"));
  1390. }
  1391. }
  1392. if (Check.isNotNull(list) && list.size() > 0) {
  1393. if ("ruixuan".equals(dbtype)) {
  1394. supplyChainMapper.replaceKuaiShouActivityOpenItemList(list);
  1395. } else if ("miaogousi".equals(dbtype)) {
  1396. supplyChainMapper.replaceMgsKuaiShouActivityOpenItemList(list);
  1397. } else if ("rocket".equals(dbtype)) {
  1398. supplyChainMapper.replaceRocketKuaiShouActivityOpenItemList(list);
  1399. } else if ("yufu".equals(dbtype)) {
  1400. supplyChainMapper.replaceYufuKuaiShouActivityOpenItemList(list);
  1401. } else if ("yuxiu".equals(dbtype)) {
  1402. supplyChainMapper.replaceYuxiuKuaiShouActivityOpenItemList(list);
  1403. }
  1404. }
  1405. List<List<Long>> splits = Lists.newArrayList(Lists.partition(itemIds, 10));
  1406. for (List<Long> itIds : splits) {
  1407. getActivityItemDetail(accessToken, url, activityId, itIds, dbtype);
  1408. }
  1409. } else {
  1410. log.error("===团长招商活动已报名商品列表(open.distribution.investment.activity.open.item.list)失败,信息:{}", obj.getString("error_msg"));
  1411. return;
  1412. }
  1413. if (total - page * 200 > 0) {
  1414. getKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1, dbtype);
  1415. }
  1416. }
  1417. private void getActivityItemDetail(KuaishouAccessToken accessToken, String url, Long activityId, List<Long> itemIds, String dbtype) {
  1418. List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
  1419. String appKey = accessToken.getAppKey();
  1420. String signSecret = accessToken.getSignSecret();
  1421. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1422. return;
  1423. }
  1424. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1425. OpenDistributionInvestmentActivityItemDetailRequest request = new OpenDistributionInvestmentActivityItemDetailRequest();
  1426. request.setAccessToken(accessToken.getAccessToken());
  1427. request.setApiMethodVersion(1L);
  1428. request.setActivityId(activityId);
  1429. request.setItemId(itemIds);
  1430. OpenDistributionInvestmentActivityItemDetailResponse response = null;
  1431. try {
  1432. response = client.execute(request);
  1433. } catch (KsMerchantApiException e) {
  1434. e.printStackTrace();
  1435. }
  1436. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1437. String code = obj.getString("code");
  1438. if ("1".equals(code)) {
  1439. JSONArray data = obj.getJSONArray("data");
  1440. for (int i = 0; i < data.size(); i++) {
  1441. JSONObject info = data.getJSONObject(i);
  1442. KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
  1443. list.add(activityInfo);
  1444. }
  1445. if (Check.isNotNull(list) && list.size() > 0) {
  1446. if ("ruixuan".equals(dbtype)) {
  1447. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1448. supplyChainMapper.updateKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1449. }
  1450. } else if ("miaogousi".equals(dbtype)) {
  1451. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1452. supplyChainMapper.updateMgsKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1453. }
  1454. } else if ("rocket".equals(dbtype)) {
  1455. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1456. supplyChainMapper.updateRocketKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1457. }
  1458. } else if ("yufu".equals(dbtype)) {
  1459. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1460. supplyChainMapper.updateYufuKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1461. }
  1462. } else if ("yuxiu".equals(dbtype)) {
  1463. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1464. supplyChainMapper.updateYuxiuKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1465. }
  1466. }
  1467. }
  1468. } else {
  1469. log.error("===招商活动商品详情接口(open.distribution.investment.activity.item.detail)失败,信息:{}", obj.getString("error_msg"));
  1470. return;
  1471. }
  1472. }
  1473. private KuaiShouActivityInfo organizeKuaishouActivityInfo(JSONObject jsonObject) {
  1474. KuaiShouActivityInfo activityInfo = new KuaiShouActivityInfo();
  1475. activityInfo.setActivityId(jsonObject.getLong("activityId"));
  1476. activityInfo.setRegimentalId(jsonObject.getLong("activityUserId"));
  1477. activityInfo.setActivityTitle(jsonObject.getString("activityTitle"));
  1478. activityInfo.setActivityType(jsonObject.getInteger("activityType"));
  1479. activityInfo.setActivityBeginTime(DateUtils.tempToDate(jsonObject.getLong("activityBeginTime")));
  1480. activityInfo.setActivityEndTime(DateUtils.tempToDate(jsonObject.getLong("activityEndTime")));
  1481. activityInfo.setActivityStatus(jsonObject.getInteger("activityStatus"));
  1482. JSONObject activityItemDataInfo = jsonObject.getJSONObject("activityItemDataView");
  1483. if (!Check.isNull(activityItemDataInfo)) {
  1484. activityInfo.setApplyItemCount(activityItemDataInfo.getInteger("applyItemCount"));
  1485. activityInfo.setWaitAuditItemCount(activityItemDataInfo.getInteger("waitAuditItemCount"));
  1486. activityInfo.setAuditPassItemCount(activityItemDataInfo.getInteger("auditPassItemCount"));
  1487. }
  1488. return activityInfo;
  1489. }
  1490. private void getMgsInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1491. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1492. String appKey = accessToken.getAppKey();
  1493. String signSecret = accessToken.getSignSecret();
  1494. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1495. return;
  1496. }
  1497. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1498. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1499. request.setAccessToken(accessToken.getAccessToken());
  1500. request.setApiMethodVersion(1L);
  1501. //每页活动数量
  1502. request.setLimit(5000);
  1503. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1504. try {
  1505. response = client.execute(request);
  1506. } catch (KsMerchantApiException e) {
  1507. e.printStackTrace();
  1508. }
  1509. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1510. String code = obj.getString("code");
  1511. if ("1".equals(code)) {
  1512. JSONObject data = obj.getJSONObject("data");
  1513. JSONArray result = data.getJSONArray("result");
  1514. for (int i = 0; i < result.size(); i++) {
  1515. JSONObject info = result.getJSONObject(i);
  1516. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1517. list.add(activityInfo);
  1518. }
  1519. } else {
  1520. log.error("===团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  1521. return;
  1522. }
  1523. if (Check.isNotNull(list) && list.size() > 0) {
  1524. supplyChainMapper.replaceMgsKuaishouActivityInfo(list);
  1525. }
  1526. }
  1527. private void getRocketInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1528. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1529. String appKey = accessToken.getAppKey();
  1530. String signSecret = accessToken.getSignSecret();
  1531. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1532. return;
  1533. }
  1534. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1535. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1536. request.setAccessToken(accessToken.getAccessToken());
  1537. request.setApiMethodVersion(1L);
  1538. //每页活动数量
  1539. request.setLimit(5000);
  1540. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1541. try {
  1542. response = client.execute(request);
  1543. } catch (KsMerchantApiException e) {
  1544. e.printStackTrace();
  1545. }
  1546. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1547. String code = obj.getString("code");
  1548. if ("1".equals(code)) {
  1549. JSONObject data = obj.getJSONObject("data");
  1550. JSONArray result = data.getJSONArray("result");
  1551. for (int i = 0; i < result.size(); i++) {
  1552. JSONObject info = result.getJSONObject(i);
  1553. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1554. list.add(activityInfo);
  1555. }
  1556. } else {
  1557. log.error("===Rocket团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  1558. return;
  1559. }
  1560. if (Check.isNotNull(list) && list.size() > 0) {
  1561. supplyChainMapper.replaceRocketKuaishouActivityInfo(list);
  1562. }
  1563. }
  1564. private void getYufuInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1565. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1566. String appKey = accessToken.getAppKey();
  1567. String signSecret = accessToken.getSignSecret();
  1568. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1569. return;
  1570. }
  1571. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1572. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1573. request.setAccessToken(accessToken.getAccessToken());
  1574. request.setApiMethodVersion(1L);
  1575. //每页活动数量
  1576. request.setLimit(5000);
  1577. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1578. try {
  1579. response = client.execute(request);
  1580. } catch (KsMerchantApiException e) {
  1581. e.printStackTrace();
  1582. }
  1583. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1584. String code = obj.getString("code");
  1585. if ("1".equals(code)) {
  1586. JSONObject data = obj.getJSONObject("data");
  1587. JSONArray result = data.getJSONArray("result");
  1588. for (int i = 0; i < result.size(); i++) {
  1589. JSONObject info = result.getJSONObject(i);
  1590. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1591. list.add(activityInfo);
  1592. }
  1593. } else {
  1594. log.error("===Yufu团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  1595. return;
  1596. }
  1597. if (Check.isNotNull(list) && list.size() > 0) {
  1598. supplyChainMapper.replaceYufuKuaishouActivityInfo(list);
  1599. }
  1600. }
  1601. private void getYuxiuInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1602. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1603. String appKey = accessToken.getAppKey();
  1604. String signSecret = accessToken.getSignSecret();
  1605. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1606. return;
  1607. }
  1608. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1609. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1610. request.setAccessToken(accessToken.getAccessToken());
  1611. request.setApiMethodVersion(1L);
  1612. //每页活动数量
  1613. request.setLimit(5000);
  1614. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1615. try {
  1616. response = client.execute(request);
  1617. } catch (KsMerchantApiException e) {
  1618. e.printStackTrace();
  1619. }
  1620. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1621. String code = obj.getString("code");
  1622. if ("1".equals(code)) {
  1623. JSONObject data = obj.getJSONObject("data");
  1624. JSONArray result = data.getJSONArray("result");
  1625. for (int i = 0; i < result.size(); i++) {
  1626. JSONObject info = result.getJSONObject(i);
  1627. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1628. list.add(activityInfo);
  1629. }
  1630. } else {
  1631. log.error("===Yuxiu团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  1632. return;
  1633. }
  1634. if (Check.isNotNull(list) && list.size() > 0) {
  1635. supplyChainMapper.replaceYuxiuKuaishouActivityInfo(list);
  1636. }
  1637. }
  1638. }