package com.hai.service.impl;

import com.hai.dao.HighMerchantTripartitePlatformMapper;
import com.hai.entity.HighMerchantTripartitePlatform;
import com.hai.entity.HighMerchantTripartitePlatformExample;
import com.hai.service.HighMerchantTripartitePlatformService;
import org.springframework.stereotype.Service;

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

@Service("merchantTripartitePlatformService")
public class HighMerchantTripartitePlatformServiceImpl implements HighMerchantTripartitePlatformService {

    @Resource
    private HighMerchantTripartitePlatformMapper merchantTripartitePlatformMapper;

    @Override
    public void editDate(HighMerchantTripartitePlatform tripartitePlatform) {
       if (tripartitePlatform.getId() == null) {
           tripartitePlatform.setStatus(1);
           tripartitePlatform.setCreateTime(new Date());
           tripartitePlatform.setUpdateTime(new Date());
           merchantTripartitePlatformMapper.insert(tripartitePlatform);
       } else {
           tripartitePlatform.setUpdateTime(new Date());
           merchantTripartitePlatformMapper.updateByPrimaryKey(tripartitePlatform);
       }
    }

    @Override
    public HighMerchantTripartitePlatform getDetail(Long merId, Integer platformType) {
        HighMerchantTripartitePlatformExample example = new HighMerchantTripartitePlatformExample();
        example.createCriteria().andMerIdEqualTo(merId).andPlatformTypeEqualTo(platformType);
        List<HighMerchantTripartitePlatform> list = merchantTripartitePlatformMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
