forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
738 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package payroll; | ||
|
||
import payroll.affiliation.Affiliation; | ||
import payroll.classify.PaymentClassification; | ||
import payroll.method.PaymentMethod; | ||
import payroll.schedule.PaymentSchedule; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 员工 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class Employee { | ||
private String id; | ||
private String name; | ||
private String address; | ||
private Affiliation affiliation; | ||
|
||
private PaymentClassification classification; | ||
private PaymentSchedule schedule; | ||
private PaymentMethod paymentMethod; | ||
|
||
public Employee(String name, String address) { | ||
this.name = name; | ||
this.address = address; | ||
} | ||
|
||
/** | ||
* 计算员工薪水 | ||
* @param pc | ||
*/ | ||
public void calculatePay(PayCheck pc) { | ||
double grossPay = classification.calculdatePay(pc); | ||
double deductions = affiliation.calculateDeductions(pc); | ||
double netPay = grossPay - deductions; | ||
pc.setGrossPay(grossPay); | ||
pc.setDeductions(deductions); | ||
pc.setNetPay(netPay); | ||
paymentMethod.pay(pc); | ||
} | ||
|
||
/** | ||
* 是否为支付日 | ||
* @param d | ||
* @return | ||
*/ | ||
public boolean isPayDay(Date d) { | ||
return schedule.isPayDate(d); | ||
} | ||
|
||
/** | ||
* 获取支付的起始时间 | ||
* @param d | ||
* @return | ||
*/ | ||
public Date getPayPeriodStartDate(Date d) { | ||
return schedule.getPayPeriodStartDate(d); | ||
} | ||
|
||
public void setClassifcation(PaymentClassification classifcation) { | ||
this.classification = classifcation; | ||
} | ||
|
||
public void setSchedule(PaymentSchedule schedule) { | ||
this.schedule = schedule; | ||
} | ||
|
||
public void setPaymentMethod(PaymentMethod paymentMethod) { | ||
this.paymentMethod = paymentMethod; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package payroll; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 可以检查是否重复执行 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class PayCheck { | ||
private Date payPeriodStart; | ||
private Date payPeriodEnd; | ||
private double grossPay;// 应付 | ||
private double netPay;// 实付 | ||
private double deductions;// 扣除 | ||
|
||
public PayCheck(Date payPeriodStart, Date payPeriodEnd) { | ||
this.payPeriodStart = payPeriodStart; | ||
this.payPeriodEnd = payPeriodEnd; | ||
} | ||
|
||
public Date getPayPeriodEnd() { | ||
return payPeriodEnd; | ||
} | ||
|
||
public Date getPayPeriodStart() { | ||
return payPeriodStart; | ||
} | ||
|
||
public void setGrossPay(double grossPay) { | ||
this.grossPay = grossPay; | ||
} | ||
|
||
public void setNetPay(double netPay) { | ||
this.netPay = netPay; | ||
} | ||
|
||
public void setDeductions(double deductions) { | ||
this.deductions = deductions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package payroll; | ||
|
||
import payroll.service.IPayrollService; | ||
import payroll.service.PayrollServiceImpl; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* 薪水支付系统 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class PaySystem { | ||
private static IPayrollService payrollService; | ||
|
||
static { | ||
payrollService = new PayrollServiceImpl(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
Date date = new Date(); | ||
List<Employee> employees = payrollService.getAllEmployees(); | ||
for (Employee e : employees) { | ||
if (e.isPayDay(date)) { | ||
PayCheck pc = new PayCheck(e.getPayPeriodStartDate(date), date); | ||
e.calculatePay(pc); | ||
payrollService.savePaycheck(pc); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package payroll; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class TimeCard { | ||
private Date date; | ||
private int hours; | ||
|
||
public Date getDate(){ | ||
return date; | ||
} | ||
|
||
public int getHours() { | ||
return hours; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
students/740707954/src/main/java/payroll/affiliation/Affiliation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package payroll.affiliation; | ||
|
||
import payroll.PayCheck; | ||
|
||
/** | ||
* Affiliation 会员 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public interface Affiliation { | ||
|
||
/** | ||
* 计算服务费 | ||
* @param pc | ||
* @return | ||
*/ | ||
double calculateDeductions(PayCheck pc); | ||
} |
14 changes: 14 additions & 0 deletions
14
students/740707954/src/main/java/payroll/affiliation/NonAffiliation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package payroll.affiliation; | ||
|
||
import payroll.PayCheck; | ||
|
||
/** | ||
* 非会员 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class NonAffiliation implements Affiliation { | ||
@Override | ||
public double calculateDeductions(PayCheck pc) { | ||
return 0; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
students/740707954/src/main/java/payroll/affiliation/ServiceCharge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package payroll.affiliation; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 服务费用 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class ServiceCharge { | ||
private Date date; | ||
private double amount; | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Date date) { | ||
this.date = date; | ||
} | ||
|
||
public double getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(double amount) { | ||
this.amount = amount; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
students/740707954/src/main/java/payroll/affiliation/UnionAffiliation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package payroll.affiliation; | ||
|
||
import payroll.PayCheck; | ||
import payroll.util.DateUtil; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* 会员 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class UnionAffiliation implements Affiliation { | ||
private int memeberId = 0; | ||
private double weekDue = 0; | ||
private Map<Date, ServiceCharge> charege; | ||
|
||
/** | ||
* 计算服务费用 | ||
* @param pc | ||
* @return | ||
*/ | ||
@Override | ||
public double calculateDeductions(PayCheck pc) { | ||
int fridays = DateUtil.getFridaysBetween(pc.getPayPeriodStart(), pc.getPayPeriodEnd()); | ||
double totalDue = fridays * weekDue; | ||
double totalCharge = 0.0d; | ||
for (Map.Entry<Date, ServiceCharge> entry : charege.entrySet()) { | ||
ServiceCharge sc = entry.getValue(); | ||
totalCharge += sc.getAmount(); | ||
// calculateCharge(sc); | ||
} | ||
return totalCharge + totalDue; | ||
} | ||
|
||
// private double calculateCharge(ServiceCharge sc) { | ||
// return sc.getAmount(); | ||
// } | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
students/740707954/src/main/java/payroll/classify/CommissionClassification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package payroll.classify; | ||
|
||
import payroll.PayCheck; | ||
import payroll.util.DateUtil; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* 佣金雇员 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class CommissionClassification implements PaymentClassification { | ||
private Map<Date, SalesReceipt> salesReceipt;// 销售凭条 | ||
private double salary;//薪水 | ||
private double rate;//单价 | ||
|
||
/** | ||
* 计算薪水 | ||
* @param pc | ||
* @return | ||
*/ | ||
@Override | ||
public double calculdatePay(PayCheck pc) { | ||
//1 统计销售凭条在pc.getStartDate 和 pc.getEndDate之间 | ||
//2 加上基本工资,计算薪水 | ||
double commission = 0.0d; | ||
for (Map.Entry<Date, SalesReceipt> entry : salesReceipt.entrySet()) { | ||
SalesReceipt receipt = entry.getValue(); | ||
if (DateUtil.between(receipt.getDate(), pc.getPayPeriodStart(), pc.getPayPeriodEnd())) { | ||
commission = receipt.getAmount() * rate; | ||
} | ||
} | ||
return commission + salary; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
students/740707954/src/main/java/payroll/classify/HourlyClassification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package payroll.classify; | ||
|
||
import payroll.PayCheck; | ||
import payroll.util.DateUtil; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* 小时工 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class HourlyClassification implements PaymentClassification { | ||
private Map<Date, TimeCard> timeCards; | ||
private double rate;// 价格 | ||
|
||
/** | ||
* 统计时间卡在pc.getStartDate 和 pc.getEndDate之间 | ||
* 并计算薪水 | ||
* | ||
* @param pc | ||
* @return | ||
*/ | ||
@Override | ||
public double calculdatePay(PayCheck pc) { | ||
double totalPay = 0.0d; | ||
for (Map.Entry<Date, TimeCard> entry : timeCards.entrySet()) { | ||
TimeCard tc = entry.getValue(); | ||
if (DateUtil.between(tc.getDate(), pc.getPayPeriodStart(), pc.getPayPeriodEnd())) { | ||
totalPay += calculatePayForTimeCard(tc); | ||
} | ||
} | ||
return totalPay; | ||
} | ||
|
||
/** | ||
* 计算每个时间卡的薪水 | ||
* | ||
* @param tc | ||
* @return | ||
*/ | ||
public double calculatePayForTimeCard(TimeCard tc) { | ||
int hours = tc.getHours(); | ||
if (tc.getHours() > 8) { | ||
return 8 * rate + (hours - 8) * 1.5 * rate; | ||
} else { | ||
return 8 * rate; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
students/740707954/src/main/java/payroll/classify/PaymentClassification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package payroll.classify; | ||
|
||
import payroll.PayCheck; | ||
|
||
/** | ||
* 分类 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public interface PaymentClassification { | ||
public double calculdatePay(PayCheck pc); | ||
} |
21 changes: 21 additions & 0 deletions
21
students/740707954/src/main/java/payroll/classify/SalariedClassification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package payroll.classify; | ||
|
||
import payroll.PayCheck; | ||
|
||
/** | ||
* 月薪雇员 | ||
* Created by lx on 2017/7/8. | ||
*/ | ||
public class SalariedClassification implements PaymentClassification { | ||
private double salary; | ||
|
||
/** | ||
* 计算支付 | ||
* @param pc | ||
* @return | ||
*/ | ||
@Override | ||
public double calculdatePay(PayCheck pc) { | ||
return salary; | ||
} | ||
} |
Oops, something went wrong.