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(PushDeviceToken.PushPlatform.valueOf(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("添加出错"); } } }