package com.hai.service.impl;

import com.hai.dao.ApiAmountRecordMapper;
import com.hai.entity.ApiAmountRecord;
import com.hai.entity.ApiAmountRecordExample;
import com.hai.service.ApiAmountRecordService;
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;

@Service("apiAmountRecordService")
public class ApiAmountRecordServiceImpl implements ApiAmountRecordService {

    @Resource
    private ApiAmountRecordMapper apiAmountRecordMapper;

    @Override
    public void insertAmountRecord(ApiAmountRecord apiAmountRecord) {
        apiAmountRecord.setCreateTime(new Date());
        apiAmountRecord.setUpdateTime(new Date());
        apiAmountRecord.setStatus(100);
        apiAmountRecordMapper.insert(apiAmountRecord);
    }

    @Override
    public ApiAmountRecord findById(Long id) {
        return apiAmountRecordMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ApiAmountRecord> getApiAmountRecordByList(Map<String, Object> map) {
        ApiAmountRecordExample example = new ApiAmountRecordExample();
        ApiAmountRecordExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isBlank(MapUtils.getString(map , "orderNo"))) {
            criteria.andSourceOrderNoEqualTo(MapUtils.getString(map , "orderNo"));
        }
        if (MapUtils.getInteger(map , "amountType") == null) {
            criteria.andAmountTypeEqualTo(MapUtils.getInteger(map , "amountType"));
        }
        if (MapUtils.getInteger(map , "sourceType") == null) {
            criteria.andSourceTypeEqualTo(MapUtils.getInteger(map , "sourceType"));
        }

        return apiAmountRecordMapper.selectByExample(example);
    }
}
