xiaoyong931011
2021-08-11 c991120a34795dee56d1d92e36f3ccfbbc4bb52a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.xzx.gc.system.controller;
 
import cn.hutool.core.convert.Convert;
import cn.jpush.api.push.model.audience.Audience;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.annotations.PassToken;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.common.utils.JGUtil;
import com.xzx.gc.model.MapDto;
import com.xzx.gc.system.dto.PushDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author :zz
 */
@RestController
@RequestMapping("/push")
@Api(tags = {"推送管理"})
@Validated
public class PushController extends BaseController {
    @Autowired
    private JGUtil jgUtil;
 
 
    @GetMapping("/jg")
    @ApiOperation(value = "极光推送")
    @PassToken
    public Result add(PushDto pushDto){
        String msg=null;
        MapDto mapDto = pushDto.getMapDto();
        Map<String,String> extra=new HashMap<>();
        if(mapDto!=null){
            extra.put(mapDto.getKey(),mapDto.getValue());
        }
        if(CommonEnum.点对点.getValue().equals(Convert.toStr(pushDto.getType()))){
            msg= jgUtil.sendByAnroid(pushDto.getAlert(), pushDto.getTitle(), extra, Audience.alias(pushDto.getId()));
        }else if(CommonEnum.群发.getValue().equals(Convert.toStr(pushDto.getType()))){
            msg=jgUtil.sendByAnroid(pushDto.getAlert(), pushDto.getTitle(), extra, Audience.tag(pushDto.getId()));
        }
        if(msg==null){
            return Result.success("推送成功");
        }else {
            return Result.error(-1,"推送失败:"+msg);
        }
    }
}