|
@@ -1,5 +1,8 @@
|
|
package com.ozs.web.controller.base;
|
|
package com.ozs.web.controller.base;
|
|
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -11,6 +14,7 @@ import com.ozs.common.core.domain.AjaxResult;
|
|
import com.ozs.common.core.domain.model.LoginUser;
|
|
import com.ozs.common.core.domain.model.LoginUser;
|
|
import com.ozs.common.core.page.TableDataInfo;
|
|
import com.ozs.common.core.page.TableDataInfo;
|
|
import com.ozs.common.enums.BusinessType;
|
|
import com.ozs.common.enums.BusinessType;
|
|
|
|
+import com.ozs.common.exception.base.BaseException;
|
|
import com.ozs.common.utils.StringUtils;
|
|
import com.ozs.common.utils.StringUtils;
|
|
import com.ozs.base.domain.BaseSupplier;
|
|
import com.ozs.base.domain.BaseSupplier;
|
|
import com.ozs.base.service.BaseSupplierService;
|
|
import com.ozs.base.service.BaseSupplierService;
|
|
@@ -18,8 +22,10 @@ import com.ozs.common.utils.poi.ExcelUtil;
|
|
import com.ozs.framework.web.service.TokenService;
|
|
import com.ozs.framework.web.service.TokenService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -27,6 +33,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -36,6 +47,7 @@ import java.util.List;
|
|
* @author sunhh
|
|
* @author sunhh
|
|
*/
|
|
*/
|
|
@Api(tags = "供应商管理")
|
|
@Api(tags = "供应商管理")
|
|
|
|
+@Slf4j
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/base/supplier")
|
|
@RequestMapping("/base/supplier")
|
|
public class BaseSupplierController extends BaseController {
|
|
public class BaseSupplierController extends BaseController {
|
|
@@ -144,4 +156,38 @@ public class BaseSupplierController extends BaseController {
|
|
IPage<BaseSupplier> page = baseSupplierService.page(new Page<BaseSupplier>(baseSupplierVo.getPageNum(), baseSupplierVo.getPageSize()), lw);
|
|
IPage<BaseSupplier> page = baseSupplierService.page(new Page<BaseSupplier>(baseSupplierVo.getPageNum(), baseSupplierVo.getPageSize()), lw);
|
|
return success(page);
|
|
return success(page);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation("模板下载")
|
|
|
|
+ @GetMapping("/downloaExcel")
|
|
|
|
+ public void downloadZip(HttpServletResponse response) {
|
|
|
|
+ List<BaseSupplierVo> list = new ArrayList<BaseSupplierVo>();
|
|
|
|
+ //list.add(new BaseSupplierVo("张先生", "法务专家", "男",
|
|
|
|
+ // "2023-07-06", "15152223667", "安全工程03",
|
|
|
|
+ // "科室一", "高级职称", "天津市/河东区", "050050101"
|
|
|
|
+ //));
|
|
|
|
+ //list.add(new BaseSupplierVo("李先生", "经济专家", "女",
|
|
|
|
+ // "2023-07-06", "14448485656", "测试工程07",
|
|
|
|
+ // "科室二", "中级职称", "山西省/阳泉市/平定县", "41133535035"
|
|
|
|
+ //));
|
|
|
|
+ InputStream resourceAsStream = this.getClass().getResourceAsStream("/template/base_supplier.xlsx");
|
|
|
|
+ OutputStream outputStream = null;
|
|
|
|
+ try {
|
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
|
+ String fileName = URLEncoder.encode("专家信息(模板)", "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(outputStream)
|
|
|
|
+ .withTemplate(resourceAsStream).autoCloseStream(true).build();
|
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
|
+ excelWriter.fill(list, writeSheet);
|
|
|
|
+ excelWriter.finish();
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ throw new BaseException("下载异常");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|