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

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.security.SM4Utils;
import io.renren.modules.sys.dao.CustomersDao;
import io.renren.modules.sys.dto.CustomersDTO;
import io.renren.modules.sys.entity.CustomersEntity;
import io.renren.modules.sys.service.CustomersService;

/**
 * 客户表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2022-05-29
 */
@Service
public class CustomersServiceImpl extends CrudServiceImpl<CustomersDao, CustomersEntity, CustomersDTO> implements CustomersService {

	/**
	 * 加解密秘钥
	 */
	@Value("${encrypt.token}")
	private String TRANSMIT_KEY;
	
    @Override
    public QueryWrapper<CustomersEntity> getWrapper(Map<String, Object> params){
        return new QueryWrapper<>();
    }
    
    @Override
    public PageData<CustomersDTO> page(Map<String, Object> params){
    	Object startDate = params.get("startDate");
    	Object endDate = params.get("endDate");
    	//SM4Utils.encryptData_ECB(customers.getMobile(), TRANSMIT_KEY)
    	if(null != startDate && null != endDate) {
			params.put("dateType", 1);//开始时间和结束时间都有，startDate <= createtime <= startDate
		}else if(null != startDate){
			params.put("dateType", 2);//只有开始时间，createtime >= startDate
		}else if(null != endDate){
			params.put("dateType", 3);//只有结束时间，createtime <= startDate
		}else {
			params.put("dateType", 4);//开始时间和结束时间都没有，不添加该查询条件
		}
    	
    	IPage<CustomersDTO> pageList = baseDao.pageList(getPage(params, null, false),params);
    	return new PageData<>(pageList.getRecords(), pageList.getTotal());
    }

}