Commit 030932a77b5d8a51505313716cc4a179197a273e

Authored by liwei2917
1 parent 231158c8

新增频道审核新消息提醒功能

src/main/java/com/cnlive/shenhe/ShenheApplication.java
... ... @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
11 11 import org.springframework.boot.ApplicationRunner;
12 12 import org.springframework.boot.SpringApplication;
13 13 import org.springframework.boot.autoconfigure.SpringBootApplication;
  14 +import org.springframework.boot.builder.SpringApplicationBuilder;
14 15 import org.springframework.boot.web.servlet.FilterRegistrationBean;
15 16 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
16 17 import org.springframework.context.annotation.Bean;
... ... @@ -259,7 +260,9 @@ public class ShenheApplication extends SpringBootServletInitializer {
259 260  
260 261  
261 262 public static void main(String[] args) {
262   - SpringApplication.run(ShenheApplication.class, args);
  263 +// SpringApplication.run(ShenheApplication.class, args);
  264 + SpringApplicationBuilder builder=new SpringApplicationBuilder(ShenheApplication.class);
  265 + builder.headless(false).run(args);
263 266 }
264 267  
265 268 /**
... ...
src/main/java/com/cnlive/shenhe/controller/VideosController.java
... ... @@ -18,6 +18,7 @@ import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
18 18 import com.cnlive.shenhe.utils.AuditPass;
19 19 import com.cnlive.shenhe.utils.CommonConst;
20 20 import com.cnlive.shenhe.utils.CommonUtils;
  21 +import com.cnlive.shenhe.utils.InfoUtil;
21 22 import com.github.pagehelper.PageInfo;
22 23 import org.slf4j.Logger;
23 24 import org.slf4j.LoggerFactory;
... ... @@ -43,6 +44,8 @@ public class VideosController extends BaseController {
43 44 @Autowired
44 45 AuditPass Pass;
45 46 @Autowired
  47 + InfoUtil infoUtil;
  48 + @Autowired
46 49 VideosServiceImpl videosService;
47 50 @Autowired
48 51 UsersServiceImpl usersService;
... ... @@ -460,12 +463,13 @@ public class VideosController extends BaseController {
460 463 return responseBean;
461 464 }
462 465  
463   - @PostMapping("/ceshi")
  466 + @GetMapping("/ceshi")
464 467 @ResponseBody
465   - public static String ceshi(String name) {
466   -
  468 + public void ceshi() {
  469 + System.out.println("进入测试");
  470 +// InfoUtil test = new InfoUtil();
  471 +// infoUtil.show("测试通知", "这是一个弹窗测试!",localhost_url+"/channel/page?shenhe_status=0&receive=0");
467 472  
468   - return name;
469 473 }
470 474  
471 475 }
... ...
src/main/java/com/cnlive/shenhe/job/ChannelJob.java
... ... @@ -8,9 +8,12 @@ import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
8 8 import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
9 9 import com.cnlive.shenhe.utils.AuditPass;
10 10 import com.cnlive.shenhe.utils.CommonConst;
  11 +import com.cnlive.shenhe.utils.InfoUtil;
  12 +
11 13 import org.slf4j.Logger;
12 14 import org.slf4j.LoggerFactory;
13 15 import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.beans.factory.annotation.Value;
14 17 import org.springframework.scheduling.annotation.Scheduled;
15 18 import org.springframework.stereotype.Component;
16 19  
... ... @@ -19,11 +22,16 @@ import java.util.List;
19 22 @Component
20 23 public class ChannelJob {
21 24 private static Logger logger = LoggerFactory.getLogger(ChannelJob.class);
  25 + @Value("${spring.localhost.url}")
  26 + private String localhost_url;//本机地址
  27 +
22 28 @Autowired
23 29 SitesServiceImpl sitesService;
24 30 @Autowired
25 31 AuditPass Pass;
26 32 @Autowired
  33 + InfoUtil infoUtil;
  34 + @Autowired
27 35 ChannelServiceImpl channelService;
28 36  
29 37 @Autowired
... ... @@ -45,5 +53,21 @@ public class ChannelJob {
45 53 }
46 54 }
47 55  
  56 + /**
  57 + * 频道审核通知
  58 + */
  59 + @Scheduled(fixedRate = 60 * 1000)
  60 + public void channelNotice() {
  61 + ShyChannel shyChannel = new ShyChannel();
  62 + shyChannel.setShenhe_type(CommonConst.AUDIT_TYPE_USER);// 审核类型为人工审
  63 + shyChannel.setShenhe_status(CommonConst.AUDIT_INTT);
  64 + List<ShyChannel> channelList = channelService.findshyChannel(shyChannel);
  65 + if (channelList.size() > 0) {
  66 + logger.info("您有"+channelList.size()+"条新的频道审核申请,请注意查看!");
  67 + infoUtil.show("新频道申请", "您有"+channelList.size()+"条新的频道审核申请,请注意查看!",localhost_url+"/channel/page?shenhe_status=0&receive=0");
  68 + }
  69 +
  70 + }
  71 +
48 72  
49 73 }
... ...
src/main/java/com/cnlive/shenhe/utils/InfoUtil.java 0 → 100644
  1 +package com.cnlive.shenhe.utils;
  2 +
  3 +import java.awt.BorderLayout;
  4 +import java.awt.Color;
  5 +import java.awt.Cursor;
  6 +import java.awt.Desktop;
  7 +import java.awt.Dimension;
  8 +import java.awt.FlowLayout;
  9 +import java.awt.Font;
  10 +import java.awt.Point;
  11 +import java.awt.event.MouseAdapter;
  12 +import java.awt.event.MouseEvent;
  13 +import java.net.URI;
  14 +
  15 +import javax.swing.BorderFactory;
  16 +import javax.swing.JButton;
  17 +import javax.swing.JLabel;
  18 +import javax.swing.JPanel;
  19 +import javax.swing.JScrollPane;
  20 +import javax.swing.JTextArea;
  21 +import javax.swing.SwingConstants;
  22 +
  23 +import org.springframework.beans.factory.annotation.Value;
  24 +import org.springframework.boot.context.properties.ConfigurationProperties;
  25 +import org.springframework.context.annotation.PropertySource;
  26 +import org.springframework.stereotype.Component;
  27 +
  28 +import java.awt.Insets;
  29 +import java.awt.Toolkit;
  30 +import javax.swing.JDialog;
  31 +
  32 +/**
  33 + * @author Administrator 此工具类用法:实例化出对象,调用 void show("标题","内容") 方法. InfoUtil tool
  34 + *         = new InfoUtil(); tool.show("标题","内容")
  35 + */
  36 +@Component
  37 +public class InfoUtil {
  38 + private TipWindow tw = null; // 提示框
  39 + private JPanel headPan = null;
  40 + private JPanel feaPan = null;
  41 + private JPanel btnPan = null;
  42 + private JLabel title = null; // 栏目名称
  43 + private JLabel head = null; // 蓝色标题
  44 + private JLabel close = null; // 关闭按钮
  45 + private JTextArea feature = null; // 内容
  46 + private JScrollPane jfeaPan = null;
  47 + private JButton sure = null;
  48 + private String titleT = null;
  49 + private String word = null;
  50 + private Desktop desktop = null;
  51 +
  52 + // private SimpleDateFormat sdf = new
  53 + // SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  54 +
  55 + public void init() {
  56 + // 新建300x180的消息提示框
  57 + tw = new TipWindow(300, 180);
  58 + headPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
  59 + feaPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
  60 + btnPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
  61 + title = new JLabel("欢迎使用本系统");
  62 + head = new JLabel(titleT);
  63 + close = new JLabel(" x");
  64 + feature = new JTextArea(word);
  65 + jfeaPan = new JScrollPane(feature);
  66 + sure = new JButton("查看");
  67 + sure.setHorizontalAlignment(SwingConstants.CENTER);
  68 +
  69 + // 设置提示框的边框,宽度和颜色
  70 + tw.getRootPane().setBorder(
  71 + BorderFactory.createMatteBorder(1, 1, 1, 1, Color.white));
  72 + title.setPreferredSize(new Dimension(260, 26));
  73 + title.setVerticalTextPosition(JLabel.CENTER);
  74 + title.setHorizontalTextPosition(JLabel.CENTER);
  75 + title.setFont(new Font("宋体", Font.PLAIN, 12));
  76 + title.setForeground(Color.black);
  77 +
  78 + close.setFont(new Font("Arial", Font.BOLD, 15));
  79 + close.setPreferredSize(new Dimension(20, 20));
  80 + close.setVerticalTextPosition(JLabel.CENTER);
  81 + close.setHorizontalTextPosition(JLabel.CENTER);
  82 + close.setCursor(new Cursor(12));
  83 + close.setToolTipText("关闭");
  84 +
  85 + head.setPreferredSize(new Dimension(250, 35));
  86 + head.setVerticalTextPosition(JLabel.CENTER);
  87 + head.setHorizontalTextPosition(JLabel.CENTER);
  88 + head.setFont(new Font("宋体", Font.PLAIN, 14));
  89 + head.setForeground(Color.black);
  90 +
  91 + feature.setEditable(false);
  92 + feature.setForeground(Color.BLACK);
  93 + feature.setFont(new Font("宋体", Font.PLAIN, 13));
  94 + feature.setBackground(new Color(255, 255, 255));
  95 + // 设置文本域自动换行
  96 + feature.setLineWrap(true);
  97 +
  98 + jfeaPan.setPreferredSize(new Dimension(260, 100));
  99 + jfeaPan.setBorder(null);
  100 + jfeaPan.setBackground(Color.black);
  101 + tw.setBackground(Color.white);
  102 +
  103 + // 为了隐藏文本域,加个空的JLabel将他挤到下面去
  104 + JLabel jsp = new JLabel();
  105 + jsp.setPreferredSize(new Dimension(300, 15));
  106 +
  107 + sure.setPreferredSize(new Dimension(60, 30));
  108 + // 设置标签鼠标手形
  109 + sure.setCursor(new Cursor(12));
  110 + // 设置button外观
  111 + sure.setContentAreaFilled(false);
  112 + sure.setBorder(BorderFactory.createRaisedBevelBorder());
  113 + sure.setBackground(Color.gray);
  114 +
  115 + // headPan.add(title);
  116 + headPan.add(head);
  117 + headPan.add(close);
  118 +
  119 + feaPan.add(jsp);
  120 + feaPan.add(jfeaPan);
  121 +
  122 + // feaPan.add(releaseLabel);
  123 +
  124 + btnPan.add(sure);
  125 +
  126 + headPan.setBackground(new Color(104, 141, 177));
  127 + feaPan.setBackground(Color.white);
  128 + btnPan.setBackground(Color.white);
  129 +
  130 + tw.add(headPan, BorderLayout.NORTH);
  131 + tw.add(feaPan, BorderLayout.CENTER);
  132 + tw.add(btnPan, BorderLayout.SOUTH);
  133 + }
  134 +
  135 + public void handle(String url) {
  136 + // 为更新按钮增加相应的事件
  137 + desktop = Desktop.getDesktop();
  138 + sure.addMouseListener(new MouseAdapter() {
  139 + public void mouseClicked(MouseEvent e) {
  140 + //注释代码为点击确认之后跳转到指定网页
  141 + try {
  142 + desktop.browse(new URI(url));
  143 + } catch (Exception e1) {
  144 + e1.printStackTrace();
  145 + }
  146 + tw.close();
  147 + }
  148 +
  149 + public void mouseEntered(MouseEvent e) {
  150 + sure.setBorder(BorderFactory.createLineBorder(Color.gray));
  151 + }
  152 +
  153 + public void mouseExited(MouseEvent e) {
  154 + sure.setBorder(null);
  155 + }
  156 + });
  157 + // 右上角关闭按钮事件
  158 + close.addMouseListener(new MouseAdapter() {
  159 + public void mouseClicked(MouseEvent e) {
  160 + tw.close();
  161 + }
  162 +
  163 + public void mouseEntered(MouseEvent e) {
  164 + close.setBorder(BorderFactory.createLineBorder(Color.gray));
  165 + }
  166 +
  167 + public void mouseExited(MouseEvent e) {
  168 + close.setBorder(null);
  169 + }
  170 + });
  171 + }
  172 +
  173 + public void show(String titleT, String word,String url) {
  174 + this.titleT = titleT;
  175 + this.word = word;
  176 + // time = sdf.format(new Date());
  177 + init();
  178 + handle(url);
  179 + tw.setAlwaysOnTop(true);
  180 + tw.setUndecorated(true);
  181 + tw.setResizable(false);
  182 + tw.setVisible(true);
  183 + tw.run();
  184 + }
  185 +
  186 + public void close() {
  187 + tw.close();
  188 + }
  189 +}
  190 +
  191 +class TipWindow extends JDialog {
  192 + private static final long serialVersionUID = 8541659783234673950L;
  193 + private static Dimension dim;
  194 + private int x, y;
  195 + private int width, height;
  196 + private static Insets screenInsets;
  197 +
  198 + public TipWindow(int width, int height) {
  199 + this.width = width;
  200 + this.height = height;
  201 + dim = Toolkit.getDefaultToolkit().getScreenSize();
  202 + screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
  203 + this.getGraphicsConfiguration());
  204 + x = (int) (dim.getWidth() - width - 3);
  205 + y = (int) (dim.getHeight() - screenInsets.bottom - 3);
  206 + initComponents();
  207 + }
  208 +
  209 + public void run() {
  210 + for (int i = 0; i <= height; i += 10) {
  211 + try {
  212 + this.setLocation(x, y - i);
  213 + Thread.sleep(50);
  214 + } catch (InterruptedException ex) {
  215 + }
  216 + }
  217 + // 此处代码用来实现让消息提示框10秒后自动消失
  218 + try {
  219 + Thread.sleep(10000);
  220 + } catch (InterruptedException e) {
  221 + e.printStackTrace();
  222 + }
  223 + close();
  224 + }
  225 +
  226 + private void initComponents() {
  227 + this.setSize(width, height);
  228 + this.setLocation(x, y);
  229 + this.setBackground(Color.black);
  230 + }
  231 +
  232 + public void close() {
  233 + x = this.getX();
  234 + y = this.getY();
  235 + int ybottom = (int) dim.getHeight() - screenInsets.bottom;
  236 + for (int i = 0; i <= ybottom - y; i += 10) {
  237 + try {
  238 + setLocation(x, y + i);
  239 + Thread.sleep(50);
  240 + } catch (InterruptedException ex) {
  241 + }
  242 + }
  243 + dispose();
  244 + }
  245 +
  246 +}
... ...