package com.hai.service.impl;

import com.hai.dao.HighCouponRecycleMapper;
import com.hai.entity.HighCouponRecycle;
import com.hai.entity.HighCouponRecycleExample;
import com.hai.service.HighCouponRecycleService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 胡锐
 * @Description:
 * @Date: 2021/4/2 21:27
 */
@Service("highCouponRecycleService")
public class HighCouponRecycleServiceImpl implements HighCouponRecycleService {

    @Resource
    private HighCouponRecycleMapper highCouponRecycleMapper;

    @Override
    public void insertCouponRecycle(HighCouponRecycle highCouponRecycle) {
        highCouponRecycleMapper.insert(highCouponRecycle);
    }

    @Override
    public List<HighCouponRecycle> getRecycleList(Map<String, Object> map) {
        HighCouponRecycleExample example = new HighCouponRecycleExample();
        HighCouponRecycleExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(MapUtils.getString(map, "userPhone"))) {
            criteria.andUserPhoneEqualTo(MapUtils.getString(map, "userPhone"));
        }

        if (StringUtils.isNotBlank(MapUtils.getString(map, "orderNo"))) {
            criteria.andOrderNoLike("%" + MapUtils.getString(map, "orderNo") + "%");
        }

        example.setOrderByClause("create_time desc");
        return highCouponRecycleMapper.selectByExample(example);
    }
}
