From 0bb85479932f9438aa256d6d82332e04a57ef24d Mon Sep 17 00:00:00 2001 From: zhangshanxue Date: Wed, 9 Oct 2019 10:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=91=8A=E6=9F=A5=E8=AF=A2=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20=E9=99=90=E6=97=B6=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jmfy/controller/NoticeController.java | 73 ++++++++++++++- src/main/java/com/jmfy/dao/NoticeInfoDao.java | 4 + .../com/jmfy/dao/impl/CdkInfoDaoImpl.java | 10 +- .../com/jmfy/dao/impl/NoticeInfoDaoImpl.java | 20 ++++ src/main/java/com/jmfy/model/NoticeInfo.java | 45 +++++++++ .../java/com/jmfy/model/vo/NoticeInfoVo.java | 50 ++++++++++ .../resources/static/html/sendSysNotice.html | 31 +++++++ .../resources/static/html/toAddCDKGoods.html | 2 +- src/main/resources/templates/ShowNotice.html | 93 +++++++++++++++++++ src/main/resources/templates/index.html | 1 + 10 files changed, 322 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/jmfy/model/vo/NoticeInfoVo.java create mode 100644 src/main/resources/templates/ShowNotice.html diff --git a/src/main/java/com/jmfy/controller/NoticeController.java b/src/main/java/com/jmfy/controller/NoticeController.java index e667aef..99a68a9 100644 --- a/src/main/java/com/jmfy/controller/NoticeController.java +++ b/src/main/java/com/jmfy/controller/NoticeController.java @@ -1,26 +1,97 @@ package com.jmfy.controller; import com.jmfy.dao.impl.NoticeInfoDaoImpl; +import com.jmfy.model.NoticeInfo; +import com.jmfy.model.ServerMail; +import com.jmfy.model.vo.NoticeInfoVo; +import com.jmfy.model.vo.ServerMailVo; +import com.jmfy.utils.JsonUtil; +import com.jmfy.utils.SeqUtils; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; @Controller public class NoticeController { @Resource private NoticeInfoDaoImpl noticeInfoDao; + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Resource + private SeqUtils seqUtils; @RequestMapping(value = "/publishNotice", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int publishNotice(HttpServletRequest request) throws Exception { String content = request.getParameter("content1"); String title = request.getParameter("title1"); - noticeInfoDao.updateNoticeInfo(title,content); + int type = Integer.valueOf(request.getParameter("addType")); + if(type==0){ + noticeInfoDao.updateNoticeInfo(title,content); + return 0; + } + String startTime = JsonUtil.date3TimeStamp(request.getParameter("startTime")); + String endTime = JsonUtil.date3TimeStamp(request.getParameter("endTime")); + NoticeInfo noticeInfo = new NoticeInfo(); + String id =String.valueOf(seqUtils.getSequence("notice_id")); + if(id.equals("1")){ + id =String.valueOf(seqUtils.getSequence("notice_id")); + } + noticeInfo.set_id(id); + noticeInfo.setContent(content); + noticeInfo.setTitle(title); + noticeInfo.setStartTime(Long.parseLong(startTime)); + noticeInfo.setEndTime(Long.parseLong(endTime)); + noticeInfo.setLeve(type); + noticeInfoDao.updateNoticeInfo(noticeInfo); + return 0; + } + + @RequestMapping(value = "/noticeInfos", method = {RequestMethod.POST, RequestMethod.GET}) + public String sysMailCheck (HttpSession session, ModelMap map , HttpServletRequest request) throws Exception { + List infos = noticeInfoDao.getAllNotice(); + List noticeInfoVos = new ArrayList<>(); + for (NoticeInfo item :infos){ + NoticeInfoVo noticeInfoVo = new NoticeInfoVo(); + noticeInfoVo.setId(item.get_id()); + noticeInfoVo.setTitle(item.getTitle()); + noticeInfoVo.setContent(item.getContent()); + Date data = new Date(item.getStartTime()); + noticeInfoVo.setCreateTime(sdf.format(data)); + Date endData = new Date(item.getEndTime()); + noticeInfoVo.setEndTime(sdf.format(endData)); + if(item.get_id().equals("1")){ + noticeInfoVo.setCreateTime("常驻"); + noticeInfoVo.setEndTime("常驻"); + } + noticeInfoVos.add(noticeInfoVo); + } + map.put("noticeInfoVos",noticeInfoVos); + return "ShowNotice"; + } + + + + @RequestMapping(value = "/deleteNotice", method = {RequestMethod.POST, RequestMethod.GET}) + public @ResponseBody + int removeNotice(HttpServletRequest request) throws Exception { + HashMap parameterMap = JsonUtil.getInstence().getParameterMap(request); + String id = parameterMap.get("noticeId"); + if(null ==id||id.equals("1")){ + return -1; + } + noticeInfoDao.deleteNotice(Integer.valueOf(id)); return 0; } diff --git a/src/main/java/com/jmfy/dao/NoticeInfoDao.java b/src/main/java/com/jmfy/dao/NoticeInfoDao.java index 53a39a8..0537053 100644 --- a/src/main/java/com/jmfy/dao/NoticeInfoDao.java +++ b/src/main/java/com/jmfy/dao/NoticeInfoDao.java @@ -1,7 +1,11 @@ package com.jmfy.dao; +import com.jmfy.model.NoticeInfo; + public interface NoticeInfoDao { + void updateNoticeInfo(NoticeInfo noticeInfo) throws Exception; + void updateNoticeInfo(String title,String content) throws Exception; } diff --git a/src/main/java/com/jmfy/dao/impl/CdkInfoDaoImpl.java b/src/main/java/com/jmfy/dao/impl/CdkInfoDaoImpl.java index 62915ac..cc5790c 100644 --- a/src/main/java/com/jmfy/dao/impl/CdkInfoDaoImpl.java +++ b/src/main/java/com/jmfy/dao/impl/CdkInfoDaoImpl.java @@ -103,10 +103,10 @@ public class CdkInfoDaoImpl implements CdkInfoDao { @Override public void updateCdkGoodsInfo(SCdkInfo scdkInfo,int goodsId) throws Exception { - Update update = new Update(); - update.set("isAdd",1); - MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName); - Query query = new Query(Criteria.where("_id").is(goodsId)); - mongoTemplate.updateMulti(query, update, SCdkInfo.class); +// Update update = new Update(); +// update.set("isAdd",1); +// MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName); +// Query query = new Query(Criteria.where("_id").is(goodsId)); +// mongoTemplate.updateMulti(query, update, SCdkInfo.class); } } diff --git a/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java b/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java index 8fd03d2..432d246 100644 --- a/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java +++ b/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java @@ -3,6 +3,7 @@ package com.jmfy.dao.impl; import com.jmfy.dao.NoticeInfoDao; import com.jmfy.model.Constant; import com.jmfy.model.NoticeInfo; +import com.jmfy.model.ServerMail; import com.jmfy.utils.Connect; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; @@ -11,6 +12,7 @@ import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.List; @Component public class NoticeInfoDaoImpl implements NoticeInfoDao { @@ -18,6 +20,12 @@ public class NoticeInfoDaoImpl implements NoticeInfoDao { @Resource private Connect connect; public static final String dbName = Constant.dbName; + @Override + public void updateNoticeInfo(NoticeInfo noticeInfo) throws Exception { + MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName); + mongoTemplate.insert(noticeInfo); + } + @Override public void updateNoticeInfo(String title, String content) throws Exception { Update update = new Update(); @@ -29,5 +37,17 @@ public class NoticeInfoDaoImpl implements NoticeInfoDao { } + public void deleteNotice(int id) throws Exception { + MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName); + Query query = new Query(); + query.addCriteria(Criteria.where("_id").is(String.valueOf(id))); + mongoTemplate.remove(query, NoticeInfo.class); + } + + public List getAllNotice() throws Exception{ + MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName); + Query query = new Query(); + return mongoTemplate.find(query,NoticeInfo.class); + } } diff --git a/src/main/java/com/jmfy/model/NoticeInfo.java b/src/main/java/com/jmfy/model/NoticeInfo.java index 531f76f..b60c3c7 100644 --- a/src/main/java/com/jmfy/model/NoticeInfo.java +++ b/src/main/java/com/jmfy/model/NoticeInfo.java @@ -21,6 +21,19 @@ public class NoticeInfo { @Field(value = "title") private String title; + /** + * 0常驻 + * 1 中级 + * 2高级 + */ + @Field(value = "leve") + private int leve; + + @Field(value = "start_time") + private long startTime; + + @Field(value = "end_time") + private long endTime; public String getContent() { return content; @@ -37,4 +50,36 @@ public class NoticeInfo { public void setTitle(String title) { this.title = title; } + + public String get_id() { + return _id; + } + + public void set_id(String _id) { + this._id = _id; + } + + public int getLeve() { + return leve; + } + + public void setLeve(int leve) { + this.leve = leve; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getEndTime() { + return endTime; + } + + public void setEndTime(long endTime) { + this.endTime = endTime; + } } diff --git a/src/main/java/com/jmfy/model/vo/NoticeInfoVo.java b/src/main/java/com/jmfy/model/vo/NoticeInfoVo.java new file mode 100644 index 0000000..325d941 --- /dev/null +++ b/src/main/java/com/jmfy/model/vo/NoticeInfoVo.java @@ -0,0 +1,50 @@ +package com.jmfy.model.vo; + +public class NoticeInfoVo { + + private String id; + private String title; + private String content; + private String createTime; + private String endTime; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/src/main/resources/static/html/sendSysNotice.html b/src/main/resources/static/html/sendSysNotice.html index 9075bb9..e38b7c0 100644 --- a/src/main/resources/static/html/sendSysNotice.html +++ b/src/main/resources/static/html/sendSysNotice.html @@ -60,6 +60,37 @@ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +