package com.gyee.frame.controller.app.bracelet;

import com.gyee.frame.netty.websocket.util.SocketToolController;
import com.gyee.frame.service.app.bracelet.BraceletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bracelet")
public class BraceletController extends SocketToolController {
    @Autowired
    private BraceletService braceletService;
    @ResponseBody
    @RequestMapping("/bracelet")
    public String bracelet(HttpServletRequest httpServletRequest, String beginDate, String endDate) throws Exception {
        String remoteAddr = httpServletRequest.getRemoteAddr();
        Map<String, List<String>> pointMap = BraceletService.bracelet_pointMap;
        List<String> list = new ArrayList<>();
        list.add(beginDate);
        list.add(endDate);
        pointMap.put(remoteAddr,list);
        BraceletService.bracelet_pointMap = pointMap;
        return remoteAddr;
    }

    @ResponseBody
    @RequestMapping("/close_bracelet")
    public String close_bracelet(HttpServletRequest httpServletRequest,String pointKey) throws Exception {
        String remoteAddr = httpServletRequest.getRemoteAddr();
        Map<String, List<String>> pointMap = BraceletService.bracelet_pointMap;
        pointMap.remove(remoteAddr);
        BraceletService.bracelet_pointMap = pointMap;
        return remoteAddr;
    }
}
