package jnpf.cultivate.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.cultivate.mapper.CultivateCourseMsgUserMapper;
import jnpf.cultivate.service.CultivateCourseMsgUserService;
import jnpf.model.cultivate.dto.course.app.FtbCultivateCourseMsgForAppDTO;
import jnpf.model.cultivate.po.course.app.CultivateCourseMsgUser;
import jnpf.util.UserProvider;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Title:CultivateCourseMsgServiceImpl
 * @Author:peng.hao
 * @create: 2023/12/2913:36
 */
@Service
public class CultivateCourseMsgUserServiceImpl extends ServiceImpl<CultivateCourseMsgUserMapper, CultivateCourseMsgUser> implements CultivateCourseMsgUserService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateInfoByMsgId(FtbCultivateCourseMsgForAppDTO dto) {
        String loginUserId = UserProvider.getLoginUserId();
        List<CultivateCourseMsgUser> collect = dto.getMsgId().stream().map(msg -> {
            CultivateCourseMsgUser cultivateCourseMsgUser = new CultivateCourseMsgUser();
            cultivateCourseMsgUser.setMsgId(msg);
            cultivateCourseMsgUser.setStatus(1);
            cultivateCourseMsgUser.setUserId(loginUserId);
            return cultivateCourseMsgUser;
        }).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(collect)) {
            this.saveBatch(collect);
        }
    }
}
