无关风月
2024-06-18 72d4afb7b0f12753846ffb9baf0d593635df55a3
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package com.ruoyi.management.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.management.domain.TPage;
import com.ruoyi.management.domain.TProtocol;
import com.ruoyi.management.domain.TSysSet;
import com.ruoyi.management.domain.TUseGuide;
import com.ruoyi.management.dto.AggrementDTO;
import com.ruoyi.management.dto.UseGuidDTO;
import com.ruoyi.management.query.UseGuideQuery;
import com.ruoyi.management.service.ITPageService;
import com.ruoyi.management.service.ITProtocolService;
import com.ruoyi.management.service.ITSysSetService;
import com.ruoyi.management.service.ITUseGuideService;
import com.ruoyi.management.vo.PageVO;
import com.ruoyi.management.vo.SysSetVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 系统设置 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@RestController
@RequestMapping("/tSysSet")
public class TSysSetController {
    @Autowired
    private ITSysSetService sysSetService;
    @Autowired
    private ITPageService pageService;
    @Autowired
    private ITProtocolService protocolService;
    @Autowired
    private ITUseGuideService useGuideService;
 
    @ApiOperation(value = "获取系统设置", tags = {"后台-系统设置"})
    @PostMapping(value = "/getSysSet")
    public AjaxResult getSysSet() {
        TSysSet byId = sysSetService.getById(1);
        SysSetVO sysSetVO = new SysSetVO();
        BeanUtils.copyProperties(byId, sysSetVO);
        return AjaxResult.success(sysSetVO);
    }
 
    @ApiOperation(value = "保存系统设置", tags = {"后台-系统设置"})
    @PostMapping(value = "/saveSysSet")
    public AjaxResult saveSysSet(SysSetVO vo) {
        TSysSet byId = sysSetService.getById(1);
        BeanUtils.copyProperties(vo, byId);
        byId.setId(1);
        sysSetService.updateById(byId);
        return AjaxResult.success("保存成功");
    }
 
    @ApiOperation(value = "获取启动页", tags = {"后台-启动页管理"})
    @PostMapping(value = "/getPage")
    public AjaxResult getPage() {
        List<TPage> list = pageService.list();
        return AjaxResult.success(list);
    }
 
    @ApiOperation(value = "获取注意事项、启动页", tags = {"家长端-获取注意事项、启动页"})
    @PostMapping(value = "/getPage1")
    public R<List<TPage>> getPage1() {
        List<TPage> list = pageService.list();
        return R.ok(list);
    }
 
    @ApiOperation(value = "保存启动页", tags = {"后台-启动页管理"})
    @PostMapping(value = "/setPage")
    public AjaxResult setPage(@RequestBody PageVO vo) {
        String page1 = vo.getPage1();
        String page2 = vo.getPage2();
        String page3 = vo.getPage3();
        String page4 = vo.getPage4();
        if (StringUtils.hasLength(page1)) {
            TPage type = pageService.getOne(new QueryWrapper<TPage>()
                    .eq("type", 1));
            TPage tPage = new TPage();
 
            if (type == null) {
                tPage.setImg(page1);
                tPage.setType(1);
                pageService.save(tPage);
            } else {
                type.setImg(page1);
                pageService.updateById(type);
            }
        }
        if (StringUtils.hasLength(page2)) {
            TPage type = pageService.getOne(new QueryWrapper<TPage>()
                    .eq("type", 2));
            TPage tPage = new TPage();
            if (type == null) {
                tPage.setImg(page2);
                tPage.setType(2);
                pageService.save(tPage);
            } else {
                type.setImg(page2);
                pageService.updateById(type);
            }
        }
        if (StringUtils.hasLength(page3)) {
            TPage type = pageService.getOne(new QueryWrapper<TPage>()
                    .eq("type", 3));
            TPage tPage = new TPage();
 
            if (type == null) {
                tPage.setImg(page3);
                tPage.setType(3);
                pageService.save(tPage);
            } else {
                type.setImg(page3);
                pageService.updateById(type);
            }
        }
        if (StringUtils.hasLength(page4)) {
            TPage type = pageService.getOne(new QueryWrapper<TPage>()
                    .eq("type", 4));
            if (type == null) {
                TPage tPage = new TPage();
                tPage.setImg(page4);
                tPage.setType(4);
                pageService.save(tPage);
            } else {
                type.setImg(page4);
                pageService.updateById(type);
            }
        }
        return AjaxResult.success("保存成功");
    }
 
