添加活动列表接口

This commit is contained in:
柏码の讲师 2024-11-12 21:45:51 +08:00
parent c8b1087b95
commit 0580c15508
7 changed files with 487 additions and 1 deletions

View File

@ -0,0 +1,103 @@
package com.ruoyi.system.controller;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Event;
import com.ruoyi.system.service.IEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 活动管理Controller
*
* @author ruoyi
* @date 2024-11-12
*/
@RestController
@RequestMapping("/system/event")
public class EventController extends BaseController
{
@Autowired
private IEventService eventService;
/**
* 查询活动管理列表
*/
@GetMapping("/list")
public TableDataInfo list(Event event)
{
startPage();
List<Event> list = eventService.selectEventList(event);
return getDataTable(list);
}
/**
* 导出活动管理列表
*/
@PreAuthorize("@ss.hasPermi('system:event:export')")
@Log(title = "活动管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Event event)
{
List<Event> list = eventService.selectEventList(event);
ExcelUtil<Event> util = new ExcelUtil<Event>(Event.class);
util.exportExcel(response, list, "活动管理数据");
}
/**
* 获取活动管理详细信息
*/
@PreAuthorize("@ss.hasPermi('system:event:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(eventService.selectEventById(id));
}
/**
* 新增活动管理
*/
@PreAuthorize("@ss.hasPermi('system:event:add')")
@Log(title = "活动管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Event event)
{
return toAjax(eventService.insertEvent(event));
}
/**
* 修改活动管理
*/
@PreAuthorize("@ss.hasPermi('system:event:edit')")
@Log(title = "活动管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Event event)
{
return toAjax(eventService.updateEvent(event));
}
/**
* 删除活动管理
*/
@PreAuthorize("@ss.hasPermi('system:event:remove')")
@Log(title = "活动管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(eventService.deleteEventByIds(ids));
}
}

View File

@ -0,0 +1,97 @@
package com.ruoyi.system.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.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 活动管理对象 db_event
*
* @author ruoyi
* @date 2024-11-12
*/
public class Event extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 活动ID */
private Long id;
/** 活动标题 */
@Excel(name = "活动标题")
private String title;
/** 活动地点 */
@Excel(name = "活动地点")
private String location;
/** 开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
/** 结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
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 setLocation(String location)
{
this.location = location;
}
public String getLocation()
{
return location;
}
public void setStartTime(Date startTime)
{
this.startTime = startTime;
}
public Date getStartTime()
{
return startTime;
}
public void setEndTime(Date endTime)
{
this.endTime = endTime;
}
public Date getEndTime()
{
return endTime;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("title", getTitle())
.append("location", getLocation())
.append("startTime", getStartTime())
.append("endTime", getEndTime())
.toString();
}
}

View File

@ -0,0 +1,61 @@
package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.Event;
/**
* 活动管理Mapper接口
*
* @author ruoyi
* @date 2024-11-12
*/
public interface EventMapper
{
/**
* 查询活动管理
*
* @param id 活动管理主键
* @return 活动管理
*/
public Event selectEventById(Long id);
/**
* 查询活动管理列表
*
* @param event 活动管理
* @return 活动管理集合
*/
public List<Event> selectEventList(Event event);
/**
* 新增活动管理
*
* @param event 活动管理
* @return 结果
*/
public int insertEvent(Event event);
/**
* 修改活动管理
*
* @param event 活动管理
* @return 结果
*/
public int updateEvent(Event event);
/**
* 删除活动管理
*
* @param id 活动管理主键
* @return 结果
*/
public int deleteEventById(Long id);
/**
* 批量删除活动管理
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteEventByIds(Long[] ids);
}

View File

@ -0,0 +1,61 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.Event;
/**
* 活动管理Service接口
*
* @author ruoyi
* @date 2024-11-12
*/
public interface IEventService
{
/**
* 查询活动管理
*
* @param id 活动管理主键
* @return 活动管理
*/
public Event selectEventById(Long id);
/**
* 查询活动管理列表
*
* @param event 活动管理
* @return 活动管理集合
*/
public List<Event> selectEventList(Event event);
/**
* 新增活动管理
*
* @param event 活动管理
* @return 结果
*/
public int insertEvent(Event event);
/**
* 修改活动管理
*
* @param event 活动管理
* @return 结果
*/
public int updateEvent(Event event);
/**
* 批量删除活动管理
*
* @param ids 需要删除的活动管理主键集合
* @return 结果
*/
public int deleteEventByIds(Long[] ids);
/**
* 删除活动管理信息
*
* @param id 活动管理主键
* @return 结果
*/
public int deleteEventById(Long id);
}

View File

@ -0,0 +1,93 @@
package com.ruoyi.system.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EventMapper;
import com.ruoyi.system.domain.Event;
import com.ruoyi.system.service.IEventService;
/**
* 活动管理Service业务层处理
*
* @author ruoyi
* @date 2024-11-12
*/
@Service
public class EventServiceImpl implements IEventService
{
@Autowired
private EventMapper eventMapper;
/**
* 查询活动管理
*
* @param id 活动管理主键
* @return 活动管理
*/
@Override
public Event selectEventById(Long id)
{
return eventMapper.selectEventById(id);
}
/**
* 查询活动管理列表
*
* @param event 活动管理
* @return 活动管理
*/
@Override
public List<Event> selectEventList(Event event)
{
return eventMapper.selectEventList(event);
}
/**
* 新增活动管理
*
* @param event 活动管理
* @return 结果
*/
@Override
public int insertEvent(Event event)
{
return eventMapper.insertEvent(event);
}
/**
* 修改活动管理
*
* @param event 活动管理
* @return 结果
*/
@Override
public int updateEvent(Event event)
{
return eventMapper.updateEvent(event);
}
/**
* 批量删除活动管理
*
* @param ids 需要删除的活动管理主键
* @return 结果
*/
@Override
public int deleteEventByIds(Long[] ids)
{
return eventMapper.deleteEventByIds(ids);
}
/**
* 删除活动管理信息
*
* @param id 活动管理主键
* @return 结果
*/
@Override
public int deleteEventById(Long id)
{
return eventMapper.deleteEventById(id);
}
}

View File

@ -0,0 +1,71 @@
<?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.system.mapper.EventMapper">
<resultMap type="Event" id="EventResult">
<result property="id" column="id" />
<result property="title" column="title" />
<result property="location" column="location" />
<result property="startTime" column="start_time" />
<result property="endTime" column="end_time" />
</resultMap>
<sql id="selectEventVo">
select id, title, location, start_time, end_time from db_event
</sql>
<select id="selectEventList" parameterType="Event" resultMap="EventResult">
<include refid="selectEventVo"/>
<where>
<if test="title != null and title != ''"> and title = #{title}</if>
<if test="location != null and location != ''"> and location = #{location}</if>
<if test="startTime != null "> and start_time = #{startTime}</if>
<if test="endTime != null "> and end_time = #{endTime}</if>
</where>
</select>
<select id="selectEventById" parameterType="Long" resultMap="EventResult">
<include refid="selectEventVo"/>
where id = #{id}
</select>
<insert id="insertEvent" parameterType="Event" useGeneratedKeys="true" keyProperty="id">
insert into db_event
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">title,</if>
<if test="location != null">location,</if>
<if test="startTime != null">start_time,</if>
<if test="endTime != null">end_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">#{title},</if>
<if test="location != null">#{location},</if>
<if test="startTime != null">#{startTime},</if>
<if test="endTime != null">#{endTime},</if>
</trim>
</insert>
<update id="updateEvent" parameterType="Event">
update db_event
<trim prefix="SET" suffixOverrides=",">
<if test="title != null">title = #{title},</if>
<if test="location != null">location = #{location},</if>
<if test="startTime != null">start_time = #{startTime},</if>
<if test="endTime != null">end_time = #{endTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEventById" parameterType="Long">
delete from db_event where id = #{id}
</delete>
<delete id="deleteEventByIds" parameterType="String">
delete from db_event where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -115,7 +115,7 @@ public class SecurityConfig
.requestMatchers("/login", "/register", "/captchaImage").permitAll() .requestMatchers("/login", "/register", "/captchaImage").permitAll()
.requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll() .requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll()
.requestMatchers("/swagger-ui.html", "/v3/api-docs/**", "/swagger-ui/**", "/druid/**").permitAll() .requestMatchers("/swagger-ui.html", "/v3/api-docs/**", "/swagger-ui/**", "/druid/**").permitAll()
.requestMatchers("/system/course/**", "/system/teacher/**", "/system/advice/**").permitAll() .requestMatchers("/system/course/**", "/system/teacher/**", "/system/advice/**", "/system/event/**").permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
}) })
// 添加Logout filter // 添加Logout filter