package com.shining.cloud.controller.information;

import com.njcn.enums.app.ReturnCode;
import com.njcn.pojo.commons.ResponseInfoData;
import com.njcn.pojo.commons.ResponseMsgData;
import com.njcn.utils.PubUtils;
import com.shining.cloud.enums.information.EventMsgCodeEnum;
import com.shining.cloud.mapper.information.DevMsgMapper;
import com.shining.cloud.mapper.information.EventMsgMapper;
import com.shining.cloud.mapper.information.SteadyMsgMapper;
import com.shining.cloud.pojo.information.EventMsgDetail;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 清理消息
 * @author: denghuajun
 * @time: 2019-11-27 11:49:39
 **/
@RestController
@RequestMapping("/cleanmsg")
@Api(tags = "清空消息接口")
public class CleanMsgInfoController {
    private static final Logger logger = LoggerFactory.getLogger(EventMsgController.class);
    @Resource
    EventMsgMapper eventMsgMapper;
    @Resource
    DevMsgMapper devMsgMapper;
    @Resource
    SteadyMsgMapper steadyMsgMapper;

    /**
     * 暂态消息获取
     */
    @PostMapping("clearMsg")
    @ApiOperation(value = "清空消息接口入口", response = ResponseInfoData.class)
    public ResponseInfoData eventDetailList(@RequestParam("eventMsgList") List<String> eventMsgList,
                                            @RequestParam("steadyMsgList") List<String> steadyMsgList,
                                            @RequestParam("deviceMsgList") List<String> deviceMsgList) {
        ResponseInfoData responseData;

        try {
            if (eventMsgList != null && eventMsgList.size() > 0) {
                for (int i = 0; i < eventMsgList.size(); i++) {
                    eventMsgMapper.updateEventState(eventMsgList.get(i));
                }
            }
            if (steadyMsgList != null && steadyMsgList.size() > 0) {
                for (int i = 0; i < steadyMsgList.size(); i++) {
                    steadyMsgMapper.updateSteadyState(deviceMsgList.get(i));
                }
            }
            if (deviceMsgList != null && deviceMsgList.size() > 0) {
                for (int i = 0; i < deviceMsgList.size(); i++) {
                    devMsgMapper.updateDevMsgState(deviceMsgList.get(i));
                }
            }
            responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, EventMsgCodeEnum.CLEANMSGINFO_SUCCESS.getCode(), EventMsgCodeEnum.CLEANMSGINFO_SUCCESS.getMsg());
        } catch (Exception e) {
            responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, EventMsgCodeEnum.CLEANMSGINFO_SUCCESS.getCode(), EventMsgCodeEnum.CLEANMSGINFO_FALL.getMsg());
        }
        return responseData;
    }

}