Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
Added deadline date to admin setting and showing, and user showing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomriddle1234 committed Aug 26, 2019
1 parent e0a3406 commit 1840c06
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 15 deletions.
27 changes: 27 additions & 0 deletions src/main/java/com/ning/admin/action/AdminAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -150,6 +152,24 @@ public void downAllFile(HttpServletResponse response, HttpSession session) throw
zipOut.close();
}

// 更改截止时间

@RequestMapping("updateDeadlineByOID")
@RequiresPermissions("admin")
public @ResponseBody
Boolean updateDeadlineByOID(Integer oid, Date deadlineDate) throws Exception{
if (oid == null || deadlineDate == null){
throw new FileException("更改失败:参数不正确");
}

Map<String, Object> map = new HashMap<>(2);
map.put("odeadline", deadlineDate);
map.put("oid", oid);

adminService.updateDeadlineByOID(map);
return true;
}

/**
* 更改科目批次启用状态
* 该方法需要管理员权限
Expand Down Expand Up @@ -221,9 +241,16 @@ Boolean addOrderInfo(OrderInfo orderInfo) throws Exception {
if (orderInfo.getOstate() == null) {
return false;
}
if (orderInfo.getOdeadlinestr() == null){
return false;
}


int oid = (orderInfo.getOname().hashCode()) + (orderInfo.getOsubject().hashCode());
orderInfo.setOid(oid);
orderInfo.setOtime(new Date());

orderInfo.setOdeadlineFromStr(orderInfo.getOdeadlinestr());
adminService.addOrderInfo(orderInfo);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ning/admin/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ning.file.entity.History;
import com.ning.file.entity.OrderInfo;

import java.util.Date;
import java.util.List;
import java.util.Map;

Expand All @@ -29,6 +30,10 @@ public interface AdminService {
*/
List<OrderInfo> getOrderInfoEntity();



void updateDeadlineByOID(Map<String, Object> map);

/**
* 更新状态
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -48,6 +49,9 @@ public List<OrderInfo> getOrderInfoEntity() {
return orderInfoDao.getOrderInfoEntity();
}

@Override
public void updateDeadlineByOID(Map<String, Object> map) { orderInfoDao.updateDeadlineByOID(map);}

@Override
public void changeKeyByOID(Map<String, Object> map) {
orderInfoDao.changeKeyByOID(map);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/ning/file/dao/OrderInfoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ning.file.entity.OrderInfo;

import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -43,6 +44,9 @@ public interface OrderInfoDao {
*/
OrderInfo getOrderInfoEntityByOID(Integer oid);


OrderInfo updateDeadlineByOID(Map<String, Object> map);

/**
* 更新作业批次信息
* Map中的KEY可有的值
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/ning/file/entity/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class History implements Serializable {
* 上传时间
*/
private Date uptime;

private Date deadline;

/**
* 文件大小
*/
Expand Down Expand Up @@ -111,6 +114,10 @@ public void setUptime(Date uptime) {
this.uptime = uptime;
}

public Date getDeadline() {return deadline;}
public void setDeadline(Date deadline) {this.deadline = deadline;}


