Commit 7c4b42bb by shj

差旅费结构、显示、增删改优化

parent 43b56536
......@@ -14,7 +14,8 @@ public class Budget implements Serializable {
private Map<Material, Integer> materials;
private Map<TestAndProcess, Integer> testAndProcesses;
private Map<Power, Integer> powers;
private Map<Travel, Pair> travels;
//private Map<Travel, Pair> travels;
private Map<Travel,Integer> travels;
//private Map<Conference, Pair> conferences;
private Map<Conference, Integer> conferences;
private Map<InternationalCommunication, Integer> internationalCommunications;
......@@ -81,11 +82,11 @@ public class Budget implements Serializable {
this.powers = powers;
}
public Map<Travel, Pair> getTravels() {
public Map<Travel, Integer> getTravels() {
return travels;
}
public void setTravels(Map<Travel, Pair> travels) {
public void setTravels(Map<Travel, Integer> travels) {
this.travels = travels;
}
......@@ -171,7 +172,7 @@ public class Budget implements Serializable {
}
if (travels != null)
for (Travel travel : travels.keySet()) {
direct += travel.cost(travels.get(travel));
direct += travel.computeUnitPrice()*travels.get(travel);
}
if (conferences != null)
for (Conference conference : conferences.keySet()) {
......
......@@ -7,37 +7,26 @@ import com.alibaba.fastjson.annotation.JSONField;
*/
public class Travel extends Item {
@JSONField(name = "dest")
private String dest;
@JSONField(name = "food")
private double food;
@JSONField(name = "traffic")
private double traffic;
@JSONField(name = "accommodation")
private double accommodation;
private int people;
private int days;
@Override
public double computeUnitPrice() {
return getPrice() + getFood() + getAccommodation() + getTraffic();
public int getPeople() {
return people;
}
@Override
public String toString() {
return "Travel{" +
"dest='" + dest + '\'' +
", food=" + food +
", traffic=" + traffic +
", accommodation=" + accommodation +
"} " + super.toString();
public void setPeople(int people) {
this.people = people;
}
public String getDest() {
return getName();
public int getDays() {
return days;
}
public void setDest(String dest) {
setName(dest);
public void setDays(int days) {
this.days = days;
}
public double getFood() {
......@@ -70,6 +59,7 @@ public class Travel extends Item {
* @param pair
* @return
*/
@Deprecated
public double cost(Pair pair) {
if(pair==null || pair.getPeople()<=0 || pair.getDays()<=0) return 0.0;
return pair.getPeople() *
......@@ -77,4 +67,9 @@ public class Travel extends Item {
+ (getTraffic() + getFood()) * pair.getDays()
+ getAccommodation() * (pair.getDays() - 1));
}
@Override
public double computeUnitPrice() {
return getPeople()*(getPrice() + (getTraffic()+getFood())*getDays() +getAccommodation()*(getDays()-1));
}
}
......@@ -413,16 +413,15 @@ public class BudgetHandler {
private IInternationalCommunicationDao internationalCommunicationDao;
/**
* 修改预算中的国际交流合作费、规则中的国际交流合作费
* 修改预算中的国际交流合作费
*
* @param mode
* @param id
* @param name
* @param price
* @param internationalCommunication
* @param nums
* @param curd
* @param request
* @param response
* @throws IOException
*/
@RequestMapping("/Modify/International")
public void modifyInternational(Integer mode, InternationalCommunication internationalCommunication, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException {
......@@ -629,10 +628,10 @@ public class BudgetHandler {
* @param response
*/
@RequestMapping("/Modify/Travel")
public void modifyTravel(Integer mode, Travel travel, Pair pair, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException {
public void modifyTravel(Integer mode, Travel travel, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("/Modify/Travel");
if (pair == null || pair.getDays() < 0 || pair.getPeople() < 0) return;
if (nums < 0) return;
String sessionID = getSessionID(request.getCookies());
Budget budget = retrieveBudget(sessionID);
......@@ -641,15 +640,15 @@ public class BudgetHandler {
return;
}
Map<Travel, Pair> items = budget.getTravels();
Map<Travel, Integer> items = budget.getTravels();
checkService.checkTravel(travel);
if (curd.equals(0)) {
items.put(travel, pair);
items.put(travel, nums);
} else if (curd.equals(1)) {
items.remove(travel);
} else {
items.remove(travel);
items.put(travel, pair);
items.put(travel, nums);
}
afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID));
......@@ -801,19 +800,20 @@ public class BudgetHandler {
}
writer.newLine();
writer.write("差旅费,目的地,往返价格,伙食费,交通费,住宿费,人数,天数,小计");
writer.write("差旅费,目的地,往返价格,伙食费,交通费,住宿费,人数,天数,次数,小计");
writer.newLine();
Map<Travel, Pair> travels = budget.getTravels();
Map<Travel, Integer> travels = budget.getTravels();
for (Item item : travels.keySet()) {
if (item instanceof Travel) {
writer.write(comma + ((Travel) item).getDest()
writer.write(comma + ((Travel) item).getName()
+ comma + item.getPrice()
+ comma + ((Travel) item).getFood()
+ comma + ((Travel) item).getTraffic()
+ comma + ((Travel) item).getAccommodation()
+ comma + travels.get(item).getPeople()
+ comma + travels.get(item).getDays()
+ comma + ((Travel) item).cost(travels.get(item)));
+ comma + ((Travel) item).getPeople()
+ comma + ((Travel) item).getDays()
+ comma + travels.get(item)
+ comma + item.computeUnitPrice() * travels.get(item));
writer.newLine();
}
}
......@@ -835,17 +835,20 @@ public class BudgetHandler {
}
writer.newLine();
writer.write("国际合作交流费,会议内容,费用标准,会议次数,小计");
writer.write("国际合作交流费,会议内容,市际交通(往返交通),住宿补贴,伙食补贴,公杂费,人数,天数,次数,小计");
writer.newLine();
items = (Map) budget.getInternationalCommunications();
for (Item item : items.keySet()) {
if (item instanceof InternationalCommunication) {
writer.write(comma + item.getName()
+ comma + item.getPrice()
+ comma + items.get(item)
+ comma + item.computeUnitPrice() * items.get(item));
writer.newLine();
}
Map<InternationalCommunication, Integer> internationalCommunications = budget.getInternationalCommunications();
for (InternationalCommunication item : internationalCommunications.keySet()) {
writer.write(comma + item.getName()
+ comma + item.getPrice()
+ comma + item.getAccommodation()
+ comma + item.getFood()
+ comma + item.getTraffic()
+ comma + item.getPeople()
+ comma + item.getDays()
+ comma + items.get(item)
+ comma + item.computeUnitPrice() * internationalCommunications.get(item));
writer.newLine();
}
writer.newLine();
......
......@@ -281,7 +281,7 @@ public class DetailHandler {
response.sendError(444,"budget not exists");
return;
}
Map<Travel, Pair> travels = budget.getTravels();
Map<Travel, Integer> travels = budget.getTravels();
List<JSONObject> list=new LinkedList<>();
for (Travel item : travels.keySet()) {
JSONObject obj=new JSONObject();
......@@ -291,8 +291,9 @@ public class DetailHandler {
obj.put("food",item.getFood());
obj.put("traffic",item.getTraffic());
obj.put("accommodation",item.getAccommodation());
obj.put("people",travels.get(item).getPeople());
obj.put("days",travels.get(item).getDays());
obj.put("people",item.getPeople());
obj.put("days",item.getDays());
obj.put("nums",travels.get(item));
list.add(obj);
}
object.put("data",list);
......
......@@ -15,7 +15,7 @@ public interface IBudgetService {
Map<Power,Integer> doPower(Double number);
Map<Travel, Pair> doTravel(Double number);
Map<Travel, Integer> doTravel(Double number);
//Map<Conference, Pair> doConference(Double number);
Map<Conference, Integer> doConference(Double number);
......
......@@ -8,7 +8,7 @@ public interface IDetailService {
double sumEquipment(Map<Equipment, Integer> equipments);
double sumTravel(Map<Travel, Pair> travels);
double sumTravel(Map<Travel, Integer> travels);
double sumLabour(Map<Labour, Integer> labour);
......
......@@ -187,24 +187,25 @@ public class BudgetService implements IBudgetService {
* @return
*/
@Override
public Map<Travel, Pair> doTravel(Double number) {
Map<Travel, Pair> result = new HashMap<>();
public Map<Travel, Integer> doTravel(Double number) {
Map<Travel, Integer> result = new HashMap<>();
List<Travel> travels = travelDao.selectAll();
if (travels != null && travels.size() != 0) {
double sofar = 0.0;
for (Travel travel : travels) {
travel.setPeople(1);
travel.setDays(1);
if (sofar < number) {
Pair pair = new Pair(1, 1);
result.put(travel, pair);
sofar += travel.cost(pair);
result.put(travel, 1);
sofar += travel.computeUnitPrice();
}
}
while (sofar < number) {
for (Travel travel : result.keySet()) {
Pair pair = result.get(travel);
double oldCost = travel.cost(pair);
pair.setDays(pair.getDays() + 1);
double newCost = travel.cost(pair);
int days = travel.getDays();
double oldCost = travel.computeUnitPrice();
travel.setDays(days+1);
double newCost = travel.computeUnitPrice();
sofar += (newCost - oldCost);
//System.out.println("oldCost:" + oldCost);
//System.out.println("newCost:" + newCost);
......
......@@ -18,10 +18,10 @@ public class DetailService implements IDetailService {
}
@Override
public double sumTravel(Map<Travel, Pair> travels) {
public double sumTravel(Map<Travel, Integer> travels) {
double sum=0.0;
for (Travel travel : travels.keySet()) {
sum+=travel.cost(travels.get(travel));
sum+=travel.computeUnitPrice()*travels.get(travel);
}
return sum;
}
......
......@@ -223,6 +223,7 @@
<th>住宿补助</th>
<th>人数</th>
<th>天数</th>
<th>次数</th>
<th>操作</th>
</tr>
</thead>
......@@ -236,6 +237,7 @@
<td><input type="number" v-model="item.accommodation" class="form-control"></td>
<td><input type="number" v-model="item.people" class="form-control"></td>
<td><input type="number" v-model="item.days" class="form-control"></td>
<td><input type="number" v-model="item.nums" class="form-control"></td>
<td>
<button class="btn btn-success" @click="update(item)">确认</button>
<button class="btn btn-danger" @click="del(item)">删除</button>
......@@ -305,7 +307,7 @@
<p class="help-block"><b>市际</b>交通:指代往返价格、会议注册费等一次性费用</p>
<p class="help-block"><b>市内</b>交通:指代一切公杂费</p>
</div>
<table class="table table-hover">
<table class="table table-hover text-nowrap">
<thead>
<tr>
<th>名称</th>
......@@ -380,7 +382,7 @@
</td>
</tr>
<tr class="success">
<td><input type="text" readonly v-model="sample.name" class="form-control"></td>
<td><input type="text" v-model="sample.name" class="form-control"></td>
<td><input type="number" v-model="sample.price" class="form-control"></td>
<td><input type="number" v-model="sample.nums" class="form-control"></td>
<td>
......@@ -736,6 +738,7 @@
traffic: item.traffic,
days: item.days,
people: item.people,
nums:item.nums,
curd: curd
},
{emulateJSON: true}
......
......@@ -183,8 +183,9 @@
</div>
<!-- Button -->
<div>
<div title="所有复选框必须勾选,如果不需要某类费用,后面的数字填0即可">
<button class="btn btn-default btn-lg center-block" type="submit">生成预算</button>
<p class="help-block" style="color:red">所有复选框必须勾选,如果不需要某类费用,后面的数字填0即可</p>
</div>
</form>
......
......@@ -21,11 +21,9 @@ public class JsonTest {
{
Map<Travel, Pair> map=new HashMap<>();
map.put(new Travel(){{
setDest("xxx");
setPrice(100);setFood(10);setTraffic(50);setAccommodation(80);
}},new Pair(1,1));
map.put(new Travel(){{
setDest("yyy");
setPrice(200);setFood(20);setTraffic(90);setAccommodation(99);
}},new Pair(1,2));
for (Map.Entry<Travel, Pair> travelPairEntry : map.entrySet()) {
......
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