Forráskód Böngészése

添加中奖人员手机号码脱敏导出

yanliming 3 hónapja
szülő
commit
e8d56f812f

+ 74 - 4
server/src/main/java/com/jpsoft/lotteryActivity/modules/base/controller/WinningInfoController.java

@@ -77,7 +77,7 @@ public class WinningInfoController {
 
             int affectCount = 0;
 
-            for (WinningInfo winningInfo:winningInfoList) {
+            for (WinningInfo winningInfo : winningInfoList) {
                 winningInfo.setId(UUID.randomUUID().toString());
                 winningInfo.setDelFlag(false);
                 winningInfo.setCreateBy(subject);
@@ -231,6 +231,7 @@ public class WinningInfoController {
             @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
             @RequestParam(value = "exportFlag", defaultValue = "false") Boolean exportFlag,
+            @RequestParam(value = "exportType", defaultValue = "") String exportType,
             HttpServletRequest request) {
         String subject = (String) request.getAttribute("subject");
 
@@ -261,6 +262,7 @@ public class WinningInfoController {
 
                 String activityName = "";
                 String phone = "";
+                String desensitizationPhone = "";
                 String lotteryPersonnelNickName = "";
                 String lotteryPersonnelImage = "";
                 String awardName = "";
@@ -281,7 +283,13 @@ public class WinningInfoController {
                     lotteryPersonnelImage = lotteryPersonnelInfo.getImage();
                 }
 
+                if (StringUtils.isNotEmpty(phone)) {
+                    desensitizationPhone = desensitizePhone(phone);
+                }
+
+
                 map.put("lotteryPersonnelPhone", phone);
+                map.put("desensitizationPhone", desensitizationPhone);
                 map.put("lotteryPersonnelNickName", lotteryPersonnelNickName);
                 map.put("lotteryPersonnelImage", lotteryPersonnelImage);
 
@@ -300,7 +308,18 @@ public class WinningInfoController {
 
 
             if (exportFlag) {
-                String filePath = exportXls(mapList);
+                String filePath = "";
+                if (StringUtils.isNotEmpty(exportType)) {
+                    if("2".equals(exportType)){
+                        filePath = exportXls2(mapList);
+                    }
+                    else{
+                        filePath = exportXls(mapList);
+                    }
+                }
+                else{
+                    filePath = exportXls(mapList);
+                }
                 msgResult.setData(filePath);
             } else {
                 Map<String, Object> dataMap = PojoUtils.pageWrapper(page);
@@ -318,6 +337,14 @@ public class WinningInfoController {
         return msgResult;
     }
 
+    private String desensitizePhone(String phone) {
+        if (phone == null || phone.length() != 11) {
+            return phone; // 非11位手机号不处理
+        }
+        // 使用正则表达式替换中间4位
+        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
+    }
+
 
     private String exportXls(List<Map> mapList) {
         String downloadUrl = "";
@@ -364,16 +391,59 @@ public class WinningInfoController {
     }
 
 
+    private String exportXls2(List<Map> mapList) {
+        String downloadUrl = "";
+
+        Workbook workbook = new HSSFWorkbook();
+        Sheet sheet = workbook.createSheet();
+
+        //表头
+        Row rowTitle = sheet.createRow(0);
+
+        String[] titles = new String[]{"序号", "中奖人电话", "奖项", "所属活动"};
+
+        for (int i = 0; i < titles.length; i++) {
+            Cell cell = rowTitle.createCell(i);
+            cell.setCellValue(titles[i]);
+        }
+
+        for (int i = 0; i < mapList.size(); i++) {
+            Map<String, Object> map = mapList.get(i);
+
+            Row row = sheet.createRow(i + 1);
+
+            int colIndex = 0;
+            row.createCell(colIndex++).setCellValue(i + 1);
+            row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("desensitizationPhone"), ""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("awardName"), ""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.lotteryActivity.utils.StringUtils.strValue(map.get("activityName"), ""));
+        }
+
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+        try {
+            workbook.write(output);
+
+            byte[] buffer = output.toByteArray();
+            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+            downloadUrl = OSSUtil.upload(ossConfig, "winningInfoList", "中奖人名单.xls", input);
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+        }
+
+        return downloadUrl;
+    }
 
 
     @ApiOperation(value = "测试抽奖")
     @PostMapping("startLottery")
-    public MessageResult<List<Map>> startLottery(String activityId,String awardId, @RequestAttribute String subject) {
+    public MessageResult<List<Map>> startLottery(String activityId, String awardId, @RequestAttribute String subject) {
         MessageResult<List<Map>> msgResult = new MessageResult<>();
 
         try {
 
-            List<WinningInfo> winningInfoList = winningInfoService.startLottery(activityId,awardId);
+            List<WinningInfo> winningInfoList = winningInfoService.startLottery(activityId, awardId);
 
             List<Map> mapList = new ArrayList<>();