cloudroam
2025-03-13 d2f062b46a96a2083864d529aff28628eea26b58
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.jsh.erp.controller;
 
import com.jsh.erp.datasource.entities.CloudContent;
import com.jsh.erp.service.cloudContent.CloudContentService;
import com.jsh.erp.utils.BaseResponseInfo;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/cloudContent")
@Api(tags = "内容管理接口")
public class CloudContentController {
    @Resource
    private CloudContentService cloudContentService;
 
    @GetMapping("/list")
    public BaseResponseInfo list(@RequestParam(value = "title", required = false) String title,
                                 @RequestParam(value = "type", required = false) String type,
                                 @RequestParam(value = "status", required = false) Integer status,
                                 @RequestParam("currentPage") Integer currentPage,
                                 @RequestParam("pageSize") Integer pageSize) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        Map<String, Object> map = new HashMap<>();
        try {
            CloudContent query = new CloudContent();
            query.setTitle(title);
            query.setType(type);
            query.setStatus(status);
 
            List<CloudContent> dataList = cloudContentService.getList(query);
            int total = dataList.size();
            map.put("total", total);
            map.put("rows", dataList);
            baseResponseInfo.code = 200;
            baseResponseInfo.data = map;
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @GetMapping("/getByType")
    public BaseResponseInfo getByType(@RequestParam(value = "type", required = true) String type) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            CloudContent cloudContent = cloudContentService.getByType(type);
            baseResponseInfo.code = 200;
            baseResponseInfo.data = cloudContent;
        } catch (Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @GetMapping("/{id}")
    public BaseResponseInfo getById(@PathVariable Long id) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            CloudContent data = cloudContentService.getById(id);
            baseResponseInfo.code = 200;
            baseResponseInfo.data = data;
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @PostMapping
    public BaseResponseInfo add(@RequestBody CloudContent cloudContent) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = cloudContentService.add(cloudContent);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.data = "新增成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @PutMapping
    public BaseResponseInfo update(@RequestBody CloudContent cloudContent) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = cloudContentService.update(cloudContent);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.data = "修改成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @DeleteMapping("/{id}")
    public BaseResponseInfo delete(@PathVariable Long id) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = cloudContentService.deleteById(id);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.data = "删除成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @DeleteMapping("/deleteBatch")
    public BaseResponseInfo deleteBatch(@RequestParam("ids") String ids) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            String[] idArray = ids.split(",");
            int result = 0;
            for(String id : idArray) {
                result += cloudContentService.deleteById(Long.parseLong(id));
            }
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.data = "删除成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.data = e.getMessage();
        }
        return baseResponseInfo;
    }
}