| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.utils.MatExcelListener; |
| | | import com.zy.asrs.utils.MatV2ExcelListener; |
| | | import com.zy.common.entity.MatExcel; |
| | | import com.zy.common.entity.MatV2Excel; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | } |
| | | return R.ok().add(matV2s); |
| | | } |
| | | |
| | | /** |
| | | * excel导入模板下载 |
| | | */ |
| | | @RequestMapping(value = "/matV2/excel/import/mould") |
| | | public void matV2ExcelImportMould(HttpServletResponse response) throws IOException { |
| | | List<MatV2Excel> excels = new ArrayList<>(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("组件档案Excel导入模板", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), MatV2Excel.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .sheet("sheet1") |
| | | .doWrite(excels); |
| | | } |
| | | |
| | | // excel导入 |
| | | @PostMapping(value = "/matV2/excel/import/auth") |
| | | @ManagerAuth(memo = "组件档案数据导入") |
| | | @Transactional |
| | | public R matV2ExcelImport(MultipartFile file) throws IOException { |
| | | MatV2ExcelListener listener = new MatV2ExcelListener(getUserId()); |
| | | EasyExcel.read(file.getInputStream(), MatV2Excel.class, listener).sheet().doRead(); |
| | | return R.ok("成功同步"+listener.getTotal()+"条商品数据"); |
| | | } |
| | | } |