|
发表于 2023-4-6 20:02:14
|
查看: 501 |
回复: 0
- /**
- * 新增保存公告
- */
- @RepeatSubmit
- @RequiresPermissions("sys:notice:add")
- @BussinessLog(title = "公告通知", businessType = BusinessType.INSERT)
- @RequestMapping(value = "/add", method = RequestMethod.POST)
- @ResponseBody
- public ResponseData add(SysNoticeEntity sysNotice) {
- try{
- //校验参数
- ValidatorUtil.validateEntity(sysNotice);
- //生成静态文件
- Configuration configuration = freeMarkerConfigurer.getConfiguration();
- // 加载模板对象
- Template template = configuration.getTemplate("common/template/announcement.html");
- String uuid = IdUtil.fastSimpleUUID();
- // 创建一个数据集
- Map<String, Object> data = new HashMap<>();
- data.put("noticeTitle",sysNotice.getNoticeTitle());
- // data.put("noticeContent",sysNotice.getNoticeContent());
- data.put("createBy", UserUtils.getLoginName());
- data.put("htmlNo",uuid + "1");
- String path = getHttpServletRequest().getContextPath();
- data.put(ConfigConstant.CTX_STATIC,path);
- data.put("noticeLevel",sysNotice.getNoticeLevel());
- data.put("startTime",sysNotice.getStartTime());
- // 指定文件输出路径以及文件名
- Writer out = new FileWriter(FileUtil.touch("templates/modules/static/"+ uuid + "0.html"));
- //存放富文本编辑器内容
- File file = FileUtil.touch("templates/modules/static/"+ uuid + "1.html");
- FileUtil.writeUtf8String(sysNotice.getNoticeContent(),file);
- // 输出文件
- template.process(data, out);
- // 关闭流
- out.close();
- sysNotice.setHtmlNo(uuid);
- //如果开始时间大于当前时间 就是未发布 时间还未到
- if(DateUtil.compare(sysNotice.getStartTime(),new Date()) > 0){
- //状态
- sysNotice.setStatus("1");
- }else{
- sysNotice.setStatus("0");
- }
- return sysNoticeService.add(sysNotice) ? success() : success();
- }catch (Exception e){
- e.printStackTrace();
- return success();
- }
- }
复制代码
|
|