务工者-用户1.0
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
package com.ruoyi.wgz.service;
|
||||
|
||||
import com.ruoyi.wgz.bo.req.WgzAppUserLongInReq;
|
||||
import com.ruoyi.wgz.bo.req.WgzAppUserRegisterReq;
|
||||
import com.ruoyi.wgz.bo.res.WgzAppUserLongInRes;
|
||||
import com.ruoyi.wgz.domain.WgzUser;
|
||||
import com.ruoyi.wgz.bo.WgzUserQueryBo;
|
||||
import com.ruoyi.common.core.mybatisplus.core.IServicePlus;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* APP务工者Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-02-14
|
||||
*/
|
||||
public interface IWgzUserService extends IServicePlus<WgzUser> {
|
||||
/**
|
||||
* 查询单个
|
||||
* @return
|
||||
*/
|
||||
WgzUser queryById(String id);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
TableDataInfo<WgzUser> queryPageList(WgzUserQueryBo bo);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
List<WgzUser> queryList(WgzUserQueryBo bo);
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入APP务工者
|
||||
* @param bo APP务工者新增业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean insert(WgzUser bo);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象修改APP务工者
|
||||
* @param bo APP务工者编辑业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean update(WgzUser bo);
|
||||
|
||||
/**
|
||||
* 校验并删除数据
|
||||
* @param ids 主键集合
|
||||
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid);
|
||||
|
||||
|
||||
/**
|
||||
* 务工者APP相关
|
||||
* =================================================================================================================
|
||||
* =================================================================================================================
|
||||
* =================================================================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* 务工者APP注册账号
|
||||
* @param bo APP务工者注册业务对象
|
||||
* @return bool
|
||||
*/
|
||||
Boolean userRegister(WgzAppUserRegisterReq bo);
|
||||
|
||||
WgzAppUserLongInRes userLongIn(WgzAppUserLongInReq req);
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
package com.ruoyi.wgz.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.PageUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.wgz.bo.WgzUserQueryBo;
|
||||
import com.ruoyi.wgz.bo.req.WgzAppUserLongInReq;
|
||||
import com.ruoyi.wgz.bo.req.WgzAppUserRegisterReq;
|
||||
import com.ruoyi.wgz.bo.res.WgzAppUserLongInRes;
|
||||
import com.ruoyi.wgz.common.SnowflakeIdUtil;
|
||||
import com.ruoyi.wgz.domain.WgzUser;
|
||||
import com.ruoyi.wgz.mapper.WgzUserMapper;
|
||||
import com.ruoyi.wgz.service.IWgzUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* APP务工者Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2025-02-14
|
||||
*/
|
||||
@Service
|
||||
public class WgzUserServiceImpl extends ServicePlusImpl<WgzUserMapper, WgzUser> implements IWgzUserService {
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Override
|
||||
public WgzUser queryById(String id){
|
||||
return getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<WgzUser> queryPageList(WgzUserQueryBo bo) {
|
||||
Page<WgzUser> result = page(PageUtils.buildPage(), buildQueryWrapper(bo));
|
||||
return PageUtils.buildDataInfo(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WgzUser> queryList(WgzUserQueryBo bo) {
|
||||
return list(buildQueryWrapper(bo));
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<WgzUser> buildQueryWrapper(WgzUserQueryBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<WgzUser> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getUserId() != null, WgzUser::getUserId, bo.getUserId());
|
||||
lqw.like(StrUtil.isNotBlank(bo.getUsername()), WgzUser::getUsername, bo.getUsername());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getBirthdate()), WgzUser::getBirthdate, bo.getBirthdate());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getIdentityCard()), WgzUser::getIdentityCard, bo.getIdentityCard());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getPhone()), WgzUser::getPhone, bo.getPhone());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getCardNo()), WgzUser::getCardNo, bo.getCardNo());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getStatus()), WgzUser::getStatus, bo.getStatus());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insert(WgzUser bo) {
|
||||
WgzUser add = BeanUtil.toBean(bo, WgzUser.class);
|
||||
validEntityBeforeSave(add);
|
||||
return save(add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(WgzUser bo) {
|
||||
WgzUser update = BeanUtil.toBean(bo, WgzUser.class);
|
||||
validEntityBeforeSave(update);
|
||||
return updateById(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*
|
||||
* @param entity 实体类数据
|
||||
*/
|
||||
private void validEntityBeforeSave(WgzUser entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return removeByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 务工者APP相关
|
||||
* =================================================================================================================
|
||||
* =================================================================================================================
|
||||
* =================================================================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean userRegister(WgzAppUserRegisterReq bo) {
|
||||
WgzUser wgzUser = new WgzUser();
|
||||
//1、查询手机号是否存在
|
||||
Integer count = baseMapper.selectCount(
|
||||
new LambdaQueryWrapper<WgzUser>().
|
||||
eq(WgzUser::getPhone, wgzUser.getPhone())
|
||||
);
|
||||
if (count>0){
|
||||
throw new RuntimeException("当前手机号已存在!");
|
||||
}
|
||||
//2、组装数据 BeanUtils.copyProperties(bo,wgzUser);
|
||||
wgzUser.setPhone(bo.getPhone());
|
||||
wgzUser.setUserId(SnowflakeIdUtil.generateId());
|
||||
wgzUser.setPassword(SecurityUtils.encryptPassword(wgzUser.getPassword()));
|
||||
//3、保存数据
|
||||
return baseMapper.insert(wgzUser) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WgzAppUserLongInRes userLongIn(WgzAppUserLongInReq req) {
|
||||
//1、验证验证码是否正确(展示忽略)
|
||||
//2、验证账号是否存在
|
||||
WgzUser wgzUser = baseMapper.selectOne(new LambdaQueryWrapper<WgzUser>().eq(WgzUser::getPhone, req.getPhone()));
|
||||
if (wgzUser == null){
|
||||
throw new RuntimeException("账号不存在!");
|
||||
}
|
||||
//3、验证密码是否正确
|
||||
if (!SecurityUtils.matchesPassword(req.getPassword(),wgzUser.getPassword())){
|
||||
throw new RuntimeException("密码错误!");
|
||||
}
|
||||
//4、创建token返回wgzUser
|
||||
String token = tokenService.createToken(wgzUser);
|
||||
WgzAppUserLongInRes res = new WgzAppUserLongInRes();
|
||||
res.setToken(token);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String createToken(WgzUser wu) {
|
||||
String token = IdUtil.fastUUID();
|
||||
loginUser.setToken(token);
|
||||
setUserAgent(loginUser);
|
||||
refreshToken(loginUser);
|
||||
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put(Constants.LOGIN_USER_KEY, token);
|
||||
return createToken(claims);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user