123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package com.benyun.controller;
- import cn.hutool.core.util.StrUtil;
- import com.benyun.boot.core.vo.Result;
- import com.benyun.entity.Event;
- import com.benyun.service.EventService;
- import com.benyun.vo.EventPageVo;
- import lombok.RequiredArgsConstructor;
- import org.beetl.sql.core.engine.PageQuery;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- /**
- * @author makejava
- * create on 2023-03-17 09:06:58
- */
- @RestController
- @RequestMapping("event")
- @RequiredArgsConstructor(onConstructor_ = {@Autowired})
- @CrossOrigin
- public class EventController {
- /**
- * 服务对象
- */
- private final EventService eventService;
- /**
- * 查询所有数据
- *
- * @return 所有数据
- */
- @GetMapping("/queryAll")
- public Result<List<Event>> queryAll() {
- return Result.success(eventService.queryAll());
- }
- /**
- * 分页查询数据
- *
- * @return 所有数据
- */
- @GetMapping("/queryPage")
- public Result<EventPageVo> queryPage(@RequestParam Integer pageNum,
- @RequestParam Integer pageSize,
- @RequestParam String applyId,
- @RequestParam(required = false) String eventName,
- @RequestParam(required = false) String eventType) {
- PageQuery<Event> pageQuery = new PageQuery<Event>();
- pageQuery.setPageSize(pageSize);
- pageQuery.setPageNumber(pageNum);
- pageQuery.setPara("applyId", applyId);
- if (StrUtil.isNotBlank(eventName))
- pageQuery.setPara("eventName", "%" + eventName + "%");
- if (StrUtil.isNotBlank(eventType))
- pageQuery.setPara("eventType", "%" + eventType + "%");
- EventPageVo eventPageVo = eventService.queryByPage(pageQuery);
- return Result.success(eventPageVo);
- }
- /**
- * 通过主键查询单条数据
- *
- * @param id 主键
- * @return 单条数据
- */
- @GetMapping("/queryOne")
- public Result<Event> queryOne(@RequestParam("id") String id, @RequestParam("applyId") String applyId) {
- return Result.success(eventService.queryById(id, applyId));
- }
- /**
- * 新增数据
- *
- * @param event 实体对象
- * @return 新增结果
- */
- @PostMapping("/create")
- public Result<?> create(@RequestBody Event event) {
- eventService.insert(event);
- return Result.success(event);
- }
- /**
- * 修改数据
- *
- * @param event 实体对象
- * @return 修改结果
- */
- @PostMapping("/update")
- public Result<?> update(@RequestBody Event event) {
- return eventService.updateById(event) ? Result.success() : Result.failure();
- }
- /**
- * 修改数据2
- *
- * @param event 实体对象
- * @return 修改结果
- */
- @PostMapping("/update2")
- public Result<?> update2(@RequestBody Event event) {
- return eventService.updateById2(event) ? Result.success() : Result.failure();
- }
- /**
- * 删除数据
- *
- * @param id 主键
- * @return 删除结果
- */
- @PostMapping("/delete")
- public Result<Boolean> delete(@RequestParam("id") String id, @RequestParam("applyId") String applyId) {
- return Result.success(this.eventService.deleteById(id, applyId));
- }
- }
|