 package com.huatek.busi.service.impl;

import java.time.LocalDateTime;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.dao.BusiVideoDao;
import com.huatek.busi.dto.BusiVideoDto;
import com.huatek.busi.entity.BusiVideo;
import com.huatek.busi.mapper.BusiVideoMapper;
import com.huatek.busi.service.BusiVideoService;
import com.huatek.busi.vo.BusiVideoVo;
import com.huatek.torch.sql.beans.LocalUser;
import com.huatek.torch.util.tools.UserUtil;
import com.huatek.torch.util.uuid.Uuid;

/**
 * 视频流service实现
 * @author buck_guo
 * @date 2019/07/24
 */
@Component
@Service(interfaceClass = BusiVideoService.class)
@Transactional(rollbackFor = Exception.class)
public class BusiVideoServiceImpl implements BusiVideoService {
    
    @Autowired
    BusiVideoMapper busiVideoMapper;
    @Autowired
    BusiVideoDao busiVideoDao;

    @Override
    public PageInfo<BusiVideoVo> page(BusiVideoDto busiVideoDto) {
        return PageHelper.startPage(busiVideoDto.getPage(), busiVideoDto.getLimit())
            .doSelectPageInfo(() -> busiVideoMapper.findBusiVideoDtoPage(busiVideoDto));
    }

    @Override
    public int add(String token,BusiVideo busiVideo) {
        busiVideo.setCreateDate(LocalDateTime.now());
        busiVideo.setId(Uuid.getUUID());
//        busiVideo.setSiteId(SiteConstants.SITE_ID);
        busiVideo.setDelFlag("0");
        LocalUser user = UserUtil.getLocalUser(token); 
        if(user != null) {
            busiVideo.setCreateUser(user.getUid());
            busiVideo.setCreateName(user.getUserName());
        }
        return busiVideoDao.add(busiVideo);
    }

    @Override
    public int update(BusiVideo busiVideo) {
        return busiVideoDao.updateLocal(busiVideo);
    }

    @Override
    public int delete(List<String> idList) {
        return busiVideoMapper.deleteBusiVideo(idList);
    }

    @Override
    public BusiVideoVo queryBusiVideoById(String id) {
        return busiVideoMapper.queryBusiVideoById(id);
    }

}
