12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691 |
- package com.szwl.controller;
- import cn.afterturn.easypoi.excel.ExcelExportUtil;
- import cn.afterturn.easypoi.excel.entity.ExportParams;
- import cn.com.crbank.ommo.bean.ResultMessage;
- import cn.com.crbank.ommo.esclient.ElasticsearchRunner;
- import cn.hutool.core.bean.BeanUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.szwl.common.aop.LogAnnotation;
- import com.szwl.constant.ResponseCodesEnum;
- import com.szwl.feign.SzwlFeign;
- import com.szwl.model.bean.ChartColumn;
- import com.szwl.model.bean.OrderDaoChuDTO;
- import com.szwl.model.bean.OrderDetailsVo;
- import com.szwl.model.bean.OrderVo;
- import com.szwl.model.bo.JsonMessage;
- import com.szwl.model.bo.R;
- import com.szwl.model.bo.ResponseModel;
- import com.szwl.model.entity.*;
- import com.szwl.model.excel.CoinOrderTarget;
- import com.szwl.model.excel.OrderByAdminTarget;
- import com.szwl.model.excel.OrderByClientidTarget;
- import com.szwl.model.excel.OrderTarget;
- import com.szwl.model.query.*;
- import com.szwl.model.utils.DateUtils;
- import com.szwl.model.utils.FgObjectUtil;
- import com.szwl.model.utils.JsonUtils;
- import com.szwl.service.*;
- import com.szwl.service.es.EsTEquipmentService;
- import com.szwl.service.es.EsTOrderService;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.URLEncoder;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author wuhs
- * @since 2022-06-14
- */
- @Slf4j
- @RestController
- @RequestMapping("/tOrder")
- public class TOrderController {
- @Autowired
- TOrderService orderService;
- @Autowired
- TEquipmentService equipmentService;
- @Autowired
- TAreaService areaService;
- @Autowired
- EsTOrderService esTOrderService;
- @Autowired
- EsTEquipmentService esTEquipmentService;
- @Autowired
- TCoinOrderService coinOrderService;
- @Autowired
- SzwlFeign szwlFeign;
- @Autowired
- TOrderDetailsService orderDetailsService;
- // 获取订单列表
- @GetMapping("/pageOrder")
- public ResponseModel<IPage<?>> pageOrder(String equipmentId, String adminId, String adminType,
- String type, String sn, String status, String userName,
- String payType, String productNo, String clientId,
- String trxNo, String dateType, String startDate,
- String companyType, String machineType, String endDate, long current, long size) {
- //判断当前账号状态
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminId));
- if (StringUtils.isEmpty(type)) {
- if (StringUtils.isNotEmpty(admin.getIfForeign())) {
- // 0 国内,1 海外
- type = admin.getIfForeign();
- } else {
- if (!admin.getIsAdmined()) {
- TAdmin parentDate = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- if (StringUtils.isNotEmpty(parentDate.getIfForeign())) {
- type = parentDate.getIfForeign();
- }
- }
- }
- }
- //类型
- //0,线上 -》 国内
- if (type.equals("0")) {
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- if (!userName.equals("admin")) {
- if (StringUtils.isNotEmpty(userName)) {
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
- TAdmin data = adminByUsername.getData();
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- if (data.getIsAdmined()) {
- query.eq(TOrder::getAdminId, data.getId());
- } else {
- if (data.getParentId() != 1) {
- query.eq(TOrder::getAdminId, data.getParentId());
- //查找子账户所管理的机器
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- if (!adminEquipment.getType().equals("0")) {
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- if (list == null || list.size() == 0) {
- return R.fail(ResponseCodesEnum.A0001, "没有机器/no machine");
- }
- query.in(TOrder::getClientId, list);
- }
- }
- }
- } else {
- //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
- if (StringUtils.isNotEmpty(adminType)) {
- if (admin.getIsAdmined() && admin.getType() > 1) {
- if (admin.getType() > 1) {
- if (adminType.equals("all")) {
- //查找所有下级
- List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
- query.in(TOrder::getAdminId, admidIdList);
- }
- }
- } else {
- if (admin.getType() > 1) {
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TOrder::getClientId, equipmentIdList);
- }
- }
- }
- } else {
- //判断当前账号状态 公司还是商家
- if (admin.getType() > 1) {
- //商家 判断是否子账户
- if (admin.getIsAdmined()) {
- //商家自己
- query.eq(TOrder::getAdminId, adminId);
- } else {
- //商家 子账户
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TOrder::getClientId, equipmentIdList);
- }
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(equipmentId)) {
- query.eq(TOrder::getEquipmentId, equipmentId);
- }
- if (StringUtils.isNotEmpty(payType)) {
- query.eq(TOrder::getFrpCode, payType);
- }
- if (StringUtils.isNotEmpty(productNo)) {
- query.eq(TOrder::getProductNo, productNo);
- }
- if (StringUtils.isNotEmpty(sn)) {
- query.like(TOrder::getSn, sn);
- }
- if (StringUtils.isNotEmpty(trxNo)) {
- query.like(TOrder::getTrxNo, trxNo);
- }
- if (StringUtils.isNotEmpty(status)) {
- query.eq(TOrder::getStatus, status);
- }
- // 公司平台
- // 申泽平台管理员
- if (admin.getId() == 2738) {
- companyType = "0";
- }
- // 七云平台管理员
- if (admin.getId() == 2739) {
- companyType = "1";
- }
- if (StringUtils.isNotEmpty(companyType)) {
- if (companyType.equals("0")) {
- String finalCompanyType = companyType;
- query.nested(q -> q.isNull(TOrder::getCompanyType).or()
- .eq(TOrder::getCompanyType, finalCompanyType));
- } else {
- query.eq(TOrder::getCompanyType, companyType);
- }
- }
- if (StringUtils.isNotEmpty(machineType)) {
- if (machineType.equals("0")) {
- query.nested(q -> q.isNull(TOrder::getMachineType).or()
- .eq(TOrder::getMachineType, machineType));
- } else {
- query.eq(TOrder::getMachineType, machineType);
- }
- }
- if (StringUtils.isNotEmpty(clientId)) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- //判断机器是否属于这个登陆账号
- if (admin.getType() > 1) {
- //商家
- if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
- query.eq(TOrder::getEquipmentId, equipment.getId());
- }
- } else {
- query.eq(TOrder::getEquipmentId, equipment.getId());
- }
- }
- if (StringUtils.isNotEmpty(dateType)) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (dateType.equals("0")) {
- //创建时间
- if (StringUtils.isNotEmpty(startDate)) {
- try {
- query.gt(TOrder::getCreateDate, simpleDateFormat.parse(startDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isNotEmpty(endDate)) {
- try {
- query.lt(TOrder::getCreateDate, simpleDateFormat.parse(endDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
- try {
- query.gt(TOrder::getCreateDate, getStartTime(new Date()));
- query.lt(TOrder::getCreateDate, getEndTime(new Date()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- if (dateType.equals("1")) {
- //退款时间
- if (StringUtils.isNotEmpty(startDate)) {
- try {
- query.gt(TOrder::getRefundDate, simpleDateFormat.parse(startDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isNotEmpty(endDate)) {
- try {
- query.lt(TOrder::getRefundDate, simpleDateFormat.parse(startDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
- try {
- query.gt(TOrder::getRefundDate, getStartTime(new Date()));
- query.lt(TOrder::getRefundDate, getEndTime(new Date()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- query.orderByDesc(TOrder::getCreateDate);
- Page<TOrder> page = new Page<>(current, size, true);
- IPage<TOrder> iPage = orderService.page(page, query);
- IPage<OrderDetailsVo> pageList = new Page<>();
- //显示订单所属机器的设备名称
- List<TOrder> orderList = iPage.getRecords();
- List<OrderDetailsVo> orderDetailsVos = new ArrayList<>();
- if(orderList.size()>0){
- // 设备编号集合
- List<String> clientIds = new ArrayList<>();
- for (TOrder order : orderList) {
- clientIds.add(order.getClientId());
- }
- // 设备编号名称集合
- Map<String, String> equipmentMap = new HashMap<>();
- // 设备编号名称集合
- List<TEquipment> equipmentList = R.getDataIfSuccess(szwlFeign.findEquipmentByClientIds(clientIds));
- for (TEquipment equipment : equipmentList) {
- equipmentMap.put(equipment.getClientId(), equipment.getName());
- }
- // 设置设备信息到订单中
- for (TOrder order : orderList) {
- String name = equipmentMap.get(order.getClientId());
- if (StringUtils.isNotEmpty(name)) {
- order.setEs(name);
- }
- OrderDetailsVo orderDetailsVo = new OrderDetailsVo();
- BeanUtil.copyProperties(order, orderDetailsVo);
- LambdaQueryWrapper<TOrderDetails> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(TOrderDetails::getOrderSn, order.getSn());
- List<TOrderDetails> orderDetailsList = orderDetailsService.list(queryWrapper);
- if(orderDetailsList != null) {
- orderDetailsVo.setOrderDetails(orderDetailsList);
- }
- orderDetailsVos.add(orderDetailsVo);
- }
- }
- pageList.setRecords(orderDetailsVos);
- pageList.setPages(iPage.getPages());
- pageList.setCurrent(iPage.getCurrent());
- pageList.setTotal(iPage.getTotal());
- pageList.setSize(iPage.getSize());
- return R.ok(pageList);
- };
- //1,海外
- if (type.equals("1")) {
- // 如果是线上 Airwallex
- // if ("1".equals(isAir)) {
- //
- // } else {
- //
- // }
- LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
- if (!userName.equals("admin")) {
- // 如果为账户
- if (admin.getType() > 2) {
- userName = null;
- }
- if (StringUtils.isNotEmpty(userName)) {
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
- TAdmin data = adminByUsername.getData();
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- query.eq(TCoinOrder::getAdminId, data.getId());
- } else {
- //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
- if (StringUtils.isNotEmpty(adminType)) {
- if (admin.getIsAdmined() && admin.getType() > 1) {
- if (admin.getType() > 1) {
- if (adminType.equals("all")) {
- //查找所有下级
- List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
- query.in(TCoinOrder::getAdminId, admidIdList);
- }
- }
- } else {
- if (admin.getType() > 1) {
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TCoinOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TCoinOrder::getClientId, equipmentIdList);
- }
- }
- }
- } else {
- //判断当前账号状态 公司还是商家
- if (admin.getType() > 1) {
- //商家 判断是否子账户
- if (!admin.getIsAdmined()) {
- //商家自己
- // query.eq(TCoinOrder::getAdminId,adminId);
- // } else {
- //商家 子账户
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(adminId)));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TCoinOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- // List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- List<String> equipmentIdList = Arrays.asList(equipmentIds.split(","));
- query.in(TCoinOrder::getEquipmentId, equipmentIdList);
- }
- query.eq(TCoinOrder::getAdminId, admin.getParentId());
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(equipmentId)) {
- query.eq(TCoinOrder::getEquipmentId, equipmentId);
- }
- if (StringUtils.isNotEmpty(payType)) {
- query.eq(TCoinOrder::getPayType, payType);
- }
- if (StringUtils.isNotEmpty(productNo)) {
- query.eq(TCoinOrder::getProductNo, productNo);
- }
- // 公司平台
- // 申泽平台管理员
- if (admin.getId() == 2738) {
- companyType = "0";
- }
- // 七云平台管理员
- if (admin.getId() == 2739) {
- companyType = "1";
- }
- if (StringUtils.isNotEmpty(companyType)) {
- if (companyType.equals("0")) {
- String finalCompanyType = companyType;
- query.nested(q -> q.isNull(TCoinOrder::getCompanyType).or()
- .eq(TCoinOrder::getCompanyType, finalCompanyType));
- } else {
- query.eq(TCoinOrder::getCompanyType, companyType);
- }
- }
- // 棉花糖机型 + 爆米花机型
- if (StringUtils.isNotEmpty(machineType)) {
- if (machineType.equals("0")) {
- query.nested(q -> q.isNull(TCoinOrder::getMachineType).or()
- .eq(TCoinOrder::getMachineType, machineType));
- } else {
- query.eq(TCoinOrder::getMachineType, machineType);
- }
- }
- if (StringUtils.isNotEmpty(clientId)) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- //判断机器是否属于这个登陆账号
- if (admin.getType() > 1) {
- //商家
- if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
- query.eq(TCoinOrder::getClientId, equipment.getClientId());
- }
- } else {
- query.eq(TCoinOrder::getClientId, equipment.getClientId());
- }
- }
- if (startDate != null) {
- query.gt(TCoinOrder::getPayDate, startDate);
- }
- if (endDate != null) {
- query.lt(TCoinOrder::getPayDate, endDate);
- }
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (StringUtils.isNotEmpty(startDate)) {
- try {
- query.gt(TCoinOrder::getPayDate, simpleDateFormat.parse(startDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isNotEmpty(endDate)) {
- try {
- query.lt(TCoinOrder::getPayDate, simpleDateFormat.parse(endDate));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- if (StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate) && StringUtils.isEmpty(sn) && StringUtils.isEmpty(trxNo) && StringUtils.isEmpty(clientId) && StringUtils.isEmpty(userName)) {
- try {
- query.gt(TCoinOrder::getPayDate, getStartTime(new Date()));
- query.lt(TCoinOrder::getPayDate, getEndTime(new Date()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- query.orderByDesc(TCoinOrder::getCreateDate);
- Page<TCoinOrder> page = new Page<>(current, size, true);
- IPage<TCoinOrder> iPage = coinOrderService.page(page, query);
- //显示订单所属机器的设备名称
- if (admin.getType() != null && admin.getType() < 2) {
- //公司人员
- List<TCoinOrder> orderList = iPage.getRecords();
- if (orderList.size() > 0) {
- for (TCoinOrder order : orderList) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- order.setEs(equipment.getName());
- }
- iPage.setRecords(orderList);
- }
- }
- if (admin.getType() != null && admin.getType() > 1) {
- //商家
- List<TCoinOrder> orderList = iPage.getRecords();
- if (orderList.size() > 0) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(orderList.get(0).getClientId()));
- for (TCoinOrder order : orderList) {
- order.setEs(equipment.getName());
- }
- }
- iPage.setRecords(orderList);
- }
- return R.ok(iPage);
- }
- return R.ok();
- }
- @ApiOperation(value = "小程序获取订单")
- @PostMapping("/getOrderlist")
- public ResponseModel<IPage<?>> getOrderlist(@RequestBody TOrderParam param) {
- if (param.getWxId() == null || param.getCurrent() == null || param.getSize() == null) {
- return R.fail(ResponseCodesEnum.A0001);
- }
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getWxId, param.getWxId());
- query.eq(TOrder::getStatus, param.getStatus());
- query.orderByDesc(TOrder::getCreateDate);
- Page<TOrder> page = new Page<>(param.getCurrent(), param.getSize(), true);
- IPage<TOrder> iPage = orderService.page(page, query);
- return R.ok(iPage);
- }
- @ApiOperation(value = "取餐码")
- @PostMapping("/getMealCode")
- public ResponseModel<?> getMealCode(String sn) {
- if (StringUtils.isEmpty(sn)) {
- return R.fail(ResponseCodesEnum.A0001);
- }
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- query.eq(TOrder::getStatus, "1");
- List<TOrder> list = orderService.list(query);
- if (list.size() > 0) {
- TOrder tOrder = list.get(0);
- String s = tOrder.getId().toString();
- if (s.length() > 6) {
- s = s.substring(s.length() - 6, s.length());
- }
- return R.ok(s, "成功");
- }
- return R.fail(ResponseCodesEnum.A0001);
- }
- private String isForeignUser(String userId) {
- if (StringUtils.isNotEmpty(userId)) {
- try {
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(userId));
- return admin.getIfForeign();
- } catch (NumberFormatException e) {
- }
- }
- return "0";
- }
- @ApiOperation(value = "获取首页数据统计")
- @PostMapping("/getStatistics")
- public ResponseEntity<?> getStatistics(@RequestBody StatisticsParam param) {
- // 判断是否为外国
- log.info("param:{}", param);
- String adminId = param.getAdminId();
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(param.getAdminId()));
- if (admin.getType() < 2) {
- // 如果是超管或公司人员
- param.setAdminId(null);
- if (param.getEquipmentId() != null) {
- //查机器
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
- param.setClientId(equipment.getClientId());
- }
- if (StringUtils.isNotEmpty(param.getClientId())) {
- //补全设备编号 clientId
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
- param.setClientId(tEquipment.getClientId());
- }
- // 公司平台
- // 申泽平台管理员
- if (admin.getId() == 2738) {
- param.setCompanyType("0");
- }
- // 七云平台管理员
- if (admin.getId() == 2739) {
- param.setCompanyType("1");
- }
- } else {
- param.setIfForeign(isForeignUser(param.getAdminId()));
- if (admin.getType() == 2) {
- //商家
- if (param.getEquipmentId() != null && param.getEquipmentId() != "") {
- //查机器
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
- param.setClientId(equipment.getClientId());
- }
- if (StringUtils.isNotEmpty(param.getClientId())) {
- // param.setAdminId(null);
- //判断是否是这个商家的
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
- if (tEquipment.getAdminId().toString().equals(admin.getId().toString())) {
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- }
- }
- if (admin.getType() == 3) {
- //子账户只能查相对的机器的订单
- //商家子账户
- if (param.getEquipmentId() != null) {
- //查机器
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
- param.setClientId(equipment.getClientId());
- } else {
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- // 如果是全部机器
- if (!adminEquipment.getType().equals("0")) {
- // param.setAdminId(admin.getParentId().toString());
- // } else {
- // 查找属于这个商家子账户的设备
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- param.setClientIds(list);
- if (StringUtils.isNotEmpty(adminEquipment.getEquipmentIds())) {
- List<String> strings = Arrays.asList(adminEquipment.getEquipmentIds().split(","));
- param.setEquipmentIds(strings);
- } else {
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(false)
- .setData(null)
- .setMessage("没有绑定机器/no machine"));
- }
- // param.setAdminId(null);
- }
- param.setAdminId(String.valueOf(admin.getParentId()));
- }
- if (StringUtils.isNotEmpty(param.getClientId())) {
- param.setAdminId(null);
- //判断是否是这个子账号的
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
- // TODO 设置用户id为商家id
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- if (adminEquipment.getType().equals("0")) {
- TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- if (tEquipment.getAdminId().toString().equals(admin1.getId())) {
- param.setAdminId(null);
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- } else {
- int i = 0;
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- if (list.size() > 0) {
- for (String clientID : list) {
- if (clientID.equals(tEquipment.getClientId())) {
- i++;
- }
- }
- }
- if (i > 0) {
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(param.getUsername())) {
- if (param.getUsername().equals("all")) {
- //商家查全部
- //判断是不是商家账户
- if (admin.getType() == 2) {
- //查下级账户id集合
- List<Long> list = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
- if (list.size() > 0) {
- param.setAdminIds(list);
- param.setAdminId(null);
- }
- }
- }
- }
- FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
- ChartColumn chartColumn = new ChartColumn();
- if (StringUtils.isNotEmpty(param.getIfForeign()) && param.getIfForeign().equals("1")) {
- if (StringUtils.isNotEmpty(param.getPayType()) && param.getPayType().equals("all")) {
- param.setPayType(null);
- }
- //国外查MYSQL
- if (ElasticsearchRunner.ES_RUNNING) {
- try {
- // 查es
- chartColumn = esTOrderService.getStatistics(param);
- } catch (Exception e) {
- log.error("使用es 查询发生错误:{}", e);
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- }
- } else {
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- chartColumn = orderService.getStatistics(param);
- }
- } else {
- //查去年的数据找数据库
- String endDate = param.getEndDate();
- String toYear = "2023-01-01 00:00:00";
- Date date = null;
- Date year = null;
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- //使用SimpleDateFormat的parse()方法生成Date
- date = sf.parse(endDate);
- year = sf.parse(toYear);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- if (date.getTime() < year.getTime()) {
- chartColumn = orderService.getStatistics(param);
- } else {
- if (ElasticsearchRunner.ES_RUNNING) {
- try {
- // 查es
- chartColumn = esTOrderService.getStatistics(param);
- } catch (Exception e) {
- log.error("使用es 查询发生错误:{}", e);
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- }
- } else {
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- }
- }
- }
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData(chartColumn)
- .setMessage("SUCCESS"));
- }
- /**
- * 统计 机器销售排行
- *
- * @param param
- * @return
- */
- @ApiOperation(value = "机器销售排行统计")
- @PostMapping("/getEquipmentStatistics")
- public ResponseEntity<?> getEquipmentStatistics(@RequestBody StatisticsParam param) {
- // 判断是否为外国
- param.setIfForeign(isForeignUser(param.getAdminId()));
- log.info("param:{}", param);
- FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
- String adminId = param.getAdminId();
- ChartColumn chartColumn = new ChartColumn();
- if (StringUtils.isNotEmpty(param.getAdminId())) {
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(param.getAdminId())));
- // 申泽平台管理员
- if (admin.getId() == 2738) {
- param.setCompanyType("0");
- }
- // 七云平台管理员
- if (admin.getId() == 2739) {
- param.setCompanyType("1");
- }
- if (admin.getType() < 2) {
- param.setAdminId(null);
- } else {
- if (admin.getType() == 2) {
- //商家
- if (param.getEquipmentId() != null && param.getEquipmentId() != "") {
- //查机器
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
- param.setClientId(equipment.getClientId());
- }
- if (StringUtils.isNotEmpty(param.getClientId())) {
- param.setAdminId(null);
- //判断是否是这个商家的
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
- if (tEquipment.getAdminId().toString().equals(admin.getId().toString())) {
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- }
- }
- if (admin.getType() == 3) {
- //子账户只能查相对的机器的订单
- //商家子账户
- if (param.getEquipmentId() != null) {
- //查机器
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
- param.setClientId(equipment.getClientId());
- } else {
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- if (!adminEquipment.getType().equals("0")) {
- // TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- // param.setAdminId(admin1.getId().toString());
- // param.setAdminId(admin.getParentId().toString());
- // } else {
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- param.setClientIds(list);
- if (StringUtils.isNotEmpty(adminEquipment.getEquipmentIds())) {
- List<String> strings = Arrays.asList(adminEquipment.getEquipmentIds().split(","));
- param.setEquipmentIds(strings);
- } else {
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(false)
- .setData(null)
- .setMessage("没有绑定机器/no machine"));
- }
- // param.setAdminId(null);
- }
- param.setAdminId(String.valueOf(admin.getParentId()));
- }
- if (StringUtils.isNotEmpty(param.getClientId())) {
- param.setAdminId(null);
- //判断是否是这个子账号的
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- if (adminEquipment.getType().equals("0")) {
- TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- if (tEquipment.getAdminId().toString().equals(admin1.getId())) {
- param.setAdminId(null);
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- } else {
- int i = 0;
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- if (list.size() > 0) {
- for (String clientID : list) {
- if (clientID.equals(tEquipment.getClientId())) {
- i++;
- }
- }
- }
- if (i > 0) {
- param.setClientId(tEquipment.getClientId());
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
- }
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(param.getIfForeign()) && param.getIfForeign().equals("1")) {
- //国外
- // chartColumn = orderService.getEquipmentStatistics(param);
- chartColumn = esTEquipmentService.getEquipmentStatistics(param);
- } else {
- //查去年的数据找数据库
- String endDate = param.getEndDate();
- String toYear = "2022-07-01 00:00:00";
- Date date = new Date();
- Date year = new Date();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- //使用SimpleDateFormat的parse()方法生成Date
- date = sf.parse(endDate);
- year = sf.parse(toYear);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- if (date.getTime() < year.getTime()) {
- chartColumn = orderService.getEquipmentStatistics(param);
- } else {
- if (ElasticsearchRunner.ES_RUNNING) {
- try {
- // 查es
- chartColumn = esTEquipmentService.getEquipmentStatistics(param);
- } catch (Exception e) {
- log.error("使用es 查询发生错误:{}", e);
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- }
- } else {
- // 查 mysql
- // chartColumn = tOrderService.getStatistics(param);
- }
- }
- // if (ElasticsearchRunner.ES_RUNNING) {
- // try {
- // // 查es
- // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
- // }catch (Exception e){
- // log.error("使用es 查询发生错误:{}",e);
- // // 查 mysql
- //// chartColumn = tOrderService.getEquipmentStatistics(param);
- // }
- // }else{
- // // 查 mysql
- //// chartColumn = tOrderService.getEquipmentStatistics(param);
- // }
- }
- // try {
- // // 查es
- // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
- // }catch (Exception e){
- // log.error("使用es 查询发生错误:{}",e);
- // // 查 mysql
- //// chartColumn = tOrderService.getEquipmentStatistics(param);
- // }
- // if (ElasticsearchRunner.ES_RUNNING) {
- // try {
- // // 查es
- // chartColumn = esTEquipmentService.getEquipmentStatistics(param);
- // }catch (Exception e){
- // log.error("使用es 查询发生错误:{}",e);
- // // 查 mysql
- // chartColumn = tOrderService.getEquipmentStatistics(param);
- // }
- // }else{
- // // 查 mysql
- // chartColumn = tOrderService.getEquipmentStatistics(param);
- // }
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData(chartColumn)
- .setMessage("SUCCESS"));
- }
- //查询线上订单
- @ApiOperation(value = "查询国内线上订单")
- @RequestMapping(value = "/findOrder", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public Object findOrder(String clientId, String sn, String productName, String status, String begin, String end, int pageNumber) {
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- if (StringUtils.isNotEmpty(sn)) {
- query.like(TOrder::getSn, sn);
- }
- if (StringUtils.isNotEmpty(productName)) {
- query.like(TOrder::getProductName, productName);
- }
- if (StringUtils.isNotEmpty(status)) {
- if (status.equals("unpay")) {
- query.eq(TOrder::getStatus, 0);
- }
- if (status.equals("pay")) {
- query.eq(TOrder::getStatus, 1);
- }
- if (status.equals("refund")) {
- query.eq(TOrder::getStatus, 3);
- }
- }
- if (StringUtils.isNotEmpty(begin) && StringUtils.isNotEmpty(end)) {
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- try {
- //使用SimpleDateFormat的parse()方法生成Date
- query.gt(TOrder::getCreateDate, sf.parse(begin));
- query.lt(TOrder::getCreateDate, sf.parse(end));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- query.like(TOrder::getClientId, clientId);
- int size = 20;
- int current = pageNumber;
- Page<TOrder> page = new Page<>(current, size, true);
- IPage<TOrder> iPage = orderService.page(page, query);
- long total = page.getTotal();
- List<TOrder> content = iPage.getRecords();
- ArrayList<OrderVo> orderVos = new ArrayList<>();
- for (TOrder order : content) {
- OrderVo orderVo = new OrderVo();
- orderVo.setSn(order.getSn());
- orderVo.setProductName(order.getProductName());
- orderVo.setPrice(order.getPrice());
- orderVo.setTrxNo(order.getTrxNo());
- orderVo.setRefundTrxNo(order.getRefundTrxNo());
- orderVo.setRefundAmount(order.getRefundAmount());
- orderVo.setPayDate(order.getPayDate());
- orderVo.setRefundDate(order.getRefundDate());
- if (order.getStatus() == 0) {
- orderVo.setStatus(OrderVo.Status.unpay);
- }
- if (order.getStatus() == 1) {
- orderVo.setStatus(OrderVo.Status.pay);
- }
- if (order.getStatus() == 3) {
- orderVo.setStatus(OrderVo.Status.refund);
- }
- orderVo.setCreateDate(order.getCreateDate());
- orderVo.setFrp_code(order.getFrpCode());
- orderVos.add(orderVo);
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("total", total);
- jsonObject.put("orders", com.gexin.fastjson.JSON.toJSONString(orderVos));
- return jsonObject.toJSONString();
- }
- /**
- * 订单数据导出
- */
- @ApiOperation(value = "订单数据导出-查询")
- @RequestMapping(value = "/orderSelect", method = RequestMethod.GET)
- public ResponseModel<?> orderSelect(String type, String clientId, String username, String ifForeign,
- String companyType, String startDate, String endDate,
- Long adminId, long current, long size) {
- if (size > 100) {
- return R.fail(ResponseCodesEnum.A0001, "请求数量过大");
- }
- Page<OrderDaoChuDTO> page0 = new Page<>(current, size, true);
- page0.setSize(size);
- page0.setCurrent(current);
- if (adminId == 2738) {
- companyType = "0";
- }
- if (adminId == 2739) {
- companyType = "1";
- }
- if (startDate != null && endDate != null) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date begin = null;
- Date end = null;
- Long n_adminId = null;
- try {
- begin = simpleDateFormat.parse(startDate);
- end = simpleDateFormat.parse(endDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- long time = end.getTime() - begin.getTime();
- if (time > 31 * 24 * 60 * 60 * 1000L) {
- return R.fail(ResponseCodesEnum.A0001, "时间跨度过长");
- }
- if (!StringUtils.isEmpty(username)) {
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdminByUsername(username));
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(username);
- TAdmin data = adminByUsername.getData();
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- n_adminId = data.getId();
- }
- List<OrderDaoChuDTO> OrderDaoChuDTOList = new ArrayList<>();
- if (ifForeign.equals("0")) {
- //大陆
- OrderDaoChuDTOList = orderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, current, size);
- } else {
- //查海外
- OrderDaoChuDTOList = coinOrderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, current, size);
- }
- for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
- String adminId1 = orderDaoChuDTO.getAdminId().toString();
- ResponseModel<TAdmin> admin1 = szwlFeign.getAdmin(adminId1);
- TAdmin admin = admin1.getData();
- if (admin == null) {
- continue;
- }
- orderDaoChuDTO.setPhone(admin.getPhone());
- orderDaoChuDTO.setUsername(admin.getUsername());
- orderDaoChuDTO.setName(admin.getName());
- if (!StringUtils.isEmpty(type) && type.equals("2")) {
- TArea area = areaService.getById(admin.getAreaId());
- if (area != null) {
- orderDaoChuDTO.setAddress(area.getFullName());
- }
- ResponseModel<List<String>> clientIds = szwlFeign.getClientIds(String.valueOf(admin.getId()));
- List<String> stringList = clientIds.getData();
- if (stringList != null && stringList.size() > 0) {
- orderDaoChuDTO.setEquipmentTotal(String.valueOf(stringList.size()));
- }
- //商户为单位
- ResponseModel<TAdmin> feignAdmin = szwlFeign.getAdmin(String.valueOf(admin.getParentId()));
- TAdmin parent = feignAdmin.getData();
- if (parent != null && parent.getId() != null) {
- orderDaoChuDTO.setLastUsername(parent.getUsername());
- }
- } else {
- //设备为单位
- ResponseModel<TEquipment> equipmentByClientId = szwlFeign.findEquipmentByClientId(String.valueOf(orderDaoChuDTO.getClientId()));
- TEquipment equipment = equipmentByClientId.getData();
- if (equipment != null && equipment.getId() != null) {
- if (StringUtils.isNotEmpty(equipment.getFullName())) {
- orderDaoChuDTO.setAddress(equipment.getFullName());
- }
- orderDaoChuDTO.setEquipmentType(equipment.getEquimentType());
- orderDaoChuDTO.setCreateDate(equipment.getCreateDate());
- }
- }
- }
- page0.setRecords(OrderDaoChuDTOList);
- page0.setTotal(1000);
- }
- return R.ok(page0);
- }
- /**
- * 订单数据导出
- */
- @ApiOperation(value = "订单数据导出-导出")
- @RequestMapping(value = "/onlineExport", method = RequestMethod.GET)
- @LogAnnotation(module = "模块名称:订单", operator = "操作参数:导出订单数据")
- public Object onlineExport(HttpServletResponse response, String type, String clientId,
- String ifForeign, String userName, String startDate,
- String companyType, Long adminId,
- String endDate, long current, long size) {
- current = 1L;
- size = 1000L;
- if (adminId == 2738) {
- companyType = "0";
- }
- if (adminId == 2739) {
- companyType = "1";
- }
- if (startDate != null && endDate != null) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date begin = null;
- Date end = null;
- Long n_adminId = null;
- try {
- begin = simpleDateFormat.parse(startDate);
- end = simpleDateFormat.parse(endDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- long time = end.getTime() - begin.getTime();
- if (time > 31 * 24 * 60 * 60 * 1000L) {
- return JsonMessage.success("时间跨度过长");
- }
- if (!StringUtils.isEmpty(userName)) {
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
- TAdmin data = adminByUsername.getData();
- if (StringUtils.isEmpty(ifForeign)) {
- ifForeign = data.getIfForeign();
- }
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- adminId = data.getId();
- }
- List<OrderDaoChuDTO> OrderDaoChuDTOList = new ArrayList<>();
- if (ifForeign.equals("0")) {
- //大陆
- OrderDaoChuDTOList = orderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, current, size);
- } else {
- //查海外
- OrderDaoChuDTOList = coinOrderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, current, size);
- }
- for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
- String adminId1 = orderDaoChuDTO.getAdminId().toString();
- ResponseModel<TAdmin> admin1 = szwlFeign.getAdmin(adminId1);
- TAdmin admin = admin1.getData();
- if (admin == null) {
- continue;
- }
- orderDaoChuDTO.setPhone(admin.getPhone());
- orderDaoChuDTO.setUsername(admin.getUsername());
- orderDaoChuDTO.setName(admin.getName());
- if (!StringUtils.isEmpty(type) && type.equals("2")) {
- TArea area = areaService.getById(admin.getAreaId());
- if (area != null) {
- orderDaoChuDTO.setAddress(area.getFullName());
- }
- ResponseModel<List<String>> clientIds = szwlFeign.getClientIds(String.valueOf(admin.getId()));
- List<String> stringList = clientIds.getData();
- if (stringList != null && stringList.size() > 0) {
- orderDaoChuDTO.setEquipmentTotal(String.valueOf(stringList.size()));
- }
- //商户为单位
- ResponseModel<TAdmin> feignAdmin = szwlFeign.getAdmin(String.valueOf(admin.getParentId()));
- TAdmin parent = feignAdmin.getData();
- if (parent != null && parent.getId() != null) {
- orderDaoChuDTO.setLastUsername(parent.getUsername());
- }
- } else {
- //设备为单位
- ResponseModel<TEquipment> equipmentByClientId = szwlFeign.findEquipmentByClientId(String.valueOf(orderDaoChuDTO.getClientId()));
- TEquipment equipment = equipmentByClientId.getData();
- if (equipment != null && equipment.getId() != null) {
- if (StringUtils.isNotEmpty(equipment.getFullName())) {
- orderDaoChuDTO.setAddress(equipment.getFullName());
- }
- orderDaoChuDTO.setEquipmentType(equipment.getEquimentType());
- orderDaoChuDTO.setCreateDate(equipment.getCreateDate());
- }
- }
- }
- ExportParams exportParams = new ExportParams("订单记录", "sheet1");
- Workbook workbook = null;
- if (!StringUtils.isEmpty(type) && type.equals("2")) {
- List<OrderByAdminTarget> orderByAdminTargetList = new ArrayList<>();
- for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
- OrderByAdminTarget orderByAdminTarget = new OrderByAdminTarget();
- orderByAdminTarget.setUsername(orderDaoChuDTO.getUsername());
- orderByAdminTarget.setAddress(orderDaoChuDTO.getAddress());
- orderByAdminTarget.setEquipmentTotal(orderDaoChuDTO.getEquipmentTotal());
- orderByAdminTarget.setLastUsername(orderDaoChuDTO.getLastUsername());
- orderByAdminTarget.setPhone(orderDaoChuDTO.getPhone());
- orderByAdminTarget.setPriceTotal(orderDaoChuDTO.getPriceTotal());
- orderByAdminTarget.setName(orderDaoChuDTO.getName());
- orderByAdminTargetList.add(orderByAdminTarget);
- }
- workbook = ExcelExportUtil.exportExcel(exportParams, OrderByAdminTarget.class, orderByAdminTargetList);
- } else {
- List<OrderByClientidTarget> orderByClientidTargetList = new ArrayList<>();
- for (OrderDaoChuDTO orderDaoChuDTO : OrderDaoChuDTOList) {
- OrderByClientidTarget orderByClientidTarget = new OrderByClientidTarget();
- orderByClientidTarget.setAddress(orderDaoChuDTO.getAddress());
- orderByClientidTarget.setClientId(orderDaoChuDTO.getClientId());
- orderByClientidTarget.setCreateDate(orderDaoChuDTO.getCreateDate());
- orderByClientidTarget.setEquipmentType(orderDaoChuDTO.getEquipmentType());
- orderByClientidTarget.setName(orderDaoChuDTO.getName());
- orderByClientidTarget.setPhone(orderDaoChuDTO.getPhone());
- orderByClientidTarget.setPriceTotal(orderDaoChuDTO.getPriceTotal());
- orderByClientidTarget.setUsername(orderDaoChuDTO.getUsername());
- orderByClientidTargetList.add(orderByClientidTarget);
- }
- workbook = ExcelExportUtil.exportExcel(exportParams, OrderByClientidTarget.class, orderByClientidTargetList);
- }
- if (workbook != null) {
- OutputStream os = null;
- try {
- os = response.getOutputStream();
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
- response.setContentType("application/vnd.ms-excel;charset=utf-8");
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
- workbook.write(os);
- return JsonMessage.success("导出成功");
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.success("导出错误");
- } finally {
- try {
- os.close();
- workbook.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return JsonMessage.success("导出成功");
- }
- @RequestMapping(value = "/orderExport", method = RequestMethod.GET)
- public Object orderExport(HttpServletResponse response, String equipmentId, String adminId,
- String adminType, String type, String status, String userName,
- String payType, String productNo, String clientId, String dateType,
- String startDate, String endDate, String companyType, String machineType,
- long current, long size) throws ParseException {
- current = 1L;
- size = 1000L;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date begin = null;
- Date end = null;
- try {
- begin = simpleDateFormat.parse(startDate);
- end = simpleDateFormat.parse(endDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- long time = end.getTime() - begin.getTime();
- if (time > 31 * 24 * 60 * 60 * 1000L) {
- return JsonMessage.success("时间跨度过长");
- }
- //判断当前账号状态
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminId));
- //类型
- //0,线上
- if (type.equals("0")) {
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- if (!userName.equals("admin")) {
- if (StringUtils.isNotEmpty(userName)) {
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
- TAdmin data = adminByUsername.getData();
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- if (data.getIsAdmined()) {
- query.eq(TOrder::getAdminId, data.getId());
- } else {
- if (data.getParentId() != 1) {
- query.eq(TOrder::getAdminId, data.getParentId());
- //查找子账户所管理的机器
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
- if (!adminEquipment.getType().equals("0")) {
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(adminId));
- if (list == null || list.size() == 0) {
- return R.fail(ResponseCodesEnum.A0001, "没有机器/no machine");
- }
- query.in(TOrder::getClientId, list);
- }
- }
- }
- } else {
- //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
- if (StringUtils.isNotEmpty(adminType)) {
- if (admin.getIsAdmined() && admin.getType() > 1) {
- if (admin.getType() > 1) {
- if (adminType.equals("all")) {
- //查找所有下级
- List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
- query.in(TOrder::getAdminId, admidIdList);
- }
- }
- } else {
- if (admin.getType() > 1) {
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TOrder::getClientId, equipmentIdList);
- }
- }
- }
- } else {
- //判断当前账号状态 公司还是商家
- if (admin.getType() > 1) {
- //商家 判断是否子账户
- if (admin.getIsAdmined()) {
- //商家自己
- query.eq(TOrder::getAdminId, adminId);
- } else {
- //商家 子账户
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TOrder::getClientId, equipmentIdList);
- }
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(payType)) {
- query.eq(TOrder::getFrpCode, payType);
- }
- if (StringUtils.isNotEmpty(productNo)) {
- query.eq(TOrder::getProductNo, productNo);
- }
- if (StringUtils.isNotEmpty(clientId)) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- //判断机器是否属于这个登陆账号
- if (admin.getType() > 1) {
- //商家
- if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
- query.eq(TOrder::getEquipmentId, equipment.getId());
- }
- } else {
- query.eq(TOrder::getEquipmentId, equipment.getId());
- }
- }
- if (StringUtils.isNotEmpty(equipmentId)) {
- query.eq(TOrder::getEquipmentId, equipmentId);
- }
- if (StringUtils.isNotEmpty(status)) {
- query.eq(TOrder::getStatus, status);
- }
- if (StringUtils.isNotEmpty(dateType)) {
- if (dateType.equals("0")) {
- //创建时间
- if (begin != null && end != null) {
- query.gt(TOrder::getCreateDate, begin);
- query.lt(TOrder::getCreateDate, end);
- }
- }
- if (dateType.equals("1")) {
- //退款时间
- if (begin != null && end != null) {
- query.gt(TOrder::getRefundDate, begin);
- query.lt(TOrder::getRefundDate, end);
- }
- }
- }
- // 公司平台
- // 申泽平台管理员
- if (admin.getId() == 2738) {
- companyType = "0";
- }
- // 七云平台管理员
- if (admin.getId() == 2739) {
- companyType = "1";
- }
- if (StringUtils.isNotEmpty(companyType)) {
- if (companyType.equals("0")) {
- String finalCompanyType = companyType;
- query.nested(q -> q.isNull(TOrder::getCompanyType).or()
- .eq(TOrder::getCompanyType, finalCompanyType));
- } else {
- query.eq(TOrder::getCompanyType, companyType);
- }
- }
- if (StringUtils.isNotEmpty(machineType)) {
- if (machineType.equals("0")) {
- query.nested(q -> q.isNull(TOrder::getMachineType).or()
- .eq(TOrder::getMachineType, machineType));
- } else {
- query.eq(TOrder::getMachineType, machineType);
- }
- }
- Page<TOrder> page = new Page<>(current, size, true);
- IPage<TOrder> iPage = orderService.page(page, query);
- List<TOrder> list = iPage.getRecords();
- List<OrderTarget> orderTargetList = orderService.findById(admin, list);
- ExportParams exportParams = new ExportParams("订单记录", "sheet1");
- Workbook workbook = ExcelExportUtil.exportExcel(exportParams, OrderTarget.class, orderTargetList);
- if (workbook != null) {
- OutputStream os = null;
- try {
- os = response.getOutputStream();
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
- response.setContentType("application/vnd.ms-excel;charset=utf-8");
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
- workbook.write(os);
- // return JsonMessage.success("导出成功");
- } catch (Exception e) {
- e.printStackTrace();
- // return JsonMessage.success("导出错误");
- } finally {
- try {
- os.close();
- workbook.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- ;
- //1,线下
- if (type.equals("1")) {
- LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
- if (StringUtils.isNotEmpty(userName) && !userName.equals("admin")) {
- ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
- TAdmin data = adminByUsername.getData();
- if (data == null || data.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- query.eq(TCoinOrder::getAdminId, data.getId());
- } else if (StringUtils.isEmpty(userName)) {
- //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
- if (StringUtils.isNotEmpty(adminType)) {
- if (admin.getIsAdmined() && admin.getType() > 1) {
- if (admin.getType() > 1) {
- if (adminType.equals("all")) {
- //查找所有下级
- List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
- query.in(TCoinOrder::getAdminId, admidIdList);
- }
- }
- } else {
- if (admin.getType() > 1) {
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TCoinOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TCoinOrder::getClientId, equipmentIdList);
- }
- }
- }
- } else {
- //判断当前账号状态 公司还是商家
- if (admin.getType() > 1) {
- //商家 判断是否子账户
- if (admin.getIsAdmined()) {
- //商家自己
- query.eq(TCoinOrder::getAdminId, adminId);
- } else {
- //商家 子账户
- //登录账户为子账户 不查下级 只查对应机器的订单
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
- if (adminEquipment.getType().equals("0")) {
- //全部机器
- TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
- query.eq(TCoinOrder::getAdminId, upAdmin.getId());
- } else {
- String equipmentIds = adminEquipment.getEquipmentIds();
- List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
- query.in(TCoinOrder::getClientId, equipmentIdList);
- }
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(payType)) {
- query.eq(TCoinOrder::getPayType, payType);
- }
- if (StringUtils.isNotEmpty(productNo)) {
- query.eq(TCoinOrder::getProductNo, productNo);
- }
- if (StringUtils.isNotEmpty(clientId)) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- //判断机器是否属于这个登陆账号
- if (admin.getType() > 1) {
- //商家
- if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
- query.eq(TCoinOrder::getClientId, equipment.getClientId());
- }
- } else {
- query.eq(TCoinOrder::getClientId, equipment.getClientId());
- }
- }
- if (begin != null && end != null) {
- query.gt(TCoinOrder::getPayDate, begin);
- query.lt(TCoinOrder::getPayDate, end);
- }
- Page<TCoinOrder> page = new Page<>(current, size, true);
- IPage<TCoinOrder> iPage = coinOrderService.page(page, query);
- List<TCoinOrder> list = iPage.getRecords();
- List<CoinOrderTarget> coinOrderTargets = coinOrderService.findByCoinOrder(admin, list);
- ExportParams exportParams = new ExportParams("线下订单记录", "sheet1");
- Workbook workbook = ExcelExportUtil.exportExcel(exportParams, CoinOrderTarget.class, coinOrderTargets);
- if (workbook != null) {
- OutputStream os = null;
- try {
- os = response.getOutputStream();
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
- response.setContentType("application/vnd.ms-excel;charset=utf-8");
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("线下订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
- workbook.write(os);
- return JsonMessage.success("导出成功");
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.success("导出错误");
- } finally {
- try {
- os.close();
- workbook.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return JsonMessage.success("导出错误");
- }
- @ApiOperation(value = "同步订单到es中")
- @PostMapping("/saveToEs")
- public ResponseModel<?> saveToEs(@RequestBody TOrder order) {
- if (order == null) {
- return R.fail(ResponseCodesEnum.A0001);
- }
- esTOrderService.insertData(order);
- return R.ok("同步es成功");
- }
- /**
- * 线上通过时间分组
- *
- * @param clientId
- * @param startTime
- * @param endTime
- * @param unit
- * @return
- */
- @RequestMapping(value = "/getStatisticsByClientId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public Object getStatisticsByClientId(String clientId, String startTime, String endTime, Integer unit) {
- String date = "";
- switch (unit) {
- //按小时计算
- case 0:
- date = DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss;
- break;
- //按天
- case 1:
- date = DateUtils.PATTERN_yyyy_MM_dd;
- break;
- //按月
- case 2:
- date = DateUtils.PATTERN_yyyy_MM;
- break;
- //按年
- case 3:
- date = DateUtils.PATTERN_yyyy;
- break;
- }
- SimpleDateFormat format = new SimpleDateFormat(date);
- Date date1 = null;
- Date date2 = null;
- try {
- date1 = format.parse(startTime);
- date2 = format.parse(endTime);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- List<OrderStatisticsDTO> list = orderService.findByTime(clientId, date1, date2, unit);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JsonUtils.toJson(list));
- jsonObject.put("errmsg", "");
- return jsonObject;
- }
- /**
- * 获取每天的开始时间 00:00:00:00
- *
- * @param date
- * @return
- */
- public static Date getStartTime(Date date) {
- Calendar dateStart = Calendar.getInstance();
- dateStart.setTime(date);
- dateStart.set(Calendar.HOUR_OF_DAY, 0);
- dateStart.set(Calendar.MINUTE, 0);
- dateStart.set(Calendar.SECOND, 0);
- return dateStart.getTime();
- }
- /**
- * 获取每天的时间 23:59:59:999
- *
- * @param date
- * @return
- */
- public static Date getEndTime(Date date) {
- Calendar dateEnd = Calendar.getInstance();
- dateEnd.setTime(date);
- dateEnd.set(Calendar.HOUR_OF_DAY, 23);
- dateEnd.set(Calendar.MINUTE, 59);
- dateEnd.set(Calendar.SECOND, 59);
- return dateEnd.getTime();
- }
- }
|