xuhy
2025-12-24 989dcc6e5a2db194954d48ef411dab60b1fd35ea
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
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.XiaoeLiveDTO;
import com.ruoyi.system.model.TSysEducationalInfo;
import com.ruoyi.system.model.TSysLive;
import com.ruoyi.system.model.TSysProductIntroduction;
import com.ruoyi.system.query.TSysLiveQuery;
import com.ruoyi.system.service.TSysLiveService;
import com.ruoyi.system.utils.util.XiaoeUtils;
import com.ruoyi.system.vo.TSysLiveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
/**
 * <p>
 * 直播管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-08-20
 */
@Api(tags = "直播管理")
@RestController
@RequestMapping("/t-sys-live")
public class TSysLiveController {
 
    private final TSysLiveService sysLiveService;
    private final TokenService tokenService;
    private final RedisCache redisCache;
    private final XiaoeUtils xiaoeUtils;
    @Autowired
    public TSysLiveController(TSysLiveService sysLiveService, TokenService tokenService, RedisCache redisCache, XiaoeUtils xiaoeUtils) {
        this.sysLiveService = sysLiveService;
        this.tokenService = tokenService;
        this.redisCache = redisCache;
        this.xiaoeUtils = xiaoeUtils;
    }
 
    /**
     * 获取直播管理管理列表
     */
    @ApiOperation(value = "获取直播管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TSysLiveVO>> pageList(@RequestBody TSysLiveQuery query) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 5){
            query.setRoleType(roleType);
            query.setUserId(userId);
        }
        return R.ok(sysLiveService.pageList(query));
    }
 
    /**
     * 获取直播管理管理列表
     */
    @ApiOperation(value = "获取直播管理列表")
    @PostMapping(value = "/list")
    public R<List<TSysLive>> list() {
        return R.ok(sysLiveService.list(Wrappers.lambdaQuery(TSysLive.class).orderByDesc(TSysLive::getCreateTime)));
    }
    /**
     * 获取直播管理管理列表
     */
    @ApiOperation(value = "获取直播管理列表-banner使用")
    @PostMapping(value = "/listBanner")
    public R<List<TSysLive>> listBanner() {
        return R.ok(sysLiveService.list(Wrappers.lambdaQuery(TSysLive.class)
                .orderByDesc(TSysLive::getCreateTime)));
    }
 
    /**
     * 添加直播管理管理
     */
    @Log(title = "直播管理信息-新增直播管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加直播管理")
    @PostMapping(value = "/add")
    public R<Boolean> add(@Validated @RequestBody TSysLive dto) {
        // 直播开始时间无法小于当前时间
        if (dto.getStartTime().isBefore(LocalDateTime.now())) {
            return R.fail("直播开始时间无法小于当前时间");
        }
        // 计算结束时间
        dto.setEndTime(dto.getStartTime().plusMinutes(dto.getExpectedDuration()));
 
        // 创建小鹅通直播
//        XiaoeLiveDTO xiaoeLiveDTO = new XiaoeLiveDTO();
//        xiaoeLiveDTO.setTitle(dto.getLiveTitle());
//        xiaoeLiveDTO.setSummary(dto.getLiveIntroduction());
//        xiaoeLiveDTO.setZbStartAt(DateUtils.localDateTimeToString(dto.getStartTime()));
//        xiaoeLiveDTO.setZbStopAt(dto.getExpectedDuration());
//        // 直播类型 0-语音,1-录播直播,2-推流直播,默认为0-语音直播
//        xiaoeLiveDTO.setAliveType(2);
//        xiaoeLiveDTO.setAliveMode(dto.getLiveMode()==1?0:1);
//        xiaoeLiveDTO.setUserId(dto.getLiveLecturer());
//        xiaoeLiveDTO.setPaymentType(dto.getLiveType()==1?1:3);
//        xiaoeLiveDTO.setResourcePassword(dto.getResourcePassword());
//        xiaoeLiveDTO.setDescrb(dto.getLiveDetail());
//        String goslingLiveId = xiaoeUtils.addLive(xiaoeLiveDTO);
//        dto.setGoslingLiveId(goslingLiveId);
 
        return R.ok(sysLiveService.save(dto));
    }
 
    /**
     * 修改直播管理
     */
    @Log(title = "直播管理信息-修改直播管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改直播管理")
    @PostMapping(value = "/update")
    public R<Boolean> update(@Validated @RequestBody TSysLive dto) {
        // 直播已开始无法编辑
//        if (dto.getStartTime().isBefore(LocalDateTime.now())) {
//            return R.fail("直播已开始,无法编辑");
//        }
        // 计算结束时间
        dto.setEndTime(dto.getStartTime().plusMinutes(dto.getExpectedDuration()));
 
        // 编辑小鹅通直播
//        XiaoeLiveDTO xiaoeLiveDTO = new XiaoeLiveDTO();
//        xiaoeLiveDTO.setTitle(dto.getLiveTitle());
//        xiaoeLiveDTO.setSummary(dto.getLiveIntroduction());
//        xiaoeLiveDTO.setZbStartAt(DateUtils.localDateTimeToString(dto.getStartTime()));
//        xiaoeLiveDTO.setZbStopAt(dto.getExpectedDuration());
//        // 直播类型 0-语音,1-录播直播,2-推流直播,默认为0-语音直播
//        xiaoeLiveDTO.setAliveType(2);
//        xiaoeLiveDTO.setAliveMode(dto.getLiveMode()==1?0:1);
//        xiaoeLiveDTO.setUserId(dto.getLiveLecturer());
//        xiaoeLiveDTO.setPaymentType(dto.getLiveType()==1?1:3);
//        xiaoeLiveDTO.setResourcePassword(dto.getResourcePassword());
//        xiaoeLiveDTO.setDescrb(dto.getLiveDetail());
//        xiaoeUtils.editLive(xiaoeLiveDTO);
 
        return R.ok(sysLiveService.updateById(dto));
    }
 
    /**
     * 查看直播管理详情
     */
    @ApiOperation(value = "查看直播管理详情")
    @GetMapping(value = "/getDetailById")
    public R<TSysLive> getDetailById(@RequestParam String id) {
        TSysLive sysLive = sysLiveService.getById(id);
        // 查询次数自增 使用数据库原子更新操作
        sysLive.setClickCount(sysLive.getClickCount()+1);
        sysLiveService.updateById(sysLive);
        // 如果是诊所
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        if(roleType == 5){
            Long userId = tokenService.getLoginUser().getUserId();
            Set<Long> clickCount = new HashSet<>();
            clickCount.add(userId);
            redisCache.setCacheSet(Constants.SYS_LIVE_CLICK_COUNT+id,clickCount);
        }
        return R.ok(sysLive);
    }
 
    /**
     * 删除直播管理
     */
    @Log(title = "直播管理信息-删除直播管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除直播管理")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        redisCache.deleteObject(Constants.SYS_LIVE_CLICK_COUNT+id);
 
        // 删除直播
        TSysLive sysLive = sysLiveService.getById(id);
        xiaoeUtils.deleteLive(sysLive.getGoslingLiveId());
 
        return R.ok(sysLiveService.removeById(id));
    }
 
    /**
     * 批量删除直播管理
     */
    @Log(title = "直播管理信息-删除直播管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除直播管理")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        for (String id : ids) {
            redisCache.deleteObject(Constants.SYS_LIVE_CLICK_COUNT+id);
        }
        return R.ok(sysLiveService.removeByIds(ids));
    }
 
    /**
     * 直播管理推送用户
     */
    @Log(title = "直播管理信息-推送用户", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "直播管理信息推送用户")
    @PutMapping(value = "/pushUser")
    public R<String> pushUser(@RequestParam(value = "id") String id,
                               @RequestParam(value = "pushType")String pushType) {
        sysLiveService.pushUser(id,pushType);
        return R.ok();
    }
    
}