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

Commit ee6f661c authored by limingyang's avatar limingyang

商城订单追加导出

parent 1fc712ac
......@@ -5,7 +5,9 @@ import com.liquidnet.client.admin.common.core.domain.AjaxResult;
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 org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -13,13 +15,17 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
@Controller
@RequestMapping("tools/export")
public class ExportDataController extends BaseController {
private static ExcelUtil<Object> excelUtil;
@Autowired
private IExportService exportService;
......@@ -80,6 +86,204 @@ public class ExportDataController extends BaseController {
return StringUtils.isNotBlank(beginTime) && StringUtils.isNotBlank(endTime) ? true : false;
}
/**
* test
*
* @param beginTime
* @param endTime
* @return
*/
@PostMapping("/export/test")
@ResponseBody
public AjaxResult test(String beginTime, String endTime, Integer state, Integer mailType) {
if (!timeIsNotNull(beginTime, endTime)) {
return error("开始时间和结束时间不能为空!");
}
List<TestDao> voList = exportService.test(beginTime, endTime, state ,mailType);
Map<String, List<String>> map = new HashMap<>();
int max = 0;
//将数据保存到list中
if (voList != null && voList.size() > 0) {
for (TestDao te : voList) {
String orderCode = te.getOrderCode();
if (map.get(orderCode) == null) {
List<String> list = new ArrayList<>();
list.add(te.getOrderCode());
list.add(te.getPriceExpress());
list.add(te.getPriceCoupon());
list.add(te.getStorePriceCoupon());
list.add(te.getExpressContacts());
list.add(te.getExpressPhone());
list.add(te.getExpressDetailAddress());
list.add(te.getPayType());
list.add(te.getPayTime());
list.add(te.getCreatedAt());
list.add(te.getLogisticsCompany());
list.add(te.getMailNo());
list.add(te.getSpuId());
list.add(te.getName());
list.add(te.getCate1Name());
list.add(te.getCate2Name());
list.add(te.getSkuName());
list.add(te.getNum());
list.add(te.getSkuPrice());
list.add(te.getSkuPriceActual());
max = max > list.size() ? max : list.size();
map.put(orderCode, list);
}
if (map.get(orderCode) != null) {
List<String> list = map.get(orderCode);
list.add(te.getSpuId());
list.add(te.getName());
list.add(te.getCate1Name());
list.add(te.getCate2Name());
list.add(te.getSkuName());
list.add(te.getNum());
list.add(te.getSkuPrice());
list.add(te.getSkuPriceActual());
max = max > list.size() ? max : list.size();
map.put(orderCode, list);
}
}
exportexcel(map, "表名test01", max);
}
if (voList.size() == 0) {
return error("查无信息");
}
return AjaxResult.success("ok!");
}
private void exportexcel(Map<String, List<String>> map, String name, int max) {
//实例化XSSFWorkbook对象,相当于新建一个Excel文件
XSSFWorkbook workbook = new XSSFWorkbook();
//根据XSSFWorkbook获取Sheet
XSSFSheet sheet = workbook.createSheet();
//添加一行作为表格头
XSSFRow header = sheet.createRow(0);
//创建表格样式
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);
cell.setCellStyle(cellStyle);
cell.setCellValue("物流单号");
int n = 12;
while (n <= max) {
int z = n / 20 + 1;
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("商品id" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("商品名" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("一级分类" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("二级分类" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("款式" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("数量" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("单价" + z);
n++;
cell = header.createCell(n);
cell.setCellStyle(cellStyle);
cell.setCellValue("价格" + z);
}
int z = 1;
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String orderCode = entry.getKey();
List<String> list = entry.getValue();
XSSFRow content = sheet.createRow(z);
content.createCell(0).setCellValue(orderCode);
//获取员工
for (int i = 0; i < list.size(); i++) {
//创建单元格并设置值
content.createCell(i + 1).setCellValue(list.get(i));
}
z++;
}
OutputStream fileOutputStream = null;
try {
ExcelUtil<TestDao> util = new ExcelUtil(TestDao.class);
String filename = util.encodingFilename(name);
//写入文件
fileOutputStream = new FileOutputStream(util.getAbsoluteFile(filename));
workbook.write(fileOutputStream);
System.out.println("导出成功!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("导出失败!");
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 导出会员订单
*
......
package com.liquidnet.client.admin.zhengzai.kylin.service;
import com.liquidnet.client.admin.zhengzai.kylin.dto.*;
import com.liquidnet.service.kylin.dao.TestDao;
import java.util.List;
......@@ -22,6 +23,8 @@ public interface IExportService {
//导出会员订单信息
List<OrderMemberExportVo> exportMemberOrder(String beginTime, String endTime);
List<TestDao> test(String beginTime, String endTime, Integer state, Integer mailType);
//导出商品订单信息
List<OrderCommodityExportVo> exportCommodityOrder(String beginTime, String endTime);
}
......@@ -6,6 +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.mapper.KylinPerformancesMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -108,6 +109,20 @@ public class ExportServiceImpl implements IExportService {
}
}
@Override
public List<TestDao> test(String beginTime, String endTime, Integer 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<TestDao> list = performancesMapper.test(beginDate,endDate, state, mailType);
return list;
} catch (ParseException e) {
e.printStackTrace();
throw new BusinessException("导出Excel失败,请联系网站管理员!");
}
}
@Override
public List<OrderCommodityExportVo> exportCommodityOrder(String beginTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......
package com.liquidnet.service.kylin.dao;
import lombok.Data;
@Data
public class TestDao {
//订单编号
private String orderCode;
//购买人手机号
private String userMobile;
//快递费
private String priceExpress;
//平台券优惠金额
private String priceCoupon;
//店铺券优惠金额
private String storePriceCoupon;
//收货人
private String expressContacts;
//收货人电话
private String expressPhone;
//快递地址
private String expressDetailAddress;
//商品id
private String spuId;
//商品名
private String name;
//一级分类
private String cate1Name;
//二级分类
private String cate2Name;
//款式
private String skuName;
//数量
private String num;
//单价
private String skuPrice;
//价格
private String skuPriceActual;
//支付方式
private String payType;
//支付时间
private String payTime;
//下单时间
private String createdAt;
//快递公司
private String logisticsCompany;
//物流单号
private String mailNo;
}
......@@ -81,4 +81,7 @@ public interface KylinPerformancesMapper extends BaseMapper<KylinPerformances> {
List<MemberOrderExportDao> exportMemberOrder(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
//商品订单信息
List<CommodityOrderExportDao> exportCommodityOrder(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
List<TestDao> test(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime, @Param("state") Integer
state, @Param("mailType") Integer mailType);
}
......@@ -99,6 +99,30 @@
<result column="status" property="status"/>
<result column="refund_at" property="refundAt"/>
</resultMap>
<resultMap id="testDaoResult" type="com.liquidnet.service.kylin.dao.TestDao">
<result column="order_code" property="orderCode"/>
<result column="user_mobile" property="userMobile"/>
<result column="price_express" property="priceExpress"/>
<result column="price_coupon" property="priceCoupon"/>
<result column="store_price_coupon" property="storePriceCoupon"/>
<result column="express_contacts" property="expressContacts"/>
<result column="express_phone" property="expressPhone"/>
<result column="express_detail_address" property="expressDetailAddress"/>
<result column="spu_id" property="spuId"/>
<result column="name" property="name"/>
<result column="cate1_name" property="cate1Name"/>
<result column="cate2_name" property="cate2Name"/>
<result column="sku_name" property="skuName"/>
<result column="num" property="num"/>
<result column="sku_price" property="skuPrice"/>
<result column="sku_price_actual" property="skuPriceActual"/>
<result column="pay_type" property="payType"/>
<result column="pay_time" property="payTime"/>
<result column="created_at" property="createdAt"/>
<result column="logistics_company" property="logisticsCompany"/>
<result column="mail_no" property="mailNo"/>
</resultMap>
<!-- <resultMap id="OrderExportDaoResult" type="com.liquidnet.service.kylin.dao.OrderExportDao">-->
<!-- <result column="performance_title" property="performanceTitle"/>-->
<!-- <result column="user_mobile" property="userMobile"/>-->
......@@ -1055,6 +1079,52 @@ GROUP BY user_mobile;
and gso.status not in (0, 5)
group by do.code) temtable group by temtable.code
</select>
<select id="test" resultMap="testDaoResult">
select gso.order_code as order_code,
gso.user_mobile as user_mobile,
gso.price_express as price_express,
gso.price_coupon as price_coupon,
gso.store_price_coupon as store_price_coupon,
goa.express_contacts as express_contacts,
goa.express_phone as express_phone,
CONCAT(goa.express_address,' ',goa.express_address_detail) as express_detail_address,
gso.pay_type as pay_type,
gso.pay_time as pay_time,
gso.created_at as created_at,
gm.logistics_company as logistics_company,
gm.mail_no as mail_no,
gos.spu_id as spu_id,
gg.name as name,
gg.cate1_name as cate1_name,
gg.cate2_name as cate2_name,
gos.sku_name as sku_name,
gos.num as num,
gos.sku_price as sku_price,
gos.sku_price_actual as sku_price_actual
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
from goblin_goods as gg
left join goblin_self_goods_category as gsgc1 on gsgc1.cate_id = gg.cate_fid
left join goblin_self_goods_category as gsgc2 on gsgc2.cate_id = gg.cate_sid) as gg
on gos.spu_id = gg.spu_id
inner join goblin_order_attr as goa on goa.order_id = gso.order_id
left join goblin_mail as gm on gm.order_id = gso.order_id
<where>
<if test="beginTime != null and endTime != null">
and gso.created_at between #{beginTime} and #{endTime}
</if>
<if test="state != null">
and gso.status in (2, 3, 4)
</if>
<if test="mailType != null and mailType == '1'">
and ggm.mail_no is null;
</if>
<if test="mailType != null and mailType == '2'">
and gm.mail_no is not null;
</if>
</where>
</select>
</mapper>
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