TOrderController.java 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  1. package com.szwl.controller;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import cn.com.crbank.ommo.bean.ResultMessage;
  5. import cn.com.crbank.ommo.esclient.ElasticsearchRunner;
  6. import cn.hutool.core.bean.BeanUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.metadata.IPage;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import com.szwl.common.aop.LogAnnotation;
  14. import com.szwl.constant.ResponseCodesEnum;
  15. import com.szwl.feign.SzwlFeign;
  16. import com.szwl.model.bean.ChartColumn;
  17. import com.szwl.model.bean.OrderDaoChuDTO;
  18. import com.szwl.model.bean.OrderDetailsVo;
  19. import com.szwl.model.bean.OrderVo;
  20. import com.szwl.model.bo.JsonMessage;
  21. import com.szwl.model.bo.R;
  22. import com.szwl.model.bo.ResponseModel;
  23. import com.szwl.model.entity.*;
  24. import com.szwl.model.excel.CoinOrderTarget;
  25. import com.szwl.model.excel.OrderByAdminTarget;
  26. import com.szwl.model.excel.OrderByClientidTarget;
  27. import com.szwl.model.excel.OrderTarget;
  28. import com.szwl.model.query.*;
  29. import com.szwl.model.utils.DateUtils;
  30. import com.szwl.model.utils.FgObjectUtil;
  31. import com.szwl.model.utils.JsonUtils;
  32. import com.szwl.service.*;
  33. import com.szwl.service.es.EsTEquipmentService;
  34. import com.szwl.service.es.EsTOrderService;
  35. import io.swagger.annotations.ApiOperation;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang.StringUtils;
  38. import org.apache.poi.ss.usermodel.Workbook;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.http.HttpStatus;
  41. import org.springframework.http.ResponseEntity;
  42. import org.springframework.web.bind.annotation.*;
  43. import javax.servlet.http.HttpServletResponse;
  44. import java.io.IOException;
  45. import java.io.OutputStream;
  46. import java.net.URLEncoder;
  47. import java.text.ParseException;
  48. import java.text.SimpleDateFormat;
  49. import java.util.*;
  50. /**
  51. * <p>
  52. * 前端控制器
  53. * </p>
  54. *
  55. * @author wuhs
  56. * @since 2022-06-14
  57. */
  58. @Slf4j
  59. @RestController
  60. @RequestMapping("/tOrder")
  61. public class TOrderController {
  62. @Autowired
  63. TOrderService orderService;
  64. @Autowired
  65. TEquipmentService equipmentService;
  66. @Autowired
  67. TAreaService areaService;
  68. @Autowired
  69. EsTOrderService esTOrderService;
  70. @Autowired
  71. EsTEquipmentService esTEquipmentService;
  72. @Autowired
  73. TCoinOrderService coinOrderService;
  74. @Autowired
  75. SzwlFeign szwlFeign;
  76. @Autowired
  77. TOrderDetailsService orderDetailsService;
  78. // 获取订单列表
  79. @GetMapping("/pageOrder")
  80. public ResponseModel<IPage<?>> pageOrder(String equipmentId, String adminId, String adminType,
  81. String type, String sn, String status, String userName,
  82. String payType, String productNo, String clientId,
  83. String trxNo, String dateType, String startDate,
  84. String companyType, String machineType, String endDate, long current, long size) {
  85. //判断当前账号状态
  86. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminId));
  87. if (StringUtils.isEmpty(type)) {
  88. if (StringUtils.isNotEmpty(admin.getIfForeign())) {
  89. // 0 国内,1 海外
  90. type = admin.getIfForeign();
  91. } else {
  92. if (!admin.getIsAdmined()) {
  93. TAdmin parentDate = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  94. if (StringUtils.isNotEmpty(parentDate.getIfForeign())) {
  95. type = parentDate.getIfForeign();
  96. }
  97. }
  98. }
  99. }
  100. //类型
  101. //0,线上 -》 国内
  102. if (type.equals("0")) {
  103. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  104. if (!userName.equals("admin")) {
  105. if (StringUtils.isNotEmpty(userName)) {
  106. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
  107. TAdmin data = adminByUsername.getData();
  108. if (data == null || data.getId() == null) {
  109. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  110. }
  111. if (data.getIsAdmined()) {
  112. query.eq(TOrder::getAdminId, data.getId());
  113. } else {
  114. if (data.getParentId() != 1) {
  115. query.eq(TOrder::getAdminId, data.getParentId());
  116. //查找子账户所管理的机器
  117. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  118. if (!adminEquipment.getType().equals("0")) {
  119. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  120. if (list == null || list.size() == 0) {
  121. return R.fail(ResponseCodesEnum.A0001, "没有机器/no machine");
  122. }
  123. query.in(TOrder::getClientId, list);
  124. }
  125. }
  126. }
  127. } else {
  128. //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
  129. if (StringUtils.isNotEmpty(adminType)) {
  130. if (admin.getIsAdmined() && admin.getType() > 1) {
  131. if (admin.getType() > 1) {
  132. if (adminType.equals("all")) {
  133. //查找所有下级
  134. List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
  135. query.in(TOrder::getAdminId, admidIdList);
  136. }
  137. }
  138. } else {
  139. if (admin.getType() > 1) {
  140. //登录账户为子账户 不查下级 只查对应机器的订单
  141. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  142. if (adminEquipment.getType().equals("0")) {
  143. //全部机器
  144. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  145. query.eq(TOrder::getAdminId, upAdmin.getId());
  146. } else {
  147. String equipmentIds = adminEquipment.getEquipmentIds();
  148. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  149. query.in(TOrder::getClientId, equipmentIdList);
  150. }
  151. }
  152. }
  153. } else {
  154. //判断当前账号状态 公司还是商家
  155. if (admin.getType() > 1) {
  156. //商家 判断是否子账户
  157. if (admin.getIsAdmined()) {
  158. //商家自己
  159. query.eq(TOrder::getAdminId, adminId);
  160. } else {
  161. //商家 子账户
  162. //登录账户为子账户 不查下级 只查对应机器的订单
  163. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  164. if (adminEquipment.getType().equals("0")) {
  165. //全部机器
  166. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  167. query.eq(TOrder::getAdminId, upAdmin.getId());
  168. } else {
  169. String equipmentIds = adminEquipment.getEquipmentIds();
  170. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  171. query.in(TOrder::getClientId, equipmentIdList);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. if (StringUtils.isNotEmpty(equipmentId)) {
  179. query.eq(TOrder::getEquipmentId, equipmentId);
  180. }
  181. if (StringUtils.isNotEmpty(payType)) {
  182. query.eq(TOrder::getFrpCode, payType);
  183. }
  184. if (StringUtils.isNotEmpty(productNo)) {
  185. query.eq(TOrder::getProductNo, productNo);
  186. }
  187. if (StringUtils.isNotEmpty(sn)) {
  188. query.like(TOrder::getSn, sn);
  189. }
  190. if (StringUtils.isNotEmpty(trxNo)) {
  191. query.like(TOrder::getTrxNo, trxNo);
  192. }
  193. if (StringUtils.isNotEmpty(status)) {
  194. query.eq(TOrder::getStatus, status);
  195. }
  196. // 公司平台
  197. // 申泽平台管理员
  198. if (admin.getId() == 2738) {
  199. companyType = "0";
  200. }
  201. // 七云平台管理员
  202. if (admin.getId() == 2739) {
  203. companyType = "1";
  204. }
  205. if (StringUtils.isNotEmpty(companyType)) {
  206. if (companyType.equals("0")) {
  207. String finalCompanyType = companyType;
  208. query.nested(q -> q.isNull(TOrder::getCompanyType).or()
  209. .eq(TOrder::getCompanyType, finalCompanyType));
  210. } else {
  211. query.eq(TOrder::getCompanyType, companyType);
  212. }
  213. }
  214. if (StringUtils.isNotEmpty(machineType)) {
  215. if (machineType.equals("0")) {
  216. query.nested(q -> q.isNull(TOrder::getMachineType).or()
  217. .eq(TOrder::getMachineType, machineType));
  218. } else {
  219. query.eq(TOrder::getMachineType, machineType);
  220. }
  221. }
  222. if (StringUtils.isNotEmpty(clientId)) {
  223. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  224. //判断机器是否属于这个登陆账号
  225. if (admin.getType() > 1) {
  226. //商家
  227. if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
  228. query.eq(TOrder::getEquipmentId, equipment.getId());
  229. }
  230. } else {
  231. query.eq(TOrder::getEquipmentId, equipment.getId());
  232. }
  233. }
  234. if (StringUtils.isNotEmpty(dateType)) {
  235. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  236. if (dateType.equals("0")) {
  237. //创建时间
  238. if (StringUtils.isNotEmpty(startDate)) {
  239. try {
  240. query.gt(TOrder::getCreateDate, simpleDateFormat.parse(startDate));
  241. } catch (ParseException e) {
  242. e.printStackTrace();
  243. }
  244. }
  245. if (StringUtils.isNotEmpty(endDate)) {
  246. try {
  247. query.lt(TOrder::getCreateDate, simpleDateFormat.parse(endDate));
  248. } catch (ParseException e) {
  249. e.printStackTrace();
  250. }
  251. }
  252. if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
  253. try {
  254. query.gt(TOrder::getCreateDate, getStartTime(new Date()));
  255. query.lt(TOrder::getCreateDate, getEndTime(new Date()));
  256. } catch (Exception e) {
  257. e.printStackTrace();
  258. }
  259. }
  260. }
  261. if (dateType.equals("1")) {
  262. //退款时间
  263. if (StringUtils.isNotEmpty(startDate)) {
  264. try {
  265. query.gt(TOrder::getRefundDate, simpleDateFormat.parse(startDate));
  266. } catch (ParseException e) {
  267. e.printStackTrace();
  268. }
  269. }
  270. if (StringUtils.isNotEmpty(endDate)) {
  271. try {
  272. query.lt(TOrder::getRefundDate, simpleDateFormat.parse(startDate));
  273. } catch (ParseException e) {
  274. e.printStackTrace();
  275. }
  276. }
  277. if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
  278. try {
  279. query.gt(TOrder::getRefundDate, getStartTime(new Date()));
  280. query.lt(TOrder::getRefundDate, getEndTime(new Date()));
  281. } catch (Exception e) {
  282. e.printStackTrace();
  283. }
  284. }
  285. }
  286. }
  287. query.orderByDesc(TOrder::getCreateDate);
  288. Page<TOrder> page = new Page<>(current, size, true);
  289. IPage<TOrder> iPage = orderService.page(page, query);
  290. IPage<OrderDetailsVo> pageList = new Page<>();
  291. //显示订单所属机器的设备名称
  292. List<TOrder> orderList = iPage.getRecords();
  293. List<OrderDetailsVo> orderDetailsVos = new ArrayList<>();
  294. if(orderList.size()>0){
  295. // 设备编号集合
  296. List<String> clientIds = new ArrayList<>();
  297. for (TOrder order : orderList) {
  298. clientIds.add(order.getClientId());
  299. }
  300. // 设备编号名称集合
  301. Map<String, String> equipmentMap = new HashMap<>();
  302. // 设备编号名称集合
  303. List<TEquipment> equipmentList = R.getDataIfSuccess(szwlFeign.findEquipmentByClientIds(clientIds));
  304. for (TEquipment equipment : equipmentList) {
  305. equipmentMap.put(equipment.getClientId(), equipment.getName());
  306. }
  307. // 设置设备信息到订单中
  308. for (TOrder order : orderList) {
  309. String name = equipmentMap.get(order.getClientId());
  310. if (StringUtils.isNotEmpty(name)) {
  311. order.setEs(name);
  312. }
  313. OrderDetailsVo orderDetailsVo = new OrderDetailsVo();
  314. BeanUtil.copyProperties(order, orderDetailsVo);
  315. LambdaQueryWrapper<TOrderDetails> queryWrapper = Wrappers.lambdaQuery();
  316. queryWrapper.eq(TOrderDetails::getOrderSn, order.getSn());
  317. List<TOrderDetails> orderDetailsList = orderDetailsService.list(queryWrapper);
  318. if(orderDetailsList != null) {
  319. orderDetailsVo.setOrderDetails(orderDetailsList);
  320. }
  321. orderDetailsVos.add(orderDetailsVo);
  322. }
  323. }
  324. pageList.setRecords(orderDetailsVos);
  325. pageList.setPages(iPage.getPages());
  326. pageList.setCurrent(iPage.getCurrent());
  327. pageList.setTotal(iPage.getTotal());
  328. pageList.setSize(iPage.getSize());
  329. return R.ok(pageList);
  330. };
  331. //1,海外
  332. if (type.equals("1")) {
  333. // 如果是线上 Airwallex
  334. // if ("1".equals(isAir)) {
  335. //
  336. // } else {
  337. //
  338. // }
  339. LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
  340. if (!userName.equals("admin")) {
  341. // 如果为账户
  342. if (admin.getType() > 2) {
  343. userName = null;
  344. }
  345. if (StringUtils.isNotEmpty(userName)) {
  346. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
  347. TAdmin data = adminByUsername.getData();
  348. if (data == null || data.getId() == null) {
  349. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  350. }
  351. query.eq(TCoinOrder::getAdminId, data.getId());
  352. } else {
  353. //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
  354. if (StringUtils.isNotEmpty(adminType)) {
  355. if (admin.getIsAdmined() && admin.getType() > 1) {
  356. if (admin.getType() > 1) {
  357. if (adminType.equals("all")) {
  358. //查找所有下级
  359. List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
  360. query.in(TCoinOrder::getAdminId, admidIdList);
  361. }
  362. }
  363. } else {
  364. if (admin.getType() > 1) {
  365. //登录账户为子账户 不查下级 只查对应机器的订单
  366. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  367. if (adminEquipment.getType().equals("0")) {
  368. //全部机器
  369. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  370. query.eq(TCoinOrder::getAdminId, upAdmin.getId());
  371. } else {
  372. String equipmentIds = adminEquipment.getEquipmentIds();
  373. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  374. query.in(TCoinOrder::getClientId, equipmentIdList);
  375. }
  376. }
  377. }
  378. } else {
  379. //判断当前账号状态 公司还是商家
  380. if (admin.getType() > 1) {
  381. //商家 判断是否子账户
  382. if (!admin.getIsAdmined()) {
  383. //商家自己
  384. // query.eq(TCoinOrder::getAdminId,adminId);
  385. // } else {
  386. //商家 子账户
  387. //登录账户为子账户 不查下级 只查对应机器的订单
  388. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(adminId)));
  389. if (adminEquipment.getType().equals("0")) {
  390. //全部机器
  391. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  392. query.eq(TCoinOrder::getAdminId, upAdmin.getId());
  393. } else {
  394. String equipmentIds = adminEquipment.getEquipmentIds();
  395. // List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  396. List<String> equipmentIdList = Arrays.asList(equipmentIds.split(","));
  397. query.in(TCoinOrder::getEquipmentId, equipmentIdList);
  398. }
  399. query.eq(TCoinOrder::getAdminId, admin.getParentId());
  400. }
  401. }
  402. }
  403. }
  404. }
  405. if (StringUtils.isNotEmpty(equipmentId)) {
  406. query.eq(TCoinOrder::getEquipmentId, equipmentId);
  407. }
  408. if (StringUtils.isNotEmpty(payType)) {
  409. query.eq(TCoinOrder::getPayType, payType);
  410. }
  411. if (StringUtils.isNotEmpty(productNo)) {
  412. query.eq(TCoinOrder::getProductNo, productNo);
  413. }
  414. // 公司平台
  415. // 申泽平台管理员
  416. if (admin.getId() == 2738) {
  417. companyType = "0";
  418. }
  419. // 七云平台管理员
  420. if (admin.getId() == 2739) {
  421. companyType = "1";
  422. }
  423. if (StringUtils.isNotEmpty(companyType)) {
  424. if (companyType.equals("0")) {
  425. String finalCompanyType = companyType;
  426. query.nested(q -> q.isNull(TCoinOrder::getCompanyType).or()
  427. .eq(TCoinOrder::getCompanyType, finalCompanyType));
  428. } else {
  429. query.eq(TCoinOrder::getCompanyType, companyType);
  430. }
  431. }
  432. // 棉花糖机型 + 爆米花机型
  433. if (StringUtils.isNotEmpty(machineType)) {
  434. if (machineType.equals("0")) {
  435. query.nested(q -> q.isNull(TCoinOrder::getMachineType).or()
  436. .eq(TCoinOrder::getMachineType, machineType));
  437. } else {
  438. query.eq(TCoinOrder::getMachineType, machineType);
  439. }
  440. }
  441. if (StringUtils.isNotEmpty(clientId)) {
  442. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  443. //判断机器是否属于这个登陆账号
  444. if (admin.getType() > 1) {
  445. //商家
  446. if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
  447. query.eq(TCoinOrder::getClientId, equipment.getClientId());
  448. }
  449. } else {
  450. query.eq(TCoinOrder::getClientId, equipment.getClientId());
  451. }
  452. }
  453. if (startDate != null) {
  454. query.gt(TCoinOrder::getPayDate, startDate);
  455. }
  456. if (endDate != null) {
  457. query.lt(TCoinOrder::getPayDate, endDate);
  458. }
  459. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  460. if (StringUtils.isNotEmpty(startDate)) {
  461. try {
  462. query.gt(TCoinOrder::getPayDate, simpleDateFormat.parse(startDate));
  463. } catch (ParseException e) {
  464. e.printStackTrace();
  465. }
  466. }
  467. if (StringUtils.isNotEmpty(endDate)) {
  468. try {
  469. query.lt(TCoinOrder::getPayDate, simpleDateFormat.parse(endDate));
  470. } catch (ParseException e) {
  471. e.printStackTrace();
  472. }
  473. }
  474. if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
  475. try {
  476. query.gt(TCoinOrder::getPayDate, getStartTime(new Date()));
  477. query.lt(TCoinOrder::getPayDate, getEndTime(new Date()));
  478. } catch (Exception e) {
  479. e.printStackTrace();
  480. }
  481. }
  482. query.orderByDesc(TCoinOrder::getCreateDate);
  483. Page<TCoinOrder> page = new Page<>(current, size, true);
  484. IPage<TCoinOrder> iPage = coinOrderService.page(page, query);
  485. //显示订单所属机器的设备名称
  486. if (admin.getType() != null && admin.getType() < 2) {
  487. //公司人员
  488. List<TCoinOrder> orderList = iPage.getRecords();
  489. if (orderList.size() > 0) {
  490. for (TCoinOrder order : orderList) {
  491. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  492. order.setEs(equipment.getName());
  493. }
  494. iPage.setRecords(orderList);
  495. }
  496. }
  497. if (admin.getType() != null && admin.getType() > 1) {
  498. //商家
  499. List<TCoinOrder> orderList = iPage.getRecords();
  500. if (orderList.size() > 0) {
  501. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(orderList.get(0).getClientId()));
  502. for (TCoinOrder order : orderList) {
  503. order.setEs(equipment.getName());
  504. }
  505. }
  506. iPage.setRecords(orderList);
  507. }
  508. return R.ok(iPage);
  509. }
  510. return R.ok();
  511. }
  512. @ApiOperation(value = "小程序获取订单")
  513. @PostMapping("/getOrderlist")
  514. public ResponseModel<IPage<?>> getOrderlist(@RequestBody TOrderParam param) {
  515. if (param.getWxId() == null || param.getCurrent() == null || param.getSize() == null) {
  516. return R.fail(ResponseCodesEnum.A0001);
  517. }
  518. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  519. query.eq(TOrder::getWxId, param.getWxId());
  520. query.eq(TOrder::getStatus, param.getStatus());
  521. query.orderByDesc(TOrder::getCreateDate);
  522. Page<TOrder> page = new Page<>(param.getCurrent(), param.getSize(), true);
  523. IPage<TOrder> iPage = orderService.page(page, query);
  524. return R.ok(iPage);
  525. }
  526. @ApiOperation(value = "取餐码")
  527. @PostMapping("/getMealCode")
  528. public ResponseModel<?> getMealCode(String sn) {
  529. if (StringUtils.isEmpty(sn)) {
  530. return R.fail(ResponseCodesEnum.A0001);
  531. }
  532. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  533. query.eq(TOrder::getSn, sn);
  534. query.eq(TOrder::getStatus, "1");
  535. List<TOrder> list = orderService.list(query);
  536. if (list.size() > 0) {
  537. TOrder tOrder = list.get(0);
  538. String s = tOrder.getId().toString();
  539. if (s.length() > 6) {
  540. s = s.substring(s.length() - 6, s.length());
  541. }
  542. return R.ok(s, "成功");
  543. }
  544. return R.fail(ResponseCodesEnum.A0001);
  545. }
  546. private String isForeignUser(String userId) {
  547. if (StringUtils.isNotEmpty(userId)) {
  548. try {
  549. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(userId));
  550. return admin.getIfForeign();
  551. } catch (NumberFormatException e) {
  552. }
  553. }
  554. return "0";
  555. }
  556. @ApiOperation(value = "获取首页数据统计")
  557. @PostMapping("/getStatistics")
  558. public ResponseEntity<?> getStatistics(@RequestBody StatisticsParam param) {
  559. // 判断是否为外国
  560. log.info("param:{}", param);
  561. String adminId = param.getAdminId();
  562. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(param.getAdminId()));
  563. if (admin.getType() < 2) {
  564. // 如果是超管或公司人员
  565. param.setAdminId(null);
  566. if (param.getEquipmentId() != null) {
  567. //查机器
  568. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
  569. param.setClientId(equipment.getClientId());
  570. }
  571. if (StringUtils.isNotEmpty(param.getClientId())) {
  572. //补全设备编号 clientId
  573. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
  574. param.setClientId(tEquipment.getClientId());
  575. }
  576. // 公司平台
  577. // 申泽平台管理员
  578. if (admin.getId() == 2738) {
  579. param.setCompanyType("0");
  580. }
  581. // 七云平台管理员
  582. if (admin.getId() == 2739) {
  583. param.setCompanyType("1");
  584. }
  585. } else {
  586. param.setIfForeign(isForeignUser(param.getAdminId()));
  587. if (admin.getType() == 2) {
  588. //商家
  589. if (param.getEquipmentId() != null && param.getEquipmentId() != "") {
  590. //查机器
  591. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
  592. param.setClientId(equipment.getClientId());
  593. }
  594. if (StringUtils.isNotEmpty(param.getClientId())) {
  595. // param.setAdminId(null);
  596. //判断是否是这个商家的
  597. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
  598. if (tEquipment.getAdminId().toString().equals(admin.getId().toString())) {
  599. param.setClientId(tEquipment.getClientId());
  600. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  601. }
  602. }
  603. }
  604. if (admin.getType() == 3) {
  605. //子账户只能查相对的机器的订单
  606. //商家子账户
  607. if (param.getEquipmentId() != null) {
  608. //查机器
  609. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
  610. param.setClientId(equipment.getClientId());
  611. } else {
  612. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  613. // 如果是全部机器
  614. if (!adminEquipment.getType().equals("0")) {
  615. // param.setAdminId(admin.getParentId().toString());
  616. // } else {
  617. // 查找属于这个商家子账户的设备
  618. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  619. param.setClientIds(list);
  620. if (StringUtils.isNotEmpty(adminEquipment.getEquipmentIds())) {
  621. List<String> strings = Arrays.asList(adminEquipment.getEquipmentIds().split(","));
  622. param.setEquipmentIds(strings);
  623. } else {
  624. return ResponseEntity
  625. .status(HttpStatus.OK)
  626. .body(new ResultMessage()
  627. .setCode(false)
  628. .setData(null)
  629. .setMessage("没有绑定机器/no machine"));
  630. }
  631. // param.setAdminId(null);
  632. }
  633. param.setAdminId(String.valueOf(admin.getParentId()));
  634. }
  635. if (StringUtils.isNotEmpty(param.getClientId())) {
  636. param.setAdminId(null);
  637. //判断是否是这个子账号的
  638. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
  639. // TODO 设置用户id为商家id
  640. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  641. if (adminEquipment.getType().equals("0")) {
  642. TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  643. if (tEquipment.getAdminId().toString().equals(admin1.getId())) {
  644. param.setAdminId(null);
  645. param.setClientId(tEquipment.getClientId());
  646. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  647. }
  648. } else {
  649. int i = 0;
  650. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  651. if (list.size() > 0) {
  652. for (String clientID : list) {
  653. if (clientID.equals(tEquipment.getClientId())) {
  654. i++;
  655. }
  656. }
  657. }
  658. if (i > 0) {
  659. param.setClientId(tEquipment.getClientId());
  660. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  661. }
  662. }
  663. }
  664. }
  665. }
  666. if (StringUtils.isNotEmpty(param.getUsername())) {
  667. if (param.getUsername().equals("all")) {
  668. //商家查全部
  669. //判断是不是商家账户
  670. if (admin.getType() == 2) {
  671. //查下级账户id集合
  672. List<Long> list = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
  673. if (list.size() > 0) {
  674. param.setAdminIds(list);
  675. param.setAdminId(null);
  676. }
  677. }
  678. }
  679. }
  680. FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
  681. ChartColumn chartColumn = new ChartColumn();
  682. if (StringUtils.isNotEmpty(param.getIfForeign()) && param.getIfForeign().equals("1")) {
  683. if (StringUtils.isNotEmpty(param.getPayType()) && param.getPayType().equals("all")) {
  684. param.setPayType(null);
  685. }
  686. //国外查MYSQL
  687. if (ElasticsearchRunner.ES_RUNNING) {
  688. try {
  689. // 查es
  690. chartColumn = esTOrderService.getStatistics(param);
  691. } catch (Exception e) {
  692. log.error("使用es 查询发生错误:{}", e);
  693. // 查 mysql
  694. // chartColumn = tOrderService.getStatistics(param);
  695. }
  696. } else {
  697. // 查 mysql
  698. // chartColumn = tOrderService.getStatistics(param);
  699. chartColumn = orderService.getStatistics(param);
  700. }
  701. } else {
  702. //查去年的数据找数据库
  703. String endDate = param.getEndDate();
  704. String toYear = "2023-01-01 00:00:00";
  705. Date date = null;
  706. Date year = null;
  707. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  708. try {
  709. //使用SimpleDateFormat的parse()方法生成Date
  710. date = sf.parse(endDate);
  711. year = sf.parse(toYear);
  712. } catch (ParseException e) {
  713. e.printStackTrace();
  714. }
  715. if (date.getTime() < year.getTime()) {
  716. chartColumn = orderService.getStatistics(param);
  717. } else {
  718. if (ElasticsearchRunner.ES_RUNNING) {
  719. try {
  720. // 查es
  721. chartColumn = esTOrderService.getStatistics(param);
  722. } catch (Exception e) {
  723. log.error("使用es 查询发生错误:{}", e);
  724. // 查 mysql
  725. // chartColumn = tOrderService.getStatistics(param);
  726. }
  727. } else {
  728. // 查 mysql
  729. // chartColumn = tOrderService.getStatistics(param);
  730. }
  731. }
  732. }
  733. return ResponseEntity
  734. .status(HttpStatus.OK)
  735. .body(new ResultMessage()
  736. .setCode(true)
  737. .setData(chartColumn)
  738. .setMessage("SUCCESS"));
  739. }
  740. /**
  741. * 统计 机器销售排行
  742. *
  743. * @param param
  744. * @return
  745. */
  746. @ApiOperation(value = "机器销售排行统计")
  747. @PostMapping("/getEquipmentStatistics")
  748. public ResponseEntity<?> getEquipmentStatistics(@RequestBody StatisticsParam param) {
  749. // 判断是否为外国
  750. param.setIfForeign(isForeignUser(param.getAdminId()));
  751. log.info("param:{}", param);
  752. FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
  753. String adminId = param.getAdminId();
  754. ChartColumn chartColumn = new ChartColumn();
  755. if (StringUtils.isNotEmpty(param.getAdminId())) {
  756. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(param.getAdminId())));
  757. // 申泽平台管理员
  758. if (admin.getId() == 2738) {
  759. param.setCompanyType("0");
  760. }
  761. // 七云平台管理员
  762. if (admin.getId() == 2739) {
  763. param.setCompanyType("1");
  764. }
  765. if (admin.getType() < 2) {
  766. param.setAdminId(null);
  767. } else {
  768. if (admin.getType() == 2) {
  769. //商家
  770. if (param.getEquipmentId() != null && param.getEquipmentId() != "") {
  771. //查机器
  772. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
  773. param.setClientId(equipment.getClientId());
  774. }
  775. if (StringUtils.isNotEmpty(param.getClientId())) {
  776. param.setAdminId(null);
  777. //判断是否是这个商家的
  778. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
  779. if (tEquipment.getAdminId().toString().equals(admin.getId().toString())) {
  780. param.setClientId(tEquipment.getClientId());
  781. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  782. }
  783. }
  784. }
  785. if (admin.getType() == 3) {
  786. //子账户只能查相对的机器的订单
  787. //商家子账户
  788. if (param.getEquipmentId() != null) {
  789. //查机器
  790. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
  791. param.setClientId(equipment.getClientId());
  792. } else {
  793. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  794. if (!adminEquipment.getType().equals("0")) {
  795. // TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  796. // param.setAdminId(admin1.getId().toString());
  797. // param.setAdminId(admin.getParentId().toString());
  798. // } else {
  799. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  800. param.setClientIds(list);
  801. if (StringUtils.isNotEmpty(adminEquipment.getEquipmentIds())) {
  802. List<String> strings = Arrays.asList(adminEquipment.getEquipmentIds().split(","));
  803. param.setEquipmentIds(strings);
  804. } else {
  805. return ResponseEntity
  806. .status(HttpStatus.OK)
  807. .body(new ResultMessage()
  808. .setCode(false)
  809. .setData(null)
  810. .setMessage("没有绑定机器/no machine"));
  811. }
  812. // param.setAdminId(null);
  813. }
  814. param.setAdminId(String.valueOf(admin.getParentId()));
  815. }
  816. if (StringUtils.isNotEmpty(param.getClientId())) {
  817. param.setAdminId(null);
  818. //判断是否是这个子账号的
  819. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
  820. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  821. if (adminEquipment.getType().equals("0")) {
  822. TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  823. if (tEquipment.getAdminId().toString().equals(admin1.getId())) {
  824. param.setAdminId(null);
  825. param.setClientId(tEquipment.getClientId());
  826. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  827. }
  828. } else {
  829. int i = 0;
  830. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  831. if (list.size() > 0) {
  832. for (String clientID : list) {
  833. if (clientID.equals(tEquipment.getClientId())) {
  834. i++;
  835. }
  836. }
  837. }
  838. if (i > 0) {
  839. param.setClientId(tEquipment.getClientId());
  840. param.setEquipmentId(String.valueOf(tEquipment.getId()));
  841. }
  842. }
  843. }
  844. }
  845. }
  846. }
  847. if (StringUtils.isNotEmpty(param.getIfForeign()) && param.getIfForeign().equals("1")) {
  848. //国外
  849. // chartColumn = orderService.getEquipmentStatistics(param);
  850. chartColumn = esTEquipmentService.getEquipmentStatistics(param);
  851. } else {
  852. //查去年的数据找数据库
  853. String endDate = param.getEndDate();
  854. String toYear = "2022-07-01 00:00:00";
  855. Date date = new Date();
  856. Date year = new Date();
  857. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  858. try {
  859. //使用SimpleDateFormat的parse()方法生成Date
  860. date = sf.parse(endDate);
  861. year = sf.parse(toYear);
  862. } catch (ParseException e) {
  863. e.printStackTrace();
  864. }
  865. if (date.getTime() < year.getTime()) {
  866. chartColumn = orderService.getEquipmentStatistics(param);
  867. } else {
  868. if (ElasticsearchRunner.ES_RUNNING) {
  869. try {
  870. // 查es
  871. chartColumn = esTEquipmentService.getEquipmentStatistics(param);
  872. } catch (Exception e) {
  873. log.error("使用es 查询发生错误:{}", e);
  874. // 查 mysql
  875. // chartColumn = tOrderService.getStatistics(param);
  876. }
  877. } else {
  878. // 查 mysql
  879. // chartColumn = tOrderService.getStatistics(param);
  880. }
  881. }
  882. // if (ElasticsearchRunner.ES_RUNNING) {
  883. // try {
  884. // // 查es
  885. // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
  886. // }catch (Exception e){
  887. // log.error("使用es 查询发生错误:{}",e);
  888. // // 查 mysql
  889. //// chartColumn = tOrderService.getEquipmentStatistics(param);
  890. // }
  891. // }else{
  892. // // 查 mysql
  893. //// chartColumn = tOrderService.getEquipmentStatistics(param);
  894. // }
  895. }
  896. // try {
  897. // // 查es
  898. // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
  899. // }catch (Exception e){
  900. // log.error("使用es 查询发生错误:{}",e);
  901. // // 查 mysql
  902. //// chartColumn = tOrderService.getEquipmentStatistics(param);
  903. // }
  904. // if (ElasticsearchRunner.ES_RUNNING) {
  905. // try {
  906. // // 查es
  907. // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
  908. // }catch (Exception e){
  909. // log.error("使用es 查询发生错误:{}",e);
  910. // // 查 mysql
  911. // chartColumn = tOrderService.getEquipmentStatistics(param);
  912. // }
  913. // }else{
  914. // // 查 mysql
  915. // chartColumn = tOrderService.getEquipmentStatistics(param);
  916. // }
  917. return ResponseEntity
  918. .status(HttpStatus.OK)
  919. .body(new ResultMessage()
  920. .setCode(true)
  921. .setData(chartColumn)
  922. .setMessage("SUCCESS"));
  923. }
  924. //查询线上订单
  925. @ApiOperation(value = "查询国内线上订单")
  926. @RequestMapping(value = "/findOrder", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  927. @ResponseBody
  928. public Object findOrder(String clientId, String sn, String productName, String status, String begin, String end, int pageNumber) {
  929. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  930. if (StringUtils.isNotEmpty(sn)) {
  931. query.like(TOrder::getSn, sn);
  932. }
  933. if (StringUtils.isNotEmpty(productName)) {
  934. query.like(TOrder::getProductName, productName);
  935. }
  936. if (StringUtils.isNotEmpty(status)) {
  937. if (status.equals("unpay")) {
  938. query.eq(TOrder::getStatus, 0);
  939. }
  940. if (status.equals("pay")) {
  941. query.eq(TOrder::getStatus, 1);
  942. }
  943. if (status.equals("refund")) {
  944. query.eq(TOrder::getStatus, 3);
  945. }
  946. }
  947. if (StringUtils.isNotEmpty(begin) && StringUtils.isNotEmpty(end)) {
  948. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
  949. try {
  950. //使用SimpleDateFormat的parse()方法生成Date
  951. query.gt(TOrder::getCreateDate, sf.parse(begin));
  952. query.lt(TOrder::getCreateDate, sf.parse(end));
  953. } catch (ParseException e) {
  954. e.printStackTrace();
  955. }
  956. }
  957. query.like(TOrder::getClientId, clientId);
  958. int size = 20;
  959. int current = pageNumber;
  960. Page<TOrder> page = new Page<>(current, size, true);
  961. IPage<TOrder> iPage = orderService.page(page, query);
  962. long total = page.getTotal();
  963. List<TOrder> content = iPage.getRecords();
  964. ArrayList<OrderVo> orderVos = new ArrayList<>();
  965. for (TOrder order : content) {
  966. OrderVo orderVo = new OrderVo();
  967. orderVo.setSn(order.getSn());
  968. orderVo.setProductName(order.getProductName());
  969. orderVo.setPrice(order.getPrice());
  970. orderVo.setTrxNo(order.getTrxNo());
  971. orderVo.setRefundTrxNo(order.getRefundTrxNo());
  972. orderVo.setRefundAmount(order.getRefundAmount());
  973. orderVo.setPayDate(order.getPayDate());
  974. orderVo.setRefundDate(order.getRefundDate());
  975. if (order.getStatus() == 0) {
  976. orderVo.setStatus(OrderVo.Status.unpay);
  977. }
  978. if (order.getStatus() == 1) {
  979. orderVo.setStatus(OrderVo.Status.pay);
  980. }
  981. if (order.getStatus() == 3) {
  982. orderVo.setStatus(OrderVo.Status.refund);
  983. }
  984. orderVo.setCreateDate(order.getCreateDate());
  985. orderVo.setFrp_code(order.getFrpCode());
  986. orderVos.add(orderVo);
  987. }
  988. JSONObject jsonObject = new JSONObject();
  989. jsonObject.put("total", total);
  990. jsonObject.put("orders", com.gexin.fastjson.JSON.toJSONString(orderVos));
  991. return jsonObject.toJSONString();
  992. }
  993. /**
  994. * 订单数据导出
  995. */
  996. @ApiOperation(value = "订单数据导出-查询")
  997. @RequestMapping(value = "/orderSelect", method = RequestMethod.GET)
  998. public ResponseModel<?> orderSelect(String type, String clientId, String username, String ifForeign,
  999. String companyType, String startDate, String endDate,
  1000. Long adminId, long current, long size) {
  1001. if (size > 100) {
  1002. return R.fail(ResponseCodesEnum.A0001, "请求数量过大");
  1003. }
  1004. Page<OrderDaoChuDTO> page0 = new Page<>(current, size, true);
  1005. page0.setSize(size);
  1006. page0.setCurrent(current);
  1007. if (adminId == 2738) {
  1008. companyType = "0";
  1009. }
  1010. if (adminId == 2739) {
  1011. companyType = "1";
  1012. }
  1013. if (startDate != null && endDate != null) {
  1014. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1015. Date begin = null;
  1016. Date end = null;
  1017. Long n_adminId = null;
  1018. try {
  1019. begin = simpleDateFormat.parse(startDate);
  1020. end = simpleDateFormat.parse(endDate);
  1021. } catch (ParseException e) {
  1022. e.printStackTrace();
  1023. }
  1024. long time = end.getTime() - begin.getTime();
  1025. if (time > 31 * 24 * 60 * 60 * 1000L) {
  1026. return R.fail(ResponseCodesEnum.A0001, "时间跨度过长");
  1027. }
  1028. if (!StringUtils.isEmpty(username)) {
  1029. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdminByUsername(username));
  1030. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(username);
  1031. TAdmin data = adminByUsername.getData();
  1032. if (data == null || data.getId() == null) {
  1033. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  1034. }
  1035. n_adminId = data.getId();
  1036. }
  1037. List<OrderDaoChuDTO> OrderDaoChuDTOList = new ArrayList<>();
  1038. if (ifForeign.equals("0")) {
  1039. //大陆
  1040. OrderDaoChuDTOList = orderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, current, size);
  1041. } else {
  1042. //查海外
  1043. OrderDaoChuDTOList = coinOrderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, current, size);
  1044. }
  1045. for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
  1046. String adminId1 = orderDaoChuDTO.getAdminId().toString();
  1047. ResponseModel<TAdmin> admin1 = szwlFeign.getAdmin(adminId1);
  1048. TAdmin admin = admin1.getData();
  1049. if (admin == null) {
  1050. continue;
  1051. }
  1052. orderDaoChuDTO.setPhone(admin.getPhone());
  1053. orderDaoChuDTO.setUsername(admin.getUsername());
  1054. orderDaoChuDTO.setName(admin.getName());
  1055. if (!StringUtils.isEmpty(type) && type.equals("2")) {
  1056. TArea area = areaService.getById(admin.getAreaId());
  1057. if (area != null) {
  1058. orderDaoChuDTO.setAddress(area.getFullName());
  1059. }
  1060. ResponseModel<List<String>> clientIds = szwlFeign.getClientIds(String.valueOf(admin.getId()));
  1061. List<String> stringList = clientIds.getData();
  1062. if (stringList != null && stringList.size() > 0) {
  1063. orderDaoChuDTO.setEquipmentTotal(String.valueOf(stringList.size()));
  1064. }
  1065. //商户为单位
  1066. ResponseModel<TAdmin> feignAdmin = szwlFeign.getAdmin(String.valueOf(admin.getParentId()));
  1067. TAdmin parent = feignAdmin.getData();
  1068. if (parent != null && parent.getId() != null) {
  1069. orderDaoChuDTO.setLastUsername(parent.getUsername());
  1070. }
  1071. } else {
  1072. //设备为单位
  1073. ResponseModel<TEquipment> equipmentByClientId = szwlFeign.findEquipmentByClientId(String.valueOf(orderDaoChuDTO.getClientId()));
  1074. TEquipment equipment = equipmentByClientId.getData();
  1075. if (equipment != null && equipment.getId() != null) {
  1076. if (StringUtils.isNotEmpty(equipment.getFullName())) {
  1077. orderDaoChuDTO.setAddress(equipment.getFullName());
  1078. }
  1079. orderDaoChuDTO.setEquipmentType(equipment.getEquimentType());
  1080. orderDaoChuDTO.setCreateDate(equipment.getCreateDate());
  1081. }
  1082. }
  1083. }
  1084. page0.setRecords(OrderDaoChuDTOList);
  1085. page0.setTotal(1000);
  1086. }
  1087. return R.ok(page0);
  1088. }
  1089. /**
  1090. * 订单数据导出
  1091. */
  1092. @ApiOperation(value = "订单数据导出-导出")
  1093. @RequestMapping(value = "/onlineExport", method = RequestMethod.GET)
  1094. @LogAnnotation(module = "模块名称:订单", operator = "操作参数:导出订单数据")
  1095. public Object onlineExport(HttpServletResponse response, String type, String clientId,
  1096. String ifForeign, String userName, String startDate,
  1097. String companyType, Long adminId,
  1098. String endDate, long current, long size) {
  1099. current = 1L;
  1100. size = 1000L;
  1101. if (adminId == 2738) {
  1102. companyType = "0";
  1103. }
  1104. if (adminId == 2739) {
  1105. companyType = "1";
  1106. }
  1107. if (startDate != null && endDate != null) {
  1108. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1109. Date begin = null;
  1110. Date end = null;
  1111. Long n_adminId = null;
  1112. try {
  1113. begin = simpleDateFormat.parse(startDate);
  1114. end = simpleDateFormat.parse(endDate);
  1115. } catch (ParseException e) {
  1116. e.printStackTrace();
  1117. }
  1118. long time = end.getTime() - begin.getTime();
  1119. if (time > 31 * 24 * 60 * 60 * 1000L) {
  1120. return JsonMessage.success("时间跨度过长");
  1121. }
  1122. if (!StringUtils.isEmpty(userName)) {
  1123. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
  1124. TAdmin data = adminByUsername.getData();
  1125. if (StringUtils.isEmpty(ifForeign)) {
  1126. ifForeign = data.getIfForeign();
  1127. }
  1128. if (data == null || data.getId() == null) {
  1129. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  1130. }
  1131. adminId = data.getId();
  1132. }
  1133. List<OrderDaoChuDTO> OrderDaoChuDTOList = new ArrayList<>();
  1134. if (ifForeign.equals("0")) {
  1135. //大陆
  1136. OrderDaoChuDTOList = orderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, current, size);
  1137. } else {
  1138. //查海外
  1139. OrderDaoChuDTOList = coinOrderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, current, size);
  1140. }
  1141. for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
  1142. String adminId1 = orderDaoChuDTO.getAdminId().toString();
  1143. ResponseModel<TAdmin> admin1 = szwlFeign.getAdmin(adminId1);
  1144. TAdmin admin = admin1.getData();
  1145. if (admin == null) {
  1146. continue;
  1147. }
  1148. orderDaoChuDTO.setPhone(admin.getPhone());
  1149. orderDaoChuDTO.setUsername(admin.getUsername());
  1150. orderDaoChuDTO.setName(admin.getName());
  1151. if (!StringUtils.isEmpty(type) && type.equals("2")) {
  1152. TArea area = areaService.getById(admin.getAreaId());
  1153. if (area != null) {
  1154. orderDaoChuDTO.setAddress(area.getFullName());
  1155. }
  1156. ResponseModel<List<String>> clientIds = szwlFeign.getClientIds(String.valueOf(admin.getId()));
  1157. List<String> stringList = clientIds.getData();
  1158. if (stringList != null && stringList.size() > 0) {
  1159. orderDaoChuDTO.setEquipmentTotal(String.valueOf(stringList.size()));
  1160. }
  1161. //商户为单位
  1162. ResponseModel<TAdmin> feignAdmin = szwlFeign.getAdmin(String.valueOf(admin.getParentId()));
  1163. TAdmin parent = feignAdmin.getData();
  1164. if (parent != null && parent.getId() != null) {
  1165. orderDaoChuDTO.setLastUsername(parent.getUsername());
  1166. }
  1167. } else {
  1168. //设备为单位
  1169. ResponseModel<TEquipment> equipmentByClientId = szwlFeign.findEquipmentByClientId(String.valueOf(orderDaoChuDTO.getClientId()));
  1170. TEquipment equipment = equipmentByClientId.getData();
  1171. if (equipment != null && equipment.getId() != null) {
  1172. if (StringUtils.isNotEmpty(equipment.getFullName())) {
  1173. orderDaoChuDTO.setAddress(equipment.getFullName());
  1174. }
  1175. orderDaoChuDTO.setEquipmentType(equipment.getEquimentType());
  1176. orderDaoChuDTO.setCreateDate(equipment.getCreateDate());
  1177. }
  1178. }
  1179. }
  1180. ExportParams exportParams = new ExportParams("订单记录", "sheet1");
  1181. Workbook workbook = null;
  1182. if (!StringUtils.isEmpty(type) && type.equals("2")) {
  1183. List<OrderByAdminTarget> orderByAdminTargetList = new ArrayList<>();
  1184. for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
  1185. OrderByAdminTarget orderByAdminTarget = new OrderByAdminTarget();
  1186. orderByAdminTarget.setUsername(orderDaoChuDTO.getUsername());
  1187. orderByAdminTarget.setAddress(orderDaoChuDTO.getAddress());
  1188. orderByAdminTarget.setEquipmentTotal(orderDaoChuDTO.getEquipmentTotal());
  1189. orderByAdminTarget.setLastUsername(orderDaoChuDTO.getLastUsername());
  1190. orderByAdminTarget.setPhone(orderDaoChuDTO.getPhone());
  1191. orderByAdminTarget.setPriceTotal(orderDaoChuDTO.getPriceTotal());
  1192. orderByAdminTarget.setName(orderDaoChuDTO.getName());
  1193. orderByAdminTargetList.add(orderByAdminTarget);
  1194. }
  1195. workbook = ExcelExportUtil.exportExcel(exportParams, OrderByAdminTarget.class, orderByAdminTargetList);
  1196. } else {
  1197. List<OrderByClientidTarget> orderByClientidTargetList = new ArrayList<>();
  1198. for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
  1199. OrderByClientidTarget orderByClientidTarget = new OrderByClientidTarget();
  1200. orderByClientidTarget.setAddress(orderDaoChuDTO.getAddress());
  1201. orderByClientidTarget.setClientId(orderDaoChuDTO.getClientId());
  1202. orderByClientidTarget.setCreateDate(orderDaoChuDTO.getCreateDate());
  1203. orderByClientidTarget.setEquipmentType(orderDaoChuDTO.getEquipmentType());
  1204. orderByClientidTarget.setName(orderDaoChuDTO.getName());
  1205. orderByClientidTarget.setPhone(orderDaoChuDTO.getPhone());
  1206. orderByClientidTarget.setPriceTotal(orderDaoChuDTO.getPriceTotal());
  1207. orderByClientidTarget.setUsername(orderDaoChuDTO.getUsername());
  1208. orderByClientidTargetList.add(orderByClientidTarget);
  1209. }
  1210. workbook = ExcelExportUtil.exportExcel(exportParams, OrderByClientidTarget.class, orderByClientidTargetList);
  1211. }
  1212. if (workbook != null) {
  1213. OutputStream os = null;
  1214. try {
  1215. os = response.getOutputStream();
  1216. SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
  1217. response.setContentType("application/vnd.ms-excel;charset=utf-8");
  1218. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
  1219. workbook.write(os);
  1220. return JsonMessage.success("导出成功");
  1221. } catch (Exception e) {
  1222. e.printStackTrace();
  1223. return JsonMessage.success("导出错误");
  1224. } finally {
  1225. try {
  1226. os.close();
  1227. workbook.close();
  1228. } catch (IOException e) {
  1229. e.printStackTrace();
  1230. }
  1231. }
  1232. }
  1233. }
  1234. return JsonMessage.success("导出成功");
  1235. }
  1236. @RequestMapping(value = "/orderExport", method = RequestMethod.GET)
  1237. public Object orderExport(HttpServletResponse response, String equipmentId, String adminId,
  1238. String adminType, String type, String status, String userName,
  1239. String payType, String productNo, String clientId, String dateType,
  1240. String startDate, String endDate, String companyType, String machineType,
  1241. long current, long size) throws ParseException {
  1242. current = 1L;
  1243. size = 1000L;
  1244. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1245. Date begin = null;
  1246. Date end = null;
  1247. try {
  1248. begin = simpleDateFormat.parse(startDate);
  1249. end = simpleDateFormat.parse(endDate);
  1250. } catch (ParseException e) {
  1251. e.printStackTrace();
  1252. }
  1253. long time = end.getTime() - begin.getTime();
  1254. if (time > 31 * 24 * 60 * 60 * 1000L) {
  1255. return JsonMessage.success("时间跨度过长");
  1256. }
  1257. //判断当前账号状态
  1258. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminId));
  1259. //类型
  1260. //0,线上
  1261. if (type.equals("0")) {
  1262. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  1263. if (!userName.equals("admin")) {
  1264. if (StringUtils.isNotEmpty(userName)) {
  1265. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
  1266. TAdmin data = adminByUsername.getData();
  1267. if (data == null || data.getId() == null) {
  1268. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  1269. }
  1270. if (data.getIsAdmined()) {
  1271. query.eq(TOrder::getAdminId, data.getId());
  1272. } else {
  1273. if (data.getParentId() != 1) {
  1274. query.eq(TOrder::getAdminId, data.getParentId());
  1275. //查找子账户所管理的机器
  1276. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
  1277. if (!adminEquipment.getType().equals("0")) {
  1278. List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
  1279. if (list == null || list.size() == 0) {
  1280. return R.fail(ResponseCodesEnum.A0001, "没有机器/no machine");
  1281. }
  1282. query.in(TOrder::getClientId, list);
  1283. }
  1284. }
  1285. }
  1286. } else {
  1287. //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
  1288. if (StringUtils.isNotEmpty(adminType)) {
  1289. if (admin.getIsAdmined() && admin.getType() > 1) {
  1290. if (admin.getType() > 1) {
  1291. if (adminType.equals("all")) {
  1292. //查找所有下级
  1293. List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
  1294. query.in(TOrder::getAdminId, admidIdList);
  1295. }
  1296. }
  1297. } else {
  1298. if (admin.getType() > 1) {
  1299. //登录账户为子账户 不查下级 只查对应机器的订单
  1300. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  1301. if (adminEquipment.getType().equals("0")) {
  1302. //全部机器
  1303. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  1304. query.eq(TOrder::getAdminId, upAdmin.getId());
  1305. } else {
  1306. String equipmentIds = adminEquipment.getEquipmentIds();
  1307. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  1308. query.in(TOrder::getClientId, equipmentIdList);
  1309. }
  1310. }
  1311. }
  1312. } else {
  1313. //判断当前账号状态 公司还是商家
  1314. if (admin.getType() > 1) {
  1315. //商家 判断是否子账户
  1316. if (admin.getIsAdmined()) {
  1317. //商家自己
  1318. query.eq(TOrder::getAdminId, adminId);
  1319. } else {
  1320. //商家 子账户
  1321. //登录账户为子账户 不查下级 只查对应机器的订单
  1322. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  1323. if (adminEquipment.getType().equals("0")) {
  1324. //全部机器
  1325. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  1326. query.eq(TOrder::getAdminId, upAdmin.getId());
  1327. } else {
  1328. String equipmentIds = adminEquipment.getEquipmentIds();
  1329. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  1330. query.in(TOrder::getClientId, equipmentIdList);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. if (StringUtils.isNotEmpty(payType)) {
  1338. query.eq(TOrder::getFrpCode, payType);
  1339. }
  1340. if (StringUtils.isNotEmpty(productNo)) {
  1341. query.eq(TOrder::getProductNo, productNo);
  1342. }
  1343. if (StringUtils.isNotEmpty(clientId)) {
  1344. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  1345. //判断机器是否属于这个登陆账号
  1346. if (admin.getType() > 1) {
  1347. //商家
  1348. if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
  1349. query.eq(TOrder::getEquipmentId, equipment.getId());
  1350. }
  1351. } else {
  1352. query.eq(TOrder::getEquipmentId, equipment.getId());
  1353. }
  1354. }
  1355. if (StringUtils.isNotEmpty(equipmentId)) {
  1356. query.eq(TOrder::getEquipmentId, equipmentId);
  1357. }
  1358. if (StringUtils.isNotEmpty(status)) {
  1359. query.eq(TOrder::getStatus, status);
  1360. }
  1361. if (StringUtils.isNotEmpty(dateType)) {
  1362. if (dateType.equals("0")) {
  1363. //创建时间
  1364. if (begin != null && end != null) {
  1365. query.gt(TOrder::getCreateDate, begin);
  1366. query.lt(TOrder::getCreateDate, end);
  1367. }
  1368. }
  1369. if (dateType.equals("1")) {
  1370. //退款时间
  1371. if (begin != null && end != null) {
  1372. query.gt(TOrder::getRefundDate, begin);
  1373. query.lt(TOrder::getRefundDate, end);
  1374. }
  1375. }
  1376. }
  1377. // 公司平台
  1378. // 申泽平台管理员
  1379. if (admin.getId() == 2738) {
  1380. companyType = "0";
  1381. }
  1382. // 七云平台管理员
  1383. if (admin.getId() == 2739) {
  1384. companyType = "1";
  1385. }
  1386. if (StringUtils.isNotEmpty(companyType)) {
  1387. if (companyType.equals("0")) {
  1388. String finalCompanyType = companyType;
  1389. query.nested(q -> q.isNull(TOrder::getCompanyType).or()
  1390. .eq(TOrder::getCompanyType, finalCompanyType));
  1391. } else {
  1392. query.eq(TOrder::getCompanyType, companyType);
  1393. }
  1394. }
  1395. if (StringUtils.isNotEmpty(machineType)) {
  1396. if (machineType.equals("0")) {
  1397. query.nested(q -> q.isNull(TOrder::getMachineType).or()
  1398. .eq(TOrder::getMachineType, machineType));
  1399. } else {
  1400. query.eq(TOrder::getMachineType, machineType);
  1401. }
  1402. }
  1403. Page<TOrder> page = new Page<>(current, size, true);
  1404. IPage<TOrder> iPage = orderService.page(page, query);
  1405. List<TOrder> list = iPage.getRecords();
  1406. List<OrderTarget> orderTargetList = orderService.findById(admin, list);
  1407. ExportParams exportParams = new ExportParams("订单记录", "sheet1");
  1408. Workbook workbook = ExcelExportUtil.exportExcel(exportParams, OrderTarget.class, orderTargetList);
  1409. if (workbook != null) {
  1410. OutputStream os = null;
  1411. try {
  1412. os = response.getOutputStream();
  1413. SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
  1414. response.setContentType("application/vnd.ms-excel;charset=utf-8");
  1415. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
  1416. workbook.write(os);
  1417. // return JsonMessage.success("导出成功");
  1418. } catch (Exception e) {
  1419. e.printStackTrace();
  1420. // return JsonMessage.success("导出错误");
  1421. } finally {
  1422. try {
  1423. os.close();
  1424. workbook.close();
  1425. } catch (IOException e) {
  1426. e.printStackTrace();
  1427. }
  1428. }
  1429. }
  1430. }
  1431. ;
  1432. //1,线下
  1433. if (type.equals("1")) {
  1434. LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
  1435. if (StringUtils.isNotEmpty(userName) && !userName.equals("admin")) {
  1436. ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
  1437. TAdmin data = adminByUsername.getData();
  1438. if (data == null || data.getId() == null) {
  1439. return R.fail(ResponseCodesEnum.A0001, "找不到商家");
  1440. }
  1441. query.eq(TCoinOrder::getAdminId, data.getId());
  1442. } else if (StringUtils.isEmpty(userName)) {
  1443. //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
  1444. if (StringUtils.isNotEmpty(adminType)) {
  1445. if (admin.getIsAdmined() && admin.getType() > 1) {
  1446. if (admin.getType() > 1) {
  1447. if (adminType.equals("all")) {
  1448. //查找所有下级
  1449. List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
  1450. query.in(TCoinOrder::getAdminId, admidIdList);
  1451. }
  1452. }
  1453. } else {
  1454. if (admin.getType() > 1) {
  1455. //登录账户为子账户 不查下级 只查对应机器的订单
  1456. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  1457. if (adminEquipment.getType().equals("0")) {
  1458. //全部机器
  1459. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  1460. query.eq(TCoinOrder::getAdminId, upAdmin.getId());
  1461. } else {
  1462. String equipmentIds = adminEquipment.getEquipmentIds();
  1463. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  1464. query.in(TCoinOrder::getClientId, equipmentIdList);
  1465. }
  1466. }
  1467. }
  1468. } else {
  1469. //判断当前账号状态 公司还是商家
  1470. if (admin.getType() > 1) {
  1471. //商家 判断是否子账户
  1472. if (admin.getIsAdmined()) {
  1473. //商家自己
  1474. query.eq(TCoinOrder::getAdminId, adminId);
  1475. } else {
  1476. //商家 子账户
  1477. //登录账户为子账户 不查下级 只查对应机器的订单
  1478. TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
  1479. if (adminEquipment.getType().equals("0")) {
  1480. //全部机器
  1481. TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
  1482. query.eq(TCoinOrder::getAdminId, upAdmin.getId());
  1483. } else {
  1484. String equipmentIds = adminEquipment.getEquipmentIds();
  1485. List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
  1486. query.in(TCoinOrder::getClientId, equipmentIdList);
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. if (StringUtils.isNotEmpty(payType)) {
  1493. query.eq(TCoinOrder::getPayType, payType);
  1494. }
  1495. if (StringUtils.isNotEmpty(productNo)) {
  1496. query.eq(TCoinOrder::getProductNo, productNo);
  1497. }
  1498. if (StringUtils.isNotEmpty(clientId)) {
  1499. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  1500. //判断机器是否属于这个登陆账号
  1501. if (admin.getType() > 1) {
  1502. //商家
  1503. if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
  1504. query.eq(TCoinOrder::getClientId, equipment.getClientId());
  1505. }
  1506. } else {
  1507. query.eq(TCoinOrder::getClientId, equipment.getClientId());
  1508. }
  1509. }
  1510. if (begin != null && end != null) {
  1511. query.gt(TCoinOrder::getPayDate, begin);
  1512. query.lt(TCoinOrder::getPayDate, end);
  1513. }
  1514. Page<TCoinOrder> page = new Page<>(current, size, true);
  1515. IPage<TCoinOrder> iPage = coinOrderService.page(page, query);
  1516. List<TCoinOrder> list = iPage.getRecords();
  1517. List<CoinOrderTarget> coinOrderTargets = coinOrderService.findByCoinOrder(admin, list);
  1518. ExportParams exportParams = new ExportParams("线下订单记录", "sheet1");
  1519. Workbook workbook = ExcelExportUtil.exportExcel(exportParams, CoinOrderTarget.class, coinOrderTargets);
  1520. if (workbook != null) {
  1521. OutputStream os = null;
  1522. try {
  1523. os = response.getOutputStream();
  1524. SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
  1525. response.setContentType("application/vnd.ms-excel;charset=utf-8");
  1526. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("线下订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
  1527. workbook.write(os);
  1528. return JsonMessage.success("导出成功");
  1529. } catch (Exception e) {
  1530. e.printStackTrace();
  1531. return JsonMessage.success("导出错误");
  1532. } finally {
  1533. try {
  1534. os.close();
  1535. workbook.close();
  1536. } catch (IOException e) {
  1537. e.printStackTrace();
  1538. }
  1539. }
  1540. }
  1541. }
  1542. return JsonMessage.success("导出错误");
  1543. }
  1544. @ApiOperation(value = "同步订单到es中")
  1545. @PostMapping("/saveToEs")
  1546. public ResponseModel<?> saveToEs(@RequestBody TOrder order) {
  1547. if (order == null) {
  1548. return R.fail(ResponseCodesEnum.A0001);
  1549. }
  1550. esTOrderService.insertData(order);
  1551. return R.ok("同步es成功");
  1552. }
  1553. /**
  1554. * 线上通过时间分组
  1555. *
  1556. * @param clientId
  1557. * @param startTime
  1558. * @param endTime
  1559. * @param unit
  1560. * @return
  1561. */
  1562. @RequestMapping(value = "/getStatisticsByClientId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  1563. @ResponseBody
  1564. public Object getStatisticsByClientId(String clientId, String startTime, String endTime, Integer unit) {
  1565. String date = "";
  1566. switch (unit) {
  1567. //按小时计算
  1568. case 0:
  1569. date = DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss;
  1570. break;
  1571. //按天
  1572. case 1:
  1573. date = DateUtils.PATTERN_yyyy_MM_dd;
  1574. break;
  1575. //按月
  1576. case 2:
  1577. date = DateUtils.PATTERN_yyyy_MM;
  1578. break;
  1579. //按年
  1580. case 3:
  1581. date = DateUtils.PATTERN_yyyy;
  1582. break;
  1583. }
  1584. SimpleDateFormat format = new SimpleDateFormat(date);
  1585. Date date1 = null;
  1586. Date date2 = null;
  1587. try {
  1588. date1 = format.parse(startTime);
  1589. date2 = format.parse(endTime);
  1590. } catch (ParseException e) {
  1591. e.printStackTrace();
  1592. }
  1593. List<OrderStatisticsDTO> list = orderService.findByTime(clientId, date1, date2, unit);
  1594. JSONObject jsonObject = new JSONObject();
  1595. jsonObject.put("code", 0);
  1596. jsonObject.put("data", JsonUtils.toJson(list));
  1597. jsonObject.put("errmsg", "");
  1598. return jsonObject;
  1599. }
  1600. /**
  1601. * 获取每天的开始时间 00:00:00:00
  1602. *
  1603. * @param date
  1604. * @return
  1605. */
  1606. public static Date getStartTime(Date date) {
  1607. Calendar dateStart = Calendar.getInstance();
  1608. dateStart.setTime(date);
  1609. dateStart.set(Calendar.HOUR_OF_DAY, 0);
  1610. dateStart.set(Calendar.MINUTE, 0);
  1611. dateStart.set(Calendar.SECOND, 0);
  1612. return dateStart.getTime();
  1613. }
  1614. /**
  1615. * 获取每天的时间 23:59:59:999
  1616. *
  1617. * @param date
  1618. * @return
  1619. */
  1620. public static Date getEndTime(Date date) {
  1621. Calendar dateEnd = Calendar.getInstance();
  1622. dateEnd.setTime(date);
  1623. dateEnd.set(Calendar.HOUR_OF_DAY, 23);
  1624. dateEnd.set(Calendar.MINUTE, 59);
  1625. dateEnd.set(Calendar.SECOND, 59);
  1626. return dateEnd.getTime();
  1627. }
  1628. }