package com.philisense.www.service.impl;


import com.philisense.www.core.text.Convert;
import com.philisense.www.dao.ProTenantDAO;
import com.philisense.www.pojos.entity.ProTenant;
import com.philisense.www.service.ProTenantService;
import com.philisense.www.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

@Service
public class ProTenantServiceImpl implements ProTenantService {

    @Autowired
    private ProTenantDAO proTenantDAO;

    @Override
    public int deleteByPrimaryKey(String id) {
        return proTenantDAO.deleteByPrimaryKey(id);
    }

    @Override
    public Map<String, Object> selectByPrimaryKey(String id) {
        return proTenantDAO.selectByPrimaryKey(id);
    }

    @Override
    public int insert(Map<String, Object> map) {
        return proTenantDAO.insert(map);
    }

    @Override
    public int update(Map<String, Object> map) {
        return proTenantDAO.update(map);
    }

    @Override
    public int deleteByMap(Map<String, Object> map) {
        return proTenantDAO.deleteByMap(map);
    }

    @Override
    public int updateByMap(Map<String, Object> map) {
        return proTenantDAO.updateByMap(map);
    }

    @Override
    public Map<String, Object> getOne(Map<String, Object> map) {
        return proTenantDAO.getOne(map);
    }

    @Override
    public List<Map<String, Object>> getAll(Map<String, Object> map) {
        return proTenantDAO.getAll(map);
    }

    @Override
    public List<Map<String, Object>> queryPage(Map<String, Object> map) {
        return proTenantDAO.queryPage(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return proTenantDAO.count(map);
    }

    @Override
    public void insertBatch(List<Map<String, Object>> list) {
        proTenantDAO.insertBatch(list);
    }

    @Override
    public void deleteBatch(List<Map<String, Object>> list) {
        proTenantDAO.deleteBatch(list);
    }

    @Override
    public void updateBatch(List<Map<String, Object>> list) {
        proTenantDAO.updateBatch(list);
    }

    @Override
    public boolean checkTenantCodeUnique(Map<String, Object> map) {
        String id = Convert.toStr(map.get(ProTenant.ID_KEY), "");
        String tenant_code = Convert.toStr(map.get(ProTenant.TENANT_CODE_KEY), "");
        Map<String, Object> info = proTenantDAO.checkTenantCodeUnique(tenant_code);
        if (StringUtils.isNotEmpty(info) && !id.equals(Convert.toStr(info.get(ProTenant.ID_KEY), ""))){
            return false;
        }
        return true;
    }
}