Browse Source

feat(all): 完善价格体系导入

dist.1.3.0
zhaoqiaobo 9 months ago
parent
commit
9fa3ef3b90
  1. 47
      blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/vo/BasicdataPriceImportVO.java
  2. 13
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/constant/BasicdataConstants.java
  3. 73
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/dto/BasicdataPriceRouteImportDTO.java
  4. 16
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/DispatchPricingTypeEnums.java
  5. 6
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/FullVehicleTypeEnums.java
  6. 4
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/WarehousePricingTypeEnums.java
  7. 34
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryBasicExcel.java
  8. 38
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryDispatchExcel.java
  9. 27
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryWarehouseExcel.java
  10. 19
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceExcel.java
  11. 32
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceFullVehicleExcel.java
  12. 56
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceGeneralExcel.java
  13. 14
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataPriceMapper.java
  14. 18
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataPriceMapper.xml
  15. 1175
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataPriceServiceImpl.java
  16. 81
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/util/EasyExcelUtil.java
  17. 43
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/util/TrimConverter.java

47
blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/vo/BasicdataPriceImportVO.java

@ -0,0 +1,47 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package com.logpm.basicdata.vo;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logpm.basicdata.entity.BasicdataPriceEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.util.Date;
/**
* 基础价格表 实体类
*
* @author zqb
* @since 2024-04-02
*/
@Data
@ApiModel(value = "BasicdataPrice对象", description = "基础价格表")
@EqualsAndHashCode(callSuper = true)
public class BasicdataPriceImportVO extends BasicdataPriceEntity {
@ApiModelProperty(value = "客户名称")
private String clientName;
@ApiModelProperty(value = "客户编码")
private String clientCode;
@ApiModelProperty(value = "品牌名称")
private String brandName;
}

13
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/constant/BasicdataConstants.java

@ -0,0 +1,13 @@
package com.logpm.basicdata.constant;
/**
* @author zhaoqiaobo
* @create 2024-04-24
*/
public abstract class BasicdataConstants {
public interface Price {
String VEHICLE_TYPE = "price_vehicle_type";
}
}

73
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/dto/BasicdataPriceRouteImportDTO.java

@ -0,0 +1,73 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package com.logpm.basicdata.dto;
import lombok.Data;
import java.io.Serializable;
/**
* 基础价格路径 数据传输对象实体类
*
* @author zqb
* @since 2024-04-08
*/
@Data
public class BasicdataPriceRouteImportDTO implements Serializable {
/**
* 客户编码
*/
private String clientCode;
/**
* 品牌
*/
private String brand;
/**
* 发货单位
*/
private String sendOrgCode;
/**
* 发站省
*/
private String startProvince;
/**
* 发站市
*/
private String startCity;
/**
* 发站区
*/
private String startArea;
/**
* 到站省
*/
private String endProvince;
/**
* 到站市
*/
private String endCity;
/**
* 到站区
*/
private String endArea;
/**
* 类型 提货干线
*/
private String type;
}

16
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/DispatchPricingTypeEnums.java

@ -10,14 +10,14 @@ import org.springblade.common.model.IDict;
*/
public enum DispatchPricingTypeEnums implements IDict<Integer> {
PIECE(1, "按件计费"),
WEIGHT(2, "按重量计费"),
CUBE(3, "按方计费"),
COMPLETE_VEHICLE(4, "按整车计费"),
DESTINATIONS_NUMBER(5, "按点位计费"),
TON_PER_KILOMETER(6, "按吨公里计费"),
KILOMETER(7, "按公里计费"),
TON(8, "按吨计费"),
PIECE(1, "按件"),
WEIGHT(2, "按重量"),
CUBE(3, "按方"),
COMPLETE_VEHICLE(4, "按整车"),
DESTINATIONS_NUMBER(5, "按点位"),
TON_PER_KILOMETER(6, "按吨公里"),
KILOMETER(7, "按公里"),
TON(8, "按吨"),
;
DispatchPricingTypeEnums(Integer code, String text) {

6
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/FullVehicleTypeEnums.java

@ -10,9 +10,9 @@ import org.springblade.common.model.IDict;
*/
public enum FullVehicleTypeEnums implements IDict<Integer> {
PICK_UP(1, "提货整车"),
TRUNK_LINE(2, "干线整车"),
DISPATCH(4, "配送整车"),
PICK_UP(1, "提货"),
TRUNK_LINE(2, "干线"),
DISPATCH(4, "配送"),
;
FullVehicleTypeEnums(Integer code, String text) {

4
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/enums/WarehousePricingTypeEnums.java

@ -12,8 +12,8 @@ public enum WarehousePricingTypeEnums implements IDict<Integer> {
PIECE(1, "按件"),
CUBE(2, "按方"),
WEIGHT(3, "按重量(Kg)"),
TONNE(4, "按吨(t)"),
WEIGHT(3, "按重量"),
TONNE(4, "按吨"),
;
WarehousePricingTypeEnums(Integer code, String text) {

34
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryBasicExcel.java

@ -40,23 +40,35 @@ public class BasicdataPriceCategoryBasicExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty(value = "客户名称", index = 0)
@ExcelProperty(value = {"客户名称", "客户名称"}, index = 0)
private String client;
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = {"客户编码", "客户编码"}, index = 1)
private String clientCode;
@ExcelProperty(value = {"品牌", "品牌"}, index = 2)
private String brand;
@ExcelProperty(value = "发站", index = 2)
private String startName;
@ExcelProperty(value = "到站", index = 3)
private String endName;
@ExcelProperty(value = "发货单位", index = 4)
@ExcelProperty(value = {"发站", "省"}, index = 3)
private String startProvince;
@ExcelProperty(value = {"发站", "市"}, index = 4)
private String startCity;
@ExcelProperty(value = {"发站", "区"}, index = 5)
private String startArea;
@ExcelProperty(value = {"到站", "省"}, index = 6)
private String endProvince;
@ExcelProperty(value = {"到站", "市"}, index = 7)
private String endCity;
@ExcelProperty(value = {"到站", "区"}, index = 8)
private String endArea;
@ExcelProperty(value = {"发货单位", "发货单位"}, index = 9)
private String sendOrg;
@ExcelProperty(value = "服务类型", index = 5)
@ExcelProperty(value = {"发货单位", "发货单位编码"}, index = 10)
private String sendOrgCode;
@ExcelProperty(value = {"类型", "类型"}, index = 11)
private String type;
@ExcelProperty(value = "计费类型", index = 6)
@ExcelProperty(value = {"计价方式", "计价方式"}, index = 12)
private String costType;
@ExcelProperty(value = "品类", index = 7)
@ExcelProperty(value = {"品类", "品类"}, index = 13)
private String category;
@ExcelProperty(value = "单价", index = 8)
@ExcelProperty(value = {"单价", "单价"}, index = 14)
private String price;
}

38
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryDispatchExcel.java

@ -40,27 +40,29 @@ public class BasicdataPriceCategoryDispatchExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty(value = "客户名称", index = 0)
@ExcelProperty(value = {"客户名称", "客户名称"}, index = 0)
private String client;
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = {"客户编码", "客户编码"}, index = 1)
private String clientCode;
@ExcelProperty(value = {"品牌", "品牌"}, index = 2)
private String brand;
@ExcelProperty(value = "费用类型", index = 2)
@ExcelProperty(value = {"费用类型", "费用类型"}, index = 3)
private String type;
@ExcelProperty(value = "计价方式", index = 3)
private String costType;
@ExcelProperty(value = "品类", index = 4)
@ExcelProperty(value = {"品类", "品类"}, index = 4)
private String category;
@ExcelProperty(value = "单价", index = 5)
private Double price;
@ExcelProperty(value = "遗留单价", index = 6)
private Double leaveBehindPrice;
@ExcelProperty(value = "分货费", index = 7)
private Double sortPrice;
@ExcelProperty(value = "操作/装卸费", index = 8)
private Double handlingPrice;
@ExcelProperty(value = "平移费", index = 9)
private Double relocationPrice;
@ExcelProperty(value = "上楼费", index = 10)
private Double upstairsDeliveryPrice;
@ExcelProperty(value = {"一般计费", "计价方式"}, index = 5)
private String costType;
@ExcelProperty(value = {"一般计费", "单价"}, index = 6)
private String price;
@ExcelProperty(value = {"一般计费", "单价"}, index = 7)
private String leaveBehindPrice;
@ExcelProperty(value = {"附加费", "分货费"}, index = 8)
private String sortPrice;
@ExcelProperty(value = {"附加费", "操作/装卸费"}, index = 9)
private String handlingPrice;
@ExcelProperty(value = {"附加费", "平移费"}, index = 10)
private String relocationPrice;
@ExcelProperty(value = {"附加费", "上楼费"}, index = 11)
private String upstairsDeliveryPrice;
}

27
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceCategoryWarehouseExcel.java

@ -21,7 +21,6 @@ import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@ -41,27 +40,31 @@ public class BasicdataPriceCategoryWarehouseExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty(value = "客户名称", index = 0)
@ExcelProperty(value = {"客户名称", "客户名称"}, index = 0)
private String client;
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = {"客户编码", "客户编码"}, index = 1)
private String clientCode;
@ExcelProperty(value = {"品牌", "品牌"}, index = 2)
private String brand;
@ExcelProperty(value = "计价方式", index = 2)
@ExcelProperty(value = {"费用类型", "费用类型"}, index = 3)
private String type;
@ExcelProperty(value = {"计价方式", "计价方式"}, index = 4)
private String costType;
@ExcelProperty(value = "品类", index = 3)
@ExcelProperty(value = {"品类", "品类"}, index = 5)
private String category;
@ExcelProperty(value = "30天内", index = 4)
@ExcelProperty(value = {"一般计费", "30天内"}, index = 6)
private String withinThirtyPrice;
@ExcelProperty(value = "30-60天", index = 5)
@ExcelProperty(value = {"一般计费", "30-60天"}, index = 7)
private String betweenThirtySixtyPrice;
@ExcelProperty(value = "60天外", index = 6)
@ExcelProperty(value = {"一般计费", "60天外"}, index = 8)
private String beyondSixtyPrice;
@ExcelProperty(value = "上限价格", index = 7)
@ExcelProperty(value = {"一般计费", "上限价格"}, index = 9)
private String maximumPrice;
@ExcelProperty(value = "操作/装卸费", index = 8)
@ExcelProperty(value = {"附加费", "操作/装卸费"}, index = 10)
private String operatePrice;
@ExcelProperty(value = "仓储管理费", index = 9)
@ExcelProperty(value = {"附加费", "仓储管理费"}, index = 11)
private String warehouseManagementPrice;
@ExcelProperty(value = "仓储分货费", index = 10)
@ExcelProperty(value = {"附加费", "仓储分货费"}, index = 12)
private String warehouseSortPrice;
}

