SupplyChainServiceImpl.java 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395
  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.OpenDistributionCpsLeaderOrderDetailRequest;
  10. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityItemDetailRequest;
  11. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenItemListRequest;
  12. import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenListRequest;
  13. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionCpsLeaderOrderCursorListResponse;
  14. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionCpsLeaderOrderDetailResponse;
  15. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityItemDetailResponse;
  16. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenItemListResponse;
  17. import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenListResponse;
  18. import com.ruixuan.common.utils.Check;
  19. import com.ruixuan.common.utils.DateUtils;
  20. import com.ruixuan.isc.constants.KuaiShouConstants;
  21. import com.ruixuan.isc.entity.ItemCheck;
  22. import com.ruixuan.isc.entity.KuaiShouActivityInfo;
  23. import com.ruixuan.isc.entity.KuaiShouActivityOpenItemList;
  24. import com.ruixuan.isc.entity.KuaishouAccessToken;
  25. import com.ruixuan.isc.entity.KuaishouSupplyChain;
  26. import com.ruixuan.isc.mapper.KuaishouItemListMapper;
  27. import com.ruixuan.isc.mapper.SupplyChainMapper;
  28. import com.ruixuan.isc.service.IAccessTokenService;
  29. import com.ruixuan.isc.service.ISupplyChainService;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.data.mongodb.core.MongoTemplate;
  34. import org.springframework.data.mongodb.core.query.Criteria;
  35. import org.springframework.data.mongodb.core.query.Query;
  36. import org.springframework.stereotype.Service;
  37. import java.util.ArrayList;
  38. import java.util.Date;
  39. import java.util.HashMap;
  40. import java.util.List;
  41. import java.util.Map;
  42. import java.util.concurrent.ExecutorService;
  43. import java.util.concurrent.Executors;
  44. @Slf4j
  45. @Service
  46. public class SupplyChainServiceImpl implements ISupplyChainService {
  47. @Autowired
  48. private SupplyChainMapper supplyChainMapper;
  49. @Autowired
  50. private KuaishouItemListMapper itemListMapper;
  51. @Autowired
  52. private IAccessTokenService accessTokenService;
  53. @Value("${ownership.id}")
  54. private String ownershipId;
  55. @Autowired
  56. private MongoTemplate mongoTemplate;
  57. // 获取订单数据 
  58. @Override
  59. public List<JSONObject> getOrderList(Map<String, Object> requestMap) {
  60. List<JSONObject> list = supplyChainMapper.getOrderList(requestMap);
  61. if (!Check.isNull(list)) {
  62. for (int i = 0; i < list.size(); i++) {
  63. JSONObject jsonObject = list.get(i);
  64. String promoterId = jsonObject.getString("promoterId");
  65. requestMap.put("promoterId", promoterId);
  66. List<JSONObject> topOrders = supplyChainMapper.getTopOrders(requestMap);
  67. jsonObject.put("topOrders", topOrders);
  68. List<JSONObject> tags = supplyChainMapper.getPromoterId(Long.valueOf(promoterId));
  69. jsonObject.put("tags", tags);
  70. }
  71. }
  72. return list;
  73. }
  74. //达人带货详情
  75. @Override
  76. public List<JSONObject> anchorOrderDetail(Map<String, Object> requestMap) {
  77. return supplyChainMapper.anchorOrderDetail(requestMap);
  78. }
  79. //订单统计
  80. @Override
  81. public List<JSONObject> orderStatistics(Map<String, Object> requestMap) {
  82. return supplyChainMapper.orderStatistics(requestMap);
  83. }
  84. //商品列表
  85. @Override
  86. public List<JSONObject> itemList(Map<String, Object> requestMap) {
  87. List<JSONObject> list = supplyChainMapper.itemList(requestMap);
  88. return list;
  89. }
  90. @Override
  91. public List<JSONObject> itemBindList(Map<String, Object> requestMap) {
  92. return supplyChainMapper.itemBindList(requestMap);
  93. }
  94. @Override
  95. public List<JSONObject> itemDetail(Map<String, Object> requestMap) {
  96. return supplyChainMapper.itemDetail(requestMap);
  97. }
  98. @Override
  99. public List<JSONObject> itemServiceCharge(Map<String, Object> requestMap) {
  100. return supplyChainMapper.itemServiceCharge(requestMap);
  101. }
  102. @Override
  103. public JSONObject getOrderTotal(Map<String, Object> requestMap) {
  104. return supplyChainMapper.getOrderTotal(requestMap);
  105. }
  106. @Override
  107. public Double getOrderTotalRatio(Map<String, Object> ratioMap) {
  108. return supplyChainMapper.getOrderTotalRatio(ratioMap);
  109. }
  110. @Override
  111. public JSONObject getAmountTotal(Map<String, Object> requestMap) {
  112. return supplyChainMapper.getAmountTotal(requestMap);
  113. }
  114. @Override
  115. public Double getAmountTotalRatio(Map<String, Object> ratioMap) {
  116. return supplyChainMapper.getAmountTotalRatio(ratioMap);
  117. }
  118. @Override
  119. public JSONObject getServiceAmountTotal(Map<String, Object> requestMap) {
  120. return supplyChainMapper.getServiceAmountTotal(requestMap);
  121. }
  122. @Override
  123. public List<JSONObject> getOrderRankRatioList(Map<String, Object> requestMap) {
  124. return supplyChainMapper.getOrderRankRatioList(requestMap);
  125. }
  126. @Override
  127. public List<JSONObject> getOrderRankList(Map<String, Object> requestMap) {
  128. return supplyChainMapper.getOrderRankList(requestMap);
  129. }
  130. @Override
  131. public List<JSONObject> getPromoterRankRatioList(Map<String, Object> requestMap) {
  132. return supplyChainMapper.getPromoterRankRatioList(requestMap);
  133. }
  134. @Override
  135. public List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap) {
  136. return supplyChainMapper.getPromoterRatioList(requestMap);
  137. }
  138. @Override
  139. public List<JSONObject> exportPromoterTotal(Map<String, Object> requestMap) {
  140. return supplyChainMapper.exportPromoterTotal(requestMap);
  141. }
  142. @Override
  143. public List<JSONObject> exportPromoter(Map<String, Object> requestMap) {
  144. return supplyChainMapper.exportPromoter(requestMap);
  145. }
  146. @Override
  147. public List<JSONObject> exportOrder(Map<String, Object> requestMap) {
  148. return supplyChainMapper.exportOrder(requestMap);
  149. }
  150. @Override
  151. public List<JSONObject> getTopPromoterByItemId(Map<String, Object> requestMap) {
  152. return supplyChainMapper.getTopPromoterByItemId(requestMap);
  153. }
  154. @Override
  155. public List<JSONObject> bindUserItemList(Map<String, Object> requestMap) {
  156. return supplyChainMapper.bindUserItemList(requestMap);
  157. }
  158. @Override
  159. public List<JSONObject> getSupplyChainUserList() {
  160. return supplyChainMapper.getSupplyChainUserList();
  161. }
  162. @Override
  163. public boolean unbindUser(Long itemId) {
  164. return supplyChainMapper.unbindUser(itemId);
  165. }
  166. @Override
  167. public boolean bindUser(Long itemId, Long userId, String nikeName) {
  168. return supplyChainMapper.bindUser(itemId, userId, nikeName);
  169. }
  170. @Override
  171. public List<JSONObject> adminReportList(Map<String, Object> requestMap) {
  172. return supplyChainMapper.adminReportList(requestMap);
  173. }
  174. @Override
  175. public List<JSONObject> userItemDetail(Map<String, Object> requestMap) {
  176. return supplyChainMapper.userItemDetail(requestMap);
  177. }
  178. @Override
  179. public JSONObject getTimeIntervalRatio(Map<String, Object> requestMap) {
  180. return supplyChainMapper.getTimeIntervalRatio(requestMap);
  181. }
  182. @Override
  183. public List<JSONObject> indexStatistics(Map<String, Object> requestMap) {
  184. return supplyChainMapper.indexStatistics(requestMap);
  185. }
  186. @Override
  187. public JSONObject itemBindSummary() {
  188. return supplyChainMapper.itemBindSummary();
  189. }
  190. @Override
  191. public JSONObject userItemTotal(Map<String, Object> requestMap) {
  192. return supplyChainMapper.userItemTotal(requestMap);
  193. }
  194. @Override
  195. public List<JSONObject> exportUserItemDetail(Map<String, Object> requestMap) {
  196. return supplyChainMapper.exportUserItemDetail(requestMap);
  197. }
  198. @Override
  199. public JSONObject selectOrderInfo(Map<String, Object> requestMap) {
  200. return supplyChainMapper.selectOrderInfo(requestMap);
  201. }
  202. @Override
  203. public JSONObject selectOrderRate(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate, int hour) {
  204. return supplyChainMapper.selectOrderRate(promoterIds, itemIds, statDate, endDate, hour);
  205. }
  206. @Override
  207. public JSONObject selectOrderRateBytedance(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate, int hour) {
  208. return supplyChainMapper.selectOrderRateBytedance(promoterIds, itemIds, statDate, endDate, hour);
  209. }
  210. @Override
  211. public List<JSONObject> getMonthOrderAmount(Map<String, Object> map) {
  212. return supplyChainMapper.getMonthOrderAmount(map);
  213. }
  214. @Override
  215. public List<JSONObject> getMonthOrderAmountBytedance(Map<String, Object> map) {
  216. return supplyChainMapper.getMonthOrderAmountBytedance(map);
  217. }
  218. @Override
  219. public JSONObject getMonthOrderAmountTotalBytedance(Map<String, Object> map) {
  220. return supplyChainMapper.getMonthOrderAmountTotalBytedance(map);
  221. }
  222. @Override
  223. public List<JSONObject> getMonthOrderAmountByItemsBytedance(Map<String, Object> map) {
  224. return supplyChainMapper.getMonthOrderAmountByItemsBytedance(map);
  225. }
  226. @Override
  227. public JSONObject getMonthOrderAmountTotalByItemsBytedance(Map<String, Object> map) {
  228. return supplyChainMapper.getMonthOrderAmountTotalByItemsBytedance(map);
  229. }
  230. @Override
  231. public List<JSONObject> getOrderRankRatioListBytedance(Map<String, Object> requestMap) {
  232. return supplyChainMapper.getOrderRankRatioListBytedance(requestMap);
  233. }
  234. @Override
  235. public List<JSONObject> getOrderRankListBytedance(Map<String, Object> requestMap) {
  236. return supplyChainMapper.getOrderRankListBytedance(requestMap);
  237. }
  238. @Override
  239. public List<JSONObject> getPromoterRankRatioListBytedance(Map<String, Object> requestMap) {
  240. return supplyChainMapper.getPromoterRankRatioListBytedance(requestMap);
  241. }
  242. @Override
  243. public List<JSONObject> getPromoterRatioListBytedance(Map<String, Object> requestMap) {
  244. return supplyChainMapper.getPromoterRatioListBytedance(requestMap);
  245. }
  246. @Override
  247. public JSONObject selectOrderInfoBytedance(Map<String, Object> parMap) {
  248. return supplyChainMapper.selectOrderInfoBytedance(parMap);
  249. }
  250. @Override
  251. public List<JSONObject> bdReportListV2ByBind(Map<String, Object> requestMap) {
  252. return supplyChainMapper.bdReportListV2ByBind(requestMap);
  253. }
  254. @Override
  255. public List<JSONObject> exportBindOrder(Map<String, Object> requestMap) {
  256. return supplyChainMapper.exportBindOrder(requestMap);
  257. }
  258. @Override
  259. public JSONObject getMonthOrderAmountTotal(Map<String, Object> map) {
  260. return supplyChainMapper.getMonthOrderAmountTotal(map);
  261. }
  262. @Override
  263. public JSONObject selectOrderInfoByItemIds(Map<String, Object> requestMap) {
  264. return supplyChainMapper.selectOrderInfoByItemIds(requestMap);
  265. }
  266. @Override
  267. public List<JSONObject> getMonthOrderAmountByItems(Map<String, Object> map) {
  268. return supplyChainMapper.getMonthOrderAmountByItems(map);
  269. }
  270. @Override
  271. public JSONObject getMonthOrderAmountTotalByItems(Map<String, Object> map) {
  272. return supplyChainMapper.getMonthOrderAmountTotalByItems(map);
  273. }
  274. @Override
  275. public List<JSONObject> bdReportList(Map<String, Object> requestMap) {
  276. return supplyChainMapper.bdReportList(requestMap);
  277. }
  278. @Override
  279. public List<JSONObject> bdDetailList(Map<String, Object> requestMap) {
  280. return supplyChainMapper.bdDetailList(requestMap);
  281. }
  282. @Override
  283. public List<JSONObject> bdTotal(Map<String, Object> requestMap) {
  284. return supplyChainMapper.bdTotal(requestMap);
  285. }
  286. @Override
  287. public List<JSONObject> exportBdDetail(Map<String, Object> requestMap) {
  288. return supplyChainMapper.exportBdDetail(requestMap);
  289. }
  290. @Override
  291. public String getUserName(Long promoterId) {
  292. return supplyChainMapper.getUserName(promoterId);
  293. }
  294. @Override
  295. public List<JSONObject> exportBdReportList(Map<String, Object> requestMap) {
  296. return supplyChainMapper.exportBdReportList(requestMap);
  297. }
  298. @Override
  299. public List<JSONObject> exportAdminReportList(Map<String, Object> requestMap) {
  300. return supplyChainMapper.exportAdminReportList(requestMap);
  301. }
  302. @Override
  303. public List<JSONObject> getSupplyChainCourtshipUserList() {
  304. return supplyChainMapper.getSupplyChainCourtshipUserList();
  305. }
  306. @Override
  307. public List<JSONObject> adminReportListByBind(Map<String, Object> requestMap) {
  308. return supplyChainMapper.adminReportListByBind(requestMap);
  309. }
  310. @Override
  311. public List<JSONObject> exportAdminReportListByBind(Map<String, Object> requestMap) {
  312. return supplyChainMapper.exportAdminReportListByBind(requestMap);
  313. }
  314. @Override
  315. public List<JSONObject> bdReportListV2(Map<String, Object> requestMap) {
  316. return supplyChainMapper.bdReportListV2(requestMap);
  317. }
  318. @Override
  319. public List<JSONObject> bdTotalV2(Map<String, Object> requestMap) {
  320. return supplyChainMapper.bdTotalV2(requestMap);
  321. }
  322. @Override
  323. public List<JSONObject> bdDetailListV2(Map<String, Object> requestMap) {
  324. List<JSONObject> jsonObjects = supplyChainMapper.bdDetailListV2(requestMap);
  325. if (!Check.isNull(jsonObjects)) {
  326. for (int i = 0; i < jsonObjects.size(); i++) {
  327. JSONObject jsonObject = jsonObjects.get(i);
  328. Long promoterId = jsonObject.getLong("promoterId");
  329. List<JSONObject> tags = supplyChainMapper.getPromoterId(promoterId);
  330. jsonObject.put("tags", tags);
  331. }
  332. }
  333. return jsonObjects;
  334. }
  335. @Override
  336. public JSONObject selectOrderInfoByItemIdsBytedance(Map<String, Object> requestMap) {
  337. return supplyChainMapper.selectOrderInfoByItemIdsBytedance(requestMap);
  338. }
  339. @Override
  340. public void updateOrder(JSONObject eventJSon) {
  341. try {
  342. JSONObject info = eventJSon.getJSONObject("info");
  343. if (!Check.isNull(info)) {
  344. Long oid = info.getLong("oid");
  345. Integer cpsOrderStatus = info.getInteger("cpsOrderStatus");
  346. if (cpsOrderStatus == 30) {
  347. return;
  348. }
  349. if (cpsOrderStatus == 60) {
  350. Integer i = updateOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  351. if (i > 0) {
  352. log.info("订单ID:{},状态:{} 修改成功", oid, cpsOrderStatus);
  353. } else {
  354. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  355. }
  356. } else {
  357. Integer i = this.updateOrderStatus(oid, cpsOrderStatus);
  358. if (i > 0) {
  359. log.info("订单ID:{},状态:{} 修改成功", oid, cpsOrderStatus);
  360. } else {
  361. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  362. }
  363. }
  364. }
  365. } catch (Exception e) {
  366. e.printStackTrace();
  367. }
  368. }
  369. private Integer updateOrderStatus(Long oid, Integer cpsOrderStatus) {
  370. if ("ruixuan".equals(ownershipId)) {
  371. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  372. if (ruixuan > 0) {
  373. return ruixuan;
  374. }
  375. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  376. if (mgs > 0) {
  377. return mgs;
  378. }
  379. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  380. if (rocket > 0) {
  381. return rocket;
  382. }
  383. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  384. if (yufu > 0) {
  385. return yufu;
  386. }
  387. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  388. if (yuxiu > 0) {
  389. return yuxiu;
  390. }
  391. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  392. if (zhishui > 0) {
  393. return zhishui;
  394. }
  395. }
  396. if ("miaogousi".equals(ownershipId)) {
  397. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  398. if (mgs > 0) {
  399. return mgs;
  400. }
  401. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  402. if (ruixuan > 0) {
  403. return ruixuan;
  404. }
  405. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  406. if (rocket > 0) {
  407. return rocket;
  408. }
  409. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  410. if (yufu > 0) {
  411. return yufu;
  412. }
  413. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  414. if (yuxiu > 0) {
  415. return yuxiu;
  416. }
  417. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  418. if (zhishui > 0) {
  419. return zhishui;
  420. }
  421. }
  422. if ("rocket".equals(ownershipId)) {
  423. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  424. if (rocket > 0) {
  425. return rocket;
  426. }
  427. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  428. if (ruixuan > 0) {
  429. return ruixuan;
  430. }
  431. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  432. if (mgs > 0) {
  433. return mgs;
  434. }
  435. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  436. if (yufu > 0) {
  437. return yufu;
  438. }
  439. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  440. if (yuxiu > 0) {
  441. return yuxiu;
  442. }
  443. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  444. if (zhishui > 0) {
  445. return zhishui;
  446. }
  447. }
  448. if ("yufu".equals(ownershipId)) {
  449. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  450. if (yufu > 0) {
  451. return yufu;
  452. }
  453. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  454. if (ruixuan > 0) {
  455. return ruixuan;
  456. }
  457. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  458. if (mgs > 0) {
  459. return mgs;
  460. }
  461. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  462. if (rocket > 0) {
  463. return rocket;
  464. }
  465. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  466. if (yuxiu > 0) {
  467. return yuxiu;
  468. }
  469. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  470. if (zhishui > 0) {
  471. return zhishui;
  472. }
  473. }
  474. if ("yuxiu".equals(ownershipId)) {
  475. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  476. if (yuxiu > 0) {
  477. return yuxiu;
  478. }
  479. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  480. if (ruixuan > 0) {
  481. return ruixuan;
  482. }
  483. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  484. if (mgs > 0) {
  485. return mgs;
  486. }
  487. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  488. if (rocket > 0) {
  489. return rocket;
  490. }
  491. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  492. if (yufu > 0) {
  493. return yufu;
  494. }
  495. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  496. if (zhishui > 0) {
  497. return zhishui;
  498. }
  499. }
  500. if ("zhishui".equals(ownershipId)) {
  501. int zhishui = supplyChainMapper.updateZhishuiOrder(oid, cpsOrderStatus);
  502. if (zhishui > 0) {
  503. return zhishui;
  504. }
  505. int yuxiu = supplyChainMapper.updateYuXiuOrder(oid, cpsOrderStatus);
  506. if (yuxiu > 0) {
  507. return yuxiu;
  508. }
  509. int ruixuan = supplyChainMapper.updateRuixuanOrder(oid, cpsOrderStatus);
  510. if (ruixuan > 0) {
  511. return ruixuan;
  512. }
  513. int mgs = supplyChainMapper.updateMgsOrder(oid, cpsOrderStatus);
  514. if (mgs > 0) {
  515. return mgs;
  516. }
  517. int rocket = supplyChainMapper.updateRocketOrder(oid, cpsOrderStatus);
  518. if (rocket > 0) {
  519. return rocket;
  520. }
  521. int yufu = supplyChainMapper.updateYufuOrder(oid, cpsOrderStatus);
  522. if (yufu > 0) {
  523. return yufu;
  524. }
  525. }
  526. return 0;
  527. }
  528. private Integer updateOrderRegimentalSettleAmount(Long oid, Integer cpsOrderStatus) {
  529. if ("ruixuan".equals(ownershipId)) {
  530. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  531. if (ruixuan > 0) {
  532. return ruixuan;
  533. }
  534. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  535. if (mgs > 0) {
  536. return mgs;
  537. }
  538. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  539. if (rocket > 0) {
  540. return rocket;
  541. }
  542. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  543. if (yufu > 0) {
  544. return yufu;
  545. }
  546. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  547. if (yuxiu > 0) {
  548. return yuxiu;
  549. }
  550. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  551. if (zhishui > 0) {
  552. return zhishui;
  553. }
  554. }
  555. if ("miaogousi".equals(ownershipId)) {
  556. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  557. if (mgs > 0) {
  558. return mgs;
  559. }
  560. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  561. if (ruixuan > 0) {
  562. return ruixuan;
  563. }
  564. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  565. if (rocket > 0) {
  566. return rocket;
  567. }
  568. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  569. if (yufu > 0) {
  570. return yufu;
  571. }
  572. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  573. if (yuxiu > 0) {
  574. return yuxiu;
  575. }
  576. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  577. if (zhishui > 0) {
  578. return zhishui;
  579. }
  580. }
  581. if ("rocket".equals(ownershipId)) {
  582. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  583. if (rocket > 0) {
  584. return rocket;
  585. }
  586. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  587. if (ruixuan > 0) {
  588. return ruixuan;
  589. }
  590. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  591. if (mgs > 0) {
  592. return mgs;
  593. }
  594. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  595. if (yufu > 0) {
  596. return yufu;
  597. }
  598. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  599. if (yuxiu > 0) {
  600. return yuxiu;
  601. }
  602. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  603. if (zhishui > 0) {
  604. return zhishui;
  605. }
  606. }
  607. if ("yufu".equals(ownershipId)) {
  608. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  609. if (yufu > 0) {
  610. return yufu;
  611. }
  612. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  613. if (ruixuan > 0) {
  614. return ruixuan;
  615. }
  616. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  617. if (mgs > 0) {
  618. return mgs;
  619. }
  620. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  621. if (rocket > 0) {
  622. return rocket;
  623. }
  624. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  625. if (yuxiu > 0) {
  626. return yuxiu;
  627. }
  628. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  629. if (zhishui > 0) {
  630. return zhishui;
  631. }
  632. }
  633. if ("yuxiu".equals(ownershipId)) {
  634. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  635. if (yuxiu > 0) {
  636. return yuxiu;
  637. }
  638. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  639. if (ruixuan > 0) {
  640. return ruixuan;
  641. }
  642. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  643. if (mgs > 0) {
  644. return mgs;
  645. }
  646. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  647. if (rocket > 0) {
  648. return rocket;
  649. }
  650. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  651. if (yufu > 0) {
  652. return yufu;
  653. }
  654. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  655. if (zhishui > 0) {
  656. return zhishui;
  657. }
  658. }
  659. if ("zhishui".equals(ownershipId)) {
  660. int zhishui = supplyChainMapper.updateZhishuiOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  661. if (zhishui > 0) {
  662. return zhishui;
  663. }
  664. int ruixuan = supplyChainMapper.updateRuiXuanOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  665. if (ruixuan > 0) {
  666. return ruixuan;
  667. }
  668. int mgs = supplyChainMapper.updateMgsOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  669. if (mgs > 0) {
  670. return mgs;
  671. }
  672. int rocket = supplyChainMapper.updateRocketOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  673. if (rocket > 0) {
  674. return rocket;
  675. }
  676. int yufu = supplyChainMapper.updateYufuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  677. if (yufu > 0) {
  678. return yufu;
  679. }
  680. int yuxiu = supplyChainMapper.updateYuxiuOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  681. if (yuxiu > 0) {
  682. return yuxiu;
  683. }
  684. }
  685. return 0;
  686. }
  687. @Override
  688. public void updateItem(JSONObject eventJSon) {
  689. try {
  690. JSONObject info = eventJSon.getJSONObject("info");
  691. if (!Check.isNull(info)) {
  692. Long itemId = info.getLong("itemId");
  693. Integer status = info.getInteger("status");
  694. supplyChainMapper.updateItem(itemId, status);
  695. log.info("商品id:{},状态:{} 修改成功", itemId, status);
  696. }
  697. } catch (Exception e) {
  698. e.printStackTrace();
  699. }
  700. }
  701. @Override
  702. public void insertOrder(JSONObject eventJSon) {
  703. JSONObject info = eventJSon.getJSONObject("info");
  704. if (!Check.isNull(info)) {
  705. Integer messageType = info.getInteger("messageType");
  706. //新增
  707. if (1 == messageType) {
  708. KuaishouSupplyChain supplyChain = new KuaishouSupplyChain(info);
  709. String ownership = null;
  710. Criteria criteria = new Criteria();
  711. criteria = Criteria.where("_id").is(supplyChain.getItemId());
  712. Query query = new Query(criteria);
  713. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  714. if (!Check.isNull(itemCheck)) {
  715. ownership = itemCheck.getOwnership();
  716. }
  717. // supplyChainMapper.replaceOne(ownership, supplyChain);
  718. supplyChainMapper.replaceOne("rocket", supplyChain);// todo 测试完 删除改行 放开上面 并修改数据表
  719. } //更新
  720. else if (2 == messageType) {
  721. Integer cpsOrderStatus = info.getInteger("cpsOrderStatus");
  722. Long oid = info.getLong("oid");
  723. if (cpsOrderStatus == 60 || cpsOrderStatus == 40) {
  724. // Integer i = updateOrderRegimentalSettleAmount(oid, cpsOrderStatus);
  725. Integer i = updateOrderRegimentalSettleAmountCeshi(oid, cpsOrderStatus);// todo 测试完 删除改行 放开上面
  726. if (i <= 0) {
  727. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  728. }
  729. } else {
  730. Integer i = this.updateOrderStatus(oid, cpsOrderStatus);
  731. if (i <= 0) {
  732. log.error("订单ID:{},状态:{} 修改失败", oid, cpsOrderStatus);
  733. }
  734. }
  735. }
  736. }
  737. }
  738. /*测完删除*/
  739. private Integer updateOrderRegimentalSettleAmountCeshi(Long oid, Integer cpsOrderStatus) {
  740. return supplyChainMapper.updateRocketOrderRegimentalSettleAmountCS(oid, cpsOrderStatus);
  741. }
  742. @Override
  743. public void addList(String beginDate, String endDate, String pcursor) throws InterruptedException {
  744. String url = KuaiShouConstants.KFX_URL;
  745. Long beginTime = DateUtils.getStartLongTime(beginDate);
  746. Long endTime = DateUtils.getEndLongTime(endDate);
  747. // Map<Long, Long> itemMap = getItemMap();
  748. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  749. for (KuaishouAccessToken accessToken : tokens) {
  750. getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  751. }
  752. Thread.sleep(3000);
  753. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  754. for (KuaishouAccessToken accessToken : mgsTokens) {
  755. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  756. }
  757. Thread.sleep(3000);
  758. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  759. for (KuaishouAccessToken accessToken : rocketTokens) {
  760. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  761. }
  762. Thread.sleep(3000);
  763. List<KuaishouAccessToken> yufuTokens = accessTokenService.getYufuTokenInfos();
  764. for (KuaishouAccessToken accessToken : yufuTokens) {
  765. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  766. }
  767. Thread.sleep(3000);
  768. List<KuaishouAccessToken> yuxiuTokens = accessTokenService.getYuxiuTokenInfos();
  769. for (KuaishouAccessToken accessToken : yuxiuTokens) {
  770. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  771. }
  772. Thread.sleep(3000);
  773. List<KuaishouAccessToken> zhishuiTokens = accessTokenService.getZhishuiTokenInfos();
  774. for (KuaishouAccessToken accessToken : zhishuiTokens) {
  775. getZhishuiInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  776. }
  777. }
  778. @Override
  779. public void insertOrderList(Long tokenId, Integer queryType, String beginDate, String endDate) throws Exception {
  780. Long beginTime = DateUtils.getStartLongTime(beginDate);
  781. Long endTime = DateUtils.getEndLongTime(endDate);
  782. KuaishouAccessToken token = accessTokenService.getAccessToken(tokenId);
  783. insertRuixuanOrderList(queryType, token, beginTime, endTime, KuaiShouConstants.KFX_URL, "", 1);
  784. }
  785. public static void main(String[] args) {
  786. Long beginTime = DateUtils.getTimeStamp(DateUtils.getHourTime(-2));
  787. //当前时间
  788. Long endTime = DateUtils.getTimeStamp(DateUtils.getTime());
  789. System.err.println(beginTime);
  790. System.err.println(endTime);
  791. }
  792. @Override
  793. public void insertNowdayOrderList(Long tokenId) throws Exception {
  794. //2小时前 时间戳
  795. Long beginTime = DateUtils.getTimeStamp(DateUtils.getHourTime(-2));
  796. //当前时间
  797. Long endTime = DateUtils.getTimeStamp(DateUtils.getTime());
  798. KuaishouAccessToken token = accessTokenService.getAccessToken(tokenId);
  799. insertRuixuanOrderList(1, token, beginTime, endTime, KuaiShouConstants.KFX_URL, "", 1);
  800. }
  801. private void insertRuixuanOrderList(Integer queryType, KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, int counts) {
  802. try {
  803. List<KuaishouSupplyChain> commonlist = new ArrayList<>();
  804. List<KuaishouSupplyChain> ruixuanList = new ArrayList<>();
  805. List<KuaishouSupplyChain> mgsList = new ArrayList<>();
  806. List<KuaishouSupplyChain> rocketList = new ArrayList<>();
  807. List<KuaishouSupplyChain> yufuList = new ArrayList<>();
  808. List<KuaishouSupplyChain> yuxiuList = new ArrayList<>();
  809. List<KuaishouSupplyChain> zhishuiList = new ArrayList<>();
  810. String appKey = accessToken.getAppKey();
  811. String signSecret = accessToken.getSignSecret();
  812. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  813. return;
  814. }
  815. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  816. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  817. request.setAccessToken(accessToken.getAccessToken());
  818. request.setApiMethodVersion(1L);
  819. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  820. request.setSortType(1);
  821. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  822. request.setQueryType(queryType);
  823. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  824. request.setCpsOrderStatus(0);
  825. request.setDistributorId(0l);
  826. request.setBeginTime(beginTime);
  827. request.setEndTime(endTime);
  828. request.setPcursor(pcursor);
  829. request.setPageize(100);
  830. request.setFundType(1);
  831. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  832. try {
  833. response = client.execute(request);
  834. } catch (KsMerchantApiException e) {
  835. e.printStackTrace();
  836. }
  837. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  838. String code = obj.getString("code");
  839. if ("1".equals(code)) {
  840. JSONObject data = obj.getJSONObject("data");
  841. pcursor = data.getString("pcursor");
  842. JSONArray orderView = data.getJSONArray("orderView");
  843. for (int i = 0; i < orderView.size(); i++) {
  844. JSONObject info = orderView.getJSONObject(i);
  845. KuaishouSupplyChain supplyChain = new KuaishouSupplyChain(info, "1");
  846. String ownership = null;
  847. // Criteria criteria = new Criteria();
  848. // criteria = Criteria.where("_id").is(supplyChain.getItemId());
  849. // Query query = new Query(criteria);
  850. // ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  851. // if (!Check.isNull(itemCheck)) {
  852. // ownership = itemCheck.getOwnership();
  853. // }
  854. if (Check.isNull(ownership)) {
  855. commonlist.add(supplyChain);
  856. } else {
  857. if ("ruixuan".equals(ownership)) {
  858. ruixuanList.add(supplyChain);
  859. } else if ("miaogousi".equals(ownership)) {
  860. mgsList.add(supplyChain);
  861. } else if ("rocket".equals(ownership)) {
  862. rocketList.add(supplyChain);
  863. } else if ("yufu".equals(ownership)) {
  864. yufuList.add(supplyChain);
  865. } else if ("yuxiu".equals(ownership)) {
  866. yuxiuList.add(supplyChain);
  867. } else if ("zhishui".equals(ownership)) {
  868. zhishuiList.add(supplyChain);
  869. }
  870. }
  871. }
  872. } else {
  873. log.error("===查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("msg"));
  874. log.error("游标:{},执行次数:{}", pcursor, counts);
  875. if (counts <= 3) {
  876. insertRuixuanOrderList(queryType, accessToken, beginTime, endTime, url, pcursor, counts + 1);
  877. }
  878. }
  879. //入库操作
  880. if (!Check.isNull(commonlist)) {
  881. supplyChainMapper.replaceBatchOrder(null, commonlist);
  882. }
  883. if (!Check.isNull(ruixuanList)) {
  884. supplyChainMapper.replaceBatchOrder("ruixuan", ruixuanList); //TODO 测试完 修改该方法数据表
  885. }
  886. if (!Check.isNull(mgsList)) {
  887. supplyChainMapper.replaceBatchOrder("miaogousi", mgsList);
  888. }
  889. if (!Check.isNull(rocketList)) {
  890. supplyChainMapper.replaceBatchOrder("rocket", rocketList);
  891. }
  892. if (!Check.isNull(yufuList)) {
  893. supplyChainMapper.replaceBatchOrder("yufu", yufuList);
  894. }
  895. if (!Check.isNull(yuxiuList)) {
  896. supplyChainMapper.replaceBatchOrder("yuxiu", yuxiuList);
  897. }
  898. if (!Check.isNull(zhishuiList)) {
  899. supplyChainMapper.replaceBatchOrder("zhishui", zhishuiList);
  900. }
  901. if (!"nomore".equals(pcursor)) {
  902. insertRuixuanOrderList(queryType, accessToken, beginTime, endTime, url, pcursor, 1);
  903. }
  904. } catch (Exception e) {
  905. e.printStackTrace();
  906. }
  907. }
  908. static ExecutorService insertShopInfoService = Executors.newFixedThreadPool(6);
  909. @Override
  910. public void insertShopInfo(Long tokenId, String bdtype, Integer date) throws Exception {
  911. KuaishouAccessToken token = accessTokenService.getAccessTokenBybd(tokenId, bdtype);
  912. List<JSONObject> list = supplyChainMapper.getAllOid(bdtype, date);
  913. list.forEach(data -> insertShopInfoService.submit(() -> {
  914. try {
  915. insertShopInfo(data, token, KuaiShouConstants.KFX_URL);
  916. } catch (Exception e) {
  917. e.printStackTrace();
  918. }
  919. }));
  920. }
  921. private void insertShopInfo(JSONObject data, KuaishouAccessToken accessToken, String url) {
  922. try {
  923. String appKey = accessToken.getAppKey();
  924. String signSecret = accessToken.getSignSecret();
  925. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  926. return;
  927. }
  928. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  929. OpenDistributionCpsLeaderOrderDetailRequest request = new OpenDistributionCpsLeaderOrderDetailRequest();
  930. request.setAccessToken(accessToken.getAccessToken());
  931. request.setApiMethodVersion(1L);
  932. request.setOid(data.getLong("oid"));
  933. request.setSellerId(data.getLong("seller_id"));
  934. request.setFundType(1);
  935. OpenDistributionCpsLeaderOrderDetailResponse response = null;
  936. try {
  937. response = client.execute(request);
  938. } catch (KsMerchantApiException e) {
  939. e.printStackTrace();
  940. }
  941. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  942. String code = obj.getString("code");
  943. if ("1".equals(code)) {
  944. JSONArray arr = obj.getJSONArray("data");
  945. for (int i = 0; i < arr.size(); i++) {
  946. JSONObject info = arr.getJSONObject(i);
  947. addKuaishouActivityShopInfo(info);
  948. }
  949. }
  950. } catch (Exception e) {
  951. e.printStackTrace();
  952. }
  953. }
  954. private void addKuaishouActivityShopInfo(JSONObject info) {
  955. List<JSONObject> list = new ArrayList<>();
  956. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  957. for (int i = 0; i < cpsOrderProductView.size(); i++) {
  958. JSONObject object = cpsOrderProductView.getJSONObject(i);
  959. list.add(object);
  960. }
  961. if (Check.isNotNull(list) && list.size() > 0) {
  962. supplyChainMapper.replaceBatchShopInfo(list);
  963. }
  964. }
  965. private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  966. List<Long> ruixuanList = new ArrayList<>();
  967. List<Long> mgsList = new ArrayList<>();
  968. List<Long> rocketList = new ArrayList<>();
  969. List<Long> yufuList = new ArrayList<>();
  970. List<Long> yuxiuList = new ArrayList<>();
  971. List<Long> zhishuiList = new ArrayList<>();
  972. String appKey = accessToken.getAppKey();
  973. String signSecret = accessToken.getSignSecret();
  974. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  975. return;
  976. }
  977. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  978. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  979. request.setAccessToken(accessToken.getAccessToken());
  980. request.setApiMethodVersion(1L);
  981. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  982. request.setSortType(1);
  983. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  984. request.setQueryType(2);
  985. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  986. request.setCpsOrderStatus(0);
  987. request.setDistributorId(0l);
  988. request.setBeginTime(beginTime);
  989. request.setEndTime(endTime);
  990. request.setPcursor(pcursor);
  991. request.setPageize(100);
  992. request.setFundType(1);
  993. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  994. try {
  995. response = client.execute(request);
  996. } catch (KsMerchantApiException e) {
  997. e.printStackTrace();
  998. }
  999. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1000. String code = obj.getString("code");
  1001. if ("1".equals(code)) {
  1002. JSONObject data = obj.getJSONObject("data");
  1003. pcursor = data.getString("pcursor");
  1004. JSONArray orderView = data.getJSONArray("orderView");
  1005. for (int i = 0; i < orderView.size(); i++) {
  1006. JSONObject info = orderView.getJSONObject(i);
  1007. Integer sendStatus = info.getInteger("sendStatus");
  1008. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1009. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1010. if (!Check.isNull(cpsOrderProductView)) {
  1011. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1012. Long itemId = itemJson.getLong("itemId");
  1013. Criteria criteria = new Criteria();
  1014. criteria = Criteria.where("_id").is(itemId);
  1015. Query query = new Query(criteria);
  1016. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1017. if (Check.isNull(itemCheck)) {
  1018. ruixuanList.add(info.getLong("oid"));
  1019. }
  1020. if (!Check.isNull(itemCheck)) {
  1021. String ownership = itemCheck.getOwnership();
  1022. if ("ruixuan".equals(ownership)) {
  1023. ruixuanList.add(info.getLong("oid"));
  1024. }
  1025. if ("miaogousi".equals(ownership)) {
  1026. mgsList.add(info.getLong("oid"));
  1027. }
  1028. if ("rocket".equals(ownership)) {
  1029. rocketList.add(info.getLong("oid"));
  1030. }
  1031. if ("yufu".equals(ownership)) {
  1032. yufuList.add(info.getLong("oid"));
  1033. }
  1034. if ("yuxiu".equals(ownership)) {
  1035. yuxiuList.add(info.getLong("oid"));
  1036. }
  1037. if ("zhishui".equals(ownership)) {
  1038. zhishuiList.add(info.getLong("oid"));
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. } else {
  1045. log.error("===查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("msg"));
  1046. log.error("游标:{},执行次数:{}", pcursor, counts);
  1047. if (counts <= 3) {
  1048. getInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1049. }
  1050. }
  1051. if (!Check.isNull(ruixuanList)) {
  1052. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1053. }
  1054. if (!Check.isNull(mgsList)) {
  1055. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1056. }
  1057. if (!Check.isNull(rocketList)) {
  1058. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1059. }
  1060. if (!Check.isNull(yufuList)) {
  1061. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1062. }
  1063. if (!Check.isNull(yuxiuList)) {
  1064. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1065. }
  1066. if (!Check.isNull(zhishuiList)) {
  1067. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1068. }
  1069. if (!"nomore".equals(pcursor)) {
  1070. getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1071. }
  1072. }
  1073. private void getMgsInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1074. List<Long> ruixuanList = new ArrayList<>();
  1075. List<Long> mgsList = new ArrayList<>();
  1076. List<Long> rocketList = new ArrayList<>();
  1077. List<Long> yufuList = new ArrayList<>();
  1078. List<Long> yuxiuList = new ArrayList<>();
  1079. List<Long> zhishuiList = new ArrayList<>();
  1080. String appKey = accessToken.getAppKey();
  1081. String signSecret = accessToken.getSignSecret();
  1082. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1083. return;
  1084. }
  1085. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1086. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1087. request.setAccessToken(accessToken.getAccessToken());
  1088. request.setApiMethodVersion(1L);
  1089. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1090. request.setSortType(1);
  1091. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1092. request.setQueryType(2);
  1093. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1094. request.setCpsOrderStatus(0);
  1095. request.setDistributorId(0l);
  1096. request.setBeginTime(beginTime);
  1097. request.setEndTime(endTime);
  1098. request.setPcursor(pcursor);
  1099. request.setPageize(100);
  1100. request.setFundType(1);
  1101. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1102. try {
  1103. response = client.execute(request);
  1104. } catch (KsMerchantApiException e) {
  1105. e.printStackTrace();
  1106. }
  1107. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1108. String code = obj.getString("code");
  1109. if ("1".equals(code)) {
  1110. JSONObject data = obj.getJSONObject("data");
  1111. pcursor = data.getString("pcursor");
  1112. JSONArray orderView = data.getJSONArray("orderView");
  1113. for (int i = 0; i < orderView.size(); i++) {
  1114. JSONObject info = orderView.getJSONObject(i);
  1115. Integer sendStatus = info.getInteger("sendStatus");
  1116. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1117. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1118. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1119. Long itemId = itemJson.getLong("itemId");
  1120. Criteria criteria = new Criteria();
  1121. criteria = Criteria.where("_id").is(itemId);
  1122. Query query = new Query(criteria);
  1123. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1124. if (Check.isNull(itemCheck)) {
  1125. mgsList.add(info.getLong("oid"));
  1126. }
  1127. if (!Check.isNull(itemCheck)) {
  1128. String ownership = itemCheck.getOwnership();
  1129. if ("ruixuan".equals(ownership)) {
  1130. ruixuanList.add(info.getLong("oid"));
  1131. }
  1132. if ("miaogousi".equals(ownership)) {
  1133. mgsList.add(info.getLong("oid"));
  1134. }
  1135. if ("rocket".equals(ownership)) {
  1136. rocketList.add(info.getLong("oid"));
  1137. }
  1138. if ("yufu".equals(ownership)) {
  1139. yufuList.add(info.getLong("oid"));
  1140. }
  1141. if ("yuxiu".equals(ownership)) {
  1142. yuxiuList.add(info.getLong("oid"));
  1143. }
  1144. if ("zhishui".equals(ownership)) {
  1145. zhishuiList.add(info.getLong("oid"));
  1146. }
  1147. }
  1148. }
  1149. }
  1150. } else {
  1151. log.error("===MGS查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1152. log.error("MGS游标:{},执行次数:{}", pcursor, counts);
  1153. if (counts <= 3) {
  1154. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1155. }
  1156. }
  1157. if (!Check.isNull(ruixuanList)) {
  1158. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1159. }
  1160. if (!Check.isNull(mgsList)) {
  1161. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1162. }
  1163. if (!Check.isNull(rocketList)) {
  1164. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1165. }
  1166. if (!Check.isNull(yufuList)) {
  1167. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1168. }
  1169. if (!Check.isNull(yuxiuList)) {
  1170. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1171. }
  1172. if (!Check.isNull(zhishuiList)) {
  1173. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1174. }
  1175. if (!"nomore".equals(pcursor)) {
  1176. getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1177. }
  1178. }
  1179. private void getRocketInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1180. List<Long> ruixuanList = new ArrayList<>();
  1181. List<Long> mgsList = new ArrayList<>();
  1182. List<Long> rocketList = new ArrayList<>();
  1183. List<Long> yufuList = new ArrayList<>();
  1184. List<Long> yuxiuList = new ArrayList<>();
  1185. List<Long> zhishuiList = new ArrayList<>();
  1186. String appKey = accessToken.getAppKey();
  1187. String signSecret = accessToken.getSignSecret();
  1188. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1189. return;
  1190. }
  1191. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1192. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1193. request.setAccessToken(accessToken.getAccessToken());
  1194. request.setApiMethodVersion(1L);
  1195. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1196. request.setSortType(1);
  1197. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1198. request.setQueryType(2);
  1199. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1200. request.setCpsOrderStatus(0);
  1201. request.setDistributorId(0l);
  1202. request.setBeginTime(beginTime);
  1203. request.setEndTime(endTime);
  1204. request.setPcursor(pcursor);
  1205. request.setPageize(100);
  1206. request.setFundType(1);
  1207. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1208. try {
  1209. response = client.execute(request);
  1210. } catch (KsMerchantApiException e) {
  1211. e.printStackTrace();
  1212. }
  1213. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1214. String code = obj.getString("code");
  1215. if ("1".equals(code)) {
  1216. JSONObject data = obj.getJSONObject("data");
  1217. pcursor = data.getString("pcursor");
  1218. JSONArray orderView = data.getJSONArray("orderView");
  1219. for (int i = 0; i < orderView.size(); i++) {
  1220. JSONObject info = orderView.getJSONObject(i);
  1221. Integer sendStatus = info.getInteger("sendStatus");
  1222. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1223. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1224. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1225. Long itemId = itemJson.getLong("itemId");
  1226. Criteria criteria = new Criteria();
  1227. criteria = Criteria.where("_id").is(itemId);
  1228. Query query = new Query(criteria);
  1229. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1230. if (Check.isNull(itemCheck)) {
  1231. rocketList.add(info.getLong("oid"));
  1232. }
  1233. if (!Check.isNull(itemCheck)) {
  1234. String ownership = itemCheck.getOwnership();
  1235. if ("ruixuan".equals(ownership)) {
  1236. ruixuanList.add(info.getLong("oid"));
  1237. }
  1238. if ("miaogousi".equals(ownership)) {
  1239. mgsList.add(info.getLong("oid"));
  1240. }
  1241. if ("rocket".equals(ownership)) {
  1242. rocketList.add(info.getLong("oid"));
  1243. }
  1244. if ("yufu".equals(ownership)) {
  1245. yufuList.add(info.getLong("oid"));
  1246. }
  1247. if ("yuxiu".equals(ownership)) {
  1248. yuxiuList.add(info.getLong("oid"));
  1249. }
  1250. if ("zhishui".equals(ownership)) {
  1251. zhishuiList.add(info.getLong("oid"));
  1252. }
  1253. }
  1254. }
  1255. }
  1256. } else {
  1257. log.error("===Rocket查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1258. log.error("Rocket游标:{},执行次数:{}", pcursor, counts);
  1259. if (counts <= 3) {
  1260. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1261. }
  1262. }
  1263. if (!Check.isNull(ruixuanList)) {
  1264. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1265. }
  1266. if (!Check.isNull(mgsList)) {
  1267. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1268. }
  1269. if (!Check.isNull(rocketList)) {
  1270. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1271. }
  1272. if (!Check.isNull(yufuList)) {
  1273. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1274. }
  1275. if (!Check.isNull(yuxiuList)) {
  1276. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1277. }
  1278. if (!Check.isNull(zhishuiList)) {
  1279. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1280. }
  1281. if (!"nomore".equals(pcursor)) {
  1282. getRocketInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1283. }
  1284. }
  1285. private void getYufuInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1286. List<Long> ruixuanList = new ArrayList<>();
  1287. List<Long> mgsList = new ArrayList<>();
  1288. List<Long> rocketList = new ArrayList<>();
  1289. List<Long> yufuList = new ArrayList<>();
  1290. List<Long> yuxiuList = new ArrayList<>();
  1291. List<Long> zhishuiList = new ArrayList<>();
  1292. String appKey = accessToken.getAppKey();
  1293. String signSecret = accessToken.getSignSecret();
  1294. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1295. return;
  1296. }
  1297. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1298. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1299. request.setAccessToken(accessToken.getAccessToken());
  1300. request.setApiMethodVersion(1L);
  1301. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1302. request.setSortType(1);
  1303. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1304. request.setQueryType(2);
  1305. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1306. request.setCpsOrderStatus(0);
  1307. request.setDistributorId(0l);
  1308. request.setBeginTime(beginTime);
  1309. request.setEndTime(endTime);
  1310. request.setPcursor(pcursor);
  1311. request.setPageize(100);
  1312. request.setFundType(1);
  1313. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1314. try {
  1315. response = client.execute(request);
  1316. } catch (KsMerchantApiException e) {
  1317. e.printStackTrace();
  1318. }
  1319. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1320. String code = obj.getString("code");
  1321. if ("1".equals(code)) {
  1322. JSONObject data = obj.getJSONObject("data");
  1323. pcursor = data.getString("pcursor");
  1324. JSONArray orderView = data.getJSONArray("orderView");
  1325. for (int i = 0; i < orderView.size(); i++) {
  1326. JSONObject info = orderView.getJSONObject(i);
  1327. Integer sendStatus = info.getInteger("sendStatus");
  1328. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1329. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1330. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1331. Long itemId = itemJson.getLong("itemId");
  1332. Criteria criteria = new Criteria();
  1333. criteria = Criteria.where("_id").is(itemId);
  1334. Query query = new Query(criteria);
  1335. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1336. if (Check.isNull(itemCheck)) {
  1337. yufuList.add(info.getLong("oid"));
  1338. }
  1339. if (!Check.isNull(itemCheck)) {
  1340. String ownership = itemCheck.getOwnership();
  1341. if ("ruixuan".equals(ownership)) {
  1342. ruixuanList.add(info.getLong("oid"));
  1343. }
  1344. if ("miaogousi".equals(ownership)) {
  1345. mgsList.add(info.getLong("oid"));
  1346. }
  1347. if ("rocket".equals(ownership)) {
  1348. rocketList.add(info.getLong("oid"));
  1349. }
  1350. if ("yufu".equals(ownership)) {
  1351. yufuList.add(info.getLong("oid"));
  1352. }
  1353. if ("yuxiu".equals(ownership)) {
  1354. yuxiuList.add(info.getLong("oid"));
  1355. }
  1356. if ("zhishui".equals(ownership)) {
  1357. zhishuiList.add(info.getLong("oid"));
  1358. }
  1359. }
  1360. }
  1361. }
  1362. } else {
  1363. log.error("===yufu查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1364. log.error("yufu游标:{},执行次数:{}", pcursor, counts);
  1365. if (counts <= 3) {
  1366. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1367. }
  1368. }
  1369. if (!Check.isNull(ruixuanList)) {
  1370. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1371. }
  1372. if (!Check.isNull(mgsList)) {
  1373. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1374. }
  1375. if (!Check.isNull(rocketList)) {
  1376. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1377. }
  1378. if (!Check.isNull(yufuList)) {
  1379. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1380. }
  1381. if (!Check.isNull(yuxiuList)) {
  1382. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1383. }
  1384. if (!Check.isNull(zhishuiList)) {
  1385. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1386. }
  1387. if (!"nomore".equals(pcursor)) {
  1388. getYufuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1389. }
  1390. }
  1391. private void getYuxiuInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1392. List<Long> ruixuanList = new ArrayList<>();
  1393. List<Long> mgsList = new ArrayList<>();
  1394. List<Long> rocketList = new ArrayList<>();
  1395. List<Long> yufuList = new ArrayList<>();
  1396. List<Long> yuxiuList = new ArrayList<>();
  1397. List<Long> zhishuiList = new ArrayList<>();
  1398. String appKey = accessToken.getAppKey();
  1399. String signSecret = accessToken.getSignSecret();
  1400. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1401. return;
  1402. }
  1403. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1404. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1405. request.setAccessToken(accessToken.getAccessToken());
  1406. request.setApiMethodVersion(1L);
  1407. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1408. request.setSortType(1);
  1409. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1410. request.setQueryType(2);
  1411. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1412. request.setCpsOrderStatus(0);
  1413. request.setDistributorId(0l);
  1414. request.setBeginTime(beginTime);
  1415. request.setEndTime(endTime);
  1416. request.setPcursor(pcursor);
  1417. request.setPageize(100);
  1418. request.setFundType(1);
  1419. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1420. try {
  1421. response = client.execute(request);
  1422. } catch (KsMerchantApiException e) {
  1423. e.printStackTrace();
  1424. }
  1425. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1426. String code = obj.getString("code");
  1427. if ("1".equals(code)) {
  1428. JSONObject data = obj.getJSONObject("data");
  1429. pcursor = data.getString("pcursor");
  1430. JSONArray orderView = data.getJSONArray("orderView");
  1431. for (int i = 0; i < orderView.size(); i++) {
  1432. JSONObject info = orderView.getJSONObject(i);
  1433. Integer sendStatus = info.getInteger("sendStatus");
  1434. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1435. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1436. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1437. Long itemId = itemJson.getLong("itemId");
  1438. Criteria criteria = new Criteria();
  1439. criteria = Criteria.where("_id").is(itemId);
  1440. Query query = new Query(criteria);
  1441. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1442. if (Check.isNull(itemCheck)) {
  1443. yuxiuList.add(info.getLong("oid"));
  1444. }
  1445. if (!Check.isNull(itemCheck)) {
  1446. String ownership = itemCheck.getOwnership();
  1447. if ("ruixuan".equals(ownership)) {
  1448. ruixuanList.add(info.getLong("oid"));
  1449. }
  1450. if ("miaogousi".equals(ownership)) {
  1451. mgsList.add(info.getLong("oid"));
  1452. }
  1453. if ("rocket".equals(ownership)) {
  1454. rocketList.add(info.getLong("oid"));
  1455. }
  1456. if ("yufu".equals(ownership)) {
  1457. yufuList.add(info.getLong("oid"));
  1458. }
  1459. if ("yuxiu".equals(ownership)) {
  1460. yuxiuList.add(info.getLong("oid"));
  1461. }
  1462. if ("zhishui".equals(ownership)) {
  1463. zhishuiList.add(info.getLong("oid"));
  1464. }
  1465. }
  1466. }
  1467. }
  1468. } else {
  1469. log.error("===yuxiu查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1470. log.error("yuxiu游标:{},执行次数:{}", pcursor, counts);
  1471. if (counts <= 3) {
  1472. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1473. }
  1474. }
  1475. if (!Check.isNull(yuxiuList)) {
  1476. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1477. }
  1478. if (!Check.isNull(ruixuanList)) {
  1479. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1480. }
  1481. if (!Check.isNull(mgsList)) {
  1482. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1483. }
  1484. if (!Check.isNull(rocketList)) {
  1485. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1486. }
  1487. if (!Check.isNull(yufuList)) {
  1488. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1489. }
  1490. if (!Check.isNull(zhishuiList)) {
  1491. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1492. }
  1493. if (!"nomore".equals(pcursor)) {
  1494. getYuxiuInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1495. }
  1496. }
  1497. private void getZhishuiInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
  1498. List<Long> ruixuanList = new ArrayList<>();
  1499. List<Long> mgsList = new ArrayList<>();
  1500. List<Long> rocketList = new ArrayList<>();
  1501. List<Long> yufuList = new ArrayList<>();
  1502. List<Long> yuxiuList = new ArrayList<>();
  1503. List<Long> zhishuiList = new ArrayList<>();
  1504. String appKey = accessToken.getAppKey();
  1505. String signSecret = accessToken.getSignSecret();
  1506. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1507. return;
  1508. }
  1509. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1510. OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
  1511. request.setAccessToken(accessToken.getAccessToken());
  1512. request.setApiMethodVersion(1L);
  1513. //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
  1514. request.setSortType(1);
  1515. //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
  1516. request.setQueryType(2);
  1517. //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
  1518. request.setCpsOrderStatus(0);
  1519. request.setDistributorId(0l);
  1520. request.setBeginTime(beginTime);
  1521. request.setEndTime(endTime);
  1522. request.setPcursor(pcursor);
  1523. request.setPageize(100);
  1524. request.setFundType(1);
  1525. OpenDistributionCpsLeaderOrderCursorListResponse response = null;
  1526. try {
  1527. response = client.execute(request);
  1528. } catch (KsMerchantApiException e) {
  1529. e.printStackTrace();
  1530. }
  1531. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1532. String code = obj.getString("code");
  1533. if ("1".equals(code)) {
  1534. JSONObject data = obj.getJSONObject("data");
  1535. pcursor = data.getString("pcursor");
  1536. JSONArray orderView = data.getJSONArray("orderView");
  1537. for (int i = 0; i < orderView.size(); i++) {
  1538. JSONObject info = orderView.getJSONObject(i);
  1539. Integer sendStatus = info.getInteger("sendStatus");
  1540. if (Check.isNotNull(sendStatus) && sendStatus == 1) {
  1541. JSONArray cpsOrderProductView = info.getJSONArray("cpsOrderProductView");
  1542. JSONObject itemJson = cpsOrderProductView.getJSONObject(0);
  1543. Long itemId = itemJson.getLong("itemId");
  1544. Criteria criteria = new Criteria();
  1545. criteria = Criteria.where("_id").is(itemId);
  1546. Query query = new Query(criteria);
  1547. ItemCheck itemCheck = mongoTemplate.findOne(query, ItemCheck.class);
  1548. if (Check.isNull(itemCheck)) {
  1549. zhishuiList.add(info.getLong("oid"));
  1550. }
  1551. if (!Check.isNull(itemCheck)) {
  1552. String ownership = itemCheck.getOwnership();
  1553. if ("ruixuan".equals(ownership)) {
  1554. ruixuanList.add(info.getLong("oid"));
  1555. }
  1556. if ("miaogousi".equals(ownership)) {
  1557. mgsList.add(info.getLong("oid"));
  1558. }
  1559. if ("rocket".equals(ownership)) {
  1560. rocketList.add(info.getLong("oid"));
  1561. }
  1562. if ("yufu".equals(ownership)) {
  1563. yufuList.add(info.getLong("oid"));
  1564. }
  1565. if ("yuxiu".equals(ownership)) {
  1566. yuxiuList.add(info.getLong("oid"));
  1567. }
  1568. if ("zhishui".equals(ownership)) {
  1569. zhishuiList.add(info.getLong("oid"));
  1570. }
  1571. }
  1572. }
  1573. }
  1574. } else {
  1575. log.error("===zhishui查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("error_msg"));
  1576. log.error("zhishui游标:{},执行次数:{}", pcursor, counts);
  1577. if (counts <= 3) {
  1578. getZhishuiInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
  1579. }
  1580. }
  1581. if (!Check.isNull(zhishuiList)) {
  1582. supplyChainMapper.updateZhishuiKuaishouSupplyChain(zhishuiList);
  1583. }
  1584. if (!Check.isNull(yuxiuList)) {
  1585. supplyChainMapper.updateYuxiuKuaishouSupplyChain(yuxiuList);
  1586. }
  1587. if (!Check.isNull(ruixuanList)) {
  1588. supplyChainMapper.updateKuaishouSupplyChain(ruixuanList);
  1589. }
  1590. if (!Check.isNull(mgsList)) {
  1591. supplyChainMapper.updateMgsKuaishouSupplyChain(mgsList);
  1592. }
  1593. if (!Check.isNull(rocketList)) {
  1594. supplyChainMapper.updateRocketKuaishouSupplyChain(rocketList);
  1595. }
  1596. if (!Check.isNull(yufuList)) {
  1597. supplyChainMapper.updateYufuKuaishouSupplyChain(yufuList);
  1598. }
  1599. if (!"nomore".equals(pcursor)) {
  1600. getZhishuiInfo(accessToken, beginTime, endTime, url, pcursor, 1);
  1601. }
  1602. }
  1603. private KuaishouSupplyChain organizeData(JSONObject jsonObject, Map<Long, Long> itemMap) {
  1604. KuaishouSupplyChain supplyChain = new KuaishouSupplyChain();
  1605. supplyChain.setOid(jsonObject.getLong("oid"));
  1606. JSONObject item = jsonObject.getJSONArray("cpsOrderProductView").getJSONObject(0);
  1607. if (!Check.isNull(item)) {
  1608. supplyChain.setItemId(item.getLong("itemId"));
  1609. supplyChain.setItemTitle(item.getString("itemTitle"));
  1610. supplyChain.setReservePrice(item.getLong("itemPrice"));
  1611. supplyChain.setImageUrl(itemListMapper.getItemImgUrl(item.getLong("itemId")));
  1612. supplyChain.setSellerId(item.getLong("sellerId"));
  1613. }
  1614. supplyChain.setOrderStatus(jsonObject.getInteger("cpsOrderStatus"));
  1615. supplyChain.setOrderCreateTime(jsonObject.getLong("orderCreateTime"));
  1616. supplyChain.setSendStatus(jsonObject.getInteger("sendStatus"));
  1617. supplyChain.setSettlementBizType(jsonObject.getInteger("settlementBizType"));
  1618. supplyChain.setSettlementBizTypeDesc(getSettlementBizTypeDesc(jsonObject.getInteger("settlementBizType")));
  1619. supplyChain.setSendTime(jsonObject.getLong("sendTime"));
  1620. supplyChain.setRecvTime(jsonObject.getLong("recvTime"));
  1621. supplyChain.setPromoterId(jsonObject.getLong("promotionId"));
  1622. supplyChain.setPromoterNickName(jsonObject.getString("promotionNickName"));
  1623. supplyChain.setActivityId(jsonObject.getLong("activityId"));
  1624. supplyChain.setOrderAmount(jsonObject.getLong("payAmount"));
  1625. supplyChain.setPayAmount(jsonObject.getLong("payAmount"));
  1626. supplyChain.setRegimentalPromotionRate(jsonObject.getLong("regimentalPromotionRate"));
  1627. if (!jsonObject.getString("shareRateStr").contains("正在计算中")) {
  1628. supplyChain.setShareRate(jsonObject.getString("shareRateStr"));
  1629. }
  1630. supplyChain.setBaseAmount(jsonObject.getLong("baseAmount"));
  1631. supplyChain.setRegimentalPromotionAmount(jsonObject.getLong("regimentalPromotionAmount") / 1000);
  1632. supplyChain.setTotalRegimentalSettleAmount(jsonObject.getLong("settlementAmount"));
  1633. supplyChain.setStatDate(DateUtils.tempToDate(jsonObject.getLong("orderCreateTime")));
  1634. supplyChain.setItemCommissionRate(itemMap.get(item.getLong("itemId")));
  1635. return supplyChain;
  1636. }
  1637. private String getSettlementBizTypeDesc(Integer settlementBizType) {
  1638. return settlementBizType == 1 ? "快分销" : "聚力计划";
  1639. }
  1640. // 获取订单佣金率
  1641. public Map<Long, Long> getItemMap() {
  1642. Map<Long, Long> returnMap = new HashMap<>();
  1643. List<JSONObject> list = itemListMapper.itemList();
  1644. if (!Check.isNull(list)) {
  1645. for (int i = 0; i < list.size(); i++) {
  1646. JSONObject jsonObject = list.get(i);
  1647. returnMap.put(jsonObject.getLong("itemId"), jsonObject.getLong("itemCommissionRate"));
  1648. }
  1649. }
  1650. return returnMap;
  1651. }
  1652. @Override
  1653. public void addListKuaishouActivityInfo() throws InterruptedException {
  1654. String url = KuaiShouConstants.KFX_URL;
  1655. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  1656. for (KuaishouAccessToken mgsToken : mgsTokens) {
  1657. getMgsInfoKuaishouActivityInfo(mgsToken, url);
  1658. }
  1659. Thread.sleep(3000);
  1660. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  1661. for (KuaishouAccessToken token : rocketTokens) {
  1662. getRocketInfoKuaishouActivityInfo(token, url);
  1663. }
  1664. Thread.sleep(3000);
  1665. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  1666. for (KuaishouAccessToken accessToken : tokens) {
  1667. getInfoKuaishouActivityInfo(accessToken, url);
  1668. }
  1669. Thread.sleep(3000);
  1670. List<KuaishouAccessToken> yufutokens = accessTokenService.getYufuTokenInfos();
  1671. for (KuaishouAccessToken accessToken : yufutokens) {
  1672. getYufuInfoKuaishouActivityInfo(accessToken, url);
  1673. }
  1674. Thread.sleep(3000);
  1675. List<KuaishouAccessToken> yuxiutokens = accessTokenService.getYuxiuTokenInfos();
  1676. for (KuaishouAccessToken accessToken : yuxiutokens) {
  1677. getYuxiuInfoKuaishouActivityInfo(accessToken, url);
  1678. }
  1679. Thread.sleep(3000);
  1680. List<KuaishouAccessToken> zhishuitokens = accessTokenService.getZhishuiTokenInfos();
  1681. for (KuaishouAccessToken accessToken : zhishuitokens) {
  1682. getZhishuiInfoKuaishouActivityInfo(accessToken, url);
  1683. }
  1684. }
  1685. @Override
  1686. public void addKuaishouActivityOpenItemList() throws InterruptedException {
  1687. String url = KuaiShouConstants.KFX_URL;
  1688. List<Long> mgsActivityIds = supplyChainMapper.getMgsKuaishouActivityInfoList();
  1689. List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
  1690. for (KuaishouAccessToken mgsToken : mgsTokens) {
  1691. for (Long activityId : mgsActivityIds) {
  1692. getKuaishouActivityOpenItemList(mgsToken, url, activityId, 1, "miaogousi");
  1693. }
  1694. }
  1695. Thread.sleep(3000);
  1696. List<Long> rocketActivityIds = supplyChainMapper.getRocketKuaishouActivityInfoList();
  1697. List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
  1698. for (KuaishouAccessToken token : rocketTokens) {
  1699. for (Long activityId : rocketActivityIds) {
  1700. getKuaishouActivityOpenItemList(token, url, activityId, 1, "rocket");
  1701. }
  1702. }
  1703. Thread.sleep(3000);
  1704. List<Long> activityIds = supplyChainMapper.getKuaishouActivityInfoList();
  1705. List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
  1706. for (KuaishouAccessToken accessToken : tokens) {
  1707. for (Long activityId : activityIds) {
  1708. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "ruixuan");
  1709. }
  1710. }
  1711. Thread.sleep(3000);
  1712. List<Long> yufuActivityIds = supplyChainMapper.getYufuKuaishouActivityInfoList();
  1713. List<KuaishouAccessToken> yufutokens = accessTokenService.getYufuTokenInfos();
  1714. for (KuaishouAccessToken accessToken : yufutokens) {
  1715. for (Long activityId : yufuActivityIds) {
  1716. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "yufu");
  1717. }
  1718. }
  1719. Thread.sleep(30000);
  1720. List<Long> yuxiuActivityIds = supplyChainMapper.getYuxiuKuaishouActivityInfoList();
  1721. List<KuaishouAccessToken> yuxiutokens = accessTokenService.getYuxiuTokenInfos();
  1722. for (KuaishouAccessToken accessToken : yuxiutokens) {
  1723. for (Long activityId : yuxiuActivityIds) {
  1724. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "yuxiu");
  1725. }
  1726. }
  1727. Thread.sleep(30000);
  1728. List<Long> zhishuiActivityIds = supplyChainMapper.getZhishuiKuaishouActivityInfoList();
  1729. List<KuaishouAccessToken> zhishuitokens = accessTokenService.getZhishuiTokenInfos();
  1730. for (KuaishouAccessToken accessToken : zhishuitokens) {
  1731. for (Long activityId : zhishuiActivityIds) {
  1732. getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "zhishui");
  1733. }
  1734. }
  1735. }
  1736. @Override
  1737. public List<JSONObject> getBytedanceOrderHourDataList(Long date) {
  1738. return supplyChainMapper.getBytedanceOrderHourDataList(date);
  1739. }
  1740. @Override
  1741. public List<JSONObject> getKuaishouOrderHourDataList(Long date) {
  1742. return supplyChainMapper.getKuaishouOrderHourDataList(date);
  1743. }
  1744. @Override
  1745. public List<JSONObject> getTopOrders(Map<String, Object> requestMap) {
  1746. return supplyChainMapper.getTopOrders(requestMap);
  1747. }
  1748. @Override
  1749. public List<JSONObject> exportItemDetail(Map<String, Object> requestMap) {
  1750. return supplyChainMapper.exportItemDetail(requestMap);
  1751. }
  1752. @Override
  1753. public List<JSONObject> getKsChannelGmvHourByDate(List<Long> userList, Integer nowDate, Integer hourType) {
  1754. return supplyChainMapper.getKsChannelGmvHourByDate(userList, nowDate, hourType);
  1755. }
  1756. @Override
  1757. public List<JSONObject> getKsCourtshipGmvHourByDate(List<Long> userList, Integer nowDate, Integer hourType) {
  1758. return supplyChainMapper.getKsCourtshipGmvHourByDate(userList, nowDate, hourType);
  1759. }
  1760. @Override
  1761. public List<JSONObject> getBytedanceChannelGmvHourByDate(List<Long> userList, Long date, Integer hourType) {
  1762. return supplyChainMapper.getBytedanceChannelGmvHourByDate(userList, date, hourType);
  1763. }
  1764. @Override
  1765. public List<JSONObject> getBytedanceCourtshipGmvHourByDate(List<Long> userList, Long data, Integer hourType) {
  1766. return supplyChainMapper.getBytedanceCourtshipGmvHourByDate(userList, data, hourType);
  1767. }
  1768. @Override
  1769. public List<JSONObject> shopList(Map<String, Object> requestMap) {
  1770. return supplyChainMapper.shopList(requestMap);
  1771. }
  1772. @Override
  1773. public List<JSONObject> shopDetail(Map<String, Object> requestMap) {
  1774. return supplyChainMapper.shopDetail(requestMap);
  1775. }
  1776. @Override
  1777. public List<Long> getItemIdsByUserId(Long userId) {
  1778. return supplyChainMapper.getItemIdsByUserId(userId);
  1779. }
  1780. @Override
  1781. public List<Long> getItemIdsByDeptId(Long deptId) {
  1782. return supplyChainMapper.getItemIdsByDeptId(deptId);
  1783. }
  1784. @Override
  1785. public List<JSONObject> getKsChannelGmvHourByDateRoi(List<Long> userList, Integer nowDate, Integer hourType) {
  1786. return supplyChainMapper.getKsChannelGmvHourByDateRoi(userList, nowDate, hourType);
  1787. }
  1788. @Override
  1789. public List<JSONObject> getKsCourtshipGmvHourByDateRoi(List<Long> userList, Integer nowDate, Integer hourType) {
  1790. return supplyChainMapper.getKsCourtshipGmvHourByDateRoi(userList, nowDate, hourType);
  1791. }
  1792. @Override
  1793. public List<JSONObject> getBytedanceChannelGmvHourByDateRoi(List<Long> userList, Long dataNow, Integer hourType) {
  1794. return supplyChainMapper.getBytedanceChannelGmvHourByDateRoi(userList, dataNow, hourType);
  1795. }
  1796. @Override
  1797. public List<JSONObject> getBytedanceCourtshipGmvHourByDateRoi(List<Long> userList, Long dataNow, Integer hourType) {
  1798. return supplyChainMapper.getBytedanceCourtshipGmvHourByDateRoi(userList, dataNow, hourType);
  1799. }
  1800. private void getInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1801. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1802. String appKey = accessToken.getAppKey();
  1803. String signSecret = accessToken.getSignSecret();
  1804. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1805. return;
  1806. }
  1807. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1808. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1809. request.setAccessToken(accessToken.getAccessToken());
  1810. request.setApiMethodVersion(1L);
  1811. //每页活动数量
  1812. request.setLimit(200);
  1813. OpenDistributionInvestmentActivityOpenListResponse response = null;
  1814. try {
  1815. response = client.execute(request);
  1816. } catch (KsMerchantApiException e) {
  1817. e.printStackTrace();
  1818. }
  1819. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1820. String code = obj.getString("code");
  1821. if ("1".equals(code)) {
  1822. JSONObject data = obj.getJSONObject("data");
  1823. JSONArray result = data.getJSONArray("result");
  1824. for (int i = 0; i < result.size(); i++) {
  1825. JSONObject info = result.getJSONObject(i);
  1826. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  1827. list.add(activityInfo);
  1828. }
  1829. } else {
  1830. log.error("===团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,tokenId:{},返回信息:{}", accessToken.getId(), obj.toJSONString());
  1831. return;
  1832. }
  1833. if (Check.isNotNull(list) && list.size() > 0) {
  1834. supplyChainMapper.replaceKuaishouActivityInfo(list);
  1835. }
  1836. }
  1837. private void getKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page, String dbtype) {
  1838. String appKey = accessToken.getAppKey();
  1839. String signSecret = accessToken.getSignSecret();
  1840. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1841. return;
  1842. }
  1843. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1844. OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
  1845. request.setAccessToken(accessToken.getAccessToken());
  1846. request.setApiMethodVersion(1L);
  1847. //每页活动数量
  1848. request.setLimit(200);
  1849. Integer offset = (page - 1) * 200;
  1850. request.setOffset(offset);
  1851. request.setActivityId(activityId);
  1852. OpenDistributionInvestmentActivityOpenItemListResponse response = null;
  1853. try {
  1854. Thread.sleep(1000);
  1855. response = client.execute(request);
  1856. } catch (Exception e) {
  1857. e.printStackTrace();
  1858. }
  1859. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1860. Integer total = null;
  1861. String code = obj.getString("code");
  1862. if ("1".equals(code)) {
  1863. JSONObject data = obj.getJSONObject("data");
  1864. JSONArray result = data.getJSONArray("activityItemDataList");
  1865. total = data.getInteger("total");
  1866. List<Long> itemIds = new ArrayList<>();
  1867. List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
  1868. for (int i = 0; i < result.size(); i++) {
  1869. JSONObject info = result.getJSONObject(i);
  1870. //商品活动审核状态:1-待审核,2-审核通过,3-审核拒绝,5-已失效
  1871. // if (info.getLong("itemAuditStatus") == 1 || info.getLong("itemAuditStatus") == 2) {
  1872. KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
  1873. list.add(activityInfo);
  1874. // }
  1875. //2-审核通过
  1876. if (info.getLong("itemAuditStatus") == 2) {
  1877. itemIds.add(info.getLong("itemId"));
  1878. }
  1879. }
  1880. if (Check.isNotNull(list) && list.size() > 0) {
  1881. if ("ruixuan".equals(dbtype)) {
  1882. supplyChainMapper.replaceKuaiShouActivityOpenItemList(list);
  1883. } else if ("miaogousi".equals(dbtype)) {
  1884. supplyChainMapper.replaceMgsKuaiShouActivityOpenItemList(list);
  1885. } else if ("rocket".equals(dbtype)) {
  1886. supplyChainMapper.replaceRocketKuaiShouActivityOpenItemList(list);
  1887. } else if ("yufu".equals(dbtype)) {
  1888. supplyChainMapper.replaceYufuKuaiShouActivityOpenItemList(list);
  1889. } else if ("yuxiu".equals(dbtype)) {
  1890. supplyChainMapper.replaceYuxiuKuaiShouActivityOpenItemList(list);
  1891. } else if ("zhishui".equals(dbtype)) {
  1892. supplyChainMapper.replaceZhishuiKuaiShouActivityOpenItemList(list);
  1893. }
  1894. }
  1895. List<List<Long>> splits = Lists.newArrayList(Lists.partition(itemIds, 10));
  1896. for (List<Long> itIds : splits) {
  1897. getActivityItemDetail(accessToken, url, activityId, itIds, dbtype);
  1898. }
  1899. } else {
  1900. log.error("===团长招商活动已报名商品列表(open.distribution.investment.activity.open.item.list)失败,tokenId:{},活动ID:{}" +
  1901. "\n返还信息:{}", accessToken.getId(), activityId, obj);
  1902. return;
  1903. }
  1904. if (total - page * 200 > 0) {
  1905. getKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1, dbtype);
  1906. }
  1907. }
  1908. /**
  1909. * open.distribution.investment.activity.item.detail
  1910. * 招商活动商品详情接口
  1911. */
  1912. private void getActivityItemDetail(KuaishouAccessToken accessToken, String url, Long activityId, List<Long> itemIds, String dbtype) {
  1913. List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
  1914. String appKey = accessToken.getAppKey();
  1915. String signSecret = accessToken.getSignSecret();
  1916. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1917. return;
  1918. }
  1919. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1920. OpenDistributionInvestmentActivityItemDetailRequest request = new OpenDistributionInvestmentActivityItemDetailRequest();
  1921. request.setAccessToken(accessToken.getAccessToken());
  1922. request.setApiMethodVersion(1L);
  1923. request.setActivityId(activityId);
  1924. request.setItemId(itemIds);
  1925. OpenDistributionInvestmentActivityItemDetailResponse response = null;
  1926. try {
  1927. response = client.execute(request);
  1928. } catch (KsMerchantApiException e) {
  1929. e.printStackTrace();
  1930. }
  1931. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  1932. String code = obj.getString("code");
  1933. if ("1".equals(code)) {
  1934. JSONArray data = obj.getJSONArray("data");
  1935. for (int i = 0; i < data.size(); i++) {
  1936. JSONObject info = data.getJSONObject(i);
  1937. KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
  1938. list.add(activityInfo);
  1939. }
  1940. if (Check.isNotNull(list) && list.size() > 0) {
  1941. if ("ruixuan".equals(dbtype)) {
  1942. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1943. supplyChainMapper.updateKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1944. }
  1945. } else if ("miaogousi".equals(dbtype)) {
  1946. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1947. supplyChainMapper.updateMgsKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1948. }
  1949. } else if ("rocket".equals(dbtype)) {
  1950. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1951. supplyChainMapper.updateRocketKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1952. }
  1953. } else if ("yufu".equals(dbtype)) {
  1954. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1955. supplyChainMapper.updateYufuKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1956. }
  1957. } else if ("yuxiu".equals(dbtype)) {
  1958. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1959. supplyChainMapper.updateYuxiuKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1960. }
  1961. } else if ("zhishui".equals(dbtype)) {
  1962. for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
  1963. supplyChainMapper.updateZhishuiKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
  1964. }
  1965. }
  1966. }
  1967. } else {
  1968. log.error("===招商活动商品详情接口(open.distribution.investment.activity.item.detail)失败,信息:{}", obj.getString("error_msg"));
  1969. return;
  1970. }
  1971. }
  1972. private KuaiShouActivityInfo organizeKuaishouActivityInfo(JSONObject jsonObject) {
  1973. KuaiShouActivityInfo activityInfo = new KuaiShouActivityInfo();
  1974. activityInfo.setActivityId(jsonObject.getLong("activityId"));
  1975. activityInfo.setRegimentalId(jsonObject.getLong("activityUserId"));
  1976. activityInfo.setActivityTitle(jsonObject.getString("activityTitle"));
  1977. activityInfo.setActivityType(jsonObject.getInteger("activityType"));
  1978. activityInfo.setActivityBeginTime(DateUtils.tempToDate(jsonObject.getLong("activityBeginTime")));
  1979. activityInfo.setActivityEndTime(DateUtils.tempToDate(jsonObject.getLong("activityEndTime")));
  1980. activityInfo.setActivityStatus(jsonObject.getInteger("activityStatus"));
  1981. JSONObject activityItemDataInfo = jsonObject.getJSONObject("activityItemDataView");
  1982. if (!Check.isNull(activityItemDataInfo)) {
  1983. activityInfo.setApplyItemCount(activityItemDataInfo.getInteger("applyItemCount"));
  1984. activityInfo.setWaitAuditItemCount(activityItemDataInfo.getInteger("waitAuditItemCount"));
  1985. activityInfo.setAuditPassItemCount(activityItemDataInfo.getInteger("auditPassItemCount"));
  1986. }
  1987. return activityInfo;
  1988. }
  1989. private void getMgsInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  1990. List<KuaiShouActivityInfo> list = new ArrayList<>();
  1991. String appKey = accessToken.getAppKey();
  1992. String signSecret = accessToken.getSignSecret();
  1993. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  1994. return;
  1995. }
  1996. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  1997. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  1998. request.setAccessToken(accessToken.getAccessToken());
  1999. request.setApiMethodVersion(1L);
  2000. //每页活动数量
  2001. request.setLimit(200);
  2002. OpenDistributionInvestmentActivityOpenListResponse response = null;
  2003. try {
  2004. response = client.execute(request);
  2005. } catch (KsMerchantApiException e) {
  2006. e.printStackTrace();
  2007. }
  2008. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  2009. String code = obj.getString("code");
  2010. if ("1".equals(code)) {
  2011. JSONObject data = obj.getJSONObject("data");
  2012. JSONArray result = data.getJSONArray("result");
  2013. for (int i = 0; i < result.size(); i++) {
  2014. JSONObject info = result.getJSONObject(i);
  2015. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  2016. list.add(activityInfo);
  2017. }
  2018. } else {
  2019. log.error("===团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  2020. return;
  2021. }
  2022. if (Check.isNotNull(list) && list.size() > 0) {
  2023. supplyChainMapper.replaceMgsKuaishouActivityInfo(list);
  2024. }
  2025. }
  2026. private void getRocketInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  2027. List<KuaiShouActivityInfo> list = new ArrayList<>();
  2028. String appKey = accessToken.getAppKey();
  2029. String signSecret = accessToken.getSignSecret();
  2030. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  2031. return;
  2032. }
  2033. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  2034. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  2035. request.setAccessToken(accessToken.getAccessToken());
  2036. request.setApiMethodVersion(1L);
  2037. //每页活动数量
  2038. request.setLimit(200);
  2039. OpenDistributionInvestmentActivityOpenListResponse response = null;
  2040. try {
  2041. response = client.execute(request);
  2042. } catch (KsMerchantApiException e) {
  2043. e.printStackTrace();
  2044. }
  2045. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  2046. String code = obj.getString("code");
  2047. if ("1".equals(code)) {
  2048. JSONObject data = obj.getJSONObject("data");
  2049. JSONArray result = data.getJSONArray("result");
  2050. for (int i = 0; i < result.size(); i++) {
  2051. JSONObject info = result.getJSONObject(i);
  2052. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  2053. list.add(activityInfo);
  2054. }
  2055. } else {
  2056. log.error("===Rocket团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  2057. return;
  2058. }
  2059. if (Check.isNotNull(list) && list.size() > 0) {
  2060. supplyChainMapper.replaceRocketKuaishouActivityInfo(list);
  2061. }
  2062. }
  2063. private void getYufuInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  2064. List<KuaiShouActivityInfo> list = new ArrayList<>();
  2065. String appKey = accessToken.getAppKey();
  2066. String signSecret = accessToken.getSignSecret();
  2067. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  2068. return;
  2069. }
  2070. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  2071. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  2072. request.setAccessToken(accessToken.getAccessToken());
  2073. request.setApiMethodVersion(1L);
  2074. //每页活动数量
  2075. request.setLimit(200);
  2076. OpenDistributionInvestmentActivityOpenListResponse response = null;
  2077. try {
  2078. response = client.execute(request);
  2079. } catch (KsMerchantApiException e) {
  2080. e.printStackTrace();
  2081. }
  2082. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  2083. String code = obj.getString("code");
  2084. if ("1".equals(code)) {
  2085. JSONObject data = obj.getJSONObject("data");
  2086. JSONArray result = data.getJSONArray("result");
  2087. for (int i = 0; i < result.size(); i++) {
  2088. JSONObject info = result.getJSONObject(i);
  2089. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  2090. list.add(activityInfo);
  2091. }
  2092. } else {
  2093. log.error("===Yufu团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  2094. return;
  2095. }
  2096. if (Check.isNotNull(list) && list.size() > 0) {
  2097. supplyChainMapper.replaceYufuKuaishouActivityInfo(list);
  2098. }
  2099. }
  2100. private void getYuxiuInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  2101. List<KuaiShouActivityInfo> list = new ArrayList<>();
  2102. String appKey = accessToken.getAppKey();
  2103. String signSecret = accessToken.getSignSecret();
  2104. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  2105. return;
  2106. }
  2107. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  2108. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  2109. request.setAccessToken(accessToken.getAccessToken());
  2110. request.setApiMethodVersion(1L);
  2111. //每页活动数量
  2112. request.setLimit(200);
  2113. OpenDistributionInvestmentActivityOpenListResponse response = null;
  2114. try {
  2115. response = client.execute(request);
  2116. } catch (KsMerchantApiException e) {
  2117. e.printStackTrace();
  2118. }
  2119. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  2120. String code = obj.getString("code");
  2121. if ("1".equals(code)) {
  2122. JSONObject data = obj.getJSONObject("data");
  2123. JSONArray result = data.getJSONArray("result");
  2124. for (int i = 0; i < result.size(); i++) {
  2125. JSONObject info = result.getJSONObject(i);
  2126. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  2127. list.add(activityInfo);
  2128. }
  2129. } else {
  2130. log.error("===Yuxiu团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  2131. return;
  2132. }
  2133. if (Check.isNotNull(list) && list.size() > 0) {
  2134. supplyChainMapper.replaceYuxiuKuaishouActivityInfo(list);
  2135. }
  2136. }
  2137. private void getZhishuiInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
  2138. List<KuaiShouActivityInfo> list = new ArrayList<>();
  2139. String appKey = accessToken.getAppKey();
  2140. String signSecret = accessToken.getSignSecret();
  2141. if (Check.isNull(signSecret) || Check.isNull(appKey)) {
  2142. return;
  2143. }
  2144. AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
  2145. OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
  2146. request.setAccessToken(accessToken.getAccessToken());
  2147. request.setApiMethodVersion(1L);
  2148. //每页活动数量
  2149. request.setLimit(200);
  2150. OpenDistributionInvestmentActivityOpenListResponse response = null;
  2151. try {
  2152. response = client.execute(request);
  2153. } catch (KsMerchantApiException e) {
  2154. e.printStackTrace();
  2155. }
  2156. JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
  2157. String code = obj.getString("code");
  2158. if ("1".equals(code)) {
  2159. JSONObject data = obj.getJSONObject("data");
  2160. JSONArray result = data.getJSONArray("result");
  2161. for (int i = 0; i < result.size(); i++) {
  2162. JSONObject info = result.getJSONObject(i);
  2163. KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
  2164. list.add(activityInfo);
  2165. }
  2166. } else {
  2167. log.error("===zhishui团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}", obj.getString("msg"));
  2168. return;
  2169. }
  2170. if (Check.isNotNull(list) && list.size() > 0) {
  2171. supplyChainMapper.replaceZhishuiKuaishouActivityInfo(list);
  2172. }
  2173. }
  2174. }