SupplyChainController.java 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809
  1. package com.ruixuan.isc.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.kuaishou.merchant.open.api.KsMerchantApiException;
  4. import com.kuaishou.merchant.open.api.common.utils.PlatformEventSecurityUtil;
  5. import com.ruixuan.common.core.controller.BaseController;
  6. import com.ruixuan.common.core.domain.ResultResponse;
  7. import com.ruixuan.common.core.page.TableDataInfo;
  8. import com.ruixuan.common.utils.Check;
  9. import com.ruixuan.common.utils.DateUtils;
  10. import com.ruixuan.data.utils.ExportExcelUtils;
  11. import com.ruixuan.isc.service.IKuaishouPromoterService;
  12. import com.ruixuan.isc.service.IKuaishouRewardBaseInfoService;
  13. import com.ruixuan.isc.service.IKwaixiaodianOrderCursorListService;
  14. import com.ruixuan.isc.service.ISupplyChainService;
  15. import com.ruixuan.system.service.ISysDeptService;
  16. import com.ruixuan.system.service.ISysUserService;
  17. import io.swagger.annotations.ApiOperation;
  18. import io.swagger.annotations.ApiParam;
  19. import lombok.SneakyThrows;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.beans.factory.annotation.Value;
  23. import org.springframework.web.bind.annotation.GetMapping;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.File;
  34. import java.io.IOException;
  35. import java.io.OutputStream;
  36. import java.io.UnsupportedEncodingException;
  37. import java.text.SimpleDateFormat;
  38. import java.util.ArrayList;
  39. import java.util.Arrays;
  40. import java.util.Collections;
  41. import java.util.HashMap;
  42. import java.util.List;
  43. import java.util.Map;
  44. import java.util.concurrent.ExecutorService;
  45. import java.util.concurrent.Executors;
  46. @RestController
  47. @RequestMapping("/isv/supply_chain")
  48. public class SupplyChainController extends BaseController {
  49. @Autowired
  50. private ISupplyChainService supplyChainService;
  51. @Autowired
  52. private IKwaixiaodianOrderCursorListService orderCursorListService;
  53. @Autowired
  54. private IKuaishouPromoterService promoterService;
  55. @Autowired
  56. private IKuaishouRewardBaseInfoService kuaishouRewardBaseInfoService;
  57. @Value("${accept.ruiXuanPrivateKey}")
  58. private String ruiXuanPrivateKey;
  59. @Value("${accept.rocketPrivateKey}")
  60. private String rocketPrivateKey;
  61. @Value("${accept.dfcPrivateKey}")
  62. private String dfcPrivateKey;
  63. @Value("${accept.mgsPrivateKey2}")
  64. private String mgsPrivateKey2;
  65. @Value("${accept.yufuPrivateKey}")
  66. private String yufuPrivateKey;
  67. @Value("${accept.yuXiuPrivateKey}")
  68. private String yuXiuPrivateKey;
  69. @Value("${accept.zhiShuiPrivateKey}")
  70. private String zhiShuiPrivateKey;
  71. @Value("${ownership.id}")
  72. private String ownershipId;
  73. @GetMapping("/privateKey")
  74. @ApiOperation(value = "达人订单")
  75. public String privateKey() {
  76. return ruiXuanPrivateKey;
  77. }
  78. /**
  79. * 达人订单
  80. *
  81. * @param orderStartDate
  82. * @param orderEndDate
  83. * @param promoterNickName
  84. * @param promoterId
  85. * @return
  86. */
  87. @GetMapping("/orderList")
  88. @ApiOperation(value = "达人订单")
  89. public TableDataInfo orderList(@ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  90. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  91. @ApiParam("达人名称") @RequestParam(value = "promoterNickName", required = false) String promoterNickName,
  92. @ApiParam("达人ID") @RequestParam(value = "promoterId", required = false) Long promoterId) {
  93. Map<String, Object> requestMap = new HashMap<>();
  94. if (!Check.isNull(orderStartDate)) {
  95. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  96. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  97. Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
  98. //下个周期的开始时间
  99. String lastTimeStart = map.get("lastTimeStart");
  100. //下个周期的结束时间
  101. String lastTimeEnd = map.get("lastTimeEnd");
  102. //当前小时
  103. Integer hour = DateUtils.getNowHour();
  104. //当天 yyyy-MM-dd
  105. String today = DateUtils.getNowDateStr();
  106. if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
  107. hour = 23;
  108. }
  109. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  110. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  111. requestMap.put("hour", hour);
  112. }
  113. if (!Check.isNull(orderEndDate)) {
  114. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  115. }
  116. if (!Check.isNull(promoterNickName)) {
  117. requestMap.put("promoterNickName", promoterNickName);
  118. }
  119. if (!Check.isNull(promoterId)) {
  120. requestMap.put("promoterId", promoterId);
  121. }
  122. TableDataInfo dataInfo = new TableDataInfo();
  123. if (Check.isNullMap(requestMap)) {
  124. dataInfo.setCode(-1);
  125. dataInfo.setMsg("入参不能为空");
  126. return dataInfo;
  127. }
  128. startPage();
  129. List<JSONObject> list = supplyChainService.getOrderList(requestMap);
  130. return getDataTable(list);
  131. }
  132. /**
  133. * 达人带货详情
  134. *
  135. * @param promoterId
  136. * @param orderStartDate
  137. * @param orderEndDate
  138. * @param itemTitle
  139. * @param itemId
  140. * @return
  141. */
  142. @GetMapping("/anchorOrderDetail")
  143. @ApiOperation(value = "达人带货详情")
  144. public TableDataInfo anchorOrderDetail(
  145. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  146. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  147. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  148. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  149. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) String itemId) {
  150. Map<String, Object> requestMap = new HashMap<>();
  151. if (!Check.isNull(orderStartDate)) {
  152. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  153. }
  154. if (!Check.isNull(orderEndDate)) {
  155. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  156. }
  157. if (!Check.isNull(promoterId)) {
  158. requestMap.put("promoterId", promoterId);
  159. }
  160. if (!Check.isNull(itemId)) {
  161. requestMap.put("itemId", itemId);
  162. }
  163. if (!Check.isNull(itemTitle)) {
  164. requestMap.put("itemTitle", itemTitle);
  165. }
  166. TableDataInfo dataInfo = new TableDataInfo();
  167. if (Check.isNullMap(requestMap)) {
  168. dataInfo.setCode(-1);
  169. dataInfo.setMsg("入参不能为空");
  170. return dataInfo;
  171. }
  172. startPage();
  173. List<JSONObject> list = supplyChainService.anchorOrderDetail(requestMap);
  174. return getDataTable(list);
  175. }
  176. /**
  177. * 订单统计
  178. *
  179. * @param promoterId
  180. * @param orderStartDate
  181. * @param orderEndDate
  182. * @return
  183. */
  184. @GetMapping("/orderStatistics")
  185. @ApiOperation(value = "订单统计")
  186. public JSONObject orderStatistics(
  187. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  188. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  189. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  190. Map<String, Object> requestMap = new HashMap<>();
  191. if (!Check.isNull(orderStartDate)) {
  192. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  193. }
  194. if (!Check.isNull(orderEndDate)) {
  195. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  196. }
  197. if (!Check.isNull(promoterId)) {
  198. requestMap.put("promoterId", promoterId);
  199. }
  200. JSONObject returnJson = new JSONObject();
  201. if (Check.isNullMap(requestMap)) {
  202. returnJson.put("code", -1);
  203. returnJson.put("message", "入参不能为空");
  204. return returnJson;
  205. }
  206. List<JSONObject> list = supplyChainService.orderStatistics(requestMap);
  207. returnJson.put("code", 0);
  208. returnJson.put("data", list);
  209. return returnJson;
  210. }
  211. /**
  212. * 商品列表
  213. *
  214. * @param itemId
  215. * @param itemTitle
  216. * @param orderStartDate
  217. * @param orderEndDate
  218. * @return
  219. */
  220. @GetMapping("/itemList")
  221. @ApiOperation(value = "商品列表")
  222. public TableDataInfo itemList(
  223. @ApiParam("商品Id") @RequestParam(value = "itemId", required = false) String itemId,
  224. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  225. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  226. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  227. @ApiParam("开始时间") @RequestParam(value = "bindStartDate", required = false) String bindStartDate,
  228. @ApiParam("结束时间") @RequestParam(value = "bindEndDate", required = false) String bindEndDate,
  229. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  230. @ApiParam("排序方式") @RequestParam(value = "sort", required = false) String sort,
  231. @ApiParam("用户ID") @RequestParam(value = "userId", required = false) String userId) {
  232. Map<String, Object> requestMap = new HashMap<>();
  233. if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
  234. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  235. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  236. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  237. Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
  238. //下个周期的开始时间
  239. String lastTimeStart = map.get("lastTimeStart");
  240. //下个周期的结束时间
  241. String lastTimeEnd = map.get("lastTimeEnd");
  242. //当前小时
  243. Integer hour = DateUtils.getNowHour();
  244. //当天 yyyy-MM-dd
  245. String today = DateUtils.getNowDateStr();
  246. if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
  247. hour = 23;
  248. }
  249. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  250. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  251. requestMap.put("hour", hour);
  252. }
  253. if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
  254. requestMap.put("start", DateUtils.strDateToInt(bindStartDate));
  255. requestMap.put("bindStartDate", bindStartDate);
  256. requestMap.put("end", DateUtils.strDateToInt(bindEndDate));
  257. requestMap.put("bindEndDate", bindEndDate);
  258. }
  259. if (!Check.isNull(itemId)) {
  260. requestMap.put("itemId", itemId);
  261. }
  262. if (!Check.isNull(itemTitle)) {
  263. requestMap.put("itemTitle", itemTitle);
  264. }
  265. if (!Check.isNull(userId)) {
  266. requestMap.put("userId", userId);
  267. }
  268. requestMap.put("fieId", fieId);
  269. requestMap.put("sort", sort);
  270. TableDataInfo dataInfo = new TableDataInfo();
  271. if (Check.isNullMap(requestMap)) {
  272. dataInfo.setCode(-1);
  273. dataInfo.setMsg("入参不能为空");
  274. return dataInfo;
  275. }
  276. startPage();
  277. List<JSONObject> list = new ArrayList<>();
  278. if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
  279. list = supplyChainService.itemList(requestMap);
  280. } else if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
  281. list = supplyChainService.itemBindList(requestMap);
  282. }
  283. return getDataTable(list);
  284. }
  285. @PostMapping("/exportOrder")
  286. @ApiOperation(value = "exportOrder")
  287. @ResponseBody
  288. public void exportOrder(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
  289. Map<String, Object> requestMap = new HashMap<>();
  290. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  291. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  292. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  293. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  294. Map<String, String> map = DateUtils.getStartEndTime(requestJson.getString("orderStartDate"), requestJson.getString("orderEndDate"));
  295. //下个周期的开始时间
  296. String lastTimeStart = map.get("lastTimeStart");
  297. //下个周期的结束时间
  298. String lastTimeEnd = map.get("lastTimeEnd");
  299. //当前小时
  300. Integer hour = DateUtils.getNowHour();
  301. //当天 yyyy-MM-dd
  302. String today = DateUtils.getNowDateStr();
  303. if (!(requestJson.getString("orderStartDate").equals(requestJson.getString("orderEndDate")) && requestJson.getString("orderStartDate").equals(today))) {
  304. hour = 23;
  305. }
  306. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  307. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  308. requestMap.put("hour", hour);
  309. }
  310. if (!Check.isNull(requestJson.getString("bindStartDate"))) {
  311. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("bindStartDate")));
  312. requestMap.put("bindStartDate", requestJson.getString("bindStartDate"));
  313. }
  314. if (!Check.isNull(requestJson.getString("bindEndDate"))) {
  315. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("bindEndDate")));
  316. requestMap.put("bindEndDate", requestJson.getString("bindEndDate"));
  317. }
  318. if (!Check.isNull(requestJson.getString("promoterNickName"))) {
  319. requestMap.put("promoterNickName", requestJson.getString("promoterNickName"));
  320. }
  321. if (!Check.isNull(requestJson.getLong("promoterId"))) {
  322. requestMap.put("promoterId", requestJson.getLong("promoterId"));
  323. }
  324. if (!Check.isNull(requestJson.getLong("itemId"))) {
  325. requestMap.put("itemId", requestJson.getLong("itemId"));
  326. }
  327. if (!Check.isNull(requestJson.getString("itemTitle"))) {
  328. requestMap.put("itemTitle", requestJson.getString("itemTitle"));
  329. }
  330. if (!Check.isNull(requestJson.getLong("userId"))) {
  331. requestMap.put("userId", requestJson.getLong("userId"));
  332. }
  333. String[] headers = null;
  334. List<JSONObject> list = new ArrayList<>();
  335. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  336. list = supplyChainService.exportOrder(requestMap);
  337. headers = new String[]{"所属人", "商品ID", "商品名称", "是否预售", "商品封面", "佣金率", "订单数", "订单数环比", "有效订单数", "有效订单率", "发货数", "发货率", "未发货数", "ccr", "小店星级", "店铺物流分", "店铺评分", "店铺服务分", "店铺质量分"};
  338. } else if (!Check.isNull(requestJson.getString("bindStartDate")) && !Check.isNull(requestJson.getString("bindEndDate"))) {
  339. list = supplyChainService.exportBindOrder(requestMap);
  340. headers = new String[]{"所属人", "商品ID", "商品名称", "是否预售", "商品封面", "佣金率", "订单数", "有效订单数", "有效订单率", "发货数", "发货率", "未发货数", "ccr", "小店星级", "店铺物流分", "店铺评分", "店铺服务分", "店铺质量分"};
  341. }
  342. List<List<Object>> exportList = new ArrayList<>();
  343. if (!Check.isNull(list)) {
  344. for (int i = 0; i < list.size(); i++) {
  345. JSONObject date = list.get(i);
  346. List<Object> export = new ArrayList();
  347. export.add(date.getString("userName"));
  348. export.add(date.getLong("itemId"));
  349. export.add(date.getString("itemTitle"));
  350. export.add(date.getString("isPresale"));
  351. export.add(date.getString("imageUrl"));
  352. export.add(date.getString("itemCommissionRate"));
  353. export.add(date.getInteger("orderNum"));
  354. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  355. export.add(date.getString("orderNumRoi"));
  356. }
  357. export.add(date.getInteger("validOrderNUm"));
  358. export.add(date.getString("validRadio"));
  359. export.add(date.getString("deliveryNum"));
  360. export.add(date.getString("deliveryRadio"));
  361. export.add(date.getString("notDeliveryNum"));
  362. export.add(date.getString("ccrValue"));
  363. export.add(date.getString("shopStar"));
  364. export.add(date.getString("mallLogisticsScore"));
  365. export.add(date.getString("shopScore"));
  366. export.add(date.getString("mallServiceScore"));
  367. export.add(date.getString("mallQualityScore"));
  368. exportList.add(export);
  369. }
  370. }
  371. OutputStream os = response.getOutputStream();
  372. ExportExcelUtils eeu = new ExportExcelUtils();
  373. XSSFWorkbook workbook = new XSSFWorkbook();
  374. eeu.exportExcel(workbook, 0, "订单信息", headers, exportList);
  375. this.setResponseHeader(response, "订单信息.xls");
  376. workbook.write(os);
  377. os.flush();
  378. os.close();
  379. }
  380. /**
  381. * 根据商品id获取top达人
  382. *
  383. * @param itemId
  384. * @param orderStartDate
  385. * @param orderEndDate
  386. * @return
  387. */
  388. @GetMapping("/getTopPromoterByItemId")
  389. @ApiOperation(value = "商品列表")
  390. public TableDataInfo getTopPromoterByItemId(
  391. @ApiParam("商品Id") @RequestParam(value = "itemId", required = false) String itemId,
  392. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  393. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  394. Map<String, Object> requestMap = new HashMap<>();
  395. if (!Check.isNull(orderStartDate)) {
  396. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  397. }
  398. if (!Check.isNull(orderEndDate)) {
  399. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  400. }
  401. if (!Check.isNull(itemId)) {
  402. requestMap.put("itemId", itemId);
  403. }
  404. List<JSONObject> list = supplyChainService.getTopPromoterByItemId(requestMap);
  405. return getDataTable(list);
  406. }
  407. /**
  408. * 商品详情
  409. *
  410. * @param itemId
  411. * @param orderStartDate
  412. * @param orderEndDate
  413. * @param promoterId
  414. * @param promoterNickName
  415. * @return
  416. */
  417. @GetMapping("/itemDetail")
  418. @ApiOperation(value = "商品详情")
  419. public TableDataInfo itemDetail(
  420. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) String itemId,
  421. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  422. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  423. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  424. @ApiParam("达人名称") @RequestParam(value = "promoterNickName", required = false) String promoterNickName,
  425. @ApiParam("渠道名称") @RequestParam(value = "userId", required = false) Integer userId
  426. ) {
  427. Map<String, Object> requestMap = new HashMap<>();
  428. if (!Check.isNull(orderStartDate)) {
  429. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  430. }
  431. if (!Check.isNull(orderEndDate)) {
  432. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  433. }
  434. if (!Check.isNull(promoterId)) {
  435. requestMap.put("promoterId", promoterId);
  436. }
  437. if (!Check.isNull(itemId)) {
  438. requestMap.put("itemId", itemId);
  439. }
  440. if (!Check.isNull(promoterNickName)) {
  441. requestMap.put("itemTitle", promoterNickName);
  442. }
  443. if (!Check.isNull(userId)) {
  444. requestMap.put("userId", userId);
  445. }
  446. TableDataInfo dataInfo = new TableDataInfo();
  447. if (Check.isNullMap(requestMap)) {
  448. dataInfo.setCode(-1);
  449. dataInfo.setMsg("入参不能为空");
  450. return dataInfo;
  451. }
  452. startPage();
  453. List<JSONObject> list = supplyChainService.itemDetail(requestMap);
  454. return getDataTable(list);
  455. }
  456. @PostMapping("/exportItemDetail")
  457. @ResponseBody
  458. public void exportItemDetail(
  459. HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson
  460. ) throws IOException {
  461. Map<String, Object> requestMap = new HashMap<>();
  462. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  463. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  464. }
  465. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  466. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  467. }
  468. if (!Check.isNull(requestJson.getLong("promoterId"))) {
  469. requestMap.put("promoterId", requestJson.getLong("promoterId"));
  470. }
  471. if (!Check.isNull(requestJson.getLong("itemId"))) {
  472. requestMap.put("itemId", requestJson.getLong("itemId"));
  473. }
  474. if (!Check.isNull(requestJson.getString("promoterNickName"))) {
  475. requestMap.put("itemTitle", requestJson.getString("promoterNickName"));
  476. }
  477. if (!Check.isNull(requestJson.getLong("userId"))) {
  478. requestMap.put("userId", requestJson.getLong("userId"));
  479. }
  480. List<JSONObject> list = supplyChainService.exportItemDetail(requestMap);
  481. List<List<Object>> exportList = new ArrayList<>();
  482. if (!Check.isNull(list)) {
  483. for (int i = 0; i < list.size(); i++) {
  484. JSONObject data = list.get(i);
  485. List<Object> export = new ArrayList();
  486. export.add(data.getString("userName"));
  487. String promoterNickName = data.getString("promoterNickName");
  488. String promoterId = data.getString("promoterId");
  489. String name = promoterNickName + "(" + promoterId + ")";
  490. export.add(name);
  491. export.add(data.getInteger("orderNum"));
  492. export.add(data.getString("validOrderNUm"));
  493. export.add(data.getString("validRadio"));
  494. export.add(data.getString("deliveryNum"));
  495. export.add(data.getString("shippingGreen"));
  496. export.add(data.getString("effDeliveryNum"));
  497. export.add(data.getString("deliveryRadio"));
  498. export.add(data.getString("notDeliveryNum"));
  499. export.add(data.getInteger("payAmount"));
  500. export.add(data.getString("regimentalPromotionRate"));
  501. exportList.add(export);
  502. }
  503. String[] headers = {"绑定人", "达人信息", "单量", "有效订单数", "有效率", "发货数", "发货率", "有效发货数", "有效发货率", "未发货数", "付款金额", "服务费率"};
  504. OutputStream os = response.getOutputStream();
  505. ExportExcelUtils eeu = new ExportExcelUtils();
  506. XSSFWorkbook workbook = new XSSFWorkbook();
  507. eeu.exportExcel(workbook, 0, "商品出单详情", headers, exportList);
  508. this.setResponseHeader(response, "商品出单详情.xls");
  509. workbook.write(os);
  510. os.flush();
  511. os.close();
  512. }
  513. }
  514. /**
  515. * 产品服务费
  516. *
  517. * @param itemId
  518. * @param itemTitle
  519. * @param orderStartDate
  520. * @param orderEndDate
  521. * @return
  522. */
  523. @GetMapping("/itemServiceCharge")
  524. @ApiOperation(value = "产品服务费")
  525. public TableDataInfo itemServiceCharge(
  526. @ApiParam("商品Id") @RequestParam(value = "itemId", required = false) String itemId,
  527. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  528. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  529. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  530. Map<String, Object> requestMap = new HashMap<>();
  531. if (!Check.isNull(orderStartDate)) {
  532. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  533. }
  534. if (!Check.isNull(orderEndDate)) {
  535. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  536. }
  537. if (!Check.isNull(itemId)) {
  538. requestMap.put("itemId", itemId);
  539. }
  540. if (!Check.isNull(itemTitle)) {
  541. requestMap.put("itemTitle", itemTitle);
  542. }
  543. TableDataInfo dataInfo = new TableDataInfo();
  544. if (Check.isNullMap(requestMap)) {
  545. dataInfo.setCode(-1);
  546. dataInfo.setMsg("入参不能为空");
  547. return dataInfo;
  548. }
  549. startPage();
  550. List<JSONObject> list = supplyChainService.itemServiceCharge(requestMap);
  551. return getDataTable(list);
  552. }
  553. /**
  554. * 首页-订单数据
  555. *
  556. * @param dateType
  557. * @param orderStartDate
  558. * @param orderEndDate
  559. * @return
  560. */
  561. @GetMapping("/indexOrderInfo")
  562. @ApiOperation(value = "首页-订单数据")
  563. public JSONObject orderTotal(
  564. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  565. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  566. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  567. Map<String, Object> requestMap = new HashMap<>();
  568. JSONObject returnJson = new JSONObject();
  569. if (dateType == 0) {
  570. if (!Check.isNull(orderStartDate)) {
  571. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  572. }
  573. if (!Check.isNull(orderEndDate)) {
  574. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  575. }
  576. JSONObject orderTotal = supplyChainService.getOrderTotal(requestMap);
  577. returnJson.put("orderTotal", orderTotal);
  578. Integer hour = DateUtils.getNowHour(); // 当前小时
  579. if (hour >= 0) {
  580. JSONObject ratioJson = new JSONObject();
  581. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate); // 当天开始时间戳
  582. // Long nowEndHourTemp = DateUtils.getNowEndHourTemp(orderStartDate, hour); // 当前结束时间戳
  583. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  584. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日开始时间戳
  585. // Long yesterdayEndHourTemp = DateUtils.getNowEndHourTemp(yesterday, hour); // 昨日结束时间戳
  586. Map<String, Object> ratioMap = new HashMap<>();
  587. ratioMap.put("nowStartHourTemp", nowStartHourTemp);
  588. ratioMap.put("hour", hour);
  589. ratioMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  590. Double ringRatio = supplyChainService.getOrderTotalRatio(ratioMap); //环比
  591. ratioJson.put("ringRatio", ringRatio);
  592. String yearDay = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -6); // 昨日日期
  593. Long yearStartHourTemp = DateUtils.strDateToInt(yearDay); //前7日开始时间戳
  594. // Long yearEndHourTemp = DateUtils.getNowEndHourTemp(yearDay, hour);//前7日结束时间戳
  595. ratioMap.put("yesterdayStartHourTemp", yearStartHourTemp);
  596. Double yearRatio = supplyChainService.getOrderTotalRatio(ratioMap); //同比
  597. ratioJson.put("yearRatio", yearRatio);
  598. returnJson.put("ratio", ratioJson);
  599. }
  600. } else {
  601. if (!Check.isNull(orderStartDate)) {
  602. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  603. }
  604. if (!Check.isNull(orderEndDate)) {
  605. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  606. }
  607. JSONObject orderTotal = supplyChainService.getOrderTotal(requestMap);
  608. returnJson.put("orderTotal", orderTotal);
  609. }
  610. return returnJson;
  611. }
  612. /**
  613. * 首页-金额数据
  614. *
  615. * @param dateType
  616. * @param orderStartDate
  617. * @param orderEndDate
  618. * @return
  619. */
  620. @GetMapping("/indexAmountInfo")
  621. @ApiOperation(value = "首页-金额数据")
  622. public JSONObject indexAmountInfo(
  623. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  624. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  625. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  626. Map<String, Object> requestMap = new HashMap<>();
  627. JSONObject returnJson = new JSONObject();
  628. if (dateType == 0) {
  629. if (!Check.isNull(orderStartDate)) {
  630. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  631. }
  632. if (!Check.isNull(orderEndDate)) {
  633. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  634. }
  635. JSONObject amountTotal = supplyChainService.getAmountTotal(requestMap);
  636. returnJson.put("amountTotal", amountTotal);
  637. Integer hour = DateUtils.getNowHour(); // 当前小时
  638. if (hour >= 0) {
  639. JSONObject amountRatioJson = new JSONObject();
  640. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate); // 当天开始时间
  641. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  642. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日开始时间
  643. Map<String, Object> ratioMap = new HashMap<>();
  644. ratioMap.put("nowStartHourTemp", nowStartHourTemp);
  645. ratioMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  646. ratioMap.put("hour", hour);
  647. Double amountRingRatio = supplyChainService.getAmountTotalRatio(ratioMap); //环比
  648. amountRatioJson.put("amountRingRatio", amountRingRatio);
  649. String yearDay = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -6); // 昨日日期
  650. Long yearStartHourTemp = DateUtils.strDateToInt(yearDay); //前7日开始时间
  651. ratioMap.put("yesterdayStartHourTemp", yearStartHourTemp);
  652. Double amountYearRatio = supplyChainService.getAmountTotalRatio(ratioMap); //同比
  653. amountRatioJson.put("amountYearRatio", amountYearRatio);
  654. returnJson.put("amountRatio", amountRatioJson);
  655. }
  656. } else {
  657. if (!Check.isNull(orderStartDate)) {
  658. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  659. }
  660. if (!Check.isNull(orderEndDate)) {
  661. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  662. }
  663. JSONObject amountTotal = supplyChainService.getAmountTotal(requestMap);
  664. returnJson.put("amountTotal", amountTotal);
  665. }
  666. return returnJson;
  667. }
  668. /**
  669. * 首页-服务费数据
  670. *
  671. * @param dateType
  672. * @param orderStartDate
  673. * @param orderEndDate
  674. * @return
  675. */
  676. @GetMapping("/indexServiceAmountInfo")
  677. @ApiOperation(value = "首页-服务费数据")
  678. public JSONObject indexServiceAmountInfo(
  679. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  680. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  681. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  682. Map<String, Object> requestMap = new HashMap<>();
  683. JSONObject returnJson = new JSONObject();
  684. if (!Check.isNull(orderStartDate)) {
  685. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  686. }
  687. if (!Check.isNull(orderEndDate)) {
  688. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  689. }
  690. JSONObject serviceAmountTotal = supplyChainService.getServiceAmountTotal(requestMap);
  691. returnJson.put("serviceAmountTotal", serviceAmountTotal);
  692. return returnJson;
  693. }
  694. /**
  695. * 首页-商品排行
  696. *
  697. * @param dateType
  698. * @param orderStartDate
  699. * @param orderEndDate
  700. * @return
  701. */
  702. @GetMapping("/indexOrderRank")
  703. @ApiOperation(value = "首页-商品排行")
  704. public TableDataInfo indexOrderRank(
  705. @ApiParam("时间类型") @RequestParam(value = "dateType", required = true) Integer dateType,
  706. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = true) String orderStartDate,
  707. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = true) String orderEndDate,
  708. @ApiParam("媒体,1-抖音;2-快手") @RequestParam(value = "mediaId", required = false) String mediaId) {
  709. Map<String, Object> requestMap = new HashMap<>();
  710. if (dateType == 0) {
  711. if ("1".equals(mediaId)) {
  712. return indexOrderRankBytedance(dateType, orderStartDate, orderEndDate);
  713. } else {
  714. Integer hour = DateUtils.getNowHour(); // 当前小时
  715. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate); // 当天开始时间
  716. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  717. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日开始时间
  718. requestMap.put("nowStartHourTemp", nowStartHourTemp);
  719. requestMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  720. requestMap.put("hour", hour);
  721. startPage();
  722. List<JSONObject> orderRankRatioList = supplyChainService.getOrderRankRatioList(requestMap);
  723. return getDataTable(orderRankRatioList);
  724. }
  725. } else {
  726. if ("1".equals(mediaId)) {
  727. return indexOrderRankBytedance(dateType, orderStartDate, orderEndDate);
  728. } else {
  729. if (!Check.isNull(orderStartDate)) {
  730. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  731. }
  732. if (!Check.isNull(orderEndDate)) {
  733. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  734. }
  735. startPage();
  736. List<JSONObject> orderRankRatioList = supplyChainService.getOrderRankList(requestMap);
  737. return getDataTable(orderRankRatioList);
  738. }
  739. }
  740. }
  741. private TableDataInfo indexOrderRankBytedance(Integer dateType, String orderStartDate, String orderEndDate) {
  742. Map<String, Object> requestMap = new HashMap<>();
  743. if (dateType == 0) {
  744. Integer hour = DateUtils.getNowHour(); // 当前小时
  745. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate);
  746. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  747. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日时间
  748. requestMap.put("nowStartHourTemp", nowStartHourTemp);
  749. requestMap.put("nowEndHourTemp", nowStartHourTemp);
  750. requestMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  751. requestMap.put("yesterdayEndHourTemp", yesterdayStartHourTemp);
  752. requestMap.put("yesterdayEndHourTemp", yesterdayStartHourTemp);
  753. requestMap.put("hour", hour);
  754. startPage();
  755. List<JSONObject> orderRankRatioList = supplyChainService.getOrderRankRatioListBytedance(requestMap);
  756. return getDataTable(orderRankRatioList);
  757. } else {
  758. if (!Check.isNull(orderStartDate)) {
  759. Long start = DateUtils.strDateToInt(orderStartDate);
  760. requestMap.put("start", start);
  761. }
  762. if (!Check.isNull(orderEndDate)) {
  763. Long end = DateUtils.strDateToInt(orderEndDate);
  764. requestMap.put("end", end);
  765. }
  766. startPage();
  767. List<JSONObject> orderRankRatioList = supplyChainService.getOrderRankListBytedance(requestMap);
  768. return getDataTable(orderRankRatioList);
  769. }
  770. }
  771. @GetMapping("/indexPromoterRank")
  772. @ApiOperation(value = "首页-达人排行")
  773. public TableDataInfo indexPromoterRank(
  774. @ApiParam("时间类型") @RequestParam(value = "dateType", required = true) Integer dateType,
  775. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = true) String orderStartDate,
  776. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = true) String orderEndDate,
  777. @ApiParam("userId") @RequestParam(value = "userId", required = false) Long userId,
  778. @ApiParam("媒体,1-抖音;2-快手") @RequestParam(value = "mediaId", required = false) String mediaId
  779. ) {
  780. Map<String, Object> requestMap = new HashMap<>();
  781. if (dateType == 0) {
  782. if ("1".equals(mediaId)) {
  783. return indexPromoterRankBytedance(dateType, orderStartDate, orderEndDate, userId);
  784. } else {
  785. if (Check.isNotNull(userId)) {
  786. List<String> promoterIds = promoterService.selectPromoterIdList(Arrays.asList(userId), mediaId);
  787. if (Check.isNull(promoterIds)) {
  788. return getDataTable(null);
  789. }
  790. requestMap.put("promoterIds", promoterIds);
  791. }
  792. if (!Check.isNull(orderStartDate)) {
  793. Long start = DateUtils.getStartLongTime(orderStartDate); //当天开始时间
  794. requestMap.put("start", start);
  795. }
  796. if (!Check.isNull(orderEndDate)) {
  797. Long end = DateUtils.getEndLongTime(orderEndDate); // 当天结束时间
  798. requestMap.put("end", end);
  799. }
  800. Integer hour = DateUtils.getNowHour(); // 当前小时
  801. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate); // 当天开始时间
  802. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  803. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日开始时间
  804. requestMap.put("nowStartHourTemp", nowStartHourTemp);
  805. requestMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  806. requestMap.put("hour", hour);
  807. startPage();
  808. List<JSONObject> promoterRankRatioList = supplyChainService.getPromoterRankRatioList(requestMap);
  809. return getDataTable(promoterRankRatioList);
  810. }
  811. } else {
  812. if ("1".equals(mediaId)) {
  813. return indexPromoterRankBytedance(dateType, orderStartDate, orderEndDate, userId);
  814. } else {
  815. if (!Check.isNull(orderStartDate)) {
  816. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  817. }
  818. if (!Check.isNull(orderEndDate)) {
  819. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  820. }
  821. startPage();
  822. List<JSONObject> orderRatioList = supplyChainService.getPromoterRatioList(requestMap);
  823. return getDataTable(orderRatioList);
  824. }
  825. }
  826. }
  827. public TableDataInfo indexPromoterRankBytedance(Integer dateType, String orderStartDate, String orderEndDate, Long userId) {
  828. Map<String, Object> requestMap = new HashMap<>();
  829. if (dateType == 0) {
  830. if (Check.isNotNull(userId)) {
  831. List<String> promoterIds = promoterService.selectPromoterIdList(Arrays.asList(userId), "1");
  832. if (Check.isNull(promoterIds)) {
  833. return getDataTable(null);
  834. }
  835. requestMap.put("promoterIds", promoterIds);
  836. }
  837. Integer hour = DateUtils.getNowHour(); // 当前小时
  838. Long nowStartHourTemp = DateUtils.strDateToInt(orderStartDate); // 当天开始时间戳
  839. String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1); // 昨日日期
  840. Long yesterdayStartHourTemp = DateUtils.strDateToInt(yesterday); //昨日开始时间戳
  841. requestMap.put("nowStartHourTemp", nowStartHourTemp);
  842. requestMap.put("nowEndHourTemp", nowStartHourTemp);
  843. requestMap.put("yesterdayStartHourTemp", yesterdayStartHourTemp);
  844. requestMap.put("yesterdayEndHourTemp", yesterdayStartHourTemp);
  845. requestMap.put("yesterdayEndHourTemp", yesterdayStartHourTemp);
  846. requestMap.put("hour", hour);
  847. startPage();
  848. List<JSONObject> promoterRankRatioList = supplyChainService.getPromoterRankRatioListBytedance(requestMap);
  849. return getDataTable(promoterRankRatioList);
  850. } else {
  851. if (!Check.isNull(orderStartDate)) {
  852. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  853. }
  854. if (!Check.isNull(orderEndDate)) {
  855. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  856. }
  857. startPage();
  858. List<JSONObject> orderRatioList = supplyChainService.getPromoterRatioListBytedance(requestMap);
  859. return getDataTable(orderRatioList);
  860. }
  861. }
  862. @PostMapping("/exportPromoterTotal")
  863. @ApiOperation(value = "exportPromoterTotal")
  864. @ResponseBody
  865. public void exportPromoterTotal(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
  866. Map<String, Object> requestMap = new HashMap<>();
  867. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  868. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  869. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  870. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  871. Map<String, String> map = DateUtils.getStartEndTime(requestJson.getString("orderStartDate"), requestJson.getString("orderEndDate"));
  872. //下个周期的开始时间
  873. String lastTimeStart = map.get("lastTimeStart");
  874. //下个周期的结束时间
  875. String lastTimeEnd = map.get("lastTimeEnd");
  876. //当前小时
  877. Integer hour = DateUtils.getNowHour();
  878. //当天 yyyy-MM-dd
  879. String today = DateUtils.getNowDateStr();
  880. if (!(requestJson.getString("orderStartDate").equals(requestJson.getString("orderEndDate")) && requestJson.getString("orderStartDate").equals(today))) {
  881. hour = 23;
  882. }
  883. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  884. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  885. requestMap.put("hour", hour);
  886. }
  887. if (!Check.isNull(requestJson.getString("promoterNickName"))) {
  888. requestMap.put("promoterNickName", requestJson.getString("promoterNickName"));
  889. }
  890. if (!Check.isNull(requestJson.getLong("promoterId"))) {
  891. requestMap.put("promoterId", requestJson.getLong("promoterId"));
  892. }
  893. if (!Check.isNull(requestJson.getLong("itemId"))) {
  894. requestMap.put("itemId", requestJson.getLong("itemId"));
  895. }
  896. if (!Check.isNull(requestJson.getString("itemTitle"))) {
  897. requestMap.put("itemTitle", requestJson.getString("itemTitle"));
  898. }
  899. List<JSONObject> list = supplyChainService.exportPromoterTotal(requestMap);
  900. List<List<Object>> exportList = new ArrayList<>();
  901. if (!Check.isNull(list)) {
  902. for (int i = 0; i < list.size(); i++) {
  903. JSONObject date = list.get(i);
  904. List<Object> export = new ArrayList();
  905. if (ownershipId.equals("miaogousi") || ownershipId.equals("yufu")) {
  906. Long promoterId = date.getLong("promoterId");
  907. export.add(promoterId);
  908. String promoterNickName = date.getString("promoterNickName");
  909. export.add(promoterNickName);
  910. } else {
  911. Long promoterId = date.getLong("promoterId");
  912. String promoterNickName = date.getString("promoterNickName");
  913. String name = promoterNickName + "(" + promoterId + ")";
  914. export.add(name);
  915. }
  916. export.add(date.getInteger("orderNum"));
  917. export.add(date.getString("orderNumRoi"));
  918. export.add(date.getInteger("validOrderNUm"));
  919. export.add(date.getString("validRadio"));
  920. export.add(date.getString("payAmount"));
  921. export.add(date.getString("validPayAmount"));
  922. // export.add(date.getString("regimentalPromotionAmount"));
  923. export.add(date.getString("deliveryNum"));
  924. export.add(date.getString("deliveryRadio"));
  925. export.add(date.getString("notDeliveryNum"));
  926. String userName = supplyChainService.getUserName(date.getLong("promoterId"));
  927. if (!Check.isNull(userName)) {
  928. export.add(userName);
  929. }
  930. /* Map<String, Object> map = new HashMap<>();
  931. map.put("promoterId", promoterId);
  932. map.put("start", DateUtils.getStartLongTime(requestJson.getString("orderStartDate")));
  933. map.put("end", DateUtils.getEndLongTime(requestJson.getString("orderEndDate")));
  934. List<JSONObject> topOrders = supplyChainService.getTopOrders(map);
  935. if (!Check.isNull(topOrders)) {
  936. JSONObject top1 = topOrders.get(0);
  937. StringBuffer top1StringBuffer = new StringBuffer();
  938. top1StringBuffer.append("商品ID:").append(top1.getString("itemId")).append(String.valueOf((char) 10))
  939. .append("出单量:").append(top1.getString("orderNum")).append(String.valueOf((char) 10))
  940. .append("标题:").append(top1.getString("itemTitle")).append(String.valueOf((char) 10))
  941. .append("链接:").append(top1.getString("imageUrl"));
  942. export.add(top1StringBuffer);
  943. }
  944. if (!Check.isNull(topOrders) && topOrders.size() >= 2) {
  945. JSONObject top2 = topOrders.get(1);
  946. if (!Check.isNull(top2)) {
  947. StringBuffer top2StringBuffer = new StringBuffer();
  948. top2StringBuffer.append("商品ID:").append(top2.getString("itemId")).append(String.valueOf((char) 10))
  949. .append("出单量:").append(top2.getString("orderNum")).append(String.valueOf((char) 10))
  950. .append("标题:").append(top2.getString("itemTitle")).append(String.valueOf((char) 10))
  951. .append("链接:").append(top2.getString("imageUrl"));
  952. export.add(top2StringBuffer);
  953. }
  954. }
  955. if (!Check.isNull(topOrders) && topOrders.size() >= 3) {
  956. JSONObject top3 = topOrders.get(2);
  957. if (!Check.isNull(top3)) {
  958. StringBuffer top3StringBuffer = new StringBuffer();
  959. top3StringBuffer.append("商品ID:").append(top3.getString("itemId")).append(String.valueOf((char) 10))
  960. .append("出单量:").append(top3.getString("orderNum")).append(String.valueOf((char) 10))
  961. .append("标题:").append(top3.getString("itemTitle")).append(String.valueOf((char) 10))
  962. .append("链接:").append(top3.getString("imageUrl"));
  963. export.add(top3StringBuffer);
  964. }
  965. }*/
  966. exportList.add(export);
  967. }
  968. }
  969. String[] headers = {};
  970. if (ownershipId.equals("miaogousi") || ownershipId.equals("yufu")) {
  971. headers = new String[]{"达人ID", "达人名称", "订单数", "订单数环比", "有效订单数", "有效订单率", "GVM", "有效GMV", "发货数", "发货率", "未发货数", "绑定人"};
  972. } else {
  973. headers = new String[]{"达人名称", "订单数", "订单数环比", "有效订单数", "有效订单率", "GVM", "有效GMV", "发货数", "发货率", "未发货数", "绑定人"};
  974. }
  975. OutputStream os = response.getOutputStream();
  976. ExportExcelUtils eeu = new ExportExcelUtils();
  977. XSSFWorkbook workbook = new XSSFWorkbook();
  978. eeu.exportExcel(workbook, 0, "达人信息", headers, exportList);
  979. this.setResponseHeader(response, "达人信息.xls");
  980. workbook.write(os);
  981. os.flush();
  982. os.close();
  983. }
  984. @RequestMapping(value = "/exportPromoter")
  985. @ResponseBody
  986. public void exportPromoter(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
  987. Map<String, Object> requestMap = new HashMap<>();
  988. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  989. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  990. }
  991. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  992. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  993. }
  994. if (!Check.isNull(requestJson.getString("promoterNickName"))) {
  995. requestMap.put("promoterNickName", requestJson.getString("promoterNickName"));
  996. }
  997. if (!Check.isNull(requestJson.getLong("promoterId"))) {
  998. requestMap.put("promoterId", requestJson.getLong("promoterId"));
  999. }
  1000. if (!Check.isNull(requestJson.getLong("itemId"))) {
  1001. requestMap.put("itemId", requestJson.getLong("itemId"));
  1002. }
  1003. if (!Check.isNull(requestJson.getString("itemTitle"))) {
  1004. requestMap.put("itemTitle", requestJson.getString("itemTitle"));
  1005. }
  1006. List<JSONObject> list = supplyChainService.exportPromoter(requestMap);
  1007. List<List<Object>> exportList = new ArrayList<>();
  1008. if (!Check.isNull(list)) {
  1009. for (int i = 0; i < list.size(); i++) {
  1010. JSONObject date = list.get(i);
  1011. List<Object> export = new ArrayList();
  1012. String promoterNickName = date.getString("promoterNickName");
  1013. Long promoterId = date.getLong("promoterId");
  1014. Long itemId = date.getLong("itemId");
  1015. String itemTitle = date.getString("itemTitle");
  1016. if ("miaogousi".equals(ownershipId) || "yufu".equals(ownershipId)) {
  1017. export.add(promoterNickName);
  1018. export.add(promoterId);
  1019. export.add(itemTitle);
  1020. export.add(itemId);
  1021. } else {
  1022. String promoter = promoterNickName + "(" + promoterId + ")";
  1023. export.add(promoter);
  1024. String item = itemTitle + "(" + itemId + ")";
  1025. export.add(item);
  1026. }
  1027. export.add(date.getString("imageUrl"));
  1028. export.add(date.getInteger("orderNum"));
  1029. export.add(date.getInteger("validOrderNUm"));
  1030. export.add(date.getString("validRadio"));
  1031. export.add(date.getString("deliveryNum"));
  1032. export.add(date.getString("deliveryRadio"));
  1033. export.add(date.getString("activityItemStatus"));
  1034. exportList.add(export);
  1035. }
  1036. }
  1037. String[] headers = {};
  1038. if ("miaogousi".equals(ownershipId) || "yufu".equals(ownershipId)) {
  1039. headers = new String[]{"达人名称", "达人id", "商品名称", "商品id", "商品封面", "订单数", "有效订单数", "有效订单率", "发货数", "发货率", "商品状态"};
  1040. } else {
  1041. headers = new String[]{"达人", "商品", "商品封面", "订单数", "有效订单数", "有效订单率", "发货数", "发货率", "商品状态"};
  1042. }
  1043. OutputStream os = response.getOutputStream();
  1044. ExportExcelUtils eeu = new ExportExcelUtils();
  1045. XSSFWorkbook workbook = new XSSFWorkbook();
  1046. eeu.exportExcel(workbook, 0, "达人信息", headers, exportList);
  1047. this.setResponseHeader(response, "达人信息.xls");
  1048. workbook.write(os);
  1049. os.flush();
  1050. os.close();
  1051. }
  1052. /**
  1053. * 获取供应链人员列表
  1054. *
  1055. * @return
  1056. */
  1057. @GetMapping("/getSupplyChainUserList")
  1058. @ApiOperation(value = "获取供应链成员列表")
  1059. public TableDataInfo getSupplyChainUserList() {
  1060. List<JSONObject> list = supplyChainService.getSupplyChainUserList();
  1061. return getDataTable(list);
  1062. }
  1063. @GetMapping("/getSupplyChainCourtshipUserList")
  1064. @ApiOperation(value = "获取供应链成员列表")
  1065. public TableDataInfo getSupplyChainCourtshipUserList() {
  1066. List<JSONObject> list = supplyChainService.getSupplyChainCourtshipUserList();
  1067. return getDataTable(list);
  1068. }
  1069. /**
  1070. * 获取商品绑定人员列表
  1071. *
  1072. * @param status
  1073. * @param userId
  1074. * @param itemId
  1075. * @param itemTitle
  1076. * @param activityId
  1077. * @return
  1078. */
  1079. @GetMapping("/bindUserItemList")
  1080. @ApiOperation(value = "商品认领列表")
  1081. public TableDataInfo bindUserItemList(
  1082. @ApiParam("状态") @RequestParam(value = "status", required = false) Integer status,
  1083. @ApiParam("userId") @RequestParam(value = "userId", required = false) Long userId,
  1084. @ApiParam("商品id") @RequestParam(value = "itemId", required = false) Long itemId,
  1085. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  1086. @ApiParam("活动ID") @RequestParam(value = "activityId", required = false) Long activityId
  1087. ) {
  1088. Map<String, Object> requestMap = new HashMap<>();
  1089. if (!Check.isNull(status)) {
  1090. requestMap.put("status", status);
  1091. }
  1092. if (!Check.isNull(userId)) {
  1093. requestMap.put("userId", userId);
  1094. }
  1095. if (!Check.isNull(itemId)) {
  1096. requestMap.put("itemId", itemId);
  1097. }
  1098. if (!Check.isNull(itemTitle)) {
  1099. requestMap.put("itemTitle", itemTitle);
  1100. }
  1101. if (!Check.isNull(activityId)) {
  1102. requestMap.put("activityId", activityId);
  1103. }
  1104. startPage();
  1105. List<JSONObject> list = supplyChainService.bindUserItemList(requestMap);
  1106. return getDataTable(list);
  1107. }
  1108. /**
  1109. * 商品解绑
  1110. *
  1111. * @param itemId
  1112. * @return
  1113. */
  1114. @GetMapping("/unbindUser")
  1115. @ApiOperation(value = "商品解绑")
  1116. public JSONObject unbindUser(
  1117. @ApiParam("商品id") @RequestParam(value = "itemId", required = false) Long itemId) {
  1118. JSONObject returnJson = new JSONObject();
  1119. if (Check.isNull(itemId)) {
  1120. returnJson.put("code", -1);
  1121. returnJson.put("message", "请传入商品ID");
  1122. return returnJson;
  1123. }
  1124. boolean isTrueOrFalse = supplyChainService.unbindUser(itemId);
  1125. if (isTrueOrFalse) {
  1126. returnJson.put("code", 0);
  1127. returnJson.put("message", "解绑成功");
  1128. return returnJson;
  1129. } else {
  1130. returnJson.put("code", -1);
  1131. returnJson.put("message", "解绑失败");
  1132. return returnJson;
  1133. }
  1134. }
  1135. /**
  1136. * 绑定商品
  1137. *
  1138. * @param itemId
  1139. * @return
  1140. */
  1141. @GetMapping("/bindUser")
  1142. @ApiOperation(value = "绑定商品")
  1143. public JSONObject bindUser(
  1144. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) Long itemId,
  1145. @ApiParam("用户ID") @RequestParam(value = "userId", required = false) Long userId,
  1146. @ApiParam("用户名称") @RequestParam(value = "nikeName", required = false) String nikeName) {
  1147. JSONObject returnJson = new JSONObject();
  1148. if (Check.isNull(itemId)) {
  1149. returnJson.put("code", -1);
  1150. returnJson.put("message", "请传入商品ID");
  1151. return returnJson;
  1152. }
  1153. if (Check.isNull("userId")) {
  1154. returnJson.put("code", -1);
  1155. returnJson.put("message", "请传入用户ID");
  1156. return returnJson;
  1157. }
  1158. if (Check.isNull("nikeName")) {
  1159. returnJson.put("code", -1);
  1160. returnJson.put("message", "请传入用户名称");
  1161. return returnJson;
  1162. }
  1163. boolean isTrueOrFalse = supplyChainService.bindUser(itemId, userId, nikeName);
  1164. if (isTrueOrFalse) {
  1165. returnJson.put("code", 0);
  1166. returnJson.put("message", "认领成功");
  1167. return returnJson;
  1168. } else {
  1169. returnJson.put("code", -1);
  1170. returnJson.put("message", "认领失败");
  1171. return returnJson;
  1172. }
  1173. }
  1174. /**
  1175. * 供应链管理员统计列表
  1176. *
  1177. * @param orderStartDate
  1178. * @param orderEndDate
  1179. * @return
  1180. */
  1181. @GetMapping("/adminReportList")
  1182. @ApiOperation(value = "供应链管理员统计列表")
  1183. public TableDataInfo adminReportList(
  1184. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1185. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1186. @ApiParam("结束时间") @RequestParam(value = "bindStartDate", required = false) String bindStartDate,
  1187. @ApiParam("结束时间") @RequestParam(value = "bindEndDate", required = false) String bindEndDate,
  1188. @ApiParam("用户ID") @RequestParam(value = "userId", required = false) Long userId
  1189. ) {
  1190. Map<String, Object> requestMap = new HashMap<>();
  1191. if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
  1192. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  1193. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  1194. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  1195. Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
  1196. //下个周期的开始时间
  1197. String lastTimeStart = map.get("lastTimeStart");
  1198. //下个周期的结束时间
  1199. String lastTimeEnd = map.get("lastTimeEnd");
  1200. //当前小时
  1201. Integer hour = DateUtils.getNowHour();
  1202. //当天 yyyy-MM-dd
  1203. String today = DateUtils.getNowDateStr();
  1204. if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
  1205. hour = 23;
  1206. }
  1207. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  1208. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  1209. requestMap.put("hour", hour);
  1210. }
  1211. if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
  1212. requestMap.put("startDate", bindStartDate);
  1213. requestMap.put("endDate", bindEndDate + " 23:59:59");
  1214. }
  1215. if (!Check.isNull(userId)) {
  1216. requestMap.put("userId", userId);
  1217. }
  1218. TableDataInfo dataInfo = new TableDataInfo();
  1219. if (Check.isNullMap(requestMap)) {
  1220. dataInfo.setCode(-1);
  1221. dataInfo.setMsg("入参不能为空");
  1222. return dataInfo;
  1223. }
  1224. List<JSONObject> list = new ArrayList<>();
  1225. startPage();
  1226. if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
  1227. list = supplyChainService.adminReportList(requestMap);
  1228. } else if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
  1229. list = supplyChainService.adminReportListByBind(requestMap);
  1230. }
  1231. return getDataTable(list);
  1232. }
  1233. @PostMapping("/exportAdminReportList")
  1234. @ApiOperation(value = "供应链管理员统计列表")
  1235. public void exportAdminReportList(
  1236. HttpServletRequest request, HttpServletResponse response,
  1237. @RequestBody JSONObject requestJson
  1238. ) throws IOException {
  1239. Map<String, Object> requestMap = new HashMap<>();
  1240. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  1241. requestMap.put("startDate", requestJson.getString("orderStartDate"));
  1242. requestMap.put("endDate", requestJson.getString("orderEndDate") + " 23:59:59");
  1243. //根据本阶段日期 获取上阶段 开始 和 截至 日期
  1244. Map<String, String> map = DateUtils.getStartEndTime(requestJson.getString("orderStartDate"), requestJson.getString("orderStartDate"));
  1245. //下个周期的开始时间
  1246. String lastTimeStart = map.get("lastTimeStart");
  1247. //下个周期的结束时间
  1248. String lastTimeEnd = map.get("lastTimeEnd");
  1249. //当前小时
  1250. Integer hour = DateUtils.getNowHour();
  1251. //当天 yyyy-MM-dd
  1252. String today = DateUtils.getNowDateStr();
  1253. if (!(requestJson.getString("orderStartDate").equals(requestJson.getString("orderStartDate")) && requestJson.getString("orderStartDate").equals(today))) {
  1254. hour = 23;
  1255. }
  1256. requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
  1257. requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
  1258. requestMap.put("hour", hour);
  1259. }
  1260. if (!Check.isNull(requestJson.getString("bindStartDate"))) {
  1261. Long start = DateUtils.getStartLongTime(requestJson.getString("bindStartDate"));
  1262. requestMap.put("start", start);
  1263. requestMap.put("startDate", requestJson.getString("bindStartDate"));
  1264. }
  1265. if (!Check.isNull(requestJson.getString("bindEndDate"))) {
  1266. Long end = DateUtils.getEndLongTime(requestJson.getString("bindEndDate"));
  1267. requestMap.put("end", end);
  1268. requestMap.put("endDate", requestJson.getString("bindEndDate") + " 23:59:59");
  1269. }
  1270. if (!Check.isNull(requestJson.getString("userId"))) {
  1271. requestMap.put("userId", requestJson.getString("userId"));
  1272. }
  1273. String[] headers = null;
  1274. List<JSONObject> list = new ArrayList<>();
  1275. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  1276. list = supplyChainService.exportAdminReportList(requestMap);
  1277. headers = new String[]{"招商", "商品数", "发样数", "订单数", "订单数环比", "有效订单数", "有效率", "发货数", "未发货数", "发货率", "实付金额", "预估服务费收入", "结算服务费收入", "平均服务费率"};
  1278. } else if (!Check.isNull(requestJson.getString("bindStartDate")) && !Check.isNull(requestJson.getString("bindEndDate"))) {
  1279. list = supplyChainService.exportAdminReportListByBind(requestMap);
  1280. headers = new String[]{"招商", "商品数", "发样数", "订单数", "有效订单数", "有效率", "发货数", "未发货数", "发货率", "实付金额", "预估服务费收入", "结算服务费收入", "平均服务费率"};
  1281. }
  1282. List<List<Object>> exportList = new ArrayList<>();
  1283. if (!Check.isNull(list)) {
  1284. for (int i = 0; i < list.size(); i++) {
  1285. JSONObject date = list.get(i);
  1286. List<Object> export = new ArrayList();
  1287. export.add(date.getString("userName"));
  1288. export.add(date.getString("itemCount"));
  1289. export.add(date.getString("sendSampleCount"));
  1290. export.add(date.getString("orderNum"));
  1291. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  1292. export.add(date.getString("orderNumRoi"));
  1293. }
  1294. export.add(date.getString("validOrderNUm"));
  1295. export.add(date.getString("validRadio"));
  1296. export.add(date.getString("deliveryNum"));
  1297. export.add(date.getString("notDeliveryNum"));
  1298. export.add(date.getString("deliveryRadio"));
  1299. export.add(date.getString("payAmount"));
  1300. export.add(date.getString("regimentalPromotionAmount"));
  1301. export.add(date.getString("totalRegimentalSettleAmount"));
  1302. export.add(date.getString("avgServiceRate"));
  1303. exportList.add(export);
  1304. }
  1305. }
  1306. OutputStream os = response.getOutputStream();
  1307. ExportExcelUtils eeu = new ExportExcelUtils();
  1308. XSSFWorkbook workbook = new XSSFWorkbook();
  1309. eeu.exportExcel(workbook, 0, "订单信息", headers, exportList);
  1310. this.setResponseHeader(response, "订单信息.xls");
  1311. workbook.write(os);
  1312. os.flush();
  1313. os.close();
  1314. }
  1315. /**
  1316. * 认领商品列表
  1317. *
  1318. * @param userId
  1319. * @param orderStartDate
  1320. * @param orderEndDate
  1321. * @param itemId
  1322. * @param itemTitle
  1323. * @return
  1324. */
  1325. @GetMapping("/userItemDetail")
  1326. @ApiOperation(value = "认领商品列表")
  1327. public TableDataInfo userItemDetail(
  1328. @ApiParam("userId") @RequestParam(value = "userId", required = false) Long userId,
  1329. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1330. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1331. @ApiParam("商品Id") @RequestParam(value = "itemId", required = false) Long itemId,
  1332. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  1333. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  1334. @ApiParam("排序方式") @RequestParam(value = "sort", required = false) String sort
  1335. ) {
  1336. Map<String, Object> requestMap = new HashMap<>();
  1337. if (!Check.isNull(userId)) {
  1338. requestMap.put("userId", userId);
  1339. }
  1340. if (!Check.isNull(orderStartDate)) {
  1341. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  1342. }
  1343. if (!Check.isNull(orderEndDate)) {
  1344. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  1345. }
  1346. if (!Check.isNull(itemId)) {
  1347. requestMap.put("itemId", itemId);
  1348. }
  1349. if (!Check.isNull(itemTitle)) {
  1350. requestMap.put("itemTitle", itemTitle);
  1351. }
  1352. requestMap.put("fieId", fieId);
  1353. requestMap.put("sort", sort);
  1354. TableDataInfo dataInfo = new TableDataInfo();
  1355. if (Check.isNullMap(requestMap)) {
  1356. dataInfo.setCode(-1);
  1357. dataInfo.setMsg("入参不能为空");
  1358. return dataInfo;
  1359. }
  1360. startPage();
  1361. List<JSONObject> list = supplyChainService.userItemDetail(requestMap);
  1362. return getDataTable(list);
  1363. }
  1364. /**
  1365. * 认领商品列表导出
  1366. *
  1367. * @return
  1368. */
  1369. @PostMapping("/exportUserItemDetail")
  1370. @ApiOperation(value = "认领商品列表")
  1371. @ResponseBody
  1372. public void exportUserItemDetail(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  1373. Map<String, Object> requestMap = new HashMap<>();
  1374. if (!Check.isNull(requestJson.getLong("userId"))) {
  1375. requestMap.put("userId", requestJson.getLong("userId"));
  1376. }
  1377. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  1378. Long start = DateUtils.strDateToInt(requestJson.getString("orderStartDate"));
  1379. requestMap.put("start", start);
  1380. }
  1381. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  1382. Long end = DateUtils.strDateToInt(requestJson.getString("orderEndDate"));
  1383. requestMap.put("end", end);
  1384. }
  1385. if (!Check.isNull(requestJson.getLong("itemId"))) {
  1386. requestMap.put("itemId", requestJson.getLong("itemId"));
  1387. }
  1388. if (!Check.isNull(requestJson.getString("itemTitle"))) {
  1389. requestMap.put("itemTitle", requestJson.getString("itemTitle"));
  1390. }
  1391. List<JSONObject> list = supplyChainService.exportUserItemDetail(requestMap);
  1392. List<List<Object>> exportList = new ArrayList<>();
  1393. if (!Check.isNull(list)) {
  1394. for (int i = 0; i < list.size(); i++) {
  1395. JSONObject date = list.get(i);
  1396. List<Object> export = new ArrayList();
  1397. export.add(date.getString("userName"));
  1398. export.add(date.getLong("itemId"));
  1399. export.add(date.getString("itemTitle"));
  1400. export.add(date.getString("reservePrice"));
  1401. export.add(date.getString("itemCommissionRate"));
  1402. export.add(date.getString("orderNum"));
  1403. export.add(date.getString("validOrderNUm"));
  1404. export.add(date.getString("validRadio"));
  1405. export.add(date.getString("invalidOrderNUm"));
  1406. export.add(date.getString("deliveryNum"));
  1407. export.add(date.getString("deliveryRadio"));
  1408. export.add(date.getString("notDeliveryNum"));
  1409. export.add(date.getString("payAmount"));
  1410. export.add(date.getString("regimentalPromotionRate"));
  1411. export.add(date.getString("regimentalPromotionAmount"));
  1412. export.add(date.getString("totalRegimentalSettleAmount"));
  1413. export.add(date.getString("imageUrl"));
  1414. export.add(date.getString("ccrValue"));
  1415. exportList.add(export);
  1416. }
  1417. }
  1418. String[] headers = {"所属人", "商品ID", "商品名称", "商品单价", "佣金率", "订单数", "有效订单数", "有效订单率", "失效订单数", "发货数", "发货率", "未发货数", "付款金额", "服务费率", "预估服务费收入", "结算服务费收入", "商品封面", "ccr"};
  1419. OutputStream os = response.getOutputStream();
  1420. ExportExcelUtils eeu = new ExportExcelUtils();
  1421. XSSFWorkbook workbook = new XSSFWorkbook();
  1422. eeu.exportExcel(workbook, 0, "认领列表", headers, exportList);
  1423. this.setResponseHeader(response, "认领列表.xls");
  1424. workbook.write(os);
  1425. os.flush();
  1426. os.close();
  1427. }
  1428. @GetMapping("/userItemTotal")
  1429. @ApiOperation(value = "认领商品列表汇总")
  1430. public JSONObject userItemTotal(
  1431. @ApiParam("userId") @RequestParam(value = "userId", required = false) Long userId,
  1432. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1433. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate
  1434. ) {
  1435. Map<String, Object> requestMap = new HashMap<>();
  1436. if (!Check.isNull(userId)) {
  1437. requestMap.put("userId", userId);
  1438. }
  1439. if (!Check.isNull(orderStartDate)) {
  1440. Long start = DateUtils.strDateToInt(orderStartDate);
  1441. requestMap.put("start", start);
  1442. }
  1443. if (!Check.isNull(orderEndDate)) {
  1444. Long end = DateUtils.strDateToInt(orderEndDate);
  1445. requestMap.put("end", end);
  1446. }
  1447. JSONObject returnJson = supplyChainService.userItemTotal(requestMap);
  1448. return returnJson;
  1449. }
  1450. /**
  1451. * 商品认领汇总
  1452. *
  1453. * @return
  1454. */
  1455. @GetMapping("/itemBindSummary")
  1456. @ApiOperation(value = "商品认领汇总")
  1457. public JSONObject itemBindSummary() {
  1458. JSONObject json = supplyChainService.itemBindSummary();
  1459. return json;
  1460. }
  1461. /**
  1462. * 首页-时段对比
  1463. *
  1464. * @param orderStartDate
  1465. * @param orderEndDate
  1466. * @return
  1467. */
  1468. @SneakyThrows
  1469. @GetMapping("/indexTimeIntervalRatio")
  1470. @ApiOperation(value = "首页-时段对比")
  1471. public JSONObject indexTimeIntervalRatio(
  1472. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1473. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate) {
  1474. Map<String, Object> requestMap = new HashMap<>();
  1475. String nowDate = DateUtils.getNowDateStr();
  1476. String thisCycleEnd = null; // 当前时段结束日期
  1477. String thisCycleStart = null; // 当前时段开始日期
  1478. String lastCycleEnd = null; // 上一时段结束日期
  1479. String lastCycleStart = null; // 上一时段开始日期
  1480. if (nowDate.equals(orderStartDate) && nowDate.equals(orderEndDate)) {
  1481. thisCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
  1482. thisCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", thisCycleEnd, -6);
  1483. lastCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", thisCycleStart, -1);
  1484. lastCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", lastCycleEnd, -6);
  1485. } else {
  1486. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1487. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(orderStartDate), simpleDateFormat.parse(orderEndDate));
  1488. thisCycleEnd = orderEndDate;
  1489. thisCycleStart = orderStartDate;
  1490. lastCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1);
  1491. lastCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", lastCycleEnd, -differDay);
  1492. }
  1493. if (!Check.isNull(thisCycleStart)) {
  1494. Long thisCycleStartTemp = DateUtils.strDateToInt(thisCycleStart);
  1495. requestMap.put("thisCycleStartTemp", thisCycleStartTemp);
  1496. }
  1497. if (!Check.isNull(thisCycleEnd)) {
  1498. Long thisCycleEndTemp = DateUtils.strDateToInt(thisCycleEnd);
  1499. requestMap.put("thisCycleEndTemp", thisCycleEndTemp);
  1500. }
  1501. if (!Check.isNull(lastCycleStart)) {
  1502. Long lastCycleStartTemp = DateUtils.strDateToInt(lastCycleStart);
  1503. requestMap.put("lastCycleStartTemp", lastCycleStartTemp);
  1504. }
  1505. if (!Check.isNull(lastCycleEnd)) {
  1506. Long lastCycleEndTemp = DateUtils.strDateToInt(lastCycleEnd);
  1507. requestMap.put("lastCycleEndTemp", lastCycleEndTemp);
  1508. }
  1509. JSONObject timeIntervalRatioJson = supplyChainService.getTimeIntervalRatio(requestMap);
  1510. return timeIntervalRatioJson;
  1511. }
  1512. /**
  1513. * 首页-统计图
  1514. *
  1515. * @param orderStartDate
  1516. * @param orderEndDate
  1517. * @param type
  1518. * @return
  1519. */
  1520. @GetMapping("/indexStatistics")
  1521. @ApiOperation(value = "首页-统计图")
  1522. public List<JSONObject> indexStatistics(
  1523. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1524. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1525. @ApiParam("类型") @RequestParam(value = "type", required = false) String type) {
  1526. Map<String, Object> requestMap = new HashMap<>();
  1527. String nowDate = DateUtils.getNowDateStr();
  1528. String start = null;
  1529. String end = null;
  1530. if (nowDate.equals(orderStartDate) && nowDate.equals(orderEndDate)) {
  1531. end = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
  1532. start = DateUtils.getAnotherDay("yyyy-MM-dd", end, -6);
  1533. } else {
  1534. start = orderStartDate;
  1535. end = orderEndDate;
  1536. }
  1537. if (!Check.isNull(start)) {
  1538. Long startTemp = DateUtils.strDateToInt(start);
  1539. requestMap.put("startTemp", startTemp);
  1540. }
  1541. if (!Check.isNull(end)) {
  1542. Long endTemp = DateUtils.strDateToInt(end);
  1543. requestMap.put("endTemp", endTemp);
  1544. }
  1545. if (!Check.isNull(type)) {
  1546. requestMap.put("type", type);
  1547. }
  1548. List<JSONObject> list = supplyChainService.indexStatistics(requestMap);
  1549. return list;
  1550. }
  1551. //发送响应流方法
  1552. public void setResponseHeader(HttpServletResponse response, String fileName) {
  1553. try {
  1554. try {
  1555. fileName = new String(fileName.getBytes(), "ISO8859-1");
  1556. } catch (UnsupportedEncodingException e) {
  1557. e.printStackTrace();
  1558. }
  1559. response.setContentType("application/octet-stream;charset=ISO8859-1");
  1560. response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
  1561. response.addHeader("Pargam", "no-cache");
  1562. response.addHeader("Cache-Control", "no-cache");
  1563. } catch (Exception ex) {
  1564. ex.printStackTrace();
  1565. }
  1566. }
  1567. @GetMapping("/bdReportList")
  1568. @ApiOperation(value = "供应链管理员统计列表")
  1569. public TableDataInfo bdReportList(
  1570. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1571. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1572. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId) {
  1573. Map<String, Object> requestMap = new HashMap<>();
  1574. if (!Check.isNull(orderStartDate)) {
  1575. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1576. requestMap.put("start", start);
  1577. }
  1578. if (!Check.isNull(orderEndDate)) {
  1579. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1580. requestMap.put("end", end);
  1581. }
  1582. if (!Check.isNull(collectSampleId)) {
  1583. requestMap.put("collectSampleId", collectSampleId);
  1584. }
  1585. TableDataInfo dataInfo = new TableDataInfo();
  1586. if (Check.isNullMap(requestMap)) {
  1587. dataInfo.setCode(500);
  1588. dataInfo.setMsg("入参不能为空");
  1589. return dataInfo;
  1590. }
  1591. startPage();
  1592. List<JSONObject> list = supplyChainService.bdReportList(requestMap);
  1593. return getDataTable(list);
  1594. }
  1595. @PostMapping("/exportBdReportList")
  1596. @ApiOperation(value = "供应链管理员统计列表")
  1597. @ResponseBody
  1598. public void exportBdReportList(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  1599. Map<String, Object> requestMap = new HashMap<>();
  1600. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  1601. Integer start = DateUtils.getIntegerTime(requestJson.getString("orderStartDate"));
  1602. requestMap.put("start", start);
  1603. }
  1604. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  1605. Integer end = DateUtils.getIntegerTime(requestJson.getString("orderEndDate"));
  1606. requestMap.put("end", end);
  1607. }
  1608. if (!Check.isNull(requestJson.getLong("collectSampleId"))) {
  1609. requestMap.put("collectSampleId", requestJson.getLong("collectSampleId"));
  1610. }
  1611. List<JSONObject> list = supplyChainService.exportBdReportList(requestMap);
  1612. List<List<Object>> exportList = new ArrayList<>();
  1613. if (!Check.isNull(list)) {
  1614. for (int i = 0; i < list.size(); i++) {
  1615. JSONObject date = list.get(i);
  1616. List<Object> export = new ArrayList();
  1617. export.add(date.getString("collectSampleId"));
  1618. export.add(date.getString("collectSampleName"));
  1619. export.add(date.getString("promoterCount"));
  1620. export.add(date.getString("sampleCount"));
  1621. export.add(date.getString("sampleRate"));
  1622. export.add(date.getString("notSampleCount"));
  1623. export.add(date.getString("sendTotalCount"));
  1624. export.add(date.getString("sendPromoterCount"));
  1625. export.add(date.getString("sendItemCount"));
  1626. export.add(date.getString("orderNum"));
  1627. export.add(date.getString("voucherOrderNum"));
  1628. export.add(date.getString("validOrderNum"));
  1629. export.add(date.getString("voucherValidOrderNum"));
  1630. export.add(date.getString("validOrderRate"));
  1631. export.add(date.getString("orderAmount"));
  1632. export.add(date.getString("voucherOrderAmount"));
  1633. export.add(date.getString("regimentalPromotionAmount"));
  1634. export.add(date.getString("voucherRegimentalPromotionAmount"));
  1635. export.add(date.getString("totalRegimentalSettleAmount"));
  1636. export.add(date.getString("voucherTotalRegimentalSettleAmount"));
  1637. exportList.add(export);
  1638. }
  1639. }
  1640. String[] headers = {"渠道ID", "渠道姓名", "(总)达人数", "(总)领样达人数", "(总)领样率", "(总)未领样数", "发样数", "发样达人数", "发样商品数", "订单数", "(凭)订单数", "有效订单数", "(凭)有效订单数", "有效订单率", "订单金额", "凭(订单金额)", "预估服务费", "(凭)预估服务费", "结算服务费", "(凭)结算服务费"};
  1641. OutputStream os = response.getOutputStream();
  1642. ExportExcelUtils eeu = new ExportExcelUtils();
  1643. XSSFWorkbook workbook = new XSSFWorkbook();
  1644. eeu.exportExcel(workbook, 0, "bd业绩汇总", headers, exportList);
  1645. this.setResponseHeader(response, "bd业绩汇总.xls");
  1646. workbook.write(os);
  1647. os.flush();
  1648. os.close();
  1649. }
  1650. @GetMapping("/bdDetailList")
  1651. @ApiOperation(value = "供应链管理员统计列表")
  1652. public TableDataInfo bdDetailList(
  1653. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1654. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1655. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId,
  1656. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  1657. @ApiParam("排序放肆") @RequestParam(value = "sort", required = false) String sort) {
  1658. Map<String, Object> requestMap = new HashMap<>();
  1659. if (!Check.isNull(orderStartDate)) {
  1660. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1661. requestMap.put("start", start);
  1662. }
  1663. if (!Check.isNull(orderEndDate)) {
  1664. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1665. requestMap.put("end", end);
  1666. }
  1667. if (!Check.isNull(collectSampleId)) {
  1668. requestMap.put("collectSampleId", collectSampleId);
  1669. }
  1670. requestMap.put("fieId", fieId);
  1671. requestMap.put("sort", sort);
  1672. TableDataInfo dataInfo = new TableDataInfo();
  1673. if (Check.isNullMap(requestMap)) {
  1674. dataInfo.setCode(500);
  1675. dataInfo.setMsg("入参不能为空");
  1676. return dataInfo;
  1677. }
  1678. startPage();
  1679. List<JSONObject> list = supplyChainService.bdDetailList(requestMap);
  1680. return getDataTable(list);
  1681. }
  1682. @GetMapping("/bdTotal")
  1683. @ApiOperation(value = "供应链管理员统计列表")
  1684. public TableDataInfo bdTotal(
  1685. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1686. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1687. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId) {
  1688. Map<String, Object> requestMap = new HashMap<>();
  1689. if (!Check.isNull(orderStartDate)) {
  1690. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1691. requestMap.put("start", start);
  1692. }
  1693. if (!Check.isNull(orderEndDate)) {
  1694. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1695. requestMap.put("end", end);
  1696. }
  1697. if (!Check.isNull(collectSampleId)) {
  1698. requestMap.put("collectSampleId", collectSampleId);
  1699. }
  1700. TableDataInfo dataInfo = new TableDataInfo();
  1701. if (Check.isNullMap(requestMap)) {
  1702. dataInfo.setCode(500);
  1703. dataInfo.setMsg("入参不能为空");
  1704. return dataInfo;
  1705. }
  1706. startPage();
  1707. List<JSONObject> list = supplyChainService.bdTotal(requestMap);
  1708. return getDataTable(list);
  1709. }
  1710. @PostMapping("/exportBdDetail")
  1711. @ApiOperation(value = "认领商品列表")
  1712. @ResponseBody
  1713. public void exportBdDetail(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  1714. Map<String, Object> requestMap = new HashMap<>();
  1715. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  1716. Integer start = DateUtils.getIntegerTime(requestJson.getString("orderStartDate"));
  1717. requestMap.put("start", start);
  1718. }
  1719. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  1720. Integer end = DateUtils.getIntegerTime(requestJson.getString("orderEndDate"));
  1721. requestMap.put("end", end);
  1722. }
  1723. if (!Check.isNull(requestJson.getLong("collectSampleId"))) {
  1724. requestMap.put("collectSampleId", (requestJson.getLong("collectSampleId")));
  1725. }
  1726. List<JSONObject> list = supplyChainService.exportBdDetail(requestMap);
  1727. List<List<Object>> exportList = new ArrayList<>();
  1728. if (!Check.isNull(list)) {
  1729. for (int i = 0; i < list.size(); i++) {
  1730. JSONObject date = list.get(i);
  1731. List<Object> export = new ArrayList();
  1732. export.add(date.getString("promoterId"));
  1733. export.add(date.getString("promoterName"));
  1734. export.add(date.getString("sampleCount"));
  1735. export.add(date.getString("orderNum"));
  1736. export.add(date.getString("validOrderNum"));
  1737. export.add(date.getString("validOrderRate"));
  1738. export.add(date.getString("regimentalPromotionAmount"));
  1739. export.add(date.getString("totalRegimentalSettleAmount"));
  1740. export.add(date.getString("promoterUrl"));
  1741. exportList.add(export);
  1742. }
  1743. }
  1744. String[] headers = {"达人ID", "达人名称", "领样数", "订单数", "有效订单数", "有效率", "预估服务费收入", "结算服务费收入", "达人头像"};
  1745. OutputStream os = response.getOutputStream();
  1746. ExportExcelUtils eeu = new ExportExcelUtils();
  1747. XSSFWorkbook workbook = new XSSFWorkbook();
  1748. eeu.exportExcel(workbook, 0, "bd业绩", headers, exportList);
  1749. this.setResponseHeader(response, "bd业绩.xls");
  1750. workbook.write(os);
  1751. os.flush();
  1752. os.close();
  1753. }
  1754. @GetMapping("/bdReportListV2")
  1755. @ApiOperation(value = "供应链管理员统计列表")
  1756. public TableDataInfo bdReportListV2(
  1757. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1758. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1759. @ApiParam("结束时间") @RequestParam(value = "bindStartDate", required = false) String bindStartDate,
  1760. @ApiParam("结束时间") @RequestParam(value = "bindEndDate", required = false) String bindEndDate,
  1761. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId) {
  1762. Map<String, Object> requestMap = new HashMap<>();
  1763. if (!Check.isNull(orderStartDate)) {
  1764. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1765. requestMap.put("start", start);
  1766. }
  1767. if (!Check.isNull(orderEndDate)) {
  1768. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1769. requestMap.put("end", end);
  1770. }
  1771. if (!Check.isNull(collectSampleId)) {
  1772. requestMap.put("collectSampleId", collectSampleId);
  1773. }
  1774. if (!Check.isNull(bindStartDate)) {
  1775. Integer start = DateUtils.getIntegerTime(bindStartDate);
  1776. requestMap.put("bindStartDate", start);
  1777. }
  1778. if (!Check.isNull(bindEndDate)) {
  1779. Integer end = DateUtils.getIntegerTime(bindEndDate);
  1780. requestMap.put("bindEndDate", end);
  1781. }
  1782. TableDataInfo dataInfo = new TableDataInfo();
  1783. if (Check.isNullMap(requestMap)) {
  1784. dataInfo.setCode(500);
  1785. dataInfo.setMsg("入参不能为空");
  1786. return dataInfo;
  1787. }
  1788. startPage();
  1789. List<JSONObject> list = new ArrayList<>();
  1790. if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
  1791. list = supplyChainService.bdReportListV2(requestMap);
  1792. } else if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
  1793. list = supplyChainService.bdReportListV2ByBind(requestMap);
  1794. }
  1795. return getDataTable(list);
  1796. }
  1797. @PostMapping("/exportBdReportListV2")
  1798. @ApiOperation(value = "供应链管理员统计列表")
  1799. @ResponseBody
  1800. public void exportBdReportListV2(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  1801. Map<String, Object> requestMap = new HashMap<>();
  1802. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  1803. Integer start = DateUtils.getIntegerTime(requestJson.getString("orderStartDate"));
  1804. requestMap.put("start", start);
  1805. }
  1806. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  1807. Integer end = DateUtils.getIntegerTime(requestJson.getString("orderEndDate"));
  1808. requestMap.put("end", end);
  1809. }
  1810. if (!Check.isNull(requestJson.getLong("collectSampleId"))) {
  1811. requestMap.put("collectSampleId", requestJson.getLong("collectSampleId"));
  1812. }
  1813. if (!Check.isNull(requestJson.getString("bindStartDate"))) {
  1814. Integer start = DateUtils.getIntegerTime(requestJson.getString("bindStartDate"));
  1815. requestMap.put("bindStartDate", start);
  1816. }
  1817. if (!Check.isNull(requestJson.getString("bindEndDate"))) {
  1818. Integer end = DateUtils.getIntegerTime(requestJson.getString("bindEndDate"));
  1819. requestMap.put("bindEndDate", end);
  1820. }
  1821. List<JSONObject> list = new ArrayList<>();
  1822. if (!Check.isNull(requestJson.getString("orderStartDate")) && !Check.isNull(requestJson.getString("orderEndDate"))) {
  1823. list = supplyChainService.bdReportListV2(requestMap);
  1824. } else if (!Check.isNull(requestJson.getString("bindStartDate")) && !Check.isNull(requestJson.getString("bindEndDate"))) {
  1825. list = supplyChainService.bdReportListV2ByBind(requestMap);
  1826. }
  1827. List<List<Object>> exportList = new ArrayList<>();
  1828. if (!Check.isNull(list)) {
  1829. for (int i = 0; i < list.size(); i++) {
  1830. JSONObject date = list.get(i);
  1831. List<Object> export = new ArrayList();
  1832. export.add(date.getString("collectSampleId"));
  1833. export.add(date.getString("collectSampleName"));
  1834. export.add(date.getString("promoterCount"));
  1835. export.add(date.getString("sampleCount"));
  1836. export.add(date.getString("sampleRate"));
  1837. export.add(date.getString("notSampleCount"));
  1838. export.add(date.getString("sendTotalCount"));
  1839. export.add(date.getString("sendPromoterCount"));
  1840. export.add(date.getString("sendItemCount"));
  1841. export.add(date.getString("orderNum"));
  1842. export.add(date.getString("validOrderNum"));
  1843. export.add(date.getString("validOrderRate"));
  1844. export.add(date.getString("orderAmount"));
  1845. export.add(date.getString("regimentalPromotionAmount"));
  1846. export.add(date.getString("totalRegimentalSettleAmount"));
  1847. exportList.add(export);
  1848. }
  1849. }
  1850. String[] headers = {"渠道ID", "渠道姓名", "(总)达人数", "(总)领样达人数", "(总)领样率", "(总)未领样数", "发样数", "发样达人数", "发样商品数", "订单数", "有效订单数", "有效订单率", "订单金额", "预估服务费", "结算服务费"};
  1851. OutputStream os = response.getOutputStream();
  1852. ExportExcelUtils eeu = new ExportExcelUtils();
  1853. XSSFWorkbook workbook = new XSSFWorkbook();
  1854. eeu.exportExcel(workbook, 0, "bd业绩汇总V2", headers, exportList);
  1855. this.setResponseHeader(response, "bd业绩汇总V2.xls");
  1856. workbook.write(os);
  1857. os.flush();
  1858. os.close();
  1859. }
  1860. @GetMapping("/bdTotalV2")
  1861. @ApiOperation(value = "供应链管理员统计列表")
  1862. public TableDataInfo bdTotalV2(
  1863. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1864. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1865. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId) {
  1866. Map<String, Object> requestMap = new HashMap<>();
  1867. if (!Check.isNull(orderStartDate)) {
  1868. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1869. requestMap.put("start", start);
  1870. }
  1871. if (!Check.isNull(orderEndDate)) {
  1872. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1873. requestMap.put("end", end);
  1874. }
  1875. if (!Check.isNull(collectSampleId)) {
  1876. requestMap.put("collectSampleId", collectSampleId);
  1877. }
  1878. TableDataInfo dataInfo = new TableDataInfo();
  1879. if (Check.isNullMap(requestMap)) {
  1880. dataInfo.setCode(500);
  1881. dataInfo.setMsg("入参不能为空");
  1882. return dataInfo;
  1883. }
  1884. startPage();
  1885. List<JSONObject> list = supplyChainService.bdTotalV2(requestMap);
  1886. return getDataTable(list);
  1887. }
  1888. @GetMapping("/bdDetailListV2")
  1889. @ApiOperation(value = "供应链管理员统计列表")
  1890. public TableDataInfo bdDetailListV2(
  1891. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  1892. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  1893. @ApiParam("用户ID") @RequestParam(value = "collectSampleId", required = false) Long collectSampleId,
  1894. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  1895. @ApiParam("排序放肆") @RequestParam(value = "sort", required = false) String sort) {
  1896. Map<String, Object> requestMap = new HashMap<>();
  1897. if (!Check.isNull(orderStartDate)) {
  1898. Integer start = DateUtils.getIntegerTime(orderStartDate);
  1899. requestMap.put("start", start);
  1900. }
  1901. if (!Check.isNull(orderEndDate)) {
  1902. Integer end = DateUtils.getIntegerTime(orderEndDate);
  1903. requestMap.put("end", end);
  1904. }
  1905. if (!Check.isNull(collectSampleId)) {
  1906. requestMap.put("collectSampleId", collectSampleId);
  1907. }
  1908. requestMap.put("fieId", fieId);
  1909. requestMap.put("sort", sort);
  1910. TableDataInfo dataInfo = new TableDataInfo();
  1911. if (Check.isNullMap(requestMap)) {
  1912. dataInfo.setCode(500);
  1913. dataInfo.setMsg("入参不能为空");
  1914. return dataInfo;
  1915. }
  1916. startPage();
  1917. List<JSONObject> list = supplyChainService.bdDetailListV2(requestMap);
  1918. return getDataTable(list);
  1919. }
  1920. @PostMapping("/exportBdDetailV2")
  1921. @ApiOperation(value = "认领商品列表")
  1922. @ResponseBody
  1923. public void exportBdDetailV2(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  1924. Map<String, Object> requestMap = new HashMap<>();
  1925. if (!Check.isNull(requestJson.getString("orderStartDate"))) {
  1926. Integer start = DateUtils.getIntegerTime(requestJson.getString("orderStartDate"));
  1927. requestMap.put("start", start);
  1928. }
  1929. if (!Check.isNull(requestJson.getString("orderEndDate"))) {
  1930. Integer end = DateUtils.getIntegerTime(requestJson.getString("orderEndDate"));
  1931. requestMap.put("end", end);
  1932. }
  1933. if (!Check.isNull(requestJson.getLong("collectSampleId"))) {
  1934. requestMap.put("collectSampleId", requestJson.getLong("collectSampleId"));
  1935. }
  1936. requestMap.put("fieId", "orderNum");
  1937. requestMap.put("sort", "desc");
  1938. List<JSONObject> list = supplyChainService.bdDetailListV2(requestMap);
  1939. List<List<Object>> exportList = new ArrayList<>();
  1940. if (!Check.isNull(list)) {
  1941. for (int i = 0; i < list.size(); i++) {
  1942. JSONObject date = list.get(i);
  1943. List<Object> export = new ArrayList();
  1944. export.add(date.getString("promoterId"));
  1945. export.add(date.getString("promoterName"));
  1946. export.add(date.getString("sampleCount"));
  1947. export.add(date.getString("orderNum"));
  1948. export.add(date.getString("validOrderNum"));
  1949. export.add(date.getString("validOrderRate"));
  1950. export.add(date.getString("regimentalPromotionAmount"));
  1951. export.add(date.getString("totalRegimentalSettleAmount"));
  1952. export.add(date.getString("promoterUrl"));
  1953. exportList.add(export);
  1954. }
  1955. }
  1956. String[] headers = {"达人ID", "达人名称", "领样数", "订单数", "有效订单数", "有效率", "预估服务费收入", "结算服务费收入", "达人头像"};
  1957. OutputStream os = response.getOutputStream();
  1958. ExportExcelUtils eeu = new ExportExcelUtils();
  1959. XSSFWorkbook workbook = new XSSFWorkbook();
  1960. eeu.exportExcel(workbook, 0, "bd业绩", headers, exportList);
  1961. this.setResponseHeader(response, "bd业绩.xls");
  1962. workbook.write(os);
  1963. os.flush();
  1964. os.close();
  1965. }
  1966. static ExecutorService updateListCService = Executors.newFixedThreadPool(6);
  1967. /**
  1968. * 接口链接:
  1969. * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.open.close&version=1
  1970. * 状态修改
  1971. */
  1972. @GetMapping("/addList")
  1973. @ApiOperation(value = "分销团长订单列表(游标方式),状态修改")
  1974. public void addList(String beginDate, String endDate) {
  1975. List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes(beginDate, endDate);
  1976. allDatesOfTwoTimes.forEach(date -> updateListCService.submit(() -> {
  1977. try {
  1978. supplyChainService.addList(date, date, "");
  1979. } catch (InterruptedException e) {
  1980. e.printStackTrace();
  1981. }
  1982. }));
  1983. }
  1984. /**
  1985. * 新增 open.distribution.cps.leader.order.cursor.list
  1986. * 接口链接:
  1987. * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.open.close&version=1
  1988. */
  1989. @GetMapping("/insertOrderList")
  1990. @ApiOperation(value = "新增分销团长订单列表(游标方式)")
  1991. public void insertOrderList(Long tokenId, Integer queryType, String beginDate, String endDate) {
  1992. Thread thread = new Thread() {
  1993. @Override
  1994. public void run() {
  1995. try {
  1996. supplyChainService.insertOrderList(tokenId, queryType, beginDate, endDate);
  1997. } catch (Exception e) {
  1998. e.printStackTrace();
  1999. }
  2000. }
  2001. };
  2002. thread.start();
  2003. }
  2004. /**
  2005. * 当日2小时内数据新增
  2006. * open.distribution.cps.leader.order.cursor.list
  2007. * 接口链接:
  2008. * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.open.close&version=1
  2009. */
  2010. @GetMapping("/insertNowdayOrderList")
  2011. @ApiOperation(value = "新增当天分销团长订单列表(游标方式)")
  2012. public void insertNowdayOrderList(Long tokenId) {
  2013. Thread thread = new Thread() {
  2014. @Override
  2015. public void run() {
  2016. try {
  2017. supplyChainService.insertNowdayOrderList(tokenId);
  2018. } catch (Exception e) {
  2019. e.printStackTrace();
  2020. }
  2021. }
  2022. };
  2023. thread.start();
  2024. }
  2025. static ExecutorService fxNowService = Executors.newFixedThreadPool(10);
  2026. @PostMapping(value = "/ruixuanAccept")
  2027. public Map<String, Object> ruixuanAccept(@RequestBody String eventsEncoded) {
  2028. try {
  2029. logger.info("567睿选消息订阅");
  2030. String events = PlatformEventSecurityUtil.decode(eventsEncoded, ruiXuanPrivateKey);
  2031. JSONObject eventJSon = JSONObject.parseObject(events);
  2032. fxNowService.submit(new Runnable() {
  2033. @Override
  2034. public void run() {
  2035. try {
  2036. if (!Check.isNull(eventJSon)) {
  2037. String event = eventJSon.getString("event");
  2038. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2039. supplyChainService.updateOrder(eventJSon);
  2040. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2041. supplyChainService.updateItem(eventJSon);
  2042. }
  2043. }
  2044. } catch (Exception e) {
  2045. e.printStackTrace();
  2046. }
  2047. }
  2048. });
  2049. } catch (KsMerchantApiException e) {
  2050. e.printStackTrace();
  2051. }
  2052. //返回成功
  2053. Map<String, Object> result = new HashMap<>();
  2054. result.put("result", 1);
  2055. return result;
  2056. }
  2057. static ExecutorService orderNewsService = Executors.newFixedThreadPool(10);
  2058. /**
  2059. * https://open.kwaixiaodian.com/zone/new/docs/msg?name=kwaishop_order_delivering&version=1
  2060. * KWaiShop订单状态消息
  2061. * 订单已支付消息、订单已发货消息、订单已收货消息、订单交易失败消息、订单交易成功消息 ->状态变更
  2062. * 新增订单 ->调取新增详情接口
  2063. */
  2064. public static final List<String> EVENT_LIST =
  2065. Collections.unmodifiableList(Arrays.asList(
  2066. "kwaishop_order_deliverySuccess",//已收货消息
  2067. "kwaishop_order_paySuccess",//已支付消息
  2068. "kwaishop_order_orderFail",//交易失败消息
  2069. "kwaishop_order_orderSuccess",//交易成功消息
  2070. "kwaishop_order_delivering"//已发货消息
  2071. ));
  2072. @PostMapping(value = "/ruixuanKWaiShopOrderAccept")
  2073. public Map<String, Object> ruixuanKWaiShopOrderAccept(@RequestBody String eventsEncoded) {
  2074. Map<String, Object> result = new HashMap<>();
  2075. try {
  2076. String events = PlatformEventSecurityUtil.decode(eventsEncoded, "xjX0jX828wWrnnwt26UYDA==");
  2077. logger.info("-KWaiShop-订单-消息-订阅-");
  2078. JSONObject eventJSon = JSONObject.parseObject(events);
  2079. /* List<String> list = new ArrayList<>();
  2080. list.add("kwaishop_order_deliverySuccess");//已收货消息
  2081. list.add("kwaishop_order_paySuccess");//已支付消息
  2082. list.add("kwaishop_order_delivering");//已发货消息
  2083. list.add("kwaishop_order_orderFail");//交易失败消息
  2084. list.add("kwaishop_order_orderSuccess");//交易成功消息*/
  2085. orderNewsService.submit(new Runnable() {
  2086. @Override
  2087. public void run() {
  2088. try {
  2089. if (!Check.isNull(eventJSon)) {
  2090. String event = eventJSon.getString("event");
  2091. //订单新增消息
  2092. if ("kwaishop_order_addOrder".equals(event)) {
  2093. orderCursorListService.insertKWaiShopOrder(eventJSon);
  2094. } else if (EVENT_LIST.contains(event)) {
  2095. //状态变更 kwaixiaodian_order_cursor_list
  2096. orderCursorListService.updateKWaiShopOrderStatus(eventJSon);
  2097. }
  2098. }
  2099. } catch (Exception e) {
  2100. e.printStackTrace();
  2101. }
  2102. }
  2103. });
  2104. } catch (KsMerchantApiException e) {
  2105. e.printStackTrace();
  2106. }
  2107. //返回成功
  2108. result.put("result", 1);
  2109. return result;
  2110. }
  2111. @PostMapping(value = "/rocketAccept")
  2112. public Map<String, Object> rocketAccept(@RequestBody String eventsEncoded) {
  2113. try {
  2114. logger.info("王炸睿选消息订阅");
  2115. String events = PlatformEventSecurityUtil.decode(eventsEncoded, rocketPrivateKey);
  2116. JSONObject eventJSon = JSONObject.parseObject(events);
  2117. // logger.info("返回信息:{}", eventJSon);
  2118. fxNowService.submit(new Runnable() {
  2119. @Override
  2120. public void run() {
  2121. try {
  2122. if (!Check.isNull(eventJSon)) {
  2123. String event = eventJSon.getString("event");
  2124. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2125. supplyChainService.updateOrder(eventJSon);
  2126. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2127. supplyChainService.updateItem(eventJSon);
  2128. } else if ("kwaishop_distribution_regimentalOrder".equals(event)) {
  2129. supplyChainService.insertOrder(eventJSon);
  2130. }
  2131. }
  2132. } catch (Exception e) {
  2133. e.printStackTrace();
  2134. }
  2135. }
  2136. });
  2137. } catch (KsMerchantApiException e) {
  2138. e.printStackTrace();
  2139. }
  2140. //返回成功
  2141. Map<String, Object> result = new HashMap<>();
  2142. result.put("result", 1);
  2143. return result;
  2144. }
  2145. @PostMapping(value = "/test111")
  2146. @ApiOperation(value = "---------测试")
  2147. public Map<String, Object> test111(@RequestBody JSONObject eventsEncoded) {
  2148. supplyChainService.insertOrder(eventsEncoded);
  2149. Map<String, Object> result = new HashMap<>();
  2150. result.put("result", 1);
  2151. return result;
  2152. }
  2153. @PostMapping(value = "/dfcAccept")
  2154. public Map<String, Object> dfcAccept(@RequestBody String eventsEncoded) {
  2155. try {
  2156. logger.info("佰川心选消息订阅");
  2157. String events = PlatformEventSecurityUtil.decode(eventsEncoded, dfcPrivateKey);
  2158. JSONObject eventJSon = JSONObject.parseObject(events);
  2159. fxNowService.submit(new Runnable() {
  2160. @Override
  2161. public void run() {
  2162. try {
  2163. if (!Check.isNull(eventJSon)) {
  2164. String event = eventJSon.getString("event");
  2165. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2166. supplyChainService.updateOrder(eventJSon);
  2167. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2168. supplyChainService.updateItem(eventJSon);
  2169. }
  2170. }
  2171. } catch (Exception e) {
  2172. e.printStackTrace();
  2173. }
  2174. }
  2175. });
  2176. } catch (KsMerchantApiException e) {
  2177. e.printStackTrace();
  2178. }
  2179. //返回成功
  2180. Map<String, Object> result = new HashMap<>();
  2181. result.put("result", 1);
  2182. return result;
  2183. }
  2184. @PostMapping(value = "/mgsAccept2")
  2185. public Map<String, Object> mgsAccept2(@RequestBody String eventsEncoded) {
  2186. try {
  2187. logger.info("RX食品消息订阅");
  2188. String events = PlatformEventSecurityUtil.decode(eventsEncoded, mgsPrivateKey2);
  2189. JSONObject eventJSon = JSONObject.parseObject(events);
  2190. fxNowService.submit(new Runnable() {
  2191. @Override
  2192. public void run() {
  2193. try {
  2194. if (!Check.isNull(eventJSon)) {
  2195. String event = eventJSon.getString("event");
  2196. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2197. supplyChainService.updateOrder(eventJSon);
  2198. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2199. supplyChainService.updateItem(eventJSon);
  2200. }
  2201. }
  2202. } catch (Exception e) {
  2203. e.printStackTrace();
  2204. }
  2205. }
  2206. });
  2207. } catch (KsMerchantApiException e) {
  2208. e.printStackTrace();
  2209. }
  2210. //返回成功
  2211. Map<String, Object> result = new HashMap<>();
  2212. result.put("result", 1);
  2213. return result;
  2214. }
  2215. @PostMapping(value = "/yufuAccept")
  2216. public Map<String, Object> yufuAccept(@RequestBody String eventsEncoded) {
  2217. try {
  2218. logger.info("雪峰优选消息订阅");
  2219. String events = PlatformEventSecurityUtil.decode(eventsEncoded, yufuPrivateKey);
  2220. JSONObject eventJSon = JSONObject.parseObject(events);
  2221. fxNowService.submit(new Runnable() {
  2222. @Override
  2223. public void run() {
  2224. try {
  2225. if (!Check.isNull(eventJSon)) {
  2226. String event = eventJSon.getString("event");
  2227. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2228. supplyChainService.updateOrder(eventJSon);
  2229. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2230. supplyChainService.updateItem(eventJSon);
  2231. }
  2232. }
  2233. } catch (Exception e) {
  2234. e.printStackTrace();
  2235. }
  2236. }
  2237. });
  2238. } catch (KsMerchantApiException e) {
  2239. e.printStackTrace();
  2240. }
  2241. //返回成功
  2242. Map<String, Object> result = new HashMap<>();
  2243. result.put("result", 1);
  2244. return result;
  2245. }
  2246. @PostMapping(value = "/yuXiuAccept")
  2247. public Map<String, Object> yuXiuAccept(@RequestBody String eventsEncoded) {
  2248. try {
  2249. logger.info("毓秀优选消息订阅");
  2250. String events = PlatformEventSecurityUtil.decode(eventsEncoded, yuXiuPrivateKey);
  2251. JSONObject eventJSon = JSONObject.parseObject(events);
  2252. fxNowService.submit(new Runnable() {
  2253. @Override
  2254. public void run() {
  2255. try {
  2256. if (!Check.isNull(eventJSon)) {
  2257. String event = eventJSon.getString("event");
  2258. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2259. supplyChainService.updateOrder(eventJSon);
  2260. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2261. supplyChainService.updateItem(eventJSon);
  2262. }
  2263. }
  2264. } catch (Exception e) {
  2265. e.printStackTrace();
  2266. }
  2267. }
  2268. });
  2269. } catch (KsMerchantApiException e) {
  2270. e.printStackTrace();
  2271. }
  2272. //返回成功
  2273. Map<String, Object> result = new HashMap<>();
  2274. result.put("result", 1);
  2275. return result;
  2276. }
  2277. @PostMapping(value = "/zhiShuiAccept")
  2278. public Map<String, Object> zhishuiAccept(@RequestBody String eventsEncoded) {
  2279. try {
  2280. logger.info("止水优选消息订阅");
  2281. String events = PlatformEventSecurityUtil.decode(eventsEncoded, zhiShuiPrivateKey);
  2282. JSONObject eventJSon = JSONObject.parseObject(events);
  2283. fxNowService.submit(new Runnable() {
  2284. @Override
  2285. public void run() {
  2286. try {
  2287. if (!Check.isNull(eventJSon)) {
  2288. String event = eventJSon.getString("event");
  2289. if ("kwaishop_distribute_order_change_notify".equals(event)) {
  2290. supplyChainService.updateOrder(eventJSon);
  2291. } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
  2292. supplyChainService.updateItem(eventJSon);
  2293. }
  2294. }
  2295. } catch (Exception e) {
  2296. e.printStackTrace();
  2297. }
  2298. }
  2299. });
  2300. } catch (KsMerchantApiException e) {
  2301. e.printStackTrace();
  2302. }
  2303. //返回成功
  2304. Map<String, Object> result = new HashMap<>();
  2305. result.put("result", 1);
  2306. return result;
  2307. }
  2308. @GetMapping("/addListKuaishouActivityInfo")
  2309. @ApiOperation(value = "团长查询招商活动列表")
  2310. public void addListKuaishouActivityInfo() {
  2311. try {
  2312. supplyChainService.addListKuaishouActivityInfo();
  2313. } catch (InterruptedException e) {
  2314. e.printStackTrace();
  2315. }
  2316. }
  2317. @Autowired
  2318. private ISysUserService sysUserService;
  2319. @Autowired
  2320. private ISysDeptService deptService;
  2321. @GetMapping("/shopList")
  2322. @ApiOperation(value = "商品列表")
  2323. public TableDataInfo shopList(
  2324. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  2325. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  2326. @ApiParam("结束时间") @RequestParam(value = "sellerId", required = false) Long sellerId,
  2327. @ApiParam("结束时间") @RequestParam(value = "userId", required = false) Long userId,
  2328. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  2329. @ApiParam("排序方式") @RequestParam(value = "sort", required = false) String sort) {
  2330. TableDataInfo dataInfo = new TableDataInfo();
  2331. try {
  2332. if (Check.isNull(orderStartDate) || Check.isNull(orderEndDate)) {
  2333. throw new Exception("请输入开始时间和结束时间");
  2334. }
  2335. if (Check.isNull(userId)) {
  2336. throw new Exception("请输入用户id");
  2337. }
  2338. Map<String, Object> requestMap = new HashMap<>();
  2339. String roleKey = sysUserService.getRoleKeyByUserId(userId);
  2340. if (roleKey.equals("courtship")) {
  2341. List<Long> itemIds = supplyChainService.getItemIdsByUserId(userId);
  2342. requestMap.put("itemIds", itemIds);
  2343. }
  2344. if (roleKey.equals("courtshipManager")) {
  2345. Long deptId = deptService.getDeptIdByUserId(userId);
  2346. List<Long> itemIds = supplyChainService.getItemIdsByDeptId(deptId);
  2347. requestMap.put("itemIds", itemIds);
  2348. }
  2349. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  2350. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  2351. if (!Check.isNull(sellerId)) {
  2352. requestMap.put("sellerId", sellerId);
  2353. }
  2354. requestMap.put("fieId", fieId);
  2355. requestMap.put("sort", sort);
  2356. if (Check.isNullMap(requestMap)) {
  2357. dataInfo.setCode(-1);
  2358. dataInfo.setMsg("入参不能为空");
  2359. return dataInfo;
  2360. }
  2361. startPage();
  2362. List<JSONObject> list = supplyChainService.shopList(requestMap);
  2363. return getDataTable(list);
  2364. } catch (Exception e) {
  2365. e.printStackTrace();
  2366. dataInfo.setCode(-1);
  2367. dataInfo.setMsg(e.getMessage());
  2368. return dataInfo;
  2369. }
  2370. }
  2371. @GetMapping("/shopDetail")
  2372. @ApiOperation(value = "商品列表")
  2373. public TableDataInfo shopDetail(
  2374. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  2375. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  2376. @ApiParam("店铺Id") @RequestParam(value = "sellerId", required = false) Long sellerId,
  2377. @ApiParam("用户ID") @RequestParam(value = "userId", required = false) Long userId,
  2378. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) Long itemId,
  2379. @ApiParam("商品名") @RequestParam(value = "itemTitle", required = false) String itemTitle
  2380. ) {
  2381. TableDataInfo dataInfo = new TableDataInfo();
  2382. try {
  2383. if (Check.isNull(orderStartDate) || Check.isNull(orderEndDate)) {
  2384. throw new Exception("请输入开始时间和结束时间");
  2385. }
  2386. if (Check.isNull(sellerId)) {
  2387. throw new Exception("请输入店铺Id");
  2388. }
  2389. Map<String, Object> requestMap = new HashMap<>();
  2390. String roleKey = sysUserService.getRoleKeyByUserId(userId);
  2391. if (roleKey.equals("courtship")) {
  2392. List<Long> itemIds = supplyChainService.getItemIdsByUserId(userId);
  2393. requestMap.put("itemIds", itemIds);
  2394. }
  2395. if (roleKey.equals("courtshipManager")) {
  2396. Long deptId = deptService.getDeptIdByUserId(userId);
  2397. List<Long> itemIds = supplyChainService.getItemIdsByDeptId(deptId);
  2398. requestMap.put("itemIds", itemIds);
  2399. }
  2400. requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
  2401. requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
  2402. requestMap.put("sellerId", sellerId);
  2403. if (!Check.isNull(itemId)) {
  2404. requestMap.put("itemId", itemId);
  2405. }
  2406. if (!Check.isNull(itemTitle)) {
  2407. requestMap.put("itemTitle", itemTitle);
  2408. }
  2409. if (Check.isNullMap(requestMap)) {
  2410. dataInfo.setCode(-1);
  2411. dataInfo.setMsg("入参不能为空");
  2412. return dataInfo;
  2413. }
  2414. startPage();
  2415. List<JSONObject> list = supplyChainService.shopDetail(requestMap);
  2416. return getDataTable(list);
  2417. } catch (Exception e) {
  2418. e.printStackTrace();
  2419. dataInfo.setCode(-1);
  2420. dataInfo.setMsg(e.getMessage());
  2421. return dataInfo;
  2422. }
  2423. }
  2424. @PostMapping("/exportShopDetail")
  2425. @ResponseBody
  2426. public void exportShopDetail(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  2427. try {
  2428. if (Check.isNull(requestJson.getString("orderStartDate")) || Check.isNull(requestJson.getString("orderEndDate"))) {
  2429. throw new Exception("请输入开始时间和结束时间");
  2430. }
  2431. if (Check.isNull(requestJson.getLong("sellerId"))) {
  2432. throw new Exception("请输入店铺Id");
  2433. }
  2434. Long userId = requestJson.getLong("userId");
  2435. if (Check.isNull(userId)) {
  2436. throw new Exception("请输入用户ID");
  2437. }
  2438. Map<String, Object> requestMap = new HashMap<>();
  2439. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  2440. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  2441. requestMap.put("sellerId", requestJson.getLong("sellerId"));
  2442. String roleKey = sysUserService.getRoleKeyByUserId(userId);
  2443. if (roleKey.equals("courtship")) {
  2444. List<Long> itemIds = supplyChainService.getItemIdsByUserId(userId);
  2445. requestMap.put("itemIds", itemIds);
  2446. }
  2447. if (roleKey.equals("courtshipManager")) {
  2448. Long deptId = deptService.getDeptIdByUserId(userId);
  2449. List<Long> itemIds = supplyChainService.getItemIdsByDeptId(deptId);
  2450. requestMap.put("itemIds", itemIds);
  2451. }
  2452. List<JSONObject> list = supplyChainService.shopDetail(requestMap);
  2453. List<List<Object>> exportList = new ArrayList<>();
  2454. if (!Check.isNull(list)) {
  2455. for (int i = 0; i < list.size(); i++) {
  2456. JSONObject date = list.get(i);
  2457. List<Object> export = new ArrayList();
  2458. export.add(date.getString("itemId"));
  2459. export.add(date.getString("itemTitle"));
  2460. export.add(date.getString("reservePrice"));
  2461. export.add(date.getString("userName"));
  2462. export.add(date.getString("ccrValue"));
  2463. export.add(date.getString("orderNum"));
  2464. export.add(date.getString("validOrderNUm"));
  2465. export.add(date.getString("validRadio"));
  2466. export.add(date.getString("payAmount"));
  2467. export.add(date.getString("deliveryNum"));
  2468. export.add(date.getString("shippingGreen"));
  2469. export.add(date.getString("effDeliveryNum"));
  2470. export.add(date.getString("notDeliveryNum"));
  2471. export.add(date.getString("deliveryRadio"));
  2472. export.add(date.getString("regimentalPromotionRate"));
  2473. exportList.add(export);
  2474. }
  2475. }
  2476. String[] headers = {"商品ID", "商品名称", "单价", "归属人", "ccr", "单量", "有效单量", "有效率", "付款金额", "发货数", "发货率", "有效发货数", "未发货数", "有效发货率", "服务费率"};
  2477. OutputStream os = response.getOutputStream();
  2478. ExportExcelUtils eeu = new ExportExcelUtils();
  2479. XSSFWorkbook workbook = new XSSFWorkbook();
  2480. eeu.exportExcel(workbook, 0, "店铺详情", headers, exportList);
  2481. this.setResponseHeader(response, "店铺详情.xls");
  2482. workbook.write(os);
  2483. os.flush();
  2484. os.close();
  2485. } catch (Exception e) {
  2486. e.printStackTrace();
  2487. }
  2488. }
  2489. @PostMapping("/exportShopList")
  2490. @ResponseBody
  2491. public void exportShopList(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws IOException {
  2492. try {
  2493. if (Check.isNull(requestJson.getString("orderStartDate")) || Check.isNull(requestJson.getString("orderEndDate"))) {
  2494. throw new Exception("请输入开始时间和结束时间");
  2495. }
  2496. if (Check.isNull(requestJson.getLong("userId"))) {
  2497. throw new Exception("请输入用户id");
  2498. }
  2499. Map<String, Object> requestMap = new HashMap<>();
  2500. String roleKey = sysUserService.getRoleKeyByUserId(requestJson.getLong("userId"));
  2501. if (roleKey.equals("courtship")) {
  2502. List<Long> itemIds = supplyChainService.getItemIdsByUserId(requestJson.getLong("userId"));
  2503. requestMap.put("itemIds", itemIds);
  2504. }
  2505. if (roleKey.equals("courtshipManager")) {
  2506. Long deptId = deptService.getDeptIdByUserId(requestJson.getLong("userId"));
  2507. List<Long> itemIds = supplyChainService.getItemIdsByDeptId(deptId);
  2508. requestMap.put("itemIds", itemIds);
  2509. }
  2510. requestMap.put("start", DateUtils.strDateToInt(requestJson.getString("orderStartDate")));
  2511. requestMap.put("end", DateUtils.strDateToInt(requestJson.getString("orderEndDate")));
  2512. if (!Check.isNull(requestJson.getLong("sellerId"))) {
  2513. requestMap.put("sellerId", requestJson.getLong("sellerId"));
  2514. }
  2515. requestMap.put("fieId", "orderNum");
  2516. requestMap.put("sort", "desc");
  2517. List<JSONObject> list = supplyChainService.shopList(requestMap);
  2518. List<List<Object>> exportList = new ArrayList<>();
  2519. if (!Check.isNull(list)) {
  2520. for (int i = 0; i < list.size(); i++) {
  2521. JSONObject date = list.get(i);
  2522. List<Object> export = new ArrayList();
  2523. export.add(date.getString("sellerId"));
  2524. export.add(date.getString("sellerName"));
  2525. export.add(date.getString("orderNum"));
  2526. export.add(date.getString("validOrderNUm"));
  2527. export.add(date.getString("validRadio"));
  2528. export.add(date.getString("settledOrderNUm"));
  2529. export.add(date.getString("settledOrderRate"));
  2530. export.add(date.getString("payAmount"));
  2531. export.add(date.getString("deliveryNum"));
  2532. export.add(date.getString("shippingGreen"));
  2533. export.add(date.getString("effDeliveryNum"));
  2534. export.add(date.getString("notDeliveryNum"));
  2535. export.add(date.getString("deliveryRadio"));
  2536. exportList.add(export);
  2537. }
  2538. }
  2539. String[] headers = {"店铺ID", "店铺名称", "单量", "有效单量", "有效率", "已结单量", "结算率", "付款金额", "发货数", "发货率", "有效发货数", "未发货数", "有效发货率"};
  2540. OutputStream os = response.getOutputStream();
  2541. ExportExcelUtils eeu = new ExportExcelUtils();
  2542. XSSFWorkbook workbook = new XSSFWorkbook();
  2543. eeu.exportExcel(workbook, 0, "店铺列表", headers, exportList);
  2544. this.setResponseHeader(response, "店铺列表.xls");
  2545. workbook.write(os);
  2546. os.flush();
  2547. os.close();
  2548. } catch (Exception e) {
  2549. e.printStackTrace();
  2550. }
  2551. }
  2552. /**
  2553. * open.distribution.investment.activity.open.item.list
  2554. * 团长招商活动已报名商品列表
  2555. */
  2556. @GetMapping("/addKuaishouActivityOpenItemList")
  2557. @ApiOperation(value = "团长招商活动已报名商品列表")
  2558. public void addKuaishouActivityOpenItemList() {
  2559. try {
  2560. supplyChainService.addKuaishouActivityOpenItemList();
  2561. } catch (InterruptedException e) {
  2562. e.printStackTrace();
  2563. }
  2564. }
  2565. /**
  2566. * 通过excel导入RewardBaseInfo
  2567. */
  2568. @PostMapping(value = "/insertRewardBaseInfoByExcel")
  2569. @ApiOperation(value = "导入rewardBaseInfo")
  2570. public ResultResponse insertRewardBaseInfoByExcel(@ApiParam("文件数组") @RequestParam("file") MultipartFile file) {
  2571. try {
  2572. return kuaishouRewardBaseInfoService.insertRewardBaseInfoByExcel(file);
  2573. } catch (Exception e) {
  2574. e.printStackTrace();
  2575. return ResultResponse.error("导入异常");
  2576. }
  2577. }
  2578. }