Commit 007da332 authored by liuzeheng's avatar liuzeheng

execl 导出

parent 2cfdc0f9
......@@ -655,8 +655,19 @@ public interface OrderMapper extends AbstractMapper<OrderDO> {
List<OrderExcelVO> exportOrderExcelList(@Param("start")int start, @Param("size") int size,@Param("query") OrderQueryVO query);
/**
* execl 导出
* @param start
* @param size
* @param query
* @return
*/
List<OrderExcelVO> exportMyOrderExcelList(@Param("start")int start, @Param("size") int size,@Param("query") OrderQueryDTO query);
long exportOrderExcelCount(@Param("query") OrderQueryVO query);
long exportMyOrderExcelCount(@Param("query") OrderQueryDTO query);
@ResultType(OrderBackPageVO.class)
@Select({
"<script>",
......
......@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.order.listener.export;
import cn.iocoder.yudao.framework.apollo.core.event.export.OrderExcelExportEvent;
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
import cn.iocoder.yudao.module.order.dto.OrderQueryDTO;
import cn.iocoder.yudao.module.order.service.order.OrderQueryService;
import cn.iocoder.yudao.module.order.vo.order.OrderQueryVO;
import com.alibaba.fastjson.JSONObject;
......@@ -53,4 +54,26 @@ public class OrderExcelExportListener {
}
}
@EventListener(OrderExcelExportEvent.class)
public void MyOrderExcelExportEvent(OrderExcelExportEvent event) throws IOException {
if (StringUtils.isNotBlank(event.getRequestParams())){
try {
OrderQueryDTO query = JSONObject.parseObject(event.getRequestParams(), OrderQueryDTO.class);
query.setLang(event.getLang());
FileDO fileDO = orderQueryService.makeMyOrderExcelFile(event.getUserId(), event.getUserType(), query);
event.setPath(fileDO.getPath());
event.setFileName(fileDO.getPath());
event.setUrl(fileDO.getUrl());
event.setFileId(fileDO.getId());
}catch (Exception e){
// TODO 测试阶段打印堆栈错误信息,便于分析原因
e.printStackTrace();
event.setResult(e.getMessage());
}
}else {
event.setResult("param fail");
}
}
}
......@@ -318,6 +318,8 @@ public interface OrderQueryService {
FileDO makeOrderExcelFile(Long userId, Integer userType, OrderQueryVO query) throws Exception;
FileDO makeMyOrderExcelFile(Long userId, Integer userType, OrderQueryDTO query) throws Exception;
List<OrderExceptionStatisticsExcelVo> getOrderExceptionStatisticsExcel(OrderQueryVO query);
List<OrderHeavyExcelVo> getHeavyOrderExcelList(OrderQueryVO query);
......
......@@ -1873,6 +1873,87 @@ public class OrderQueryServiceImpl implements OrderQueryService {
return fileDO;
}
@Override
public FileDO makeMyOrderExcelFile(Long userId, Integer userType, OrderQueryDTO query) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATA_FORMAT);
String nowTime = formatter.format(LocalDateTime.now());
String sheetName = query.getLang() == 0 ? "订单管理第{0}页" : "Order Management number {0}";
if (Objects.isNull(userId)) {
userId = 0L;
}
if (Objects.isNull(userType)) {
userType = 2;
}
String fileName = userId.toString().concat(StrUtil.DASHED).concat(userType.toString()).concat(StrUtil.DASHED).concat(nowTime).concat(".xlsx");
String dir = ueProperties.getTempDir().concat("/excel/");
// 创建需要写入的文件目录
File fileDir = new File(dir);
if (!fileDir.exists()) {
// 不存在则创建一个目录
fileDir.mkdirs();
}
String path = dir + fileName;
// 创建写入的输出流
OutputStream out = new FileOutputStream(path);
ExcelWriter excelWriter = EasyExcel.write(out, OrderExcelVO.class).inMemory(true).build();
PageVO page = new PageVO();
page.setField("o.order_id");
long total = orderMapper.exportMyOrderExcelCount(query);
int pageNumber = (int) Math.ceil((double) total / (double) PAGE_SIZE); //分页条数看情况
// 去调用写入,根据数据库分页的总的页数来
for (int i = 1; i <= pageNumber; i++) {
// 根据最大查询值配置来进行sheet分页
WriteSheet writeSheet = EasyExcel.writerSheet(MessageFormat.format(sheetName, i)).registerWriteHandler(new WaterMarkHandler("捷道机密文件,禁止传播")).build();
//先定义一个空集合每次循环使他变成null减少内存的占用
int start = (i - 1) * PAGE_SIZE;
int end = i * PAGE_SIZE;
page.setField("o.order_id");
List<OrderExcelVO> pageList = orderMapper.exportMyOrderExcelList(start, end, query).stream().peek(excData -> {
WarehouseInInfoVO warehouseInInfoVO = excData.getWarehouseInInfoVO();
if (Objects.nonNull(warehouseInInfoVO)) {
List<OrderLocationMergeVO> orderLocationSet = warehouseInInfoVO.getOrderLocationMergeVOSet();
String storageLocation = "";
if (CollectionUtil.isNotEmpty(orderLocationSet)) {
for (OrderLocationMergeVO vo : orderLocationSet) {
if (StringUtils.isBlank(storageLocation)) {
storageLocation = vo.getAreaName() + vo.getLocationName();
} else {
storageLocation = storageLocation + "," + vo.getAreaName() + vo.getLocationName();
}
}
}
excData.setStorageLocation(storageLocation);
}
String consignorPhone = "+" + excData.getConsignorCountryCode() + excData.getConsignorPhone();
String consigneePhone = "+" + excData.getConsigneeCountryCode() + excData.getConsigneePhone();
excData.setConsignorPhone(consignorPhone);
excData.setConsigneePhone(consigneePhone);
}).collect(Collectors.toList());
excelWriter.write(pageList, writeSheet);
pageList.clear();
}
// 千万别忘记finish 会帮忙关闭流
excelWriter.finish();
out.flush();
// 获取到临时文件
File file = new File(path);
// 创建FileInputStream对象
FileInputStream fileInputStream = new FileInputStream(file);
// 读取文件内容
byte[] fileBytes = new byte[(int) file.length()];
fileInputStream.read(fileBytes);
// 关闭文件流
fileInputStream.close();
// 将文件上传到资源服务器
FileDO fileDO = fileService.createFile(dir, fileName, fileBytes);
// 删除临时文件
FileUtil.del(file);
fileDO.setFileName(fileName);
return fileDO;
}
/**
* 获取异常单统计信息
*
......
......@@ -3709,6 +3709,95 @@
<include refid="orderQuery"/>
limit #{start}, #{size}
</select>
<select id="exportMyOrderExcelList" resultType="cn.iocoder.yudao.module.order.vo.order.OrderExcelVO">
select
IF(#{query.lang} = 0, it.prod_title_zh, it.prod_title_en) as prod_title,
it.prod_title_zh,
it.prod_title_en,
IFNULL((select IF(#{query.lang} = 0, pb.title_zh, pb.title_en) from ecw_product_brank pb where pb.id =
it.brand), '') as brand_name,
IF(it.warehouse_in_info is not null, it.warehouse_in_info->>'$.cartonsNum', 0) as num,
IF(it.warehouse_in_info is not null, it.warehouse_in_info->>'$.volume', 0) as volume,
IF(it.warehouse_in_info is not null, it.warehouse_in_info->>'$.weight', 0) as weight,
IF(it.warehouse_in_info is not null, it.warehouse_in_info->>'$.unit', 1) as unit,
IF(it.warehouse_in_info is not null, it.warehouse_in_info->>'$.quantityAll', 0) as quantity,
it.warehouse_in_info as warehouse_in_info,
it.worth as worth,
o.sum_num as total_num,
o.sum_volume as total_volume,
o.sum_weight as total_weight,
o.order_no,
o.tidan_no,
o.customs_type,
o.air_shipment,
(select MIN(owi.in_time) from ecw_order_warehouse_in owi where owi.order_item_id = it.order_item_id) as
rucang_time,
w.start_warehouse_name,
w.dest_warehouse_name,
o.marks,
o.status,
o.abnormal_state,
o.in_warehouse_state,
o.shipment_state,
o.audit_type,
o.audit_result,
o.transport_id,
o.is_cargo_control,
o.cargo_control_status,
o.exception_reason,
o.create_time,
if(#{query.userType} = 1, 1, 2) as user_type,
nor.name as consignor_name,
nor.name_en as consignor_name_en,
nor.phone as consignor_phone,
nor.country_code as consignor_country_code,
nee.name as consignee_name,
nee.name_en as consignee_name_en,
nee.phone as consignee_phone,
nee.country_code as consignee_country_code,
o.update_time,
#{query.lang} as lang
from ecw_order_item it
left join ecw_order o
ON it.order_id = o.order_id and it.deleted = 0
left join (
SELECT
ewl.id AS line_id,
ew_start.id AS start_warehouse_id,
ew_dest.id AS dest_warehouse_id,
IF( #{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en ) AS dest_warehouse_name,
IF( #{query.lang} = 0, ew_start.title_zh, ew_start.title_en ) AS start_warehouse_name,
#{query.lang} as lang
FROM
ecw_warehouse_line ewl
LEFT JOIN ecw_warehouse ew_start ON ewl.start_warehouse_id = ew_start.id
LEFT JOIN ecw_warehouse ew_dest ON ewl.dest_warehouse_id = ew_dest.id
) w ON w.line_id = o.line_id
left join ecw_order_departure de on de.order_id = o.order_id
left join ecw_order_objective ob on ob.order_id = o.order_id
left join ecw_order_consignor nor on nor.order_id = o.order_id
left join ecw_order_consignee nee on nee.order_id = o.order_id
left join ecw_channel channel on channel.channel_id = o.channel_id
where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10
<if test="query.deptId != null ">
AND o.dept_id = #{query.deptId}
</if>
<if test="query.deptIdList != null and query.deptIdList.size() > 0">
AND (o.dept_id IN
<foreach item="deptId" collection="query.deptIdList" open="(" close=")" separator=",">
#{deptId}
</foreach>
or
(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN
<foreach item="deptId" collection="query.deptIdList" open="(" close=")" separator=",">
#{deptId}
</foreach>
)
</if>
<include refid="myOrderQuery"/>
limit #{start}, #{size}
</select>
<select id="exportOrderExcelCount" resultType="long">
select
count(1)
......@@ -3751,6 +3840,48 @@
<include refid="orderQuery"/>
</select>
<select id="exportMyOrderExcelCount" resultType="long">
select
count(1)
from ecw_order_item it
left join ecw_order o
ON it.order_id = o.order_id and it.deleted = 0
left join (
SELECT
ewl.id AS line_id,
ew_start.id AS start_warehouse_id,
ew_dest.id AS dest_warehouse_id,
IF( #{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en ) AS dest_warehouse_name,
IF( #{query.lang} = 0, ew_start.title_zh, ew_start.title_en ) AS start_warehouse_name
FROM
ecw_warehouse_line ewl
LEFT JOIN ecw_warehouse ew_start ON ewl.start_warehouse_id = ew_start.id
LEFT JOIN ecw_warehouse ew_dest ON ewl.dest_warehouse_id = ew_dest.id
) w ON w.line_id = o.line_id
left join ecw_order_departure de on de.order_id = o.order_id
left join ecw_order_objective ob on ob.order_id = o.order_id
left join ecw_order_consignor nor on nor.order_id = o.order_id
left join ecw_order_consignee nee on nee.order_id = o.order_id
left join ecw_channel channel on channel.channel_id = o.channel_id
where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10
<if test="query.deptId != null ">
AND o.dept_id = #{query.deptId}
</if>
<if test="query.deptIdList != null and query.deptIdList.size() > 0">
AND (o.dept_id IN
<foreach item="deptId" collection="query.deptIdList" open="(" close=")" separator=",">
#{deptId}
</foreach>
or
(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN
<foreach item="deptId" collection="query.deptIdList" open="(" close=")" separator=",">
#{deptId}
</foreach>
)
</if>
<include refid="myOrderQuery"/>
</select>
<select id="getAirRefreshOrderPrice" resultType="cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO">
select * from ecw_order o
where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10
......
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