添加新闻功能

This commit is contained in:
sk1551
2020-12-25 15:00:46 +08:00
parent 0e021d2f83
commit 8650200345
10 changed files with 1678 additions and 1 deletions

View File

@ -0,0 +1,116 @@
package com.ruoyi.project.benyi.controller;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.common.SchoolCommon;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.benyi.domain.BySchoolNews;
import com.ruoyi.project.benyi.service.IBySchoolNewsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
/**
* 新闻中心Controller
*
* @author tsbz
* @date 2020-12-25
*/
@RestController
@RequestMapping("/benyi/news")
public class BySchoolNewsController extends BaseController
{
@Autowired
private IBySchoolNewsService bySchoolNewsService;
@Autowired
private SchoolCommon schoolCommon;
/**
* 查询新闻中心列表
*/
@PreAuthorize("@ss.hasPermi('benyi:news:list')")
@GetMapping("/list")
public TableDataInfo list(BySchoolNews bySchoolNews)
{
bySchoolNews.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
startPage();
List<BySchoolNews> list = bySchoolNewsService.selectBySchoolNewsList(bySchoolNews);
return getDataTable(list);
}
/**
* 导出新闻中心列表
*/
@PreAuthorize("@ss.hasPermi('benyi:news:export')")
@Log(title = "新闻中心", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(BySchoolNews bySchoolNews)
{
List<BySchoolNews> list = bySchoolNewsService.selectBySchoolNewsList(bySchoolNews);
ExcelUtil<BySchoolNews> util = new ExcelUtil<BySchoolNews>(BySchoolNews.class);
return util.exportExcel(list, "news");
}
/**
* 获取新闻中心详细信息
*/
@PreAuthorize("@ss.hasPermi('benyi:news:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(bySchoolNewsService.selectBySchoolNewsById(id));
}
/**
* 新增新闻中心
*/
@PreAuthorize("@ss.hasPermi('benyi:news:add')")
@Log(title = "新闻中心", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody BySchoolNews bySchoolNews)
{
bySchoolNews.setIsdel("N");
bySchoolNews.setCreateTime(new Date());
bySchoolNews.setCreateuserid(SecurityUtils.getLoginUser().getUser().getUserId());
bySchoolNews.setIscheck("N");
bySchoolNews.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
bySchoolNews.setType("1");
return toAjax(bySchoolNewsService.insertBySchoolNews(bySchoolNews));
}
/**
* 修改新闻中心
*/
@PreAuthorize("@ss.hasPermi('benyi:news:edit')")
@Log(title = "新闻中心", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BySchoolNews bySchoolNews)
{
return toAjax(bySchoolNewsService.updateBySchoolNews(bySchoolNews));
}
/**
* 删除新闻中心
*/
@PreAuthorize("@ss.hasPermi('benyi:news:remove')")
@Log(title = "新闻中心", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(bySchoolNewsService.deleteBySchoolNewsByIds(ids));
}
}

View File

@ -0,0 +1,239 @@
package com.ruoyi.project.benyi.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
/**
* 新闻中心对象 by_school_news
*
* @author tsbz
* @date 2020-12-25
*/
public class BySchoolNews extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 编号
*/
private Long id;
/**
* 标题
*/
@Excel(name = "标题")
private String title;
/**
* 封面图片
*/
@Excel(name = "封面图片")
private String imgurl;
/**
* 摘要
*/
@Excel(name = "摘要")
private String abstractcontent;
/**
* 类型
*/
@Excel(name = "类型")
private String type;
/**
* 内容
*/
@Excel(name = "内容")
private String content;
/**
* 是否删除
*/
@Excel(name = "是否删除")
private String isdel;
/**
* 创建人
*/
@Excel(name = "创建人")
private Long createuserid;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date createTime;
/**
* 所属学校
*/
@Excel(name = "所属学校")
private Long deptId;
/**
* 是否置顶
*/
@Excel(name = "是否置顶")
private String istop;
/**
* 是否审核
*/
@Excel(name = "是否审核")
private String ischeck;
/**
* 审核人
*/
@Excel(name = "审核人")
private Long checkuserid;
/**
* 审核时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date checkTime;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl;
}
public String getImgurl() {
return imgurl;
}
public void setAbstractcontent(String abstractcontent) {
this.abstractcontent = abstractcontent;
}
public String getAbstractcontent() {
return abstractcontent;
}
public void setType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setIsdel(String isdel) {
this.isdel = isdel;
}
public String getIsdel() {
return isdel;
}
public void setCreateuserid(Long createuserid) {
this.createuserid = createuserid;
}
public Long getCreateuserid() {
return createuserid;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public Long getDeptId() {
return deptId;
}
public void setIstop(String istop) {
this.istop = istop;
}
public String getIstop() {
return istop;
}
public void setIscheck(String ischeck) {
this.ischeck = ischeck;
}
public String getIscheck() {
return ischeck;
}
public void setCheckuserid(Long checkuserid) {
this.checkuserid = checkuserid;
}
public Long getCheckuserid() {
return checkuserid;
}
public void setCheckTime(Date checkTime) {
this.checkTime = checkTime;
}
public Date getCheckTime() {
return checkTime;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("title", getTitle())
.append("imgurl", getImgurl())
.append("abstractcontent", getAbstractcontent())
.append("type", getType())
.append("content", getContent())
.append("isdel", getIsdel())
.append("createuserid", getCreateuserid())
.append("createTime", getCreateTime())
.append("deptId", getDeptId())
.append("istop", getIstop())
.append("ischeck", getIscheck())
.append("checkuserid", getCheckuserid())
.append("checkTime", getCheckTime())
.toString();
}
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -0,0 +1,61 @@
package com.ruoyi.project.benyi.mapper;
import java.util.List;
import com.ruoyi.project.benyi.domain.BySchoolNews;
/**
* 新闻中心Mapper接口
*
* @author tsbz
* @date 2020-12-25
*/
public interface BySchoolNewsMapper
{
/**
* 查询新闻中心
*
* @param id 新闻中心ID
* @return 新闻中心
*/
public BySchoolNews selectBySchoolNewsById(Long id);
/**
* 查询新闻中心列表
*
* @param bySchoolNews 新闻中心
* @return 新闻中心集合
*/
public List<BySchoolNews> selectBySchoolNewsList(BySchoolNews bySchoolNews);
/**
* 新增新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
public int insertBySchoolNews(BySchoolNews bySchoolNews);
/**
* 修改新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
public int updateBySchoolNews(BySchoolNews bySchoolNews);
/**
* 删除新闻中心
*
* @param id 新闻中心ID
* @return 结果
*/
public int deleteBySchoolNewsById(Long id);
/**
* 批量删除新闻中心
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteBySchoolNewsByIds(Long[] ids);
}

View File

@ -0,0 +1,61 @@
package com.ruoyi.project.benyi.service;
import java.util.List;
import com.ruoyi.project.benyi.domain.BySchoolNews;
/**
* 新闻中心Service接口
*
* @author tsbz
* @date 2020-12-25
*/
public interface IBySchoolNewsService
{
/**
* 查询新闻中心
*
* @param id 新闻中心ID
* @return 新闻中心
*/
public BySchoolNews selectBySchoolNewsById(Long id);
/**
* 查询新闻中心列表
*
* @param bySchoolNews 新闻中心
* @return 新闻中心集合
*/
public List<BySchoolNews> selectBySchoolNewsList(BySchoolNews bySchoolNews);
/**
* 新增新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
public int insertBySchoolNews(BySchoolNews bySchoolNews);
/**
* 修改新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
public int updateBySchoolNews(BySchoolNews bySchoolNews);
/**
* 批量删除新闻中心
*
* @param ids 需要删除的新闻中心ID
* @return 结果
*/
public int deleteBySchoolNewsByIds(Long[] ids);
/**
* 删除新闻中心信息
*
* @param id 新闻中心ID
* @return 结果
*/
public int deleteBySchoolNewsById(Long id);
}

View File

@ -0,0 +1,95 @@
package com.ruoyi.project.benyi.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.benyi.mapper.BySchoolNewsMapper;
import com.ruoyi.project.benyi.domain.BySchoolNews;
import com.ruoyi.project.benyi.service.IBySchoolNewsService;
/**
* 新闻中心Service业务层处理
*
* @author tsbz
* @date 2020-12-25
*/
@Service
public class BySchoolNewsServiceImpl implements IBySchoolNewsService
{
@Autowired
private BySchoolNewsMapper bySchoolNewsMapper;
/**
* 查询新闻中心
*
* @param id 新闻中心ID
* @return 新闻中心
*/
@Override
public BySchoolNews selectBySchoolNewsById(Long id)
{
return bySchoolNewsMapper.selectBySchoolNewsById(id);
}
/**
* 查询新闻中心列表
*
* @param bySchoolNews 新闻中心
* @return 新闻中心
*/
@Override
public List<BySchoolNews> selectBySchoolNewsList(BySchoolNews bySchoolNews)
{
return bySchoolNewsMapper.selectBySchoolNewsList(bySchoolNews);
}
/**
* 新增新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
@Override
public int insertBySchoolNews(BySchoolNews bySchoolNews)
{
bySchoolNews.setCreateTime(DateUtils.getNowDate());
return bySchoolNewsMapper.insertBySchoolNews(bySchoolNews);
}
/**
* 修改新闻中心
*
* @param bySchoolNews 新闻中心
* @return 结果
*/
@Override
public int updateBySchoolNews(BySchoolNews bySchoolNews)
{
return bySchoolNewsMapper.updateBySchoolNews(bySchoolNews);
}
/**
* 批量删除新闻中心
*
* @param ids 需要删除的新闻中心ID
* @return 结果
*/
@Override
public int deleteBySchoolNewsByIds(Long[] ids)
{
return bySchoolNewsMapper.deleteBySchoolNewsByIds(ids);
}
/**
* 删除新闻中心信息
*
* @param id 新闻中心ID
* @return 结果
*/
@Override
public int deleteBySchoolNewsById(Long id)
{
return bySchoolNewsMapper.deleteBySchoolNewsById(id);
}
}

View File

@ -46,7 +46,7 @@ public class SysDeptController extends BaseController {
/**
* 获取部门列表
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@PreAuthorize("@ss.hasPermi('system:dept:list')" + "||@ss.hasPermi('benyi:news:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept);

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.benyi.mapper.BySchoolNewsMapper">
<resultMap type="BySchoolNews" id="BySchoolNewsResult">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="imgurl" column="imgurl"/>
<result property="abstractcontent" column="abstractcontent"/>
<result property="type" column="type"/>
<result property="content" column="content"/>
<result property="isdel" column="isdel"/>
<result property="createuserid" column="createuserid"/>
<result property="createTime" column="create_time"/>
<result property="deptId" column="dept_id"/>
<result property="istop" column="istop"/>
<result property="ischeck" column="ischeck"/>
<result property="checkuserid" column="checkuserid"/>
<result property="checkTime" column="check_time"/>
</resultMap>
<sql id="selectBySchoolNewsVo">
select id, title, imgurl, abstractcontent, type, content, isdel, createuserid, create_time, dept_id, istop, ischeck, checkuserid, check_time from by_school_news
</sql>
<select id="selectBySchoolNewsList" parameterType="BySchoolNews" resultMap="BySchoolNewsResult">
<include refid="selectBySchoolNewsVo"/>
<where>
<if test="title != null and title != ''">and title = #{title}</if>
<if test="imgurl != null and imgurl != ''">and imgurl = #{imgurl}</if>
<if test="abstractcontent != null and abstractcontent != ''">and abstractcontent = #{abstractcontent}</if>
<if test="type != null and type != ''">and type = #{type}</if>
<if test="content != null and content != ''">and content = #{content}</if>
<if test="isdel != null and isdel != ''">and isdel = #{isdel}</if>
<if test="createuserid != null ">and createuserid = #{createuserid}</if>
<if test="deptId != null ">and dept_id = #{deptId}</if>
<if test="istop != null and istop != ''">and istop = #{istop}</if>
<if test="ischeck != null and ischeck != ''">and ischeck = #{ischeck}</if>
<if test="checkuserid != null ">and checkuserid = #{checkuserid}</if>
<if test="checkTime != null ">and check_time = #{checkTime}</if>
</where>
</select>
<select id="selectBySchoolNewsById" parameterType="Long" resultMap="BySchoolNewsResult">
<include refid="selectBySchoolNewsVo"/>
where id = #{id}
</select>
<insert id="insertBySchoolNews" parameterType="BySchoolNews" useGeneratedKeys="true" keyProperty="id">
insert into by_school_news
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">title,</if>
<if test="imgurl != null and imgurl != ''">imgurl,</if>
<if test="abstractcontent != null and abstractcontent != ''">abstractcontent,</if>
<if test="type != null and type != ''">type,</if>
<if test="content != null and content != ''">content,</if>
<if test="isdel != null and isdel != ''">isdel,</if>
<if test="createuserid != null ">createuserid,</if>
<if test="createTime != null ">create_time,</if>
<if test="deptId != null ">dept_id,</if>
<if test="istop != null and istop != ''">istop,</if>
<if test="ischeck != null and ischeck != ''">ischeck,</if>
<if test="checkuserid != null ">checkuserid,</if>
<if test="checkTime != null ">check_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">#{title},</if>
<if test="imgurl != null and imgurl != ''">#{imgurl},</if>
<if test="abstractcontent != null and abstractcontent != ''">#{abstractcontent},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="content != null and content != ''">#{content},</if>
<if test="isdel != null and isdel != ''">#{isdel},</if>
<if test="createuserid != null ">#{createuserid},</if>
<if test="createTime != null ">#{createTime},</if>
<if test="deptId != null ">#{deptId},</if>
<if test="istop != null and istop != ''">#{istop},</if>
<if test="ischeck != null and ischeck != ''">#{ischeck},</if>
<if test="checkuserid != null ">#{checkuserid},</if>
<if test="checkTime != null ">#{checkTime},</if>
</trim>
</insert>
<update id="updateBySchoolNews" parameterType="BySchoolNews">
update by_school_news
<trim prefix="SET" suffixOverrides=",">
<if test="title != null and title != ''">title = #{title},</if>
<if test="imgurl != null and imgurl != ''">imgurl = #{imgurl},</if>
<if test="abstractcontent != null and abstractcontent != ''">abstractcontent = #{abstractcontent},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="content != null and content != ''">content = #{content},</if>
<if test="isdel != null and isdel != ''">isdel = #{isdel},</if>
<if test="createuserid != null ">createuserid = #{createuserid},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
<if test="deptId != null ">dept_id = #{deptId},</if>
<if test="istop != null and istop != ''">istop = #{istop},</if>
<if test="ischeck != null and ischeck != ''">ischeck = #{ischeck},</if>
<if test="checkuserid != null ">checkuserid = #{checkuserid},</if>
<if test="checkTime != null ">check_time = #{checkTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteBySchoolNewsById" parameterType="Long">
delete from by_school_news where id = #{id}
</delete>
<delete id="deleteBySchoolNewsByIds" parameterType="String">
delete from by_school_news where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>