107 lines
3.0 KiB
Java
107 lines
3.0 KiB
Java
|
|
package com.cdzy.activity.controller;
|
|||
|
|
|
|||
|
|
import com.cdzy.activity.model.Bulletin;
|
|||
|
|
import com.cdzy.activity.model.JsonResult;
|
|||
|
|
import com.cdzy.activity.model.PageParam;
|
|||
|
|
import com.cdzy.activity.model.vo.BulletinVo;
|
|||
|
|
import com.cdzy.activity.service.BulletinService;
|
|||
|
|
import com.mybatisflex.core.paginate.Page;
|
|||
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|||
|
|
import com.mybatisflex.core.util.StringUtil;
|
|||
|
|
import jakarta.annotation.Resource;
|
|||
|
|
import org.springframework.web.bind.annotation.*;
|
|||
|
|
|
|||
|
|
import java.io.IOException;
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
import static com.cdzy.activity.model.table.BulletinTableDef.BULLETIN;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 公告控制层。
|
|||
|
|
*
|
|||
|
|
* @author attiya
|
|||
|
|
* @since 2025-09-18
|
|||
|
|
*/
|
|||
|
|
@RestController
|
|||
|
|
@RequestMapping("/bulletin")
|
|||
|
|
public class BulletinController {
|
|||
|
|
|
|||
|
|
@Resource
|
|||
|
|
private BulletinService bulletinService;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 保存。
|
|||
|
|
*
|
|||
|
|
* @param bulletin 公告基础信息
|
|||
|
|
* @return {@code true} 保存成功,{@code false} 保存失败
|
|||
|
|
*/
|
|||
|
|
@PostMapping(value = "save",consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|||
|
|
public JsonResult<?> save(BulletinVo bulletin) throws IOException {
|
|||
|
|
bulletinService.saveBulletin(bulletin);
|
|||
|
|
return JsonResult.success();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 根据主键删除。
|
|||
|
|
*
|
|||
|
|
* @param id 主键
|
|||
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|||
|
|
*/
|
|||
|
|
@DeleteMapping("remove/{id}")
|
|||
|
|
public JsonResult<?> remove(@PathVariable Long id) {
|
|||
|
|
bulletinService.removeById(id);
|
|||
|
|
return JsonResult.success();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 根据主键更新。
|
|||
|
|
*
|
|||
|
|
* @param bulletin 基础信息
|
|||
|
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
|||
|
|
*/
|
|||
|
|
@PutMapping(value = "update",consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|||
|
|
public JsonResult<?> update(BulletinVo bulletin) throws IOException {
|
|||
|
|
bulletinService.updateBulletind(bulletin);
|
|||
|
|
return JsonResult.success();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询所有。
|
|||
|
|
*
|
|||
|
|
* @return 所有数据
|
|||
|
|
*/
|
|||
|
|
@GetMapping("list")
|
|||
|
|
public JsonResult<?> list() {
|
|||
|
|
List<Bulletin> list = bulletinService.list();
|
|||
|
|
return JsonResult.success(list);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 根据主键获取。
|
|||
|
|
*
|
|||
|
|
* @param id 主键
|
|||
|
|
* @return 详情
|
|||
|
|
*/
|
|||
|
|
@GetMapping("getInfo/{id}")
|
|||
|
|
public JsonResult<?> getInfo(@PathVariable Long id) {
|
|||
|
|
Bulletin bulletin = bulletinService.getById(id);
|
|||
|
|
return JsonResult.success(bulletin);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 分页查询
|
|||
|
|
* @param pageParam 分页参数
|
|||
|
|
* @param bulletinTitle 公告标题
|
|||
|
|
* @return 分页结果
|
|||
|
|
*/
|
|||
|
|
@GetMapping("page")
|
|||
|
|
public JsonResult<?> page(PageParam pageParam, String bulletinTitle) {
|
|||
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|||
|
|
.where(BULLETIN.BULLETIN_TITLE.like(bulletinTitle, StringUtil.hasText(bulletinTitle)));
|
|||
|
|
Page<Bulletin> page = bulletinService.page(pageParam.getPage(), queryWrapper);
|
|||
|
|
return JsonResult.success(page);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|