Browse Source

fixed 商品导入、会员导入功能开发迭代

fushengqian 1 month ago
parent
commit
281363e1e3

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

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

+ 13 - 0
fuint-application/src/main/java/com/fuint/common/service/MemberService.java

@@ -2,6 +2,7 @@ package com.fuint.common.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.alibaba.fastjson.JSONObject;
+import com.fuint.common.dto.AccountInfo;
 import com.fuint.common.dto.GroupMemberDto;
 import com.fuint.common.dto.MemberTopDto;
 import com.fuint.common.dto.UserDto;
@@ -10,6 +11,8 @@ import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.repository.model.MtUser;
 import com.fuint.repository.model.MtUserGrade;
+import org.springframework.web.multipart.MultipartFile;
+
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.List;
@@ -259,4 +262,14 @@ public interface MemberService extends IService<MtUser> {
      * @return
      * */
     List<Integer> getUserIdList(Integer merchantId, Integer storeId);
+
+    /**
+     * 导入会员
+     *
+     * @param file excel文件
+     * @param accountInfo 操作者
+     * @param filePath 文件地址
+     * */
+    Boolean importMember(MultipartFile file, AccountInfo accountInfo, String filePath) throws BusinessCheckException;
+
 }

+ 2 - 10
fuint-application/src/main/java/com/fuint/common/service/impl/CouponGroupServiceImpl.java

@@ -9,7 +9,6 @@ import com.fuint.common.dto.ReqSendLogDto;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.service.*;
 import com.fuint.common.util.CommonUtil;
-import com.fuint.common.util.DateUtil;
 import com.fuint.common.util.XlsUtil;
 import com.fuint.framework.annoation.OperationServiceLog;
 import com.fuint.framework.exception.BusinessCheckException;
@@ -26,15 +25,13 @@ import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.core.env.Environment;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.ResourceUtils;
 import org.springframework.web.multipart.MultipartFile;
-import javax.servlet.http.HttpServletRequest;
-import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.lang.String;
@@ -48,7 +45,7 @@ import java.util.regex.Pattern;
  * CopyRight https://www.fuint.cn
  */
 @Service
-@AllArgsConstructor
+@AllArgsConstructor(onConstructor_= {@Lazy})
 public class CouponGroupServiceImpl extends ServiceImpl<MtCouponGroupMapper, MtCouponGroup> implements CouponGroupService {
 
     private static final Logger log = LoggerFactory.getLogger(CouponGroupServiceImpl.class);
@@ -79,11 +76,6 @@ public class CouponGroupServiceImpl extends ServiceImpl<MtCouponGroupMapper, MtC
      * */
     private SendSmsService sendSmsService;
 
-    /**
-     * 系统环境变量
-     * */
-    private Environment env;
-
     /**
      * 分页查询卡券分组列表
      *

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

@@ -34,7 +34,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.core.env.Environment;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;

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

@@ -33,6 +33,8 @@ import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.util.*;
@@ -1027,4 +1029,31 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
     public List<Integer> getUserIdList(Integer merchantId, Integer storeId) {
         return mtUserMapper.getUserIdList(merchantId, storeId);
     }
+
+    /**
+     * 导入会员
+     *
+     * @param file excel文件
+     * @param accountInfo 操作者
+     * @return
+     * */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @OperationServiceLog(description = "导入会员列表")
+    public Boolean importMember(MultipartFile file, AccountInfo accountInfo, String filePath) throws BusinessCheckException {
+        String originalFileName = file.getOriginalFilename();
+        boolean isExcel2003 = XlsUtil.isExcel2003(originalFileName);
+        boolean isExcel2007 = XlsUtil.isExcel2007(originalFileName);
+
+        if (!isExcel2003 && !isExcel2007) {
+            logger.error("importMember->uploadFile:{}", "文件类型不正确");
+            throw new BusinessCheckException("文件类型不正确");
+        }
+
+        if (accountInfo == null || accountInfo.getMerchantId() == null || accountInfo.getMerchantId() <= 0) {
+            throw new BusinessCheckException("没有操作权限");
+        }
+
+        return true;
+    }
 }

+ 0 - 41
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendFileController.java

@@ -6,7 +6,6 @@ import com.fuint.common.service.SettingService;
 import com.fuint.common.service.UploadService;
 import com.fuint.common.util.AliyunOssUtil;
 import com.fuint.common.util.CommonUtil;
