package cn.api.system;

import java.util.Map;
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 com.alibaba.fastjson2.JSON;
import cn.common.page.response.Result;
import cn.component.message.sms.PushMsgUtil;
import cn.facade.pojo.MsgParams;

import javax.annotation.Resource;

/**消息模板 */
@RestController
@RequestMapping("/api/message/sysMessageTemplate")
public class SysMsgTemplateCtrl {

	@Resource
	private PushMsgUtil pushMsgUtil;
	
	/**
	 * 发送消息
	 */
	@SuppressWarnings("unchecked")
	@PostMapping(value = "/sendMsg")
	public Result<?> sendMessage(@RequestBody MsgParams msgParams)
	{
		Map<String, String> map;
		try {
			map = (Map<String, String>) JSON.parse(msgParams.getTestData());
		} catch (Exception e) {
			return Result.warnMsg("解析Json出错！");
		}
		boolean is_sendSuccess = pushMsgUtil.sendMessage(msgParams.getMsgType(), msgParams.getTemplateCode(), map, msgParams.getReceiver());
		if (is_sendSuccess) {
			return Result.okMsg("发送消息任务添加成功！");
		} else {
			return Result.warnMsg("发送消息任务添加失败！");
		}
	}
}
