新版仿ok交易所-后端
1
zj
2025-07-10 f15406ac788fb4e17a630c4d48129943af89fb9c
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
143
144
145
146
147
148
149
package com.yami.trading.admin.controller.cms;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.controller.cms.model.DeleteModel;
import com.yami.trading.admin.model.*;
import com.yami.trading.bean.cms.News;
import com.yami.trading.bean.cms.dto.NewsDto;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.security.common.manager.PasswordManager;
import com.yami.trading.service.AwsS3OSSFileService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.service.cms.NewsSerivce;
import com.yami.trading.sys.model.SysUser;
import com.yami.trading.sys.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
 
@RestController
@RequestMapping("news")
@Api(tags = "新闻管理")
public class NewsController  {
 
 
    @Autowired
    NewsSerivce newsSerivce;
 
    @Autowired
    PasswordManager passwordManager;
 
    @Autowired
    PasswordEncoder passwordEncoder;
 
    @Autowired
    SysUserService sysUserService;
 
    @Autowired
    UserService userService;
 
    @Autowired
    AwsS3OSSFileService awsS3OSSFileService;
 
    @ApiOperation(value = "列表")
    @PostMapping("list")
    public Result<Page<NewsDto>> list(@RequestBody @Valid NewsListModel request){
        Page<NewsDto> page=new Page(request.getCurrent(),request.getSize());
        newsSerivce.pageNews(page,request.getTitle(),request.getLanguage(),request.getUserCode());
        for (NewsDto news:page.getRecords()){
            news.setLanguageText(Constants.LANGUAGE.get(news.getLanguage()));
            String nUrl = Constants.IMAGES_HTTP+news.getImgUrl();
            news.setHttpImgUrl(nUrl);
        }
        return  Result.ok(page);
    }
 
    @ApiOperation(value = "新增")
    @PostMapping("add")
    public  Result<?> add(@RequestBody @Valid NewsModel model){
        model.setLoginSafeword(passwordManager.decryptPassword(model.getLoginSafeword()));
        SysUser sysUser = sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId());
        if (!passwordEncoder.matches(model.getLoginSafeword(), sysUser.getSafePassword())) {
            throw new YamiShopBindException("资金密码不正确!");
        }
        News news=new News();
        if (!StringUtils.isEmptyString(model.getUserCode())) {
            User user= userService.findUserByUserCode(model.getUserCode());
            if (user==null){
                throw  new YamiShopBindException("UID不存在");
            }
            news.setUserId(user.getUserId());
        } else {
            news.setUserId("");
        }
        news.setTitle(model.getTitle());
        news.setImgJumpUrl(model.getImgJumpUrl());
        news.setImgUrl(Constants.IMAGES_HTTP+model.getImgUrl());
        news.setClick(model.isClick());
        news.setPopUp(model.isPopUp());
        news.setIndexTop(model.isIndex());
        news.setLanguage(model.getLanguage());
        news.setStartTime(model.getStartTime());
        news.setEndTime(model.getEndTime());
        news.setContent(model.getContent());
        newsSerivce.save(news);
        return  Result.ok(null);
    }
 
 
    @ApiOperation(value = "更新")
    @PostMapping("update")
    public  Result<?> update(@RequestBody @Valid NewsModel model){
        model.setLoginSafeword(passwordManager.decryptPassword(model.getLoginSafeword()));
        SysUser sysUser = sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId());
        if (!passwordEncoder.matches(model.getLoginSafeword(), sysUser.getSafePassword())) {
            throw new YamiShopBindException("资金密码不正确!");
        }
        News news=newsSerivce.getById(model.getId());
        if (news==null){
            throw  new YamiShopBindException("参数错误!");
        }
 
        if (!StringUtils.isEmptyString(model.getUserCode())) {
            User user= userService.findUserByUserCode(model.getUserCode());
            if (user==null){
                throw  new YamiShopBindException("UID不存在");
            }
            news.setUserId(user.getUserId());
        } else {
            news.setUserId("");
        }
        news.setTitle(model.getTitle());
        news.setImgJumpUrl(model.getImgJumpUrl());
        news.setClick(model.isClick());
        news.setPopUp(model.isPopUp());
        news.setImgUrl(Constants.IMAGES_HTTP+model.getImgUrl());
        news.setIndexTop(model.isIndex());
        news.setLanguage(model.getLanguage());
        news.setStartTime(model.getStartTime());
        news.setEndTime(model.getEndTime());
        news.setContent(model.getContent());
        newsSerivce.updateById(news);
        return  Result.ok(null);
    }
 
    @ApiOperation(value = "获取语言")
    @GetMapping("getLanguage")
    public  Result<?> getLanguage(){
        return  Result.ok(Constants.LANGUAGE);
    }
 
 
 
    @ApiOperation(value = "删除")
    @PostMapping("delete")
    public  Result<?> delete(@RequestBody @Valid DeleteModel model){
        sysUserService.checkSafeWord(model.getLoginSafeword());
        newsSerivce.removeById(model.getId());
        return  Result.ok(null);
    }
}