From 2a3cf951b86a69a05a5668a3aacd09083dd3bf99 Mon Sep 17 00:00:00 2001 From: lym <1994302445@qq.com> Date: Tue, 5 Mar 2024 17:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=8D=95=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/order/OrderController.java | 56 ++++++++++++++++++- .../service/order/OrderServiceImpl.java | 17 ++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java index 879737b83..a00e4a2a2 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/order/OrderController.java @@ -3,6 +3,8 @@ package com.cf.imes.module.executor.controller.admin.order; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderPageReqVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderRespVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderSaveReqVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ResourceUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -13,8 +15,9 @@ import io.swagger.v3.oas.annotations.Operation; import javax.validation.*; import javax.servlet.http.*; +import java.io.*; +import java.net.URLEncoder; import java.util.*; -import java.io.IOException; import com.cf.imes.framework.common.pojo.PageParam; import com.cf.imes.framework.common.pojo.PageResult; @@ -30,6 +33,16 @@ import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*; import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; import com.cf.imes.module.executor.service.order.OrderService; + +import org.springframework.http.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; + + @Tag(name = "管理后台 - 生产单表 order_{N}") @RestController @RequestMapping("/executor/order") @@ -39,6 +52,8 @@ public class OrderController { @Resource private OrderService orderService; + private static final Logger log = LoggerFactory.getLogger(OrderController.class); + @PostMapping("/create") @Operation(summary = "创建生产单表 order_{N}") @PreAuthorize("@ss.hasPermission('executor:order:create')") @@ -93,4 +108,43 @@ public class OrderController { BeanUtils.toBean(list, OrderRespVO.class)); } + @GetMapping("/get-import-template") + @Operation(summary = "获得导入生产单模板") + public void importTemplate(HttpServletResponse response) { + try { + // path是指想要下载的文件的路径 + File file = new File(ResourceUtils.getURL("classpath:").getPath()+ "\\files\\生产单上传样式.xlsx"); + log.info(file.getPath()); + // 获取文件名 + String filename = file.getName(); + // 获取文件后缀名 + String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); + log.info("文件后缀名:" + ext); + + // 将文件写入输入流 + FileInputStream fileInputStream = new FileInputStream(file); + InputStream fis = new BufferedInputStream(fileInputStream); + byte[] buffer = new byte[fis.available()]; + fis.read(buffer); + fis.close(); + + // 清空response + response.reset(); + // 设置response的Header + response.setCharacterEncoding("UTF-8"); + //Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存 + //attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3" + // filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称 + response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); + // 告知浏览器文件的大小 + response.addHeader("Content-Length", "" + file.length()); + OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); + response.setContentType("application/octet-stream"); + outputStream.write(buffer); + outputStream.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java index bb56dc807..8b601a197 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/order/OrderServiceImpl.java @@ -1,9 +1,16 @@ package com.cf.imes.module.executor.service.order; +import com.cf.imes.framework.common.enums.CommonStatusEnum; +import com.cf.imes.framework.excel.core.util.ExcelUtils; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderPageReqVO; import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderSaveReqVO; +import com.cf.imes.module.system.enums.common.SexEnum; +import io.swagger.v3.oas.annotations.Operation; import org.springframework.stereotype.Service; + import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; + import org.springframework.validation.annotation.Validated; import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; @@ -11,6 +18,11 @@ import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.common.util.object.BeanUtils; import com.cf.imes.module.executor.dal.mysql.order.OrderMapper; +import org.springframework.web.bind.annotation.GetMapping; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*; @@ -29,6 +41,11 @@ public class OrderServiceImpl implements OrderService { @Override public Long createOrder(OrderSaveReqVO createReqVO) { + /** + * 1、解析文件 + * + */ + // 插入 OrderDO order = BeanUtils.toBean(createReqVO, OrderDO.class); orderMapper.insert(order);