Commit 82d3086e authored by 霍传世's avatar 霍传世

1.笔试表 删除uuid

2.面试候考表 增加out_id
parent 3fd1fd88
......@@ -80,6 +80,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.4</version> <!-- 请根据需要选择最新版本 -->
</dependency>
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos-sts_api</artifactId>
......@@ -101,6 +111,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -30,7 +30,7 @@ public class LoginController {
public ResponseEntity LoginGo(@RequestBody CandidateExam candidate){
try{
CandidateExam candidateExam = DBOperator.queryForObject("SELECT \n" +
"\tb.uuid, \n" +
"\ta.out_id, \n" +
"\tb.NAME, \n" +
"\ta.zkz_num, \n" +
"\tb.id_card, \n" +
......
......@@ -3,8 +3,8 @@ package com.yuda.hainafacetofaceai.controller;
import com.yuda.hainafacetofaceai.constant.AppThirdPartUrls;
import com.yuda.hainafacetofaceai.entity.CandidateCreateQuery;
import com.yuda.hainafacetofaceai.entity.CandidateExam;
import com.yuda.hainafacetofaceai.entity.ExamQuery;
import com.yuda.hainafacetofaceai.service.impl.ScriptInterfaceServiceImpl;
import com.yuda.hainafacetofaceai.service.impl.SeleniumService;
import com.yuda.hainafacetofaceai.util.AppUtil;
import com.yuda.hainafacetofaceai.util.ExcelUtil;
import com.yuda.hainafacetofaceai.util.RandomNumberUtil;
......@@ -27,9 +27,9 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("/scripts")
......@@ -46,33 +46,8 @@ public class ScriptInterfaceController {
private ScriptInterfaceServiceImpl scriptInterfaceService;
@Autowired
private JdbcTemplate DBOperator;
@PostMapping("/batchGenCandidatesOftest")
@Transactional
public ResponseEntity batchGenTest(@RequestParam("examConnectionCode")String examConnectionCode){
for (int i = 0; i < 10; i++) {
String uuid = UUID.randomUUID().toString().replace("-","");
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type","application/json");
CandidateCreateQuery candidateCreateQuery = new CandidateCreateQuery();
candidateCreateQuery.setOutId(uuid);
candidateCreateQuery.setRepeatVersion("0");
candidateCreateQuery.setExamConnectCode(examConnectionCode);
candidateCreateQuery.setPhone(randomNumberUtil.generateRandomPhoneNumber());
candidateCreateQuery.setShowName(randomNumberUtil.generateRandomChineseNickname());
JSONObject requestBodyObject = new JSONObject(candidateCreateQuery);
HttpEntity<String> entity = new HttpEntity<>(requestBodyObject.toString(),headers);
ResponseEntity<String> response = restTemplate.exchange(
appUtil.ApiUrlGen(AppThirdPartUrls.candidateCreate),
HttpMethod.POST,
entity,
String.class
);
JSONObject object = new JSONObject(response.getBody());
//操作库
log.info("添加成功");
}
return ResponseEntity.ok("");
}
@Autowired
private SeleniumService seleniumService;
@PostMapping("/{examConnectionCode}")
public ResponseEntity importCandidates(@PathVariable String examConnectionCode,MultipartFile file) {
ExcelUtil<CandidateExam> excelUtil = new ExcelUtil<>();
......@@ -106,7 +81,7 @@ public class ScriptInterfaceController {
List<CandidateExam> candidateExamList = DBOperator.query("select\n" +
"a.phone, \n" +
"b.id_card, \n" +
"b.uuid,\n" +
"a.out_id,\n" +
"b.name,\n" +
"a.exam_connect_code\n" +
"from \n" +
......@@ -181,4 +156,11 @@ public class ScriptInterfaceController {
}}).toString());
}
@RequestMapping("/getAiJsonFile")
public ResponseEntity getAiJsonFile() throws UnsupportedEncodingException {
List<CandidateExam> lists = DBOperator.query("select exam_connect_code ,candidate_connect_code,interview_results from candidate_exam where result_back = 1",new Object[]{},new BeanPropertyRowMapper<>(CandidateExam.class));
seleniumService.extractDataAndSaveToJson(lists);
return ResponseEntity.ok("success");
}
}
......@@ -6,6 +6,7 @@ import org.joda.time.DateTime;
@Data
public class CandidateExam {
private String outId;
private String uuid;
@ExcelColumn(headerName = "姓名")
private String name;
......
......@@ -20,6 +20,7 @@ import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -51,8 +52,11 @@ public class ScriptInterfaceServiceImpl implements ScriptInterfaceService {
List<String> alreadyExistStudentIdCards = DBOperator.queryForList("select id_card from candidate_exam where exam_connect_code = ?",new Object[]{examConnectionCode},String.class);
if(!alreadyExistStudentIdCards.isEmpty()){
paperExamStudents = paperExamStudents.stream().filter(x->!alreadyExistStudentIdCards.contains(x.getIdCard())).collect(Collectors.toList());
}
if(!paperExamStudents.isEmpty()){
for (CandidateExam paperExamStudent : paperExamStudents) {
paperExamStudent.setExamConnectCode(examConnectionCode);
paperExamStudent.setOutId(UUID.randomUUID().toString().replace("-",""));
}
}
if(!paperExamStudents.isEmpty()){
......@@ -60,7 +64,7 @@ public class ScriptInterfaceServiceImpl implements ScriptInterfaceService {
int total = paperExamStudents.size();
for (int i = 0; i < total; i += chunkSize) {
int end = Math.min(i + chunkSize, total);
List<CandidateExam> chunk = candidateExamList.subList(i, end);
List<CandidateExam> chunk = paperExamStudents.subList(i, end);
try{
batchInsert(chunk);
}catch (Exception e){
......@@ -79,7 +83,7 @@ public class ScriptInterfaceServiceImpl implements ScriptInterfaceService {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type","application/json");
JSONObject requestBodyObject = new JSONObject(candidateExam);
requestBodyObject.put("outId",candidateExam.getUuid());
requestBodyObject.put("outId",candidateExam.getOutId());
requestBodyObject.put("showName",candidateExam.getName());
HttpEntity<String> entity = new HttpEntity<>(requestBodyObject.toString(),headers);
ResponseEntity<String> response = restTemplate.exchange(
......@@ -105,11 +109,11 @@ public class ScriptInterfaceServiceImpl implements ScriptInterfaceService {
@Transactional // 开启事务,确保操作的一致性
public void batchInsert(List<CandidateExam> candidateExamList) {
// 批量插入 SQL 语句
String sql = "INSERT INTO candidate_exam (id_card,zkz_num,exam_connect_code,phone) VALUES (?,?,?,?)";
String sql = "INSERT INTO candidate_exam (id_card,zkz_num,exam_connect_code,phone,out_id) VALUES (?,?,?,?,?)";
// 将 idCards 转换为批量操作所需的参数数组
List<Object[]> batchArgs = new ArrayList<>();
for (CandidateExam candidateExam : candidateExamList) {
batchArgs.add(new Object[]{candidateExam.getIdCard(),candidateExam.getZkzNum(),candidateExam.getExamConnectCode(),candidateExam.getPhone()});
batchArgs.add(new Object[]{candidateExam.getIdCard(),candidateExam.getZkzNum(),candidateExam.getExamConnectCode(),candidateExam.getPhone(),candidateExam.getOutId()});
}
// 使用 batchUpdate 方法执行批量插入
DBOperator.batchUpdate(sql,batchArgs);
......
package com.yuda.hainafacetofaceai.service.impl;
import com.yuda.hainafacetofaceai.entity.CandidateExam;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.json.JSONObject;
@Service
public class SeleniumService {
private static final Logger logger = Logger.getLogger(SeleniumService.class.getName());
private static final String driverPath = "D:/Game/chromedriver-win64/chromedriver-win64/chromedriver.exe";
public void extractDataAndSaveToJson(List<CandidateExam> list) throws UnsupportedEncodingException {
System.setProperty("webdriver.chrome.driver", driverPath);
// 设置ChromeDriver路径
for (CandidateExam candidateExam : list) {
WebDriver driver = new ChromeDriver();
String json = candidateExam.getInterviewResults();
JSONObject object = new JSONObject(json);
String url = object.get("reportUrl").toString();
Integer i = 0;
Integer j = 0;
// 创建WebDriver实例
try {
// 打开目标网页
driver.get(url);
// 等待元素可见
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#full > div.mainBox > div.big-card-con")));
// 提取元素的HTML内容
String elementHtml = element.getAttribute("outerHTML");
// 使用Jsoup解析HTML
Document doc = Jsoup.parse(elementHtml);
List<Element> newQBlocks = doc.select(".new-q-block");
Map<String, String> resultMap = new HashMap<>();
// 遍历每个new-q-block元素
for (Element block : newQBlocks) {
// 查找第一个class="P-inline"的元素并获取其文本内容作为键
Element keyElement = block.selectFirst(".P-inline");
String key = keyElement != null ? keyElement.text().trim() : null;
// 查找第二个class="content"的元素并获取其文本内容作为值
List<Element> valueElements = block.select(".content");
String value = valueElements.size() > 1 ? valueElements.get(1).text().trim() : null;
// 如果键和值都存在,则将其添加到字典中
if (key != null && value != null) {
resultMap.put(key, value);
}
}
// 打印提取的内容
// 将结果保存为JSON文件
String outputFile = "D:/jsonResults/"+candidateExam.getExamConnectCode()+"/"+candidateExam.getCandidateConnectCode()+"_ai.json";
saveToJson(resultMap, outputFile);
logger.info("结果已保存到: " + outputFile);
logger.info("处理成功进度—ai_json:(面试编号)"+candidateExam.getExamConnectCode()+"_(候选人链接编号)"+candidateExam.getCandidateConnectCode()+"=成功"+(++i)+"/"+list.size());
} catch (Exception e) {
logger.info("处理成功进度—ai_json:(面试编号)"+candidateExam.getExamConnectCode()+"_(候选人链接编号)"+candidateExam.getCandidateConnectCode()+"=失败"+(++j)+"/"+list.size());
} finally {
driver.quit();
}
}
}
private void saveToJson(Map<String, String> data, String filePath) throws IOException {
String json = new JSONObject(data).toString(4);
Files.write(Paths.get(filePath), json.getBytes());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment