From dd608fe24d4fb9fdec5287f398f2175a67b2c46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=B8=85?= <3115919733@qq.com> Date: Wed, 11 Jun 2025 10:56:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=9C=80=E6=B1=82=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E6=9D=BF=EF=BC=8C=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/controller/JeecgController.java | 14 ++ .../controller/DeliveryDemandController.java | 56 +++++++- .../deliverydemand/entity/DeliveryDemand.java | 12 +- .../entity/DeliveryDemandDetail.java | 119 ----------------- .../entity/DeliveryDemandExcel.java | 122 ++++++++++++++++++ .../entity/DeliveryDemandDetail.java | 13 +- 6 files changed, 203 insertions(+), 133 deletions(-) delete mode 100644 jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandDetail.java create mode 100644 jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandExcel.java diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java index 512f6ea..d890537 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java @@ -100,6 +100,20 @@ public class JeecgController> { mv.addObject(NormalExcelConstants.DATA_LIST, pageList); return mv; } + + protected ModelAndView exportTemplate(List pageList, Class clazz, String title) { + // AutoPoi 导出Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + mv.addObject(NormalExcelConstants.FILE_NAME, title); + mv.addObject(NormalExcelConstants.CLASS, clazz); + ExportParams exportParams = new ExportParams(null, null, title); + exportParams.setImageBasePath(upLoadPath); + exportParams.setType(ExcelType.XSSF); + exportParams.setFixedTitle(false); + mv.addObject(NormalExcelConstants.PARAMS, exportParams); + mv.addObject(NormalExcelConstants.DATA_LIST, pageList); + return mv; + } /** * 根据每页sheet数量导出多sheet * diff --git a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/controller/DeliveryDemandController.java b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/controller/DeliveryDemandController.java index baa2f17..3cd5ac8 100644 --- a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/controller/DeliveryDemandController.java +++ b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/controller/DeliveryDemandController.java @@ -18,6 +18,7 @@ import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.tms.carinout.vehicleinout.entity.VehicleParam; import org.jeecg.modules.tms.outbound.deliverydemand.entity.DeliveryDemand; +import org.jeecg.modules.tms.outbound.deliverydemand.entity.DeliveryDemandExcel; import org.jeecg.modules.tms.outbound.deliverydemand.service.IDeliveryDemandService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -199,6 +200,16 @@ public class DeliveryDemandController extends JeecgController deliveryDemandExcelList = new ArrayList<>(); + return super.exportTemplate(deliveryDemandExcelList, DeliveryDemandExcel.class, "发货需求模板"); + } + /** * 通过excel导入数据 * @@ -209,7 +220,50 @@ public class DeliveryDemandController extends JeecgController importExcel(HttpServletRequest request, HttpServletResponse response) { - return super.importExcel(request, response, DeliveryDemand.class); + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + for (Map.Entry entity : fileMap.entrySet()) { + // 获取上传文件对象 + MultipartFile file = entity.getValue(); + ImportParams params = new ImportParams(); + params.setHeadRows(1); + params.setNeedSave(true); + try { + List deliveryDemandExcelList = ExcelImportUtil.importExcel(file.getInputStream(), DeliveryDemandExcel.class, params); + long start = System.currentTimeMillis(); + List demandDetails = new ArrayList<>(); + for (DeliveryDemandExcel excel: deliveryDemandExcelList) { + List deliveryDemandDetailList = excel.getDeliveryDemandDetailList(); + DeliveryDemand deliveryDemand = BeanUtil.toBean(excel, DeliveryDemand.class); + deliveryDemandService.save(deliveryDemand); + deliveryDemandDetailList.forEach(item -> { + item.setDeliveryDemandId(deliveryDemand.getId()); + }); + demandDetails.addAll(deliveryDemandDetailList); + } + // 新增到明细表 + deliveryDemandDetailService.saveBatch(demandDetails); + log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); + return Result.ok("文件导入成功!数据行数:"); + } catch (Exception e) { + //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 + String msg = e.getMessage(); + log.error(msg, e); + if(msg!=null && msg.indexOf("Duplicate entry")>=0){ + return Result.error("文件导入失败:有重复数据!"); + }else{ + return Result.error("文件导入失败:" + e.getMessage()); + } + //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return Result.error("文件导入失败!"); } /** diff --git a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemand.java b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemand.java index 6b3ddc1..e98c373 100644 --- a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemand.java +++ b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemand.java @@ -93,16 +93,16 @@ public class DeliveryDemand implements Serializable { @DateTimeFormat(pattern="yyyy-MM-dd") @ApiModelProperty(value = "到货时间") private java.util.Date deliveryDate; + /**取货地点*/ + @Excel(name = "取货地点", width = 15) + @Dict(dicCode = "pick_up_hub") + @ApiModelProperty(value = "取货地点") + private java.lang.String pickUpHub; /**送货地点*/ - @Excel(name = "送货地点", width = 15, dicCode = "delivery_address") + @Excel(name = "送货地点", width = 15) @Dict(dicCode = "delivery_address") @ApiModelProperty(value = "送货地点") private java.lang.String deliveryAddress; - /**取货仓库*/ - @Excel(name = "取货仓库", width = 15, dicCode = "pick_up_hub") - @Dict(dicCode = "pick_up_hub") - @ApiModelProperty(value = "取货仓库") - private java.lang.String pickUpHub; /**发货单*/ // @Excel(name = "发货单", width = 15) @ApiModelProperty(value = "发货单") diff --git a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandDetail.java b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandDetail.java deleted file mode 100644 index d2890fc..0000000 --- a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandDetail.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.jeecg.modules.tms.outbound.deliverydemand.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -import org.jeecg.common.aspect.annotation.Dict; -import org.jeecgframework.poi.excel.annotation.Excel; -import org.springframework.format.annotation.DateTimeFormat; - -import java.io.Serializable; -import java.util.Date; - -/** - * @Description: 发货需求 - * @Author: jeecg-boot - * @Date: 2025-04-11 - * @Version: V1.0 - */ -@Data -@TableName("tms_delivery_demand") -@Accessors(chain = true) -@EqualsAndHashCode(callSuper = false) -@ApiModel(value="tms_delivery_demand对象", description="发货需求") -public class DeliveryDemandDetail implements Serializable { - private static final long serialVersionUID = 1L; - - /**主键*/ - @TableId(type = IdType.ASSIGN_ID) - @ApiModelProperty(value = "主键") - private String id; - /**创建人*/ - @ApiModelProperty(value = "创建人") - private String createBy; - /**创建日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") - @ApiModelProperty(value = "创建日期") - private Date createTime; - /**更新人*/ - @ApiModelProperty(value = "更新人") - private String updateBy; - /**更新日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") - @ApiModelProperty(value = "更新日期") - private Date updateTime; - /**所属部门*/ - @ApiModelProperty(value = "所属部门") - private String sysOrgCode; - /**发货类型*/ - @Excel(name = "发货类型", width = 15, dicCode = "ship_type") - @Dict(dicCode = "ship_type") - @ApiModelProperty(value = "发货类型") - private String shipType; - /**料号*/ - @Excel(name = "料号", width = 15) - @ApiModelProperty(value = "料号") - private String pn; - /**规格*/ - @Excel(name = "规格", width = 15) - @ApiModelProperty(value = "规格") - private String spec; - /**发货数量*/ - @Excel(name = "发货数量", width = 15) - @ApiModelProperty(value = "发货数量") - private Integer shipNumber; - /**单位*/ - @Excel(name = "单位", width = 15, dicCode = "unit") - @Dict(dicCode = "unit") - @ApiModelProperty(value = "单位") - private String unit; - /**预估托盘数*/ - @Excel(name = "预估托盘数", width = 15) - @ApiModelProperty(value = "预估托盘数") - private Integer palletsNum; - /**发货时间*/ - @Excel(name = "发货时间", width = 20, format = "yyyy-MM-dd") - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") - @DateTimeFormat(pattern="yyyy-MM-dd") - @ApiModelProperty(value = "发货时间") - private Date shipDate; - /**送货地点*/ - @Excel(name = "送货地点", width = 15, dicCode = "delivery_address") - @Dict(dicCode = "delivery_address") - @ApiModelProperty(value = "送货地点") - private String deliveryAddress; - /**取货仓库*/ - @Excel(name = "取货仓库", width = 15, dicCode = "pick_up_hub") - @Dict(dicCode = "pick_up_hub") - @ApiModelProperty(value = "取货仓库") - private String pickUpHub; - /**发货单*/ - @Excel(name = "发货单", width = 15) - @ApiModelProperty(value = "发货单") - private String invoice; - /**销售人员*/ - @Excel(name = "销售人员", width = 15) - @ApiModelProperty(value = "销售人员") - private String salesperson; - /**作业备注*/ - @Excel(name = "作业备注", width = 15) - @ApiModelProperty(value = "作业备注") - private String workNotes; - /**当前状态*/ - @Excel(name = "当前状态", width = 15, dicCode = "current_status") - @Dict(dicCode = "current_status") - @ApiModelProperty(value = "当前状态") - private String currentStatus; - /**用车需求编号*/ - @Excel(name = "用车需求编号", width = 15) - @ApiModelProperty(value = "用车需求编号") - private String vdNo; -} diff --git a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandExcel.java b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandExcel.java new file mode 100644 index 0000000..772c4de --- /dev/null +++ b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemand/entity/DeliveryDemandExcel.java @@ -0,0 +1,122 @@ +package org.jeecg.modules.tms.outbound.deliverydemand.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.aspect.annotation.Dict; +import org.jeecg.modules.tms.outbound.deliverydemanddetail.entity.DeliveryDemandDetail; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.jeecgframework.poi.excel.annotation.ExcelCollection; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.List; + +/** + * @Description: 发货需求 + * @Author: jeecg-boot + * @Date: 2025-04-11 + * @Version: V1.0 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +public class DeliveryDemandExcel implements Serializable { + private static final long serialVersionUID = 1L; + + /**主键*/ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "主键") + private java.lang.String id; + /**创建人*/ + @ApiModelProperty(value = "创建人") + private java.lang.String createBy; + /**创建日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建日期") + private java.util.Date createTime; + /**更新人*/ + @ApiModelProperty(value = "更新人") + private java.lang.String updateBy; + /**更新日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "更新日期") + private java.util.Date updateTime; + /**所属部门*/ + @ApiModelProperty(value = "所属部门") + private java.lang.String sysOrgCode; + /**发货类型*/ + @Excel(name = "发货类型", width = 15, dicCode = "ship_type", needMerge = true) + @Dict(dicCode = "ship_type") + @ApiModelProperty(value = "发货类型") + private java.lang.String shipType; + /**料号*/ + @ApiModelProperty(value = "料号") + private java.lang.String pn; + /**规格*/ + @ApiModelProperty(value = "规格") + private java.lang.String spec; + /**发货数量*/ + @Excel(name = "发货数量", width = 15, needMerge = true) + @ApiModelProperty(value = "发货数量") + private java.lang.Integer shipNumber; + /**单位*/ + @Dict(dicCode = "unit") + @ApiModelProperty(value = "单位") + private java.lang.String unit; + /**预估托盘数*/ + @Excel(name = "预估托盘数", width = 15, needMerge = true) + @ApiModelProperty(value = "预估托盘数") + private java.lang.Integer palletsNum; + /**发货时间*/ + @Excel(name = "发货时间", width = 20, format = "yyyy-MM-dd", needMerge = true) + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") + @DateTimeFormat(pattern="yyyy-MM-dd") + @ApiModelProperty(value = "发货时间") + private java.util.Date shipDate; + /**到货时间*/ + @Excel(name = "到货时间", width = 20, format = "yyyy-MM-dd", needMerge = true) + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") + @DateTimeFormat(pattern="yyyy-MM-dd") + @ApiModelProperty(value = "到货时间") + private java.util.Date deliveryDate; + /**送货地点*/ + @Excel(name = "送货地点", width = 15, needMerge = true) + @Dict(dicCode = "delivery_address") + @ApiModelProperty(value = "送货地点") + private java.lang.String deliveryAddress; + /**取货仓库*/ + @Excel(name = "取货仓库", width = 15, needMerge = true) + @Dict(dicCode = "pick_up_hub") + @ApiModelProperty(value = "取货仓库") + private java.lang.String pickUpHub; + /**发货单*/ + @ApiModelProperty(value = "发货单") + private java.lang.String invoice; + /**销售人员*/ + @ApiModelProperty(value = "销售人员") + private java.lang.String salesperson; + /**作业备注*/ + @Excel(name = "作业备注", width = 15, needMerge = true) + @ApiModelProperty(value = "作业备注") + private java.lang.String workNotes; + /**当前状态 0-创建, 1-已合并需求, 2-计算车辆需求中, 3-发送车辆需求, 4-等待装车, + * 5-车辆离厂(完成), 6-取消, 7-超期无效*/ + @Excel(name = "当前状态", width = 15, dicCode = "current_status") + @Dict(dicCode = "current_status") + @ApiModelProperty(value = "当前状态") + private java.lang.String currentStatus; + /**用车需求编号*/ + @ApiModelProperty(value = "用车需求编号") + private String vdNo; + @TableField(exist = false) + @ExcelCollection(name = "发货明细") + private List deliveryDemandDetailList; +} diff --git a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemanddetail/entity/DeliveryDemandDetail.java b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemanddetail/entity/DeliveryDemandDetail.java index bafb378..cd86aa7 100644 --- a/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemanddetail/entity/DeliveryDemandDetail.java +++ b/jeecg-boot/jeecg-module-tms/src/main/java/org/jeecg/modules/tms/outbound/deliverydemanddetail/entity/DeliveryDemandDetail.java @@ -57,13 +57,13 @@ public class DeliveryDemandDetail implements Serializable { @Excel(name = "发货单", width = 15) @ApiModelProperty(value = "发货单") private String invoice; - /**取货仓库*/ - @Excel(name = "取货仓库", width = 15) - @ApiModelProperty(value = "取货仓库") + /**发货仓库*/ + @Excel(name = "发货仓库", width = 15) + @ApiModelProperty(value = "发货仓库") private String pickUpHub; - /**取货仓库编码*/ - @Excel(name = "取货仓库编码", width = 15) - @ApiModelProperty(value = "取货仓库编码") + /**发货仓库编码*/ + @Excel(name = "发货仓库编码", width = 15) + @ApiModelProperty(value = "发货仓库编码") private String pickUpHubCode; /**料号*/ @Excel(name = "料号", width = 15) @@ -86,7 +86,6 @@ public class DeliveryDemandDetail implements Serializable { @ApiModelProperty(value = "单位") private String unit; /**发货需求id*/ - @Excel(name = "发货需求id", width = 15) @ApiModelProperty(value = "发货需求id") private String deliveryDemandId; @TableField(exist = false)