package com.emergency.avenue.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.emergency.avenue.admin.api.entity.SysUserMsg;
import com.emergency.avenue.admin.service.SysUserMsgService;
import com.emergency.avenue.common.core.util.R;
import com.emergency.avenue.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("/usermsg")
public class SysUserMsgController {

	private final SysUserMsgService userMsgService;

	@GetMapping("/page")
	public R getUserPage(Page page, SysUserMsg usermsg){

		return R.ok( userMsgService. getPmUserMsg(page,usermsg) );
	}
	@GetMapping("/getone")
	public R getUserPage( SysUserMsg usermsg){
		SysUserMsg old=userMsgService.getById(usermsg.getUmsgId());
		SysUserMsg updateumsg =new SysUserMsg();
		updateumsg.setReadstate(1);updateumsg.setUmsgId(usermsg.getUmsgId()  );
		userMsgService.updateById(updateumsg);
		return R.ok(  old );
	}
	@RequestMapping("/addone")
	public R addOne(@RequestBody SysUserMsg usermsg){

		userMsgService.addOneUserMsg( SecurityUtils.getUser().getUsername(),usermsg.getUserId(),usermsg.getMsgContent() );

		return R.ok();
	}

	//stompClient.send("/app/ping", {}, "userid=xx");
	@MessageMapping("/msgping")
	public R ping(String messages){
		log.info("client {} ping",messages );
		return R.ok();
	}


}
