Skip to content

Commit

Permalink
2017年7月15日 13:01:19
Browse files Browse the repository at this point in the history
  • Loading branch information
lorcx committed Jul 15, 2017
1 parent c70aaf7 commit ede72d4
Show file tree
Hide file tree
Showing 27 changed files with 738 additions and 0 deletions.
72 changes: 72 additions & 0 deletions students/740707954/src/main/java/payroll/Employee.java
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;
}
}
40 changes: 40 additions & 0 deletions students/740707954/src/main/java/payroll/PayCheck.java
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;
}
}
30 changes: 30 additions & 0 deletions students/740707954/src/main/java/payroll/PaySystem.java
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);
}
}
}
}
19 changes: 19 additions & 0 deletions students/740707954/src/main/java/payroll/TimeCard.java
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;
}
}
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);
}
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;
}
}
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;
}
}
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();
// }


}
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;
}
}
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;
}
}
}
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);
}
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;
}
}
Loading

0 comments on commit ede72d4

Please sign in to comment.