123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764 |
- 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 orderClientId = order.getClientId();
- String name = equipmentMap.get(orderClientId);
- if (StringUtils.isNotEmpty(name)) {
- order.setEs(name);
- } else {
- order.setEs(orderClientId.substring(orderClientId.length() - 6));
- }
- 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 != null) {
- 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);
- // }
- // }
- List<TCoinOrder> coinOrderList = iPage.getRecords();
- if (coinOrderList.size() > 0) {
- // 设备编号集合
- List<String> clientIds = new ArrayList<>();
- for (TCoinOrder coinOrder : coinOrderList) {
- clientIds.add(coinOrder.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());
- }
- // List<TCoinOrder> orderList = iPage.getRecords();
- // if (orderList.size() > 0) {
- //// TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(orderList.get(0).getClientId()));
- // for (TCoinOrder order : orderList) {
- // TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(orderList.get(0).getClientId()));
- // order.setEs(equipment.getName());
- // }
- // }
- for (TCoinOrder coinOrder : coinOrderList) {
- String coinOrderClientId = coinOrder.getClientId();
- String name = equipmentMap.get(coinOrderClientId);
- if (StringUtils.isNotEmpty(name)) {
- coinOrder.setEs(name);
- } else {
- coinOrder.setEs(coinOrderClientId.substring(coinOrderClientId.length() - 6));
- }
- }
- iPage.setRecords(coinOrderList);
- }
- 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);
- }
- 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 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 R.fail(ResponseCodesEnum.A0001, "时间跨度过长");
- }
- if (!StringUtils.isEmpty(username)) {
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdminByUsername(username));
- if (admin == null || admin.getId() == null) {
- return R.fail(ResponseCodesEnum.A0001, "找不到商家");
- }
- n_adminId = admin.getId();
- }
- List<OrderDaoChuDTO> OrderDaoChuDTOList = new ArrayList<>();
- Long OrderDaoChuTotal = 0L;
- if (ifForeign.equals("0")) {
- //大陆
- LambdaQueryWrapper<TOrder> queryWrapper = new LambdaQueryWrapper<>();
- // ------ 查询条件 ------
- queryWrapper.eq(TOrder::getStatus, 1)
- .ge(TOrder::getCreateDate, begin)
- .le(TOrder::getCreateDate, end);
- if (StringUtils.isNotBlank(clientId)) {
- queryWrapper.eq(TOrder::getClientId, clientId);
- }
- if (StringUtils.isNotBlank(companyType)) {
- if ("0".equals(companyType)) {
- queryWrapper.and(i -> i.isNull(TOrder::getCompanyType).or().eq(TOrder::getCompanyType, "0"));
- } else if ("1".equals(companyType)) {
- queryWrapper.eq(TOrder::getCompanyType, "1");
- }
- }
- // ------ 分组 ------
- if (type.equals("2")) {
- queryWrapper.groupBy(TOrder::getAdminId);
- } else if (type.equals("1")) {
- queryWrapper.groupBy(TOrder::getClientId);
- }
- Page<TOrder> tOrderPage = new Page<>(current, size, true);
- Page<TOrder> page = orderService.page(tOrderPage, queryWrapper);
- OrderDaoChuTotal = page.getTotal();
- OrderDaoChuDTOList = orderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, current, size);
- } else {
- //查海外
- LambdaQueryWrapper<TCoinOrder> queryWrapper = new LambdaQueryWrapper<>();
- // ------ 查询条件 ------
- queryWrapper.eq(TCoinOrder::getStatus, 1)
- .ge(TCoinOrder::getCreateDate, begin)
- .le(TCoinOrder::getCreateDate, end);
- if (StringUtils.isNotBlank(clientId)) {
- queryWrapper.eq(TCoinOrder::getClientId, clientId);
- }
- if (StringUtils.isNotBlank(companyType)) {
- if ("0".equals(companyType)) {
- queryWrapper.and(i -> i.isNull(TCoinOrder::getCompanyType).or().eq(TCoinOrder::getCompanyType, "0"));
- } else if ("1".equals(companyType)) {
- queryWrapper.eq(TCoinOrder::getCompanyType, "1");
- }
- }
- // ------ 分组 ------
- if (type.equals("2")) {
- queryWrapper.groupBy(TCoinOrder::getAdminId);
- } else if (type.equals("1")) {
- queryWrapper.groupBy(TCoinOrder::getClientId);
- }
- Page<TCoinOrder> tOrderPage = new Page<>(current, size, true);
- Page<TCoinOrder> page = coinOrderService.page(tOrderPage, queryWrapper);
- OrderDaoChuTotal = page.getTotal();
- OrderDaoChuDTOList = coinOrderService.orderDaoChu(simpleDateFormat.format(begin), simpleDateFormat.format(end), n_adminId, clientId, type, companyType, 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());
- }
- List<TEquipment> equipmentList = R.getDataIfSuccess(szwlFeign.listEquipment(adminId1));
- if (equipmentList != null && equipmentList.size() > 0) {
- orderDaoChuDTO.setEquipmentTotal(String.valueOf(equipmentList.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(OrderDaoChuTotal);
- }
- 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, companyType, 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();
- }
- }
|