package com.njcn.cloud.controller.information;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.cloud.pojo.dto.AppDevMsg;
import com.njcn.cloud.pojo.dto.AppEventMsg;
import com.njcn.cloud.pojo.dto.AppSteadyMsg;
import com.njcn.cloud.pojo.vo.MsgInfo;
import com.njcn.cloud.service.IAppDevMsgService;
import com.njcn.cloud.service.IAppEventMsgService;
import com.njcn.cloud.service.IAppSteadyMsgService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 清理消息
 * @Author: wr
 * @Date: 2023/11/8 13:48
 */
@RestController
@RequestMapping("/cleanmsg")
@Api(tags = "清空消息接口")
@RequiredArgsConstructor
public class CleanMsgInfoController extends BaseController {

    private final IAppEventMsgService eventMsgService;
    private final IAppSteadyMsgService steadyMsgMapper;
    private final IAppDevMsgService devMsgService;
    /**
     * 暂态消息获取
     */
    @PostMapping("/clearMsg")
    @ApiOperation(value = "清空消息接口入口")
    public HttpResult<Boolean> eventDetailList(@RequestBody MsgInfo param) {
        String methodDescribe = getMethodDescribe("eventDetailList");
        List<String> eventMsgList = param.getEventMsgList();
        List<String> steadyMsgList = param.getSteadyMsgList();
        List<String> deviceMsgList = param.getDeviceMsgList();
        //暂态消息
        if(CollUtil.isNotEmpty(eventMsgList)){
            eventMsgService.update(new LambdaUpdateWrapper<AppEventMsg>()
                    .set(AppEventMsg::getState,1)
                    .in(AppEventMsg::getEventmsgIndex,eventMsgList)
            );
        }
        //稳态消息
        if(CollUtil.isNotEmpty(steadyMsgList)){
            steadyMsgMapper.update(new LambdaUpdateWrapper<AppSteadyMsg>()
                    .set(AppSteadyMsg::getState,1)
                    .in(AppSteadyMsg::getSteadyIndex,steadyMsgList)
            );
        }
        //终端消息
        if(CollUtil.isNotEmpty(deviceMsgList)){
            devMsgService.update(new LambdaUpdateWrapper<AppDevMsg>()
                    .set(AppDevMsg::getState,1)
                    .in(AppDevMsg::getDevmsgIndex,eventMsgList)
            );
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

}