package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.CompanyInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.CompanyInfo;
import com.jpsoft.shinestar.modules.base.service.CompanyInfoService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

@Transactional
@Component(value="companyInfoService")
public class CompanyInfoServiceImpl implements CompanyInfoService {
	@Resource(name="companyInfoDAO")
	private CompanyInfoDAO companyInfoDAO;

	@Override
	public CompanyInfo get(String id) {
		// TODO Auto-generated method stub
		return companyInfoDAO.get(id);
	}

	@Override
	public int insert(CompanyInfo model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());

		return companyInfoDAO.insert(model);
	}

	@Override
	public int update(CompanyInfo model) {
		// TODO Auto-generated method stub
		return companyInfoDAO.update(model);
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return companyInfoDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = companyInfoDAO.exist(id);

		return count > 0 ? true : false;
	}

	@Override
	public List<CompanyInfo> list() {
		// TODO Auto-generated method stub
		return companyInfoDAO.list();
	}

	@Override
	public Page<CompanyInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<CompanyInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            companyInfoDAO.search(searchParams,sortList);
        });

        return page;
	}

	@Override
	public List<CompanyInfo> findByCompanyCode(String code,Long personId) {
		return companyInfoDAO.findByCompanyCode(code,personId);
	}
	@Override
	public List<CompanyInfo> findAllCompanyByCode(String code) {
		return companyInfoDAO.findAllCompanyByCode(code);
	}

	@Override
	public List<CompanyInfo> findBySceneIdAndType(String sceneId, String type) {
		return companyInfoDAO.findBySceneIdAndType(sceneId,type);
	}

	@Override
	public List<CompanyInfo> findByRelationCompanyId(String relationCompanyId) {
		return companyInfoDAO.findByRelationCompanyId(relationCompanyId);
	}

	@Override
	public List<CompanyInfo> findByRegionIdAndSceneIdAndEnableRegister(String regionId, String sceneId, boolean enableRegister) {
		return companyInfoDAO.findByRegionIdAndSceneIdAndEnableRegister(regionId,sceneId,enableRegister);
	}

	@Override
	public List<CompanyInfo> findByType(String type) {
		return companyInfoDAO.findByType(type);
	}

	@Override
	public List<CompanyInfo> findByUnitType(String unitType) {
		return companyInfoDAO.findByUnitType(unitType);
	}


	@Override
	public long countByParentId(String parentId) {
		return companyInfoDAO.countByParentId(parentId);
	}

	@Override
	public long countByCompanyCode(String code,Long personId) {
		return companyInfoDAO.countByCompanyCode(code,personId);
	}

	@Override
	public int updateCode(String oldCode, String newCode) {
		return companyInfoDAO.updateCode(oldCode + "%",oldCode.length()+1 ,newCode);
	}

	@Override
	public Boolean hasChildren(String id) {
		return countByParentId(id)>0;
	}

	@Override
	public List<CompanyInfo> findByParentId(String parentId) {
		return companyInfoDAO.findByParentId(parentId);
	}

	@Override
	public CompanyInfo findByName(String name) {
		return companyInfoDAO.findByName(name);
	}

	@Override
	public List<CompanyInfo> findByCompanyCodeAndType(String code,String type){
		return companyInfoDAO.findByCompanyCodeAndType(code,type);
	}

	@Override
	public List<CompanyInfo> findByRegionIdAndSceneId(String regionId, String sceneId) {
		return companyInfoDAO.findByRegionIdAndSceneId(regionId,sceneId);
	}

	@Override
	public List<CompanyInfo> findByHealthyReportTime(String healthyReportTime) {
		return companyInfoDAO.findByHealthyReportTime(healthyReportTime);
	}

	@Override
	public CompanyInfo findByIdIgnoreDel(String companyId) {
		return companyInfoDAO.findByIdIgnoreDel(companyId);
	}

	@Override
	public List<CompanyInfo> findByOutscourcer(Boolean isOutsourcer){
		return companyInfoDAO.findByOutscourcer(isOutsourcer);
	}

	@Override
	public List<CompanyInfo> findByCompanyCodeAndOutscourcer(String code, Long personId,Boolean isOutsourcer){
		return companyInfoDAO.findByCompanyCodeAndOutscourcer(code,personId,isOutsourcer);
	}

	@Override
	public List<CompanyInfo> findByClassify(String classify){
		return companyInfoDAO.findByClassify(classify);
	}
}