From 0fd79fd5999fd97ba6bd18df0f4ce66610e9fa98 Mon Sep 17 00:00:00 2001 From: anthonyywj2 <353682448@qq.com> Date: Mon, 7 Mar 2022 16:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=BA=93=E4=BF=A1=E6=81=AF=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inventory/InvWarehouseController.java | 67 +++++++++++++++++-- .../inventory/InvWarehouseExportResponse.java | 12 ++++ .../mapper/inventory/InvWarehouseDao.xml | 21 ++++-- 3 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 api-admin/src/main/java/com/glxp/sale/admin/res/inventory/InvWarehouseExportResponse.java diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/inventory/InvWarehouseController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/inventory/InvWarehouseController.java index ae315b8..c607ce8 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/inventory/InvWarehouseController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/inventory/InvWarehouseController.java @@ -1,32 +1,44 @@ package com.glxp.sale.admin.controller.inventory; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.glxp.sale.admin.annotation.AuthRuleAnnotation; +import com.glxp.sale.admin.constant.ConstantStatus; import com.glxp.sale.admin.entity.auth.AuthPermissionRule; +import com.glxp.sale.admin.entity.inout.OrderEntity; +import com.glxp.sale.admin.entity.inout.WarehouseEntity; import com.glxp.sale.admin.entity.inventory.InvWarehouseEntity; import com.glxp.sale.admin.req.auth.AuthPermissionRuleSaveRequest; import com.glxp.sale.admin.req.info.DeleteRequest; +import com.glxp.sale.admin.req.inout.PostOrderRequest; import com.glxp.sale.admin.req.inventory.FilterInvProductRequest; import com.glxp.sale.admin.req.inventory.FilterInvWarehouseRequest; import com.glxp.sale.admin.res.auth.AuthPermissionRuleMergeResponse; import com.glxp.sale.admin.res.inventory.InvProductPageRespnonse; import com.glxp.sale.admin.res.inventory.InvProductResponse; +import com.glxp.sale.admin.res.inventory.InvWarehouseExportResponse; import com.glxp.sale.admin.res.inventory.InvWarehouseResponse; import com.glxp.sale.admin.service.inventory.InvProductService; import com.glxp.sale.admin.service.inventory.InvWarehouseService; +import com.glxp.sale.admin.util.CustomUtil; +import com.glxp.sale.admin.util.DateUtil; +import com.glxp.sale.admin.util.FileUtils; import com.glxp.sale.admin.util.PermissionRuleTreeUtils; import com.glxp.sale.common.enums.ResultEnum; import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.util.ResultVOUtils; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -125,4 +137,51 @@ public class InvWarehouseController { } + //仓库信息文件导出 + @PostMapping("/spms/inv/warehouse/exportJson") + public void exportJson(@RequestBody DeleteRequest deleteRequest, HttpServletResponse res) { + FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest(); + List invWarehouseEntities = invWarehouseService.filterInvWarehouse(filterInvWarehouseRequest); + InvWarehouseExportResponse invWarehouseExportResponse = new InvWarehouseExportResponse(); + invWarehouseExportResponse.setInvWarehouseEntities(invWarehouseEntities); + String json = JSONObject.toJSON(invWarehouseExportResponse).toString(); + String fileName = "仓库信息导出_" + DateUtil.getDate() + ".json"; + res.setHeader("Content-disposition", "attachment;fileName=" + fileName); + res.setContentType("text/plain;charset=UTF-8"); + try { + res.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + //仓库信息文件导入 + @PostMapping("/spms/inv/warehouse/uploadJson") + public BaseResponse uploadOrders(@RequestParam("file") List files) { + for (int i = 0; i < files.size(); i++) { + MultipartFile file = files.get(i); + if (file.isEmpty()) { + return ResultVOUtils.error(500, "上传第" + (i++) + "个文件失败"); + } + try { + InputStream inputStream = file.getInputStream(); + String json = FileUtils.readStream(inputStream); + InvWarehouseExportResponse invWarehouseExportResponse = (InvWarehouseExportResponse) JSON.parseObject(json, InvWarehouseExportResponse.class); + List invWarehouseEntities = invWarehouseExportResponse.getInvWarehouseEntities(); + if (invWarehouseEntities != null) { + for (InvWarehouseEntity invWarehouseEntity : invWarehouseEntities) { + invWarehouseService.insertInvWarehouse(invWarehouseEntity); + } + } + + + } catch (IOException e) { + e.printStackTrace(); + } + } + return ResultVOUtils.success("后台正在生成导入生成订单,请稍后查看!"); + } + + } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/res/inventory/InvWarehouseExportResponse.java b/api-admin/src/main/java/com/glxp/sale/admin/res/inventory/InvWarehouseExportResponse.java new file mode 100644 index 0000000..97d58dd --- /dev/null +++ b/api-admin/src/main/java/com/glxp/sale/admin/res/inventory/InvWarehouseExportResponse.java @@ -0,0 +1,12 @@ +package com.glxp.sale.admin.res.inventory; + +import com.glxp.sale.admin.entity.inventory.InvWarehouseEntity; +import lombok.Data; + +import java.util.List; + +@Data +public class InvWarehouseExportResponse { + + List invWarehouseEntities; +} diff --git a/api-admin/src/main/resources/mybatis/mapper/inventory/InvWarehouseDao.xml b/api-admin/src/main/resources/mybatis/mapper/inventory/InvWarehouseDao.xml index d6823e8..423949a 100644 --- a/api-admin/src/main/resources/mybatis/mapper/inventory/InvWarehouseDao.xml +++ b/api-admin/src/main/resources/mybatis/mapper/inventory/InvWarehouseDao.xml @@ -64,17 +64,26 @@ - insert INTO inv_warehouse + replace + INTO inv_warehouse (pid, code, name, advanceType, isDefault, status, updateTime, remark) - values (#{pid}, #{code}, - #{name}, #{advanceType}, #{isDefault}, - #{status}, #{updateTime}, - #{remark}) + values ( + #{pid}, + #{code}, + #{name}, + #{advanceType}, + #{isDefault}, + #{status}, + #{updateTime}, + #{remark} + )