113 lines
5.2 KiB
Java
113 lines
5.2 KiB
Java
package de.jeyp91.tippliga;
|
|
|
|
import de.jeyp91.tippligaforum.TippligaSQLConnector;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
|
|
import static de.jeyp91.googlecalendar.TippligaGoogleEventManager.*;
|
|
|
|
public class TLWMatchdaysUpdater {
|
|
|
|
private final Logger logger = LogManager.getLogger(TLWMatch.class);
|
|
|
|
int season;
|
|
int league;
|
|
ArrayList<TLWMatchday> matchdaysOriginal;
|
|
ArrayList<TLWMatchday> matchdaysUpdated;
|
|
String beautifulInfo = "";
|
|
|
|
public TLWMatchdaysUpdater(int season, int league, String configPath) {
|
|
this.season = season;
|
|
this.league = league;
|
|
|
|
TippligaSQLConnector conn = TippligaSQLConnector.getInstance();
|
|
this.matchdaysOriginal = conn.getMatchdays(String.valueOf(season), String.valueOf(league));
|
|
this.matchdaysOriginal.sort(Comparator.comparing(TLWMatchday::getMatchday));
|
|
|
|
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(season, league, configPath);
|
|
this.matchdaysUpdated = creator.getMatchdays();
|
|
this.matchdaysUpdated.sort(Comparator.comparing(TLWMatchday::getMatchday));
|
|
}
|
|
|
|
public String getUpdateSql() {
|
|
String updateSql = "";
|
|
|
|
if(this.matchdaysUpdated.size() != this.matchdaysOriginal.size()) {
|
|
this.logger.error("Wrong matchdays config!");
|
|
} else {
|
|
|
|
for (int i = 0; i < this.matchdaysUpdated.size(); i++) {
|
|
TLWMatchday matchdayOriginal = this.matchdaysOriginal.get(i);
|
|
TLWMatchday matchdayUpdated = this.matchdaysUpdated.get(i);
|
|
|
|
if (matchdayOriginal.getMatchday() != matchdayUpdated.getMatchday()) {
|
|
this.logger.error("BUUUUG!");
|
|
} else {
|
|
|
|
Date now = new Date(System.currentTimeMillis());
|
|
|
|
Date earliestDate = null;
|
|
try {
|
|
earliestDate = new SimpleDateFormat("yyyy-MM-dd").parse(matchdayUpdated.getDeliveryDate().substring(0, 10));
|
|
} catch (java.text.ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (earliestDate.after(now)) {
|
|
|
|
String updateStart = "UPDATE phpbb_footb_matchdays SET ";
|
|
String condition = "WHERE season = " + matchdayOriginal.getSeason() + " " +
|
|
"AND league = " + matchdayOriginal.getLeague() + " " +
|
|
"AND matchday = " + matchdayOriginal.getMatchday() + ";\n";
|
|
String beautifulInfoStart = "Aktualisiere Saison " + matchdayOriginal.getSeason() + ", " +
|
|
"Liga " + matchdayOriginal.getLeague() + ", " +
|
|
"Spieltag " + matchdayOriginal.getMatchday() + ", ";
|
|
|
|
if (!matchdayOriginal.getDeliveryDate().equals(matchdayUpdated.getDeliveryDate())) {
|
|
updateSql += updateStart +
|
|
"delivery_date = '" + matchdayUpdated.getDeliveryDate() + "' " +
|
|
condition;
|
|
this.beautifulInfo += beautifulInfoStart +
|
|
"Tippabgabeschluss 1 zu '" + matchdayUpdated.getDeliveryDate() + "'.\n";
|
|
createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate(), 1);
|
|
}
|
|
|
|
if (!matchdayOriginal.getDeliveryDate2().equals(matchdayUpdated.getDeliveryDate2())) {
|
|
updateSql += updateStart +
|
|
"delivery_date_2 = '" + matchdayUpdated.getDeliveryDate2() + "' " +
|
|
condition;
|
|
this.beautifulInfo += beautifulInfoStart +
|
|
"Tippabgabeschluss 2 zu '" + matchdayUpdated.getDeliveryDate2() + "'.\n";
|
|
if(!matchdayUpdated.getDeliveryDate2().equals(""))
|
|
createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate2(), 2);
|
|
else
|
|
deleteEvent(matchdayUpdated, 2);
|
|
}
|
|
|
|
if (!matchdayOriginal.getMatchdayName().equals(matchdayUpdated.getMatchdayName())) {
|
|
updateSql += updateStart +
|
|
"matchday_name = '" + matchdayUpdated.getMatchdayName() + "' " +
|
|
condition;
|
|
this.beautifulInfo += beautifulInfoStart +
|
|
"Spieltagsname zu '" + matchdayUpdated.getMatchdayName() + "'.\n";
|
|
createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate(), 1);
|
|
if(!matchdayUpdated.getDeliveryDate2().equals(""))
|
|
createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate2(), 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return updateSql;
|
|
}
|
|
|
|
public String getBeautifulInfo() {
|
|
return this.beautifulInfo;
|
|
}
|
|
}
|