Commit b2d453f8 by shj

数据库备份;数据库查询接口

parent b77a3c79
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
select * from conference where id=#{id} select * from conference where id=#{id}
</select> </select>
<insert id="insertConference"> <insert id="insertConference">
insert into budgetmanagementsystem.conference(name, price, experts,people) values (#{name},#{price},#{experts},#{people}) insert into budgetmanagementsystem.conference(name, price, experts,people,days) values (#{name},#{price},#{experts},#{people},#{days})
</insert> </insert>
<update id="updateConference"> <update id="updateConference">
update budgetmanagementsystem.conference set name=#{name},price=#{price},experts=#{experts},people=#{people} where id=#{id}; update budgetmanagementsystem.conference set name=#{name},price=#{price},experts=#{experts},people=#{people} where id=#{id};
......
...@@ -6,4 +6,8 @@ import java.util.List; ...@@ -6,4 +6,8 @@ import java.util.List;
public interface IOthersDao { public interface IOthersDao {
List<Others> selectAll(); List<Others> selectAll();
void insertOthers(Others others);
void deleteOthers(Others others);
} }
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.IOthersDao">
<select id="selectAll" resultType="beans.Others">
select * from others
</select>
<select id="selectById" resultType="beans.Others">
select * from others where id=#{id}
</select>
<insert id="insertOthers" useGeneratedKeys="true" keyProperty="id">
insert into others(name,price) values (#{name},#{price})
</insert>
<update id="updateProperty">
update budgetmanagementsystem.others set name=#{name},price=#{price} where id=#{id}
</update>
<delete id="deleteOthers">
delete from others where id=#{id}
</delete>
</mapper>
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<select id="selectById" resultType="beans.Property"> <select id="selectById" resultType="beans.Property">
select * from property where id=#{id} select * from property where id=#{id}
</select> </select>
<insert id="insertProperty"> <insert id="insertProperty" useGeneratedKeys="true" keyProperty="id">
insert into budgetmanagementsystem.property(name,price) values (#{name},#{price}) insert into budgetmanagementsystem.property(name,price) values (#{name},#{price})
</insert> </insert>
<update id="updateProperty"> <update id="updateProperty">
......
...@@ -6,4 +6,8 @@ import java.util.List; ...@@ -6,4 +6,8 @@ import java.util.List;
public interface ITestAndProcessDao { public interface ITestAndProcessDao {
List<TestAndProcess> selectAll(); List<TestAndProcess> selectAll();
void insertTestAndProcess(TestAndProcess testAndProcess);
void deleteTestAndProcess(TestAndProcess testAndProcess);
} }
...@@ -5,4 +5,10 @@ ...@@ -5,4 +5,10 @@
<select id="selectAll" resultType="beans.TestAndProcess"> <select id="selectAll" resultType="beans.TestAndProcess">
select * from testandprocess select * from testandprocess
</select> </select>
<insert id="insertTestAndProcess" useGeneratedKeys="true" keyProperty="id">
insert into testandprocess(name,price) values(#{name},#{price})
</insert>
<delete id="deleteTestAndProcess">
delete from testandprocess where id=#{id}
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -551,14 +551,25 @@ public class BudgetHandler { ...@@ -551,14 +551,25 @@ public class BudgetHandler {
{ {
items.remove(material); items.remove(material);
items.put(material, nums); items.put(material, nums);
} else } else if(curd.equals(0))
{
items.put(material, nums); items.put(material, nums);
materialDao.insertMaterial(material);
}else if(curd.equals(3))
{
items.put(material, nums);
}else if(curd.equals(4))
{
materialDao.deleteMaterial(material);
}
} }
afterUpdate(budget); afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID)); serializeBudget(budget, getFilePath(sessionID));
} }
@Autowired
private ITestAndProcessDao testAndProcessDao;
@RequestMapping("/Modify/TestAndProcess") @RequestMapping("/Modify/TestAndProcess")
public void modifyTestAndProcess(Integer mode, TestAndProcess testAndProcess, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException { public void modifyTestAndProcess(Integer mode, TestAndProcess testAndProcess, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("/Modify/TestAndProcess"); System.out.println("/Modify/TestAndProcess");
...@@ -581,8 +592,14 @@ public class BudgetHandler { ...@@ -581,8 +592,14 @@ public class BudgetHandler {
{ {
items.remove(testAndProcess); items.remove(testAndProcess);
items.put(testAndProcess, nums); items.put(testAndProcess, nums);
} else } else if(curd.equals(3))
items.put(testAndProcess, nums); items.put(testAndProcess, nums);
else if(curd.equals(0)){
items.put(testAndProcess,nums);
testAndProcessDao.insertTestAndProcess(testAndProcess);
}else if(curd.equals(4)){
testAndProcessDao.deleteTestAndProcess(testAndProcess);
}
} }
afterUpdate(budget); afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID)); serializeBudget(budget, getFilePath(sessionID));
...@@ -630,6 +647,12 @@ public class BudgetHandler { ...@@ -630,6 +647,12 @@ public class BudgetHandler {
{ {
items.put(internationalCommunication, nums); items.put(internationalCommunication, nums);
internationalCommunicationDao.insertInternational(internationalCommunication); internationalCommunicationDao.insertInternational(internationalCommunication);
}else if(curd.equals(3))
{
items.put(internationalCommunication, nums);
}else if(curd.equals(4))
{
internationalCommunicationDao.deleteInternational(internationalCommunication);
} }
} }
afterUpdate(budget); afterUpdate(budget);
...@@ -668,11 +691,16 @@ public class BudgetHandler { ...@@ -668,11 +691,16 @@ public class BudgetHandler {
if (!checkService.checkProperty(property)) return; if (!checkService.checkProperty(property)) return;
if (curd.equals(0)) { if (curd.equals(0)) {
items.put(property, nums); items.put(property, nums);
propertyDao.insertProperty(property);
} else if (curd.equals(1)) { } else if (curd.equals(1)) {
items.remove(property); items.remove(property);
} else { } else if(curd.equals(2)){
items.remove(property); items.remove(property);
items.put(property, nums); items.put(property, nums);
}else if(curd.equals(3)){
items.put(property,nums);
}else if(curd.equals(4)){
propertyDao.deleteProperty(property);
} }
afterUpdate(budget); afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID)); serializeBudget(budget, getFilePath(sessionID));
...@@ -747,11 +775,16 @@ public class BudgetHandler { ...@@ -747,11 +775,16 @@ public class BudgetHandler {
Map<Conference, Integer> items = budget.getConferences(); Map<Conference, Integer> items = budget.getConferences();
if (curd.equals(0)) { if (curd.equals(0)) {
items.put(conference, nums); items.put(conference, nums);
conferenceDao.insertConference(conference);
} else if (curd.equals(1)) { } else if (curd.equals(1)) {
items.remove(conference); items.remove(conference);
} else { } else if(curd.equals(2)){
items.remove(conference); items.remove(conference);
items.put(conference, nums); items.put(conference, nums);
}else if(curd.equals(3)){
items.put(conference,nums);
}else if(curd.equals(4)){
conferenceDao.deleteConference(conference);
} }
afterUpdate(budget); afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID)); serializeBudget(budget, getFilePath(sessionID));
...@@ -867,6 +900,8 @@ public class BudgetHandler { ...@@ -867,6 +900,8 @@ public class BudgetHandler {
@Autowired
private IOthersDao othersDao;
@RequestMapping("/Modify/Others") @RequestMapping("/Modify/Others")
public void modifyOthers(Integer mode, Others others, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException { public void modifyOthers(Integer mode, Others others, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("/Modify/Others"); System.out.println("/Modify/Others");
...@@ -884,11 +919,16 @@ public class BudgetHandler { ...@@ -884,11 +919,16 @@ public class BudgetHandler {
items = budget.getOthers(); items = budget.getOthers();
if (curd.equals(0)) { if (curd.equals(0)) {
items.put(others, nums); items.put(others, nums);
othersDao.insertOthers(others);
} else if (curd.equals(1)) { } else if (curd.equals(1)) {
items.remove(others); items.remove(others);
} else { } else if(curd.equals(2)){
items.remove(others); items.remove(others);
items.put(others, nums); items.put(others, nums);
}else if(curd.equals(3)){
items.put(others, nums);
}else if(curd.equals(4)){
othersDao.deleteOthers(others);
} }
afterUpdate(budget); afterUpdate(budget);
serializeBudget(budget, getFilePath(sessionID)); serializeBudget(budget, getFilePath(sessionID));
......
...@@ -48,6 +48,60 @@ public class DatabaseQueryHandler { ...@@ -48,6 +48,60 @@ public class DatabaseQueryHandler {
} }
} }
@Autowired
private IMaterialDao materialDao;
@RequestMapping("/Material")
public void queryMaterial(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<Material> materials = materialDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (Material item : materials) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
@Autowired
private ITestAndProcessDao testAndProcessDao;
@RequestMapping("/TestAndProcess")
public void queryTestAndProcess(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<TestAndProcess> testAndProcesses = testAndProcessDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (TestAndProcess item : testAndProcesses) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
@Autowired @Autowired
private ILabourDao labourDao; private ILabourDao labourDao;
@RequestMapping("/Labour") @RequestMapping("/Labour")
...@@ -136,6 +190,61 @@ public class DatabaseQueryHandler { ...@@ -136,6 +190,61 @@ public class DatabaseQueryHandler {
} }
@Autowired
private IConferenceDao conferenceDao;
@RequestMapping("/Conference")
public void queryConference(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<Conference> conferences = conferenceDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (Conference item : conferences) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("people",item.getPeople());
obj.put("days",item.getDays());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
@Autowired
private IPropertyDao propertyDao;
@RequestMapping("/Property")
public void queryProperty(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<Property> properties = propertyDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (Property item : properties) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
@Autowired @Autowired
private IInternationalCommunicationDao internationalCommunicationDao; private IInternationalCommunicationDao internationalCommunicationDao;
...@@ -167,4 +276,30 @@ public class DatabaseQueryHandler { ...@@ -167,4 +276,30 @@ public class DatabaseQueryHandler {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Autowired
private IOthersDao othersDao;
@RequestMapping("/Others")
public void queryOthers(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<Others> others = othersDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (Others item : others) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -150,7 +150,16 @@ public class BudgetService implements IBudgetService { ...@@ -150,7 +150,16 @@ public class BudgetService implements IBudgetService {
@Override @Override
public Map<Material, Integer> doMaterial(Double number) { public Map<Material, Integer> doMaterial(Double number) {
List<Material> materials = materialDao.selectAll(); List<Material> materials = materialDao.selectAll();
return generateMap((List) materials, number); Map<Material,Integer> result=new HashMap<>();
if(materials!=null && materials.size()>0){
Material material = materials.get(0);
int i=0;
while (i*material.getPrice()<number){
i++;
}
result.put(material,i);
}
return result;
} }
/** /**
...@@ -163,6 +172,7 @@ public class BudgetService implements IBudgetService { ...@@ -163,6 +172,7 @@ public class BudgetService implements IBudgetService {
public Map<TestAndProcess, Integer> doTestAndProcess(Double number) { public Map<TestAndProcess, Integer> doTestAndProcess(Double number) {
Map<TestAndProcess,Integer> result=new HashMap<>(); Map<TestAndProcess,Integer> result=new HashMap<>();
TestAndProcess testAndProcess = new TestAndProcess(); TestAndProcess testAndProcess = new TestAndProcess();
testAndProcess.setId(0);
testAndProcess.setPrice(number); testAndProcess.setPrice(number);
testAndProcess.setName("测试化验加工费"); testAndProcess.setName("测试化验加工费");
result.put(testAndProcess,1); result.put(testAndProcess,1);
...@@ -179,6 +189,7 @@ public class BudgetService implements IBudgetService { ...@@ -179,6 +189,7 @@ public class BudgetService implements IBudgetService {
public Map<Power, Integer> doPower(Double number) { public Map<Power, Integer> doPower(Double number) {
Map<Power,Integer> result=new HashMap<>(); Map<Power,Integer> result=new HashMap<>();
Power power = new Power(); Power power = new Power();
power.setId(1);
power.setPrice(number); power.setPrice(number);
power.setName("燃料动力费"); power.setName("燃料动力费");
result.put(power,1); result.put(power,1);
...@@ -196,31 +207,16 @@ public class BudgetService implements IBudgetService { ...@@ -196,31 +207,16 @@ 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) {
double sofar = 0.0; Travel travel = travels.get(0);
for (Travel travel : travels) { int i=1;
travel.setPeople(1); travel.setDays(1);
travel.setDays(1); travel.setPeople(1);
if (sofar < number) { while(travel.computeUnitPrice()<number){
result.put(travel, 1); i++;
sofar += travel.computeUnitPrice(); travel.setPeople(i);
}
}
while (sofar < number) {
for (Travel travel : result.keySet()) {
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);
//System.out.println("sofar:" + sofar);
if (sofar >= number) {
//System.out.println(result);
return result;
}
}
} }
result.put(travel,1);
} }
return result; return result;
} }
...@@ -237,22 +233,15 @@ public class BudgetService implements IBudgetService { ...@@ -237,22 +233,15 @@ public class BudgetService implements IBudgetService {
public Map<Conference, Integer> doConference(Double number) { public Map<Conference, Integer> doConference(Double number) {
Map<Conference, Integer> map = new HashMap<>(); Map<Conference, Integer> map = new HashMap<>();
List<Conference> conferences = conferenceDao.selectAll(); List<Conference> conferences = conferenceDao.selectAll();
double sum = 0.0; if(conferences!=null && conferences.size()>0){
for (Conference conference : conferences) { Conference conference = conferences.get(0);
if (sum < number) { conference.setDays(1);
conference.setPeople(1); conference.setPeople(1);
conference.setDays(1); int i=1;
map.put(conference, 1); while(conference.computeUnitPrice()<number){
sum += conference.computeUnitPrice(); conference.setPeople(++i);
}
}
while (sum < number) {
for (Conference conference : map.keySet()) {
int i = map.get(conference);
map.put(conference, ++i);
sum += conference.computeUnitPrice();
if (sum >= number) return map;
} }
map.put(conference,1);
} }
return map; return map;
} }
...@@ -287,7 +276,16 @@ public class BudgetService implements IBudgetService { ...@@ -287,7 +276,16 @@ public class BudgetService implements IBudgetService {
@Override @Override
public Map<Property, Integer> doProperty(Double number) { public Map<Property, Integer> doProperty(Double number) {
List<Property> properties = propertyDao.selectAll(); List<Property> properties = propertyDao.selectAll();
return generateMap((List) properties, number); Map<Property,Integer> result=new HashMap<>();
if(properties!=null && properties.size()>0){
Property property = properties.get(0);
int i=0;
while(i*property.getPrice()<number){
i++;
}
result.put(property,i);
}
return result;
} }
/** /**
...@@ -395,6 +393,7 @@ public class BudgetService implements IBudgetService { ...@@ -395,6 +393,7 @@ public class BudgetService implements IBudgetService {
public Map<Others, Integer> doOthers(Double number) { public Map<Others, Integer> doOthers(Double number) {
Map<Others, Integer> others = new HashMap<>(); Map<Others, Integer> others = new HashMap<>();
Others item = new Others(); Others item = new Others();
item.setId(0);
item.setName("其他费用"); item.setName("其他费用");
item.setPrice(number); item.setPrice(number);
others.put(item, 1); others.put(item, 1);
......
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