Commit 8b0d1c3a by shj

历史预算列表的展示优化,在历史预算列表可以进行预算文件的删除

parent 367acd13
...@@ -8,4 +8,6 @@ public interface IUserBudgetDao { ...@@ -8,4 +8,6 @@ public interface IUserBudgetDao {
void insertUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetid); void insertUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetid);
List<Long> selectBudgetByUserid(@Param("userid") Integer userid); List<Long> selectBudgetByUserid(@Param("userid") Integer userid);
void deleteUserBudget(@Param("userid") Integer userid, @Param("budgetid") Long budgetId);
} }
...@@ -8,4 +8,7 @@ ...@@ -8,4 +8,7 @@
<select id="selectBudgetByUserid" resultType="java.lang.Long"> <select id="selectBudgetByUserid" resultType="java.lang.Long">
select budgetid from user_budget where userid=#{userid} order by budgetid desc select budgetid from user_budget where userid=#{userid} order by budgetid desc
</select> </select>
<delete id="deleteUserBudget">
delete from user_budget where userid=#{userid} and budgetid=#{budgetid}
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -197,6 +197,21 @@ public class BudgetHandler { ...@@ -197,6 +197,21 @@ public class BudgetHandler {
return modelAndView; return modelAndView;
} }
@RequestMapping("/Delete/{budgetId}")
public void deleteBudgetById(@PathVariable("budgetId") Long budgetId,HttpServletRequest request, HttpServletResponse response) {
if (budgetId == null) return ;
Cookie useridCookie = CookieUtil.getCookieByName(request.getCookies(), "userid");
Integer userid = Integer.valueOf(useridCookie.getValue());
//删除数据库记录
userBudgetService.deleteUserBudget(userid,budgetId);
//删除文件
String filePath = getFilePath(budgetId.toString());
File budgetFile=new File(filePath);
if(budgetFile.delete()){
System.out.println("成功删除文件");
}
}
@RequestMapping("/HistoryPage") @RequestMapping("/HistoryPage")
public ModelAndView historyPage(HttpServletRequest request,HttpServletResponse response){ public ModelAndView historyPage(HttpServletRequest request,HttpServletResponse response){
ModelAndView modelAndView=new ModelAndView(); ModelAndView modelAndView=new ModelAndView();
......
...@@ -9,4 +9,6 @@ public interface IUserBudgetService { ...@@ -9,4 +9,6 @@ public interface IUserBudgetService {
void addUserBudget(Integer userid, Long id); void addUserBudget(Integer userid, Long id);
List<Long> getBudgetByUserid(Integer userid); List<Long> getBudgetByUserid(Integer userid);
void deleteUserBudget(Integer userid, Long budgetId);
} }
...@@ -23,4 +23,9 @@ public class UserBudgetService implements IUserBudgetService { ...@@ -23,4 +23,9 @@ public class UserBudgetService implements IUserBudgetService {
List<Long> budgets=userBudgetDao.selectBudgetByUserid(userid); List<Long> budgets=userBudgetDao.selectBudgetByUserid(userid);
return budgets; return budgets;
} }
@Override
public void deleteUserBudget(Integer userid, Long budgetId) {
userBudgetDao.deleteUserBudget(userid,budgetId);
}
} }
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="${pageContext.request.contextPath}/">创建预算</a></li> <li><a href="${pageContext.request.contextPath}/">创建预算</a></li>
<li class="active"><a href="${pageContext.request.contextPath}/Budget/HistoryPage">历史预算</a></li> <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}/Budget/Detail">修改预算</a></li>
<li><a href="${pageContext.request.contextPath}/Rule/">修改规则</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}/Test">测试</a></li>
...@@ -56,24 +56,47 @@ ...@@ -56,24 +56,47 @@
</nav> </nav>
<div id="budgetList"> <div id="budgetList">
<ul> <%--<ul>
<li v-for="budget in budgetList"> <li v-for="budget in budgetList">
<a v-bind:href="'${pageContext.request.contextPath}/Budget/Detail/'+budget.id"> <a v-bind:href="'${pageContext.request.contextPath}/Budget/Detail/'+budget.id">
{{budget.id}},创建时间:{{budget.date}} {{budget.id}},创建时间:{{budget.date}}
</a> </a>
</li> </li>
</ul> </ul>--%>
<table class="table table-hover">
<thead>
<tr>
<th>预算ID</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="budget in budgetList">
<td>{{budget.id}}</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-danger" @click="del(budget.id)">删除</button>
</td>
</tr>
</tbody>
</table>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var budgetListVue=new Vue({ var budgetListVue = new Vue({
el:"#budgetList", el: "#budgetList",
data:{ data: {
budgetList:[] budgetList: []
}, },
methods:{ methods: {
getBudgetHistory:function () { getBudgetHistory: function () {
/*alert("getBudgetHistory")*/ /*alert("getBudgetHistory")*/
this.$http.get("${pageContext.request.contextPath}/Budget/HistoryList").then( this.$http.get("${pageContext.request.contextPath}/Budget/HistoryList").then(
function (data) { function (data) {
...@@ -84,7 +107,19 @@ ...@@ -84,7 +107,19 @@
} }
) )
}, },
detail:function (budget) { detail: function (budget) {
},
del: function (budgetid) {
//alert(budgetid)
if (confirm("确定删除预算文件?")) {
this.$http.get("${pageContext.request.contextPath}/Budget/Delete/" + budgetid).then(
function (data) {
this.getBudgetHistory()
}, function (error) {
console.log(error)
}
)
}
} }
} }
}) })
......
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