zjk
2026-09-23 fb33ef7ea01af3e59178b8437f3ecf8d76b2b32c
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
package com.tcm.training.admin.live.service;
 
import com.tcm.training.admin.live.dto.LiveRoomSettingSaveRequest;
import com.tcm.training.admin.live.entity.LiveRoomSetting;
import com.tcm.training.admin.live.mapper.LiveRoomSettingMapper;
import com.tcm.training.admin.live.vo.LiveRoomSettingVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
public class LiveRoomSettingService {
    private final LiveRoomSettingMapper mapper;
 
    public LiveRoomSettingService(LiveRoomSettingMapper mapper) {
        this.mapper = mapper;
    }
 
    public LiveRoomSettingVO current() {
        return toVO(mapper.selectCurrent());
    }
 
    @Transactional(rollbackFor = Exception.class)
    public LiveRoomSettingVO save(LiveRoomSettingSaveRequest request) {
        LiveRoomSetting setting = mapper.selectCurrent();
        if (setting == null) {
            setting = new LiveRoomSetting();
            fill(setting, request);
            mapper.insertCurrent(setting);
        } else {
            fill(setting, request);
            mapper.updateCurrent(setting);
        }
        return toVO(setting);
    }
 
    private void fill(LiveRoomSetting setting, LiveRoomSettingSaveRequest request) {
        setting.setBannerImageUrl(request.getBannerImageUrl().trim());
        String liveRoomUrl = request.getLiveRoomUrl();
        setting.setLiveRoomUrl(liveRoomUrl == null || liveRoomUrl.trim().isEmpty() ? null : liveRoomUrl.trim());
    }
 
    private LiveRoomSettingVO toVO(LiveRoomSetting setting) {
        if (setting == null) {
            return null;
        }
        LiveRoomSettingVO vo = new LiveRoomSettingVO();
        vo.setBannerImageUrl(setting.getBannerImageUrl());
        vo.setLiveRoomUrl(setting.getLiveRoomUrl());
        return vo;
    }
}