19
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceExcel.java

@ -21,6 +21,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.logpm.basicdata.util.TrimConverter;
import lombok.Data;
import java.io.Serializable;
@ -45,42 +46,44 @@ public class BasicdataPriceExcel implements Serializable {
*/
@ExcelProperty(value = "客户名称", index = 0)
private String client;
@ExcelProperty(value = "客户编码", index = 1)
private String clientCode;
/**
* 品牌
*/
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = "品牌", index = 2)
private String brand;
/**
* 生效时间
*/
@ExcelProperty(value = "生效时间", index = 2)
@ExcelProperty(value = "生效时间", index = 3)
private String effectiveTime;
/**
* 到期时间
*/
@ExcelProperty(value = "到期时间", index = 3)
@ExcelProperty(value = "到期时间", index = 4)
private String expiryTime;
/**
* 模版名称
*/
@ExcelProperty(value = "模版名称", index = 4)
@ExcelProperty(value = "模版名称", index = 5)
private String templateName;
/**
* 向上判断件数
*/
@ExcelProperty(value = "向上判断件数", index = 5)
@ExcelProperty(value = "向上判断件数", index = 6)
private String dispatchUpwardJudgment;
/**
* 向上判断件数
* 向上判断加价
*/
@ExcelProperty(value = "向上判断件数", index = 6)
@ExcelProperty(value = "向上判断加价", index = 7)
private String dispatchUpwardJudgmentCost;
/**
* 上楼费免费楼层
*/
@ExcelProperty(value = "上楼费免费楼层", index = 7)
@ExcelProperty(value = "上楼费免费楼层", index = 8)
private String dispatchStairsCarryingCharge;
}

32
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceFullVehicleExcel.java

