package com.palmnest.service.dorm.manager.impl;

import com.palmnest.application.bean.Page;
import com.palmnest.application.dto.input.DormRoomerListDto;
import com.palmnest.application.dto.output.WxDormCheckOutDto;
import com.palmnest.dao.dorm.DormCheckOutDao;
import com.palmnest.model.dorm.DormCheckOut;
import com.palmnest.service.dorm.manager.DormCheckOutManager;
import com.palmnest.service.impl.GenericManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 退宿申请单manager实现类
 *
 * @author longmeizhen
 */
@Slf4j
@Service("dormCheckOutManager")
public class DormCheckOutManagerImpl extends GenericManagerImpl<DormCheckOut, Long> implements DormCheckOutManager {


	private DormCheckOutDao dormCheckOutDao;

	@Autowired
	public void setDormCheckOutDao(DormCheckOutDao dormCheckOutDao) {
		this.dormCheckOutDao = dormCheckOutDao;
		this.dao = dormCheckOutDao;
	}

	/**
	 * 获取退宿申请列表
	 *
	 * @param dto      查询条件
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@Override
	public Page getDormCheckOutList(DormRoomerListDto dto, int pageNo,
									int pageSize) {
		return dormCheckOutDao.getDormCheckOutList(dto, pageNo, pageSize);
	}

	@Override
	public DormCheckOut get(Long id) {
		return dormCheckOutDao.get(id);
	}

	@Override
	public boolean exists(Long id) {
		return dormCheckOutDao.exists(id);
	}

	/**
	 * 获取该用户的退宿申请列表
	 *
	 * @param openId
	 * @return
	 */
	@Override
	public List<WxDormCheckOutDto> getCheckOutList(String orgId, String idCard, String mobile) {
		List<Map<String, Object>> list = dormCheckOutDao.getCheckOutListByCreator(orgId, idCard, mobile);
		if (list != null && list.size() > 0) {
			List<WxDormCheckOutDto> dtoList = new ArrayList<WxDormCheckOutDto>();
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				WxDormCheckOutDto   dto = new WxDormCheckOutDto();
				if (map != null) {
					dto.setId(map.get("id").toString());
					dto.setCreateTime(map.get("createTime").toString());
					dto.setGoodsInfo(map.get("goodsInfo").toString());
					dto.setNumber(map.get("number").toString());
					dto.setRoomerNo(map.get("roomieNo").toString());
					dto.setStatus(map.get("status").toString());
					dtoList.add(dto);
				}
			}
			return dtoList;
		}
		return null;
	}

	/**
	 * 判断该项目下该用户是否还存在未处理完的退房信息
	 *
	 * @param openId
	 * @param orgId
	 * @return
	 */
	@Override
	public int hasCheckOutByStatus(String orgId, String idCard, String mobile) {
		return dormCheckOutDao.hasCheckOutByStatus(orgId, idCard, mobile);
	}

	@Override
	public int getDormCheckOutIndex(String status, String orgIds) {
		return dormCheckOutDao.getDormCheckOutIndex(status, orgIds);
	}
}
