package com.hfkj.service.impl;

import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsPlatformMapper;
import com.hfkj.entity.BsPlatform;
import com.hfkj.entity.BsPlatformExample;
import com.hfkj.service.BsPlatformService;
import org.springframework.stereotype.Service;

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

@Service("platformService")
public class BsPlatformServiceImpl implements BsPlatformService {

    @Resource
    private BsPlatformMapper platformMapper;

    @Override
    public BsPlatform getCurrentPlatform() {
        BsPlatformExample example = new BsPlatformExample();
        example.createCriteria().andStatusEqualTo(1);
        example.setOrderByClause("sort");
        List<BsPlatform> list = platformMapper.selectByExample(example);
        if (list.size() == 0) {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到进件平台");
        }
        return list.get(0);
    }

    @Override
    public void editPlatform(BsPlatform bsPlatform) {
        if (bsPlatform.getId() == null) {
            platformMapper.insert(bsPlatform);
        } else {
            platformMapper.updateByPrimaryKey(bsPlatform);
        }
    }

    @Override
    public BsPlatform getDetail(Long id) {
        return platformMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<BsPlatform> getPlatformList() {
        BsPlatformExample example = new BsPlatformExample();
        example.createCriteria().andStatusEqualTo(1);
        example.setOrderByClause("sort");
        return platformMapper.selectByExample(example);
    }

    @Override
    public List<BsPlatform> getPlatformList(Map<String, Object> param) {
        BsPlatformExample example = new BsPlatformExample();
        example.createCriteria().andStatusNotEqualTo(0);
        example.setOrderByClause("sort");
        return platformMapper.selectByExample(example);
    }
}
