重新调整工具类
This commit is contained in:
parent
aba32a0c1d
commit
1180a3ee6f
@ -9,6 +9,8 @@ import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@ -16,8 +18,12 @@ import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.usvisatrack.core.common.data.VisaEntry;
|
||||
import com.usvisatrack.core.common.data.VisaStatus;
|
||||
import com.usvisatrack.core.dao.model.USEmbassy;
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaClass;
|
||||
import com.usvisatrack.core.factories.USFactory;
|
||||
import com.usvisatrack.core.factories.VisaFactory;
|
||||
import com.usvisatrack.services.common.DataCrawl;
|
||||
|
||||
@ -91,6 +97,7 @@ public class VisaImporter extends DataCrawl {
|
||||
|
||||
if (!StringUtils.equalsIgnoreCase("ID", tds.get(1).text())) {
|
||||
Visa visa = new Visa();
|
||||
String checkeeCaseNumber = getCheckeeCaseNumber(tds.get(0));
|
||||
|
||||
// SET VISA CLASS
|
||||
String visaClassName = StringUtils.trimToEmpty(tds.get(2).text());
|
||||
@ -107,10 +114,68 @@ public class VisaImporter extends DataCrawl {
|
||||
visa.setVisaClass(visaClassMap.get(visaClassName));
|
||||
}
|
||||
|
||||
// SET VISA ENTRY
|
||||
String visaEntryName = StringUtils.upperCase(StringUtils.trimToEmpty(tds.get(3).text()));
|
||||
if (StringUtils.isNotBlank(visaEntryName)) {
|
||||
switch (visaEntryName) {
|
||||
case "NEW":
|
||||
visa.setVisaEntry(VisaEntry.NEW);
|
||||
break;
|
||||
case "RENEWAL":
|
||||
visa.setVisaEntry(VisaEntry.RENEWAL);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SET US Embassy
|
||||
String usEmbassyName = StringUtils.upperCase(StringUtils.trimToEmpty(tds.get(4).text()));
|
||||
if (StringUtils.isNotBlank(usEmbassyName)) {
|
||||
switch (usEmbassyName) {
|
||||
case "GUANGZHOU":
|
||||
visa.setUsEmbassy(USFactory.searchUSEmbassy("China", "Guangzhou"));
|
||||
break;
|
||||
case "RENEWAL":
|
||||
visa.setVisaEntry(VisaEntry.RENEWAL);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SET VISA MAJOR
|
||||
visa.setMajor(StringUtils.trimToEmpty(tds.get(5).text()));
|
||||
logger.debug("[{}]", visa.getMajor());
|
||||
|
||||
// SET VISA STATUS
|
||||
String visaStatusName = StringUtils.upperCase(StringUtils.trimToEmpty(tds.get(6).text()));
|
||||
if (StringUtils.isNotBlank(visaStatusName)) {
|
||||
switch (visaStatusName) {
|
||||
case "CLEAR":
|
||||
visa.setVisaStatus(VisaStatus.ISSUED);
|
||||
break;
|
||||
case "PENDING":
|
||||
visa.setVisaStatus(VisaStatus.ADMINISTRATIVEPROCESSING);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SET VISA Date
|
||||
String dateVisaInterview = StringUtils.upperCase(StringUtils.trimToEmpty(tds.get(7).text()));
|
||||
String dateVisaIssued = StringUtils.upperCase(StringUtils.trimToEmpty(tds.get(8).text()));
|
||||
if (StringUtils.isNotBlank(dateVisaInterview)) {
|
||||
visa.setDateVisaInterview(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(dateVisaInterview).toDate());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dateVisaIssued)) {
|
||||
visa.setDateVisaIssued(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(dateVisaIssued).toDate());
|
||||
}
|
||||
|
||||
Element link = tds.get(10).select("a").first();
|
||||
|
||||
logger.debug(">>>>>>>>>>>>>>>[{}]", link.attr("href"));
|
||||
|
||||
updateVisaNote(visa, checkeeCaseNumber);
|
||||
|
||||
VisaFactory.save(visa);
|
||||
}
|
||||
|
||||
@ -136,8 +201,47 @@ public class VisaImporter extends DataCrawl {
|
||||
for (VisaClass visaClass : visaClassList) {
|
||||
visaClassMap.put(visaClass.getVisaClassName(), visaClass);
|
||||
}
|
||||
|
||||
|
||||
logger.debug("XXX [{}]", visaClassMap.get("H1-B").getVisaClassEligibility());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CheckeeCaseNumber from Checkee website
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
private String getCheckeeCaseNumber(Element element) {
|
||||
String checkeeCaseNumber = null;
|
||||
|
||||
Element link = element.select("a").first();
|
||||
checkeeCaseNumber = StringUtils.substringAfterLast(link.attr("href"), "casenum=");
|
||||
|
||||
return checkeeCaseNumber;
|
||||
}
|
||||
|
||||
private void updateVisaNote(Visa visa, String checkeeCaseNumber) {
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect("https://www.checkee.info/personal_detail.php?casenum=" + checkeeCaseNumber).get();
|
||||
Elements newsHeadlines = doc.select("table");
|
||||
Element table = newsHeadlines.get(2);
|
||||
|
||||
for (Element row : table.select("tr")) {
|
||||
Elements tds = row.select("td");
|
||||
String dataString = tds.get(0).text();
|
||||
if (StringUtils.startsWithIgnoreCase(dataString, "Note:")) {
|
||||
visa.setDescription(StringUtils.trimToEmpty(StringUtils.substringAfter(dataString, "Note:")));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.debug("Case Description - [{}]", visa.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user