Browse Source

fixed 会员excel表格导入功能迭代

fushengqian 1 month ago
parent
commit
5121f15a78

+ 1 - 0
fuint-application/src/main/java/com/fuint/common/config/WebConfig.java

@@ -69,6 +69,7 @@ public class WebConfig extends WebMvcConfigurationSupport {
                 .excludePathPatterns("/backendApi/userCoupon/exportList")
                 .excludePathPatterns("/backendApi/order/export")
                 .excludePathPatterns("/backendApi/goods/goods/downloadTemplate")
+                .excludePathPatterns("/backendApi/member/downloadTemplate")
                 .excludePathPatterns("/backendApi/login/**");
 
         // 客户端拦截

+ 1 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/GoodsServiceImpl.java

@@ -823,6 +823,7 @@ public class GoodsServiceImpl extends ServiceImpl<MtGoodsMapper, MtGoods> implem
      *
      * @param file excel文件
      * @param accountInfo 操作者
+     * @param filePath 文件路径
      * @return
      * */
     @Override

+ 21 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java

@@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
 
@@ -1035,6 +1036,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
      *
      * @param file excel文件
      * @param accountInfo 操作者
+     * @param filePath 文件路径
      * @return
      * */
     @Override
@@ -1054,6 +1056,25 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
             throw new BusinessCheckException("没有操作权限");
         }
 
+        List<List<String>> memberList = new ArrayList<>();
+        try {
+            memberList = XlsUtil.readExcelContent(file.getInputStream(), isExcel2003, 0, 1, null, null, null);
+        } catch (IOException e) {
+            logger.error("MemberServiceImpl->parseExcelContent{}", e);
+            throw new BusinessCheckException("会员导入失败" + e.getMessage());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (memberList != null && memberList.size() > 0) {
+            if (memberList.size() > 5000) {
+                throw new BusinessCheckException("会员导入失败,单次导入会员数量不能大于5000");
+            }
+            for (int i = 0; i < memberList.size(); i++) {
+
+            }
+        }
+
         return true;
     }
 }

+ 32 - 2
fuint-application/src/main/java/com/fuint/common/util/ExcelUtil.java

