package com.hfkj.service.impl;

import com.hfkj.dao.BsMerAttachMapper;
import com.hfkj.entity.BsMerAttach;
import com.hfkj.entity.BsMerAttachExample;
import com.hfkj.service.BsMerAttachService;
import com.hfkj.sysenum.PlatformTypeEnum;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * @author hurui
 */
@Service("merAttachService")
public class BsMerAttachServiceImpl implements BsMerAttachService {

    @Resource
    private BsMerAttachMapper merAttachMapper;

    @Override
    public void editMerAttach(BsMerAttach merAttach) {
        if (merAttach.getId() == null) {
            merAttach.setStatus(1);
            merAttach.setCreateTime(new Date());
            merAttach.setUpdateTime(new Date());
            merAttachMapper.insert(merAttach);
        } else {
            merAttach.setUpdateTime(new Date());
            merAttachMapper.updateByPrimaryKey(merAttach);
        }
    }

    @Override
    public BsMerAttach getDetail(Long id) {
        return merAttachMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<BsMerAttach> getAttachListByMer(Long merId, PlatformTypeEnum platformType, Integer type) {
        BsMerAttachExample example = new BsMerAttachExample();
        BsMerAttachExample.Criteria criteria = example.createCriteria()
                                                .andMerIdEqualTo(merId)
                                                .andPlatformTypeEqualTo(platformType.getNumber())
                                                .andStatusEqualTo(1);

        if (type != null) {
            criteria.andTypeEqualTo(type);
        }

        return merAttachMapper.selectByExample(example);
    }
}
