13 changed files with 203 additions and 15 deletions
-
6pom.xml
-
11src/main/java/com/example/demo/Mysql/MysqlServiceImpl.java
-
5src/main/java/com/example/demo/controller/MenuController.java
-
10src/main/java/com/example/demo/domain/entity/User.java
-
5src/main/java/com/example/demo/mapper/MenuMapper.java
-
2src/main/java/com/example/demo/mapper/RoleMapper.java
-
108src/main/java/com/example/demo/password/ExcelProcessor.java
-
3src/main/java/com/example/demo/service/MenuService.java
-
1src/main/java/com/example/demo/service/PermissionService.java
-
33src/main/java/com/example/demo/serviceImpl/MenuServiceImpl.java
-
15src/main/resources/mapper/MenuMapper.xml
-
15src/main/resources/mapper/RoleMapper.xml
-
4src/main/resources/mapper/UserMapper.xml
@ -0,0 +1,108 @@ |
|||
package com.example.demo.password; |
|||
|
|||
import com.example.demo.Util.BaseDES; |
|||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|||
import org.apache.poi.ss.usermodel.*; |
|||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|||
import org.springframework.http.*; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.io.File; |
|||
import java.io.FileInputStream; |
|||
import java.io.FileOutputStream; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
public class ExcelProcessor { |
|||
|
|||
public static void main(String[] args) { |
|||
String inputFilePath = "D:\\地区导出.xls"; // 输入文件路径 |
|||
String outputFilePath = "D:\\output.xlsx"; // 输出文件路径 |
|||
|
|||
try (FileInputStream fis = new FileInputStream(new File(inputFilePath)); |
|||
Workbook workbook = new HSSFWorkbook(fis); |
|||
FileOutputStream fos = new FileOutputStream(new File(outputFilePath))) { |
|||
|
|||
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表 |
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
|
|||
// 创建新的输出工作簿 |
|||
Workbook outputWorkbook = new XSSFWorkbook(); |
|||
Sheet outputSheet = outputWorkbook.createSheet("Result"); |
|||
Row headerRow = outputSheet.createRow(0); |
|||
headerRow.createCell(0).setCellValue("jwcode"); |
|||
headerRow.createCell(1).setCellValue("name"); |
|||
headerRow.createCell(2).setCellValue("country"); |
|||
|
|||
int outputRowIndex = 1; |
|||
|
|||
// 遍历输入文件的每一行 |
|||
for (int i = 1; i <= sheet.getLastRowNum(); i++) { // 假设第一行是标题 |
|||
Row row = sheet.getRow(i); |
|||
if (row == null) continue; |
|||
|
|||
String jwcode = row.getCell(1).getStringCellValue(); // 假设 jwcode 在第一列 |
|||
System.out.println("Processing jwcode: " + jwcode); |
|||
|
|||
// 调用接口 |
|||
Map<String, String> result = callApi(jwcode, restTemplate); |
|||
|
|||
// 写入结果到新 Excel 文件 |
|||
Row outputRow = outputSheet.createRow(outputRowIndex++); |
|||
outputRow.createCell(0).setCellValue(jwcode); |
|||
outputRow.createCell(1).setCellValue(result.getOrDefault("name", "未知")); |
|||
outputRow.createCell(2).setCellValue(result.getOrDefault("country", "未知")); |
|||
} |
|||
|
|||
// 保存输出文件 |
|||
outputWorkbook.write(fos); |
|||
System.out.println("Processing completed. Output file saved to: " + outputFilePath); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
private static Map<String, String> callApi(String jwcode, RestTemplate restTemplate) { |
|||
Map<String, String> result = new HashMap<>(); |
|||
result.put("name", "未知"); |
|||
result.put("country", "未知"); |
|||
|
|||
try { |
|||
BaseDES des = new BaseDES(); |
|||
String desjwcode = des.encrypt(String.valueOf(jwcode)); |
|||
|
|||
// 创建 JSON 请求体 |
|||
Map<String, String> requestBody = new HashMap<>(); |
|||
requestBody.put("jwcode", desjwcode); |
|||
|
|||
// 设置请求头 |
|||
HttpHeaders headers = new HttpHeaders(); |
|||
headers.setContentType(MediaType.APPLICATION_JSON); |
|||
|
|||
// 创建 HttpEntity |
|||
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers); |
|||
|
|||
// 发送 POST 请求 |
|||
ResponseEntity<Map> response = restTemplate.exchange( |
|||
"http://hwapi.rzfwq.com/hwjnApp/hwhc-login/hwhclogin/hc/login/clent/info", |
|||
HttpMethod.POST, entity, Map.class); |
|||
|
|||
// 检查响应状态码 |
|||
if (response.getStatusCode().is2xxSuccessful()) { |
|||
Map<String, Object> responseBody = response.getBody(); |
|||
if (responseBody != null) { |
|||
Map<String, Object> data = (Map<String, Object>) responseBody.get("data"); |
|||
if (data != null) { |
|||
result.put("name", (String) data.getOrDefault("name", "未知")); |
|||
result.put("country", (String) data.getOrDefault("country", "未知")); |
|||
} |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
System.out.println("Error processing jwcode: " + jwcode + ", Error: " + e.getMessage()); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue