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.JhsBakendData;
import org.jeecg.modules.ctop.mapper.JhsBakendDataMapper;
import org.jeecg.modules.ctop.service.IJhsBakendDataService;
import org.jeecg.modules.excelutil.entity.JhsBakendDataEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 聚划算后端数据
 * @author jeecg-boot
 * @date   2020-09-07
 * @version V1.0
 */
@Service
public class JhsBakendDataServiceImpl extends ServiceImpl<JhsBakendDataMapper, JhsBakendData> implements IJhsBakendDataService {
    @Autowired
    private JhsBakendDataMapper bakendDataMapper;
    @Override
    public void saveOrUpdateEntity(JhsBakendDataEntity dataEntity) {
        QueryWrapper<JhsBakendData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state_date", dataEntity.getStateDate());
        queryWrapper.eq("ad_id", dataEntity.getAdId());
        JhsBakendData getData = this.getOne(queryWrapper);
        if (null == getData) {
            getData = new JhsBakendData(dataEntity);
            this.save(getData);
        } else {
            getData.setStateDate(dataEntity.getStateDate());
            getData.setProductLine(dataEntity.getProductLine());
            getData.setTaskName(dataEntity.getTaskName());
            getData.setClientName(dataEntity.getClientName());
            getData.setChannelId(dataEntity.getChannelId());
            getData.setChannelName(dataEntity.getChannelName());
            getData.setPageView(dataEntity.getPageView());
            getData.setDealNumber(dataEntity.getDealNumber());
            getData.setUpdateTime(new Date());
            this.updateById(getData);
        }
    }

    @Override
    public void replaceEntity(JhsBakendDataEntity dataEntity) {
        JhsBakendData getData = new JhsBakendData(dataEntity);
        bakendDataMapper.replaceData(getData);
    }

    @Override
    public void replaceEntityList(List<JhsBakendDataEntity> datas) {
        bakendDataMapper.replaceBatch(datas);
    }
}
