package com.jsowell.pile.service.impl;

import com.google.common.collect.Lists;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.pile.domain.MemberTransactionRecord;
import com.jsowell.pile.mapper.MemberTransactionRecordMapper;
import com.jsowell.pile.service.IMemberTransactionRecordService;
import com.jsowell.pile.vo.web.MemberTransactionVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

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

@Service
public class MemberTransactionRecordServiceImpl implements IMemberTransactionRecordService {

    @Resource
    private MemberTransactionRecordMapper memberTransactionRecordMapper;

    @Override
    public int insertSelective(MemberTransactionRecord record) {
        return memberTransactionRecordMapper.insertSelective(record);
    }

    @Override
    public List<MemberTransactionVO> selectMemberTransactionRecordList(String memberId) {
        List<MemberTransactionRecord> list = memberTransactionRecordMapper.selectByMemberId(memberId);
        if (CollectionUtils.isEmpty(list)) {
            return Lists.newArrayList();
        }
        List<MemberTransactionVO> resultList = Lists.newArrayList();
        for (MemberTransactionRecord memberTransactionRecord : list) {
            MemberTransactionVO vo = new MemberTransactionVO();
            BeanUtils.copyBeanProp(vo, memberTransactionRecord);
            resultList.add(vo);
        }
        return resultList;
    }

    @Override
    public MemberTransactionRecord selectByOrderCode(String orderCode) {
        return memberTransactionRecordMapper.selectByOrderCode(orderCode);
    }

}
