44323
2024-04-23 16b704d18a875d1fb63827aaa507790ba2bef5be
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package com.stylefeng.guns.modular.code.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.common.annotion.BussinessLog;
import com.stylefeng.guns.core.common.constant.dictmap.DeptDict;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dto.AggrementDTO;
import com.stylefeng.guns.modular.system.dto.OrderQuery;
import com.stylefeng.guns.modular.system.dto.UseGuidDTO;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.vo.OrderListVO;
import com.stylefeng.guns.modular.system.vo.RedPackageVO;
import com.stylefeng.guns.modular.system.vo.SystemSetVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.*;
 
@Controller
@RequestMapping("/base/system")
public class SystemController {
 
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IPageService pageService;
    @Autowired
    private IProtocolService protocolService;
    @Autowired
    private IUseGuideService useGuideService;
    @Autowired
    private ISysSetService sysSetService;
    @Autowired
    private IRedPackageService redPackageService;
    @Autowired
    private IAppUserService appUserService;
    @ResponseBody
    @PostMapping("/page")
    @ApiOperation(value = "启动页引导页", tags = {"启动页引导页管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型1=启动页 2=引导页", name = "type", required = true),
            @ApiImplicitParam(value = "图片,多张逗号隔开(该字段不传的时候为查看,传了为修改)", name = "img")
    })
    public ResultUtil page(Integer type,String img) {
        Page type1 = pageService.selectOne(new EntityWrapper<Page>()
                .eq("type", type));
        if(StringUtils.hasLength(img)){
            if (type1!=null){
                type1.setImg(img);
                pageService.updateById(type1);
            }else{
                Page page = new Page();
                page.setImg(img);
                page.setType(type);
                pageService.insert(page);
            }
            return ResultUtil.success("修改成功");
        }else{
            if (type1!=null){
                return ResultUtil.success(type1.getImg());
            }else{
                Page page = new Page();
                page.setImg(img);
                page.setType(type);
                pageService.insert(page);
                return ResultUtil.success();
            }
        }
    }
    @ResponseBody
    @PostMapping("/riskInfo")
    @ApiOperation(value = "运动风险告知", tags = {"运动风险告知"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "内容", name = "content"),
    })
    public ResultUtil page(String content) {
        SysSet sysSet = sysSetService.selectById(1);
        String riskInfo = sysSet.getRiskInfo();
 
        if(StringUtils.hasLength(content)){
            sysSet.setRiskInfo(content);
            sysSetService.updateById(sysSet);
            return ResultUtil.success("修改成功");
        }else{
            return ResultUtil.success(riskInfo);
        }
    }
 
    @ResponseBody
    @PostMapping("/agreement")
    @ApiOperation(value = "协议", tags = {"协议管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型1=用户协议 2=隐私协议 3=注销协议 4=关于我们", name = "type", required = true),
            @ApiImplicitParam(value = "内容(该字段不传的时候为查看,传了为修改)", name = "content"),
    })
    public ResultUtil agreement(@RequestBody AggrementDTO dto) {
        Protocol protocol = protocolService.selectById(dto.getType());
        if(StringUtils.hasLength(dto.getContent())){
            protocol.setContent(dto.getContent());
            protocolService.updateById(protocol);
            return ResultUtil.success("修改成功");
        }else{
            return ResultUtil.success(protocol.getContent());
        }
    }
    @ResponseBody
    @PostMapping("/useGuide")
    @ApiOperation(value = "使用指南-列表查询", tags = {"使用指南"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题标题", name = "title"),
    })
    public ResultUtil<PageInfo<UseGuide>> agreement(String title,Integer pageNum,Integer pageSize) {
        EntityWrapper<UseGuide> wrapper = new EntityWrapper<>();
        if (StringUtils.hasLength(title)){
            wrapper.like("title",title);
        }
        List<String> strings = new ArrayList<>();
        strings.add("insertTime");
        wrapper.orderDesc(strings);
        wrapper.ne("isDelete",1);
        List<UseGuide> useGuides = useGuideService.selectList(wrapper);
//        PageHelper.startPage(pageNum,pageSize);
        PageInfo<UseGuide> info=new PageInfo<>(useGuides);
        return ResultUtil.success(info);
    }
 
    @ResponseBody
    @PostMapping("/updateUseGuide")
    @ApiOperation(value = "使用指南-添加/编辑/查看详情", tags = {"使用指南"})
    public ResultUtil<UseGuide> updateUseGuide(@RequestBody UseGuidDTO dto) {
        switch (dto.getType()){
            case 1:
                UseGuide useGuide = new UseGuide();
                useGuide.setTitle(dto.getTitle());
                useGuide.setSort(dto.getSort());
                useGuide.setIsDelete(0);
                useGuide.setAnswer(dto.getAnswer());
                useGuide.setInsertTime(new Date());
                useGuideService.insert(useGuide);
                return ResultUtil.success(useGuide);
            case 2:
                UseGuide useGuide1 = useGuideService.selectById(dto.getId());
                useGuide1.setId(dto.getId());
                useGuide1.setTitle(dto.getTitle());
                useGuide1.setSort(dto.getSort());
                useGuide1.setAnswer(dto.getAnswer());
                useGuideService.updateById(useGuide1);
                return ResultUtil.success(useGuide1);
            case 3:
                UseGuide useGuide2 = useGuideService.selectById(dto.getId());
                return ResultUtil.success(useGuide2);
        }
        return ResultUtil.success(new UseGuide());
    }
    @ResponseBody
    @PostMapping("/deleteUseGuide")
    @ApiOperation(value = "使用指南删除", tags = {"使用指南"})
    public ResultUtil deleteUseGuide(Integer id) {
        UseGuide useGuide = useGuideService.selectById(id);
        useGuide.setIsDelete(1);
        useGuideService.updateById(useGuide);
        return ResultUtil.success("删除成功");
    }
    @Autowired
    private IUpdateSetService updateSetService;
    @ResponseBody
    @PostMapping("/systemSet")
    @ApiOperation(value = "系统设置", tags = {"系统设置"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "联系方式", name = "phone"),
            @ApiImplicitParam(value = "邀请人可获得被邀请人消费金额比例", name = "people"),
            @ApiImplicitParam(value = "团队长可获得团员消费金额比例", name = "header"),
            @ApiImplicitParam(value = "推广赚钱说明", name = "introduce"),
            @ApiImplicitParam(value = "是否首次下单赠送物品0否1是", name = "isGive"),
            @ApiImplicitParam(value = "运动风险告知", name = "riskInfo"),
            @ApiImplicitParam(value = "类型1=编辑 2=查看详情", name = "type",required = true),
    })
    public ResultUtil<SystemSetVO> systemSet(String phone, String people, String header, String introduce, Integer isGive, String riskInfo, Integer type) {
        SysSet sysSet2 = sysSetService.selectById(1);
        SystemSetVO systemSetVO = new SystemSetVO();
        switch (type){
            case 1:
                // 编辑
                SysSet sysSet = new SysSet();
                sysSet.setId(1);
                sysSet.setPhone(phone);
                sysSet.setPeople(people);
                sysSet.setHeader(header);
                sysSet.setIntroduce(introduce);
                sysSet.setIsGive(isGive);
                sysSet.setRiskInfo(riskInfo);
                sysSetService.updateById(sysSet);
                if (!people.equals(sysSet2.getPeople())){
                    // 修改了
                    UpdateSet updateSet = new UpdateSet();
                    updateSet.setBeforePeople(sysSet2.getPeople());
                    updateSet.setPeople(people);
                    updateSet.setBeforeHeader(sysSet2.getHeader());
                    updateSet.setHeader(header);
                    updateSet.setUpdateTime(new Date());
                    updateSetService.insert(updateSet);
                }else if (!header.equals(sysSet2.getHeader())){
                    // 修改了
                    UpdateSet updateSet = new UpdateSet();
                    updateSet.setBeforePeople(sysSet2.getPeople());
                    updateSet.setPeople(people);
                    updateSet.setBeforeHeader(sysSet2.getHeader());
                    updateSet.setHeader(header);
                    updateSet.setUpdateTime(new Date());
                    updateSetService.insert(updateSet);
                }
                systemSetVO.setId(1);
                systemSetVO.setPhone(phone);
                systemSetVO.setPeople(people);
                systemSetVO.setHeader(header);
                systemSetVO.setIntroduce(introduce);
                systemSetVO.setIsGive(isGive);
                systemSetVO.setRiskInfo(riskInfo);
                break;
            case 2:
                // 查看详情
                SysSet sysSet1 = sysSetService.selectById(1);
                BeanUtils.copyProperties(sysSet1,systemSetVO);
                break;
        }
        List<RedPackageVO> vo = redPackageService.selectAll();
        systemSetVO.setRedPackageList(vo);
        // 查询红包记录
        return ResultUtil.success(systemSetVO);
    }
    @ResponseBody
    @PostMapping("/reaPackageList")
    @ApiOperation(value = "红包领取记录列表查询", tags = {"系统设置"})
    public ResultUtil<PageInfo<RedPackageVO>> courseList(OrderQuery query) {
        List<RedPackageVO> vo = redPackageService.selectAll();
//        PageHelper.startPage(query.getPageNum(),query.getPageSize());
        PageInfo<RedPackageVO> info=new PageInfo<>(vo);
        return ResultUtil.success(info);
    }
    @Autowired
    private IMessageService messageService;
    @ResponseBody
    @PostMapping("/addRedPackage")
    @ApiOperation(value = "发放红包", tags = {"系统设置"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发放金额", name = "amount"),
    })
    public ResultUtil addRedPackage(BigDecimal amount) {
        // 添加发放红包记录
        RedPackage redPackage = new RedPackage();
        redPackage.setAmount(amount);
        redPackage.setInsertUserId(Objects.requireNonNull(ShiroKit.getUser()).id);
        redPackage.setInsertTime(new Date());
        redPackageService.insert(redPackage);
        // 给每个用户的余额增加响应的金额
        List<AppUser> users = appUserService.selectList(new EntityWrapper<AppUser>()
                .eq("state", 1));
        for (AppUser user : users) {
            BigDecimal balance = user.getBalance();
            BigDecimal add = balance.add(amount);
            user.setBalance(add);
            appUserService.updateById(user);
            // 给用户发消息
            Message message = new Message();
            message.setUserId(user.getId());
            message.setType(1);
            message.setContent("系统发送红包¥"+amount+"到账至您的余额");
            message.setInsertTime(new Date());
            message.setIsRead(0);
            messageService.insert(message);
        }
        return ResultUtil.success("发放成功");
    }
}