Commit e2ca3cf9 by shj

会议费与专家独立,由价格、人数、天数、次数构成,代码重构,budget里会议map的value统一为次数,人数天数放在conference类里,会议费的生成算法…

会议费与专家独立,由价格、人数、天数、次数构成,代码重构,budget里会议map的value统一为次数,人数天数放在conference类里,会议费的生成算法随之改变;咨询费单独生成,与会议独立,由用户在编预算的时候自己把专家分配到会议里;此时,除了间接经费外,其他费用之间均没有关联
parent 56ecbbe6
......@@ -14,7 +14,8 @@ public class Budget implements Serializable {
private Map<TestAndProcess, Integer> testAndProcesses;
private Map<Power, Integer> powers;
private Map<Travel, Pair> travels;
private Map<Conference, Pair> conferences;
//private Map<Conference, Pair> conferences;
private Map<Conference, Integer> conferences;
private Map<InternationalCommunication, Integer> internationalCommunications;
private Map<Property, Integer> properties;
private Map<Labour, Integer> labour;
......@@ -79,11 +80,11 @@ public class Budget implements Serializable {
this.travels = travels;
}
public Map<Conference, Pair> getConferences() {
public Map<Conference, Integer> getConferences() {
return conferences;
}
public void setConferences(Map<Conference, Pair> conferences) {
public void setConferences(Map<Conference, Integer> conferences) {
this.conferences = conferences;
}
......@@ -165,7 +166,7 @@ public class Budget implements Serializable {
}
if (conferences != null)
for (Conference conference : conferences.keySet()) {
direct += conference.getPrice() * conferences.get(conference).getPeople() * conferences.get(conference).getDays();
direct += conference.computeUnitPrice()*conferences.get(conference);
}
if (consultations!=null) {
for (Consultation consultation : consultations.keySet()) {
......
......@@ -75,8 +75,8 @@ public class BudgetHandler {
} else if (item.contains("conference")) {
budget.setConferences(budgetService.doConference(number));
budget.getRequirement().setConference(number);
int experts = expertSum(budget.getConferences());
budget.setConsultations(budgetService.doConsultation(experts));
/*int experts = expertSum(budget.getConferences());
budget.setConsultations(budgetService.doConsultation(experts));*/
} else if (item.contains("international")) {
budget.setInternationalCommunications(budgetService.doInternationalCommunication(number));
budget.getRequirement().setInternational(number);
......@@ -418,6 +418,7 @@ public class BudgetHandler {
/**
* 修改预算中的劳务费、规则中的劳务费
*
* @param mode
* @param labour
* @param nums
......@@ -454,66 +455,35 @@ public class BudgetHandler {
private IConferenceDao conferenceDao;
/**
*
* @param mode
* @param conference
* @param pair
* @param nums
* @param curd
* @param request
* @param response
*/
@RequestMapping("/Modify/Conference")
public void modifyConference(Integer mode, Conference conference, Pair pair, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) {
public void modifyConference(Integer mode, Conference conference, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) {
System.out.println("/Modify/Conference");
if (mode.equals(0))//修改预算
{
if (pair == null || pair.getDays() < 0 || pair.getPeople() < 0) return;
String sessionID = getSessionID(request.getCookies());
Budget budget = retrieveBudget(sessionID);
if(nums<0) return;
String sessionID = getSessionID(request.getCookies());
Budget budget = retrieveBudget(sessionID);
assert budget != null;
assert budget != null;
Map<Conference, Pair> items = budget.getConferences();
Conference mod = conferenceDao.selectById(conference.getId());
if (mod != null)
items.put(mod, pair);
int experts = 0;
for (Conference item : items.keySet()) {
experts += item.getExperts() * items.get(item).getDays();
}
budget.setConsultations(budgetService.doConsultation(experts));
try {
double sum = 0.0;
Map<Conference, Pair> conferencesMap = budget.getConferences();
Map<Consultation, Integer> consultationsMap = budget.getConsultations();
Consultation consultation = null;
for (Consultation item : consultationsMap.keySet()) {
consultation = item;
}
for (Conference item : conferencesMap.keySet()) {
sum += (consultation.getPrice() * item.getExperts()
+ item.getPrice() * conferencesMap.get(item).getPeople()) * conferencesMap.get(item).getDays();
}
response.getWriter().print(sum);
} catch (IOException e) {
e.printStackTrace();
}
serializeBudget(budget, getFilePath(sessionID));
} else//修改规则
{
Conference item = conference;
if (curd.equals(0))//增
{
conferenceDao.insertConference(item);
} else if (curd.equals(1))//删
{
conferenceDao.deleteConference(item);
} else//改
{
conferenceDao.updateConference(item);
}
Map<Conference, Integer> items = budget.getConferences();
if (curd.equals(0)) {
items.put(conference, nums);
} else if (curd.equals(1)) {
items.remove(conference);
} else {
items.remove(conference);
items.put(conference, nums);
}
afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID));
}
......@@ -772,16 +742,17 @@ public class BudgetHandler {
}
writer.newLine();
writer.write("会议费,会议内容,费用标准,参会人数,会议次数,小计");
writer.write("会议费,会议内容,费用标准,参会人数,举办天数,会议次数,小计");
writer.newLine();
Map<Conference, Pair> conferences = budget.getConferences();
Map<Conference, Integer> conferences = budget.getConferences();
for (Item item : conferences.keySet()) {
if (item instanceof Conference) {
writer.write(comma + item.getName()
+ comma + item.getPrice()
+ comma + conferences.get(item).getPeople()
+ comma + conferences.get(item).getDays()
+ comma + item.getPrice() * conferences.get(item).getPeople() * conferences.get(item).getDays());
+ comma + ((Conference) item).getPeople()
+ comma + ((Conference) item).getDays()
+ comma + conferences.get(item)
+ comma + item.computeUnitPrice() * conferences.get(item));
writer.newLine();
}
}
......@@ -830,24 +801,15 @@ public class BudgetHandler {
writer.newLine();
if (budget.getConferences() != null && budget.getConferences().size() > 0 && budget.getConsultations() != null) {
writer.write("咨询费,工作内容,人员类型,费用标准,每次人数,次数,小计");
writer.write("咨询费,人员类型,费用标准,人数,小计");
writer.newLine();
Map<Consultation, Integer> consultations = budget.getConsultations();
Consultation consultation = null;
for (Consultation item : consultations.keySet()) {
consultation = item;
}
conferences = budget.getConferences();
for (Item item : conferences.keySet()) {
if (item instanceof Conference) {
writer.write(comma + item.getName()
+ comma + consultation.getName()
+ comma + consultation.getPrice()
+ comma + ((Conference) item).getExperts()
+ comma + conferences.get(item).getDays()
+ comma + ((Conference) item).getExperts() * consultation.getPrice() * conferences.get(item).getDays());
writer.newLine();
}
for (Consultation consultation : consultations.keySet()) {
writer.write(comma + consultation.getName()
+ comma + consultation.getPrice()
+ comma + consultations.get(consultation)
+ comma + consultation.getPrice() * consultations.get(consultation));
writer.newLine();
}
}
writer.newLine();
......
......@@ -247,7 +247,7 @@ public class DetailHandler {
JSONObject object=new JSONObject();
String sessionID = BudgetHandler.getSessionID(request.getCookies());
Budget budget = BudgetHandler.retrieveBudget(sessionID);
Map<Conference, Pair> conferencePairMap = budget.getConferences();
Map<Conference, Integer> conferencePairMap = budget.getConferences();
List<JSONObject> list=new LinkedList<>();
for (Conference item : conferencePairMap.keySet()) {
JSONObject obj=new JSONObject();
......@@ -256,8 +256,9 @@ public class DetailHandler {
obj.put("experts",item.getExperts());
obj.put("expertType","专家");
obj.put("price",item.getPrice());
obj.put("people",conferencePairMap.get(item).getPeople());
obj.put("days",conferencePairMap.get(item).getDays());
obj.put("people",item.getPeople());
obj.put("days",item.getDays());
obj.put("nums",conferencePairMap.get(item));
list.add(obj);
}
object.put("data",list);
......
......@@ -17,7 +17,8 @@ public interface IBudgetService {
Map<Travel, Pair> doTravel(Double number);
Map<Conference, Pair> doConference(Double number);
//Map<Conference, Pair> doConference(Double number);
Map<Conference, Integer> doConference(Double number);
Map<InternationalCommunication,Integer> doInternationalCommunication(Double number);
......
......@@ -228,32 +228,23 @@ public class BudgetService implements IBudgetService {
* @return
*/
@Override
public Map<Conference, Pair> doConference(Double number) {
Map<Conference, Pair> map = new HashMap<>();
public Map<Conference, Integer> doConference(Double number) {
Map<Conference, Integer> map = new HashMap<>();
List<Conference> conferences = conferenceDao.selectAll();
List<Consultation> consultations = consultationDao.selectAll();
Consultation consultation = null;
if (consultations != null && consultations.size() > 0) {
for (Consultation item : consultations) {
consultation = item;
break;
}
}
double sum = 0.0;
for (Conference conference : conferences) {
if (sum < number) {
Pair value = new Pair(1, 1);
map.put(conference, value);
sum += conference.cost(value, consultation);
conference.setPeople(1);
conference.setDays(1);
map.put(conference, 1);
sum += conference.computeUnitPrice();
}
}
while (sum < number) {
for (Conference conference : map.keySet()) {
Pair pair = map.get(conference);
double oldCost = conference.cost(pair, consultation);
pair.setPeople(pair.getPeople() + 1);
double newCost = conference.cost(pair, consultation);
sum += (newCost - oldCost);
int i=map.get(conference);
map.put(conference,++i);
sum += conference.computeUnitPrice();
if (sum >= number) return map;
}
}
......
......@@ -611,7 +611,7 @@
el: "#conference",
data: {
items: [],
sample: {name: "sample",expertType:"专家",experts:0, price: 0, people: 0,days:0}
sample: {name: "sample",expertType:"专家",experts:0, price: 0, people: 0,days:0,nums:0}
},
methods: {
update: function (item) {
......@@ -643,6 +643,7 @@
price: item.price,
people: item.people,
days: item.days,
nums: item.nums,
curd: curd
},
{emulateJSON: true}
......
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