@@ -5,7 +5,11 @@ import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.core.io.ClassPathResource;
+
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 
@@ -25,7 +29,7 @@ public class ExcelUtil {
      * @param wb HSSFWorkbook对象
      * @return
      */
-    public static HSSFWorkbook getHSSFWorkbook(String sheetName,String []title,String [][]values, HSSFWorkbook wb){
+    public static HSSFWorkbook getHSSFWorkbook(String sheetName,String []title,String [][]values, HSSFWorkbook wb) {
 
         // 第一步,创建一个HSSFWorkbook,对应一个Excel文件
         if(wb == null){
@@ -97,4 +101,30 @@ public class ExcelUtil {
 
         return;
     }
-}
+
+    /**
+     * 下载Excel模板文件
+     *
+     * @param response
+     * @param templateName
+     * @return
+     * */
+    public static void downLoadTemplate(HttpServletResponse response, String templateName) throws IOException {
+        ClassPathResource classPathResource = new ClassPathResource("template/" + templateName);
+        InputStream inputStream = classPathResource.getInputStream();
+        response.setContentType("application/vnd.ms-excel;charset=utf-8");
+        response.addHeader("Pargam", "no-cache");
+        response.addHeader("Cache-Control", "no-cache");
+        OutputStream out = response.getOutputStream();
+        response.setHeader("Content-Disposition", "attachment; filename=" + templateName);
+        int b = 0;
+        byte[] buffer = new byte[1024*1024];
+        while (b != -1) {
+            b = inputStream.read(buffer);
+            if(b!=-1) out.write(buffer, 0, b);
+        }
+        inputStream.close();
+        out.close();
+        out.flush();
+    }
+}

+ 6 - 25
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGoodsController.java

@@ -9,6 +9,7 @@ import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.param.GoodsListParam;
 import com.fuint.common.service.*;
 import com.fuint.common.util.CommonUtil;
+import com.fuint.common.util.ExcelUtil;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
@@ -25,7 +26,6 @@ import lombok.AllArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
-import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -170,6 +170,7 @@ public class BackendGoodsController extends BaseController {
 
         String operator = accountInfo.getAccountName();
         goodsService.updateStatus(goodsId, status, operator);
+        logger.info("更新商品状态, goodsId = {},account = {}", goodsId, accountInfo.getAccountName());
 
         return getSuccessResult(true);
     }
@@ -513,6 +514,8 @@ public class BackendGoodsController extends BaseController {
         Map<String, Object> result = new HashMap();
         result.put("goodsInfo", goodsInfo);
 
+        logger.info("保存商品信息, goodsId = {},account = {}", goodsInfo.getId(), accountInfo.getAccountName());
+
         return getSuccessResult(result);
     }
 
@@ -755,30 +758,8 @@ public class BackendGoodsController extends BaseController {
     @ApiOperation(value = "下载商品导入模板")
     @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
     @CrossOrigin
-    public void downloadTemplate(HttpServletRequest request, HttpServletResponse response) {
-        String token = request.getParameter("token");
-        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
-        try {
-            String filename = "GoodsTemplate.xlsx";
-            ClassPathResource classPathResource = new ClassPathResource("template/" + filename);
-            InputStream inputStream = classPathResource.getInputStream();
-            response.setContentType("application/vnd.ms-excel;charset=utf-8");
-            response.addHeader("Pargam", "no-cache");
-            response.addHeader("Cache-Control", "no-cache");
-            OutputStream out = response.getOutputStream();
-            response.setHeader("Content-Disposition", "attachment; filename=" + filename);
-            int b = 0;
-            byte[] buffer = new byte[1024*1024];
-            while (b != -1) {
-                b = inputStream.read(buffer);
-                if(b!=-1) out.write(buffer, 0, b);
-            }
-            inputStream.close();
-            out.close();
-            out.flush();
-        } catch (IOException e) {
-            logger.error("下载文件出错:account = {},message = {}", accountInfo.getAccountName(), e.getMessage());
-        }
+    public void downloadTemplate(HttpServletResponse response) throws IOException {
+        ExcelUtil.downLoadTemplate(response, "GoodsTemplate.xlsx");
     }
 
     /**

+ 15 - 4
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -7,10 +7,7 @@ import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.enums.UserSettingEnum;
 import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.service.*;
-import com.fuint.common.util.CommonUtil;
-import com.fuint.common.util.DateUtil;
-import com.fuint.common.util.PhoneFormatCheckUtils;
-import com.fuint.common.util.TokenUtil;
+import com.fuint.common.util.*;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
@@ -29,6 +26,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
 import weixin.popular.util.JsonUtil;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.text.ParseException;
 import java.util.*;
 
@@ -563,6 +562,18 @@ public class BackendMemberController extends BaseController {
         return getSuccessResult(memberList);
     }
 
+    /**
+     * 下载会员导入模板
+     *
+     * @return
+     */
+    @ApiOperation(value = "下载会员导入模板")
+    @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
+    @CrossOrigin
+    public void downloadTemplate(HttpServletResponse response) throws IOException {
+        ExcelUtil.downLoadTemplate(response, "MemberTemplate.xlsx");
+    }
+
     /**
      * 上传会员导入文件
      *

+ 2 - 2
fuint-application/src/main/resources/application.properties

@@ -1,7 +1,7 @@
 # \u57FA\u672C\u914D\u7F6E
 server.port=8080
-env.profile=prod
-env.properties.path=/usr/local/fuint/configure/
+env.profile=dev
+env.properties.path=C:/Code/fuint/fuint-backend/configure/
 
 # \u6570\u636E\u5E93\u914D\u7F6E
 spring.datasource.type=com.zaxxer.hikari.HikariDataSource

BIN
fuint-application/src/main/resources/template/MemberTemplate.xlsx