public Double getFilesize() {
return filesize;
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/ning/file/entity/OrderInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.ning.file.entity;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
Expand Down Expand Up @@ -31,6 +34,9 @@ public class OrderInfo implements Serializable {
*/
private Date otime;

private Date odeadline;
private String odeadlinestr;

public Boolean getOstate() {
return ostate;
}
Expand All @@ -43,6 +49,21 @@ public Date getOtime() {
return otime;
}

// 截止时间
public Date getOdeadline() {return odeadline;}
public void setOdeadline(Date odeadline) {this.odeadline = odeadline;}
public String getOdeadlinestr() {return odeadlinestr;}
public void setOdeadlinestr(String odeadlinestr) {this.odeadlinestr = odeadlinestr;}

// convert string to java date
//https://stackoverflow.com/questions/2318719/how-to-convert-timestamp-string-to-java-util-date
public void setOdeadlineFromStr(String odeadlinestr) throws ParseException {
// unix timestamp counts seconds, need to multiply 1000
Date deadlineDate = new Date(Long.parseLong(odeadlinestr) * 1000);
this.odeadline = deadlineDate;
}


public void setOtime(Date otime) {
this.otime = otime;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ning/file/service/impl/FileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ public void delEntityByHOID(Integer hoid) {
@Override
public List<History> getUserHistoryByUserId(String uId) {
return this.getUpListByUID(uId).stream().peek(history -> {
// here we could have the deadline
OrderInfo orderInfo = this.getOrderInfoEntityByOID(history.getHoid());

if (orderInfo != null) {
history.setOsubject(orderInfo.getOsubject());
history.setOname(orderInfo.getOname());
//设置文件扩展名
history.setFilepath(history.getFilepath().substring(history.getFilepath().lastIndexOf(".") + 1));

//set deadline
history.setDeadline(orderInfo.getOdeadline());
}
}).collect(Collectors.toList());
}
Expand Down
21 changes: 15 additions & 6 deletions src/main/resources/OrderInfoMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@
<result property="osubject" column="osubject"/>
<result property="ostate" column="ostate"/>
<result property="otime" column="otime"/>
<result property="odeadline" column="odeadline"/>
</resultMap>

<select id="getONameBySubject" parameterType="String" resultType="OrderInfo">
SELECT oid, oname, osubject, ostate, otime
SELECT oid, oname, osubject, ostate, otime, odeadline
FROM orderinfo
WHERE osubject = #{osubject}
AND ostate = true
</select>

<select id="getONameBySubjectOfAll" parameterType="String" resultType="OrderInfo">
SELECT oid, oname, osubject, ostate, otime
SELECT oid, oname, osubject, ostate, otime, odeadline
FROM orderinfo
WHERE osubject = #{osubject}
</select>

<select id="getOrderInfoEntity" resultType="OrderInfo">
SELECT oid, oname, osubject, ostate, otime
SELECT oid, oname, osubject, ostate, otime, odeadline
FROM orderinfo
</select>

<select id="getOrderInfoEntityByOID" resultType="OrderInfo" parameterType="int">
SELECT oid, oname, osubject, ostate, otime
SELECT oid, oname, osubject, ostate, otime, odeadline
FROM orderinfo
WHERE oid = #{oid}
</select>

<insert id="addOrderInfo" parameterType="OrderInfo">
INSERT INTO orderinfo(oid, oname, osubject, ostate, otime)
VALUES (#{oid}, #{oname}, #{osubject}, #{ostate}, #{otime})
INSERT INTO orderinfo(oid, oname, osubject, ostate, otime, odeadline)
VALUES (#{oid}, #{oname}, #{osubject}, #{ostate}, #{otime}, #{odeadline})
</insert>
<update id="changeKeyByOID" parameterType="map">
UPDATE orderinfo
Expand All @@ -48,6 +49,14 @@
</set>
WHERE oid = #{oid}
</update>
<update id="updateDeadlineByOID" parameterType="map">
UPDATE orderinfo
<set>
<if test="odeadline!=null">odeadline = #{odeadline}</if>
</set>
WHERE oid = #{oid}
</update>

<delete id="delOrderinfoByOID" parameterType="int">
DELETE
FROM orderinfo
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ body {
background: rgba(233, 233, 233, .6);
border-radius: 10px;
}

9 changes: 9 additions & 0 deletions src/main/webapp/css/subject.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.input-group {
padding-left: 15px !important;
padding-right: 15px !important;
}

.form-horizontal {
padding-left: 15px !important;
padding-right: 15px !important;
}
34 changes: 30 additions & 4 deletions src/main/webapp/jsp/addsubjectui.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
application.setAttribute("basePath", basePath);
%>

<link rel="stylesheet" href="${basePath }css/subject.css">

<form class="form-horizontal">
<h1>添加学科和类别:</h1>
<div class="alert alert-danger alert-dismissible fade in hidden" role="alert" id="adderrormessage">
Expand All @@ -15,17 +18,31 @@
<strong>添加失败!</strong> 请检查网络连接!
</div>
<div class="form-group">
<label for="osubject" class="col-sm-2 control-label">学科:</label>
<label for="osubject" class="col-sm-2 control-label">课程:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="osubject" placeholder="请输入学科...">
<input type="text" class="form-control" id="osubject" placeholder="请输入课程名称...">
</div>
</div>
<div class="form-group">
<label for="oname" class="col-sm-2 control-label">类别:</label>
<label for="oname" class="col-sm-2 control-label">批次:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="oname" placeholder="请输入类别...">
<input type="text" class="form-control" id="oname" placeholder="请输入作业名称...">
</div>
</div>

<input type="hidden" id="timezone" name="timezone" value="+08:00">

<div class="form-group">
<label for="oname" class="col-sm-2 control-label">截止:</label>

<div class='col-sm-10 input-group date' id='odeadline'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>

<div class="form-group">
<label for="oname" class="col-sm-2 control-label">状态:</label>
<div class="col-sm-10">
Expand All @@ -47,4 +64,13 @@
$("#closemessage_id").click(function () {
$("#adderrormessage").addClass("hidden");
});
$(function () {
$('#odeadline').datetimepicker({
locale: 'zh-cn'
});
});
</script>
18 changes: 17 additions & 1 deletion src/main/webapp/jsp/admin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<link rel="shortcut icon" href="${basePath }img/favicon.ico"/>
<link rel="bookmark" href="${basePath }img/favicon.ico"/>
<link href="${basePath }weblib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="${basePath }weblib/bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet">

<link rel="stylesheet" href="${basePath }css/base.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
Expand Down Expand Up @@ -158,17 +160,31 @@

<%@include file="footer.jsp" %>


<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="${basePath }weblib/jquery/jquery-3.2.1.min.js"></script>
<%--moment need to before bootstrap--%>
<script src="${basePath }weblib/moment/moment.min.js"></script>
<script src="${basePath }weblib/moment/zh-cn.js"></script>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="${basePath }weblib/bootstrap/js/bootstrap.min.js"></script>
<script src="${basePath }weblib/bootstrap/js/bootstrap-datetimepicker.min.js "></script>



<script src="${basePath }js/base.js"></script>
<script>
function add() {
var osubject = $("#osubject").val();
var oname = $("#oname").val();
var ostate = $("#ostate").val();
$.get("${basePath }addOrderInfo?osubject=" + osubject + "&oname=" + oname + "&ostate=" + ostate, function (data) {
// here need to convert js data-localtime to
// var odeadline = $("#odeadline").data("DateTimePicker").date().toDate().getTime(); // this gets wrong timestamp
var odeadline = $("#odeadline").data("DateTimePicker").date().unix();
console.log('odeadline string from JS: ', odeadline);
$.get("${basePath }addOrderInfo?osubject=" + osubject + "&oname=" + oname + "&ostate=" + ostate + "&odeadlinestr=" + odeadline, function (data) {
if (data) {
$('#addmodel').modal('hide');
$("#loadsubject").load("${basePath}subjectui");
Expand Down
9 changes: 7 additions & 2 deletions src/main/webapp/jsp/fileupload.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@
<div class="table-responsive">
<table class="table table-hover">
<tr>
<td>科目</td>
<td>次序</td>
<td>课程</td>
<td>作业名称</td>
<td>文件类型</td>
<td>上传时间</td>
<td>截止时间</td>
<td>文件大小</td>
<td>操作</td>
</tr>
Expand All @@ -152,6 +153,10 @@
<td><p>${userHistory.filepath}</p></td>
<td><p><fmt:formatDate value="${userHistory.uptime }" pattern="yyyy年MM月dd日 HH:mm:ss"/></p>
</td>
<td>
<p><fmt:formatDate value="${userHistory.deadline }" pattern="yyyy年MM月dd日 HH:mm:ss"/></p>
</td>

<td><p><fmt:formatNumber value="${(userHistory.filesize)/1024 }"
maxFractionDigits="2"/>Kb</p></td>
<td>
Expand Down
Loading

0 comments on commit 1840c06

Please sign in to comment.