diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..47b3c5c
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..1514f2e
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ DevCalendar
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..f9fe345
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..abec6ca
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/DevCalendar.jar b/DevCalendar.jar
new file mode 100644
index 0000000..5b7e346
Binary files /dev/null and b/DevCalendar.jar differ
diff --git a/conf/config b/conf/config
new file mode 100644
index 0000000..eaa20f4
--- /dev/null
+++ b/conf/config
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..292bd59
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,38 @@
+
+ 4.0.0
+
+ bas.sourcecode
+ DevCalendar
+ 0.0.1-SNAPSHOT
+ jar
+
+ DevCalendar
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.8-dmr
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.4
+
+
+
+
diff --git a/src/main/java/bas/sourcecode/DevCalendar/App.java b/src/main/java/bas/sourcecode/DevCalendar/App.java
new file mode 100644
index 0000000..1919b80
--- /dev/null
+++ b/src/main/java/bas/sourcecode/DevCalendar/App.java
@@ -0,0 +1,377 @@
+package bas.sourcecode.DevCalendar;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+
+import org.apache.http.Consts;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+
+import com.mysql.cj.api.jdbc.Statement;
+
+import obj.DevInfo;
+
+public class App {
+
+ private static String Connection = "jdbc:mysql://202.162.79.195/devcalendar?user=devcalendar&password=9iwK8Fm801yLbWRP&useSSL=false&serverTimezone=UTC";
+ private static String Token = "2mQSvqy17d0Dodi6fENsaUcSVKY2Xhh5FQ2aKLuE396"; //s4MVB0CjPyRfoxE7DFOkFgr2TR2CZy1qt6N8Bylnrpf //per
+ private static LinkedHashSet Person = new LinkedHashSet(); //2mQSvqy17d0Dodi6fENsaUcSVKY2Xhh5FQ2aKLuE396
+ private static String IgnorePerson = "karun,nungp,nutthaphons,patcharin,piyapongs,pla,sasawatt,siwatchl,sukrit,top,voravuts,wanida";
+
+ public static void main(String[] args) {
+
+
+ // read config
+// File file = new File("conf/config");
+// try {
+// BufferedReader br = new BufferedReader(new FileReader(file));
+// String line;
+// while ((line = br.readLine()) != null)
+// {
+//// System.out.println(line);
+// if (line.contains("connection"))
+// Connection = (line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")));
+// else if(line.contains("linetoken"))
+// Token = (line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")));
+//
+// }
+// br.close();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+
+
+ HashSet ignoreDay = getWeekendDays();
+ ignoreDay = getHoliday(ignoreDay);
+ Connection connect = null;
+ ArrayList personList = new ArrayList();
+
+
+ try {
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ connect = DriverManager.getConnection(Connection);
+
+ if (connect != null) {
+ System.out.println("Database Connected.");
+
+ Statement s = (Statement) connect.createStatement();
+
+
+
+ String sql2 = "SELECT username,user_id ";
+ sql2 = sql2+" FROM devcalendar.dev_work ";
+ sql2 = sql2+" where 1 = 1 ";
+ sql2 = sql2+" group by username ";
+ sql2 = sql2+" order by username,worked_on desc ";
+
+ ResultSet rec2 = s.executeQuery(sql2);
+ while((rec2!=null) && (rec2.next()))
+ {
+ Person.add(rec2.getString("username"));
+ }
+
+ String sql = "SELECT username,DAY(worked_on) as worked_on FROM devcalendar.dev_work ";
+ sql = sql+" where 1 = 1 ";
+ sql = sql+" AND MONTH(worked_on) = MONTH(CURRENT_DATE()) ";
+ sql = sql+" AND YEAR(worked_on) = YEAR(CURRENT_DATE()) ";
+ sql = sql+" order by username,worked_on desc ";
+
+ System.out.println(sql);
+
+ ResultSet rec = s.executeQuery(sql);
+ String tempName = "";
+ int tempDay = 0;
+ DevInfo person = new DevInfo();
+ person.setDays(new HashSet());
+ while((rec!=null) && (rec.next()))
+ {
+ if(tempName.equals(rec.getString("username")) || tempName.equals(""))
+ {
+ //same person
+ person.setName(rec.getString("username"));
+ if(!ignoreDay.contains(Integer.parseInt(rec.getString("worked_on"))) && Integer.parseInt(rec.getString("worked_on")) != tempDay)
+ person.getDays().add(Integer.parseInt(rec.getString("worked_on")));
+
+
+
+ }else
+ {
+ //change person
+ if(person.getName() == null)
+ person.setName(tempName);
+ personList.add(person);
+ person = new DevInfo();
+ person.setDays(new HashSet());
+ }
+
+ tempName = rec.getString("username");
+ tempDay = Integer.parseInt(rec.getString("worked_on"));
+ }
+ if(person.getName() == null)
+ person.setName(tempName);
+ personList.add(person);
+
+ Calendar mycal = new GregorianCalendar();
+ int toDay = mycal.get(Calendar.DAY_OF_MONTH);
+
+ if(Person.size() != personList.size())
+ {
+// System.out.println(Person.size());
+// System.out.println(personList.size());
+ for(DevInfo dev : personList)
+ {
+ Person.remove(dev.name);
+ }
+ String[] ignore = IgnorePerson.split(",");
+ for(int i=0;i());
+ personList.add(personData);
+ }
+
+ String[] sortData = new String[personList.size()];
+
+ for(int i=0;i0)
+ {
+ String personMsg = "\r\nคนไม่บันทึกงานเดือนนี้!!!\r\n";
+ personMsg = personMsg + "Time : " + getCurrentTimeStamp("MM/dd HH:mm") +"\r\n";
+
+ for(String noDataPerson: Person)
+ {
+ personMsg = personMsg + noDataPerson +" \r\n";
+ }
+
+
+// sendNoti(personMsg);
+ }
+
+
+ if(!notiMsg.equals(""))
+ {
+ notiMsg = "\r\nคนไม่บันทึกงาน!!!\r\n" + notiMsg;
+ notiMsg = "Time : " + getCurrentTimeStamp("MM/dd HH:mm") + notiMsg + "\r\n";
+ sendNoti(notiMsg);
+ }else
+ {
+ notiMsg = "\uDBC0\uDC33\uDBC0\uDC33\uDBC0\uDC33";
+ notiMsg = "\r\nทุกคนบันทึกงานเยี่ยมมาก!!!\r\n" + notiMsg;
+ notiMsg = "Time : " + getCurrentTimeStamp("MM/dd HH:mm") + notiMsg + "\r\n";
+ sendNoti(notiMsg);
+ }
+
+
+ } else {
+ System.out.println("Database Connect Failed.");
+ }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // Close
+ try {
+ if (connect != null) {
+ connect.close();
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public static HashSet getWeekendDays() {
+
+ HashSet returnData = new HashSet();
+
+ Calendar calendar = Calendar.getInstance();
+ int toDay = calendar.get(Calendar.DAY_OF_MONTH);
+ int year = calendar.get(Calendar.YEAR);
+ int month = calendar.get(Calendar.MONTH)+1;
+// System.out.println(year+" "+month);
+ // Note that month is 0-based in calendar, bizarrely.
+ calendar.set(year, month - 1, 1);
+ int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+
+// int count = 0;
+ for (int day = 1; day <= daysInMonth; day++) {
+ calendar.set(year, month - 1, day);
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
+ if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
+// count++;
+ if(day <= toDay)
+ {
+ returnData.add(day);
+// System.out.println("day :" +(day));
+ }
+ // Or do whatever you need to with the result.
+ }
+ }
+ return returnData;
+ }
+
+
+ public static HashSet getHoliday(HashSet ignoreDay) {
+
+ Connection connect = null;
+ try {
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ connect = DriverManager.getConnection(Connection);
+
+ if (connect != null) {
+ System.out.println("Database Connected.");
+
+ Statement s = (Statement) connect.createStatement();
+
+ String sql = "SELECT DAY(holiday) as holiday FROM holidays ";
+ sql = sql+" where 1 = 1 ";
+ sql = sql+" AND MONTH(holiday) = MONTH(CURRENT_DATE()) ";
+ sql = sql+" AND YEAR(holiday) = YEAR(CURRENT_DATE()) ";
+ sql = sql+" AND holiday <= CURRENT_DATE() ";
+
+ ResultSet rec = s.executeQuery(sql);
+
+ while((rec!=null) && (rec.next()))
+ {
+// System.out.print(rec.getString("holiday"));
+ ignoreDay.add(Integer.parseInt(rec.getString("holiday")));
+ }
+
+
+ } else {
+ System.out.println("Database Connect Failed.");
+ }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return ignoreDay;
+ }
+
+ private static void sendNoti(String msg)
+ {
+
+ try {
+
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost postRequest = new HttpPost("https://notify-api.line.me/api/notify");
+ // StringEntity input = new StringEntity(msg,"UTF-8");
+ ArrayList form = new ArrayList();
+ form.add(new BasicNameValuePair("message", msg));
+ UrlEncodedFormEntity input = new UrlEncodedFormEntity(form, Consts.UTF_8);
+
+ input.setContentType("application/json;charset=UTF-8");
+ postRequest.setEntity(input);
+ input.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
+ postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
+ postRequest.setHeader("Authorization", "Bearer " + Token);
+ postRequest.setHeader("Accept", "application/json");
+ postRequest.setEntity(input);
+
+ HttpResponse response = httpClient.execute(postRequest);
+
+ BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
+
+ String output;
+
+ while ((output = br.readLine()) != null) {
+ System.out.println(output);
+ }
+
+ httpClient.getConnectionManager().shutdown();
+
+ } catch (MalformedURLException e) {
+
+ e.printStackTrace();
+
+ } catch (IOException e) {
+
+ e.printStackTrace();
+
+ }
+
+ }
+
+ private static String getCurrentTimeStamp(String format) {
+ // "MM/dd HH:mm"
+ SimpleDateFormat sdfDate = new SimpleDateFormat(format);// dd/MM/yyyy
+ Date now = new Date();
+ String strDate = sdfDate.format(now);
+ return strDate;
+ }
+}
diff --git a/src/main/java/obj/DevInfo.java b/src/main/java/obj/DevInfo.java
new file mode 100644
index 0000000..3f3ac59
--- /dev/null
+++ b/src/main/java/obj/DevInfo.java
@@ -0,0 +1,25 @@
+package obj;
+
+import java.util.HashSet;
+
+public class DevInfo {
+
+ public String name;
+ public HashSet days;
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public HashSet getDays() {
+ return days;
+ }
+ public void setDays(HashSet days) {
+ this.days = days;
+ }
+
+
+
+}
diff --git a/src/test/java/bas/sourcecode/DevCalendar/AppTest.java b/src/test/java/bas/sourcecode/DevCalendar/AppTest.java
new file mode 100644
index 0000000..ceb6b04
--- /dev/null
+++ b/src/test/java/bas/sourcecode/DevCalendar/AppTest.java
@@ -0,0 +1,38 @@
+package bas.sourcecode.DevCalendar;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9a31738
--- /dev/null
+++ b/target/classes/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: SourceCode
+Build-Jdk: 1.8.0_161
+Created-By: Maven Integration for Eclipse
+
diff --git a/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.properties b/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.properties
new file mode 100644
index 0000000..6d20cc4
--- /dev/null
+++ b/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.properties
@@ -0,0 +1,7 @@
+#Generated by Maven Integration for Eclipse
+#Thu Mar 15 14:21:23 ICT 2018
+version=0.0.1-SNAPSHOT
+groupId=bas.sourcecode
+m2e.projectName=DevCalendar
+m2e.projectLocation=C\:\\myWork\\eclipseCode\\DevCalendar
+artifactId=DevCalendar
diff --git a/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.xml b/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.xml
new file mode 100644
index 0000000..292bd59
--- /dev/null
+++ b/target/classes/META-INF/maven/bas.sourcecode/DevCalendar/pom.xml
@@ -0,0 +1,38 @@
+
+ 4.0.0
+
+ bas.sourcecode
+ DevCalendar
+ 0.0.1-SNAPSHOT
+ jar
+
+ DevCalendar
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.8-dmr
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.4
+
+
+
+
diff --git a/target/classes/bas/sourcecode/DevCalendar/App.class b/target/classes/bas/sourcecode/DevCalendar/App.class
new file mode 100644
index 0000000..c958bf9
Binary files /dev/null and b/target/classes/bas/sourcecode/DevCalendar/App.class differ
diff --git a/target/classes/obj/DevInfo.class b/target/classes/obj/DevInfo.class
new file mode 100644
index 0000000..64d8dd6
Binary files /dev/null and b/target/classes/obj/DevInfo.class differ
diff --git a/target/test-classes/bas/sourcecode/DevCalendar/AppTest.class b/target/test-classes/bas/sourcecode/DevCalendar/AppTest.class
new file mode 100644
index 0000000..994e55c
Binary files /dev/null and b/target/test-classes/bas/sourcecode/DevCalendar/AppTest.class differ
--
libgit2 0.21.2