admin
2021-03-01 d73687bc6115007145b4aab050e4e29ff87fd8ae
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
57
58
59
60
61
62
63
64
65
66
67
68
package com.yeshi.buwan.controller.api;
 
import com.yeshi.buwan.domain.push.PushDeviceToken;
import com.yeshi.buwan.service.inter.push.PushDeviceTokenService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.vo.AcceptData;
import org.hibernate.validator.constraints.NotEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
 
@Controller
@RequestMapping("api/v2/push")
public class PushController {
 
    Logger logger = LoggerFactory.getLogger(PushController.class);
 
    @Resource
    private PushDeviceTokenService pushDeviceTokenService;
 
 
    /**
     * 设备绑定
     *
     * @param acceptData
     * @param type
     * @param regId
     * @return
     */
    @RequestMapping("bindDeviceToken")
    @ResponseBody
    public String bindDeviceToken(AcceptData acceptData, String loginUid, @NotEmpty(message = "type不能为空") String type, @NotEmpty(message = "regId不能为空") String regId, String model, String androidVersion, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return JsonUtil.loadFalseJson(msg);
        }
 
        if (StringUtil.isNullOrEmpty(acceptData.getUtdId())) {
            return JsonUtil.loadFalseJson("utdId为空");
        }
 
 
        PushDeviceToken token = new PushDeviceToken();
        token.setType(type);
        token.setDetailSystemId(acceptData.getDetailSystem().getId());
        token.setUtdId(acceptData.getUtdId());
        token.setToken(regId);
        token.setVersion(acceptData.getVersion());
        token.setLoginUid(loginUid);
        token.setBuildModel(model);
        token.setBuildVersion(androidVersion);
        try {
            pushDeviceTokenService.addDeviceToken(token);
            return JsonUtil.loadTrueJson("");
        } catch (Exception e) {
            return JsonUtil.loadFalseJson("添加出错");
        }
 
    }
 
 
}