Commit bac7ff0c by shj

历史预算功能:数据库用户-预算表,生成预算时记录用户与预算的关系

parent 9f52ee39
......@@ -9,6 +9,7 @@ import java.util.Map;
* 经费报表对象,内含各种经费的集合
*/
public class Budget implements Serializable {
private Long id;
private Map<Equipment, Integer> equipments;
private Map<Material, Integer> materials;
private Map<TestAndProcess, Integer> testAndProcesses;
......@@ -28,6 +29,14 @@ public class Budget implements Serializable {
return requirement;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setRequirement(Requirement requirement) {
this.requirement = requirement;
}
......
package dao;
import org.apache.ibatis.annotations.Param;
public interface IUserBudgetDao {
void insertUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetid);
}
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.IUserBudgetDao">
<insert id="insertUserBudget" useGeneratedKeys="true" keyProperty="id">
insert into user_budget(userid,budgetid) values (#{userid},#{budgetid})
</insert>
</mapper>
\ No newline at end of file
......@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import service.IBudgetService;
import service.ICheckService;
import service.IUserBudgetService;
import util.CookieUtil;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
......@@ -31,6 +33,9 @@ public class BudgetHandler {
@Autowired
private IBudgetService budgetService;
@Autowired
private IUserBudgetService userBudgetService;
@RequestMapping("/Generate")
public void generateBudget(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
//PrintWriter writer = null;
......@@ -50,6 +55,7 @@ public class BudgetHandler {
response.addCookie(cookie);
Budget budget = new Budget();
budget.setId(sessionID);
Integer actualBudget = 0;
if (items != null && items.length != 0) {
......@@ -101,7 +107,7 @@ public class BudgetHandler {
//budget.setOthers(budgetService.doOthers(totalBudget.doubleValue()*10000-actualBudget.doubleValue()));
budget.setIndirects(budget.computeIndirect());
System.out.println(budget);
//System.out.println(budget);
/*String filePath = this.getClass().getClassLoader().getResource("..").getPath() +
......@@ -109,12 +115,17 @@ public class BudgetHandler {
File.separator + sessionID;*/
String filePath = getFilePath(Long.toString(sessionID));
serializeBudget(budget, filePath);
Cookie useridCookie = CookieUtil.getCookieByName(request.getCookies(), "userid");
Integer userid = Integer.valueOf(useridCookie.getValue());
System.out.println("get userid "+userid);
userBudgetService.addUserBudget(userid,budget.getId());
//response.setHeader("content-disposition", "attachment;filename=Budget" + sessionID + ".csv");
System.out.println("ContextPath: " + request.getContextPath());
System.out.println(session.getServletContext().getRealPath(""));
//budgetToOutputStream(budget, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -4,4 +4,5 @@ package service;
* 维护用户与预算文件的关系
*/
public interface IUserBudgetService {
void addUserBudget(Integer userid, Long id);
}
......@@ -206,11 +206,11 @@ public class BudgetService implements IBudgetService {
pair.setDays(pair.getDays() + 1);
double newCost = travel.cost(pair);
sofar += (newCost - oldCost);
System.out.println("oldCost:" + oldCost);
System.out.println("newCost:" + newCost);
System.out.println("sofar:" + sofar);
//System.out.println("oldCost:" + oldCost);
//System.out.println("newCost:" + newCost);
//System.out.println("sofar:" + sofar);
if (sofar >= number) {
System.out.println(result);
//System.out.println(result);
return result;
}
}
......
package service.impl;
import dao.IUserBudgetDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.IUserBudgetService;
@Service
public class UserBudgetService implements IUserBudgetService {
@Autowired
private IUserBudgetDao userBudgetDao;
@Override
public void addUserBudget(Integer userid, Long budgetid) {
if(userid==null || budgetid==null) return ;
userBudgetDao.insertUserBudget(userid,budgetid);
System.out.println("add User-Budget");
}
}
package util;
import javax.servlet.http.Cookie;
public class CookieUtil {
public static Cookie getCookieByName(Cookie[] cookies,String name){
if(cookies==null) return null;
for (Cookie cookie : cookies) {
if(cookie.getName().equals(name))
return cookie;
}
return null;
}
}
......@@ -67,8 +67,8 @@
consultation = 2,
others = 0; %>
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath}/Budget/Generate">
<iframe hidden id="hidden_frame" name="hidden_frame"></iframe>
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath}/Budget/Generate" target="hidden_frame">
<div class="form-group">
<label class="control-label col-sm-4">总预算(万元)</label>
......@@ -194,6 +194,5 @@
</form>
</body>
</html>
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