package com.hai.service.impl;

import com.hai.dao.HighCompanyAccountRecordMapper;
import com.hai.entity.HighCompanyAccountRecord;
import com.hai.entity.HighCompanyAccountRecordExample;
import com.hai.service.HighCompanyAccountRecordService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

@Service("companyAccountRecordService")
public class HighCompanyAccountRecordServiceImpl implements HighCompanyAccountRecordService {
    @Resource
    private HighCompanyAccountRecordMapper companyAccountRecordMapper;

    @Override
    public void insertRecord(HighCompanyAccountRecord companyAmountRecord) {
        companyAmountRecord.setStatus(1);
        companyAmountRecord.setCreateTime(new Date());
        companyAccountRecordMapper.insert(companyAmountRecord);
    }

    @Override
    public List<HighCompanyAccountRecord> getRecordList(Map<String, Object> param) {
        HighCompanyAccountRecordExample example = new HighCompanyAccountRecordExample();
        HighCompanyAccountRecordExample.Criteria criteria = example.createCriteria().andStatusEqualTo(1);

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

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

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

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

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

        if (MapUtils.getLong(param, "createTimeS") != null) {
            criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(param, "createTimeS")));
        }

        if (MapUtils.getLong(param, "createTimeE") != null) {
            criteria.andCreateTimeLessThanOrEqualTo(new Date(MapUtils.getLong(param, "createTimeE")));
        }

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