package com.hai.service.impl;

import com.hai.dao.HighDiscountInventoryRecordMapper;
import com.hai.entity.HighDiscountInventoryRecord;
import com.hai.entity.HighDiscountInventoryRecordExample;
import com.hai.service.HighDiscountInventoryRecordService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

@Service("highDiscountInventoryRecordService")
public class HighDiscountInventoryRecordServiceImpl implements HighDiscountInventoryRecordService {

    @Resource
    private HighDiscountInventoryRecordMapper discountInventoryRecordMapper;

    @Override
    public List<HighDiscountInventoryRecord> getDiscountInventoryRecordServList(Map<String, Object> map) {

        HighDiscountInventoryRecordExample example = new HighDiscountInventoryRecordExample();
        HighDiscountInventoryRecordExample.Criteria criteria = example.createCriteria();

        if (MapUtils.getInteger(map , "companyId") != null) {
            criteria.andCompanyIdEqualTo(MapUtils.getInteger(map , "companyId"));
        }

        if (MapUtils.getString(map , "title") != null) {
            criteria.andDiscountPackageTitleLike("%" + MapUtils.getString(map , "title") + "%");
        }

        example.setOrderByClause("created_time");

        return discountInventoryRecordMapper.selectByExample(example);
    }
}
