package org.jeecg.modules.ctop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.ctop.entity.KuaishouChannelRegInfo;
import org.jeecg.modules.ctop.mapper.KuaishouChannelRegInfoMapper;
import org.jeecg.modules.ctop.service.IKuaishouChannelRegInfoService;
import org.jeecg.modules.excelutil.entity.KuaishouChannelRegInfoEntity;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 快手渠道注册信息表
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2020-03-26
 */
@Service
public class KuaishouChannelRegInfoServiceImpl extends ServiceImpl<KuaishouChannelRegInfoMapper, KuaishouChannelRegInfo> implements IKuaishouChannelRegInfoService {

    @Override
    public void saveOrUpdateBychannelCodeAndDate(KuaishouChannelRegInfoEntity regInfo) {
        QueryWrapper<KuaishouChannelRegInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state_date", regInfo.getStateDate());
        queryWrapper.eq("channel_code", regInfo.getChannelCode());
        KuaishouChannelRegInfo getRegInfo = this.getOne(queryWrapper);
        if (null == getRegInfo) {
            getRegInfo = new KuaishouChannelRegInfo(regInfo);
            this.save(getRegInfo);
        } else {
            getRegInfo.setRegNum(regInfo.getRegNum());
            getRegInfo.setPerfectDataRate(regInfo.getPerfectDataRate());
            getRegInfo.setMaleRatio(regInfo.getMaleRatio());
            getRegInfo.setUpdateTime(new Date());
            this.updateById(getRegInfo);
        }
    }
}
