1. 快速登录
2. 解绑设备
This commit is contained in:
parent
b2cfaf1e0c
commit
82e881ce1b
|
@ -132,10 +132,23 @@ public class SysLoginController
|
|||
* 微信登录
|
||||
*/
|
||||
@PostMapping("/wxlogin")
|
||||
public AjaxResult wxlogin(String mobileCode) {
|
||||
public AjaxResult wxlogin(String mobileCode,String openid) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.wxloing(mobileCode);
|
||||
String token = loginService.wxloing(mobileCode,openid);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据openid静默登录
|
||||
*/
|
||||
@PostMapping("/loginByopenid")
|
||||
public AjaxResult loginByopenid(String openid) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.loginByopenid(openid);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 用户对象 as_user
|
||||
*
|
||||
*
|
||||
* @author qiuzhenzhao
|
||||
*/
|
||||
@ToString
|
||||
|
@ -81,6 +81,17 @@ public class AsUser extends BaseEntity
|
|||
/** 展示当前设备id */
|
||||
private Long deviceId;
|
||||
|
||||
/** 微信openid */
|
||||
private String wxopenid;
|
||||
|
||||
public String getWxopenid() {
|
||||
return wxopenid;
|
||||
}
|
||||
|
||||
public void setWxopenid(String wxopenid) {
|
||||
this.wxopenid = wxopenid;
|
||||
}
|
||||
|
||||
|
||||
public AsUser()
|
||||
{
|
||||
|
|
|
@ -113,7 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||
// 过滤请求
|
||||
.authorizeRequests()
|
||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload").permitAll()
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload","/loginByopenid").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
|
|
|
@ -259,7 +259,7 @@ public class SysLoginService
|
|||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
public String wxloing(String mobileCode) {
|
||||
public String wxloing(String mobileCode,String openid) {
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
||||
String phoneNumber = null;
|
||||
AsUser user = null;
|
||||
|
@ -286,6 +286,7 @@ public class SysLoginService
|
|||
asUser.setPhonenumber(phoneNumber);
|
||||
asUser.setLoginIp(IpUtils.getIpAddr());
|
||||
asUser.setLoginDate(DateUtils.getNowDate());
|
||||
asUser.setWxopenid(openid);
|
||||
asUser.setCreateTime(DateUtils.getNowDate());
|
||||
int i = asUserService.insertUser(asUser);
|
||||
user = asUser;
|
||||
|
@ -314,5 +315,37 @@ public class SysLoginService
|
|||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openid静默登录
|
||||
*/
|
||||
public String loginByopenid(String openid) {
|
||||
AsUser user = asUserService.selectUserByWxopenid(openid);
|
||||
if(ObjectUtils.isEmpty(user)){
|
||||
throw new ServiceException("未查询到用户信息");
|
||||
}
|
||||
Authentication authentication = null; // 用户验证
|
||||
try {
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(), Constants.CUSTOM_LOGIN_WX);
|
||||
// 用户名和密码等信息保存在一个上下文中,只要是同一线程等会就能拿到用户名和密码,也就是能在loadUserByUsername(String username)方法中进行密码验证等
|
||||
AuthenticationContextHolder.setContext(authenticationToken);
|
||||
// 把用户类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
||||
authenticationToken.setDetails(Constants.USER_TYPE_APP);
|
||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||
authentication = authenticationManager.authenticate(authenticationToken);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof BadCredentialsException) {
|
||||
throw new UserPasswordNotMatchException(); //抛出账号或者密码错误的异常
|
||||
} else {
|
||||
throw new ServiceException(e.getMessage()); //抛出其他异常
|
||||
}
|
||||
} finally {
|
||||
AuthenticationContextHolder.clearContext();
|
||||
}
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
recordAppLoginInfo(loginUser.getUserId());
|
||||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -157,15 +157,16 @@ public class AppController extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除设备列表 逻辑删除
|
||||
* 解绑设备
|
||||
*/
|
||||
@Log(title = "删除设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/device/{deviceId}")
|
||||
public AjaxResult remove(@PathVariable Long deviceId)
|
||||
@Log(title = "解绑设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/device/unbind/{deviceId}")
|
||||
public AjaxResult unbind(@PathVariable Long deviceId)
|
||||
{
|
||||
AsDevice device = new AsDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
device.setStatus("1");
|
||||
device.setUserId(0L);
|
||||
device.setIsNetwork("0");
|
||||
return toAjax(asDeviceService.logicallyDelete(device));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 用户表 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface AsUserMapper
|
||||
{
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
*
|
||||
* @param sysUser 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -22,7 +22,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 根据条件分页查询已配用户角色列表
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -30,7 +30,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色列表
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -38,7 +38,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
|
@ -46,7 +46,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
|
@ -54,7 +54,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 新增用户信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -62,7 +62,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -70,7 +70,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param avatar 头像地址
|
||||
* @return 结果
|
||||
|
@ -79,7 +79,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
|
@ -88,7 +88,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -96,7 +96,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
*
|
||||
* @param userIds 需要删除的用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -104,7 +104,7 @@ public interface AsUserMapper
|
|||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
*
|
||||
* @param userName 用户名称
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -133,4 +133,6 @@ public interface AsUserMapper
|
|||
* @return 用户对象信息
|
||||
*/
|
||||
public AsUser selectUserByPhone(String phone);
|
||||
|
||||
AsUser selectUserByWxopenid(String openid);
|
||||
}
|
||||
|
|
|
@ -188,4 +188,12 @@ public interface IAsUserService
|
|||
* 计算下次定时时间
|
||||
*/
|
||||
public void setNextDs(AsDevice asDevice1, DatapointValue.nextDs next_ds);
|
||||
|
||||
/**
|
||||
* 通过openid查询用户
|
||||
*
|
||||
* @param openid
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
AsUser selectUserByWxopenid(String openid);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,15 @@ public class AsModelServiceImpl extends ServiceImpl<AsModelMapper, AsModel> impl
|
|||
AsDeviceClassify deviceClassify = classifyMapper.selectAsDeviceClassifyByClassifyId(asModel.getClassifyId());
|
||||
String classifyName = deviceClassify.getClassifyName();
|
||||
asModel.setClassifyName(classifyName);
|
||||
return asModelMapper.updateAsModel(asModel);
|
||||
int i = asModelMapper.updateAsModel(asModel);
|
||||
AsDevice device = new AsDevice();
|
||||
device.setModelId(asModel.getModelId());
|
||||
List<AsDevice> asDevices = deviceMapper.selectAsDeviceList(device);
|
||||
for(AsDevice device1: asDevices){
|
||||
device1.setModel(asModel.getModel());
|
||||
deviceMapper.updateAsDevice(device1);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -418,6 +418,17 @@ public class AsUserServiceImpl implements IAsUserService
|
|||
return asUserMapper.selectUserByPhone(phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过openid查询用户
|
||||
*
|
||||
* @param openid 手机号
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@Override
|
||||
public AsUser selectUserByWxopenid(String openid) {
|
||||
return asUserMapper.selectUserByWxopenid(openid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据登录用户获取绑定设备
|
||||
* 根据登录用户获取是否有绑定设备,没有则显示添加设备页面,如果有则从列表中取一条记录展示
|
||||
|
|
|
@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="onlineStatus != null and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
|
||||
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="deviceId != null "> and device_id != #{deviceId}</if>
|
||||
<if test="modelId != null "> and model_id = #{modelId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="isBandByMac" resultType="java.lang.Integer">
|
||||
select count(1) from as_device
|
||||
where mac = #{mac} and user_id IS NOT NULL and is_network = 1
|
||||
where mac = #{mac} and user_id IS NOT NULL and is_network = 1 and user_id != 0
|
||||
</select>
|
||||
|
||||
<insert id="insertAsDevice" parameterType="AsDevice" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
|
|
|
@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select u.user_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber,u.birthday, u.password, u.pay_password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark
|
||||
from as_user u
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectUserList" parameterType="AsUser" resultMap="AsUserResult">
|
||||
select u.user_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark from as_user u
|
||||
where u.del_flag = '0'
|
||||
|
@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectAllocatedList" parameterType="AsUser" resultMap="AsUserResult">
|
||||
select distinct u.user_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from as_user u
|
||||
|
@ -65,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUnallocatedList" parameterType="AsUser" resultMap="AsUserResult">
|
||||
select distinct u.user_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from as_user u
|
||||
|
@ -77,25 +77,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
AND u.phonenumber like concat('%', #{phonenumber}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="AsUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_name = #{userName} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="AsUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkUserNameUnique" parameterType="String" resultMap="AsUserResult">
|
||||
select user_id, user_name from as_user where user_name = #{userName} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkPhoneUnique" parameterType="String" resultMap="AsUserResult">
|
||||
select user_id, phonenumber from as_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkEmailUnique" parameterType="String" resultMap="AsUserResult">
|
||||
select user_id, email from as_user where email = #{email} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
@ -104,7 +104,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectUserVo"/>
|
||||
where u.phonenumber = #{phonenumber}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserByWxopenid" parameterType="String" resultMap="AsUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.wxopenid = #{openid}
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="AsUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into as_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
|
@ -134,7 +139,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateUser" parameterType="AsUser">
|
||||
update as_user
|
||||
<set>
|
||||
|
@ -154,28 +159,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</set>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateUserStatus" parameterType="AsUser">
|
||||
update as_user set status = #{status} where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateUserAvatar" parameterType="AsUser">
|
||||
update as_user set avatar = #{avatar} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="resetUserPwd" parameterType="AsUser">
|
||||
update as_user set password = #{password} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
|
||||
<delete id="deleteUserById" parameterType="Long">
|
||||
update as_user set del_flag = '2' where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
|
||||
<delete id="deleteUserByIds" parameterType="Long">
|
||||
update as_user set del_flag = '2' where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user