package com.yc.ship.module.trade.controller.admin.notify;

import com.alibaba.fastjson.JSONObject;
import com.yc.ship.module.trade.controller.admin.notify.vo.NotifyInsuranceReqVO;
import com.yc.ship.module.trade.service.notify.NotifyService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
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 javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;

/**
 * 第三方调用的通知接口
 */
@Tag(name = "管理后台 - 第三方调用的通知接口")
@RestController
@RequestMapping("/notify")
@Slf4j
public class NotifyController {

    @Resource
    private NotifyService notifyService;

    @PostMapping("/insurance")
    public String insuranceNotify(HttpServletRequest request) throws UnsupportedEncodingException {
        request.setCharacterEncoding("UTF-8");
        String req = request.getParameter("req");
        log.info("收到保险通知：{}", req);
        NotifyInsuranceReqVO notifyInsuranceReqVO = JSONObject.parseObject(req, NotifyInsuranceReqVO.class);
        notifyService.notifyInsurance(notifyInsuranceReqVO);
        return "SUCCESS";
    }
}
