Jelajahi Sumber

fengji 兑换码导入

yanite 3 tahun lalu
induk
melakukan
105f55a8b4

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/AppRedemptionCodeService.java

@@ -14,7 +14,7 @@ import java.util.List;
  */
 public interface AppRedemptionCodeService extends IService<AppRedemptionCode> {
 
-    List<AppRedemptionCode> importRedemptionCode(MultipartFile file) throws Exception;
+    String importRedemptionCode(MultipartFile file) throws Exception;
 
     AppRedemptionCode allocation(Integer userId);
 

+ 4 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/AppRedemptionCodeServiceImpl.java

@@ -56,7 +56,7 @@ public class AppRedemptionCodeServiceImpl extends ServiceImpl<RedemptionCodeDao,
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public List<AppRedemptionCode> importRedemptionCode(MultipartFile file) throws Exception {
+    public String importRedemptionCode(MultipartFile file) throws Exception {
         Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(
                 new ByteArrayInputStream(file.getBytes()), 0, file.getOriginalFilename());
 
@@ -96,11 +96,12 @@ public class AppRedemptionCodeServiceImpl extends ServiceImpl<RedemptionCodeDao,
         try {
             redemptionCodeDao.insertBatch(redemptionCodesList);
         } catch (DuplicateKeyException dupKeyEx) {
-            throw new BizException("数据重复:" + dupKeyEx.getCause(), dupKeyEx);
+            logger.error("数据导入重复: " + dupKeyEx.getCause());
+            return "数据重复:" + dupKeyEx;
         } catch (Exception ex) {
             throw new BizException("导入数据出错:" + ex, ex);
         }
-        return redemptionCodesList;
+        return "成功导入 " + redemptionCodesList.size() + "条";
     }
 
     @Override

+ 5 - 3
mec-web/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -68,13 +68,15 @@ public class ImportController extends BaseController {
     @ApiOperation(value = "导入兑换码分配模板")
     @PostMapping(value = "importRedemptionCode")
     @PreAuthorize("@pcs.hasPermissions('import/importRedemptionCode')")
-    public HttpResponseResult<List<AppRedemptionCode>> importRedemptionCode(@RequestParam("file") MultipartFile file) throws Exception {
+    public HttpResponseResult<String> importRedemptionCode(@RequestParam("file") MultipartFile file) throws Exception {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if (sysUser == null) {
             return failed("用户信息获取失败");
         }
-        List<AppRedemptionCode> ret = appRedemptionCodeService.importRedemptionCode(file);
-        return succeed(ret);
+        String msg = appRedemptionCodeService.importRedemptionCode(file);
+        HttpResponseResult response = succeed(null);
+        response.setMsg(msg);
+        return response;
     }
 
     @ApiOperation(value = "导入财务管理订单")