Commit a3de9b40 by shj

预算属性修改:包括预算名称、预算分配等数据,页面的实现与接口

parent 9bff1093
......@@ -13,4 +13,6 @@ public interface IUserBudgetDao {
void deleteUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetId);
void updateBudgetName(@Param("budgetid") Long id,@Param("budgetname") String budgetName);
UserBudget selectBudgetByBudgetid(@Param("budgetid") Long budgetId);
}
......@@ -14,4 +14,7 @@
<update id="updateBudgetName">
update user_budget set budgetname=#{budgetname} where budgetid=#{budgetid}
</update>
<select id="selectBudgetByBudgetid" resultType="beans.UserBudget">
select * from user_budget where budgetid=#{budgetid}
</select>
</mapper>
\ No newline at end of file
......@@ -259,6 +259,78 @@ public class BudgetHandler {
return modelAndView;
}
@RequestMapping("/Setting/{budgetId}")
public ModelAndView budgetSettingById(@PathVariable("budgetId") Long budgetId, HttpServletRequest request, HttpServletResponse response) {
if (budgetId == null) return new ModelAndView("/");
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/budgetSetting.jsp");
modelAndView.addObject("budget", retrieveBudget(budgetId.toString()));
Cookie sessionID = CookieUtil.getCookieByName(request.getCookies(), "sessionID");
if (sessionID == null) {
sessionID = new Cookie("sessionID", budgetId.toString());
} else {
sessionID.setValue(budgetId.toString());
}
sessionID.setPath("/");
response.addCookie(sessionID);
UserBudget userBudget=userBudgetService.getBudgetByBudgetid(budgetId);
modelAndView.addObject("name",userBudget.getBudgetname());
return modelAndView;
}
@RequestMapping("/Setting.do")
public void doBudgetSettingById(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
String sessionID = getSessionID(request.getCookies());
if (sessionID == null) return;
Integer totalBudget = Integer.valueOf(request.getParameter("total"));
String[] items = request.getParameterValues("items");
Budget budget = retrieveBudget(sessionID);
if(budget==null) return ;
budget.getRequirement().setTotal(totalBudget);
if (items != null && items.length != 0) {
for (String item : items) {
Double number = Double.valueOf(request.getParameter(item + "-number"));
if (item.contains("equipment")) {
budget.getRequirement().setEquip(number);
} else if (item.contains("material")) {
budget.getRequirement().setMaterial(number);
} else if (item.contains("test")) {
budget.getRequirement().setTest(number);
} else if (item.contains("power")) {
budget.getRequirement().setPower(number);
} else if (item.contains("travel")) {
budget.getRequirement().setTravel(number);
} else if (item.contains("conference")) {
budget.getRequirement().setConference(number);
} else if (item.contains("international")) {
budget.getRequirement().setInternational(number);
} else if (item.contains("property")) {
budget.getRequirement().setProperty(number);
} else if (item.contains("labour")) {
budget.getRequirement().setLabour(number);
} else if (item.contains("consultation")) {
budget.getRequirement().setConsultation(number);
} else if (item.contains("others")) {
budget.getRequirement().setOthers(number);
}
}
}
serializeBudget(budget, getFilePath(sessionID));
String budgetName = request.getParameter("name");
userBudgetService.changeBudgetName(budget.getId(),budgetName);
} catch (Exception e) {
e.printStackTrace();
}
response.sendRedirect(request.getContextPath()+"/Budget/HistoryPage");
}
@RequestMapping("/Delete/{budgetId}")
public void deleteBudgetById(@PathVariable("budgetId") Long budgetId, HttpServletRequest request, HttpServletResponse response) {
if (budgetId == null) return;
......
......@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import service.IDetailService;
import service.IUserBudgetService;
import util.SalaryCalculator;
import javax.servlet.http.HttpServletRequest;
......@@ -57,6 +58,8 @@ public class DetailHandler {
@Autowired
private IDetailService detailService;
@Autowired
private IUserBudgetService userBudgetService;
@RequestMapping("/Stats")
public void getStats(HttpServletRequest request,HttpServletResponse response)
{
......@@ -75,6 +78,7 @@ public class DetailHandler {
double req_sofar=0.0,sum_sofar=0.0,req,sum;
//设备费
JSONObject sub=new JSONObject();
req=budget.getRequirement().getEquip();
......@@ -199,6 +203,9 @@ public class DetailHandler {
object.put("sum",sum_sofar);
object.put("diff",budget.getRequirement().getTotal()-sum_sofar);
UserBudget userBudget = userBudgetService.getBudgetByBudgetid(Long.valueOf(sessionID));
object.put("name",userBudget.getBudgetname());
writer.write(object.toJSONString());
} catch (IOException e) {
e.printStackTrace();
......
......@@ -15,4 +15,6 @@ public interface IUserBudgetService {
void deleteUserBudget(Integer userid, Long budgetId);
void changeBudgetName(Long id, String budgetName);
UserBudget getBudgetByBudgetid(Long budgetId);
}
......@@ -34,4 +34,9 @@ public class UserBudgetService implements IUserBudgetService {
public void changeBudgetName(Long id, String budgetName) {
userBudgetDao.updateBudgetName(id,budgetName);
}
@Override
public UserBudget getBudgetByBudgetid(Long budgetId) {
return userBudgetDao.selectBudgetByBudgetid(budgetId);
}
}
......@@ -56,7 +56,7 @@
<li><a href="${pageContext.request.contextPath}/">创建预算</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
<li class="active"><a href="${pageContext.request.contextPath}/Budget/Detail">修改预算</a></li>
......
<%--
Created by IntelliJ IDEA.
User: Song
Date: 2019/5/23
Time: 22:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>预算属性</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
body {
padding-top: 70px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="${pageContext.request.contextPath}/">预算辅助管理系统</a>
</div>
<div>
<ul class="nav navbar-nav">
<li><a href="${pageContext.request.contextPath}/">创建预算</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Detail" >修改预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
<li class="active"><a href="#">预算属性</a></li>
</ul>
</div>
</div>
</nav>
<iframe hidden id="hidden_frame" name="hidden_frame"></iframe>
<div id="form">
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath}/Budget/Setting.do">
<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 v-model="budget.name">
</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="填写大于0的数字" class="form-control" required v-model="budget.req">
</div>
<div class="col-sm-4">
<label>{{sum}}</label>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">项目周期(年)</label>
<div class="col-sm-4">
<input name="years" type="number" placeholder="填写大于0的数字" class="form-control" required>
</div>
</div>
<hr>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="equipment" checked required>
设备费
</label>
<div class="col-sm-4">
<input name="equipment-number" class="form-control" type="number" v-model="budget.equipment.req">
</div>
<div class="col-sm-2">
<input name="equipment-distribution" class="form-control" type="text" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="material" checked required>
材料费
</label>
<div class="col-sm-4">
<input name="material-number" class="form-control" type="number" v-model="budget.material.req">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="test-and-process" checked required>
测试化验加工费
</label>
<div class="col-sm-4">
<input name="test-and-process-number" class="form-control" type="number" v-model="budget.testAndProcess.req">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="power" checked required>
燃料动力费
</label>
<div class="col-sm-4">
<input name="power-number" class="form-control" type="number" v-model="budget.power.req">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="travel" checked required>
差旅费
</label>
<div class="col-sm-4">
<input name="travel-number" class="form-control" type="number" v-model="budget.travel.req">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="conference" checked required>
会议费
</label>
<div class="col-sm-4" id="tip">
<input name="conference-number" class="form-control" type="number" v-model="budget.conference.req">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="international-communication" checked required>
国际合作交流费
</label>
<div class="col-sm-4">
<input name="international-communication-number" class="form-control" type="number"
v-model="budget.international.req"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="property" checked required>
产权费
</label>
<div class="col-sm-4">
<input name="property-number" class="form-control" type="number" v-model="budget.property.req"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="labour" checked required>
劳务费
</label>
<div class="col-sm-4">
<input name="labour-number" class="form-control" type="number" v-model="budget.labour.req"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="consultation" checked required>
咨询费
</label>
<div class="col-sm-4">
<input name="consultation-number" class="form-control" type="number" v-model="budget.consultation.req"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">
<input name="items" type="checkbox" value="others" checked required>
其他费用
</label>
<div class="col-sm-4">
<input name="others-number" class="form-control" type="number" v-model="budget.others.req"></div>
</div>
<!-- Button -->
<div title="所有复选框必须勾选,如果不需要某类费用,后面的数字填0即可">
<button class="btn btn-default btn-lg center-block" type="submit">生成预算</button>
<p class="help-block" style="color:red">所有复选框必须勾选,如果不需要某类费用,后面的数字填0即可</p>
</div>
</form>
</div>
<script type="text/javascript">
var formVue = new Vue({
el: "#form",
data:{
arr:[0,2,5,0,2,5, 6,8,6,2,0],
total:150,
budget:{}
},
computed:{
sum:function () {
var sum=Number(0);
sum+=(Number(this.budget.equipment.req)
+Number(this.budget.material.req)
+Number(this.budget.testAndProcess.req)
+Number(this.budget.power.req)
+Number(this.budget.travel.req)
+Number(this.budget.conference.req)
+Number(this.budget.international.req)
+Number(this.budget.property.req)
+Number(this.budget.labour.req)
+Number(this.budget.consultation.req)
+Number(this.budget.others.req)
);
return sum;
}
},
created:function () {
this.$http.get("${pageContext.request.contextPath}/Budget/Detail/Stats").then(
function (data) {
this.budget = data.body;
console.log("show history list");
}, function (error) {
console.log(error)
}
)
}
})
</script>
</body>
</html>
......@@ -47,7 +47,7 @@
<li class="active"><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Detail">修改预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
</ul>
......@@ -80,9 +80,11 @@
<td>{{budget.date}}</td>
<td>
<a v-bind:href="'${pageContext.request.contextPath}/Budget/Detail/'+budget.id">
<button class="btn btn-success">查看详情</button>
<button class="btn btn-info">查看详情</button>
</a>
<a v-bind:href="'${pageContext.request.contextPath}/Budget/Setting/'+budget.id">
<button class="btn btn-success">修改预算属性</button>
</a>
<button class="btn btn-info">修改属性</button>
<a v-bind:href="'${pageContext.request.contextPath}/Budget/Download/csv/'+budget.id">
<button class="btn btn-success">下载费用清单</button>
</a>
......
......@@ -40,7 +40,7 @@
<li><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Detail" >修改预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
</ul>
......
......@@ -48,7 +48,7 @@
<li><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Detail" >修改预算</a></li>--%>
<li class="active"><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
</ul>
......
......@@ -47,7 +47,7 @@
<li><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Detail">修改预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</a></li>
<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>
<%--<li><a href="${pageContext.request.contextPath}/Budget/Download">导出最新预算</a></li>--%>
<li><a href="${pageContext.request.contextPath}/Test">测试</a></li>
<li class="active"><a href="${pageContext.request.contextPath}/usercenter.jsp">用户中心</a></li>
</ul>
......
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