/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.yifu.cloud.plus.v1.msg.controller;

import com.alibaba.fastjson.JSONObject;
import com.yifu.cloud.plus.v1.msg.service.MsgService;
import com.yifu.cloud.plus.v1.msg.vo.EkpAlertVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;


/**
 * @Author fxj
 * @Description EKP 消息生成及查询
 * @Date 16:21 2023/5/30
 * @Param
 * @return
**/
@RestController
@RequiredArgsConstructor
@RequestMapping("/mail" )
@Tag(name = "消息生成及查询")
public class MsgController {
	private MsgService msgService;
	@Operation(summary = "触发消息提醒--EKP调用接口", description = "触发消息提醒--EKP调用接口")
	@SysLog("触发消息提醒--EKP调用接口")
	@PostMapping("/createMsg")
	public R<Boolean> createMsg(@RequestBody String jsonStr) {
		try {
			jsonStr = URLDecoder.decode(jsonStr, CommonConstants.UTF8).replace("=", "");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		List<EkpAlertVo> list= JSONObject.parseArray(jsonStr, EkpAlertVo.class);
		return msgService.createMsg(list);
	}
}
