|
|
@ -55,7 +55,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
private IDbPhoneService dbPhoneService; |
|
|
|
@Resource |
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 分页列表查询 |
|
|
|
* |
|
|
@ -83,7 +83,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
IPage<DbPhone> pageList = dbPhoneService.page(page, queryWrapper); |
|
|
|
return Result.OK(pageList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 添加 |
|
|
|
* |
|
|
@ -97,7 +97,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
dbPhoneService.save(dbPhone); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 编辑 |
|
|
|
* |
|
|
@ -111,7 +111,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
dbPhoneService.updateById(dbPhone); |
|
|
|
return Result.OK("编辑成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 通过id删除 |
|
|
|
* |
|
|
@ -125,7 +125,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
dbPhoneService.removeById(id); |
|
|
|
return Result.OK("删除成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 批量删除 |
|
|
|
* |
|
|
@ -139,7 +139,7 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
this.dbPhoneService.removeByIds(Arrays.asList(ids.split(","))); |
|
|
|
return Result.OK("批量删除成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 通过id查询 |
|
|
|
* |
|
|
@ -168,102 +168,6 @@ public class DbPhoneController extends JeecgController<DbPhone, IDbPhoneService> |
|
|
|
return super.exportXls(request, dbPhone, DbPhone.class, "电话去重复表"); |
|
|
|
} |
|
|
|
|
|
|
|
// /** |
|
|
|
// * 通过excel导入数据 |
|
|
|
// * |
|
|
|
// * @param request |
|
|
|
// * @param response |
|
|
|
// * @return |
|
|
|
// */ |
|
|
|
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
// public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
// return super.importExcel(request, response, DbPhone.class); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
// public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
|
|
|
// |
|
|
|
// // 用于存储最终要导入的数据 |
|
|
|
// List<DbPhone> finalDataList = new ArrayList<>(); |
|
|
|
// |
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
|
|
|
// MultipartFile file = entity.getValue(); |
|
|
|
// ImportParams params = new ImportParams(); |
|
|
|
// params.setTitleRows(2); |
|
|
|
// params.setHeadRows(1); |
|
|
|
// |
|
|
|
// try { |
|
|
|
// // 读取Excel文件中的所有数据 |
|
|
|
// List<DbPhone> listFromExcel = ExcelImportUtil.importExcel(file.getInputStream(), DbPhone.class, params); |
|
|
|
// |
|
|
|
// // 创建一个Set来存储唯一的电话号码,用于检查重复项 |
|
|
|
// Set<String> uniquePhoneNumbers = new HashSet<>(); |
|
|
|
// |
|
|
|
// // 遍历Excel中的数据,检查重复并过滤 |
|
|
|
// for (DbPhone item : listFromExcel) { |
|
|
|
// String phoneNumber = item.getPhone(); // 假设DbPhone类有一个getPhoneNumber()方法 |
|
|
|
// |
|
|
|
// // 检查电话号码是否已在Excel中重复或数据库中已存在 |
|
|
|
// if (!uniquePhoneNumbers.contains(phoneNumber) && !this.existsByPhoneNumber(phoneNumber)) { |
|
|
|
// uniquePhoneNumbers.add(phoneNumber); |
|
|
|
// finalDataList.add(item); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// // 如果有数据要导入,则执行批量插入 |
|
|
|
// if (!finalDataList.isEmpty()) { |
|
|
|
// long start = System.currentTimeMillis(); |
|
|
|
// service.saveBatch(finalDataList); |
|
|
|
// log.info("导入并过滤重复数据消耗时间:" + (System.currentTimeMillis() - start) + "毫秒"); |
|
|
|
// return Result.ok("文件导入成功!已导入数据行数:" + finalDataList.size()); |
|
|
|
// } else { |
|
|
|
// return Result.ok("文件导入成功,但无新数据导入,因为所有数据均为重复项。"); |
|
|
|
// } |
|
|
|
// } catch (Exception e) { |
|
|
|
// String msg = e.getMessage(); |
|
|
|
// log.error(msg, e); |
|
|
|
// if (msg != null && msg.contains("Duplicate entry")) { |
|
|
|
// // 注意:这里通常不会由ExcelImportUtil抛出“Duplicate entry”异常,除非有内部数据库操作 |
|
|
|
// // 但为了保持代码的完整性,我们仍然检查这个条件 |
|
|
|
// return Result.error("文件导入失败:处理过程中发现重复数据!"); |
|
|
|
// } else { |
|
|
|
// return Result.error("文件导入失败:" + e.getMessage()); |
|
|
|
// } |
|
|
|
// } finally { |
|
|
|
// // 注意:通常不需要在这里关闭InputStream,因为ExcelImportUtil应该已经处理了它 |
|
|
|
// // 但如果确实需要,并且你确定ExcelImportUtil没有关闭它,则应该这样做 |
|
|
|
// // 然而,更好的做法是让ExcelImportUtil负责资源管理 |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// // 如果没有文件被处理(理论上不应该发生,因为至少应该有一个文件),则返回错误 |
|
|
|
// return Result.error("文件导入失败!未找到有效的上传文件。"); |
|
|
|
// } |
|
|
|
// |
|
|
|
// // 假设在service层中添加了以下方法来检查电话号码是否已存在 |
|
|
|
// public boolean existsByPhoneNumber(String phoneNumber) { |
|
|
|
// |
|
|
|
// |
|
|
|
// // 先从缓存中查找 |
|
|
|
// String s= (String)redisUtil.get(phoneNumber); |
|
|
|
// if (StringUtils.isNotBlank(s)) { |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
// // 缓存中不存在,则查询数据库 |
|
|
|
// DbPhone one = service.lambdaQuery().eq(DbPhone::getPhone, phoneNumber).one(); |
|
|
|
// if (one != null) { |
|
|
|
// // 如果数据库中存在,则更新缓存 |
|
|
|
// redisUtil.set(phoneNumber,phoneNumber); |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
// return false; |
|
|
|
// |
|
|
|
// } |
|
|
|
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|