MaterialController.java
4.41 KB
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
package com.bs.reception.controller.materials;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bs.common.core.domain.AjaxResult;
import com.bs.reception.entity.materials.Material;
import com.bs.reception.model.materials.MaterialPageQuery;
import com.bs.reception.model.materials.MaterialPageVO;
import com.bs.reception.service.IMaterialService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
@Tag(name = "素材管理", description = "素材管理接口")
@RequestMapping("/materials/materials")
public class MaterialController {
@Resource
private IMaterialService materialService;
@PostMapping("/list")
@Operation(summary = "素材列表")
public AjaxResult list(@RequestBody Material body) {
try {
List<Material> list = materialService.getMaterialList(body);
return AjaxResult.success(list);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/create")
@Operation(summary = "创建素材")
public AjaxResult create(@RequestBody Material body) {
try {
Material data = materialService.createMaterial(body);
return AjaxResult.success(data);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/update")
@Operation(summary = "更新素材")
public AjaxResult update(@RequestBody Material body) {
try {
boolean ok = materialService.updateMaterial(body);
return AjaxResult.success(ok);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+ e.getMessage());
}
}
@PostMapping("/sort")
@Operation(summary = "设置排序")
public AjaxResult setSort(@RequestBody Material body) {
try {
boolean ok = materialService.setMaterialSort(body);
return AjaxResult.success(ok);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/homepage")
@Operation(summary = "设置首页展示")
public AjaxResult setHomepage(@RequestBody Material body) {
try {
boolean ok = materialService.setMaterialHomepage(body);
return AjaxResult.success(ok);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/page")
@Operation(summary = "素材分页查询")
public AjaxResult page(@RequestBody MaterialPageQuery query) {
try {
Page<MaterialPageVO> data = materialService.pageMaterials(query);
return AjaxResult.success(data);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/delete")
@Operation(summary = "删除素材")
public AjaxResult delete(@RequestBody Material body) {
try {
boolean ok = materialService.deleteMaterial(body);
return AjaxResult.success(ok);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
@PostMapping("/detail")
@Operation(summary = "素材详情")
public AjaxResult detail(@RequestBody Material body) {
try {
Material ok = materialService.getMaterialDetail(body);
return AjaxResult.success(ok);
} catch (Exception e) {
log.error("操作失败:{}", e.getMessage(), e);
return AjaxResult.error("操作失败:"+e.getMessage());
}
}
}