package com.ruoyi.web.controller.api; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.dto.SystemBulletinDTO; import com.ruoyi.system.model.TSystemBulletin; import com.ruoyi.system.query.SystemBulletinQuery; import com.ruoyi.system.service.TSystemBulletinService; import com.ruoyi.system.vo.system.SystemBulletinListVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Arrays; /** *

* 系统公告 前端控制器 *

* * @author xiaochen * @since 2025-05-28 */ @Api(tags = "系统公告") @RestController @RequestMapping("/t-system-bulletin") public class TSystemBulletinController { @Resource private TSystemBulletinService systemBulletinService; /** * 获取谱系图详情待入库菌种分页列表 */ @ApiOperation(value = "系统公告分页列表") @PostMapping(value = "/pageList") public R> pageList(@RequestBody SystemBulletinQuery query) { return R.ok(systemBulletinService.pageList(query)); } @Log(title = "新增系统公告", businessType = BusinessType.INSERT) @ApiOperation(value = "新增系统公告") @PostMapping(value = "/add") public R add(@RequestBody SystemBulletinDTO dto) { if(dto.getStatus()==1){ systemBulletinService.update(Wrappers.lambdaUpdate(TSystemBulletin.class) .set(TSystemBulletin::getStatus, 2)); } systemBulletinService.save(dto); return R.ok(); } @Log(title = "编辑系统公告", businessType = BusinessType.UPDATE) @ApiOperation(value = "编辑系统公告") @PostMapping(value = "/edit") public R edit(@RequestBody SystemBulletinDTO dto) { if(dto.getStatus()==1){ systemBulletinService.update(Wrappers.lambdaUpdate(TSystemBulletin.class) .set(TSystemBulletin::getStatus, 2)); } systemBulletinService.updateById(dto); return R.ok(); } @ApiOperation(value = "详情系统公告") @GetMapping(value = "/detail") public R detail(@RequestParam String id) { return R.ok(systemBulletinService.getById(id)); } @Log(title = "删除系统公告", businessType = BusinessType.DELETE) @ApiOperation(value = "删除系统公告") @DeleteMapping(value = "/deleteById") public R deleteById(@RequestParam String id) { systemBulletinService.removeById(id); return R.ok(); } @Log(title = "批量删除系统公告", businessType = BusinessType.DELETE) @ApiOperation(value = "批量删除系统公告") @DeleteMapping(value = "/deleteByIds") public R deleteByIds(@RequestParam String ids) { String[] split = ids.split(","); systemBulletinService.removeBatchByIds(Arrays.asList(split)); return R.ok(); } @Log(title = "启用/禁用系统公告", businessType = BusinessType.OTHER) @ApiOperation(value = "启用/禁用系统公告") @GetMapping(value = "/editStatus") public R editStatus(@RequestParam String id) { TSystemBulletin byId = systemBulletinService.getById(id); if (byId.getStatus()==1){ byId.setStatus(2); }else{ // 查询是否存在已启用的公告 long count = systemBulletinService.count(Wrappers.lambdaQuery(TSystemBulletin.class) .eq(TSystemBulletin::getStatus, 1)); if (count>0){ return R.fail("已有启用公告,请将旧公告禁用"); } byId.setStatus(1); } systemBulletinService.updateById(byId); return R.ok(); } }