Commit 7c4b42bb by shj

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

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