package com.hfkj.service.impl;

import com.hfkj.dao.BsMerPlatformTermMapper;
import com.hfkj.entity.BsMerPlatformTerm;
import com.hfkj.entity.BsMerPlatformTermExample;
import com.hfkj.service.BsMerPlatformTermService;
import org.springframework.stereotype.Service;

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

@Service("merPlatformTermService")
public class BsMerPlatformTermServiceImpl implements BsMerPlatformTermService {

    @Resource
    private BsMerPlatformTermMapper merPlatformTermMapper;

    @Override
    public void editMerPlatformTerm(BsMerPlatformTerm merPlatformTerm) {
        if (merPlatformTerm.getId() == null) {
            merPlatformTerm.setCreateTime(new Date());
            merPlatformTerm.setUpdateTime(new Date());
            merPlatformTerm.setStatus(1);
            merPlatformTermMapper.insert(merPlatformTerm);
        } else {
            merPlatformTerm.setUpdateTime(new Date());
            merPlatformTermMapper.updateByPrimaryKey(merPlatformTerm);
        }
    }

    @Override
    public BsMerPlatformTerm getMerPlatformTerm(Long platformTermNoId, String busiTypeCode) {
        BsMerPlatformTermExample example = new BsMerPlatformTermExample();
        example.createCriteria()
                .andStatusEqualTo(1)
                .andMerPlatformNoIdEqualTo(platformTermNoId)
                .andBusiTypeCodeEqualTo(busiTypeCode);
        List<BsMerPlatformTerm> list = merPlatformTermMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
