package com.hotent.portal.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.jms.Notice;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import com.hotent.portal.model.PortalMsgSendLog;
import com.hotent.portal.persistence.manager.PortalMsgSendLogManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  外部系统消息日志管理
 *
 * @company 广州宏天软件股份有限公司
 * @author cola
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/portalMsgSendLog/v1/")
@Api(tags = "外部系统消息日志管理")
@ApiGroup(group = {ApiGroupConsts.GROUP_PORTAL})
public class PortalMsgSendLogController extends BaseController<PortalMsgSendLogManager, PortalMsgSendLog> {

	@Autowired
	PortalMsgSendLogManager portalMsgSendLogManager;

	/**
	 * 根据id获取数据详情
	 * @param id
	 * @return
	 * @throws Exception 
	 * ModelAndView
	 */
	@GetMapping(value="/getDetail")
	@ApiOperation(value="根据id获取数据详情",httpMethod = "GET",notes = "根据id获取数据详情")
	public CommonResult<PortalMsgSendLog> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
		return CommonResult.<PortalMsgSendLog>ok().value(baseService.getDetail(id));
	}
    /**
	 * 新增,更新
	 * @param portalMsgSendLog
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="/save")
	@ApiOperation(value = "新增,更新数据", httpMethod = "POST", notes = "新增,更新数据")
	public CommonResult<String> save(@ApiParam(name="PortalMsgSendLog",value="对象", required = true)@RequestBody PortalMsgSendLog portalMsgSendLog) throws Exception{
		String msg = StringUtil.isEmpty(portalMsgSendLog.getId()) ? "添加成功" : "更新成功";
		baseService.createOrUpdate(portalMsgSendLog);
		return CommonResult.<String>ok().message(msg);
	}


	@RequestMapping(value = "/sendMsgToExternalQueue",method = RequestMethod.POST)
	@ApiOperation(value = "把消息转发到外部系统对应的Queue", httpMethod = "POST", notes = "把消息转发到外部系统对应的Queue")
	public CommonResult sendMsgToExternalQueue(@RequestBody Notice notice,@RequestParam(value = "sysCode")String sysCode){
		return portalMsgSendLogManager.sendMsgToExternalQueue(notice,sysCode);
	}

	@RequestMapping(value = "/retrySendMsg",method = RequestMethod.GET)
	@ApiOperation(value = "根据id重发消息给外部系统对应的队列",httpMethod = "GET",notes = "根据id重发消息给外部系统对应的队列")
	public CommonResult retrySendMsgById(@RequestParam(value = "id")String id){
		return portalMsgSendLogManager.retrySendMsgById(id);
	}
}
