73 lines
2.9 KiB
Java
73 lines
2.9 KiB
Java
|
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;
|
|||
|
import com.xkrs.utils.ListUtils;
|
|||
|
import org.apache.hc.core5.util.TextUtils;
|
|||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|||
|
import org.springframework.web.bind.annotation.PostMapping;
|
|||
|
import org.springframework.web.bind.annotation.RequestBody;
|
|||
|
import org.springframework.web.bind.annotation.RestController;
|
|||
|
|
|||
|
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
|
|||
|
public class PushController {
|
|||
|
|
|||
|
private final Locale locale = LocaleContextHolder.getLocale();
|
|||
|
|
|||
|
@Resource
|
|||
|
private SysUserDao sysUserDao;
|
|||
|
|
|||
|
@PostMapping("/bindPushInfo")
|
|||
|
public String bindPushInfo(@RequestBody SysUserPushAccountQo sysUserPushAccountQo) {
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
}
|