-import com.fuint.common.util.DateUtil;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
@@ -14,7 +13,6 @@ import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -26,13 +24,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.core.env.Environment;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.*;
-import java.net.URL;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 
 /**
  * 文件上传管理控制类
@@ -164,39 +158,4 @@ public class BackendFileController extends BaseController {
 
         return getSuccessResult(resultMap);
     }
-
-    /**
-     * 下载文件
-     *
-     * @return
-     */
-    @ApiOperation(value = "下载文件")
-    @RequestMapping(value = "/download", method = RequestMethod.GET)
-    @CrossOrigin
-    public void download(HttpServletRequest request, HttpServletResponse response) {
-        String token = request.getParameter("token");
-        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
-        try {
-            URL resourceUrl = getClass().getClassLoader().getResource("GoodsTemplate.xlsx");
-            String path = resourceUrl.getPath();
-            logger.info("下载文件路径:path = {}", path);
-            File file = new File(path);
-            String filename = file.getName();
-            InputStream fis = new BufferedInputStream(new FileInputStream(path));
-            byte[] buffer = new byte[fis.available()];
-            fis.read(buffer);
-            fis.close();
-            response.reset();
-            response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
-            response.addHeader("Content-Length", "" + file.length());
-            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
-            response.setContentType("application/octet-stream");
-            toClient.write(buffer);
-            toClient.flush();
-            toClient.close();
-        } catch (IOException ex) {
-            ex.printStackTrace();
-            logger.error("下载文件出错:account = {},message = {}", accountInfo.getAccountName(), ex.getMessage());
-        }
-    }
 }

+ 3 - 7
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGiveLogController.java

@@ -184,9 +184,8 @@ public class BackendGiveLogController extends BaseController {
         List<GiveDto> list = paginationResponse.getContent();
 
         // excel标题
-        String[] title = {"记录ID", "用户手机号", "转赠数量", "转赠总金额", "赠予对象手机号", "赠予时间"};
-        String fileName;
-        fileName = "转赠记录" + System.currentTimeMillis() + ".xls";
+        String[] title = { "记录ID", "用户手机号", "转赠数量", "转赠总金额", "赠予对象手机号", "赠予时间" };
+        String fileName = "转赠记录" + System.currentTimeMillis() + ".xls";
 
         String[][] content = null;
         if (list.size() > 0) {
@@ -203,11 +202,8 @@ public class BackendGiveLogController extends BaseController {
              content[i][5] = objectConvertToString(obj.getCreateTime());
         }
 
-        // 创建HSSFWorkbook
-        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("转赠记录", title, content, null);
-
-        // 响应到客户端
         try {
+            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("转赠记录", title, content, null);
             XlsUtil.setXlsHeader(request, response, fileName);
             OutputStream os = response.getOutputStream();
             wb.write(os);

+ 41 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGoodsController.java

@@ -22,13 +22,17 @@ import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 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;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
-
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.util.*;
@@ -45,6 +49,8 @@ import java.util.*;
 @RequestMapping(value = "/backendApi/goods/goods")
 public class BackendGoodsController extends BaseController {
 
+    private static final Logger logger = LoggerFactory.getLogger(BackendGoodsController.class);
+
     private MtGoodsSpecMapper mtGoodsSpecMapper;
 
     private MtGoodsSkuMapper mtGoodsSkuMapper;
@@ -741,6 +747,40 @@ public class BackendGoodsController extends BaseController {
         return getSuccessResult(result);
     }
 
+    /**
+     * 下载商品导入模板
+     *
+     * @return
+     */
+    @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());
+        }
+    }
+
     /**
      * 上传商品导入文件
      *

+ 29 - 0
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -24,6 +24,8 @@ import lombok.AllArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
 import weixin.popular.util.JsonUtil;
 
 import javax.servlet.http.HttpServletRequest;
@@ -72,6 +74,11 @@ public class BackendMemberController extends BaseController {
      * */
     private WeixinService weixinService;
 
+    /**
+     * 上传文件服务接口
+     * */
+    private UploadService uploadService;
+
     /**
      * 查询会员列表
      *
@@ -555,4 +562,26 @@ public class BackendMemberController extends BaseController {
         List<GroupMemberDto> memberList = memberService.searchMembers(accountInfo.getMerchantId(), keyword, groupIds,1, Constants.MAX_ROWS);
         return getSuccessResult(memberList);
     }
+
+    /**
+     * 上传会员导入文件
+     *
+     * @param request
+     * @throws
+     */
+    @ApiOperation(value = "上传会员导入文件")
+    @RequestMapping(value = "/uploadMemberFile", method = RequestMethod.POST)
+    @CrossOrigin
+    public ResponseObject uploadMemberFile(HttpServletRequest request) throws Exception {
+        String token = request.getHeader("Access-Token");
+        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
+
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        MultipartFile file = multipartRequest.getFile("file");
+        String filePath = uploadService.saveUploadFile(request, file);
+
+        Boolean result = memberService.importMember(file, accountInfo, filePath);
+
+        return getSuccessResult(result);
+    }
 }

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

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

+ 0 - 0
fuint-application/src/main/resources/GoodsTemplate.xlsx → fuint-application/src/main/resources/template/GoodsTemplate.xlsx