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.dao.CompanyStructureInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.CompanyPosition;
import com.jpsoft.shinestar.modules.base.entity.CompanyStructureInfo;
import com.jpsoft.shinestar.modules.base.service.CompanyStructureInfoService;
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;

/**
 * @author 墨鱼_mo
 * @date 2020-10-14 15:27
 */
@Transactional
@Component(value="companyStructureInfoService")
public class CompanyStructureInfoServiceImpl implements CompanyStructureInfoService {

    @Resource(name="companyStructureInfoDAO")
    private CompanyStructureInfoDAO companyStructureInfoDAO;

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

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

        return companyStructureInfoDAO.insert(model);
    }

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

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

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

        return count > 0 ? true : false;
    }

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

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

        return page;
    }

    @Override
    public List<CompanyStructureInfo> findTopStructureByCompanyId(String companyId) {
        return companyStructureInfoDAO.findTopStructureByCompanyId(companyId);
    }

    @Override
    public List<CompanyStructureInfo> findByCompanyId(String companyId){
        return companyStructureInfoDAO.findByCompanyId(companyId);
    }

    @Override
    public CompanyStructureInfo findByCompanyIdAndName(String companyId,String structureName){
        return companyStructureInfoDAO.findByCompanyIdAndName(companyId,structureName);
    }

    @Override
    public List<CompanyStructureInfo> findByParentId(String id) {
        return companyStructureInfoDAO.findByParentId(id);
    }

    @Override
    public List<CompanyStructureInfo> findByCompanyIdAndPositionName(String companyId, String positionName) {
        return companyStructureInfoDAO.findByCompanyIdAndPositionName(companyId,positionName);
    }
}
