| | |
| | | package org.jeecg.modules.base.controller; |
| | | |
| | | import java.io.File; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import java.net.URLDecoder; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.base.entity.Supplier; |
| | |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:add") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody Supplier supplier) { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_1); |
| | | supplierService.save(supplier); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | |
| | | return super.importExcel(request, response, Supplier.class); |
| | | } |
| | | |
| | | |
| | | @AutoLog(value = "供应商-启用&禁用") |
| | | @ApiOperation(value = "供应商-启用&禁用", notes = "供应商-启用&禁用") |
| | | @PutMapping(value = "/active") |
| | | public Result<?> active(@RequestParam(name = "id", required = true) String id) { |
| | | Supplier supplier = supplierService.getById(id); |
| | | if (CommonConstant.STATUS_1.equals(supplier.getSupplierStatus())) { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_0); |
| | | } else { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_1); |
| | | } |
| | | supplierService.updateById(supplier); |
| | | return Result.ok("操作成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 导入模板下载 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/loadTemplate") |
| | | public void loadTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | |
| | | Map<String,String[]> req = request.getParameterMap(); |
| | | Workbook workbook = WorkbookFactory.create(new File("D:\\opt\\upFiles\\供应商信息导入模板.xlsx")); |
| | | //导出Workbook |
| | | //设置响应头 |
| | | String fileName = "供应商信息导入模板.xlsx"; |
| | | // 对文件名进行URL编码,防止中文乱码 |
| | | String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName); |
| | | // 将Workbook写入响应输出流 |
| | | try { // try-with-resources自动关闭资源 |
| | | workbook.write(response.getOutputStream()); |
| | | response.flushBuffer(); |
| | | } catch (IOException e) { |
| | | // 异常处理(如记录日志) |
| | | throw new IOException("下载模板失败", e); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |