diff --git a/xhpc-modules/xhpc-order/pom.xml b/xhpc-modules/xhpc-order/pom.xml index bdb09969..bce8e5eb 100644 --- a/xhpc-modules/xhpc-order/pom.xml +++ b/xhpc-modules/xhpc-order/pom.xml @@ -101,11 +101,11 @@ org.springframework.boot spring-boot-starter-websocket - - org.apache.poi - poi-ooxml - 3.9 - + + + + + diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java index d8db4640..1dc68bb6 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java @@ -4,6 +4,9 @@ import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import cn.hutool.poi.excel.ExcelWriter; +import com.xhpc.common.core.utils.StringUtils; +import com.xhpc.common.core.utils.poi.ExcelUtil; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; @@ -15,17 +18,18 @@ import com.xhpc.order.dto.XhpcChargeHistoryOrder; import com.xhpc.order.service.IXhpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import com.xhpc.order.service.IXhpcStatisticsService; +import com.xhpc.system.api.domain.SysUser; import io.swagger.annotations.Api; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; @@ -84,6 +88,31 @@ public class XhpcHistoryOrderController extends BaseController { return xhpcHistoryOrderService.getById(historyOrderId); } + + /** + * 历史订单导出 + * @param response 返回数据流 + * @param map 参数集 + * @throws IOException 文件创建异常 + */ + @PostMapping("/export") + public void getListPage(HttpServletResponse response, @RequestBody Map map) throws IOException { + + String phone = map.get("phone").toString(); + String transactionNumber = map.get("transactionNumber").toString(); + Integer status = StringUtils.isNotEmpty(map.get("transactionNumber").toString())? Integer.valueOf(map.get("transactionNumber").toString()) : null ; + String chargingStationName = map.get("chargingStationName").toString(); + Long operatorId = StringUtils.isNotEmpty(map.get("operatorId").toString())? Long.parseLong(map.get("operatorId").toString()) : null; + Integer source = StringUtils.isNotEmpty(map.get("source").toString())? Integer.valueOf(map.get("source").toString()): null; + String startTime = map.get("startTime").toString(); + String endTime = map.get("endTime").toString(); + Long userId = StringUtils.isNotEmpty(map.get("userId").toString())? Long.parseLong(map.get("userId").toString()): null; + Integer type = StringUtils.isNotEmpty(map.get("type").toString())? Integer.valueOf(map.get("type").toString()): null; + + xhpcHistoryOrderService.export(response, phone, transactionNumber, status, chargingStationName, operatorId, source, startTime, endTime, userId, type); + + } + /** * 终端统计 */ diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcHistoryOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcHistoryOrderService.java index 6fd3b30e..1eeafb65 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcHistoryOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcHistoryOrderService.java @@ -4,6 +4,8 @@ import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.dto.XhpcChargeHistoryOrder; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -52,6 +54,14 @@ public interface IXhpcHistoryOrderService { */ List> getListPage(String phone,String transactionNumber,Integer status,String chargingStationName,Long operatorId,Integer source,String startTime,String endTime,Long userId,Integer type); + + /** + * 历史订单记录导出(PC) + * @return + */ + void export(HttpServletResponse response, String phone, String transactionNumber, Integer status, String chargingStationName, Long operatorId, Integer source, String startTime, String endTime, Long userId, Integer type) throws IOException; + + /** * 历史订单详情(PC) * @param historyOrderId 历史订单id diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java index c5fac094..02d1204f 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java @@ -3,6 +3,9 @@ package com.xhpc.order.service.impl; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import com.xhpc.common.api.SmsService; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; @@ -20,6 +23,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ExecutorService; @@ -32,7 +39,7 @@ import java.util.concurrent.Executors; @Service public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { - @Autowired + @Resource private XhpcHistoryOrderMapper xhpcHistoryOrderMapper; @Autowired @@ -54,68 +61,125 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { @Override public List> list(Long userId) { + return xhpcHistoryOrderMapper.list(userId); } @Override public int update(XhpcHistoryOrder xhpcHistoryOrder) { + return xhpcHistoryOrderMapper.update(xhpcHistoryOrder); } @Override - public AjaxResult gethistotyOrderMessage(Long userId, Long historyOrderId,Integer type,Long chargingOrderId) { - return AjaxResult.success(xhpcHistoryOrderMapper.gethistotyOrderMessage(userId,historyOrderId,type,chargingOrderId)); + public AjaxResult gethistotyOrderMessage(Long userId, Long historyOrderId, Integer type, Long chargingOrderId) { + + return AjaxResult.success(xhpcHistoryOrderMapper.gethistotyOrderMessage(userId, historyOrderId, type, chargingOrderId)); } @Override public void insert(XhpcHistoryOrder xhpcHistoryOrder) { - xhpcHistoryOrderMapper.insert(xhpcHistoryOrder); + + xhpcHistoryOrderMapper.insert(xhpcHistoryOrder); } @Override public List> getListPage(String phone, String transactionNumber, Integer status, String chargingStationName, Long operatorId, Integer source, String startTime, String endTime, Long userId, Integer type) { - Integer number=0; - if(!"".equals(phone) && phone!=null && !"".equals(source) && source !=null){ - number =3; - }else if (!"".equals(phone) && phone!=null){ - number =1; - }else{ - number =2; + + Integer number = 0; + if (!"".equals(phone) && phone != null && !"".equals(source) && source != null) { + number = 3; + } else if (!"".equals(phone) && phone != null) { + number = 1; + } else { + number = 2; } //获取登陆用户 Long logUserId = SecurityUtils.getUserId(); //桩的统计、该时段金额 - List> list =new ArrayList<>(); - if(userId !=1){ + List> list = new ArrayList<>(); + if (userId != 1) { Map landUser = xhpcHistoryOrderMapper.getLandUser(logUserId); - if(landUser !=null){ - if(landUser.get("userType") !=null){ - if("01".equals(landUser.get("userType").toString()) || "03".equals(landUser.get("userType").toString())){ + if (landUser != null) { + if (landUser.get("userType") != null) { + if ("01".equals(landUser.get("userType").toString()) || "03".equals(landUser.get("userType").toString())) { Long logOperatorId = Long.valueOf(landUser.get("operatorId").toString()); //运营商看自己的场站 - list = xhpcHistoryOrderMapper.getListPage(phone,transactionNumber,1,chargingStationName,operatorId,source,startTime,endTime,logOperatorId,type,number); - }else{ + list = xhpcHistoryOrderMapper.getListPage(phone, transactionNumber, 1, chargingStationName, operatorId, source, startTime, endTime, logOperatorId, type, number); + } else { //查询赋值的场站 - list = xhpcHistoryOrderMapper.getListPage(phone,transactionNumber,2,chargingStationName,operatorId,source,startTime,endTime,logUserId,type,number); + list = xhpcHistoryOrderMapper.getListPage(phone, transactionNumber, 2, chargingStationName, operatorId, source, startTime, endTime, logUserId, type, number); } } } - }else{ - list =xhpcHistoryOrderMapper.getListPage(phone,transactionNumber,0,chargingStationName,operatorId,source,startTime,endTime,userId,type,number); + } else { + list = xhpcHistoryOrderMapper.getListPage(phone, transactionNumber, 0, chargingStationName, operatorId, source, startTime, endTime, userId, type, number); } return list; } + + @Override + public void export(HttpServletResponse response, String phone, String transactionNumber, Integer status, String chargingStationName, Long operatorId, Integer source, String startTime, String endTime, Long userId, Integer type) throws IOException { + + List> list = getListPage(phone, transactionNumber, status, chargingStationName, operatorId, source, startTime, endTime, userId, type); + // 通过工具类创建writer,默认创建xls格式 + ExcelWriter writer = ExcelUtil.getWriter(); + writer.addHeaderAlias("historyOrderId", "历史订单ID"); + writer.addHeaderAlias("serialNumber", "订单号"); + writer.addHeaderAlias("chargingStationName", "电站名称"); + writer.addHeaderAlias("pileSerialNumber", "桩编号"); + writer.addHeaderAlias("terminalName", "终端名称"); + writer.addHeaderAlias("operatorId", "运营商ID"); + writer.addHeaderAlias("operatorName", "运营商名称"); + writer.addHeaderAlias("power", "功率"); + writer.addHeaderAlias("type", "桩类型(1直流(慢) 2交流(快)"); + writer.addHeaderAlias("orderType", "状态1 自动结算 2 平台结算"); + writer.addHeaderAlias("startSoc", "开始soc"); + writer.addHeaderAlias("endSoc", "结束soc"); +// writer.addHeaderAlias("internetSerialNumber", "电站名称"); + writer.addHeaderAlias("totalPrice", "订单总价"); + writer.addHeaderAlias("actPrice", "实际价格"); +// writer.addHeaderAlias("confirmResult", "历史订单ID"); + writer.addHeaderAlias("chargingTime", "累计充电时间"); + writer.addHeaderAlias("chargingDegree", "充电度数"); + writer.addHeaderAlias("startTime", "开始充电时间"); + writer.addHeaderAlias("endTime", "结束充电时间"); + writer.addHeaderAlias("updateTime", "结算时间"); + writer.addHeaderAlias("source", "订单来源(0C端用户 1流量用户)"); +// writer.addHeaderAlias("plateNum", "电站名称"); +// writer.addHeaderAlias("disputeOrderStatus", "桩编号"); + + // 默认的,未添加alias的属性也会写出,如果想只写出加了别名的字段,可以调用此方法排除之 + writer.setOnlyAlias(true); + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + //out为OutputStream,需要写出到的目标流 + + //response为HttpServletResponse对象 + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=历史订单列表.xls"); + ServletOutputStream out = response.getOutputStream(); + + writer.flush(out, true); + // 关闭writer,释放内存 + writer.close(); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + @Override public AjaxResult getById(Long historyOrderId) { - try{ + + try { Map byId = xhpcHistoryOrderMapper.getById(historyOrderId); - if(byId !=null){ - byId.putAll(getRateTime(byId.get("serialNumber").toString(),byId.get("actPrice").toString())); + if (byId != null) { + byId.putAll(getRateTime(byId.get("serialNumber").toString(), byId.get("actPrice").toString())); } return AjaxResult.success(byId); - }catch (Exception e){ + } catch (Exception e) { } return AjaxResult.success(); @@ -123,26 +187,29 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { @Override public List> getReatTimeList(String startTime, String endTime, Long rateModelId) { + return xhpcHistoryOrderMapper.getReatTimeList(startTime, endTime, rateModelId); } @Override - public List getStatistisList(int number,int state) { - return xhpcHistoryOrderMapper.getStatistisList(number,state); + public List getStatistisList(int number, int state) { + + return xhpcHistoryOrderMapper.getStatistisList(number, state); } @Override public void updateXhpcHistoryOrder(Long historyOrderId, Integer state) { - xhpcHistoryOrderMapper.updateXhpcHistoryOrder(historyOrderId,state); + + xhpcHistoryOrderMapper.updateXhpcHistoryOrder(historyOrderId, state); } @Override - public void addXhpcChargeOrder(String orderNo,Integer type) { + public void addXhpcChargeOrder(String orderNo, Integer type) { //(调用时间-启动时间《3分钟 自动结算) - logger.info("订单异常回调接口>>>>>orderNo:" + orderNo+" type:"+type); + logger.info("订单异常回调接口>>>>>orderNo:" + orderNo + " type:" + type); //获取实时订单 CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord"); - if(cacheRealtimeData !=null){ + if (cacheRealtimeData != null) { XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); Long userId = xhpcChargeOrder.getUserId(); try { @@ -151,24 +218,24 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { //当checking为true时,自动结算 Integer chargingTime = cacheRealtimeData.getChargingTime(); boolean checking = false; - if(type==1){ - if(chargingTime<3){ - checking=true; + if (type == 1) { + if (chargingTime < 3) { + checking = true; } - }else{ - checking=true; + } else { + checking = true; } //毫秒 DateTime date = DateUtil.offsetMinute(xhpcChargeOrder.getStartTime(), chargingTime); xhpcChargeOrder.setEndTime(date); xhpcChargeOrder.setUpdateTime(date); - if(checking){ + if (checking) { xhpcChargeOrder.setStatus(3); - }else{ + } else { xhpcChargeOrder.setStatus(2); } - xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+""); + xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc() + ""); //充电时长 Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000); if (tiem > 3600) { @@ -180,32 +247,32 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); } BigDecimal decimal = new BigDecimal(10000); - xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal,2,BigDecimal.ROUND_DOWN)); - xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal,2,BigDecimal.ROUND_DOWN)); + xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal, 2, BigDecimal.ROUND_DOWN)); + xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal, 2, BigDecimal.ROUND_DOWN)); xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime())); - if(checking){ - BigDecimal money =xhpcChargeOrder.getAmountCharged(); + if (checking) { + BigDecimal money = xhpcChargeOrder.getAmountCharged(); //结算 //总电费 - BigDecimal powerPrice =new BigDecimal(0); + BigDecimal powerPrice = new BigDecimal(0); //算时间是否跨天 Long rateModelId = xhpcChargeOrder.getRateModelId(); Date updateTime2 = xhpcChargeOrder.getEndTime(); long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); - if(betweenDay==0){ - powerPrice=getBigDecimal(rateModelId,startTime2,updateTime2,xhpcChargeOrder.getChargingDegree()); - }else{ + if (betweenDay == 0) { + powerPrice = getBigDecimal(rateModelId, startTime2, updateTime2, xhpcChargeOrder.getChargingDegree()); + } else { //跨天 Date updateTime = DateUtil.endOfDay(startTime2); - powerPrice=getBigDecimal(rateModelId,startTime2,updateTime,xhpcChargeOrder.getChargingDegree()); + powerPrice = getBigDecimal(rateModelId, startTime2, updateTime, xhpcChargeOrder.getChargingDegree()); //明天 - DateTime tomorrow = DateUtil.offsetDay(startTime2,1); - Date startTime3 =DateUtil.beginOfDay(tomorrow); - powerPrice=powerPrice.add(getBigDecimal(rateModelId,startTime3,updateTime2,xhpcChargeOrder.getChargingDegree())); + DateTime tomorrow = DateUtil.offsetDay(startTime2, 1); + Date startTime3 = DateUtil.beginOfDay(tomorrow); + powerPrice = powerPrice.add(getBigDecimal(rateModelId, startTime3, updateTime2, xhpcChargeOrder.getChargingDegree())); } //总服务费 @@ -221,7 +288,7 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { xhpcHistoryOrder.setStopReasonEvcs(5); xhpcHistoryOrder.setPowerPriceTotal(powerPrice); xhpcHistoryOrder.setServicePriceTotal(servicePrice); - xhpcHistoryOrder.setTotalPower(cacheRealtimeData.getAmountCharged().doubleValue()/10000); + xhpcHistoryOrder.setTotalPower(cacheRealtimeData.getAmountCharged().doubleValue() / 10000); //电表总起值 //xhpcHistoryOrder.setMeterValueStartEvcs(cacheOrderData.getElectricMeterStart().doubleValue()); //电表总止值 @@ -233,87 +300,87 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { BigDecimal promotionDiscount = new BigDecimal(0); //实际价格-用户支付的钱 - BigDecimal actPrice =money; + BigDecimal actPrice = money; //流量方总金额抽成 - BigDecimal internetCommission =new BigDecimal(0); + BigDecimal internetCommission = new BigDecimal(0); //流量方服务费抽成 - BigDecimal internetSvcCommission =new BigDecimal(0); + BigDecimal internetSvcCommission = new BigDecimal(0); //平台总金额抽成 - BigDecimal platformCommission =new BigDecimal(0); + BigDecimal platformCommission = new BigDecimal(0); //平台服务费抽成 - BigDecimal platformSvcCommission =new BigDecimal(0); + BigDecimal platformSvcCommission = new BigDecimal(0); //运维总抽成 - BigDecimal operationCommission =new BigDecimal(0); + BigDecimal operationCommission = new BigDecimal(0); //运维服务费抽成 - BigDecimal operationSvcCommission =new BigDecimal(0); + BigDecimal operationSvcCommission = new BigDecimal(0); //判断是C端用户还是流量端用户 if (xhpcChargeOrder.getSource() == 0) { String state = ""; BigDecimal discount = new BigDecimal(0); //用户第几次充电 - int count = xhpcChargeOrderService.getCount(userId,xhpcChargeOrder.getChargeOrderId()); + int count = xhpcChargeOrderService.getCount(userId, xhpcChargeOrder.getChargeOrderId()); if (count == 0) { //活动折扣 Map promotion = xhpcChargeOrderService.getPromotion(); if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { //state 1.总金额 2.电费 3.服务费 discount 折扣率 state = promotion.get("state").toString(); - discount =new BigDecimal(promotion.get("discount").toString()); + discount = new BigDecimal(promotion.get("discount").toString()); } } - if(!"".equals(state)){ + if (!"".equals(state)) { //查看是否优惠为0 boolean fan = discount.compareTo(new BigDecimal(0)) != 0; - if("1".equals(state)){ + if ("1".equals(state)) { //总金额 - if(fan){ - promotionDiscount=money.multiply(discount); + if (fan) { + promotionDiscount = money.multiply(discount); actPrice = money.subtract(promotionDiscount); surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount.divide(new BigDecimal(2))); - surplusServicePrice= surplusServicePrice.subtract(promotionDiscount.divide(new BigDecimal(2))); + surplusServicePrice = surplusServicePrice.subtract(promotionDiscount.divide(new BigDecimal(2))); } - }else if("2".equals(state)){ - if(fan){ + } else if ("2".equals(state)) { + if (fan) { //电费 - promotionDiscount =powerPrice.multiply(balance); + promotionDiscount = powerPrice.multiply(balance); actPrice = money.subtract(promotionDiscount); - surplusPowerPrice=surplusPowerPrice.subtract(promotionDiscount); + surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount); } - }else if("3".equals(state)){ - if(fan){ + } else if ("3".equals(state)) { + if (fan) { //服务费 promotionDiscount = servicePrice.multiply(balance); actPrice = money.subtract(promotionDiscount); - surplusServicePrice =surplusServicePrice.subtract(promotionDiscount); + surplusServicePrice = surplusServicePrice.subtract(promotionDiscount); } } } xhpcHistoryOrder.setInternetCommission(internetCommission); xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission); - }else{ + } else { //流量方,未实现,新增接口 } //获取运营商 Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); - if(operatorMessage !=null){ - if(operatorMessage.get("operatorIdEvcs")!=null){ + if (operatorMessage != null) { + if (operatorMessage.get("operatorIdEvcs") != null) { - if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ + if (operatorMessage.get("operatorIdEvcs") != null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())) { String stw = operatorMessage.get("operatorIdEvcs").toString(); - if(stw.length()>9){ + if (stw.length() > 9) { xhpcHistoryOrder.setOperatorIdEvcs(stw.substring(8, stw.length() - 1)); } } } - if(operatorMessage.get("maintenanceCommissionRate") !=null && operatorMessage.get("commissionType") !=null && operatorMessage.get("platformCommissionRate") !=null){ + if (operatorMessage.get("maintenanceCommissionRate") != null && operatorMessage.get("commissionType") != null && operatorMessage.get("platformCommissionRate") != null) { Integer commissionType = (Integer) operatorMessage.get("commissionType"); //运维提成 BigDecimal maintenanceCommissionRate = new BigDecimal(operatorMessage.get("maintenanceCommissionRate").toString()).divide(new BigDecimal(100)); //平台提成 BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100)); //提成类型(0总金额提成 1服务费提成) - if(commissionType==0){ + if (commissionType == 0) { BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate); BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); platformCommission = multiply1.add(multiply2); @@ -327,9 +394,9 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { surplusPowerPrice = surplusPowerPrice.subtract(multiply3); surplusServicePrice = surplusServicePrice.subtract(multiply4); - }else if(commissionType==1){ + } else if (commissionType == 1) { BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); - platformSvcCommission=multiply2; + platformSvcCommission = multiply2; //剩下的钱 surplusServicePrice = surplusServicePrice.subtract(multiply2); @@ -338,7 +405,7 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { //剩下的钱 surplusServicePrice = surplusServicePrice.subtract(multiply4); } - }else{ + } else { //订单异常 xhpcChargeOrder.setStatus(2); //异常原因 @@ -385,30 +452,30 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { //扣除用户实际消费金额,添加消费记录 Map user = xhpcChargeOrderService.getUserMessage(userId); //剩余的钱 - BigDecimal balance1 =(BigDecimal) user.get("balance"); + BigDecimal balance1 = (BigDecimal) user.get("balance"); BigDecimal subtract = balance1.subtract(actPrice); int i = xhpcChargeOrderService.updateUserBalance(userId, subtract); - if(i==0){ + if (i == 0) { //扣钱失败 xhpcChargeOrder.setStatus(2); xhpcChargeOrder.setErroRemark("扣钱失败"); - }else{ + } else { insert(xhpcHistoryOrder); //添加流水 xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); - try{ + try { Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); - if(xhpcChargingPile !=null){ + if (xhpcChargingPile != null) { //发送短信 - if(user.get("phone") !=null){ - if("1".equals(xhpcChargingPile.get("type").toString())){ + if (user.get("phone") != null) { + if ("1".equals(xhpcChargingPile.get("type").toString())) { HashMap paramMap = new HashMap<>(); paramMap.put("elec", xhpcChargeOrder.getEndSoc()); paramMap.put("sumMoney", actPrice.toString()); paramMap.put("phone", user.get("phone").toString()); paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); smsService.sendNotice(paramMap); - }else { + } else { HashMap paramMap = new HashMap<>(); paramMap.put("sumMoney", actPrice.toString()); paramMap.put("phone", user.get("phone").toString()); @@ -417,14 +484,15 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { } } } - }catch (Exception e){ + } catch (Exception e) { logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); } // 另起线程处理业务上传redis数据 executorService.execute(new Runnable() { @Override public void run() { - xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); + + xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(), 1); } }); } @@ -448,9 +516,10 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { /** * 历史信息费率时段 */ - private Map getRateTime(String serialNumber,String actPrice){ - BigDecimal powerPriceTotal =new BigDecimal(0); - BigDecimal servicePriceTotal =new BigDecimal(0); + private Map getRateTime(String serialNumber, String actPrice) { + + BigDecimal powerPriceTotal = new BigDecimal(0); + BigDecimal servicePriceTotal = new BigDecimal(0); //累计充电时间、计费模型、开始时间、结束时间、已充金额 XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getSerialNumberMessage(serialNumber); Long rateModelId = chargeOrder.getRateModelId(); @@ -458,68 +527,69 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { Date updateTime2 = chargeOrder.getEndTime(); //充电度数 BigDecimal chargingDegree = chargeOrder.getChargingDegree(); - List> list =new ArrayList<>(); + List> list = new ArrayList<>(); //1时间没有跨天 long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); - if(betweenDay==0){ + if (betweenDay == 0) { return getBigDecimal(actPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime2, chargingDegree, list); - }else{ + } else { //跨天 Date updateTime = DateUtil.endOfDay(startTime2); Map map1 = getBigDecimal(actPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list); //获取 - BigDecimal powerPriceTotal1 =(BigDecimal)map1.get("powerPriceTotal"); - BigDecimal servicePriceTotal1 =(BigDecimal)map1.get("servicePriceTotal"); + BigDecimal powerPriceTotal1 = (BigDecimal) map1.get("powerPriceTotal"); + BigDecimal servicePriceTotal1 = (BigDecimal) map1.get("servicePriceTotal"); //明天 - DateTime tomorrow = DateUtil.offsetDay(startTime2,1); - Date startTime3 =DateUtil.beginOfDay(tomorrow); + DateTime tomorrow = DateUtil.offsetDay(startTime2, 1); + Date startTime3 = DateUtil.beginOfDay(tomorrow); Map map2 = getBigDecimal(actPrice, powerPriceTotal1, servicePriceTotal1, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list); return map2; } } private Map getBigDecimal(String actPrice, BigDecimal powerPriceTotal, BigDecimal servicePriceTotal, XhpcChargeOrder chargeOrder, Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree, List> list) { - Map map =new HashMap<>(); + + Map map = new HashMap<>(); //算出相差时间,分 - BigDecimal decimal = new BigDecimal((updateTime2.getTime()-startTime2.getTime())/60000).setScale(2); + BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime()) / 60000).setScale(2); //每分钟多少度 - BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_DOWN); + BigDecimal degree = chargingDegree.divide(decimal, 2, BigDecimal.ROUND_DOWN); //获取费率时间段 String startTime = DateUtil.formatTime(startTime2); String endTime = DateUtil.formatTime(updateTime2); List> reatTimeList = getReatTimeList(startTime, endTime, rateModelId); - if(reatTimeList !=null && reatTimeList.size()>0){ - Map map1 =new HashMap<>(); + if (reatTimeList != null && reatTimeList.size() > 0) { + Map map1 = new HashMap<>(); int size = reatTimeList.size(); - if(size==1){ + if (size == 1) { BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); //powerPriceTotal = powerFee.multiply(degree).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal servicePrice = new BigDecimal(reatTimeList.get(0).get("serviceFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); //servicePriceTotal=servicePrice.multiply(chargingDegree).setScale(2, BigDecimal.ROUND_DOWN); - map1.put("time",startTime+"-"+endTime); - map1.put("powerPrice",powerFee); - map1.put("servicePrice",servicePrice); - map1.put("chargingDegree",chargeOrder.getChargingDegree()); - map1.put("actPrice",actPrice); + map1.put("time", startTime + "-" + endTime); + map1.put("powerPrice", powerFee); + map1.put("servicePrice", servicePrice); + map1.put("chargingDegree", chargeOrder.getChargingDegree()); + map1.put("actPrice", actPrice); list.add(map1); - }else{ - for (int i = 0; i objectMap = reatTimeList.get(i); - BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); - BigDecimal servicePrice =new BigDecimal(objectMap.get("serviceFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal powerPrice = new BigDecimal(objectMap.get("powerFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal servicePrice = new BigDecimal(objectMap.get("serviceFee").toString()).setScale(2, BigDecimal.ROUND_DOWN); String startTime1 = objectMap.get("startTime").toString(); String endTime1 = objectMap.get("endTime").toString(); - if(i==0){ - list.add(getRateTimeList(startTime,endTime1,degree,powerPrice,servicePrice)); - }else{ - if(size==2){ - list.add(getRateTimeList(startTime1,endTime,degree,powerPrice,servicePrice)); - }else{ + if (i == 0) { + list.add(getRateTimeList(startTime, endTime1, degree, powerPrice, servicePrice)); + } else { + if (size == 2) { + list.add(getRateTimeList(startTime1, endTime, degree, powerPrice, servicePrice)); + } else { //三个时段以上 - if(i getRateTimeList(String startTime,String endTime,BigDecimal degree,BigDecimal powerPrice,BigDecimal servicePrice){ - Map map =new HashMap<>(); - BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime())/60000).multiply(degree); + private Map getRateTimeList(String startTime, String endTime, BigDecimal degree, BigDecimal powerPrice, BigDecimal servicePrice) { + + Map map = new HashMap<>(); + BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime()) / 60000).multiply(degree); BigDecimal multiply = powerPrice.add(servicePrice).multiply(v).setScale(2, BigDecimal.ROUND_DOWN); - map.put("time",startTime+"-"+endTime); - map.put("powerPrice",powerPrice); - map.put("servicePrice",servicePrice); - map.put("chargingDegree",v); - map.put("actPrice",multiply); + map.put("time", startTime + "-" + endTime); + map.put("powerPrice", powerPrice); + map.put("servicePrice", servicePrice); + map.put("chargingDegree", v); + map.put("actPrice", multiply); return map; } /** - * - * @param rateModelId 费率id - * @param startTime2 开始时间 - * @param updateTime2 结算时间 - * @param chargingDegree 总度数 + * @param rateModelId 费率id + * @param startTime2 开始时间 + * @param updateTime2 结算时间 + * @param chargingDegree 总度数 * @return */ private BigDecimal getBigDecimal(Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree) { //算出相差时间,分 - BigDecimal decimal = new BigDecimal((updateTime2.getTime()-startTime2.getTime())/60000).setScale(2); + BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime()) / 60000).setScale(2); //每分钟多少度 - BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_DOWN); - BigDecimal powerPriceTotal =new BigDecimal(0); + BigDecimal degree = chargingDegree.divide(decimal, 2, BigDecimal.ROUND_DOWN); + BigDecimal powerPriceTotal = new BigDecimal(0); //获取费率时间段 String startTime = DateUtil.formatTime(startTime2); String endTime = DateUtil.formatTime(updateTime2); List> reatTimeList = getReatTimeList(startTime, endTime, rateModelId); - if(reatTimeList !=null && reatTimeList.size()>0){ + if (reatTimeList != null && reatTimeList.size() > 0) { int size = reatTimeList.size(); - if(size==1){ + if (size == 1) { BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString()); powerPriceTotal = powerPriceTotal.add(powerFee.multiply(degree).setScale(2, BigDecimal.ROUND_DOWN)); - }else{ - for (int i = 0; i objectMap = reatTimeList.get(i); - BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString()); + BigDecimal powerPrice = new BigDecimal(objectMap.get("powerFee").toString()); String startTime1 = objectMap.get("startTime").toString(); String endTime1 = objectMap.get("endTime").toString(); - if(i==0){ - powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime1,degree,powerPrice)); - }else{ - if(size==2){ - powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime,degree,powerPrice)); - }else{ + if (i == 0) { + powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime, endTime1, degree, powerPrice)); + } else { + if (size == 2) { + powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime, endTime, degree, powerPrice)); + } else { //三个时段以上 - if(i> list = iXhpcRechargeOrderService.page(phone, refundOrderNumber, status, createTimeStart, createTimeEnd,type); + List> list = iXhpcRechargeOrderService.page(phone, rechargeOrderNumber, status, createTimeStart, createTimeEnd,type); return getDataTable(list); } + + /** + * 充值订单页表导出 + */ + //@PreAuthorize(hasPermi = "refund:order:page") + @PostMapping("/export") + public void page(HttpServletResponse response, @RequestBody Map map) throws IOException { + + String phone = map.get("phone").toString(); + String rechargeOrderNumber= map.get("rechargeOrderNumber").toString(); + String status= map.get("status").toString(); + String createTimeStart= map.get("createTimeStart").toString(); + String createTimeEnd= map.get("createTimeEnd").toString(); + Integer type= StringUtils.isNotEmpty(map.get("type").toString())? Integer.valueOf(map.get("type").toString()): null; + + iXhpcRechargeOrderService.export(response, phone, rechargeOrderNumber, status, createTimeStart, createTimeEnd,type); + + } + /** * 统计 */ diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundOrderController.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundOrderController.java index 2a8e8ccb..dff15329 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundOrderController.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/XhpcRefundOrderController.java @@ -12,6 +12,8 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -107,6 +109,23 @@ public class XhpcRefundOrderController extends BaseController { return getDataTable(list); } + + + @PostMapping("/export") + public void export(HttpServletResponse response, @RequestBody Map map) throws IOException { + + String phone = map.get("phone").toString(); + String refundOrderNumber= map.get("refundOrderNumber").toString(); + String status= map.get("status").toString(); + String createTimeStart= map.get("createTimeStart").toString(); + String createTimeEnd= map.get("createTimeEnd").toString(); + Integer type= StringUtils.isNotEmpty(map.get("type").toString())? Integer.valueOf(map.get("type").toString()): null; + + iXhpcRefundOrderService.export(response, phone, refundOrderNumber, status, createTimeStart, createTimeEnd,type); + + } + + /** * 统计 */ diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRechargeOrderService.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRechargeOrderService.java index 7c855f94..059c1f99 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRechargeOrderService.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRechargeOrderService.java @@ -2,6 +2,8 @@ package com.xhpc.payment.service; import com.xhpc.payment.domain.XhpcRechargeOrder; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -40,6 +42,20 @@ public interface IXhpcRechargeOrderService { */ public List> page(String phone, String rechargeOrderNumber, String status, String createTimeStart, String createTimeEnd,Integer type); + + /** + * 充值订单分页列表 + * + * @param phone + * @param rechargeOrderNumber + * @param status + * @param createTimeStart + * @param createTimeEnd + * @return + */ + public void export(HttpServletResponse response, String phone, String rechargeOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) throws IOException; + + /** * 统计 * diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRefundOrderService.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRefundOrderService.java index ecfd9169..aaced891 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRefundOrderService.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/IXhpcRefundOrderService.java @@ -4,6 +4,8 @@ import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.payment.domain.XhpcRefundOrder; import org.apache.ibatis.annotations.Param; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -43,6 +45,20 @@ public interface IXhpcRefundOrderService { public List> page(String phone, String refundOrderNumber, String status, String createTimeStart, String createTimeEnd,Integer type); + + /** + * 退款订单分页列表导出 + * + * @param phone + * @param refundOrderNumber + * @param status + * @param createTimeStart + * @param createTimeEnd + * @return + */ + public void export(HttpServletResponse response, String phone, String refundOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) throws IOException; + + /** * 退款订单分页列表 * diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRechargeOrderServiceImpl.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRechargeOrderServiceImpl.java index 0ac3f4d8..84e1006e 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRechargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRechargeOrderServiceImpl.java @@ -1,5 +1,8 @@ package com.xhpc.payment.service.impl; +import cn.hutool.core.io.IoUtil; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.utils.StringUtils; import com.xhpc.payment.domain.XhpcRechargeOrder; @@ -9,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -66,6 +72,45 @@ public class XhpcRechargeOrderServiceImpl implements IXhpcRechargeOrderService { return xhpcRechargeOrderMapper.page(phone, rechargeOrderNumber, status, createTimeStart, createTimeEnd,type); } + + @Override + public void export(HttpServletResponse response, String phone, String rechargeOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) throws IOException { + List list = xhpcRechargeOrderMapper.page(phone, rechargeOrderNumber, status, createTimeStart, createTimeEnd,type); + + // 通过工具类创建writer,默认创建xls格式 + ExcelWriter writer = ExcelUtil.getWriter(); + writer.addHeaderAlias("rechargeOrderId", "充值订单id"); + writer.addHeaderAlias("rechargeOrderNumber", "充值订单编号"); + writer.addHeaderAlias("userId", "C端用户id"); + writer.addHeaderAlias("amount", "退款金额"); + writer.addHeaderAlias("alipayNumber", "账号"); + writer.addHeaderAlias("prepayid", "微信编号"); + writer.addHeaderAlias("type", "充值渠道(1微信 2支付宝)"); + writer.addHeaderAlias("status", "状态(0待支付 1充值成功,2充值失败)"); + writer.addHeaderAlias("createTime", "充值时间"); + writer.addHeaderAlias("phone", "账号"); + writer.addHeaderAlias("statusName", "充值状态"); + + // 默认的,未添加alias的属性也会写出,如果想只写出加了别名的字段,可以调用此方法排除之 + writer.setOnlyAlias(true); + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + //out为OutputStream,需要写出到的目标流 + + //response为HttpServletResponse对象 + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=充值订单列表.xls"); + ServletOutputStream out = response.getOutputStream(); + + writer.flush(out, true); + // 关闭writer,释放内存 + writer.close(); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + + @Override public String sumMoney(String phone, String rechargeOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) { diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRefundOrderServiceImpl.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRefundOrderServiceImpl.java index 370ad085..2d689dae 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRefundOrderServiceImpl.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/service/impl/XhpcRefundOrderServiceImpl.java @@ -1,5 +1,8 @@ package com.xhpc.payment.service.impl; +import cn.hutool.core.io.IoUtil; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import com.xhpc.common.core.constant.HttpStatus; import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.utils.StringUtils; @@ -13,6 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -68,6 +74,46 @@ public class XhpcRefundOrderServiceImpl implements IXhpcRefundOrderService { return xhpcRefundOrderMapper.page(phone, rechargeOrderNumber, status, createTimeStart, createTimeEnd,type); } + + @Override + public void export(HttpServletResponse response, String phone, String refundOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) throws IOException { + List list = xhpcRefundOrderMapper.page(phone, refundOrderNumber, status, createTimeStart, createTimeEnd,type); + +// 通过工具类创建writer,默认创建xls格式 + ExcelWriter writer = ExcelUtil.getWriter(); + writer.addHeaderAlias("refundOrderId", "退款订单id"); + writer.addHeaderAlias("refundOrderNumber", "退款订单编号"); +// writer.addHeaderAlias("alipayId", "电站名称"); +// writer.addHeaderAlias("openId", "桩编号"); + writer.addHeaderAlias("userId", "C端用户id"); + writer.addHeaderAlias("amount", "退款金额"); + writer.addHeaderAlias("examineStatus", "审核状态(0审核中 1审核通过,2审核失败)"); + writer.addHeaderAlias("status", "状态(0退款中 1退款成功,2退款失败,3退款异常)"); + writer.addHeaderAlias("createTime", "退款时间"); + writer.addHeaderAlias("phone", "账号"); + writer.addHeaderAlias("statusName", "退款状态"); + writer.addHeaderAlias("examineStatusName", "审核状态名称"); + + // 默认的,未添加alias的属性也会写出,如果想只写出加了别名的字段,可以调用此方法排除之 + writer.setOnlyAlias(true); + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + //out为OutputStream,需要写出到的目标流 + + //response为HttpServletResponse对象 + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=退款订单列表.xls"); + ServletOutputStream out = response.getOutputStream(); + + writer.flush(out, true); + // 关闭writer,释放内存 + writer.close(); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + + } + @Override public String sumMoney(String phone, String refundOrderNumber, String status, String createTimeStart, String createTimeEnd, Integer type) {