package org.linlinjava.jz.hm.service.impl;

import org.linlinjava.jz.db.dao.HmEmployRelationMapper;
import org.linlinjava.jz.db.domain.HmAppUser;
import org.linlinjava.jz.db.domain.HmEmployRelation;
import org.linlinjava.jz.db.domain.HmEmployRelationExample;
import org.linlinjava.jz.db.dto.hm.EmployListDto;
import org.linlinjava.jz.db.service.hm.HmAppUserService;
import org.linlinjava.jz.hm.service.HmEmployRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HmEmployRelationServiceImpl implements HmEmployRelationService{

	@Autowired
	private HmEmployRelationMapper hmEmployRelationMapper;
	
	@Autowired
	private HmAppUserService appUserService;

	@Override
	public List<HmEmployRelation> getRelation(Long userId) {
//		HmEmployRelationExample example = new HmEmployRelationExample();
//		example.or().andUserServantIdEqualTo(userId);
//		example.or().andUserEmployerIdEqualTo(userId);
//		example.or().andUserButlerIdEqualTo(userId);

//		HmEmployRelationExample.Criteria criteria1 = example.createCriteria();
//		criteria1.andIsInvalidEqualTo(1).andOrModel(HmEmployRelation.Column.userButlerId.name(), userId.toString())
//		.andOrModel(HmEmployRelation.Column.userServantId.name(), userId.toString())
//		.andOrModel(HmEmployRelation.Column.userEmployerId.name(), userId.toString());

		return hmEmployRelationMapper.selectByRelationUserId(userId);
	}

	/**
	 * 查询管家对应的客户数量
	 * 包含了工单处理人的
	 * @param userId
	 * @return
	 */
	@Override
	public Long butlerCustomerNumber(Long userId) {
//		HmEmployRelationExample example = new HmEmployRelationExample();
//		example.or().andUserButlerIdEqualTo(userId);
//		return hmEmployRelationMapper.countByExample(example);
		HmAppUser user = appUserService.queryById(userId);
		return hmEmployRelationMapper.selectButlerCustomerCount(userId,Integer.parseInt(user.getSysUserid()));
	}

	@Override
	public List<EmployListDto> getEmployList(Long userButlerId, String queryStr) {
//		PageHelper.startPage(page, size);
		HmAppUser user = appUserService.queryById(userButlerId);
		return hmEmployRelationMapper.selectEmployLis(userButlerId, queryStr,Integer.parseInt(user.getSysUserid()));
	}

    @Override
    public HmEmployRelation queryById(Long id) {
        return hmEmployRelationMapper.selectByPrimaryKey(id);
    }

}
