Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coding2017
Submodule coding2017 added at bdbfcf
32 changes: 32 additions & 0 deletions students/862726639/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.coderising</groupId>
<artifactId>ood-assignment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ood-assignment</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

</dependencies>
<repositories>
<repository>
<id>aliyunmaven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
145 changes: 145 additions & 0 deletions students/862726639/src/main/java/com/coderising/ood/srp/Email.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.coderising.ood.srp;

import java.io.IOException;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
/**
* 只提交发送邮件的功能,主邮箱,备用邮箱需要赋予
* @author gaohuan
*
*/
public class Email {
public static final String ENCODEING = "UTF-8";

private String host; // 服务器地址

private String sender; // 发件人的邮箱

private String receiver; // 收件人的邮箱

private String name; // 发件人昵称

private String username; // 账号

private String password; // 密码

private String subject; // 主题

private String message; // 信息(支持HTML)

public boolean send2(Email mail) {
if ("".equals(mail.getReceiver())&&null == mail.getReceiver()) {
return false;
}
System.out.println("开始发送邮件");
// 发送email
HtmlEmail email = new HtmlEmail();
try {
// 这里是SMTP发送服务器的名字:163的如下:"smtp.163.com"
email.setHostName(mail.getHost());
// 字符编码集的设置
email.setCharset("utf-8");
// 收件人的邮箱
email.addTo(mail.getReceiver());
// 发送人的邮箱
email.setFrom(mail.getSender(), mail.getName());
// 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码
email.setAuthentication(mail.getUsername(), mail.getPassword());
// 要发送的邮件主题
email.setSubject(mail.getSubject());
// 要发送的信息,由于使用了HtmlEmail,可以在邮件内容中使用HTML标签
email.setMsg(mail.getMessage());
// 发送
email.send();
System.out.println(mail.getSender() + " 发送邮件到 " + mail.getReceiver());
return true;
} catch (EmailException e) {
e.printStackTrace();
System.out.println(mail.getSender() + " 发送邮件到 " + mail.getReceiver()
+ " 失败");
return false;
}
}


public String getHost() {
return host;
}


public void setHost(String host) {
this.host = host;
}


public String getSender() {
return sender;
}


public void setSender(String sender) {
this.sender = sender;
}


public String getReceiver() {
return receiver;
}


public void setReceiver(String receiver) {
this.receiver = receiver;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getUsername() {
return username;
}


public void setUsername(String username) {
this.username = username;
}


public String getPassword() {
return password;
}


public void setPassword(String password) {
this.password = password;
}


public String getSubject() {
return subject;
}


public void setSubject(String subject) {
this.subject = subject;
}


public String getMessage() {
return message;
}


public void setMessage(String message) {
this.message = message;
}


}
79 changes: 79 additions & 0 deletions students/862726639/src/main/java/com/coderising/ood/srp/Goods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.coderising.ood.srp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
/**
* 这个类的作用只是用于获取资源文件中的降价商品
* @author gaohuan
*
*/
public class Goods {
private String productID;
private String productDesc;

/**
* 获得降价
* @return
* @throws IOException
*/
@SuppressWarnings("finally")
public ArrayList<Goods> getSaleGoods() throws IOException {
ArrayList<Goods> goodsList = new ArrayList<Goods>();
File file = new File("src\\main\\java\\com\\coderising\\ood\\srp\\product_promotion.txt");
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String temp = br.readLine();
String[] data = temp.split(" ");
Goods goods = new Goods(data[0], data[1]);
goodsList.add(goods);
System.out.println("产品ID = " + goods.getProductID() + "\n");
System.out.println("产品描述 = " + goods.getProductDesc() + "\n");

} catch (Exception e) {
e.printStackTrace();
} finally {
br.close();
return goodsList;
}
}

public String getProductID() {
return productID;
}

public void setProductID(String productID) {
this.productID = productID;
}

public String getProductDesc() {
return productDesc;
}

public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}

public Goods() {
super();
}

public Goods(String productID, String productDesc) {
super();
this.productID = productID;
this.productDesc = productDesc;
}










}
35 changes: 35 additions & 0 deletions students/862726639/src/main/java/com/coderising/ood/srp/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.coderising.ood.srp;

import java.io.IOException;
import java.util.ArrayList;

import org.junit.Test;

public class Main {
//发送邮件
@Test
public void test() throws Exception{
//获得降价商品
Goods goods = new Goods();
ArrayList<Goods> saleGoods = goods.getSaleGoods();
//获得对应用户
for (Goods goods2 : saleGoods) {
User user = new User();
ArrayList<User> userById = user.getUserById(goods2.getProductID());
for (User user2 : userById) {
//发送邮件
Email email = new Email();
email.setHost("smtp.163.com"); // 设置邮件服务器,如果不用163的,自己找找看相关的
email.setSender("15237140070@163.com");
email.setReceiver(user2.getEmail()); // 接收人
email.setUsername("15237140070@163.com"); // 登录账号,一般都是和邮箱名一样吧
email.setPassword("sudan521"); // 发件人邮箱的登录密码
email.setSubject("降价了降价了");
email.setMessage(Message.saleMessage(user2.getName(), goods2.getProductDesc())+"");
email.send2(email);

}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coderising.ood.srp;

public class Message {

public static StringBuilder saleMessage(String userName ,String goodsName){
StringBuilder buffer = new StringBuilder();
buffer.append("Subject:").append("您关注的产品降价了").append("\n");
buffer.append("Content:").append("尊敬的 "+userName+", 您关注的产品 " + goodsName + " 降价了,欢迎购买!").append("\n");
return buffer;
}

}
53 changes: 53 additions & 0 deletions students/862726639/src/main/java/com/coderising/ood/srp/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.coderising.ood.srp;

import java.util.ArrayList;
public class User {
private String name;
private String email;


/**
* 通过降价商品的id 获取需要返回的用户
* @param productID
* @return
*/
public ArrayList<User> getUserById(String productID){
ArrayList<User> userList = new ArrayList<User>();
userList.add(new User("高欢1","15582372277@163.com"));
userList.add(new User("高欢2"));
userList.add(new User("高欢3"));
return userList;
}

public User(String name, String email) {
super();
this.name = name;
this.email = email;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
public User(String name) {
super();
this.name = name;
}

public User() {
super();
// TODO Auto-generated constructor stub
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
P8756 iPhone8
P3946 XiaoMi10
P8904 Oppo_R15
P4955 Vivo_X20