无关风月
16 小时以前 02bb94e413f6950b9786c5ee86c0937bc20f8ae8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;
 
/**
 * <p>
 * 系统公告 前端控制器
 * </p>
 *
 * @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<PageInfo<SystemBulletinListVO>> pageList(@RequestBody SystemBulletinQuery query) {
        return R.ok(systemBulletinService.pageList(query));
    }
    @Log(title = "新增系统公告", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增系统公告")
    @PostMapping(value = "/add")
    public R<Boolean> 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<Boolean> 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<TSystemBulletin> detail(@RequestParam String id) {
 
        return R.ok(systemBulletinService.getById(id));
    }
 
    @Log(title = "删除系统公告", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除系统公告")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        systemBulletinService.removeById(id);
        return R.ok();
    }
    @Log(title = "批量删除系统公告", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除系统公告")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> 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<Boolean> 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();
    }
}