Prechádzať zdrojové kódy

提示错误时。去掉异常信息

buzhanyi 1 rok pred
rodič
commit
3181067bd0

+ 46 - 0
purchase-admin/src/main/java/com/ozs/web/controller/base/BaseSupplierController.java

@@ -1,5 +1,8 @@
 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.metadata.IPage;
 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.page.TableDataInfo;
 import com.ozs.common.enums.BusinessType;
+import com.ozs.common.exception.base.BaseException;
 import com.ozs.common.utils.StringUtils;
 import com.ozs.base.domain.BaseSupplier;
 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 io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 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.RequestBody;
 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 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.List;
 
@@ -36,6 +47,7 @@ import java.util.List;
  * @author sunhh
  */
 @Api(tags = "供应商管理")
+@Slf4j
 @RestController
 @RequestMapping("/base/supplier")
 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);
         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("下载异常");
+        }
+    }
 }

BIN
purchase-admin/src/main/resources/template/base_supplier.xlsx


+ 10 - 10
purchase-system/src/main/java/com/ozs/base/service/impl/BaseExpertServiceImpl.java

@@ -214,7 +214,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                     expert.setStatus("0");
                 } else {
                     ++failureNum;
-                    failureMsg.append(failureNum + "、专家类型“" + expert.getExpertType() + "”不存在");
+                    failureMsg.append(failureNum + "、专家类型“" + expert.getExpertType() + "”不存在     <br/>");
                 }
                 if (expert.getIdNumber().length() > 18) {
                     throw new ServiceException("身份证号长度过长");
@@ -226,7 +226,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                 //身份证号已存在的不可添加
                 if (!ObjectUtils.isEmpty(idNumberList)) {
                     ++failureNum;
-                    failureMsg.append(failureNum + "、身份证号“" + expert.getIdNumber() + "”已被使用");
+                    failureMsg.append(failureNum + "、身份证号“" + expert.getIdNumber() + "”已被使用 <br/>");
                 }
                 //专业类型
                 LambdaQueryWrapper<BaseProfessional> wrapper = new LambdaQueryWrapper<>();
@@ -237,14 +237,14 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                     expert.setMajorType(list.get(0).getProfessionalCode());
                 } else {
                     ++failureNum;
-                    failureMsg.append(failureNum + "、专业类型“" + expert.getExpertType() + "”不存在");
+                    failureMsg.append(failureNum + "、专业类型“" + expert.getExpertType() + "”不存在     <br/>");
                 }
                 //职称
                 if (!StringUtils.isEmpty(professionalTitleMap.get(expert.getProfessionalTitle()))) {
                     expert.setProfessionalTitle(professionalTitleMap.get(expert.getProfessionalTitle()));
                 } else {
                     ++failureNum;
-                    failureMsg.append(failureNum + "、职称“" + expert.getProfessionalTitle() + "”不存在");
+                    failureMsg.append(failureNum + "、职称“" + expert.getProfessionalTitle() + "”不存在    <br/>");
                 }
                 if (StringUtils.isNotNull(expert.getUnitInformation())) {
                     List<BaseUnitInformation> baseUnitInformationList = baseExpertMapper.selectByUnitInformation(expert.getUnitInformation());
@@ -260,7 +260,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                 //地区
                 if (StringUtils.isEmpty(expert.getLocalArea()) || expert.getLocalArea().split("/").length < 2) {
                     ++failureNum;
-                    failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”不存在");
+                    failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”不存在    <br/>");
                 } else {
                     //大部分地区是三级
                     String[] localAreas = expert.getLocalArea().split("/");
@@ -270,7 +270,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                         List<SysRegionVO> sysRegionVO2 = sysRegionService.selectInfoByName(localAreas[2]);
                         if (ObjectUtils.isEmpty(sysRegionVO2) || ObjectUtils.isEmpty(sysRegionVO1) || ObjectUtils.isEmpty(sysRegionVO)) {
                             ++failureNum;
-                            failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”信息有误");
+                            failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”信息有误  <br/>");
                         } else {
                             //是否成立上下级关系
                             boolean isLea = false;
@@ -291,7 +291,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                             }
                             if (isLea == false) {
                                 ++failureNum;
-                                failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”非上下级关系");
+                                failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”非上下级关系    <br/>");
                             }
                         }
 
@@ -301,7 +301,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                         List<SysRegionVO> sysRegionVO1 = sysRegionService.selectInfoByName(localAreas[1]);
                         if (ObjectUtils.isEmpty(sysRegionVO1) || ObjectUtils.isEmpty(sysRegionVO)) {
                             ++failureNum;
-                            failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”信息有误");
+                            failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”信息有误  <br/>");
                         } else {
                             //是否成立上下级关系
                             boolean isLea = false;
@@ -317,7 +317,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                             }
                             if (isLea == false) {
                                 ++failureNum;
-                                failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”非上下级关系");
+                                failureMsg.append(failureNum + "、地区“" + expert.getLocalArea() + "”非上下级关系    <br/>");
                             }
                         }
                     }
@@ -330,7 +330,7 @@ public class BaseExpertServiceImpl extends ServiceImpl<BaseExpertMapper, BaseExp
                 successNum++;
                 successMsg.append(successNum + "、专家【" + expert.getExpertName() + "】导入成功!");
             } catch (Exception exc) {
-                String msg = "  专家【" + expert.getExpertName() + "】导入失败 <br/>";
+                String msg = "**专家【" + expert.getExpertName() + "】导入失败 <br/>";
                 failureMsg.append(msg);
                 log.error(msg, exc);
             }