package com.nantian.cloud.jly.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.jly.entity.EnterpriseInfo;
import com.nantian.cloud.jly.mapper.EnterpriseInfoMapper;
import com.nantian.cloud.jly.service.EnterpriseInfoService;
import com.nantian.sc.cloud.common.data.datascope.DataScope;
import org.springframework.stereotype.Service;

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

/**
 * @date 2018-09-27
 */
@Service("enterpriseInfoService")
public class EnterpriseInfoServiceImpl extends ServiceImpl<EnterpriseInfoMapper, EnterpriseInfo> implements EnterpriseInfoService {

    @Resource
    EnterpriseInfoMapper enterpriseInfoMapper;

    public List<Map> getAllCompany() {
        return enterpriseInfoMapper.getAllCompany(new DataScope());
    }

    @Override
    public List<Map> queryByEpc(String epc) {
        return enterpriseInfoMapper.queryByEpc(epc);
    }

    @Override
    public IPage<EnterpriseInfo> selectPageAll(Page page, EnterpriseInfo enterpriseInfo) {
        String code = "";
        if (enterpriseInfo.getRegionCode().equals("530000")){
            code = "53";
        } else if (enterpriseInfo.getRegionCode().substring(4).equals("00") ){
            code = enterpriseInfo.getRegionCode().substring(0,4);
        }else {
            code = enterpriseInfo.getRegionCode();
        }
        return enterpriseInfoMapper.selectPageAll(page,enterpriseInfo,code,new DataScope());
    }

    @Override
    public IPage<EnterpriseInfo> getOnlinePage(Page page, EnterpriseInfo enterpriseInfo) {
        String code = "";
        if (enterpriseInfo.getRegionCode().equals("530000")){
            code = "53";
        } else if (enterpriseInfo.getRegionCode().substring(4).equals("00") ){
            code = enterpriseInfo.getRegionCode().substring(0,4);
        }else {
            code = enterpriseInfo.getRegionCode();
        }
        return enterpriseInfoMapper.getOnlinePage(page,enterpriseInfo,code,new DataScope());
    }
}


