package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.sys.dao.RdAudienceCityDao;
import io.renren.modules.sys.dto.RdAudienceCityDTO;
import io.renren.modules.sys.entity.RdAudienceCityEntity;
import io.renren.modules.sys.service.RdAudienceCityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 受众分析数据（市级）
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2022-06-03
 */
@Service
public class RdAudienceCityServiceImpl extends CrudServiceImpl<RdAudienceCityDao, RdAudienceCityEntity, RdAudienceCityDTO> implements RdAudienceCityService {

    @Override
    public QueryWrapper<RdAudienceCityEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String advertiserId = (String)params.get("advertiserId");
        String startDate = (String)params.get("startDate");
        String endDate = (String)params.get("endDate");
        String provinceName = (String)params.get("provinceName");
        String cityName = (String)params.get("cityName");

        QueryWrapper<RdAudienceCityEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id).eq("status",1)
                .eq(StringUtils.isNotBlank(advertiserId), "advertiser_id", advertiserId)
                .ge(StringUtils.isNotBlank(startDate), "date", startDate)
                .le(StringUtils.isNotBlank(endDate), "date", endDate)
                .eq(StringUtils.isNotBlank(provinceName), "province_name", provinceName)
                .eq(StringUtils.isNotBlank(cityName), "city_name", cityName)
                .orderByDesc("id");

        return wrapper;
    }


}