2022-09-06 15:35:55 +08:00
|
|
|
|
package com.xkrs.controller;
|
|
|
|
|
|
|
|
|
|
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
|
|
|
|
import com.xkrs.dao.SysUserDao;
|
|
|
|
|
import com.xkrs.model.entity.SysUserEntity;
|
|
|
|
|
import com.xkrs.model.qo.SysUserPushAccountQo;
|
2022-09-06 17:15:58 +08:00
|
|
|
|
import com.xkrs.sms.PushHelper;
|
2022-09-06 15:35:55 +08:00
|
|
|
|
import com.xkrs.utils.ListUtils;
|
|
|
|
|
import org.apache.hc.core5.util.TextUtils;
|
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2022-09-06 17:15:58 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2022-09-06 15:35:55 +08:00
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
|
|
|
|
|
|
|
|
|
@RestController
|
2022-09-06 17:15:58 +08:00
|
|
|
|
@RequestMapping(value = "/push")
|
2022-09-06 15:35:55 +08:00
|
|
|
|
public class PushController {
|
|
|
|
|
|
|
|
|
|
private final Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SysUserDao sysUserDao;
|
|
|
|
|
|
2022-09-06 17:15:58 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private PushHelper pushHelper;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/bindUserPushInfo")
|
|
|
|
|
public String bindUserPushInfo(@RequestBody SysUserPushAccountQo sysUserPushAccountQo) {
|
2022-09-06 15:35:55 +08:00
|
|
|
|
Integer id = sysUserPushAccountQo.getId();
|
|
|
|
|
String userAccount = sysUserPushAccountQo.getUserAccount();
|
|
|
|
|
String regID = sysUserPushAccountQo.getRegID();
|
|
|
|
|
if (null == id) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "绑定失败,id == null", locale);
|
|
|
|
|
}
|
|
|
|
|
Optional<SysUserEntity> targetSysUserOptional = sysUserDao.findById(id);
|
|
|
|
|
if (targetSysUserOptional.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "绑定失败,id不存在", locale);
|
|
|
|
|
}
|
|
|
|
|
if (TextUtils.isEmpty(userAccount)) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "绑定失败,userAccount == null", locale);
|
|
|
|
|
}
|
|
|
|
|
if (TextUtils.isEmpty(regID)) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "绑定失败,regID == null", locale);
|
|
|
|
|
}
|
|
|
|
|
SysUserEntity targetSysUser = targetSysUserOptional.get();
|
|
|
|
|
// 更新 userAccount
|
|
|
|
|
targetSysUser.setPushUserAccount(userAccount);
|
|
|
|
|
// 更新 regID
|
|
|
|
|
String pushRegIDs = targetSysUser.getPushRegID();
|
|
|
|
|
if (TextUtils.isEmpty(pushRegIDs)) {
|
|
|
|
|
targetSysUser.setPushRegID(regID);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> pushRegIDList = new ArrayList<>();
|
|
|
|
|
if (pushRegIDs.contains(",")) {
|
|
|
|
|
pushRegIDList.addAll(ListUtils.toStringList(pushRegIDs, ","));
|
|
|
|
|
} else {
|
|
|
|
|
pushRegIDList.add(pushRegIDs);
|
|
|
|
|
}
|
|
|
|
|
if (!pushRegIDList.contains(regID)) {
|
|
|
|
|
pushRegIDList.add(regID);
|
|
|
|
|
}
|
|
|
|
|
String newPushRegIDs = ListUtils.fromStringList(pushRegIDList, ",");
|
|
|
|
|
targetSysUser.setPushRegID(newPushRegIDs);
|
|
|
|
|
}
|
|
|
|
|
sysUserDao.save(targetSysUser);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "绑定成功", locale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 17:15:58 +08:00
|
|
|
|
@GetMapping("/testPush")
|
|
|
|
|
public String testPush(@RequestParam(value = "userAccount") String userAccount) {
|
|
|
|
|
//推送
|
|
|
|
|
try {
|
|
|
|
|
List<String> userAccountList = new ArrayList<>();
|
|
|
|
|
userAccountList.add(userAccount);
|
|
|
|
|
pushHelper.dispatchPushMessage(userAccountList, null);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OKK", locale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 15:35:55 +08:00
|
|
|
|
}
|