package com.hai.service.impl;

import com.hai.dao.ApiOrderRecordMapper;
import com.hai.entity.ApiOrderRecord;
import com.hai.entity.ApiOrderRecordExample;
import com.hai.service.ApiOrderRecordService;
import com.itextpdf.text.pdf.qrcode.MaskUtil;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("apiOrderRecordService")
public class ApiOrderRecordServiceImpl implements ApiOrderRecordService {

    @Resource
    private ApiOrderRecordMapper apiOrderRecordMapper;


    @Override
    public ApiOrderRecord queryOrderResult(Map<String, Object> map) {

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

        if (StringUtils.isNotBlank(MapUtils.getString(map , "sourceOrderNo"))) {
            criteria.andSourceOrderNoEqualTo(MapUtils.getString(map , "sourceOrderNo"));
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map , "merchId"))) {
            criteria.andMchIdEqualTo(MapUtils.getString(map , "merchId"));
        }
        if (MapUtils.getLong(map , "orderId") != null) {
            criteria.andOrderIdEqualTo(MapUtils.getLong(map , "orderId"));
        }

        List<ApiOrderRecord> list = apiOrderRecordMapper.selectByExample(example);

        if (list.size() > 0) {
           return list.get(0);
        } else {
            return null;
        }
    }

    @Override
    public void insertOrderRecord(ApiOrderRecord apiOrderRecord) {
        apiOrderRecordMapper.insert(apiOrderRecord);
    }

    @Override
    public void updateOrderRecord(ApiOrderRecord apiOrderRecord) {
        apiOrderRecordMapper.updateByPrimaryKey(apiOrderRecord);
    }

    @Override
    public List<ApiOrderRecord> callBackOrderList() {
        return apiOrderRecordMapper.callBackOrderList();
    }
}
