package com.hfkj.service.impl;

import com.hfkj.dao.BsTradeOrderProfitSharingMapper;
import com.hfkj.dao.BsTradeOrderProfitSharingReceiverMapper;
import com.hfkj.entity.BsTradeOrderProfitSharing;
import com.hfkj.entity.BsTradeOrderProfitSharingExample;
import com.hfkj.entity.BsTradeOrderProfitSharingReceiver;
import com.hfkj.entity.BsTradeOrderProfitSharingReceiverExample;
import com.hfkj.service.BsTradeOrderProfitSharingReceiverService;
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;

/**
 * @className: BsTradeOrderProfitSharingReceiverServiceImpl
 * @author: HuRui
 * @date: 2023/2/22
 **/
@Service("tradeOrderProfitSharingReceiverService")
public class BsTradeOrderProfitSharingReceiverServiceImpl implements BsTradeOrderProfitSharingReceiverService {

    @Resource
    private BsTradeOrderProfitSharingReceiverMapper tradeOrderProfitSharingReceiverMapper;

    @Override
    public void editData(BsTradeOrderProfitSharingReceiver profitSharingReceiver) {
        if (profitSharingReceiver.getId() == null) {
            profitSharingReceiver.setCreateTime(new Date());
            profitSharingReceiver.setStatus(0);
            tradeOrderProfitSharingReceiverMapper.insert(profitSharingReceiver);
        } else {
            tradeOrderProfitSharingReceiverMapper.updateByPrimaryKeySelective(profitSharingReceiver);
        }
    }

    @Override
    public List<BsTradeOrderProfitSharingReceiver> getReceiverListByProfitSharingId(Long profitSharingId) {
        BsTradeOrderProfitSharingReceiverExample example = new BsTradeOrderProfitSharingReceiverExample();
        example.createCriteria().andTradeOrderProfitSharingIdEqualTo(profitSharingId);
        return tradeOrderProfitSharingReceiverMapper.selectByExample(example);
    }

    @Override
    public List<BsTradeOrderProfitSharingReceiver> getProfitSharingList(Map<String, Object> param) {
        BsTradeOrderProfitSharingReceiverExample example  = new BsTradeOrderProfitSharingReceiverExample();
        BsTradeOrderProfitSharingReceiverExample.Criteria criteria = example.createCriteria();

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

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

        return tradeOrderProfitSharingReceiverMapper.selectByExample(example);
    }
}
