Hentua
2023-06-15 bfa4d0fc1ce8d297fb2bea1c467ec335def8fa89
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
package cc.mrbird.febs.mall.controller;
 
import cc.mrbird.febs.common.annotation.ControllerEndpoint;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.mall.dto.MallNewsInfoDto;
import cc.mrbird.febs.mall.entity.MallNewsCategory;
import cc.mrbird.febs.mall.entity.MallNewsInfo;
import cc.mrbird.febs.mall.service.IMallNewsCategoryService;
import cc.mrbird.febs.mall.service.IMallNewsInfoService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.management.Query;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2022-05-13
 **/
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/admin/news")
public class AdminNewsInfoController extends BaseController {
 
    private final IMallNewsInfoService mallNewsInfoService;
    private final IMallNewsCategoryService mallNewsCategoryService;
 
    /**
     * 新闻中心-列表
     * @param mallNewsInfo
     * @param request
     * @return
     */
    @GetMapping("getNewInfoList")
    public FebsResponse getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) {
        Map<String, Object> data = getDataTable(mallNewsInfoService.getNewInfoList(mallNewsInfo, request));
        return new FebsResponse().success().data(data);
    }
 
    /**
     * 新闻中心-新增
     */
    @PostMapping("addNewsInfo")
    @ControllerEndpoint(operation = " 新闻中心-新增", exceptionMessage = "操作失败")
    public FebsResponse addNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
        return mallNewsInfoService.addNewsInfo(mallNewsInfoDto);
    }
 
    /**
     * 新闻中心-删除
     */
    @GetMapping("delNewsInfo/{id}")
    @ControllerEndpoint(operation = " 新闻中心-删除", exceptionMessage = "操作失败")
    public FebsResponse delNewsInfo(@NotNull(message = "{required}") @PathVariable Long id) {
        return mallNewsInfoService.delNewsInfo(id);
    }
 
    /**
     * 新闻中心-更新
     */
    @PostMapping("updateNewsInfo")
    @ControllerEndpoint(operation = "新闻中心-更新", exceptionMessage = "操作失败")
    public FebsResponse updateNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
        return mallNewsInfoService.updateNewsInfo(mallNewsInfoDto);
    }
 
 
    @GetMapping("findNewsCategoryList")
    @ControllerEndpoint(operation = "新闻分类列表", exceptionMessage = "获取失败")
    public FebsResponse findNewsCategoryList(MallNewsCategory mallNewsCategory, QueryRequest request) {
        return new FebsResponse().success().data(getDataTable(mallNewsInfoService.findNewsCategoryInPage(mallNewsCategory, request)));
    }
 
    @PostMapping("addOrModifyNewsCategory")
    @ControllerEndpoint(operation = "新闻分类", exceptionMessage = "新增失败")
    public FebsResponse addOrModifyNewsCategory(MallNewsCategory mallNewsCategory) {
        mallNewsInfoService.addOrModifyNewsCategory(mallNewsCategory);
        return new FebsResponse().success().message("新增成功");
    }
 
    /**
     * 新闻分类-删除
     */
    @GetMapping("delNewsCategoryInfo/{id}")
    @ControllerEndpoint(operation = "新闻分类-删除", exceptionMessage = "操作失败")
    public FebsResponse delNewsCategoryInfo(@NotNull(message = "{required}") @PathVariable Long id) {
        return mallNewsInfoService.delNewsCategoryInfo(id);
    }
 
    @GetMapping(value = "findAllCategoryList")
    public FebsResponse findAllCategoryList(String code) {
        LambdaQueryWrapper<MallNewsCategory> query = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(code)) {
            query.eq(MallNewsCategory::getCode, code);
        }
        List<MallNewsCategory> categories = mallNewsCategoryService.list(query);
        return new FebsResponse().success().data(categories);
    }
 
    @PostMapping(value = "/topNews/{id}")
    public FebsResponse topNews(@PathVariable Long id) {
        MallNewsInfo mallNewsInfo = new MallNewsInfo();
        mallNewsInfo.setIsTop(1);
        mallNewsInfo.setId(id);
        mallNewsInfoService.updateById(mallNewsInfo);
        return new FebsResponse().success();
    }
 
    @PostMapping(value = "/unTopNews/{id}")
    public FebsResponse unTopNews(@PathVariable Long id) {
        MallNewsInfo mallNewsInfo = new MallNewsInfo();
        mallNewsInfo.setIsTop(2);
        mallNewsInfo.setId(id);
        mallNewsInfoService.updateById(mallNewsInfo);
        return new FebsResponse().success();
    }
}