@ -40,21 +40,33 @@ public class BasicdataPriceFullVehicleExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty(value = "客户名称", index = 0)
@ExcelProperty(value = {"客户名称", "客户名称"}, index = 0)
private String client;
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = "客户编码", index = 1)
private String clientCode;
@ExcelProperty(value = {"品牌", "品牌"}, index = 2)
private String brand;
@ExcelProperty(value = "发站", index = 2)
private String startName;
@ExcelProperty(value = "到站", index = 3)
private String endName;
@ExcelProperty(value = "发货单位", index = 4)
@ExcelProperty(value = {"发站", "省"}, index = 3)
private String startProvince;
@ExcelProperty(value = {"发站", "市"}, index = 4)
private String startCity;
@ExcelProperty(value = {"发站", "区"}, index = 5)
private String startArea;
@ExcelProperty(value = {"到站", "省"}, index = 6)
private String endProvince;
@ExcelProperty(value = {"到站", "市"}, index = 7)
private String endCity;
@ExcelProperty(value = {"到站", "区"}, index = 8)
private String endArea;
@ExcelProperty(value = {"发货单位", "发货单位"}, index = 9)
private String sendOrg;
@ExcelProperty(value = "类型", index = 5)
@ExcelProperty(value = {"发货单位", "发货单位编码"}, index = 10)
private String sendOrgCode;
@ExcelProperty(value = {"类型", "类型"}, index = 11)
private String type;
@ExcelProperty(value = "车型", index = 6)
@ExcelProperty(value = {"车型", "车型"}, index = 12)
private String vehicleType;
@ExcelProperty(value = "整车计费(元/车)", index = 7)
@ExcelProperty(value = {"价格", "价格"}, index = 13)
private String price;
}

56
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/price/BasicdataPriceGeneralExcel.java

@ -40,45 +40,33 @@ public class BasicdataPriceGeneralExcel implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 客户名称
*/
@ExcelProperty(value = "客户名称", index = 0)
@ExcelProperty(value = {"客户名称", "客户名称"}, index = 0)
private String client;
/**
* 品牌
*/
@ExcelProperty(value = "品牌", index = 1)
@ExcelProperty(value = "客户编码", index = 1)
private String clientCode;
@ExcelProperty(value = {"品牌", "品牌"}, index = 2)
private String brand;
/**
* 发站
*/
@ExcelProperty(value = "发站", index = 2)
private String startName;
/**
* 到站
*/
@ExcelProperty(value = "到站", index = 3)
private String endName;
/**
* 发货单位
*/
@ExcelProperty(value = "发货单位", index = 4)
@ExcelProperty(value = {"发站", "省"}, index = 3)
private String startProvince;
@ExcelProperty(value = {"发站", "市"}, index = 4)
private String startCity;
@ExcelProperty(value = {"发站", "区"}, index = 5)
private String startArea;
@ExcelProperty(value = {"到站", "省"}, index = 6)
private String endProvince;
@ExcelProperty(value = {"到站", "市"}, index = 7)
private String endCity;
@ExcelProperty(value = {"到站", "区"}, index = 8)
private String endArea;
@ExcelProperty(value = {"发货单位", "发货单位"}, index = 9)
private String sendOrg;
/**
* 类型
*/
@ExcelProperty(value = "类型", index = 5)
@ExcelProperty(value = {"发货单位", "发货单位编码"}, index = 10)
private String sendOrgCode;
@ExcelProperty(value = {"类型", "类型"}, index = 11)
private String type;
/**
* 最低计费值
*/
@ExcelProperty(value = "最低计费值", index = 6)
@ExcelProperty(value = {"最低计费值", "最低计费值"}, index = 12)
private String minCost;
/**
* 加算价格
*/
@ExcelProperty(value = "加算价格", index = 7)
@ExcelProperty(value = {"加算价格", "加算价格"}, index = 13)
private String addCost;
}

14
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataPriceMapper.java

@ -20,12 +20,14 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.logpm.basicdata.entity.BasicdataPriceEntity;
import com.logpm.basicdata.excel.BasicdataPriceExcel;
import com.logpm.basicdata.excel.price.BasicdataPriceExcel;
import com.logpm.basicdata.vo.BasicdataPriceImportVO;
import com.logpm.basicdata.vo.BasicdataPricePageVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* 基础价格表 Mapper 接口
@ -45,14 +47,8 @@ public interface BasicdataPriceMapper extends BaseMapper<BasicdataPriceEntity> {
List<BasicdataPricePageVO> selectBasicdataPricePage(IPage page, BasicdataPricePageVO basicdataPrice);
/**
* 获取导出数据
*
* @param queryWrapper
* @return
*/
List<BasicdataPriceExcel> exportBasicdataPrice(@Param("ew") Wrapper<BasicdataPriceEntity> queryWrapper);
@Delete("delete from logpm_basicdata_price_route where price_id = #{id}")
void removeRouteByPriceId(Long id);
List<BasicdataPriceImportVO> findEntityByClientAndBrand(@Param("prices") List<BasicdataPriceExcel> prices);
}

