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
|
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;
|
}
|
}
|