    @PostMapping("/agreement")
    @ApiOperation(value = "协议", tags = {"后台-协议管理"})
    public AjaxResult agreement( AggrementDTO dto) {
        TProtocol protocol = protocolService.getById(dto.getType());
        if (StringUtils.hasLength(dto.getContent())) {
            protocol.setContent(dto.getContent());
            protocolService.updateById(protocol);
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.success(protocol.getContent());
        }
    }
 
    @PostMapping("/agreement1/{type}")
    @ApiOperation(value = "协议", tags = {"家长端/学习端-获取协议"})
    public R<String> agreement1(@PathVariable("type") Integer type) {
        TProtocol protocol = protocolService.getOne(new QueryWrapper<TProtocol>()
                .eq("type", type));
 
        return R.ok(protocol.getContent());
 
    }
 
    @PostMapping("/useGuide")
    @ApiOperation(value = "使用指南-列表查询", tags = {"后台-使用指南"})
    public AjaxResult<PageInfo<TUseGuide>> agreement(String title, Integer pageNumber, Integer pageSize) {
        QueryWrapper<TUseGuide> wrapper = new QueryWrapper<>();
        if (StringUtils.hasLength(title)) {
            wrapper.like("title", title);
        }
        List<String> strings = new ArrayList<>();
        strings.add("insertTime");
        wrapper.orderByDesc(strings);
 
        List<TUseGuide> useGuides = useGuideService.list(wrapper);
        PageInfo<TUseGuide> res = new PageInfo<>(pageNumber, pageSize);
        res.setRecords(useGuides);
        res.setTotal(useGuides.size());
        return AjaxResult.success(res);
    }
 
    @PostMapping("/useGuide1")
    @ApiOperation(value = "列表查询", tags = {"家长端-使用指南"})
    public R<PageInfo<TUseGuide>> useGuide1(@RequestBody UseGuideQuery query) {
        query.setPageNumber((query.getPageNumber() - 1) * query.getPageSize());
        QueryWrapper<TUseGuide> wrapper = new QueryWrapper<>();
        if (StringUtils.hasLength(query.getTitle())) {
            wrapper.like("title", query.getTitle());
        }
        List<String> strings = new ArrayList<>();
        strings.add("insertTime");
        wrapper.orderByDesc(strings);
        PageInfo<TUseGuide> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        List<TUseGuide> useGuides = useGuideService.list(wrapper);
        List<TUseGuide> useGuides2 = useGuideService.listAll(query);
        PageInfo<TUseGuide> page = useGuideService.page(new PageInfo<>(query.getPageNumber(), query.getPageSize()), wrapper);
 
        res.setRecords(useGuides2);
        res.setTotal(useGuides.size());
 
        return R.ok(res);
    }
 
    @PostMapping("/updateUseGuide")
    @ApiOperation(value = "使用指南-添加/编辑/查看详情", tags = {"使用指南"})
    public AjaxResult<TUseGuide> updateUseGuide(@RequestBody UseGuidDTO dto) {
        switch (dto.getType()) {
            case 1:
                TUseGuide useGuide = new TUseGuide();
                useGuide.setTitle(dto.getTitle());
                useGuide.setSort(dto.getSort());
                useGuide.setAnswer(dto.getAnswer());
                useGuide.setInsertTime(new Date());
                useGuideService.save(useGuide);
                return AjaxResult.success(useGuide);
            case 2:
                TUseGuide useGuide1 = useGuideService.getById(dto.getId());
                useGuide1.setId(dto.getId());
                useGuide1.setTitle(dto.getTitle());
                useGuide1.setSort(dto.getSort());
                useGuide1.setAnswer(dto.getAnswer());
                useGuideService.updateById(useGuide1);
                return AjaxResult.success(useGuide1);
            case 3:
                TUseGuide useGuide2 = useGuideService.getById(dto.getId());
                return AjaxResult.success(useGuide2);
        }
        return AjaxResult.success(new TUseGuide());
    }
 
    @DeleteMapping("/delete")
    @ApiOperation(value = "使用指南-删除", tags = {"使用指南"})
    public AjaxResult updateUseGuide(Integer id) {
//        TUseGuide useGuide2 = useGuideService.getById(id);
        useGuideService.removeById(id);
        return AjaxResult.success("删除成功");
    }
 
    @GetMapping("/shareInfo")
    @ApiOperation(value = "获取分享图片、标题及可获积分数", tags = {"获取分享图片、标题及可获积分数"})
    public R<TSysSet> shareInfo() {
        return R.ok(sysSetService.lambdaQuery().one());
    }
 
    @ApiOperation(value = "获取正确及错误提示音效", tags = {"学习端-首页"})
    @GetMapping(value = "/promptVoice")
    public R<TSysSet> promptVoice() {
        return R.ok(sysSetService.lambdaQuery().eq(TSysSet::getDisabled, 0).one());
    }
 
}