添加接口:服务器绑定用户的推送信息
This commit is contained in:
parent
17c34d95f6
commit
cedfc78357
72
src/main/java/com/xkrs/controller/PushController.java
Normal file
72
src/main/java/com/xkrs/controller/PushController.java
Normal file
@ -0,0 +1,72 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package com.xkrs.dao;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@ -14,7 +15,7 @@ import java.util.List;
|
||||
*
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysUserDao extends JpaRepository<SysUserEntity, Integer> {
|
||||
public interface SysUserDao extends JpaRepository<SysUserEntity, Integer>, JpaSpecificationExecutor<SysUserEntity> {
|
||||
|
||||
@Modifying(clearAutomatically = true)
|
||||
@Query(value = "UPDATE sys_user SET vip_level = ?2 WHERE id = ?1", nativeQuery = true)
|
||||
|
@ -124,6 +124,16 @@ public class SysUserEntity implements Serializable {
|
||||
*/
|
||||
private Long agentOrgId;
|
||||
|
||||
/**
|
||||
* 推送的 userAccount
|
||||
*/
|
||||
private String pushUserAccount;
|
||||
|
||||
/**
|
||||
* 推送的 regID
|
||||
*/
|
||||
private String pushRegID;
|
||||
|
||||
public SysUserEntity() {
|
||||
}
|
||||
|
||||
@ -327,34 +337,24 @@ public class SysUserEntity implements Serializable {
|
||||
this.agentOrgId = agentOrgId;
|
||||
}
|
||||
|
||||
public String getPushUserAccount() {
|
||||
return pushUserAccount;
|
||||
}
|
||||
|
||||
public void setPushUserAccount(String pushUserAccount) {
|
||||
this.pushUserAccount = pushUserAccount;
|
||||
}
|
||||
|
||||
public String getPushRegID() {
|
||||
return pushRegID;
|
||||
}
|
||||
|
||||
public void setPushRegID(String pushRegID) {
|
||||
this.pushRegID = pushRegID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserEntity{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", reallyName='" + reallyName + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", salt='" + salt + '\'' +
|
||||
", telephone='" + telephone + '\'' +
|
||||
", countyCode='" + countyCode + '\'' +
|
||||
", signature='" + signature + '\'' +
|
||||
", activeFlag=" + activeFlag +
|
||||
", statusCode=" + statusCode +
|
||||
", addTime='" + addTime + '\'' +
|
||||
", lastEntryTime=" + lastEntryTime +
|
||||
", deleteFlag=" + deleteFlag +
|
||||
", lastEntryIp='" + lastEntryIp + '\'' +
|
||||
", dayNum=" + dayNum +
|
||||
", overTime='" + overTime + '\'' +
|
||||
", accountType='" + accountType + '\'' +
|
||||
", countyName='" + countyName + '\'' +
|
||||
", loginNum=" + loginNum +
|
||||
", loginLastTime='" + loginLastTime + '\'' +
|
||||
", userAgent='" + userAgent + '\'' +
|
||||
", vipLevel=" + vipLevel +
|
||||
", receiveSms=" + receiveSms +
|
||||
", remark='" + remark + '\'' +
|
||||
", agentOrgId=" + agentOrgId +
|
||||
'}';
|
||||
return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", lastEntryTime=" + lastEntryTime + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", dayNum=" + dayNum + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + ", userAgent='" + userAgent + '\'' + ", vipLevel=" + vipLevel + ", receiveSms=" + receiveSms + ", remark='" + remark + '\'' + ", agentOrgId=" + agentOrgId + ", pushUserAccount='" + pushUserAccount + '\'' + ", pushRegID='" + pushRegID + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
38
src/main/java/com/xkrs/model/qo/SysUserPushAccountQo.java
Normal file
38
src/main/java/com/xkrs/model/qo/SysUserPushAccountQo.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
public class SysUserPushAccountQo {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String userAccount;
|
||||
|
||||
private String regID;
|
||||
|
||||
public SysUserPushAccountQo() {
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserAccount() {
|
||||
return userAccount;
|
||||
}
|
||||
|
||||
public void setUserAccount(String userAccount) {
|
||||
this.userAccount = userAccount;
|
||||
}
|
||||
|
||||
public String getRegID() {
|
||||
return regID;
|
||||
}
|
||||
|
||||
public void setRegID(String regID) {
|
||||
this.regID = regID;
|
||||
}
|
||||
|
||||
}
|
57
src/main/java/com/xkrs/utils/ListUtils.java
Normal file
57
src/main/java/com/xkrs/utils/ListUtils.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ListUtils {
|
||||
|
||||
/**
|
||||
* 字符串切割为集合
|
||||
*
|
||||
* @param content
|
||||
* @param splitRegex
|
||||
* @return
|
||||
*/
|
||||
public static List<String> toStringList(String content, String splitRegex) {
|
||||
if (TextUtils.isEmpty(splitRegex)) {
|
||||
throw new RuntimeException("splitRegex == null");
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
if (content.contains(splitRegex)) {
|
||||
String[] splitArray = content.split(splitRegex);
|
||||
if (splitArray.length > 0) {
|
||||
list.addAll(Arrays.asList(splitArray));
|
||||
}
|
||||
} else {
|
||||
list.add(content);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合转字符串
|
||||
*
|
||||
* @param list
|
||||
* @param splitRegex
|
||||
* @return
|
||||
*/
|
||||
public static String fromStringList(List<String> list, String splitRegex) {
|
||||
if (TextUtils.isEmpty(splitRegex)) {
|
||||
throw new RuntimeException("splitRegex == null");
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (list != null && list.size() > 0) {
|
||||
int size = list.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.append(list.get(i));
|
||||
if (i < (size - 1)) {
|
||||
builder.append(splitRegex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user