Commit eefc3b0e by shj

差旅费增删改完成,代码重构

parent cf8dd7ca
......@@ -21,15 +21,6 @@ public class Travel extends Item {
return getPrice() + getFood() + getAccommodation() + getTraffic();
}
@Override
public String getName() {
return getDest();
}
@Override
public void setName(String name) {
setDest(name);
}
@Override
public String toString() {
......@@ -42,11 +33,11 @@ public class Travel extends Item {
}
public String getDest() {
return dest;
return getName();
}
public void setDest(String dest) {
this.dest = dest;
setName(dest);
}
public double getFood() {
......
......@@ -72,15 +72,16 @@ public class DetailHandler {
sub.put("sum",sum);
sub.put("diff",req-sum);
object.put("equipment",sub);
req_sofar+=req;sum_sofar+=sum;
sub=new JSONObject();
req=budget.getRequirement().getEquip();
sum=detailService.sumEquipment(budget.getEquipments());
req=budget.getRequirement().getTravel();
sum=detailService.sumTravel(budget.getTravels());
sub.put("req",req);
sub.put("sum",sum);
sub.put("diff",req-sum);
object.put("travel",sub);
req_sofar+=req;sum_sofar+=sum;
object.put("req",req_sofar);
object.put("sum",sum_sofar);
......
package service;
import beans.Equipment;
import beans.Pair;
import beans.Travel;
import java.util.Map;
public interface IDetailService {
double sumEquipment(Map<Equipment, Integer> equipments);
double sumTravel(Map<Travel, Pair> travels);
}
......@@ -10,6 +10,8 @@ import service.ICheckService;
public class CheckService implements ICheckService {
@Override
public boolean checkEquipment(Equipment equipment) {
if(equipment==null
|| equipment.getName()==null) return false;
return true;
}
......
package service.impl;
import beans.Equipment;
import beans.Pair;
import beans.Travel;
import org.springframework.stereotype.Service;
import service.IDetailService;
......@@ -16,4 +18,13 @@ public class DetailService implements IDetailService {
}
return sum;
}
@Override
public double sumTravel(Map<Travel, Pair> travels) {
double sum=0.0;
for (Travel travel : travels.keySet()) {
sum+=travel.cost(travels.get(travel));
}
return sum;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment