仓库信息导入导出

master
anthonyywj2 3 years ago
parent 6c03d4af96
commit 0fd79fd599

@ -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<InvWarehouseEntity> 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<MultipartFile> 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<InvWarehouseEntity> invWarehouseEntities = invWarehouseExportResponse.getInvWarehouseEntities();
if (invWarehouseEntities != null) {
for (InvWarehouseEntity invWarehouseEntity : invWarehouseEntities) {
invWarehouseService.insertInvWarehouse(invWarehouseEntity);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return ResultVOUtils.success("后台正在生成导入生成订单,请稍后查看!");
}
}

@ -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<InvWarehouseEntity> invWarehouseEntities;
}

@ -64,17 +64,26 @@
</select>
<select id="getNameByCode" resultType="java.lang.String">
select name from inv_warehouse where code = #{fromCorpId}
select name
from inv_warehouse
where code = #{fromCorpId}
</select>
<insert id="insertInvWarehouse" keyProperty="id"
parameterType="com.glxp.sale.admin.entity.inventory.InvWarehouseEntity">
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}
)
</insert>

Loading…
Cancel
Save