package cn.pluss.platform.controller;

import cn.pluss.platform.PushService;
import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.util.Map;

/**
 * 发送下单，催单通知等接口
 *
 * @author DJH
 */
@RestController
@RequestMapping("/push/")
public class PushController {

    @Setter(onMethod_ = {@Autowired})
    private PushService pushService;

    @PostMapping("/pushMsg")
    public Result<Object> pushMsg(@RequestBody Map<String, Object> param) {
        String userId = (String) param.get("userId");
        String msgType = (String) param.get("type");

        Integer storeId = (Integer) param.get("storeId");

        if (StringUtils.isNotBlank(userId)) {
            pushService.pushMsg(userId, msgType);
        } else {
            pushService.pushMsg(storeId, msgType);
        }


        return ResultGenerator.genSuccessResult();
    }
 }
