Commit d5ba54ba authored by Huang's avatar Huang
Browse files

no commit message

parent da9d3b1b
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.iim.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.config.Global;
import com.jeespring.common.json.AjaxJson;
import com.jeespring.common.utils.DateUtils;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.utils.excel.ExportExcel;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.ChatHistory;
import com.jeespring.modules.iim.service.ChatHistoryService;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 聊天记录Controller
* * * * @author 黄炳桂 516821420@qq.com
* @version 2015-12-29
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/chatHistory")
public class ChatHistoryController extends AbstractBaseController {
@Autowired
private ChatHistoryService chatHistoryService;
@ModelAttribute
public ChatHistory get(@RequestParam(required=false) String id) {
ChatHistory entity = null;
if (StringUtils.isNotBlank(id)){
entity = chatHistoryService.get(id);
}
if (entity == null){
entity = new ChatHistory();
}
return entity;
}
/**
* 聊天列表页面
*/
@RequestMapping(value = {"list", ""})
public String list(ChatHistory chatHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
Page pg = new Page<ChatHistory>(request, response);
Page<ChatHistory> page = chatHistoryService.findPage(pg, chatHistory);
model.addAttribute("chatHistory", chatHistory);
model.addAttribute("page", page);
return "modules/iim/chatHistoryList";
}
/**
* 查看,增加,编辑聊天表单页面
*/
@RequestMapping(value = "form")
public String form(ChatHistory chatHistory, Model model) {
model.addAttribute("chatHistory", chatHistory);
return "modules/iim/chatHistoryForm";
}
/**
* 保存聊天
*/
@RequestMapping(value = "save")
public String save(ChatHistory chatHistory, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, chatHistory)){
return form(chatHistory, model);
}
chatHistoryService.save(chatHistory);
addMessage(redirectAttributes, "保存聊天成功");
return "redirect:"+Global.getAdminPath()+"/iim/chatHistory/?repage";
}
/**
* 删除聊天
*/
@RequestMapping(value = "delete")
public String delete(ChatHistory chatHistory, RedirectAttributes redirectAttributes) {
chatHistoryService.delete(chatHistory);
addMessage(redirectAttributes, "删除聊天成功");
return "redirect:"+Global.getAdminPath()+"/iim/chatHistory/?repage";
}
/**
* 批量删除聊天
*/
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
chatHistoryService.delete(chatHistoryService.get(id));
}
addMessage(redirectAttributes, "删除聊天成功");
return "redirect:"+Global.getAdminPath()+"/iim/chatHistory/?repage";
}
/**
* 导出excel文件
*/
@RequiresPermissions("iim:chatHistory:view")
@RequestMapping(value = "export", method=RequestMethod.POST)
public String exportFile(ChatHistory chatHistory, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "聊天"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<ChatHistory> page = chatHistoryService.findPage(new Page<ChatHistory>(request, response, -1), chatHistory);
new ExportExcel("聊天", ChatHistory.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出聊天记录失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/iim/chatHistory/?repage";
}
/**
* 获取聊天记录
*/
@ResponseBody
@RequestMapping(value = "getChats")
public AjaxJson getChats(ChatHistory chatHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<ChatHistory> page = chatHistoryService.findPage(new Page<ChatHistory>(request, response), chatHistory);
List<ChatHistory> list = page.getList();
for(ChatHistory c : list){
if("0".equals(c.getStatus())){
if(c.getUserid2().equals(UserUtils.getUser().getLoginName())){//把发送给我的信息标记为已读
c.setStatus("1");//标记为已读
chatHistoryService.save(c);
}
}
}
AjaxJson j = new AjaxJson();
j.setMsg("获取聊天记录成功!");
j.put("data", page.getList());
return j;
}
/**
* 获取未读条数
*/
@ResponseBody
@RequestMapping(value = "findUnReadCount")
public AjaxJson findUnReadCount(ChatHistory chatHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
AjaxJson j = new AjaxJson();
int size = chatHistoryService.findUnReadCount(chatHistory);
j.setMsg("获取未读条数成功!");
j.put("num", size);
return j;
}
/**
* 发送聊天内容(手机端)
*/
@ResponseBody
@RequestMapping(value = "sendChats")
public AjaxJson sendChats(ChatHistory chatHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
AjaxJson j = new AjaxJson();
j.setMsg("消息发送成功!");
chatHistory.setStatus("0");//标记未读
chatHistoryService.save(chatHistory);
return j;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.iim.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.config.Global;
import com.jeespring.common.utils.IdGen;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.Friend;
import com.jeespring.modules.iim.entity.Group;
import com.jeespring.modules.iim.entity.LayJson;
import com.jeespring.modules.sys.dao.UserDao;
import com.jeespring.modules.sys.entity.Office;
import com.jeespring.modules.sys.entity.User;
import com.jeespring.modules.sys.service.OfficeService;
import com.jeespring.modules.sys.service.SystemService;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 心电图实时显示查看Controller
* @author 黄炳桂 516821420@qq.com
* @version 2015-11-09
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/contact")
public class ContactController extends AbstractBaseController {
@Autowired
private SystemService systemService;
@Autowired
private UserDao userDao;
@Autowired
private OfficeService officeService;
/**
* 打开通讯录
* @param user
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = {"index", ""})
public String index(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
List<User> list = systemService.findUser(user);
model.addAttribute("list", list);
return "modules/iim/contacts";
}
/**
* 查找医生
* @param user
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = "searchUsers")
public String searchUsers(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
List<User> friends = userDao.searchUsers(user);
model.addAttribute("list", friends);
return "modules/iim/search_user";
}
/**
* 添加好友--->常用联系人
*/
@RequestMapping(value = "addFriend")
public String addFriend(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
User currentUser = UserUtils.getUser();
for(String id : idArray){
if(userDao.findFriend(currentUser.getId(), id) == null){
userDao.insertFriend(IdGen.uuid(), currentUser.getId(), id);//添加对方为好友
// userDao.insertFriend(IdGen.uuid(), id, currentUser.getId());//同时把自己添加为对方的好友
}
}
addMessage(redirectAttributes, "添加好友成功");
return "redirect:"+Global.getAdminPath()+"/iim/contact/myFriends/?repage";
}
/**
* 删除好友
*/
@RequestMapping(value = "delFriend")
public String delFriend(String id, RedirectAttributes redirectAttributes) {
User friend = UserUtils.get(id);
User currentUser = UserUtils.getUser();
if(friend != null && userDao.findFriend(currentUser.getId(), friend.getId()) != null){
userDao.deleteFriend(currentUser.getId(), friend.getId());//删除好友
// userDao.deleteFriend(friend.getId(), currentUser.getId());//同时把自己从对方的好友列表删除
}
return "redirect:"+Global.getAdminPath()+"/iim/contact/myFriends/?repage";
}
/**
* 打开我的好友列表--->常用联系人列表
* @param user
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = "myFriends")
public String myFriends(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
User currentUser = UserUtils.getUser();
List<User> friends = userDao.findFriends(currentUser);
model.addAttribute("list", friends);
return "modules/iim/myFriends";
}
/**
* 打开聊天窗口
* @param user
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = "layerIM")
public String layerIM(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
List<User> list = systemService.findUser(user);
model.addAttribute("list", list);
return "modules/iim/layerIM";
}
@RequestMapping(value="friend")
@ResponseBody
public LayJson getFriend(User user, HttpServletRequest request, HttpServletResponse response, Model model){
LayJson j = new LayJson();
j.setStatus(1);
//我的好友--->常用联系人
User currentUser = UserUtils.getUser();
List<User> friends = userDao.findFriends(currentUser);
Group friendGroup = new Group();
friendGroup.setName("我的好友");
friendGroup.setId(1);
friendGroup.setNums(friends.size());
for(User u : friends){
Friend friend = new Friend();
friend.setId(u.getLoginName());
friend.setName(u.getName());
friend.setFace(u.getPhoto());
friendGroup.getItem().add(friend);
}
j.getData().add(friendGroup);
List<Office> officeList = officeService.findList(true);
int index=1;
for(Office office : officeList){
user.setOffice(office);
List<User> users = userDao.findListByOffice(user);
Group group = new Group();
group.setName(office.getName());
group.setNums(users.size());
group.setId(++index);
for(User u : users){
Friend friend = new Friend();
friend.setId(u.getLoginName());
friend.setName(u.getName());
friend.setFace(u.getPhoto());
group.getItem().add(friend);
}
j.getData().add(group);
}
user.setOffice(null);
List<User> users = userDao.findListByOffice(user);
Group group = new Group();
group.setName("未分组");
group.setNums(users.size());
group.setId(++index);
for(User u : users){
Friend friend = new Friend();
friend.setId(u.getLoginName());
friend.setName(u.getName());
friend.setFace(u.getPhoto());
group.getItem().add(friend);
}
j.getData().add(group);
return j;
}
/**
* 群组列表接口 预留待开发
* @return
*/
@RequestMapping(value="group")
@ResponseBody
public LayJson getGroup(){
LayJson j = new LayJson();
j.setStatus(1);
return j;
}
/**
* 最近联系人接口 预留
* @return
*/
@RequestMapping(value="chatLog")
@ResponseBody
public LayJson getChatLog(){
LayJson j = new LayJson();
j.setStatus(1);
return j;
}
/**
* 群组成员接口 预留
* @return
*/
@RequestMapping(value="groups")
@ResponseBody
public LayJson getGroups(){
LayJson j = new LayJson();
j.setStatus(1);
return j;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.iim.web;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.config.Global;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.MailBox;
import com.jeespring.modules.iim.entity.MailCompose;
import com.jeespring.modules.iim.entity.MailPage;
import com.jeespring.modules.iim.service.MailBoxService;
import com.jeespring.modules.iim.service.MailComposeService;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 收件箱Controller
* * * * @author 黄炳桂 516821420@qq.com
* @version 2015-11-13
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/mailBox")
public class MailBoxController extends AbstractBaseController {
@Autowired
private MailComposeService mailComposeService;
@Autowired
private MailBoxService mailBoxService;
@ModelAttribute
public MailBox get(@RequestParam(required=false) String id) {
MailBox entity = null;
if (StringUtils.isNotBlank(id)){
entity = mailBoxService.get(id);
}
if (entity == null){
entity = new MailBox();
}
return entity;
}
@RequestMapping(value = {"list", ""})
public String list(MailBox mailBox, HttpServletRequest request, HttpServletResponse response, Model model) {
mailBox.setReceiver(UserUtils.getUser());
Page<MailBox> page = mailBoxService.findPage(new MailPage<MailBox>(request, response), mailBox);
model.addAttribute("page", page);
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
return "modules/iim/mailBoxList";
}
@RequestMapping(value = "detail")
public String detail(MailBox mailBox, Model model) {
if("0".equals(mailBox.getReadstatus())){//更改未读状态为已读状态
mailBox.setReadstatus("1");//1表示已读
mailBoxService.save(mailBox);
}
model.addAttribute("mailBox", mailBox);
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
return "modules/iim/mailBoxDetail";
}
@RequestMapping(value = "save")
public String save(MailBox mailBox, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, mailBox)){
return detail(mailBox, model);
}
Date date = new Date(System.currentTimeMillis());
mailBox.setSender( UserUtils.getUser());
mailBox.setSendtime(date);
mailBoxService.save(mailBox);
addMessage(redirectAttributes, "保存站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailBox/?repage";
}
@RequestMapping(value = "delete")
public String delete(MailBox mailBox, RedirectAttributes redirectAttributes) {
mailBoxService.delete(mailBox);
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailBox/?repage";
}
/**
* 批量删除
*/
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
mailBoxService.delete(mailBoxService.get(id));
}
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailBox/?repage";
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.iim.web;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.config.Global;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.MailBox;
import com.jeespring.modules.iim.entity.MailCompose;
import com.jeespring.modules.iim.entity.MailPage;
import com.jeespring.modules.iim.service.MailBoxService;
import com.jeespring.modules.iim.service.MailComposeService;
import com.jeespring.modules.iim.service.MailService;
import com.jeespring.modules.sys.entity.User;
import com.jeespring.modules.sys.service.SystemService;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 发件箱Controller
* @author 黄炳桂 516821420@qq.com
* @version 2015-11-13
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/mailCompose")
public class MailComposeController extends AbstractBaseController {
@Autowired
private MailComposeService mailComposeService;
@Autowired
private MailBoxService mailBoxService;
@Autowired
private SystemService systemService;
@Autowired
private MailService mailService;
@ModelAttribute
public MailCompose get(@RequestParam(required=false) String id) {
MailCompose entity = null;
if (StringUtils.isNotBlank(id)){
entity = mailComposeService.get(id);
}
if (entity == null){
entity = new MailCompose();
}
return entity;
}
/*
* 写站内信
*/
@RequestMapping(value = {"sendLetter"})
public String sendLetter(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
user = systemService.getUser(user.getId());
model.addAttribute("receiver", user);
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
return "modules/iim/mail_send";
}
/*
* 回复站内信
*/
@RequestMapping(value = {"replyLetter"})
public String replyLetter(MailBox mailBox, HttpServletRequest request, HttpServletResponse response, Model model) {
model.addAttribute("mailBox", mailBoxService.get(mailBox.getId()));
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
return "modules/iim/mail_reply";
}
@RequestMapping(value = {"list", ""})
public String list(MailCompose mailCompose, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<MailCompose> page = mailComposeService.findPage(new MailPage<MailCompose>(request, response), mailCompose);
model.addAttribute("page", page);
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
if(mailCompose.getStatus()== null || "0".equals(mailCompose.getStatus())){
return "modules/iim/mailDraftList";//草稿箱
}
return "modules/iim/mailComposeList";//已发送
}
@RequestMapping(value = "detail")//打开已发送信件
public String detail(MailCompose mailCompose, Model model) {
model.addAttribute("mailCompose", mailCompose);
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
return "modules/iim/mailComposeDetail";
}
@RequestMapping(value = "draftDetail")//打开草稿
public String draftDetail(MailCompose mailCompose, Model model) {
//查询未读的条数
MailBox serachBox = new MailBox();
serachBox.setReadstatus("0");
serachBox.setReceiver(UserUtils.getUser());
model.addAttribute("noReadCount", mailBoxService.getCount(serachBox));
//查询总条数
MailBox serachBox2 = new MailBox();
serachBox2.setReceiver(UserUtils.getUser());
model.addAttribute("mailBoxCount", mailBoxService.getCount(serachBox2));
//查询已发送条数
MailCompose serachBox3 = new MailCompose();
serachBox3.setSender(UserUtils.getUser());
serachBox3.setStatus("1");//已发送
model.addAttribute("mailComposeCount", mailComposeService.getCount(serachBox3));
//查询草稿箱条数
MailCompose serachBox4 = new MailCompose();
serachBox4.setSender(UserUtils.getUser());
serachBox4.setStatus("0");//草稿
model.addAttribute("mailDraftCount", mailComposeService.getCount(serachBox4));
mailCompose = mailComposeService.get(mailCompose.getId());
model.addAttribute("mailCompose", mailCompose);
return "modules/iim/mailDraftDetail";
}
@RequestMapping(value = "save")
public String save(MailCompose mailCompose, Model model, HttpServletRequest request, HttpServletResponse response) {
if (!beanValidator(model, mailCompose.getMail())){
return detail(mailCompose, model);
}
mailService.saveOnlyMain(mailCompose.getMail());
Date date = new Date(System.currentTimeMillis());
mailCompose.setSender(UserUtils.getUser());
mailCompose.setSendtime(date);
for(User receiver : mailCompose.getReceiverList()){
mailCompose.setReceiver(receiver);
mailCompose.setId(null);//标记为新纪录,每次往发件箱插入一条记录
mailComposeService.save(mailCompose);//0 显示在草稿箱,1 显示在已发送需同时保存到收信人的收件箱。
if("1".equals(mailCompose.getStatus()))//已发送,同时保存到收信人的收件箱
{
MailBox mailBox = new MailBox();
mailBox.setReadstatus("0");
mailBox.setReceiver(receiver);
mailBox.setSender(UserUtils.getUser());
mailBox.setMail(mailCompose.getMail());
mailBox.setSendtime(date);
mailBoxService.save(mailBox);
}
}
request.setAttribute("mailCompose", mailCompose);
return "modules/iim/mail_compose_success";
}
@RequestMapping(value = "delete")
public String delete(MailCompose mailCompose, RedirectAttributes redirectAttributes) {
mailComposeService.delete(mailCompose);
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailCompose/?repage&orderBy=sendtime desc&status="+mailCompose.getStatus();
}
/**
* 批量删除已发送
*/
@RequestMapping(value = "deleteAllCompose")
public String deleteAllCompose(String ids, Model model, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
mailComposeService.delete(mailComposeService.get(id));
}
addMessage(redirectAttributes, "删除邮件成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailCompose/?repage&status=1&orderBy=sendtime desc";
}
/**
* 批量删除草稿箱
*/
@RequestMapping(value = "deleteAllDraft")
public String deleteAllDraft(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
mailComposeService.delete(mailComposeService.get(id));
}
addMessage(redirectAttributes, "删除邮件成功");
return "redirect:"+Global.getAdminPath()+"/iim/mailCompose/?repage&status=0&orderBy=sendtime desc";
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.iim.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.config.Global;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.Mail;
import com.jeespring.modules.iim.service.MailService;
/**
* 发件箱Controller
* @author 黄炳桂 516821420@qq.com
* @version 2015-11-15
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/mail")
public class MailController extends AbstractBaseController {
@Autowired
private MailService mailService;
@ModelAttribute
public Mail get(@RequestParam(required=false) String id) {
Mail entity = null;
if (StringUtils.isNotBlank(id)){
entity = mailService.get(id);
}
if (entity == null){
entity = new Mail();
}
return entity;
}
@RequiresPermissions("iim:mail:view")
@RequestMapping(value = {"list", ""})
public String list(Mail mail, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Mail> page = mailService.findPage(new Page<Mail>(request, response), mail);
model.addAttribute("page", page);
return "modules/iim/mailList";
}
@RequiresPermissions("iim:mail:view")
@RequestMapping(value = "form")
public String form(Mail mail, Model model) {
model.addAttribute("mail", mail);
return "modules/iim/mailForm";
}
@RequestMapping(value = "save")
public String save(Mail mail, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, mail)){
return form(mail, model);
}
mailService.save(mail);
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mail/?repage";
}
@RequestMapping(value = "delete")
public String delete(Mail mail, RedirectAttributes redirectAttributes) {
mailService.delete(mail);
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mail/?repage";
}
/**
* 批量删除
*/
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
mailService.delete(mailService.get(id));
}
addMessage(redirectAttributes, "删除站内信成功");
return "redirect:"+Global.getAdminPath()+"/iim/mail/?repage";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeespring.modules.iim.web;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.modules.iim.entity.MyCalendar;
import com.jeespring.modules.iim.service.MyCalendarService;
import com.jeespring.modules.iim.utils.DateUtil;
import com.jeespring.modules.sys.utils.UserUtils;
/**
* 日历Controller
*
* @author liugf
* @version 2016-04-19
*/
@Controller
@RequestMapping(value = "${adminPath}/iim/myCalendar")
public class MyCalendarController extends AbstractBaseController {
@Autowired
private MyCalendarService myCalendarService;
@ModelAttribute
public MyCalendar get(@RequestParam(required = false) String id) {
MyCalendar entity = null;
if (StringUtils.isNotBlank(id)) {
entity = myCalendarService.get(id);
}
if (entity == null) {
entity = new MyCalendar();
}
return entity;
}
/**
* 日历页面
*/
@RequestMapping(value = { "index", "" })
public String index(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
return "modules/iim/myCalendar";
}
/**
* 查看,增加,编辑日历信息表单页面
*/
@RequestMapping(value = "addform")
public String addform(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
String date = request.getParameter("date");
String enddate = request.getParameter("end");
if (date.equals(enddate)) {
enddate = "";
}
String display = "";
String chk = "";
if ("".equals(enddate)) {
display = "style=\"display:none\"";
enddate = date;
} else {
chk = "checked";
}
model.addAttribute("date", date);
model.addAttribute("display", display);
model.addAttribute("chk", chk);
model.addAttribute("enddate", enddate);
model.addAttribute("myCalendar", myCalendar);
return "modules/iim/myCalendarForm-add";
}
@RequestMapping(value = "editform")
public String editform(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
String title = myCalendar.getTitle();// 事件标题
String start = myCalendar.getStart();// 事件开始时间
String end = myCalendar.getEnd();// 结束时间
String allDay = myCalendar.getAdllDay();// 是否为全天事件
String color = myCalendar.getColor();// 事件的背景
String start_d = "";
String start_h = "";
String start_m = "";
String end_d = "";
String end_h = "";
String end_m = "";
if ("1".equals(allDay) && !"".equals(end)) {
start_d = start;
end_d = end;
} else if ("1".equals(allDay) && "".equals(end)) {
start_d = start;
} else if ("0".equals(allDay) && !"".equals(end)) {
start_d = start.substring(0, 10);
start_h = start.substring(11, 13);
start_m = start.substring(14, 16);
end_d = end.substring(0, 10);
end_h = end.substring(11, 13);
end_m = end.substring(14, 16);
} else {
start_d = start.substring(0, 10);
start_h = start.substring(11, 13);
start_m = start.substring(14, 16);
}
model.addAttribute("title", title);
model.addAttribute("color", color);
model.addAttribute("start_d", start_d);
model.addAttribute("start_h", start_h);
model.addAttribute("start_m", start_m);
model.addAttribute("end", end_d);
model.addAttribute("end_d", end_d);
model.addAttribute("end_h", end_h);
model.addAttribute("end_m", end_m);
model.addAttribute("allDay", allDay);
return "modules/iim/myCalendarForm-edit";
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "findList")
protected List<MyCalendar> doPost(MyCalendar myCalendar,
HttpServletRequest request, HttpServletResponse response,
Model model) throws ServletException, IOException {
myCalendar.setUser(UserUtils.getUser());
List<MyCalendar> list = myCalendarService.findList(myCalendar);
return list;
}
/**
* 新建日历
*/
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "add")
public String add(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
String events = request.getParameter("event");// 事件内容
String isallday = request.getParameter("isallday");// 是否是全天事件
String isend = request.getParameter("isend");// 是否有结束时间
String startdate = request.getParameter("startdate");
String enddate = request.getParameter("enddate");
String s_time = request.getParameter("s_hour") + ":"
+ request.getParameter("s_minute") + ":00";
String e_time = request.getParameter("e_hour") + ":"
+ request.getParameter("e_minute") + ":00";
String start = "";
String end = "";
if ("1".equals(isallday) && "1".equals(isend)) {
start = startdate;
end = enddate;
} else if ("1".equals(isallday) && isend == null) {
start = startdate;
} else if (isallday == null && "1".equals(isend)) {
start = startdate + " " + s_time;
end = enddate + " " + e_time;
isallday = "0";
} else {
start = startdate + " " + s_time;
isallday = "0";
}
String[] colors = { "#360", "#f30", "#06c" };
int index = (int) (Math.random() * colors.length);
myCalendar.setTitle(events);
myCalendar.setStart(start);
myCalendar.setEnd(end);
myCalendar.setAdllDay(isallday);
myCalendar.setColor(colors[index]);
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
return "1";
}
/**
* 编辑日历
*/
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "edit")
public String edit(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
String events = request.getParameter("event");// 事件内容
String isallday = request.getParameter("isallday");// 是否是全天事件
String isend = request.getParameter("isend");// 是否有结束时间
String startdate = request.getParameter("startdate");
String enddate = request.getParameter("enddate");
String s_time = request.getParameter("s_hour") + ":"
+ request.getParameter("s_minute") + ":00";
String e_time = request.getParameter("e_hour") + ":"
+ request.getParameter("e_minute") + ":00";
String start = "";
String end = "";
if ("1".equals(isallday) && "1".equals(isend)) {
start = startdate;
end = enddate;
} else if ("1".equals(isallday) && isend == null) {
start = startdate;
} else if (isallday == null && "1".equals(isend)) {
start = startdate + " " + s_time;
end = enddate + " " + e_time;
isallday = "0";
} else {
start = startdate + " " + s_time;
isallday = "0";
}
String[] colors = { "#360", "#f30", "#06c" };
int index = (int) (Math.random() * colors.length);
myCalendar.setTitle(events);
myCalendar.setStart(start);
myCalendar.setEnd(end);
myCalendar.setAdllDay(isallday);
myCalendar.setColor(colors[index]);
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
model.addAttribute("myCalendar", myCalendar);
return "1";
}
/**
* 删除日历
*/
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "del")
public String del(MyCalendar myCalendar,
RedirectAttributes redirectAttributes) {
myCalendarService.delete(myCalendar);
return "1";
}
/**
* 縮放日歷
*/
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "resize")
public String resize(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
Integer daydiff = Integer.parseInt(request.getParameter("daydiff")) * 24 * 60 * 60;
Integer minudiff = Integer.parseInt(request.getParameter("minudiff")) * 60;
String start = myCalendar.getStart();
long lstart = DateUtil.string2long(start);
String end = myCalendar.getEnd();
Integer difftime = daydiff + minudiff;
if ("".equals(end)) {
myCalendar.setEnd(DateUtil.long2string(lstart + difftime));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
} else {
long lend = DateUtil.string2long(end);
myCalendar.setEnd(DateUtil.long2string(lend + difftime));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
}
return "1";
}
/**
* 拖拽日历
*/
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "drag")
public String drag(MyCalendar myCalendar, HttpServletRequest request,
HttpServletResponse response, Model model) {
Integer daydiff = Integer.parseInt(request.getParameter("daydiff")) * 24 * 60 * 60;
Integer minudiff = Integer.parseInt(request.getParameter("minudiff")) * 60;
String allday = request.getParameter("allday");
String start = myCalendar.getStart();
long lstart = DateUtil.string2long(start);
String end = myCalendar.getEnd();
if ("true".equals(allday)) {
if ("".equals(end)) {
myCalendar.setStart(DateUtil.long2string(lstart + daydiff));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
} else {
long lend = DateUtil.string2long(end);
myCalendar.setStart(DateUtil.long2string(lstart + daydiff));
myCalendar.setEnd(DateUtil.long2string(lend + daydiff));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
}
} else {
Integer difftime = daydiff + minudiff;
if ("".equals(end)) {
myCalendar.setStart(DateUtil.long2string(lstart + difftime));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
} else {
long lend = DateUtil.string2long(end);
myCalendar.setStart(DateUtil.long2string(lstart + difftime));
myCalendar.setEnd(DateUtil.long2string(lend + difftime));
myCalendar.setUser(UserUtils.getUser());
myCalendarService.save(myCalendar);
}
}
return "1";
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.dao;
import com.jeespring.common.persistence.InterfaceBaseDao;
import org.apache.ibatis.annotations.Mapper;
import com.jeespring.modules.job.entity.SysJob;
/**
* 定时任务调度DAO接口
* @author JeeSpring
* @version 2018-08-16
*/
@Mapper
public interface SysJobDao extends InterfaceBaseDao<SysJob> {
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.dao;
import com.jeespring.common.persistence.InterfaceBaseDao;
import org.apache.ibatis.annotations.Mapper;
import com.jeespring.modules.job.entity.SysJobLog;
/**
* 定时任务调度日志表DAO接口
* @author JeeSpring
* @version 2018-08-16
*/
@Mapper
public interface SysJobLogDao extends InterfaceBaseDao<SysJobLog> {
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.entity;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.common.utils.excel.annotation.ExcelField;
import com.jeespring.modules.sys.utils.DictUtils;
/**
* 定时任务调度Entity
* @author JeeSpring
* @version 2018-08-16
*/
public class SysJob extends AbstractBaseEntity<SysJob> {
private static final long serialVersionUID = 1L;
private String jobName; // 任务名称
private String jobGroup; // 任务组名
private String methodName; // 任务方法
private String methodParams; // 方法参数
private String cronExpression; // cron执行表达式
private String misfirePolicy; // 计划执行错误策略(0默认 1继续 2等待 3放弃)
private String misfirePolicyLabel; // 计划执行错误策略(0默认 1继续 2等待 3放弃)Label
private String misfirePolicyPicture; // 计划执行错误策略(0默认 1继续 2等待 3放弃)Picture
private String status; // 状态(0正常 1暂停)
private String statusLabel; // 状态(0正常 1暂停)Label
private String statusPicture; // 状态(0正常 1暂停)Picture
private String remark; // 备注信息
private java.util.Date beginCreateDate; // 开始 创建时间
private java.util.Date endCreateDate; // 结束 创建时间
private java.util.Date beginUpdateDate; // 开始 更新时间
private java.util.Date endUpdateDate; // 结束 更新时间
public SysJob() {
super();
}
public SysJob(String id){
super(id);
}
@Length(min=1, max=64, message="任务名称长度必须介于 1 和 64 之间")
@ExcelField(title="任务名称", align=2, sort=1)
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
@Length(min=1, max=64, message="任务组名长度必须介于 1 和 64 之间")
@ExcelField(title="任务组名", align=2, sort=2)
public String getJobGroup() {
return jobGroup;
}
public void setJobGroup(String jobGroup) {
this.jobGroup = jobGroup;
}
@Length(min=0, max=500, message="任务方法长度必须介于 0 和 500 之间")
@ExcelField(title="任务方法", align=2, sort=3)
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
@Length(min=0, max=200, message="方法参数长度必须介于 0 和 200 之间")
@ExcelField(title="方法参数", align=2, sort=4)
public String getMethodParams() {
return methodParams;
}
public void setMethodParams(String methodParams) {
this.methodParams = methodParams;
}
@Length(min=0, max=255, message="cron执行表达式长度必须介于 0 和 255 之间")
@ExcelField(title="cron执行表达式", align=2, sort=5)
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression;
}
@Length(min=0, max=20, message="计划执行错误策略(0默认 1继续 2等待 3放弃)长度必须介于 0 和 20 之间")
@ExcelField(title="计划执行错误策略(0默认 1继续 2等待 3放弃)", align=2, sort=6)
public String getMisfirePolicy() {
return misfirePolicy;
}
public void setMisfirePolicy(String misfirePolicy) {
this.misfirePolicy = misfirePolicy;
}
@Length(min=0, max=1, message="状态(0正常 1暂停)长度必须介于 0 和 1 之间")
@ExcelField(title="状态(0正常 1暂停)", dictType="job_status", align=2, sort=7)
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatusLabel() {
return DictUtils.getDictLabel(status,"job_status","");
}
public String getStatusPicture() {
return DictUtils.getDictPicture(status,"job_status","");
}
public String getMisfirePolicyLabel() {
return DictUtils.getDictLabel(misfirePolicy,"misfire_policy","");
}
public String getMisfirePolicyPicture() {
return DictUtils.getDictPicture(misfirePolicy,"misfire_policy","");
}
@Length(min=0, max=500, message="备注信息长度必须介于 0 和 500 之间")
@ExcelField(title="备注信息", align=2, sort=12)
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getBeginCreateDate() {
return beginCreateDate;
}
public void setBeginCreateDate(Date beginCreateDate) {
this.beginCreateDate = beginCreateDate;
}
public Date getEndCreateDate() {
return endCreateDate;
}
public void setEndCreateDate(Date endCreateDate) {
this.endCreateDate = endCreateDate;
}
public Date getBeginUpdateDate() {
return beginUpdateDate;
}
public void setBeginUpdateDate(Date beginUpdateDate) {
this.beginUpdateDate = beginUpdateDate;
}
public Date getEndUpdateDate() {
return endUpdateDate;
}
public void setEndUpdateDate(Date endUpdateDate) {
this.endUpdateDate = endUpdateDate;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.entity;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jeespring.common.persistence.AbstractBaseEntity;
import com.jeespring.common.utils.excel.annotation.ExcelField;
import com.jeespring.modules.sys.utils.DictUtils;
/**
* 定时任务调度日志表Entity
* @author JeeSpring
* @version 2018-08-16
*/
public class SysJobLog extends AbstractBaseEntity<SysJobLog> {
private static final long serialVersionUID = 1L;
private String jobName; // 任务名称
private String jobGroup; // 任务组名
private String methodName; // 任务方法
private String methodParams; // 方法参数
private String jobMessage; // 日志信息
private String status; // 执行状态(0正常 1失败)
private String statusLabel; // 执行状态(0正常 1失败)Label
private String statusPicture; // 执行状态(0正常 1失败)Picture
private String exceptionInfo; // 异常信息
private java.util.Date beginCreateDate; // 开始 创建时间
private java.util.Date endCreateDate; // 结束 创建时间
public SysJobLog() {
super();
}
public SysJobLog(String id){
super(id);
}
@Length(min=1, max=64, message="任务名称长度必须介于 1 和 64 之间")
@ExcelField(title="任务名称", align=2, sort=1)
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
@Length(min=1, max=64, message="任务组名长度必须介于 1 和 64 之间")
@ExcelField(title="任务组名", align=2, sort=2)
public String getJobGroup() {
return jobGroup;
}
public void setJobGroup(String jobGroup) {
this.jobGroup = jobGroup;
}
@Length(min=0, max=500, message="任务方法长度必须介于 0 和 500 之间")
@ExcelField(title="任务方法", align=2, sort=3)
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
@Length(min=0, max=200, message="方法参数长度必须介于 0 和 200 之间")
@ExcelField(title="方法参数", align=2, sort=4)
public String getMethodParams() {
return methodParams;
}
public void setMethodParams(String methodParams) {
this.methodParams = methodParams;
}
@Length(min=0, max=500, message="日志信息长度必须介于 0 和 500 之间")
@ExcelField(title="日志信息", align=2, sort=5)
public String getJobMessage() {
return jobMessage;
}
public void setJobMessage(String jobMessage) {
this.jobMessage = jobMessage;
}
@Length(min=0, max=1, message="执行状态(0正常 1失败)长度必须介于 0 和 1 之间")
@ExcelField(title="执行状态(0正常 1失败)", dictType="job_status", align=2, sort=6)
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatusLabel() {
return DictUtils.getDictLabel(status,"job_status","");
}
public String getStatusPicture() {
return DictUtils.getDictPicture(status,"job_status","");
}
@ExcelField(title="异常信息", align=2, sort=7)
public String getExceptionInfo() {
return exceptionInfo;
}
public void setExceptionInfo(String exceptionInfo) {
this.exceptionInfo = exceptionInfo;
}
public Date getBeginCreateDate() {
return beginCreateDate;
}
public void setBeginCreateDate(Date beginCreateDate) {
this.beginCreateDate = beginCreateDate;
}
public Date getEndCreateDate() {
return endCreateDate;
}
public void setEndCreateDate(Date endCreateDate) {
this.endCreateDate = endCreateDate;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.rest;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.jeespring.common.utils.DateUtils;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.utils.excel.ExportExcel;
import com.jeespring.common.utils.excel.ImportExcel;
import com.jeespring.modules.job.entity.SysJobLog;
import com.jeespring.modules.job.service.SysJobLogService;
import org.springframework.web.bind.annotation.RestController;
import com.jeespring.common.web.Result;
import com.jeespring.common.web.ResultFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
/**
* 定时任务调度日志表Controller
* @author JeeSpring
* @version 2018-08-16
*/
@RestController
@RequestMapping(value = "/rest/job/sysJobLog")
@Api(value="定时任务调度日志接口", description="定时任务调度日志接口")
public class SysJobLogRestController extends AbstractBaseController {
@Autowired
private SysJobLogService sysJobLogService;
/**
* 定时任务调度日志信息
*/
@RequestMapping(value = {"get"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度日志信息(Content-Type为text/html)", notes="定时任务调度日志信息(Content-Type为text/html)")
@ApiImplicitParam(name = "id", value = "定时任务调度日志id", required = false, dataType = "String",paramType="query")
public Result getRequestParam(@RequestParam(required=false) String id) {
return get(id);
}
@RequestMapping(value = {"get/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度日志信息(Content-Type为application/json)", notes="定时任务调度日志信息(Content-Type为application/json)")
@ApiImplicitParam(name = "id", value = "定时任务调度日志id", required = false, dataType = "String",paramType="body")
public Result getRequestBody(@RequestBody(required=false) String id) {
return get(id);
}
private Result get(String id) {
SysJobLog entity = null;
if (StringUtils.isNotBlank(id)){
entity = sysJobLogService.getCache(id);
//entity = sysJobLogService.get(id);
}
if (entity == null){
entity = new SysJobLog();
}
Result result = ResultFactory.getSuccessResult();
result.setResultObject(entity);
return result;
}
/**
* 定时任务调度日志列表(不包含页信息)
*/
//RequiresPermissions("job:sysJobLog:findList")
@RequestMapping(value = {"findList"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度日志列表(不包含页信息)(Content-Type为text/html)", notes="定时任务调度日志列表(不包含页信息)(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result findListRequestParam(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
return findList( sysJobLog,model);
}
@RequestMapping(value = {"findList/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度日志列表(不包含页信息)(Content-Type为application/json)", notes="定时任务调度日志列表(不包含页信息)(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result findListRequestBody(@RequestBody SysJobLog sysJobLog, Model model) {
return findList( sysJobLog,model);
}
private Result findList(SysJobLog sysJobLog, Model model) {
List<SysJobLog> list = sysJobLogService.findListCache(sysJobLog);
//List<SysJobLog> list = sysJobLogService.findList(sysJobLog);
Result result = ResultFactory.getSuccessResult();
result.setResultObject(list);
return result;
}
/**
* 定时任务调度日志列表(包含页信息)
*/
//RequiresPermissions("job:sysJobLog:list")
@RequestMapping(value = {"list"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度日志列表(包含页信息)(Content-Type为text/html)", notes="定时任务调度日志列表(包含页信息)(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result listRequestParam(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
return list(sysJobLog,model);
}
@RequestMapping(value = {"list/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度日志列表(包含页信息)(Content-Type为application/json)", notes="定时任务调度日志列表(包含页信息)(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result listRequestBody(@RequestBody SysJobLog sysJobLog, Model model) {
return list(sysJobLog,model);
}
private Result list(SysJobLog sysJobLog, Model model) {
Page<SysJobLog> page = sysJobLogService.findPageCache(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
Result result = ResultFactory.getSuccessResult();
result.setResultObject(page);
return result;
}
/**
* 定时任务调度日志获取列表第一条记录
*/
//RequiresPermissions("job:sysJobLog:listFrist")
@RequestMapping(value = {"listFrist"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度日志获取列表第一条记录(Content-Type为text/html)", notes="定时任务调度日志获取列表第一条记录(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result listFristRequestParam(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
return listFrist(sysJobLog,model);
}
@RequestMapping(value = {"listFrist/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度日志获取列表第一条记录(Content-Type为application/json)", notes="定时任务调度日志获取列表第一条记录(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result listFristRequestBody(@RequestBody SysJobLog sysJobLog, Model model) {
return listFrist(sysJobLog,model);
}
private Result listFrist(SysJobLog sysJobLog, Model model) {
Page<SysJobLog> page = sysJobLogService.findPageCache(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
Result result = ResultFactory.getSuccessResult();
if(page.getList().size()>0){
result.setResultObject(page.getList().get(0));
}else{
result=ResultFactory.getErrorResult("没有记录!");
}
return result;
}
/**
* 保存定时任务调度日志
*/
//RequiresPermissions(value={"job:sysJobLog:add","job:sysJobLog:edit"},logical=Logical.OR)
@RequestMapping(value = "save",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="保存定时任务调度日志(Content-Type为text/html)", notes="保存定时任务调度日志(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result saveRequestParam(SysJobLog sysJobLog, Model model, RedirectAttributes redirectAttributes) {
return save(sysJobLog,model,redirectAttributes);
}
@RequestMapping(value = "save/json",method ={RequestMethod.POST})
@ApiOperation(value="保存定时任务调度日志(Content-Type为application/json)", notes="保存定时任务调度日志(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result saveRequestBody(@RequestBody SysJobLog sysJobLog, Model model, RedirectAttributes redirectAttributes) {
return save(sysJobLog,model,redirectAttributes);
}
private Result save(SysJobLog sysJobLog, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, sysJobLog)){
Result result = ResultFactory.getErrorResult("数据验证失败");
}
sysJobLogService.save(sysJobLog);
Result result = ResultFactory.getSuccessResult("保存定时任务调度日志成功");
return result;
}
/**
* 删除定时任务调度日志
*/
//RequiresPermissions("job:sysJobLog:del")
@RequestMapping(value = "delete",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="删除定时任务调度日志(Content-Type为text/html)", notes="删除定时任务调度日志(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result deleteRequestParam(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
return delete(sysJobLog,redirectAttributes);
}
@RequestMapping(value = "delete/json",method ={RequestMethod.POST})
@ApiOperation(value="删除定时任务调度日志(Content-Type为application/json)", notes="删除定时任务调度日志(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result deleteRequestBody(@RequestBody SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
return delete(sysJobLog,redirectAttributes);
}
private Result delete(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
sysJobLogService.delete(sysJobLog);
Result result = ResultFactory.getSuccessResult("删除定时任务调度日志成功");
return result;
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteByLogic",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="逻辑删除定时任务调度日志(Content-Type为text/html)", notes="逻辑删除定时任务调度日志(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="query")
public Result deleteByLogicRequestParam(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
return deleteByLogic(sysJobLog,redirectAttributes);
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteByLogic/json",method ={RequestMethod.POST})
@ApiOperation(value="逻辑删除定时任务调度日志(Content-Type为application/json)", notes="逻辑删除定时任务调度日志(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJobLog", value = "定时任务调度日志", dataType = "SysJobLog",paramType="body")
public Result deleteByLogicRequestBody(@RequestBody SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
return deleteByLogic(sysJobLog,redirectAttributes);
}
private Result deleteByLogic(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
sysJobLogService.deleteByLogic(sysJobLog);
Result result = ResultFactory.getSuccessResult("删除定时任务调度日志成功");
return result;
}
/**
* 批量删除定时任务调度日志
*/
//RequiresPermissions("job:sysJobLog:del")
@RequestMapping(value = "deleteAll",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="批量删除定时任务调度日志(Content-Type为text/html)", notes="批量删除定时任务调度日志(Content-Type为text/html)")
@ApiImplicitParam(name = "ids", value = "定时任务调度日志ids,用,隔开", required = false, dataType = "String",paramType="query")
public Result deleteAllRequestParam(String ids, RedirectAttributes redirectAttributes) {
return deleteAll(ids,redirectAttributes);
}
@RequestMapping(value = "deleteAll/json",method ={RequestMethod.POST})
@ApiOperation(value="批量删除定时任务调度日志(Content-Type为application/json)", notes="批量删除定时任务调度日志(Content-Type为application/json)")
@ApiImplicitParam(name = "ids", value = "定时任务调度日志ids,用,隔开", required = false, dataType = "String",paramType="body")
public Result deleteAllRequestBody(@RequestBody String ids, RedirectAttributes redirectAttributes) {
return deleteAll(ids,redirectAttributes);
}
private Result deleteAll(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobLogService.delete(sysJobLogService.get(id));
}
Result result = ResultFactory.getSuccessResult("删除定时任务调度日志成功");
return result;
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteAllByLogic",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="逻辑批量删除定时任务调度日志(Content-Type为text/html)", notes="逻辑批量删除定时任务调度日志(Content-Type为text/html)")
@ApiImplicitParam(name = "ids", value = "定时任务调度日志ids,用,隔开", required = false, dataType = "String",paramType="query")
public Result deleteAllByLogicRequestParam(String ids, RedirectAttributes redirectAttributes) {
return deleteAllByLogic(ids,redirectAttributes);
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteAllByLogic/json",method ={RequestMethod.POST})
@ApiOperation(value="逻辑批量删除定时任务调度日志(Content-Type为application/json)", notes="逻辑批量删除定时任务调度日志(Content-Type为application/json)")
@ApiImplicitParam(name = "ids", value = "定时任务调度日志ids,用,隔开", required = false, dataType = "String",paramType="body")
public Result deleteAllByLogicRequestBody(@RequestBody String ids, RedirectAttributes redirectAttributes) {
return deleteAllByLogic(ids,redirectAttributes);
}
private Result deleteAllByLogic(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobLogService.deleteByLogic(sysJobLogService.get(id));
}
Result result = ResultFactory.getSuccessResult("删除定时任务调度日志成功");
return result;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.rest;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.jeespring.common.utils.DateUtils;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.utils.excel.ExportExcel;
import com.jeespring.common.utils.excel.ImportExcel;
import com.jeespring.modules.job.entity.SysJob;
import com.jeespring.modules.job.service.SysJobService;
import org.springframework.web.bind.annotation.RestController;
import com.jeespring.common.web.Result;
import com.jeespring.common.web.ResultFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
/**
* 定时任务调度Controller
* @author JeeSpring
* @version 2018-08-16
*/
@RestController
@RequestMapping(value = "/rest/job/sysJob")
@Api(value="定时任务调度接口", description="定时任务调度接口")
public class SysJobRestController extends AbstractBaseController {
@Autowired
private SysJobService sysJobService;
/**
* 定时任务调度信息
*/
@RequestMapping(value = {"get"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度信息(Content-Type为text/html)", notes="定时任务调度信息(Content-Type为text/html)")
@ApiImplicitParam(name = "id", value = "定时任务调度id", required = false, dataType = "String",paramType="query")
public Result getRequestParam(@RequestParam(required=false) String id) {
return get(id);
}
@RequestMapping(value = {"get/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度信息(Content-Type为application/json)", notes="定时任务调度信息(Content-Type为application/json)")
@ApiImplicitParam(name = "id", value = "定时任务调度id", required = false, dataType = "String",paramType="body")
public Result getRequestBody(@RequestBody(required=false) String id) {
return get(id);
}
private Result get(String id) {
SysJob entity = null;
if (StringUtils.isNotBlank(id)){
entity = sysJobService.getCache(id);
//entity = sysJobService.get(id);
}
if (entity == null){
entity = new SysJob();
}
Result result = ResultFactory.getSuccessResult();
result.setResultObject(entity);
return result;
}
/**
* 定时任务调度列表(不包含页信息)
*/
//RequiresPermissions("job:sysJob:findList")
@RequestMapping(value = {"findList"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度列表(不包含页信息)(Content-Type为text/html)", notes="定时任务调度列表(不包含页信息)(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result findListRequestParam(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
return findList( sysJob,model);
}
@RequestMapping(value = {"findList/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度列表(不包含页信息)(Content-Type为application/json)", notes="定时任务调度列表(不包含页信息)(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result findListRequestBody(@RequestBody SysJob sysJob, Model model) {
return findList( sysJob,model);
}
private Result findList(SysJob sysJob, Model model) {
List<SysJob> list = sysJobService.findListCache(sysJob);
//List<SysJob> list = sysJobService.findList(sysJob);
Result result = ResultFactory.getSuccessResult();
result.setResultObject(list);
return result;
}
/**
* 定时任务调度列表(包含页信息)
*/
//RequiresPermissions("job:sysJob:list")
@RequestMapping(value = {"list"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度列表(包含页信息)(Content-Type为text/html)", notes="定时任务调度列表(包含页信息)(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result listRequestParam(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
return list(sysJob,model);
}
@RequestMapping(value = {"list/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度列表(包含页信息)(Content-Type为application/json)", notes="定时任务调度列表(包含页信息)(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result listRequestBody(@RequestBody SysJob sysJob, Model model) {
return list(sysJob,model);
}
private Result list(SysJob sysJob, Model model) {
Page<SysJob> page = sysJobService.findPageCache(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
Result result = ResultFactory.getSuccessResult();
result.setResultObject(page);
return result;
}
/**
* 定时任务调度获取列表第一条记录
*/
//RequiresPermissions("job:sysJob:listFrist")
@RequestMapping(value = {"listFrist"},method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="定时任务调度获取列表第一条记录(Content-Type为text/html)", notes="定时任务调度获取列表第一条记录(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result listFristRequestParam(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
return listFrist(sysJob,model);
}
@RequestMapping(value = {"listFrist/json"},method ={RequestMethod.POST})
@ApiOperation(value="定时任务调度获取列表第一条记录(Content-Type为application/json)", notes="定时任务调度获取列表第一条记录(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result listFristRequestBody(@RequestBody SysJob sysJob, Model model) {
return listFrist(sysJob,model);
}
private Result listFrist(SysJob sysJob, Model model) {
Page<SysJob> page = sysJobService.findPageCache(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
Result result = ResultFactory.getSuccessResult();
if(page.getList().size()>0){
result.setResultObject(page.getList().get(0));
}else{
result=ResultFactory.getErrorResult("没有记录!");
}
return result;
}
/**
* 保存定时任务调度
*/
//RequiresPermissions(value={"job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping(value = "save",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="保存定时任务调度(Content-Type为text/html)", notes="保存定时任务调度(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result saveRequestParam(SysJob sysJob, Model model, RedirectAttributes redirectAttributes) {
return save(sysJob,model,redirectAttributes);
}
@RequestMapping(value = "save/json",method ={RequestMethod.POST})
@ApiOperation(value="保存定时任务调度(Content-Type为application/json)", notes="保存定时任务调度(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result saveRequestBody(@RequestBody SysJob sysJob, Model model, RedirectAttributes redirectAttributes) {
return save(sysJob,model,redirectAttributes);
}
private Result save(SysJob sysJob, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, sysJob)){
Result result = ResultFactory.getErrorResult("数据验证失败");
}
sysJobService.save(sysJob);
Result result = ResultFactory.getSuccessResult("保存定时任务调度成功");
return result;
}
/**
* 删除定时任务调度
*/
//RequiresPermissions("job:sysJob:del")
@RequestMapping(value = "delete",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="删除定时任务调度(Content-Type为text/html)", notes="删除定时任务调度(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result deleteRequestParam(SysJob sysJob, RedirectAttributes redirectAttributes) {
return delete(sysJob,redirectAttributes);
}
@RequestMapping(value = "delete/json",method ={RequestMethod.POST})
@ApiOperation(value="删除定时任务调度(Content-Type为application/json)", notes="删除定时任务调度(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result deleteRequestBody(@RequestBody SysJob sysJob, RedirectAttributes redirectAttributes) {
return delete(sysJob,redirectAttributes);
}
private Result delete(SysJob sysJob, RedirectAttributes redirectAttributes) {
sysJobService.delete(sysJob);
Result result = ResultFactory.getSuccessResult("删除定时任务调度成功");
return result;
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteByLogic",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="逻辑删除定时任务调度(Content-Type为text/html)", notes="逻辑删除定时任务调度(Content-Type为text/html)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="query")
public Result deleteByLogicRequestParam(SysJob sysJob, RedirectAttributes redirectAttributes) {
return deleteByLogic(sysJob,redirectAttributes);
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteByLogic/json",method ={RequestMethod.POST})
@ApiOperation(value="逻辑删除定时任务调度(Content-Type为application/json)", notes="逻辑删除定时任务调度(Content-Type为application/json)")
@ApiImplicitParam(name = "sysJob", value = "定时任务调度", dataType = "SysJob",paramType="body")
public Result deleteByLogicRequestBody(@RequestBody SysJob sysJob, RedirectAttributes redirectAttributes) {
return deleteByLogic(sysJob,redirectAttributes);
}
private Result deleteByLogic(SysJob sysJob, RedirectAttributes redirectAttributes) {
sysJobService.deleteByLogic(sysJob);
Result result = ResultFactory.getSuccessResult("删除定时任务调度成功");
return result;
}
/**
* 批量删除定时任务调度
*/
//RequiresPermissions("job:sysJob:del")
@RequestMapping(value = "deleteAll",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="批量删除定时任务调度(Content-Type为text/html)", notes="批量删除定时任务调度(Content-Type为text/html)")
@ApiImplicitParam(name = "ids", value = "定时任务调度ids,用,隔开", required = false, dataType = "String",paramType="query")
public Result deleteAllRequestParam(String ids, RedirectAttributes redirectAttributes) {
return deleteAll(ids,redirectAttributes);
}
@RequestMapping(value = "deleteAll/json",method ={RequestMethod.POST})
@ApiOperation(value="批量删除定时任务调度(Content-Type为application/json)", notes="批量删除定时任务调度(Content-Type为application/json)")
@ApiImplicitParam(name = "ids", value = "定时任务调度ids,用,隔开", required = false, dataType = "String",paramType="body")
public Result deleteAllRequestBody(@RequestBody String ids, RedirectAttributes redirectAttributes) {
return deleteAll(ids,redirectAttributes);
}
private Result deleteAll(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobService.delete(sysJobService.get(id));
}
Result result = ResultFactory.getSuccessResult("删除定时任务调度成功");
return result;
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteAllByLogic",method ={RequestMethod.POST,RequestMethod.GET})
@ApiOperation(value="逻辑批量删除定时任务调度(Content-Type为text/html)", notes="逻辑批量删除定时任务调度(Content-Type为text/html)")
@ApiImplicitParam(name = "ids", value = "定时任务调度ids,用,隔开", required = false, dataType = "String",paramType="query")
public Result deleteAllByLogicRequestParam(String ids, RedirectAttributes redirectAttributes) {
return deleteAllByLogic(ids,redirectAttributes);
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping(value = "deleteAllByLogic/json",method ={RequestMethod.POST})
@ApiOperation(value="逻辑批量删除定时任务调度(Content-Type为application/json)", notes="逻辑批量删除定时任务调度(Content-Type为application/json)")
@ApiImplicitParam(name = "ids", value = "定时任务调度ids,用,隔开", required = false, dataType = "String",paramType="body")
public Result deleteAllByLogicRequestBody(@RequestBody String ids, RedirectAttributes redirectAttributes) {
return deleteAllByLogic(ids,redirectAttributes);
}
private Result deleteAllByLogic(String ids, RedirectAttributes redirectAttributes) {
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobService.deleteByLogic(sysJobService.get(id));
}
Result result = ResultFactory.getSuccessResult("删除定时任务调度成功");
return result;
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.service.AbstractBaseService;
import com.jeespring.modules.job.entity.SysJobLog;
import com.jeespring.modules.job.dao.SysJobLogDao;
import com.alibaba.fastjson.JSON;
import com.jeespring.common.redis.RedisUtils;
import com.jeespring.common.security.MD5Tools;
/**
* 定时任务调度日志表Service
* @author JeeSpring
* @version 2018-08-16
*/
@Service
@Transactional(readOnly = true)
public class SysJobLogService extends AbstractBaseService<SysJobLogDao, SysJobLog> {
/**
* redis caches
*/
@Autowired
private RedisUtils redisUtils;
@Override
public SysJobLog get(String id) {
//获取数据库数据
SysJobLog sysJobLog=super.get(id);
return sysJobLog;
}
public SysJobLog getCache(String id) {
//获取缓存数据
SysJobLog sysJobLog=(SysJobLog)redisUtils.get(RedisUtils.getIdKey(SysJobLogService.class.getName(),id));
if( sysJobLog!=null) {
return sysJobLog;
}
//获取数据库数据
sysJobLog=super.get(id);
//设置缓存数据
redisUtils.set(RedisUtils.getIdKey(SysJobLogService.class.getName(),id),sysJobLog);
return sysJobLog;
}
@Override
public List<SysJobLog> total(SysJobLog sysJobLog) {
//获取数据库数据
List<SysJobLog> sysJobLogList=super.total(sysJobLog);
return sysJobLogList;
}
public List<SysJobLog> totalCache(SysJobLog sysJobLog) {
//获取缓存数据
String totalKey = RedisUtils.getTotalKey(SysJobLogService.class.getName(),JSON.toJSONString(sysJobLog));
List<SysJobLog> sysJobLogList=(List<SysJobLog>)redisUtils.get(totalKey);
if(sysJobLogList!=null) {
return sysJobLogList;
}
//获取数据库数据
sysJobLogList=super.total(sysJobLog);
//设置缓存数据
redisUtils.set(totalKey,sysJobLogList);
return sysJobLogList;
}
@Override
public List<SysJobLog> findList(SysJobLog sysJobLog) {
//获取数据库数据
List<SysJobLog> sysJobLogList=super.findList(sysJobLog);
//设置缓存数据
return sysJobLogList;
}
public List<SysJobLog> findListCache(SysJobLog sysJobLog) {
//获取缓存数据
String findListKey = RedisUtils.getFindListKey(SysJobLogService.class.getName(),JSON.toJSONString(sysJobLog));
List<SysJobLog> sysJobLogList=(List<SysJobLog>)redisUtils.get(findListKey);
if(sysJobLogList!=null) {
return sysJobLogList;
}
//获取数据库数据
sysJobLogList=super.findList(sysJobLog);
//设置缓存数据
redisUtils.set(findListKey,sysJobLogList);
return sysJobLogList;
}
public SysJobLog findListFirst(SysJobLog sysJobLog) {;
//获取数据库数据
List<SysJobLog> sysJobLogList=super.findList(sysJobLog);
if(sysJobLogList.size()>0) {
sysJobLog = sysJobLogList.get(0);
}
return sysJobLog;
}
public SysJobLog findListFirstCache(SysJobLog sysJobLog) {
//获取缓存数据
String findListFirstKey = RedisUtils.getFindListFirstKey(SysJobLogService.class.getName(),JSON.toJSONString(sysJobLog));
SysJobLog sysJobLogRedis=(SysJobLog)redisUtils.get(findListFirstKey);
if(sysJobLogRedis!=null) {
return sysJobLogRedis;
}
//获取数据库数据
List<SysJobLog> sysJobLogList=super.findList(sysJobLog);
if(sysJobLogList.size()>0) {
sysJobLog = sysJobLogList.get(0);
} else {
sysJobLog = new SysJobLog();
}
//设置缓存数据
redisUtils.set(findListFirstKey,sysJobLog);
return sysJobLog;
}
@Override
public Page<SysJobLog> findPage(Page<SysJobLog> page, SysJobLog sysJobLog) {
//获取数据库数据
Page<SysJobLog> pageReuslt=super.findPage(page, sysJobLog);
return pageReuslt;
}
public Page<SysJobLog> findPageCache(Page<SysJobLog> page, SysJobLog sysJobLog) {
//获取缓存数据
String findPageKey = RedisUtils.getFindPageKey(SysJobLogService.class.getName(),JSON.toJSONString(page)+JSON.toJSONString(sysJobLog));
Page<SysJobLog> pageReuslt=(Page<SysJobLog>)redisUtils.get(findPageKey);
if(pageReuslt!=null) {
return pageReuslt;
}
//获取数据库数据
pageReuslt=super.findPage(page, sysJobLog);
//设置缓存数据
redisUtils.set(findPageKey,pageReuslt);
return pageReuslt;
}
@Override
@Transactional(readOnly = false)
public void save(SysJobLog sysJobLog) {
//保存数据库记录
super.save(sysJobLog);
//设置清除缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobLogService.class.getName(),sysJobLog.getId()));
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobLogService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobLogService.class.getName()));
}
@Override
@Transactional(readOnly = false)
public void delete(SysJobLog sysJobLog) {
//清除记录缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobLogService.class.getName(),sysJobLog.getId()));
//删除数据库记录
super.delete(sysJobLog);
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobLogService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobLogService.class.getName()));
}
@Override
@Transactional(readOnly = false)
public void deleteByLogic(SysJobLog sysJobLog) {
//清除记录缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobLogService.class.getName(),sysJobLog.getId()));
//逻辑删除数据库记录
super.deleteByLogic(sysJobLog);
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobLogService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobLogService.class.getName()));
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.service;
import java.util.List;
import com.jeespring.common.constant.ScheduleConstants;
import com.jeespring.common.security.ShiroUtils;
import com.jeespring.modules.job.util.ScheduleUtils;
import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.service.AbstractBaseService;
import com.jeespring.modules.job.entity.SysJob;
import com.jeespring.modules.job.dao.SysJobDao;
import com.alibaba.fastjson.JSON;
import com.jeespring.common.redis.RedisUtils;
import com.jeespring.common.security.MD5Tools;
import javax.annotation.PostConstruct;
/**
* 定时任务调度Service
* @author JeeSpring
* @version 2018-08-16
*/
@Service
@Transactional(readOnly = true)
public class SysJobService extends AbstractBaseService<SysJobDao, SysJob> {
/**
* redis caches
*/
@Autowired
private RedisUtils redisUtils;
@Override
public SysJob get(String id) {
//获取数据库数据
SysJob sysJob=super.get(id);
return sysJob;
}
public SysJob getCache(String id) {
//获取缓存数据
SysJob sysJob=(SysJob)redisUtils.get(RedisUtils.getIdKey(SysJobService.class.getName(),id));
if( sysJob!=null) {
return sysJob;
}
//获取数据库数据
sysJob=super.get(id);
//设置缓存数据
redisUtils.set(RedisUtils.getIdKey(SysJobService.class.getName(),id),sysJob);
return sysJob;
}
@Override
public List<SysJob> total(SysJob sysJob) {
//获取数据库数据
List<SysJob> sysJobList=super.total(sysJob);
return sysJobList;
}
public List<SysJob> totalCache(SysJob sysJob) {
//获取缓存数据
String totalKey = RedisUtils.getTotalKey(SysJobService.class.getName(),JSON.toJSONString(sysJob));
List<SysJob> sysJobList=(List<SysJob>)redisUtils.get(totalKey);
if(sysJobList!=null) {
return sysJobList;
}
//获取数据库数据
sysJobList=super.total(sysJob);
//设置缓存数据
redisUtils.set(totalKey,sysJobList);
return sysJobList;
}
@Override
public List<SysJob> findList(SysJob sysJob) {
//获取数据库数据
List<SysJob> sysJobList=super.findList(sysJob);
//设置缓存数据
return sysJobList;
}
public List<SysJob> findListCache(SysJob sysJob) {
//获取缓存数据
String findListKey = RedisUtils.getFindListKey(SysJobService.class.getName(),JSON.toJSONString(sysJob));
List<SysJob> sysJobList=(List<SysJob>)redisUtils.get(findListKey);
if(sysJobList!=null) {
return sysJobList;
}
//获取数据库数据
sysJobList=super.findList(sysJob);
//设置缓存数据
redisUtils.set(findListKey,sysJobList);
return sysJobList;
}
public SysJob findListFirst(SysJob sysJob) {;
//获取数据库数据
List<SysJob> sysJobList=super.findList(sysJob);
if(sysJobList.size()>0) {
sysJob = sysJobList.get(0);
}
return sysJob;
}
public SysJob findListFirstCache(SysJob sysJob) {
//获取缓存数据
String findListFirstKey = RedisUtils.getFindListFirstKey(SysJobService.class.getName(),JSON.toJSONString(sysJob));
SysJob sysJobRedis=(SysJob)redisUtils.get(findListFirstKey);
if(sysJobRedis!=null) {
return sysJobRedis;
}
//获取数据库数据
List<SysJob> sysJobList=super.findList(sysJob);
if(sysJobList.size()>0) {
sysJob = sysJobList.get(0);
} else {
sysJob = new SysJob();
}
//设置缓存数据
redisUtils.set(findListFirstKey,sysJob);
return sysJob;
}
@Override
public Page<SysJob> findPage(Page<SysJob> page, SysJob sysJob) {
//获取数据库数据
Page<SysJob> pageReuslt=super.findPage(page, sysJob);
return pageReuslt;
}
public Page<SysJob> findPageCache(Page<SysJob> page, SysJob sysJob) {
//获取缓存数据
String findPageKey = RedisUtils.getFindPageKey(SysJobService.class.getName(),JSON.toJSONString(page)+JSON.toJSONString(sysJob));
Page<SysJob> pageReuslt=(Page<SysJob>)redisUtils.get(findPageKey);
if(pageReuslt!=null) {
return pageReuslt;
}
//获取数据库数据
pageReuslt=super.findPage(page, sysJob);
//设置缓存数据
redisUtils.set(findPageKey,pageReuslt);
return pageReuslt;
}
@Override
@Transactional(readOnly = false)
public void save(SysJob sysJob) {
if(sysJob.getIsNewRecord()) {
sysJob.setStatus(ScheduleConstants.Status.PAUSE.getValue());
}
//保存数据库记录
super.save(sysJob);
if(sysJob.getIsNewRecord()) {
ScheduleUtils.createScheduleJob(scheduler, sysJob);
} else {
ScheduleUtils.updateScheduleJob(scheduler, sysJob);
}
/*if (ScheduleConstants.Status.NORMAL.getValue().equals(sysJob.getStatus()))
{
resumeJob(sysJob);
}
else if (ScheduleConstants.Status.PAUSE.getValue().equals(sysJob.getStatus()))
{
pauseJob(sysJob);
}*/
//设置清除缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobService.class.getName(),sysJob.getId()));
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobService.class.getName()));
}
@Override
@Transactional(readOnly = false)
public void delete(SysJob sysJob) {
//清除记录缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobService.class.getName(),sysJob.getId()));
//删除数据库记录
super.delete(sysJob);
ScheduleUtils.deleteScheduleJob(scheduler, sysJob.getId());
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobService.class.getName()));
}
@Override
@Transactional(readOnly = false)
public void deleteByLogic(SysJob sysJob) {
//清除记录缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobService.class.getName(),sysJob.getId()));
//逻辑删除数据库记录
super.deleteByLogic(sysJob);
ScheduleUtils.deleteScheduleJob(scheduler, sysJob.getId());
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobService.class.getName()));
}
@Autowired
private Scheduler scheduler;
/**
* 项目启动时,初始化定时器
*/
@PostConstruct
public void init()
{
List<SysJob> jobList = super.findAllList(new SysJob());
for (SysJob job : jobList)
{
CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, job.getId());
// 如果不存在,则创建
if (cronTrigger == null)
{
ScheduleUtils.createScheduleJob(scheduler, job);
}
else
{
ScheduleUtils.updateScheduleJob(scheduler, job);
}
}
}
/**
* 暂停任务
*
* @param job 调度信息
*/
@Transactional(readOnly = false)
public void pauseJob(SysJob job)
{
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
super.save(job);
ScheduleUtils.pauseJob(scheduler, job.getId());
//设置清除缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobService.class.getName(),job.getId()));
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobService.class.getName()));
}
/**
* 恢复任务
*
* @param job 调度信息
*/
@Transactional(readOnly = false)
public void resumeJob(SysJob job)
{
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
super.save(job);
ScheduleUtils.resumeJob(scheduler, job.getId());
//设置清除缓存数据
redisUtils.remove(RedisUtils.getIdKey(SysJobService.class.getName(),job.getId()));
//清除列表和页面缓存数据
redisUtils.removePattern(RedisUtils.getFindListKeyPattern(SysJobService.class.getName()));
redisUtils.removePattern(RedisUtils.getFinPageKeyPattern(SysJobService.class.getName()));
}
/**
* 立即运行任务
*
* @param job 调度信息
*/
@Transactional(readOnly = false)
public int run(SysJob job)
{
return ScheduleUtils.run(scheduler, get(job.getId()));
}
/**
* 任务调度状态修改
*
* @param job 调度信息
*/
@Transactional(readOnly = false)
public void changeStatus(SysJob job)
{
String status = job.getStatus();
if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
{
pauseJob(job);
}
else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
{
resumeJob(job);
}
}
}
\ No newline at end of file
package com.jeespring.modules.job.task;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.utils.HttpRequest;
import com.jeespring.common.utils.SendMailUtil;
import com.jeespring.modules.sys.entity.SysConfig;
import com.jeespring.modules.server.entity.SysServer;
import com.jeespring.modules.sys.entity.SysUserOnline;
import com.jeespring.modules.sys.service.SysConfigService;
import com.jeespring.modules.server.service.SysServerService;
import com.jeespring.modules.server.service.ISysServerService;
import com.jeespring.modules.sys.service.SysUserOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 定时任务调度测试
*
* @author JeeSpring
*/
@Component("jeeSpringTask")
public class JeeSpringTask
{
@Autowired
SysUserOnlineService sysUserOnlineService;
@Autowired
private ISysServerService sysServerService;
@Autowired
private SysConfigService sysConfigService;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void jeeSpringParams(String params)
{
System.out.println(dateFormat.format(new Date()) + " | " + "定时任务调度测试 com.jeespring.modules.job.task.JeeSpringTask.jeeSpringParams("+params+")");
}
public void jeeSpringNoParams()
{
System.out.println(dateFormat.format(new Date()) + " | " + "定时任务调度测试 com.jeespring.modules.job.task.JeeSpringTask.jeeSpringNoParams()");
SysUserOnlineCount();
}
public void SysUserOnlineCount(){
Page<com.jeespring.modules.sys.entity.SysUserOnline> page=new Page<com.jeespring.modules.sys.entity.SysUserOnline>();
SysUserOnline sysUserOnline=new SysUserOnline();
page.setPageSize(100000);
sysUserOnline.setStatus("on_line");
Page<SysUserOnline> pageSysUserOnline=sysUserOnlineService.findPageCache(page,sysUserOnline);
SysConfig sysConfig = new SysConfig();
sysConfig.setType("toExceptionMailAddr");
sysConfig=sysConfigService.findListFirstCache(sysConfig);
if(pageSysUserOnline.getList().size()>0){
SendMailUtil.sendCommonMail(sysConfig.getValue(),"发送在线用户数邮件 SysUserOnlineCount "+pageSysUserOnline.getList().size()+"人","发送在线用户数邮件 SysUserOnlineCount "+pageSysUserOnline.getList().size()+"人");
}
}
public void serverStatus(){
List<SysServer> sysServers=sysServerService.findAllList(new SysServer());
List<SysServer> sysServersBug=new ArrayList<SysServer>();
String message="";
for (SysServer item:sysServers){
item.getServerAddress();
if("Down".equals(HttpRequest.sendGet(item.getServerAddress(), ""))){
sysServersBug.add(item);
message=message+item.getName()+" "+item.getServerAddress()+" Down;<br>";
item.setStatus("off_line");
sysServerService.save(item);
}else{
message=message+item.getName()+" "+item.getServerAddress()+" OK;<br>";
item.setStatus("on_line");
sysServerService.save(item);
}
}
SysConfig sysConfig = new SysConfig();
sysConfig.setType("toExceptionMailAddr");
sysConfig=sysConfigService.findListFirstCache(sysConfig);
if(sysServersBug.size()>0){
SendMailUtil.sendCommonMail(sysConfig.getValue(),
"服务器监控正常("+(sysServers.size()-sysServersBug.size())+")异常("+sysServersBug.size()+")",
message);
}
}
}
package com.jeespring.modules.job.util;
import com.jeespring.common.constant.Constants;
import com.jeespring.common.constant.ScheduleConstants;
import com.jeespring.common.spring.SpringUtils;
import com.jeespring.common.utils.bean.BeanUtils;
import com.jeespring.modules.job.entity.SysJob;
import com.jeespring.modules.job.entity.SysJobLog;
import com.jeespring.modules.job.service.SysJobLogService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* 定时任务
*
* @author JeeSpring
*
*/
public class ScheduleJob extends QuartzJobBean
{
private static final Logger log = LoggerFactory.getLogger(ScheduleJob.class);
private ExecutorService service = Executors.newSingleThreadExecutor();
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException
{
SysJob job = new SysJob();
BeanUtils.copyBeanProp(job, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
SysJobLogService jobLogService = (SysJobLogService) SpringUtils.getBean(SysJobLogService.class);
SysJobLog jobLog = new SysJobLog();
jobLog.setJobName(job.getJobName());
jobLog.setJobGroup(job.getJobGroup());
jobLog.setMethodName(job.getMethodName());
jobLog.setMethodParams(job.getMethodParams());
jobLog.setCreateDate(new Date());
long startTime = System.currentTimeMillis();
try
{
// 执行任务
log.info("任务开始执行 - 名称:{} 方法:{}", job.getJobName(), job.getMethodName());
ScheduleRunnable task = new ScheduleRunnable(job.getJobName(), job.getMethodName(), job.getMethodParams());
Future<?> future = service.submit(task);
future.get();
long times = System.currentTimeMillis() - startTime;
// 任务状态 0:成功 1:失败
jobLog.setStatus(Constants.SUCCESS);
jobLog.setJobMessage(job.getJobName() + " 总共耗时:" + times + "毫秒");
log.info("任务执行结束 - 名称:{} 耗时:{} 毫秒", job.getJobName(), times);
}
catch (Exception e)
{
log.info("任务执行失败 - 名称:{} 方法:{}", job.getJobName(), job.getMethodName());
log.error("任务执行异常 - :", e);
long times = System.currentTimeMillis() - startTime;
jobLog.setJobMessage(job.getJobName() + " 总共耗时:" + times + "毫秒");
// 任务状态 0:成功 1:失败
jobLog.setStatus(Constants.FAIL);
jobLog.setExceptionInfo(e.toString());
}
finally
{
jobLogService.save(jobLog);
}
}
}
package com.jeespring.modules.job.util;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.spring.SpringUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
/**
* 执行定时任务
*
* @author JeeSpring
*
*/
public class ScheduleRunnable implements Runnable
{
private Object target;
private Method method;
private String params;
public ScheduleRunnable(String beanName, String methodName, String params)
throws NoSuchMethodException, SecurityException
{
this.target = SpringUtils.getBean(beanName);
this.params = params;
if (StringUtils.isNotEmpty(params))
{
this.method = target.getClass().getDeclaredMethod(methodName, String.class);
}
else
{
this.method = target.getClass().getDeclaredMethod(methodName);
}
}
@Override
public void run()
{
try
{
ReflectionUtils.makeAccessible(method);
if (StringUtils.isNotEmpty(params))
{
method.invoke(target, params);
}
else
{
method.invoke(target);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
package com.jeespring.modules.job.util;
import com.jeespring.common.constant.ScheduleConstants;
import com.jeespring.common.exception.job.TaskException;
import com.jeespring.modules.job.entity.SysJob;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 定时任务工具类
*
* @author JeeSpring
*
*/
public class ScheduleUtils
{
private static final Logger log = LoggerFactory.getLogger(ScheduleUtils.class);
/**
* 获取触发器key
*/
public static TriggerKey getTriggerKey(String jobId)
{
return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId);
}
/**
* 获取jobKey
*/
public static JobKey getJobKey(String jobId)
{
return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId);
}
/**
* 获取表达式触发器
*/
public static CronTrigger getCronTrigger(Scheduler scheduler, String jobId)
{
try
{
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
}
catch (SchedulerException e)
{
log.error("getCronTrigger 异常:", e);
}
return null;
}
/**
* 创建定时任务
*/
public static void createScheduleJob(Scheduler scheduler, SysJob job)
{
try
{
// 构建job信息
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(job.getId())).build();
// 表达式调度构建器
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(job.getId())).withSchedule(cronScheduleBuilder).build();
// 放入参数,运行时的方法可以获取
jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
scheduler.scheduleJob(jobDetail, trigger);
// 暂停任务
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
{
pauseJob(scheduler, job.getId());
}
}
catch (SchedulerException e)
{
log.error("createScheduleJob 异常:", e);
}
catch (TaskException e)
{
log.error("createScheduleJob 异常:", e);
}
}
/**
* 更新定时任务
*/
public static void updateScheduleJob(Scheduler scheduler, SysJob job)
{
try
{
TriggerKey triggerKey = getTriggerKey(job.getId());
// 表达式调度构建器
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
CronTrigger trigger = getCronTrigger(scheduler, job.getId());
// 按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
// 参数
trigger.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
scheduler.rescheduleJob(triggerKey, trigger);
// 暂停任务
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
{
pauseJob(scheduler, job.getId());
}
}
catch (SchedulerException e)
{
log.error("SchedulerException 异常:", e);
}
catch (TaskException e)
{
log.error("SchedulerException 异常:", e);
}
}
/**
* 立即执行任务
*/
public static int run(Scheduler scheduler, SysJob job)
{
int rows = 0;
try
{
// 参数
JobDataMap dataMap = new JobDataMap();
dataMap.put(ScheduleConstants.TASK_PROPERTIES, job);
scheduler.triggerJob(getJobKey(job.getId()), dataMap);
rows = 1;
}
catch (SchedulerException e)
{
log.error("run 异常:", e.getMessage());
}
return rows;
}
/**
* 暂停任务
*/
public static void pauseJob(Scheduler scheduler, String jobId)
{
try
{
scheduler.pauseJob(getJobKey(jobId));
}
catch (SchedulerException e)
{
log.error("pauseJob 异常:", e);
}
}
/**
* 恢复任务
*/
public static void resumeJob(Scheduler scheduler, String jobId)
{
try
{
scheduler.resumeJob(getJobKey(jobId));
}
catch (SchedulerException e)
{
log.error("resumeJob 异常:", e);
}
}
/**
* 删除定时任务
*/
public static void deleteScheduleJob(Scheduler scheduler, String jobId)
{
try
{
scheduler.deleteJob(getJobKey(jobId));
}
catch (SchedulerException e)
{
log.error("deleteScheduleJob 异常:", e);
}
}
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
throws TaskException
{
switch (job.getMisfirePolicy())
{
case ScheduleConstants.MISFIRE_DEFAULT:
return cb;
case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
return cb.withMisfireHandlingInstructionIgnoreMisfires();
case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
return cb.withMisfireHandlingInstructionFireAndProceed();
case ScheduleConstants.MISFIRE_DO_NOTHING:
return cb.withMisfireHandlingInstructionDoNothing();
default:
throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
+ "' cannot be used in cron schedule tasks", TaskException.Code.CONFIG_ERROR);
}
}
}
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jeespring.modules.sys.service.SysConfigService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.jeespring.common.utils.DateUtils;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.utils.excel.ExportExcel;
import com.jeespring.common.utils.excel.ImportExcel;
import com.jeespring.modules.job.entity.SysJob;
import com.jeespring.modules.job.service.SysJobService;
/**
* 定时任务调度Controller
* @author JeeSpring
* @version 2018-08-16
*/
@Controller
@RequestMapping(value = "${adminPath}/job/sysJob")
public class SysJobController extends AbstractBaseController {
@Autowired
private SysJobService sysJobService;
@Autowired
private SysConfigService sysConfigService;
@ModelAttribute
public SysJob get(@RequestParam(required=false) String id) {
SysJob entity = null;
if (StringUtils.isNotBlank(id)){
entity = sysJobService.getCache(id);
//entity = sysJobService.get(id);
}
if (entity == null){
entity = new SysJob();
}
return entity;
}
/**
* 定时任务调度统计页面
*/
@RequiresPermissions("job:sysJob:total")
@RequestMapping(value = {"total"})
public String totalView(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
total(sysJob,request,response,model);
return "modules/job/sysJobTotal";
}
private void total(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
if(StringUtils.isEmpty(sysJob.getTotalType())){
sysJob.setTotalType("%Y-%m-%d");
}
//X轴的数据
List<String> xAxisData= new ArrayList<String>();
//Y轴的数据
Map<String,List<Double>> yAxisData = new HashMap<String,List<Double>>();
List<Double> countList = new ArrayList<Double>();
List<Double> sumList = new ArrayList<Double>();
if(sysJob.getOrderBy()==""){
sysJob.setOrderBy("totalDate");
}
List<SysJob> list = sysJobService.totalCache(sysJob);
//List<SysJob> list = sysJobService.total(sysJob);
model.addAttribute("list", list);
for(SysJob sysJobItem:list){
//x轴数据
xAxisData.add( sysJobItem.getTotalDate());
countList.add(Double.valueOf(sysJobItem.getTotalCount()));
}
yAxisData.put("数量", countList);
request.setAttribute("xAxisData", xAxisData);
request.setAttribute("yAxisData", yAxisData);
model.addAttribute("sumTotalCount", list.stream().mapToInt(SysJob::getTotalCount).sum());
//饼图数据
Map<String,Object> orientData= new HashMap<String,Object>();
for(SysJob sysJobItem:list){
orientData.put(sysJobItem.getTotalDate(), sysJobItem.getTotalCount());
}
model.addAttribute("orientData", orientData);
}
@RequiresPermissions("job:sysJob:total")
@RequestMapping(value = {"totalMap"})
public String totalMap(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
if(StringUtils.isEmpty(sysJob.getTotalType())){
sysJob.setTotalType("%Y-%m-%d");
}
List<SysJob> list = sysJobService.totalCache(sysJob);
//List<SysJob> list = sysJobService.total(sysJob);
model.addAttribute("sumTotalCount", list.stream().mapToInt(SysJob::getTotalCount).sum());
model.addAttribute("list", list);
return "modules/job/sysJobTotalMap";
}
/**
* 定时任务调度列表页面
*/
@RequiresPermissions("job:sysJob:list")
@RequestMapping(value = {"list", ""})
public String list(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJob> page = sysJobService.findPageCache(new Page<SysJob>(request, response), sysJob);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model.addAttribute("page", page);
sysJob.setOrderBy("totalDate");
total(sysJob,request,response,model);
return "modules/job/sysJobList";
}
/**
* 定时任务调度列表页面
*/
@RequiresPermissions("job:sysJob:list")
@RequestMapping(value = {"listVue"})
public String listVue(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJob> page = sysJobService.findPageCache(new Page<SysJob>(request, response), sysJob);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model.addAttribute("page", page);
return "modules/job/sysJobListVue";
}
/**
* 定时任务调度列表页面
*/
//RequiresPermissions("job:sysJob:select")
@RequestMapping(value = {"select"})
public String select(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJob> page = sysJobService.findPageCache(new Page<SysJob>(request, response), sysJob);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model.addAttribute("page", page);
return "modules/job/sysJobSelect";
}
/**
* 查看,增加,编辑定时任务调度表单页面
*/
@RequiresPermissions(value={"job:sysJob:view","job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(SysJob sysJob, Model model, HttpServletRequest request, HttpServletResponse response) {
model.addAttribute("action", request.getParameter("action"));
model.addAttribute("sysJob", sysJob);
if(request.getParameter("ViewFormType")!=null && "FormTwo".equals(request.getParameter("ViewFormType"))) {
return "modules/job/sysJobFormTwo";
}
return "modules/job/sysJobForm";
}
/**
* 保存定时任务调度
*/
@RequiresPermissions(value={"job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public String save(SysJob sysJob, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJob/?repage";
}
if (!beanValidator(model, sysJob)){
return form(sysJob, model,request,response);
}
sysJobService.save(sysJob);
addMessage(redirectAttributes, "保存定时任务调度成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 任务调度立即执行一次
*/
@RequiresPermissions(value={"job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping(value = "run")
public String run(SysJob job,RedirectAttributes redirectAttributes,HttpServletRequest request, HttpServletResponse response)
{
sysJobService.run(job);
addMessage(redirectAttributes, "任务调度立即执行一次成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 任务调度状态修改
*/
@RequiresPermissions(value={"job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping(value = "changeStatus")
public String changeStatus(SysJob job,RedirectAttributes redirectAttributes,HttpServletRequest request, HttpServletResponse response)
{
sysJobService.changeStatus(job);
addMessage(redirectAttributes, "任务调度状态修改成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 删除定时任务调度
*/
@RequiresPermissions("job:sysJob:del")
@RequestMapping(value = "delete")
public String delete(SysJob sysJob, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJob/?repage";
}
sysJobService.delete(sysJob);
addMessage(redirectAttributes, "删除定时任务调度成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions(value={"job:sysJob:del","job:sysJob:delByLogic"},logical=Logical.OR)
@RequestMapping(value = "deleteByLogic")
public String deleteByLogic(SysJob sysJob, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJob/?repage";
}
sysJobService.deleteByLogic(sysJob);
addMessage(redirectAttributes, "逻辑删除定时任务调度成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 批量删除定时任务调度
*/
@RequiresPermissions("job:sysJob:del")
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJob/?repage";
}
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobService.delete(sysJobService.get(id));
}
addMessage(redirectAttributes, "删除定时任务调度成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions(value={"job:sysJob:del","job:sysJob:delByLogic"},logical=Logical.OR)
@RequestMapping(value = "deleteAllByLogic")
public String deleteAllByLogic(String ids, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJob/?repage";
}
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobService.deleteByLogic(sysJobService.get(id));
}
addMessage(redirectAttributes, "删除定时任务调度成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 导出excel文件
*/
@RequiresPermissions("job:sysJob:export")
@RequestMapping(value = "export", method=RequestMethod.POST)
public String exportFile(SysJob sysJob, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "定时任务调度"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response, -1), sysJob);
new ExportExcel("定时任务调度", SysJob.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出定时任务调度记录失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 导入Excel数据
*/
@RequiresPermissions("job:sysJob:import")
@RequestMapping(value = "import", method=RequestMethod.POST)
public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
try {
int successNum = 0;
ImportExcel ei = new ImportExcel(file, 1, 0);
List<SysJob> list = ei.getDataList(SysJob.class);
for (SysJob sysJob : list){
sysJobService.save(sysJob);
}
addMessage(redirectAttributes, "已成功导入 "+successNum+" 条定时任务调度记录");
} catch (Exception e) {
addMessage(redirectAttributes, "导入定时任务调度失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
/**
* 下载导入定时任务调度数据模板
*/
@RequiresPermissions("job:sysJob:import")
@RequestMapping(value = "import/template")
public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "定时任务调度数据导入模板.xlsx";
List<SysJob> list = Lists.newArrayList();
new ExportExcel("定时任务调度数据", SysJob.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导入模板下载失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJob/?repage";
}
}
\ No newline at end of file
/**
* * Copyright &copy; 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package com.jeespring.modules.job.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jeespring.modules.sys.service.SysConfigService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.jeespring.common.utils.DateUtils;
import com.jeespring.common.config.Global;
import com.jeespring.common.persistence.Page;
import com.jeespring.common.web.AbstractBaseController;
import com.jeespring.common.utils.StringUtils;
import com.jeespring.common.utils.excel.ExportExcel;
import com.jeespring.common.utils.excel.ImportExcel;
import com.jeespring.modules.job.entity.SysJobLog;
import com.jeespring.modules.job.service.SysJobLogService;
/**
* 定时任务调度日志表Controller
* @author JeeSpring
* @version 2018-08-16
*/
@Controller
@RequestMapping(value = "${adminPath}/job/sysJobLog")
public class SysJobLogController extends AbstractBaseController {
@Autowired
private SysJobLogService sysJobLogService;
@Autowired
private SysConfigService sysConfigService;
@ModelAttribute
public SysJobLog get(@RequestParam(required=false) String id) {
SysJobLog entity = null;
if (StringUtils.isNotBlank(id)){
entity = sysJobLogService.getCache(id);
//entity = sysJobLogService.get(id);
}
if (entity == null){
entity = new SysJobLog();
}
return entity;
}
/**
* 定时任务调度日志统计页面
*/
@RequiresPermissions("job:sysJobLog:total")
@RequestMapping(value = {"total"})
public String totalView(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
total(sysJobLog,request,response,model);
return "modules/job/sysJobLogTotal";
}
private void total(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
if(StringUtils.isEmpty(sysJobLog.getTotalType())){
sysJobLog.setTotalType("%Y-%m-%d");
}
//X轴的数据
List<String> xAxisData= new ArrayList<String>();
//Y轴的数据
Map<String,List<Double>> yAxisData = new HashMap<String,List<Double>>();
List<Double> countList = new ArrayList<Double>();
List<Double> sumList = new ArrayList<Double>();
if(sysJobLog.getOrderBy()==""){
sysJobLog.setOrderBy("totalDate");
}
List<SysJobLog> list = sysJobLogService.totalCache(sysJobLog);
//List<SysJobLog> list = sysJobLogService.total(sysJobLog);
model.addAttribute("list", list);
for(SysJobLog sysJobLogItem:list){
//x轴数据
xAxisData.add( sysJobLogItem.getTotalDate());
countList.add(Double.valueOf(sysJobLogItem.getTotalCount()));
}
yAxisData.put("数量", countList);
request.setAttribute("xAxisData", xAxisData);
request.setAttribute("yAxisData", yAxisData);
model.addAttribute("sumTotalCount", list.stream().mapToInt(SysJobLog::getTotalCount).sum());
//饼图数据
Map<String,Object> orientData= new HashMap<String,Object>();
for(SysJobLog sysJobLogItem:list){
orientData.put(sysJobLogItem.getTotalDate(), sysJobLogItem.getTotalCount());
}
model.addAttribute("orientData", orientData);
}
@RequiresPermissions("job:sysJobLog:total")
@RequestMapping(value = {"totalMap"})
public String totalMap(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
if(StringUtils.isEmpty(sysJobLog.getTotalType())){
sysJobLog.setTotalType("%Y-%m-%d");
}
List<SysJobLog> list = sysJobLogService.totalCache(sysJobLog);
//List<SysJobLog> list = sysJobLogService.total(sysJobLog);
model.addAttribute("sumTotalCount", list.stream().mapToInt(SysJobLog::getTotalCount).sum());
model.addAttribute("list", list);
return "modules/job/sysJobLogTotalMap";
}
/**
* 定时任务调度日志列表页面
*/
@RequiresPermissions("job:sysJobLog:list")
@RequestMapping(value = {"list", ""})
public String list(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJobLog> page = sysJobLogService.findPageCache(new Page<SysJobLog>(request, response), sysJobLog);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model.addAttribute("page", page);
sysJobLog.setOrderBy("totalDate");
total(sysJobLog,request,response,model);
return "modules/job/sysJobLogList";
}
/**
* 定时任务调度日志列表页面
*/
@RequiresPermissions("job:sysJobLog:list")
@RequestMapping(value = {"listVue"})
public String listVue(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJobLog> page = sysJobLogService.findPageCache(new Page<SysJobLog>(request, response), sysJobLog);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model.addAttribute("page", page);
return "modules/job/sysJobLogListVue";
}
/**
* 定时任务调度日志列表页面
*/
//RequiresPermissions("job:sysJobLog:select")
@RequestMapping(value = {"select"})
public String select(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<SysJobLog> page = sysJobLogService.findPageCache(new Page<SysJobLog>(request, response), sysJobLog);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model.addAttribute("page", page);
return "modules/job/sysJobLogSelect";
}
/**
* 查看,增加,编辑定时任务调度日志表单页面
*/
@RequiresPermissions(value={"job:sysJobLog:view","job:sysJobLog:add","job:sysJobLog:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(SysJobLog sysJobLog, Model model, HttpServletRequest request, HttpServletResponse response) {
model.addAttribute("action", request.getParameter("action"));
model.addAttribute("sysJobLog", sysJobLog);
if(request.getParameter("ViewFormType")!=null && "FormTwo".equals(request.getParameter("ViewFormType"))) {
return "modules/job/sysJobLogFormTwo";
}
return "modules/job/sysJobLogForm";
}
/**
* 保存定时任务调度日志
*/
@RequiresPermissions(value={"job:sysJobLog:add","job:sysJobLog:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public String save(SysJobLog sysJobLog, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJobLog/?repage";
}
if (!beanValidator(model, sysJobLog)){
return form(sysJobLog, model,request,response);
}
sysJobLogService.save(sysJobLog);
addMessage(redirectAttributes, "保存定时任务调度日志成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 删除定时任务调度日志
*/
@RequiresPermissions("job:sysJobLog:del")
@RequestMapping(value = "delete")
public String delete(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJobLog/?repage";
}
sysJobLogService.delete(sysJobLog);
addMessage(redirectAttributes, "删除定时任务调度日志成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions(value={"job:sysJobLog:del","job:sysJobLog:delByLogic"},logical=Logical.OR)
@RequestMapping(value = "deleteByLogic")
public String deleteByLogic(SysJobLog sysJobLog, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJobLog/?repage";
}
sysJobLogService.deleteByLogic(sysJobLog);
addMessage(redirectAttributes, "逻辑删除定时任务调度日志成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 批量删除定时任务调度日志
*/
@RequiresPermissions("job:sysJobLog:del")
@RequestMapping(value = "deleteAll")
public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJobLog/?repage";
}
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobLogService.delete(sysJobLogService.get(id));
}
addMessage(redirectAttributes, "删除定时任务调度日志成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions(value={"job:sysJobLog:del","job:sysJobLog:delByLogic"},logical=Logical.OR)
@RequestMapping(value = "deleteAllByLogic")
public String deleteAllByLogic(String ids, RedirectAttributes redirectAttributes) {
if(sysConfigService.isDemoMode()){
addMessage(redirectAttributes, sysConfigService.isDemoModeDescription());
return "redirect:" + adminPath + "/job/sysJobLog/?repage";
}
String[] idArray = ids.split(",");
for(String id : idArray){
sysJobLogService.deleteByLogic(sysJobLogService.get(id));
}
addMessage(redirectAttributes, "删除定时任务调度日志成功");
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 导出excel文件
*/
@RequiresPermissions("job:sysJobLog:export")
@RequestMapping(value = "export", method=RequestMethod.POST)
public String exportFile(SysJobLog sysJobLog, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "定时任务调度日志"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response, -1), sysJobLog);
new ExportExcel("定时任务调度日志", SysJobLog.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出定时任务调度日志记录失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 导入Excel数据
*/
@RequiresPermissions("job:sysJobLog:import")
@RequestMapping(value = "import", method=RequestMethod.POST)
public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
try {
int successNum = 0;
ImportExcel ei = new ImportExcel(file, 1, 0);
List<SysJobLog> list = ei.getDataList(SysJobLog.class);
for (SysJobLog sysJobLog : list){
sysJobLogService.save(sysJobLog);
}
addMessage(redirectAttributes, "已成功导入 "+successNum+" 条定时任务调度日志记录");
} catch (Exception e) {
addMessage(redirectAttributes, "导入定时任务调度日志失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
/**
* 下载导入定时任务调度日志数据模板
*/
@RequiresPermissions("job:sysJobLog:import")
@RequestMapping(value = "import/template")
public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "定时任务调度日志数据导入模板.xlsx";
List<SysJobLog> list = Lists.newArrayList();
new ExportExcel("定时任务调度日志数据", SysJobLog.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导入模板下载失败!失败信息:"+e.getMessage());
}
return "redirect:"+Global.getAdminPath()+"/job/sysJobLog/?repage";
}
}
\ No newline at end of file
Supports Markdown
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