From d594c62a9073875938ba77e1d6ea546233ef5822 Mon Sep 17 00:00:00 2001 From: w Date: Wed, 26 Feb 2020 12:44:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E4=BF=9D=E5=AD=98=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WechatAuthController.java | 9 ++---- .../constant/PestWechatUserStatus.java | 29 +++++++++++++++++++ .../service/PestWechatUserService.java | 3 +- .../service/PestWechatUserServiceImpl.java | 17 +++++++++-- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gsafety/gemp/wechatmp/client/controller/WechatAuthController.java b/src/main/java/com/gsafety/gemp/wechatmp/client/controller/WechatAuthController.java index 9913ac3..16126b0 100644 --- a/src/main/java/com/gsafety/gemp/wechatmp/client/controller/WechatAuthController.java +++ b/src/main/java/com/gsafety/gemp/wechatmp/client/controller/WechatAuthController.java @@ -144,7 +144,7 @@ public class WechatAuthController { //更新授权状态 PestWechatUserPO po = pestWechatUserService.getPestWechatUserById(userInfo.getOpenid()); if(po != null){ - pestWechatUserService.authorizeUser(po); + pestWechatUserService.authorizeUser(po,userInfo); } return result.success(userInfo); } catch (Exception e) { @@ -278,12 +278,7 @@ public class WechatAuthController { private void recordLoginWechatUserMessage(WechatUserinfo userInfo){ PestWechatUserPO po = new PestWechatUserPO(); po.setOpenId(userInfo.getOpenid()); - po.setNickName(userInfo.getNickName()); - po.setCity(userInfo.getCity()); - po.setProvince(userInfo.getProvince()); - po.setCountry(userInfo.getCountry()); - po.setAvatarUrl(userInfo.getAvatarUrl()); - po.setUnionId(userInfo.getUnionId()); + po.setGender(PestWechatUserStatus.GenderEnum.UNKONW.getCode()); po.setWithCredentials(PestWechatUserStatus.AuthorizeEnum.NOT_AUTHORIZE.getCode()); po.setFirstAccessTime(Calendar.getInstance().getTime()); po.setUpdateTime(Calendar.getInstance().getTime()); diff --git a/src/main/java/com/gsafety/gemp/wuhanncov/constant/PestWechatUserStatus.java b/src/main/java/com/gsafety/gemp/wuhanncov/constant/PestWechatUserStatus.java index fb6d8c4..5db390a 100644 --- a/src/main/java/com/gsafety/gemp/wuhanncov/constant/PestWechatUserStatus.java +++ b/src/main/java/com/gsafety/gemp/wuhanncov/constant/PestWechatUserStatus.java @@ -38,6 +38,35 @@ public class PestWechatUserStatus { public void setValue(String value) { this.value = value; } + } + + public enum GenderEnum{ + + UNKONW("0","未知"),MALE("1","男性"),FEMALE("2","女性"); + + private String code; + private String value; + + private GenderEnum(String code, String value) { + this.code = code; + this.value = value; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } } diff --git a/src/main/java/com/gsafety/gemp/wuhanncov/contract/service/PestWechatUserService.java b/src/main/java/com/gsafety/gemp/wuhanncov/contract/service/PestWechatUserService.java index a1c6999..af0276b 100644 --- a/src/main/java/com/gsafety/gemp/wuhanncov/contract/service/PestWechatUserService.java +++ b/src/main/java/com/gsafety/gemp/wuhanncov/contract/service/PestWechatUserService.java @@ -1,5 +1,6 @@ package com.gsafety.gemp.wuhanncov.contract.service; +import com.gsafety.gemp.wechatmp.client.controller.WechatAuthController.WechatUserinfo; import com.gsafety.gemp.wuhanncov.dao.po.PestWechatUserPO; /** @@ -30,7 +31,7 @@ public interface PestWechatUserService { * @return void 返回类型 * @throws */ - void authorizeUser(PestWechatUserPO po); + void authorizeUser(PestWechatUserPO po,WechatUserinfo userInfo); /** * diff --git a/src/main/java/com/gsafety/gemp/wuhanncov/service/PestWechatUserServiceImpl.java b/src/main/java/com/gsafety/gemp/wuhanncov/service/PestWechatUserServiceImpl.java index 8a7d359..b7b12ed 100644 --- a/src/main/java/com/gsafety/gemp/wuhanncov/service/PestWechatUserServiceImpl.java +++ b/src/main/java/com/gsafety/gemp/wuhanncov/service/PestWechatUserServiceImpl.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import com.gsafety.gemp.wechatmp.client.controller.WechatAuthController.WechatUserinfo; import com.gsafety.gemp.wuhanncov.constant.PestWechatUserStatus; import com.gsafety.gemp.wuhanncov.contract.service.PestWechatUserService; import com.gsafety.gemp.wuhanncov.dao.PestWechatUserDao; @@ -33,9 +34,21 @@ public class PestWechatUserServiceImpl implements PestWechatUserService{ } @Override - public void authorizeUser(PestWechatUserPO po) { - vaildProperty(po); + public void authorizeUser(PestWechatUserPO po,WechatUserinfo userInfo) { + if(po == null){ + throw new RuntimeException("用户登陆失败!"); + } + if(StringUtils.isEmpty(po.getOpenId())){ + throw new RuntimeException("主键为空!"); + } po.setWithCredentials(PestWechatUserStatus.AuthorizeEnum.AUTORIZED.getCode()); + po.setNickName(userInfo.getNickName()); + po.setGender(userInfo.getGender()); + po.setCity(userInfo.getCity()); + po.setProvince(userInfo.getProvince()); + po.setCountry(userInfo.getCountry()); + po.setAvatarUrl(userInfo.getAvatarUrl()); + po.setUnionId(userInfo.getUnionId()); pestWechatUserDao.saveAndFlush(po); } -- Gitee