package com.hai.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hai.dao.HighMerchantAccountRecordMapper;
import com.hai.entity.HighMerchantAccountRecord;
import com.hai.entity.HighMerchantAccountRecordExample;
import com.hai.service.HighMerchantAccountRecordService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

@Service("merchantAccountRecordService")
public class HighMerchantAccountRecordServiceImpl implements HighMerchantAccountRecordService {

    @Resource
    private HighMerchantAccountRecordMapper merchantAccountRecordMapper;

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

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

        if (MapUtils.getLong(param, "merId") != null) {
            criteria.andMerIdEqualTo(MapUtils.getLong(param, "merId"));
        }

        if (MapUtils.getObject(param, "merIdList") != null) {
            JSONObject.toJSONString(MapUtils.getObject(param, "merIdList"));
            List<Long> merList = (List<Long>) MapUtils.getObject(param, "merIdList");
            criteria.andMerIdIn(merList);
        }

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

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