18
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataPriceMapper.xml

@ -43,10 +43,20 @@
</if>
</select>
<select id="exportBasicdataPrice" resultType="com.logpm.basicdata.excel.BasicdataPriceExcel">
SELECT *
FROM logpm_basicdata_price ${ew.customSqlSegment}
<select id="findEntityByClientAndBrand" resultType="com.logpm.basicdata.vo.BasicdataPriceImportVO">
select t.*,lbc.client_name,lbb.brand_name,lbc.client_code
from logpm_basicdata_price t
left join logpm_basicdata_client lbc on t.client_id = lbc.id
left join logpm_basicdata_brand lbb on t.brand_id = lbb.id
where t.is_deleted = 0
<if test="prices != null and prices.size() > 0">
and
<foreach collection="prices" item="item" separator=" or " open="(" close=")">
<if test="item.clientCode != null and item.clientCode != '' and item.brand != null and item.brand != '' ">
(lbc.client_code = #{item.clientCode} and lbb.brand_name = #{item.brand})
</if>
</foreach>
</if>
</select>
</mapper>

1175
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataPriceServiceImpl.java

File diff suppressed because it is too large Load Diff

81
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/util/EasyExcelUtil.java

@ -0,0 +1,81 @@
package com.logpm.basicdata.util;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.alibaba.excel.read.listener.ReadListener;
import org.springblade.core.excel.listener.DataListener;
import org.springblade.core.excel.support.ExcelException;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* easyexcel 读数据工具类
*
* @author zhaoqiaobo
* @create 2024-04-24
*/
public class EasyExcelUtil {
public static <T> List<T> read(MultipartFile excel, Class<T> clazz) {
DataListener<T> dataListener = new DataListener();
ExcelReaderBuilder builder = getReaderBuilder(excel, dataListener, clazz);
if (builder == null) {
return null;
} else {
builder.doReadAll();
return dataListener.getDataList();
}
}
public static <T> List<T> read(MultipartFile excel, int sheetNo, Class<T> clazz) {
return read(excel, sheetNo, 1, clazz);
}
public static <T> List<T> readTrim(MultipartFile excel, int sheetNo, Class<T> clazz) {
return readTrim(excel, sheetNo, 1, clazz);
}
public static <T> List<T> read(MultipartFile excel, int sheetNo, int headRowNumber, Class<T> clazz) {
DataListener<T> dataListener = new DataListener();
ExcelReaderBuilder builder = getReaderBuilder(excel, dataListener, clazz);
if (builder == null) {
return null;
} else {
((ExcelReaderSheetBuilder) builder.sheet(sheetNo).headRowNumber(headRowNumber)).doRead();
return dataListener.getDataList();
}
}
public static <T> List<T> readTrim(MultipartFile excel, int sheetNo, int headRowNumber, Class<T> clazz) {
DataListener<T> dataListener = new DataListener();
ExcelReaderBuilder builder = getReaderBuilder(excel, dataListener, clazz);
if (builder == null) {
return null;
} else {
((ExcelReaderSheetBuilder) builder.sheet(sheetNo).headRowNumber(headRowNumber)).registerConverter(new TrimConverter()).doRead();
return dataListener.getDataList();
}
}
public static <T> ExcelReaderBuilder getReaderBuilder(MultipartFile excel, ReadListener<T> readListener, Class<T> clazz) {
String filename = excel.getOriginalFilename();
if (StrUtil.isEmpty(filename)) {
throw new ExcelException("请上传文件!");
} else if (!StringUtils.endsWithIgnoreCase(filename, ".xls") && !StringUtils.endsWithIgnoreCase(filename, ".xlsx")) {
throw new ExcelException("请上传正确的excel文件!");
} else {
try {
InputStream inputStream = new BufferedInputStream(excel.getInputStream());
return EasyExcel.read(inputStream, clazz, readListener);
} catch (IOException var6) {
var6.printStackTrace();
return null;
}
}
}
}

43
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/util/TrimConverter.java

@ -0,0 +1,43 @@
package com.logpm.basicdata.util;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
* 自定义去除cell前后空格转换器
*
* @author zhaoqiaobo
* @create 2024-04-24
*/
public class TrimConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
String value = cellData.getStringValue();
if (StrUtil.isNotEmpty(value)) {
return value.trim();
}
return value;
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (StrUtil.isEmpty(value)) {
return new CellData(value);
}
return new CellData(value.trim());
}
}
Loading…
Cancel
Save