package cn.com.countrygarden.bi.main.service.manager.map.impl;

import cn.com.countrygarden.bi.main.dao.manager.map.ManagerMapMapper;
import cn.com.countrygarden.bi.main.dto.ManagerMapDTO;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * package: cn.com.countrygarden.bi.main.service.manager.map.impl
 * describe:
 * creat_user: lsl
 * creat_date: 2018/10/27
 * creat_time: 11:07
 **/
public class ManagerMapCountTask implements Runnable {

    private final CountDownLatch latch;
    private ManagerMapMapper managerMapMapper;
    private ManagerMapDTO dto;

    public ManagerMapCountTask(ManagerMapMapper managerMapMapper, ManagerMapDTO dto, CountDownLatch latch) {
        this.managerMapMapper=managerMapMapper;
        this.dto=dto;
        this.latch=latch;
    }

    @Override
    public void run() {
        try{
            List<String> communityNames= managerMapMapper.selectCommNameTreeByOrganNameStr(dto.getOrganName());
            if(communityNames!=null&&communityNames.size()>0) {
                dto.setHousekeeperCount(managerMapMapper.countHousekeeperByProjects(communityNames));
            }else {
                dto.setHousekeeperCount(0);
            }
            if(dto.getManageNumCount()==null||dto.getCommCount()==null){
                return;
            }
            dto.setManageNumAvg(dto.getManageNumCount()/dto.getCommCount());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            latch.countDown();
        }
    }
}
