Commit 42269046 by shj

在预算生成页面添加预算名称字段,并在历史预算页面进行展示

parent 41fe001c
......@@ -3,8 +3,17 @@ package beans;
import java.io.Serializable;
public class Requirement implements Serializable {
private double total;
private double equip,material,conference,consultation,indirect,international,labour,others,power,property,test,travel;
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public double getEquip() {
return equip;
}
......
package beans;
public class UserBudget {
private Integer id;
private Integer userid;
private Long budgetid;
private String budgetname;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public Long getBudgetid() {
return budgetid;
}
public void setBudgetid(Long budgetid) {
this.budgetid = budgetid;
}
public String getBudgetname() {
return budgetname;
}
public void setBudgetname(String budgetname) {
this.budgetname = budgetname;
}
}
package dao;
import beans.UserBudget;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -7,7 +8,9 @@ import java.util.List;
public interface IUserBudgetDao {
void insertUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetid);
List<Long> selectBudgetByUserid(@Param("userid") Integer userid);
List<UserBudget> selectBudgetByUserid(@Param("userid") Integer userid);
void deleteUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetId);
void updateBudgetName(@Param("budgetid") Long id,@Param("budgetname") String budgetName);
}
......@@ -5,10 +5,13 @@
<insert id="insertUserBudget" useGeneratedKeys="true" keyProperty="id">
insert into user_budget(userid,budgetid) values (#{userid},#{budgetid})
</insert>
<select id="selectBudgetByUserid" resultType="java.lang.Long">
select budgetid from user_budget where userid=#{userid} order by budgetid desc
<select id="selectBudgetByUserid" resultType="beans.UserBudget">
select * from user_budget where userid=#{userid} order by budgetid desc
</select>
<delete id="deleteUserBudget">
delete from user_budget where userid=#{userid} and budgetid=#{budgetid}
</delete>
<update id="updateBudgetName">
update user_budget set budgetname=#{budgetname} where budgetid=#{budgetid}
</update>
</mapper>
\ No newline at end of file
......@@ -58,6 +58,7 @@ public class BudgetHandler {
Budget budget = new Budget();
budget.setId(sessionID);
Integer actualBudget = 0;
budget.getRequirement().setTotal(totalBudget*10000);
if (items != null && items.length != 0) {
for (String item : items) {
......@@ -119,7 +120,9 @@ public class BudgetHandler {
Cookie useridCookie = CookieUtil.getCookieByName(request.getCookies(), "userid");
Integer userid = Integer.valueOf(useridCookie.getValue());
System.out.println("get userid " + userid);
String budgetName = request.getParameter("name");
userBudgetService.addUserBudget(userid, budget.getId());
userBudgetService.changeBudgetName(budget.getId(),budgetName);
//response.setHeader("content-disposition", "attachment;filename=Budget" + sessionID + ".csv");
System.out.println("ContextPath: " + request.getContextPath());
......@@ -218,7 +221,7 @@ public class BudgetHandler {
}
//删除budget相关cookie,防止删除后重新进入详情页面
String sessionID = getSessionID(request.getCookies());
if (sessionID.equals(budgetId.toString())) {
if (sessionID!=null && sessionID.equals(budgetId.toString())) {
Cookie cookie = new Cookie("sessionID", null);
cookie.setPath("/");
cookie.setMaxAge(0);
......@@ -244,14 +247,15 @@ public class BudgetHandler {
Cookie useridCookie = CookieUtil.getCookieByName(request.getCookies(), "userid");
Integer userid = Integer.valueOf(useridCookie.getValue());
List<Long> budgetList = userBudgetService.getBudgetByUserid(userid);
List<UserBudget> budgetList = userBudgetService.getBudgetByUserid(userid);
List<JSONObject> list = new LinkedList<>();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Long budget : budgetList) {
for (UserBudget budget : budgetList) {
JSONObject obj = new JSONObject();
obj.put("id", budget);
Date date = new Date(budget);
obj.put("id", budget.getBudgetid());
Date date = new Date(budget.getBudgetid());
obj.put("date", format.format(date));
obj.put("name",budget.getBudgetname());
list.add(obj);
}
object.put("data", list);
......
......@@ -165,9 +165,9 @@ public class DetailHandler {
object.put("consultation",sub);
req_sofar+=req;sum_sofar+=sum;
object.put("req",req_sofar);
object.put("req",budget.getRequirement().getTotal());
object.put("sum",sum_sofar);
object.put("diff",req_sofar-sum_sofar);
object.put("diff",budget.getRequirement().getTotal()-sum_sofar);
writer.write(object.toJSONString());
} catch (IOException e) {
......
package service;
import beans.UserBudget;
import java.util.List;
/**
......@@ -8,7 +10,9 @@ import java.util.List;
public interface IUserBudgetService {
void addUserBudget(Integer userid, Long id);
List<Long> getBudgetByUserid(Integer userid);
List<UserBudget> getBudgetByUserid(Integer userid);
void deleteUserBudget(Integer userid, Long budgetId);
void changeBudgetName(Long id, String budgetName);
}
package service.impl;
import beans.UserBudget;
import dao.IUserBudgetDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -19,8 +20,8 @@ public class UserBudgetService implements IUserBudgetService {
}
@Override
public List<Long> getBudgetByUserid(Integer userid) {
List<Long> budgets=userBudgetDao.selectBudgetByUserid(userid);
public List<UserBudget> getBudgetByUserid(Integer userid) {
List<UserBudget> budgets=userBudgetDao.selectBudgetByUserid(userid);
return budgets;
}
......@@ -28,4 +29,9 @@ public class UserBudgetService implements IUserBudgetService {
public void deleteUserBudget(Integer userid, Long budgetId) {
userBudgetDao.deleteUserBudget(userid,budgetId);
}
@Override
public void changeBudgetName(Long id, String budgetName) {
userBudgetDao.updateBudgetName(id,budgetName);
}
}
......@@ -67,7 +67,7 @@
<table class="table table-hover">
<thead>
<tr>
<th>预算ID</th>
<th>预算名称</th>
<th>创建时间</th>
<th>操作</th>
</tr>
......@@ -75,12 +75,15 @@
<tbody>
<tr v-for="budget in budgetList">
<td>{{budget.id}}</td>
<td hidden>{{budget.id}}</td>
<td>{{budget.name}}</td>
<td>{{budget.date}}</td>
<td>
<a v-bind:href="'${pageContext.request.contextPath}/Budget/Detail/'+budget.id">
<button class="btn btn-success">查看详情</button>
</a>
<button class="btn btn-info">修改属性</button>
<button class="btn btn-info">下载说明文件</button>
<button class="btn btn-danger" @click="del(budget.id)">删除</button>
</td>
</tr>
......
......@@ -66,6 +66,13 @@
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath}/Budget/Generate">
<div class="form-group">
<label class="control-label col-sm-4">预算名称</label>
<div class="col-sm-4">
<input name="name" type="text" placeholder="预算名称" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">总预算(万元)</label>
<div class="col-sm-4">
<input name="total" type="number" placeholder="" class="form-control" required value=<%=total%>>
......
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