护理员小程序登录代码移植
This commit is contained in:
parent
05fa888bbe
commit
0dccd03dac
@ -0,0 +1,45 @@
|
||||
package com.xinelu.applet.controller.personappletlogin;
|
||||
|
||||
|
||||
import com.xinelu.applet.service.personappletlogin.PersonAppletLoginService;
|
||||
import com.xinelu.common.core.controller.BaseController;
|
||||
import com.xinelu.common.core.domain.AjaxResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Description 护理员微信小程序登录注册控制器
|
||||
* @Author zh
|
||||
* @Date 2023-03-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/nurseApplet/personLogin")
|
||||
public class PersonAppletLoginController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private PersonAppletLoginService personAppletLoginService;
|
||||
|
||||
/**
|
||||
* 护理员根据登录凭证获取用户的登录信息
|
||||
*
|
||||
* @param loginCode 登录凭证
|
||||
* @param phoneCode 手机号凭证
|
||||
* @return 微信用户登录信息
|
||||
*/
|
||||
@GetMapping("/getPersonWeChatUserInfo")
|
||||
public AjaxResult appletLogin(@RequestParam("loginCode") String loginCode, @Param("phoneCode") String phoneCode) {
|
||||
if (StringUtils.isBlank(loginCode)) {
|
||||
return AjaxResult.error("登录凭证编码不能为空!");
|
||||
}
|
||||
if (StringUtils.isBlank(phoneCode)) {
|
||||
return AjaxResult.error("获取手机号凭证不存在");
|
||||
}
|
||||
return personAppletLoginService.personAppletLogin(loginCode, phoneCode);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.xinelu.applet.mapper.nursemanagepersonwechatinfo;
|
||||
|
||||
|
||||
import com.xinelu.manage.domain.nursemanagepersonwechatinfo.NurseManagePersonWechatInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 护理站管理人员微信个人信息Mapper接口
|
||||
*
|
||||
* @author xinyilu
|
||||
* @date 2023-04-03
|
||||
*/
|
||||
public interface NurseManagePersonWechatInfoMapper {
|
||||
/**
|
||||
* 查询护理站管理人员微信个人信息
|
||||
*
|
||||
* @param id 护理站管理人员微信个人信息主键
|
||||
* @return 护理站管理人员微信个人信息
|
||||
*/
|
||||
NurseManagePersonWechatInfo selectNurseManagePersonWechatInfoById(Long id);
|
||||
|
||||
/**
|
||||
* 查询护理站管理人员微信个人信息列表
|
||||
*
|
||||
* @param nurseManagePersonWechatInfo 护理站管理人员微信个人信息
|
||||
* @return 护理站管理人员微信个人信息集合
|
||||
*/
|
||||
List<NurseManagePersonWechatInfo> selectNurseManagePersonWechatInfoList(NurseManagePersonWechatInfo nurseManagePersonWechatInfo);
|
||||
|
||||
/**
|
||||
* 新增护理站管理人员微信个人信息
|
||||
*
|
||||
* @param nurseManagePersonWechatInfo 护理站管理人员微信个人信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertNurseManagePersonWechatInfo(NurseManagePersonWechatInfo nurseManagePersonWechatInfo);
|
||||
|
||||
/**
|
||||
* 修改护理站管理人员微信个人信息
|
||||
*
|
||||
* @param nurseManagePersonWechatInfo 护理站管理人员微信个人信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateNurseManagePersonWechatInfo(NurseManagePersonWechatInfo nurseManagePersonWechatInfo);
|
||||
|
||||
/**
|
||||
* 删除护理站管理人员微信个人信息
|
||||
*
|
||||
* @param id 护理站管理人员微信个人信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNurseManagePersonWechatInfoById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除护理站管理人员微信个人信息
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNurseManagePersonWechatInfoByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询护理站管理人员微信个人信息
|
||||
*
|
||||
* @param phone 护理站管理手机号
|
||||
* @return 护理站管理人员微信个人信息
|
||||
*/
|
||||
NurseManagePersonWechatInfo selectNurseManagePersonWechatInfoByPhone(String phone);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.xinelu.applet.mapper.personappletlogin;
|
||||
|
||||
|
||||
import com.xinelu.applet.vo.personappletlogin.PersonAppletVO;
|
||||
import com.xinelu.applet.vo.personappletlogin.UserAndRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 护理员登录Mapper接口
|
||||
*
|
||||
* @author zh
|
||||
* @date 2023-02-24
|
||||
*/
|
||||
public interface PersonAppletLoginMapper {
|
||||
/**
|
||||
* 查询用户信息
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @return SysUser
|
||||
*/
|
||||
List<UserAndRole> selectSysUser(String phone);
|
||||
|
||||
/**
|
||||
* 根据手机号查询护理员信息
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @return int
|
||||
**/
|
||||
PersonAppletVO getNurseStationPersonByPhone(String phone);
|
||||
}
|
||||
@ -0,0 +1,231 @@
|
||||
package com.xinelu.applet.service.personappletlogin.Impl;
|
||||
|
||||
|
||||
import com.xinelu.applet.mapper.nursemanagepersonwechatinfo.NurseManagePersonWechatInfoMapper;
|
||||
import com.xinelu.applet.mapper.personappletlogin.PersonAppletLoginMapper;
|
||||
import com.xinelu.applet.service.personappletlogin.PersonAppletLoginService;
|
||||
import com.xinelu.applet.utils.AppletAccessTokenUtil;
|
||||
import com.xinelu.applet.vo.personappletlogin.PersonAppletVO;
|
||||
import com.xinelu.applet.vo.personappletlogin.UserAndRole;
|
||||
import com.xinelu.common.config.NurseAppletChatConfig;
|
||||
import com.xinelu.common.constant.Constants;
|
||||
import com.xinelu.common.core.domain.AjaxResult;
|
||||
import com.xinelu.common.entity.AppletLoginVO;
|
||||
import com.xinelu.common.entity.AppletPhoneVO;
|
||||
import com.xinelu.common.exception.ServiceException;
|
||||
import com.xinelu.common.utils.AppletChatUtil;
|
||||
import com.xinelu.manage.domain.nursemanagepersonwechatinfo.NurseManagePersonWechatInfo;
|
||||
import com.xinelu.manage.mapper.nursestationperson.NurseStationPersonMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 护理员微信小程序登录注册业务层实现类
|
||||
* @Author zh
|
||||
* @Date 2023-03-30
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PersonAppletLoginServiceImpl implements PersonAppletLoginService {
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Resource
|
||||
private NurseAppletChatConfig nurseAppletChatConfig;
|
||||
@Resource
|
||||
private AppletAccessTokenUtil appletAccessTokenUtil;
|
||||
@Resource
|
||||
private NurseStationPersonMapper nurseStationPersonMapper;
|
||||
@Resource
|
||||
private PersonAppletLoginMapper personAppletLoginMapper;
|
||||
@Resource
|
||||
private NurseManagePersonWechatInfoMapper nurseManagePersonWechatInfoMapper;
|
||||
|
||||
/**
|
||||
* 返回成功状态码
|
||||
*/
|
||||
private static final int SUCCESS_CODE = 0;
|
||||
|
||||
/**
|
||||
* 获取微信小程序access_token错误码
|
||||
*/
|
||||
private static final int ERROR_ACCESS_CODE = 40001;
|
||||
|
||||
/**
|
||||
* 返回成功状态码
|
||||
*/
|
||||
private static final String OK = "ok";
|
||||
|
||||
/**
|
||||
* 根据登录凭证获取用户的登录信息
|
||||
*
|
||||
* @param loginCode 登录凭证
|
||||
* @return 微信用户登录信息
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public AjaxResult personAppletLogin(String loginCode, String phoneCode) {
|
||||
//根据code获取用户的微信unionId以及openId等信息
|
||||
AppletLoginVO appletLoginInfo = AppletChatUtil.getAppletLoginInfo(nurseAppletChatConfig.getAppletId(), nurseAppletChatConfig.getSecret(), loginCode, nurseAppletChatConfig.getGrantType());
|
||||
if (Objects.isNull(appletLoginInfo)) {
|
||||
return AjaxResult.error("获取微信小程序用户信息失败");
|
||||
}
|
||||
if (Objects.nonNull(appletLoginInfo.getErrcode()) && appletLoginInfo.getErrcode() != SUCCESS_CODE) {
|
||||
return AjaxResult.error("获取微信小程序用户信息失败,失败信息为:" + appletLoginInfo.getErrmsg());
|
||||
}
|
||||
//获取微信accessToken,从Redis中取出accessToken
|
||||
String accessToken;
|
||||
String accessTokenKey = Constants.NURSE_STATION_PERSON_APPLET_ACCESS_TOKEN + "accessToken";
|
||||
Object object = redisTemplate.opsForValue().get(accessTokenKey);
|
||||
if (Objects.isNull(object)) {
|
||||
accessToken = appletAccessTokenUtil.getPersonAppletAccessToken();
|
||||
} else {
|
||||
accessToken = (String) object;
|
||||
}
|
||||
//获取用户手机号
|
||||
AppletPhoneVO appletPhoneInfo = AppletChatUtil.getAppletPhoneInfo(phoneCode, accessToken);
|
||||
if (Objects.isNull(appletPhoneInfo)) {
|
||||
return AjaxResult.error("获取用户手机号失败");
|
||||
}
|
||||
if (Objects.nonNull(appletPhoneInfo.getErrcode()) && appletPhoneInfo.getErrcode() == ERROR_ACCESS_CODE) {
|
||||
//当前Redis缓存中的access_token无效直接删除
|
||||
if (Objects.nonNull(object)) {
|
||||
redisTemplate.delete(accessTokenKey);
|
||||
accessToken = appletAccessTokenUtil.getPersonAppletAccessToken();
|
||||
appletPhoneInfo = AppletChatUtil.getAppletPhoneInfo(phoneCode, accessToken);
|
||||
if (Objects.isNull(appletPhoneInfo)) {
|
||||
return AjaxResult.error("获取用户手机号失败");
|
||||
}
|
||||
if (Objects.nonNull(appletPhoneInfo.getErrcode()) && appletPhoneInfo.getErrcode() == ERROR_ACCESS_CODE) {
|
||||
return AjaxResult.error("登录失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(appletPhoneInfo.getErrmsg()) && !OK.equals(appletPhoneInfo.getErrmsg())) {
|
||||
return AjaxResult.error("获取用户手机号失败,失败信息为:" + appletPhoneInfo.getErrmsg());
|
||||
}
|
||||
PersonAppletVO personAppletVO = getPersonApplet(appletPhoneInfo, appletLoginInfo);
|
||||
return AjaxResult.success(personAppletVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 护理站管理人员微信个人信息对象
|
||||
*
|
||||
* @param phone 护理员手机号
|
||||
* @param openid 用户的信息
|
||||
* @param sysUser 管理员信息
|
||||
*/
|
||||
private void getNurseManagePersonWechat(String phone, String openid, List<UserAndRole> sysUser) {
|
||||
//护理站管理人员微信个人信息对象
|
||||
NurseManagePersonWechatInfo nurseManagePersonWechat = nurseManagePersonWechatInfoMapper.selectNurseManagePersonWechatInfoByPhone(phone);
|
||||
NurseManagePersonWechatInfo nurseManagePersonWechatInfo = new NurseManagePersonWechatInfo();
|
||||
if (Objects.isNull(nurseManagePersonWechat)) {
|
||||
nurseManagePersonWechatInfo.setOpenid(openid);
|
||||
nurseManagePersonWechatInfo.setPhone(phone);
|
||||
nurseManagePersonWechatInfo.setNurseStationId(StringUtils.isBlank(sysUser.get(0).getNurseStationIds()) ? "" : sysUser.get(0).getNurseStationIds());
|
||||
nurseManagePersonWechatInfo.setUserId(Objects.isNull(sysUser.get(0).getUserId()) ? null : sysUser.get(0).getUserId());
|
||||
nurseManagePersonWechatInfo.setCreateTime(LocalDateTime.now());
|
||||
int count = nurseManagePersonWechatInfoMapper.insertNurseManagePersonWechatInfo(nurseManagePersonWechatInfo);
|
||||
if (count <= 0) {
|
||||
throw new ServiceException("新增护理站管理人员微信个人信息失败,请联系管理员!");
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(nurseManagePersonWechat)) {
|
||||
nurseManagePersonWechatInfo.setId(Objects.isNull(nurseManagePersonWechat.getId()) ? null : nurseManagePersonWechat.getId());
|
||||
nurseManagePersonWechatInfo.setOpenid(openid);
|
||||
nurseManagePersonWechatInfo.setPhone(phone);
|
||||
nurseManagePersonWechatInfo.setNurseStationId(StringUtils.isBlank(sysUser.get(0).getNurseStationIds()) ? "" : sysUser.get(0).getNurseStationIds());
|
||||
nurseManagePersonWechatInfo.setUserId(Objects.isNull(sysUser.get(0).getUserId()) ? null : sysUser.get(0).getUserId());
|
||||
int update = nurseManagePersonWechatInfoMapper.updateNurseManagePersonWechatInfo(nurseManagePersonWechatInfo);
|
||||
if (update <= 0) {
|
||||
throw new ServiceException("新增护理站管理人员微信个人信息失败,请联系管理员!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 护理员登录接口方法抽取
|
||||
*
|
||||
* @param appletPhoneInfo 微信用户信息
|
||||
* @param appletLoginInfo 手机号信息
|
||||
* @return 登录标识
|
||||
*/
|
||||
private PersonAppletVO getPersonApplet(AppletPhoneVO appletPhoneInfo, AppletLoginVO appletLoginInfo) {
|
||||
PersonAppletVO appletParent = new PersonAppletVO();
|
||||
String phone = StringUtils.isBlank(appletPhoneInfo.getPhoneInfo().getPhoneNumber()) ? "" : appletPhoneInfo.getPhoneInfo().getPhoneNumber();
|
||||
String openid = StringUtils.isBlank(appletLoginInfo.getOpenid()) ? "" : appletLoginInfo.getOpenid();
|
||||
PersonAppletVO nurseStationPerson = personAppletLoginMapper.getNurseStationPersonByPhone(phone);
|
||||
List<UserAndRole> sysUser = personAppletLoginMapper.selectSysUser(phone);
|
||||
//说明当前用户角色即是:护理员又是护理站运营人员
|
||||
if (Objects.nonNull(nurseStationPerson) && CollectionUtils.isNotEmpty(sysUser)) {
|
||||
//更新用户的openid等微信标识信息
|
||||
this.updateNurseStationPerson(appletParent, nurseStationPerson, openid);
|
||||
appletParent.setPersonRoleLoginFlag(Constants.PERSON_ROLE_NAME);
|
||||
//护理站管理人员微信个人信息对象
|
||||
List<String> roleKeyList = sysUser.stream().filter(Objects::nonNull).map(UserAndRole::getRoleKey).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(roleKeyList) && (String.join((","), roleKeyList).contains(Constants.STATION_ROLE_NAME))) {
|
||||
this.getNurseManagePersonWechat(phone, openid, sysUser);
|
||||
appletParent.setPersonRoleLoginFlag(Constants.STATION_AND_PERSON_ROLE_NAME);
|
||||
}
|
||||
}
|
||||
//说明当前用户角色即是:护理员
|
||||
if (Objects.nonNull(nurseStationPerson) && Objects.isNull(sysUser)) {
|
||||
//更新用户的openid等微信标识信息
|
||||
this.updateNurseStationPerson(appletParent, nurseStationPerson, openid);
|
||||
appletParent.setPersonRoleLoginFlag(Constants.PERSON_ROLE_NAME);
|
||||
}
|
||||
//说明当前用户角色即是:护理站运营人员
|
||||
if (Objects.isNull(nurseStationPerson) && Objects.nonNull(sysUser)) {
|
||||
List<String> roleKeyList = sysUser.stream().filter(Objects::nonNull).map(UserAndRole::getRoleKey).collect(Collectors.toList());
|
||||
appletParent.setPersonRoleLoginFlag(Constants.NOT_ROLE_NAME);
|
||||
if (CollectionUtils.isNotEmpty(roleKeyList) && (String.join((","), roleKeyList).contains(Constants.STATION_ROLE_NAME))) {
|
||||
this.getNurseManagePersonWechat(phone, openid, sysUser);
|
||||
appletParent.setPersonRoleLoginFlag(Constants.STATION_ROLE_NAME);
|
||||
}
|
||||
appletParent.setPhone(phone);
|
||||
}
|
||||
//说明当前用户角色即是:即不是护理员又是不是护理站运营人员
|
||||
if (Objects.isNull(nurseStationPerson) && Objects.isNull(sysUser)) {
|
||||
appletParent.setPhone(phone);
|
||||
appletParent.setPersonRoleLoginFlag(Constants.NOT_ROLE_NAME);
|
||||
}
|
||||
//当前用户角色只要包含护理员,那么将护理员的信息返回给前端
|
||||
if (Objects.nonNull(nurseStationPerson)) {
|
||||
appletParent.setNurseStationId(Objects.isNull(nurseStationPerson.getNurseStationId()) ? null : nurseStationPerson.getNurseStationId());
|
||||
appletParent.setNurseStationPersonId(Objects.isNull(nurseStationPerson.getNurseStationPersonId()) ? null : nurseStationPerson.getNurseStationPersonId());
|
||||
appletParent.setNursePersonName(StringUtils.isBlank(nurseStationPerson.getNursePersonName()) ? "" : nurseStationPerson.getNursePersonName());
|
||||
}
|
||||
return appletParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改护理人员信息
|
||||
*
|
||||
* @param appletParent 护理员信息
|
||||
* @param nurseStationPerson 护理员信息
|
||||
* @param openid 护理员信息
|
||||
*/
|
||||
private void updateNurseStationPerson(PersonAppletVO appletParent, PersonAppletVO nurseStationPerson, String openid) {
|
||||
appletParent.setId(nurseStationPerson.getNurseStationPersonId());
|
||||
appletParent.setNurseStationPersonId(nurseStationPerson.getNurseStationPersonId());
|
||||
appletParent.setOpenid(openid);
|
||||
appletParent.setPhone(StringUtils.isBlank(nurseStationPerson.getPhone()) ? "" : nurseStationPerson.getPhone());
|
||||
appletParent.setUpdateTime(LocalDateTime.now());
|
||||
int updateCount = nurseStationPersonMapper.updateNurseStationPerson(appletParent);
|
||||
if (updateCount <= 0) {
|
||||
throw new ServiceException("修改护理人员信息失败,请联系管理员!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package com.xinelu.applet.service.personappletlogin;
|
||||
|
||||
import com.xinelu.common.core.domain.AjaxResult;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @Description 护理员微信小程序登录注册业务层
|
||||
* @Author zh
|
||||
* @Date 2023-03-30
|
||||
*/
|
||||
public interface PersonAppletLoginService {
|
||||
|
||||
/**
|
||||
* 护理员根据登录凭证获取用户的登录信息
|
||||
*
|
||||
* @param loginCode 登录凭证
|
||||
* @param phoneCode 手机号凭证
|
||||
* @return 微信用户登录信息
|
||||
*/
|
||||
AjaxResult personAppletLogin(@RequestParam("loginCode") String loginCode, String phoneCode);
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package com.xinelu.applet.utils;
|
||||
|
||||
import com.xinelu.common.config.AppletChatConfig;
|
||||
import com.xinelu.common.config.NurseAppletChatConfig;
|
||||
import com.xinelu.common.constant.Constants;
|
||||
import com.xinelu.common.entity.AppletAccessToken;
|
||||
import com.xinelu.common.exception.ServiceException;
|
||||
import com.xinelu.common.utils.AppletChatUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description 获取小程序AccessToken公共方法
|
||||
* @Author 纪寒
|
||||
* @Date 2023-02-27 18:02:05
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class AppletAccessTokenUtil {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Resource
|
||||
private AppletChatConfig appletChatConfig;
|
||||
@Resource
|
||||
private NurseAppletChatConfig nurseAppletChatConfig;
|
||||
/**
|
||||
* 返回成功状态码
|
||||
*/
|
||||
private static final int SUCCESS_CODE = 0;
|
||||
|
||||
/**
|
||||
* 获取小程序AccessToken方法
|
||||
*
|
||||
* @return 小程序的AccessToken
|
||||
*/
|
||||
public String getAppletAccessToken() {
|
||||
String accessToken;
|
||||
String accessTokenKey = Constants.NURSE_STATION_APPLET_ACCESS_TOKEN + "accessToken";
|
||||
//从Redis中取出accessToken
|
||||
Object object = redisTemplate.opsForValue().get(accessTokenKey);
|
||||
if (Objects.isNull(object)) {
|
||||
//没有,获取accessToken
|
||||
AppletAccessToken appletAccessToken = AppletChatUtil.getAppletAccessToken(appletChatConfig.getAppletId(), appletChatConfig.getSecret());
|
||||
if (Objects.isNull(appletAccessToken)) {
|
||||
throw new ServiceException("获取微信小程序accessToken信息失败");
|
||||
}
|
||||
if (Objects.nonNull(appletAccessToken.getErrcode()) && appletAccessToken.getErrcode() != SUCCESS_CODE) {
|
||||
throw new ServiceException("获取微信小程序accessToken信息失败,失败信息为:" + appletAccessToken.getErrmsg(), 201);
|
||||
}
|
||||
if (StringUtils.isBlank(appletAccessToken.getAccessToken())) {
|
||||
throw new ServiceException("accessToken信息为空");
|
||||
}
|
||||
//存入Redis中
|
||||
redisTemplate.opsForValue().set(accessTokenKey, appletAccessToken.getAccessToken(), 3600, TimeUnit.SECONDS);
|
||||
accessToken = appletAccessToken.getAccessToken();
|
||||
} else {
|
||||
accessToken = (String) object;
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 护理员小程序获取小程序AccessToken方法
|
||||
*
|
||||
* @return 小程序的AccessToken
|
||||
*/
|
||||
public String getPersonAppletAccessToken() {
|
||||
String accessToken;
|
||||
String accessTokenKey = Constants.NURSE_STATION_PERSON_APPLET_ACCESS_TOKEN + "accessToken";
|
||||
//从Redis中取出accessToken
|
||||
Object object = redisTemplate.opsForValue().get(accessTokenKey);
|
||||
if (Objects.isNull(object)) {
|
||||
//没有,获取accessToken
|
||||
AppletAccessToken appletAccessToken = AppletChatUtil.getAppletAccessToken(nurseAppletChatConfig.getAppletId(), nurseAppletChatConfig.getSecret());
|
||||
if (Objects.isNull(appletAccessToken)) {
|
||||
throw new ServiceException("获取微信小程序accessToken信息失败");
|
||||
}
|
||||
if (Objects.nonNull(appletAccessToken.getErrcode()) && appletAccessToken.getErrcode() != SUCCESS_CODE) {
|
||||
throw new ServiceException("获取微信小程序accessToken信息失败,失败信息为:" + appletAccessToken.getErrmsg(), 201);
|
||||
}
|
||||
if (StringUtils.isBlank(appletAccessToken.getAccessToken())) {
|
||||
throw new ServiceException("accessToken信息为空");
|
||||
}
|
||||
//存入Redis中
|
||||
redisTemplate.opsForValue().set(accessTokenKey, appletAccessToken.getAccessToken(), 3600, TimeUnit.SECONDS);
|
||||
accessToken = appletAccessToken.getAccessToken();
|
||||
} else {
|
||||
accessToken = (String) object;
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.xinelu.applet.vo.personappletlogin;
|
||||
|
||||
import com.xinelu.manage.domain.nursestationperson.NurseStationPerson;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 护理员登录Controller
|
||||
*
|
||||
* @author zhangheng
|
||||
* @date 2022-09-06
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PersonAppletVO extends NurseStationPerson implements Serializable {
|
||||
private static final long serialVersionUID = 2758774902139122051L;
|
||||
|
||||
/**
|
||||
* 护理员角色标识标识
|
||||
*/
|
||||
private String personRoleLoginFlag;
|
||||
|
||||
/**
|
||||
* 护理员id
|
||||
*/
|
||||
private Long nurseStationPersonId;
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.xinelu.applet.vo.personappletlogin;
|
||||
|
||||
|
||||
import com.xinelu.common.core.domain.entity.SysUser;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 角色表
|
||||
*
|
||||
* @author ZH
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UserAndRole extends SysUser implements Serializable {
|
||||
private static final long serialVersionUID = -6758998426533404299L;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
private String roleKey;
|
||||
}
|
||||
@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xinelu.applet.mapper.nursemanagepersonwechatinfo.NurseManagePersonWechatInfoMapper">
|
||||
|
||||
<resultMap type="NurseManagePersonWechatInfo" id="NurseManagePersonWechatInfoResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="nurseStationId" column="nurse_station_id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="openid" column="openid"/>
|
||||
<result property="unionid" column="unionid"/>
|
||||
<result property="phone" column="phone"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectNurseManagePersonWechatInfoVo">
|
||||
select id,
|
||||
nurse_station_id,
|
||||
user_id,
|
||||
openid,
|
||||
unionid,
|
||||
phone,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
from nurse_manage_person_wechat_info
|
||||
</sql>
|
||||
|
||||
<select id="selectNurseManagePersonWechatInfoList" parameterType="NurseManagePersonWechatInfo"
|
||||
resultMap="NurseManagePersonWechatInfoResult">
|
||||
<include refid="selectNurseManagePersonWechatInfoVo"/>
|
||||
<where>
|
||||
<if test="nurseStationId != null and nurseStationId != ''">
|
||||
and nurse_station_id = #{nurseStationId}
|
||||
</if>
|
||||
<if test="userId != null ">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="openid != null and openid != ''">
|
||||
and openid = #{openid}
|
||||
</if>
|
||||
<if test="unionid != null and unionid != ''">
|
||||
and unionid = #{unionid}
|
||||
</if>
|
||||
<if test="phone != null and phone != ''">
|
||||
and phone = #{phone}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectNurseManagePersonWechatInfoById" parameterType="Long"
|
||||
resultMap="NurseManagePersonWechatInfoResult">
|
||||
<include refid="selectNurseManagePersonWechatInfoVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertNurseManagePersonWechatInfo" parameterType="NurseManagePersonWechatInfo" useGeneratedKeys="true"
|
||||
keyProperty="id">
|
||||
insert into nurse_manage_person_wechat_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="nurseStationId != null">nurse_station_id,
|
||||
</if>
|
||||
<if test="userId != null">user_id,
|
||||
</if>
|
||||
<if test="openid != null">openid,
|
||||
</if>
|
||||
<if test="unionid != null">unionid,
|
||||
</if>
|
||||
<if test="phone != null">phone,
|
||||
</if>
|
||||
<if test="createBy != null">create_by,
|
||||
</if>
|
||||
<if test="createTime != null">create_time,
|
||||
</if>
|
||||
<if test="updateBy != null">update_by,
|
||||
</if>
|
||||
<if test="updateTime != null">update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="nurseStationId != null">#{nurseStationId},
|
||||
</if>
|
||||
<if test="userId != null">#{userId},
|
||||
</if>
|
||||
<if test="openid != null">#{openid},
|
||||
</if>
|
||||
<if test="unionid != null">#{unionid},
|
||||
</if>
|
||||
<if test="phone != null">#{phone},
|
||||
</if>
|
||||
<if test="createBy != null">#{createBy},
|
||||
</if>
|
||||
<if test="createTime != null">#{createTime},
|
||||
</if>
|
||||
<if test="updateBy != null">#{updateBy},
|
||||
</if>
|
||||
<if test="updateTime != null">#{updateTime},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateNurseManagePersonWechatInfo" parameterType="NurseManagePersonWechatInfo">
|
||||
update nurse_manage_person_wechat_info
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="nurseStationId != null">nurse_station_id =
|
||||
#{nurseStationId},
|
||||
</if>
|
||||
<if test="userId != null">user_id =
|
||||
#{userId},
|
||||
</if>
|
||||
<if test="openid != null">openid =
|
||||
#{openid},
|
||||
</if>
|
||||
<if test="unionid != null">unionid =
|
||||
#{unionid},
|
||||
</if>
|
||||
<if test="phone != null">phone =
|
||||
#{phone},
|
||||
</if>
|
||||
<if test="createBy != null">create_by =
|
||||
#{createBy},
|
||||
</if>
|
||||
<if test="createTime != null">create_time =
|
||||
#{createTime},
|
||||
</if>
|
||||
<if test="updateBy != null">update_by =
|
||||
#{updateBy},
|
||||
</if>
|
||||
<if test="updateTime != null">update_time =
|
||||
#{updateTime},
|
||||
</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteNurseManagePersonWechatInfoById" parameterType="Long">
|
||||
delete
|
||||
from nurse_manage_person_wechat_info
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteNurseManagePersonWechatInfoByIds" parameterType="String">
|
||||
delete from nurse_manage_person_wechat_info where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectNurseManagePersonWechatInfoByPhone"
|
||||
resultType="com.xinelu.manage.domain.nursemanagepersonwechatinfo.NurseManagePersonWechatInfo">
|
||||
<include refid="selectNurseManagePersonWechatInfoVo"/>
|
||||
where phone = #{phone}
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xinelu.applet.mapper.personappletlogin.PersonAppletLoginMapper">
|
||||
|
||||
<select id="selectSysUser" resultType="com.xinelu.applet.vo.personappletlogin.UserAndRole">
|
||||
select su.user_id,
|
||||
su.phonenumber,
|
||||
sr.role_name,
|
||||
sr.role_key,
|
||||
su.nurse_station_ids
|
||||
from sys_user su
|
||||
left join sys_user_role sur ON sur.user_id = su.user_id
|
||||
left join sys_role sr ON sr.role_id = sur.role_id
|
||||
where su.phonenumber = #{phone}
|
||||
and su.del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="getNurseStationPersonByPhone"
|
||||
resultType="com.xinelu.applet.vo.personappletlogin.PersonAppletVO">
|
||||
select id nurseStationPersonId,
|
||||
nurse_station_id,
|
||||
department_code,
|
||||
user_id,
|
||||
nurse_person_code,
|
||||
nurse_person_name,
|
||||
nurse_person_type,
|
||||
sex,
|
||||
phone,
|
||||
address,
|
||||
birth_date,
|
||||
openid,
|
||||
unionid,
|
||||
evaluate_star_count,
|
||||
positional_title_level,
|
||||
genius_item,
|
||||
total_revenue_amount,
|
||||
work_status,
|
||||
modify_check_status,
|
||||
positional_title_level_check,
|
||||
genius_item_check,
|
||||
modify_info_flag,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
from nurse_station_person
|
||||
<where>
|
||||
<if test="phone != null and phone != ''">
|
||||
phone = #{phone}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,86 @@
|
||||
package com.xinelu.manage.domain.nursemanagepersonwechatinfo;
|
||||
|
||||
|
||||
import com.xinelu.common.annotation.Excel;
|
||||
import com.xinelu.common.core.domain.BaseDomain;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 护理站管理人员微信个人信息对象 nurse_manage_person_wechat_info
|
||||
*
|
||||
* @author xinyilu
|
||||
* @date 2023-04-03
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "护理站管理人员微信个人信息对象", description = "nurse_manage_person_wechat_info")
|
||||
public class NurseManagePersonWechatInfo extends BaseDomain implements Serializable {
|
||||
private static final long serialVersionUID = 3468614608277422287L;
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 护理机构表id
|
||||
*/
|
||||
@ApiModelProperty(value = "护理机构表id")
|
||||
@Excel(name = "护理机构表id")
|
||||
private String nurseStationId;
|
||||
|
||||
/**
|
||||
* 护理机构管理人员用户表id
|
||||
*/
|
||||
@ApiModelProperty(value = "护理机构管理人员用户表id")
|
||||
@Excel(name = "护理机构管理人员用户表id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
@ApiModelProperty(value = "微信openid")
|
||||
@Excel(name = "微信openid")
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 微信unionid
|
||||
*/
|
||||
@ApiModelProperty(value = "微信unionid")
|
||||
@Excel(name = "微信unionid")
|
||||
private String unionid;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@ApiModelProperty(value = "手机号")
|
||||
@Excel(name = "手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("nurseStationId", getNurseStationId())
|
||||
.append("userId", getUserId())
|
||||
.append("openid", getOpenid())
|
||||
.append("unionid", getUnionid())
|
||||
.append("phone", getPhone())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user