package com.gyee.frame.controller.gen;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.conf.UserLoginContext;
import com.gyee.frame.common.dataSources.DataSource;
import com.gyee.frame.common.dataSources.DataSourceType;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Gyeeuser;
import com.gyee.frame.model.custom.*;
import com.gyee.frame.model.enumeration.Messagetype;
import com.gyee.frame.netty.websocket.util.SocketToolController;
import com.gyee.frame.service.GyeeuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.websocket.Session;
import java.io.IOException;
import java.util.*;

@Controller
@RequestMapping("GyeeuserController")
@Api(value = "")
public class GyeeuserController extends SocketToolController{
	

	@Autowired
	private GyeeuserService gyeeuserService;


	@DataSource(value = DataSourceType.TICKET)
	@GetMapping("/selectUserList")
	@ResponseBody
	public AjaxResult selectUserList(String userid) {

		List<Gyeeuser> result=gyeeuserService.findContactUserlist(userid);
		if (result == null )
		{
			return AjaxResult.error(4004, "没有用户先关通信录");
		}
		return AjaxResult.successData(result);

	}

	@DataSource(value = DataSourceType.TICKET)
	@PostMapping("/selectUserList")
	@ResponseBody
	public List<ContactUserVo> selectUserList(@RequestBody Map<String,String> map) {

		List<ContactUserVo> list=new ArrayList<>();
		if(null!=map && !map.isEmpty())
		{
			Set<Map.Entry<String, String>> set = map.entrySet();
			for (Iterator<Map.Entry<String, String>> it = set.iterator(); it.hasNext();) {
				Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
				//System.out.println(entry.getKey() + "--->" + entry.getValue());

				ContactUserVo vo=new ContactUserVo();
				vo.setId(entry.getKey());
				List<Gyeeuser> result=gyeeuserService.findContactUserlist(entry.getKey());
				{
					for(Gyeeuser user:result)
					{
						if(null!=map && map.containsKey(user.getId()))
						{
							user.setRemak1("1");
						}else
						{
							user.setRemak1("0");
						}
					}
				}
				vo.setList(result);

				list.add(vo);
			}
		}

		this.pushToWeb("pageNumber_4","functionNumber_3","all",list, Messagetype.MESSAGE);

		return  list;
	}


}
