Commit 4c65cf2e by shj

解决了生成预算无响应的bug:因为死循环,生成预算的基准条目的价格为0,解决办法是在寻找基准条目的过程中排除价格0 的条目

parent b2d453f8
...@@ -122,14 +122,16 @@ public class BudgetService implements IBudgetService { ...@@ -122,14 +122,16 @@ public class BudgetService implements IBudgetService {
Map<Equipment, Integer> map = new HashMap<>(); Map<Equipment, Integer> map = new HashMap<>();
List<Equipment> equipments = equipmentDao.selectAll(); List<Equipment> equipments = equipmentDao.selectAll();
if (equipments != null && equipments.size() > 0) { if (equipments != null && equipments.size() > 0) {
Collections.sort(equipments, new Comparator<Equipment>() { equipments.sort((o1, o2) -> {
@Override double diff = o1.getPrice() - o2.getPrice();
public int compare(Equipment o1, Equipment o2) { return (int) diff;
double diff = o1.getPrice() - o2.getPrice();
return (int) diff;
}
}); });
Equipment equipment = equipments.get(0); Equipment equipment = null;
for (Equipment item : equipments) {
if(item.computeUnitPrice()!=0)
equipment=item;
}
if(equipment==null) return map;
double sum = 0.0; double sum = 0.0;
int i = 0; int i = 0;
while (sum < number) { while (sum < number) {
...@@ -152,7 +154,12 @@ public class BudgetService implements IBudgetService { ...@@ -152,7 +154,12 @@ public class BudgetService implements IBudgetService {
List<Material> materials = materialDao.selectAll(); List<Material> materials = materialDao.selectAll();
Map<Material,Integer> result=new HashMap<>(); Map<Material,Integer> result=new HashMap<>();
if(materials!=null && materials.size()>0){ if(materials!=null && materials.size()>0){
Material material = materials.get(0); Material material = null;
for (Material item : materials) {
if(item.computeUnitPrice()>0)
material=item;
}
if(material==null) return result;
int i=0; int i=0;
while (i*material.getPrice()<number){ while (i*material.getPrice()<number){
i++; i++;
...@@ -207,7 +214,14 @@ public class BudgetService implements IBudgetService { ...@@ -207,7 +214,14 @@ public class BudgetService implements IBudgetService {
Map<Travel, Integer> 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) {
Travel travel = travels.get(0); Travel travel = null;
for (Travel item : travels) {
item.setPeople(1);
item.setDays(1);
if(item.computeUnitPrice()>0)
travel=item;
}
if(travel==null) return result;
int i=1; int i=1;
travel.setDays(1); travel.setDays(1);
travel.setPeople(1); travel.setPeople(1);
...@@ -234,7 +248,12 @@ public class BudgetService implements IBudgetService { ...@@ -234,7 +248,12 @@ public class BudgetService implements IBudgetService {
Map<Conference, Integer> map = new HashMap<>(); Map<Conference, Integer> map = new HashMap<>();
List<Conference> conferences = conferenceDao.selectAll(); List<Conference> conferences = conferenceDao.selectAll();
if(conferences!=null && conferences.size()>0){ if(conferences!=null && conferences.size()>0){
Conference conference = conferences.get(0); Conference conference = null;
for (Conference item : conferences) {
if(item.getPrice()>0)
conference=item;
}
if(conference==null) return map;
conference.setDays(1); conference.setDays(1);
conference.setPeople(1); conference.setPeople(1);
int i=1; int i=1;
...@@ -257,7 +276,14 @@ public class BudgetService implements IBudgetService { ...@@ -257,7 +276,14 @@ public class BudgetService implements IBudgetService {
List<InternationalCommunication> internationalCommunications = internationalCommunicationDao.selectAll(); List<InternationalCommunication> internationalCommunications = internationalCommunicationDao.selectAll();
Map<InternationalCommunication,Integer> result=new HashMap<>(); Map<InternationalCommunication,Integer> result=new HashMap<>();
if(internationalCommunications==null || internationalCommunications.size()==0) return result; if(internationalCommunications==null || internationalCommunications.size()==0) return result;
InternationalCommunication internationalCommunication = internationalCommunications.get(0); InternationalCommunication internationalCommunication = null;
for (InternationalCommunication item : internationalCommunications) {
item.setDays(1);
item.setPeople(1);
if(item.computeUnitPrice()>0)
internationalCommunication=item;
}
if(internationalCommunication==null) return result;
internationalCommunication.setDays(1); internationalCommunication.setDays(1);
internationalCommunication.setPeople(1); internationalCommunication.setPeople(1);
while(internationalCommunication.computeUnitPrice()<number){ while(internationalCommunication.computeUnitPrice()<number){
...@@ -278,7 +304,12 @@ public class BudgetService implements IBudgetService { ...@@ -278,7 +304,12 @@ public class BudgetService implements IBudgetService {
List<Property> properties = propertyDao.selectAll(); List<Property> properties = propertyDao.selectAll();
Map<Property,Integer> result=new HashMap<>(); Map<Property,Integer> result=new HashMap<>();
if(properties!=null && properties.size()>0){ if(properties!=null && properties.size()>0){
Property property = properties.get(0); Property property =null;
for (Property item : properties) {
if(item.getPrice()>0)
property=item;
}
if(property==null) return result;
int i=0; int i=0;
while(i*property.getPrice()<number){ while(i*property.getPrice()<number){
i++; i++;
...@@ -299,7 +330,12 @@ public class BudgetService implements IBudgetService { ...@@ -299,7 +330,12 @@ public class BudgetService implements IBudgetService {
List<Labour> list = labourDao.selectAll(); List<Labour> list = labourDao.selectAll();
Map<Labour, Integer> result = new HashMap<>(); Map<Labour, Integer> result = new HashMap<>();
try { try {
Labour labour = list.get(0); Labour labour = null;
for (Labour item : list) {
if(item.getPrice()>0)
labour=item;
}
if(labour==null) return result;
labour.setPeople(1); labour.setPeople(1);
labour.setMonths(1); labour.setMonths(1);
while (labour.computeUnitPrice() < number) { while (labour.computeUnitPrice() < number) {
......
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