JeeGit 官方论坛

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

1

收听

0

听众

192

主题
发表于 2023-4-6 20:02:14 | 查看: 501| 回复: 0
  1.    /**
  2.      * 新增保存公告
  3.      */
  4.     @RepeatSubmit
  5.     @RequiresPermissions("sys:notice:add")
  6.     @BussinessLog(title = "公告通知", businessType = BusinessType.INSERT)
  7.     @RequestMapping(value = "/add", method = RequestMethod.POST)
  8.     @ResponseBody
  9.     public ResponseData add(SysNoticeEntity sysNotice) {
  10.         try{

  11.             //校验参数
  12.             ValidatorUtil.validateEntity(sysNotice);

  13.             //生成静态文件
  14.             Configuration configuration = freeMarkerConfigurer.getConfiguration();
  15.             // 加载模板对象
  16.             Template template = configuration.getTemplate("common/template/announcement.html");
  17.             String uuid = IdUtil.fastSimpleUUID();
  18.             // 创建一个数据集
  19.             Map<String, Object> data = new HashMap<>();
  20.             data.put("noticeTitle",sysNotice.getNoticeTitle());
  21. //            data.put("noticeContent",sysNotice.getNoticeContent());
  22.             data.put("createBy", UserUtils.getLoginName());
  23.             data.put("htmlNo",uuid + "1");
  24.             String path = getHttpServletRequest().getContextPath();
  25.             data.put(ConfigConstant.CTX_STATIC,path);
  26.             data.put("noticeLevel",sysNotice.getNoticeLevel());
  27.             data.put("startTime",sysNotice.getStartTime());

  28.             // 指定文件输出路径以及文件名
  29.             Writer out = new FileWriter(FileUtil.touch("templates/modules/static/"+ uuid + "0.html"));
  30.             //存放富文本编辑器内容
  31.             File file = FileUtil.touch("templates/modules/static/"+ uuid + "1.html");
  32.             FileUtil.writeUtf8String(sysNotice.getNoticeContent(),file);
  33.             // 输出文件
  34.             template.process(data, out);
  35.             // 关闭流
  36.             out.close();
  37.             sysNotice.setHtmlNo(uuid);
  38.             //如果开始时间大于当前时间 就是未发布 时间还未到
  39.             if(DateUtil.compare(sysNotice.getStartTime(),new Date()) > 0){
  40.                 //状态
  41.                 sysNotice.setStatus("1");
  42.             }else{
  43.                 sysNotice.setStatus("0");
  44.             }



  45.             return sysNoticeService.add(sysNotice) ? success() : success();
  46.         }catch (Exception e){
  47.             e.printStackTrace();
  48.             return  success();
  49.         }
  50.     }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|JeeGit 官方论坛 ( 吉ICP备19001578号-2|吉B2-20200006 )

GMT+8, 2024-4-26 01:39 , Processed in 0.028901 second(s), 17 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表