package com.liquidnet.service.kylin.service.impl.partner;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.kylin.dto.PerformancePartnerDto;
import com.liquidnet.service.kylin.dto.param.PerformanceStep1Param;
import com.liquidnet.service.kylin.entity.KylinPerformances;
import com.liquidnet.service.kylin.mapper.KylinPerformancesMapper;
import com.liquidnet.service.kylin.service.partner.IKylinPerformancesPartnerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 演出 服务实现类
 * </p>
 *
 * @author liquidnet
 * @since 2021-05-05
 */
@Service
public class KylinPerformancesPartnerServiceImpl extends ServiceImpl<KylinPerformancesMapper, KylinPerformances> implements IKylinPerformancesPartnerService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public boolean createStep1(PerformanceStep1Param step1Param) {
        // 获取 主键id
        String performanceId = IDGenerator.nextSnowId().toString();
        // 获取 当前时间 -> 创建时间
        LocalDateTime createdAt = LocalDateTime.now();

        try {
            // mongo 操作 记录演出中间数据
//            PerformancePartnerDto performancePartnerDto = new PerformancePartnerDto();
//            BeanUtils.copyProperties(step1Param, performancePartnerDto);
//            performancePartnerDto.setPerformancesId(performanceId);
//            performancePartnerDto.setCreatedAt(createdAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            performancePartnerDto.setUpdatedAt(createdAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            PerformancePartnerDto data = mongoTemplate.insert(
//                    performancePartnerDto, PerformancePartnerDto.class.getSimpleName()
//            );

            step1Param.setCreatedAt(createdAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            step1Param.setPerformancesId(performanceId);
            PerformanceStep1Param data = mongoTemplate.insert(
                    step1Param, PerformanceStep1Param.class.getSimpleName()
            );
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public boolean createStep2() {
        return false;
    }
}
