记得上下班打卡 | git大法好,push需谨慎

Commit 64a35726 authored by limingyang's avatar limingyang

商城订单信息追加行导出

parent 45662445
......@@ -2,10 +2,11 @@ package com.liquidnet.client.admin.web.controller.zhengzai.tools;
import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.exception.BusinessException;
import com.liquidnet.client.admin.common.utils.poi.ExcelUtil;
import com.liquidnet.client.admin.zhengzai.kylin.dto.*;
import com.liquidnet.client.admin.zhengzai.kylin.service.IExportService;
import com.liquidnet.service.kylin.dao.TestDao;
import com.liquidnet.service.kylin.dao.MallOrdertDao;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -99,12 +100,13 @@ public class ExportDataController extends BaseController {
if (!timeIsNotNull(beginTime, endTime)) {
return error("开始时间和结束时间不能为空!");
}
List<TestDao> voList = exportService.exportMallOrder(beginTime, endTime, state ,mailType);
List<MallOrdertDao> voList = exportService.exportMallOrder(beginTime, endTime, state ,mailType);
AjaxResult ajaxResult = null;
Map<String, List<String>> map = new HashMap<>();
int max = 0;
//将数据保存到list中
if (voList != null && voList.size() > 0) {
for (TestDao te : voList) {
for (MallOrdertDao te : voList) {
String orderCode = te.getOrderCode();
if (map.get(orderCode) == null) {
List<String> list = new ArrayList<>();
......@@ -142,19 +144,20 @@ public class ExportDataController extends BaseController {
list.add(te.getNum());
list.add(te.getSkuPrice());
list.add(te.getSkuPriceActual());
list.add(te.getOrderSkuId());
max = Math.max(max, list.size());
map.put(orderCode, list);
}
}
exportexcel(map, "order", max);
ajaxResult = exportexcel(map, "order", max);
}
if (voList.size() == 0) {
return error("查无信息");
}
return AjaxResult.success("导出成功!");
return ajaxResult;
}
private void exportexcel(Map<String, List<String>> map, String name, int max) {
private AjaxResult exportexcel(Map<String, List<String>> map, String name, int max) {
//实例化XSSFWorkbook对象,相当于新建一个Excel文件
XSSFWorkbook workbook = new XSSFWorkbook();
//根据XSSFWorkbook获取Sheet
......@@ -165,65 +168,39 @@ public class ExportDataController extends BaseController {
//创建表格样式
XSSFCellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setAlignment(CellStyle.ALIGN_CENTER);//内容居中显示
//创建头部表格
XSSFCell cell = header.createCell(0);
cell.setCellStyle(cellStyle);
cell.setCellValue("订单编号");
cell = header.createCell(1);
cell.setCellStyle(cellStyle);
cell.setCellValue("购买人手机号");
cell = header.createCell(2);
cell.setCellStyle(cellStyle);
cell.setCellValue("快递费");
cell = header.createCell(3);
cell.setCellStyle(cellStyle);
cell.setCellValue("平台券优惠券金额");
cell = header.createCell(4);
cell.setCellStyle(cellStyle);
cell.setCellValue("店铺券优惠金额");
cell = header.createCell(5);
cell.setCellStyle(cellStyle);
cell.setCellValue("收货人");
cell = header.createCell(6);
cell.setCellStyle(cellStyle);
cell.setCellValue("收货人电话");
cell = header.createCell(7);
cell.setCellStyle(cellStyle);
cell.setCellValue("快递地址");
cell = header.createCell(8);
cell.setCellStyle(cellStyle);
cell.setCellValue("支付方式");
cell = header.createCell(9);
cell.setCellStyle(cellStyle);
cell.setCellValue("支付时间");
cell = header.createCell(10);
cell.setCellStyle(cellStyle);
cell.setCellValue("下单时间");
cell = header.createCell(11);
cell.setCellStyle(cellStyle);
cell.setCellValue("快递公司");
cell = header.createCell(12);
int index = 0;
//固定表头
List<String> fixedCells = fixedCells();
for (String cname : fixedCells) {
index++;
cell = header.createCell(index);
cell.setCellStyle(cellStyle);
cell.setCellValue("物流单号");
cell.setCellValue(cname);
}
int n = 12;
int index = 0;
int n = 13; //固定表头13个
int indext = 0;
//追加表头
List<String> cells = appendCells();
while (n < max - 1) {
index++;
while (n < max) {
indext++;
for (String cname : cells) {
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue(cname + index);
cell.setCellValue(cname + indext);
n++;
}
}
int z = 1;
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
List<String> list = entry.getValue();
//获取每行
XSSFRow content = sheet.createRow(z);
//获取员工
for (int i = 0; i < list.size(); i++) {
//创建单元格并设置值
content.createCell(i).setCellValue(list.get(i));
......@@ -232,15 +209,15 @@ public class ExportDataController extends BaseController {
}
OutputStream fileOutputStream = null;
try {
ExcelUtil<TestDao> util = new ExcelUtil(TestDao.class);
ExcelUtil<MallOrdertDao> util = new ExcelUtil(MallOrdertDao.class);
String filename = util.encodingFilename(name);
//写入文件
fileOutputStream = new FileOutputStream(util.getAbsoluteFile(filename));
workbook.write(fileOutputStream);
System.out.println("导出成功!");
return AjaxResult.success(filename);
} catch (IOException e) {
e.printStackTrace();
System.out.println("导出失败!");
throw new BusinessException("导出Excel失败,请联系网站管理员!");
} finally {
if (workbook != null) {
try {
......@@ -259,6 +236,24 @@ public class ExportDataController extends BaseController {
}
}
//固定表头
private List<String> fixedCells() {
List<String> cells = new ArrayList<>();
cells.add("购买人手机号");
cells.add("快递费");
cells.add("平台券优惠券金额");
cells.add("店铺券优惠金额");
cells.add("收货人");
cells.add("收货人电话");
cells.add("快递地址");
cells.add("支付方式");
cells.add("支付时间");
cells.add("下单时间");
cells.add("快递公司");
cells.add("物流单号");
return cells;
}
//追加表头
private List<String> appendCells() {
List<String> cells = new ArrayList<>();
cells.add("商品id");
......@@ -269,6 +264,7 @@ public class ExportDataController extends BaseController {
cells.add("数量");
cells.add("单价");
cells.add("价格");
cells.add("订单skuId");
return cells;
}
......
package com.liquidnet.client.admin.zhengzai.kylin.service;
import com.liquidnet.client.admin.zhengzai.kylin.dto.*;
import com.liquidnet.service.kylin.dao.TestDao;
import com.liquidnet.service.kylin.dao.MallOrdertDao;
import java.util.List;
......@@ -23,7 +23,7 @@ public interface IExportService {
//导出会员订单信息
List<OrderMemberExportVo> exportMemberOrder(String beginTime, String endTime);
List<TestDao> exportMallOrder(String beginTime, String endTime, String state, Integer mailType);
List<MallOrdertDao> exportMallOrder(String beginTime, String endTime, String state, Integer mailType);
//导出商品订单信息
List<OrderCommodityExportVo> exportCommodityOrder(String beginTime, String endTime);
......
......@@ -6,7 +6,7 @@ import com.liquidnet.client.admin.zhengzai.kylin.service.IExportService;
import com.liquidnet.service.kylin.dao.CommodityOrderExportDao;
import com.liquidnet.service.kylin.dao.MemberOrderExportDao;
import com.liquidnet.service.kylin.dao.OrderExportDao;
import com.liquidnet.service.kylin.dao.TestDao;
import com.liquidnet.service.kylin.dao.MallOrdertDao;
import com.liquidnet.service.kylin.mapper.KylinPerformancesMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -111,13 +111,13 @@ public class ExportServiceImpl implements IExportService {
}
@Override
public List<TestDao> exportMallOrder(String beginTime, String endTime, String state, Integer mailType) {
public List<MallOrdertDao> exportMallOrder(String beginTime, String endTime, String state, Integer mailType) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date beginDate = sdf.parse(beginTime);
Date endDate = sdf.parse(endTime);
List<String> states = Arrays.asList(state.split(","));
List<TestDao> list = performancesMapper.exportMallOrder(beginDate, endDate, states, mailType);
List<MallOrdertDao> list = performancesMapper.exportMallOrder(beginDate, endDate, states, mailType);
return list;
} catch (ParseException e) {
e.printStackTrace();
......
......@@ -3,7 +3,7 @@ package com.liquidnet.service.kylin.dao;
import lombok.Data;
@Data
public class TestDao {
public class MallOrdertDao {
//订单编号
private String orderCode;
//购买人手机号
......@@ -36,6 +36,8 @@ public class TestDao {
private String skuPrice;
//价格
private String skuPriceActual;
//订单skuId
private String orderSkuId;
//支付方式
private String payType;
//支付时间
......
......@@ -82,6 +82,6 @@ public interface KylinPerformancesMapper extends BaseMapper<KylinPerformances> {
//商品订单信息
List<CommodityOrderExportDao> exportCommodityOrder(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
List<TestDao> exportMallOrder(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime, @Param("states") List<String>
List<MallOrdertDao> exportMallOrder(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime, @Param("states") List<String>
states, @Param("mailType") Integer mailType);
}
......@@ -100,7 +100,7 @@
<result column="refund_at" property="refundAt"/>
</resultMap>
<resultMap id="testDaoResult" type="com.liquidnet.service.kylin.dao.TestDao">
<resultMap id="testDaoResult" type="com.liquidnet.service.kylin.dao.MallOrdertDao">
<result column="order_code" property="orderCode"/>
<result column="user_mobile" property="userMobile"/>
<result column="price_express" property="priceExpress"/>
......@@ -117,6 +117,7 @@
<result column="num" property="num"/>
<result column="sku_price" property="skuPrice"/>
<result column="sku_price_actual" property="skuPriceActual"/>
<result column="order_sku_id" property="orderSkuId"/>
<result column="pay_type" property="payType"/>
<result column="pay_time" property="payTime"/>
<result column="created_at" property="createdAt"/>
......@@ -1100,7 +1101,8 @@ GROUP BY user_mobile;
gos.sku_name as sku_name,
gos.num as num,
gos.sku_price as sku_price,
gos.sku_price_actual as sku_price_actual
gos.sku_price_actual as sku_price_actual,
gos.order_sku_id as order_sku_id
from goblin_store_order as gso
inner join goblin_order_sku as gos on gos.order_id = gso.order_id
inner join (select spu_id, gg.name, gsgc1.name as cate1_name, gsgc2.name as cate2_name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment