diff --git a/src/main/java/demo/dailyDemo.java b/src/main/java/demo/dailyDemo.java deleted file mode 100644 index 0046fee..0000000 --- a/src/main/java/demo/dailyDemo.java +++ /dev/null @@ -1,93 +0,0 @@ -package demo; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import mail.Mail; -import org.springframework.web.client.RestTemplate; -import utils.DateTimeUtils; - -import java.io.Serializable; -import java.sql.Timestamp; -import java.time.LocalDate; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author fuhouyin - * @time 2023/3/1 16:11 - * 日报 - */ -public class dailyDemo { - - public static void main(String[] args) throws Exception{ - Mail.sendMail("发件邮箱","密钥","收件邮箱","标题",html()); - } - - /**发薪日*/ - public static String salDay() throws Exception { - - Calendar c1 = Calendar.getInstance(); - c1.add(Calendar.MONTH, 0); - c1.set(Calendar.DAY_OF_MONTH, 15); - c1.set(Calendar.HOUR_OF_DAY, 23); - c1.set(Calendar.MINUTE, 0); - c1.set(Calendar.SECOND,0); - c1.set(Calendar.MILLISECOND, 0); - - Calendar c2 = Calendar.getInstance(); - c2.add(Calendar.MONTH, 1); - c2.set(Calendar.DAY_OF_MONTH, 15); - c2.set(Calendar.HOUR_OF_DAY, 23); - c2.set(Calendar.MINUTE, 0); - c2.set(Calendar.SECOND,0); - c2.set(Calendar.MILLISECOND, 0); - - Date toDay = new Date().after(c1.getTime()) ? c2.getTime() : c1.getTime(); - int days = DateTimeUtils.daysBetween(new Date(), toDay); - - String msg = "【距离发薪日】:还有"+days+"天"; - - return msg; - } - - /**获取tophub热门数据*/ - public static List news(){ - String url = "https://open.tophub.today/hot"; - JSONArray ja = new RestTemplate().getForObject(url, JSONObject.class).getJSONObject("data").getJSONArray("items"); - List ls = JSONObject.parseArray(ja.toJSONString(),news.class); - return ls; - } - - @Data - public class news implements Serializable { - String title; //标题 - String description; //简介 - String thumbnail; //头图 - String url; //链接 - String extra; //热度 - Timestamp time; //时间 不准 - String logo; - } - - /**组装html*/ - public static String html() throws Exception{ - - LocalDate ld = LocalDate.now(); - - String str = "\n\n\n\n\n\n"; - str += "

"+ld.getYear()+"-"+ld.getMonthValue()+"-"+ld.getDayOfMonth()+"日报

\n"; - str += "

"+salDay()+"

\n"; - String ls = news().stream().limit(30).map(e->{ - String s = ""; - s += "
  • "+e.getTitle()+"

  • \n"; - return s; - }).collect(Collectors.joining()); - str += "
    \n
      \n"+ls+"\n
    \n
    \n"; - str += "\n"; - - return str; - } -} diff --git a/src/main/java/utils/FileUtils.java b/src/main/java/utils/FileUtils.java index eb2b262..c6730c7 100644 --- a/src/main/java/utils/FileUtils.java +++ b/src/main/java/utils/FileUtils.java @@ -70,7 +70,7 @@ public class FileUtils { * @param input 输入流 * @throws IOException */ - private static void writeToLocal(String destination, InputStream input) + public static void writeToLocal(String destination, InputStream input) throws IOException { int index; byte[] bytes = new byte[1024];