Skip to content

Commit df54909

Browse files
committed
[Feature] 支付方式和发薪日 done
1 parent 5d54986 commit df54909

File tree

12 files changed

+184
-19
lines changed

12 files changed

+184
-19
lines changed

students/812350401/src/main/java/com/coderising/myood/payroll/my_payroll/database/EmployeeTable.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ public EmployeeTable() {
1313

1414
public static class EmployeeBuilder {
1515
private Map<String, Object> row;
16-
private int id;
17-
private String name;
18-
private String address;
19-
private String emp_type; // "0": salary, "1": hourly, "2": commission
20-
private double hourly_rate;
21-
private double salary;
22-
private double base_salary; // commission base salary
23-
private double commission_rate;
24-
private String schedule_type; // "0": monthly, "1": weekly, "2": double weekly
25-
private String payment_type; // "0": post office, "1": hold, "2": bank
2616

2717
@Override
2818
public String toString() {
@@ -48,6 +38,11 @@ public EmployeeBuilder address(String address) {
4838
return this;
4939
}
5040

41+
/**
42+
* 员工类型
43+
* @param emp_type "0": salary, "1": hourly, "2": commission
44+
* @return
45+
*/
5146
public EmployeeBuilder emp_type(String emp_type) {
5247
row.put("emp_type", emp_type);
5348
return this;
@@ -63,6 +58,11 @@ public EmployeeBuilder salary(double salary) {
6358
return this;
6459
}
6560

61+
/**
62+
* 销售底薪
63+
* @param base_salary commission base salary
64+
* @return
65+
*/
6666
public EmployeeBuilder base_salary(double base_salary) {
6767
row.put("base_salary", base_salary);
6868
return this;
@@ -73,11 +73,21 @@ public EmployeeBuilder commission_rate(double commission_rate) {
7373
return this;
7474
}
7575

76+
/**
77+
* 发薪日类型
78+
* @param schedule_type "0": monthly, "1": weekly, "2": double weekly
79+
* @return
80+
*/
7681
public EmployeeBuilder schedule_type(String schedule_type) {
7782
row.put("schedule_type", schedule_type);
7883
return this;
7984
}
8085

86+
/**
87+
* 支付方式类型
88+
* @param payment_type "0": post office, "1": hold, "2": bank
89+
* @return
90+
*/
8191
public EmployeeBuilder payment_type(String payment_type) {
8292
row.put("payment_type", payment_type);
8393
return this;

students/812350401/src/main/java/com/coderising/myood/payroll/my_payroll/domain/Paycheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public class Paycheck {
1010
private double deductions;
1111
private int employeeId;
1212

13-
public Paycheck(Date payPeriodStart, Date payPeriodEnd){
13+
public Paycheck(int employeeId, Date payPeriodStart, Date payPeriodEnd){
1414
this.payPeriodStart = payPeriodStart;
1515
this.payPeriodEnd = payPeriodEnd;
16+
this.employeeId = employeeId;
1617
}
1718

1819
public Date getPayPeriodStart() {

students/812350401/src/main/java/com/coderising/myood/payroll/my_payroll/paymentclassification/HourlyClassification.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.coderising.myood.payroll.my_payroll.domain.PaymentClassification;
55
import com.coderising.myood.payroll.my_payroll.util.DateUtil;
66

7-
import java.util.DoubleSummaryStatistics;
87
import java.util.LinkedList;
98
import java.util.List;
109

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.myood.payroll.my_payroll.paymentmethod;
2+
3+
import com.coderising.myood.payroll.my_payroll.domain.Paycheck;
4+
import com.coderising.myood.payroll.my_payroll.domain.PaymentMethod;
5+
6+
import java.text.SimpleDateFormat;
7+
8+
/**
9+
* Created by thomas_young on 16/9/2017.
10+
*/
11+
public class BankMethod implements PaymentMethod {
12+
@Override
13+
public void pay(Paycheck pc) {
14+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
15+
StringBuilder desp = new StringBuilder();
16+
desp.append("银行入账:\n")
17+
.append("employee_id: ").append(pc.getEmployeeId())
18+
.append(", 金额: ").append(pc.getNetPay())
19+
.append(", 区间: ").append(sdf.format(pc.getPayPeriodStart()))
20+
.append("~").append(sdf.format(pc.getPayPeriodEnd()));
21+
System.out.println(desp.toString());
22+
}
23+
}

students/812350401/src/main/java/com/coderising/myood/payroll/my_payroll/paymentmethod/HoldMethod.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import com.coderising.myood.payroll.my_payroll.domain.Paycheck;
44
import com.coderising.myood.payroll.my_payroll.domain.PaymentMethod;
55

6+
import java.text.SimpleDateFormat;
7+
68
/**
79
* Created by thomas_young on 16/9/2017.
810
* 把钱发到财务那里,所示支取
911
*/
1012
public class HoldMethod implements PaymentMethod {
1113
@Override
1214
public void pay(Paycheck pc) {
15+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
1316
StringBuilder desp = new StringBuilder();
1417
desp.append("财务入账:\n")
1518
.append("employee_id: ").append(pc.getEmployeeId())
16-
.append(", 金额: ").append(pc.getNetPay())
17-
.append(", 区间: ").append(pc.getPayPeriodStart())
19+
.append(", 金额: ").append(sdf.format(pc.getNetPay()))
20+
.append(", 区间: ").append(sdf.format(pc.getPayPeriodStart()))
1821
.append("~").append(pc.getPayPeriodEnd());
1922
System.out.println(desp.toString());
2023
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.myood.payroll.my_payroll.paymentmethod;
2+
3+
import com.coderising.myood.payroll.my_payroll.domain.Paycheck;
4+
import com.coderising.myood.payroll.my_payroll.domain.PaymentMethod;
5+
6+
import java.text.SimpleDateFormat;
7+
8+
/**
9+
* Created by thomas_young on 16/9/2017.
10+
*/
11+
public class PostOfficeMethod implements PaymentMethod {
12+
@Override
13+
public void pay(Paycheck pc) {
14+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
15+
StringBuilder desp = new StringBuilder();
16+
desp.append("邮局入账:\n")
17+
.append("employee_id: ").append(pc.getEmployeeId())
18+
.append(", 金额: ").append(sdf.format(pc.getNetPay()))
19+
.append(", 区间: ").append(sdf.format(pc.getPayPeriodStart()))
20+
.append("~").append(pc.getPayPeriodEnd());
21+
System.out.println(desp.toString());
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.myood.payroll.my_payroll.paymentschedule;
2+
3+
import com.coderising.myood.payroll.liuxin_payroll.util.DateUtil;
4+
import com.coderising.myood.payroll.my_payroll.domain.PaymentSchedule;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* Created by thomas_young on 16/9/2017.
10+
*/
11+
public class BiWeeklySchedule implements PaymentSchedule {
12+
private static Date FIRST_PAYABLE_FRIDAY = DateUtil.parseDate("2017-6-2");
13+
@Override
14+
public boolean isPayDate(Date date) {
15+
long interval = DateUtil.getDaysBetween(FIRST_PAYABLE_FRIDAY, date);
16+
return interval % 14 == 0;
17+
}
18+
19+
@Override
20+
public Date getPayPeriodStartDate(Date payPeriodEndDate) {
21+
return DateUtil.add(payPeriodEndDate, -13);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.coderising.myood.payroll.my_payroll.paymentschedule;
2+
3+
import com.coderising.myood.payroll.my_payroll.domain.PaymentSchedule;
4+
import com.coderising.myood.payroll.my_payroll.util.DateUtil;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* Created by thomas_young on 16/9/2017.
10+
*/
11+
public class WeeklySchedule implements PaymentSchedule {
12+
@Override
13+
public boolean isPayDate(Date date) {
14+
return DateUtil.isFriday(date);
15+
}
16+
17+
@Override
18+
public Date getPayPeriodStartDate(Date payPeriodEndDate) {
19+
return DateUtil.add(payPeriodEndDate, -6);
20+
}
21+
}

students/812350401/src/main/java/com/coderising/myood/payroll/my_payroll/util/DateUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public static Date parseDate(String txtDate){
2121
}
2222
}
2323
public static boolean isFriday(Date d){
24-
Calendar calendar = Calendar.getInstance();
25-
return calendar.get(Calendar.DAY_OF_WEEK) == 5;
24+
Calendar calendar = Calendar.getInstance();
25+
calendar.setTime(d);
26+
return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY;
2627
}
2728

2829
public static Date add(Date d, int days){
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.coderising.myood.payroll.my_payroll.domain;
2+
3+
import com.coderising.myood.payroll.my_payroll.paymentmethod.BankMethod;
4+
import com.coderising.myood.payroll.my_payroll.util.DateUtil;
5+
import org.junit.Test;
6+
7+
8+
/**
9+
* Created by thomas_young on 16/9/2017.
10+
*/
11+
public class PaymentMethodTest {
12+
@Test
13+
public void testBankPay() throws Exception {
14+
PaymentMethod bp = new BankMethod();
15+
Paycheck pc = new Paycheck(1, DateUtil.parseDate("2017-06-13"), DateUtil.parseDate("2017-06-20"));
16+
bp.pay(pc);
17+
}
18+
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.coderising.myood.payroll.my_payroll.domain;
2+
3+
import com.coderising.myood.payroll.my_payroll.paymentschedule.BiWeeklySchedule;
4+
import com.coderising.myood.payroll.my_payroll.paymentschedule.MonthlySchedule;
5+
import com.coderising.myood.payroll.my_payroll.paymentschedule.WeeklySchedule;
6+
import com.coderising.myood.payroll.my_payroll.util.DateUtil;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
/**
11+
* Created by thomas_young on 16/9/2017.
12+
*/
13+
public class PaymentScheduleTest {
14+
@Test
15+
public void testMonthlySchedule() throws Exception {
16+
PaymentSchedule ms = new MonthlySchedule();
17+
Assert.assertTrue(ms.isPayDate(DateUtil.parseDate("2017-06-30")));
18+
Assert.assertTrue(!ms.isPayDate(DateUtil.parseDate("2017-06-29")));
19+
Assert.assertEquals(DateUtil.parseDate("2017-06-01"),
20+
ms.getPayPeriodStartDate(ms.getPayPeriodStartDate(DateUtil.parseDate("2017-06-15"))));
21+
}
22+
23+
@Test
24+
public void testBiWeeklySchedule() {
25+
PaymentSchedule bs = new BiWeeklySchedule();
26+
Assert.assertTrue(bs.isPayDate(DateUtil.parseDate("2017-06-16")));
27+
Assert.assertTrue(!bs.isPayDate(DateUtil.parseDate("2017-06-09")));
28+
Assert.assertEquals(DateUtil.parseDate("2017-06-03"),
29+
bs.getPayPeriodStartDate(DateUtil.parseDate("2017-06-16")));
30+
}
31+
32+
@Test
33+
public void testWeeklySchedule() {
34+
PaymentSchedule ps = new WeeklySchedule();
35+
Assert.assertTrue(ps.isPayDate(DateUtil.parseDate("2017-06-16")));
36+
Assert.assertTrue(ps.isPayDate(DateUtil.parseDate("2017-06-09")));
37+
Assert.assertTrue(!ps.isPayDate(DateUtil.parseDate("2017-06-17")));
38+
Assert.assertEquals(DateUtil.parseDate("2017-06-10"),
39+
ps.getPayPeriodStartDate(DateUtil.parseDate("2017-06-16")));
40+
41+
}
42+
}

students/812350401/src/test/com/coderising/myood/payroll/my_payroll/paymentclassification/PaymentClassificationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PaymentClassificationTest {
1414
@Test
1515
public void hourlyCalculatePay1() throws Exception {
1616
HourlyClassification hc = new HourlyClassification(100);
17-
Paycheck pc = new Paycheck(DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
17+
Paycheck pc = new Paycheck(1, DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
1818
TimeCard t1 = new TimeCard("2017-06-12", 4);
1919
TimeCard t2 = new TimeCard("2017-06-15", 10);
2020
hc.addTimeCard(t1);
@@ -26,7 +26,7 @@ public void hourlyCalculatePay1() throws Exception {
2626
@Test
2727
public void hourlyCalculatePay2() throws Exception {
2828
PaymentClassification hc = new HourlyClassification(100);
29-
Paycheck pc = new Paycheck(DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
29+
Paycheck pc = new Paycheck(1, DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
3030
TimeCard t1 = new TimeCard("2017-06-13", 4);
3131
TimeCard t2 = new TimeCard("2017-06-15", 10);
3232
((HourlyClassification) hc).addTimeCard(t1);
@@ -45,7 +45,7 @@ public void salariedCalculatePay() {
4545
@Test
4646
public void commissionCalculatePay() {
4747
PaymentClassification cc = new CommissionClassification(2000d, 0.1);
48-
Paycheck pc = new Paycheck(DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
48+
Paycheck pc = new Paycheck(1, DateUtil.parseDate("2017-06-12"), DateUtil.parseDate("2017-07-12"));
4949

5050
double pay = cc.calculatePay(pc);
5151
Assert.assertEquals(2000d, pay, TOLERANCE);

0 commit comments

Comments
 (0)