package com.hfkj.service.rebate.impl;

import com.hfkj.dao.BsRebateActivityAccountRecordMapper;
import com.hfkj.entity.BsRebateActivityAccountRecord;
import com.hfkj.entity.BsRebateActivityAccountRecordExample;
import com.hfkj.service.rebate.BsRebateActivityAccountRecordService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsRebateActivityAccountRecordServiceImpl
 * @author: HuRui
 * @date: 2023/10/19
 **/
@Service("rebateActivityAccountRecordService")
public class BsRebateActivityAccountRecordServiceImpl implements BsRebateActivityAccountRecordService {

    @Resource
    private BsRebateActivityAccountRecordMapper rebateActivityAccountRecordMapper;

    @Override
    public void insert(BsRebateActivityAccountRecord record) {
        record.setCreateTime(new Date());
        record.setStatus(1);
        rebateActivityAccountRecordMapper.insert(record);
    }

    @Override
    public List<BsRebateActivityAccountRecord> getRecordList(Map<String, Object> param) {
        BsRebateActivityAccountRecordExample example = new BsRebateActivityAccountRecordExample();
        BsRebateActivityAccountRecordExample.Criteria criteria = example.createCriteria().andStatusNotEqualTo(0);

        if (StringUtils.isNotBlank(MapUtils.getString(param, "activityNo"))) {
            criteria.andActivityNoEqualTo(MapUtils.getString(param, "activityNo"));
        }

        if (MapUtils.getInteger(param, "tradeType") != null) {
            criteria.andTradeTypeEqualTo(MapUtils.getInteger(param, "tradeType"));
        }

        if (StringUtils.isNotBlank(MapUtils.getString(param, "tradeNumber"))) {
            criteria.andTradeNumberLike("%" + MapUtils.getString(param, "tradeNumber") + "%");
        }

        if (MapUtils.getInteger(param, "objectType") != null) {
            criteria.andObjectTypeEqualTo(MapUtils.getInteger(param, "objectType"));
        }

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