APP/小程序用户设备绑定
This commit is contained in:
@ -63,7 +63,7 @@ public class MPController {
|
|||||||
List<AuthorityDto> authorityDtos = new ArrayList<>();
|
List<AuthorityDto> authorityDtos = new ArrayList<>();
|
||||||
authorityDtos.add(authorityDto);
|
authorityDtos.add(authorityDto);
|
||||||
user.setPhone(authUser.getPhoneNumber());
|
user.setPhone(authUser.getPhoneNumber());
|
||||||
JwtUserDto jwtUser = new JwtUserDto(user, null, authorityDtos);
|
JwtUserDto jwtUser = new JwtUserDto(null, user, null, authorityDtos);
|
||||||
|
|
||||||
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, authorityDtos);
|
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, authorityDtos);
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
|
@ -26,7 +26,6 @@ public class APPDevice extends BaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "ID")
|
@ApiModelProperty(value = "ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "设备类型")
|
@ApiModelProperty(value = "设备类型")
|
||||||
private Long deviceType;
|
private Long deviceType;
|
||||||
|
|
||||||
@ -90,6 +89,14 @@ public class APPDevice extends BaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "绑定状态")
|
@ApiModelProperty(value = "绑定状态")
|
||||||
private Integer bindingStatus;
|
private Integer bindingStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定类型
|
||||||
|
* 0 APP
|
||||||
|
* 1 小程序
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "绑定类型")
|
||||||
|
private Integer bindingType;
|
||||||
|
|
||||||
|
|
||||||
public void copy(Device source) {
|
public void copy(Device source) {
|
||||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
@ -67,8 +67,16 @@ public class APPDeviceController {
|
|||||||
private final APPDeviceService appDeviceService;
|
private final APPDeviceService appDeviceService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/bind")
|
||||||
|
@ApiOperation("APP用户设备绑定")
|
||||||
|
public ResponseVO<String> appBindDevice(@ApiParam("设备MAC地址") String mac) {
|
||||||
|
appDeviceService.appBindDevice(mac);
|
||||||
|
return ResponseVO.success("绑定成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@ApiOperation("查看APP用户设备绑定")
|
@ApiOperation("WEB端查看APP用户设备绑定")
|
||||||
public ResponseVO<PageResult<APPDevice>> queryAPPDevice(DeviceQueryCriteria criteria) {
|
public ResponseVO<PageResult<APPDevice>> queryAPPDevice(DeviceQueryCriteria criteria) {
|
||||||
Page<APPDevice> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<APPDevice> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
PageResult<APPDevice> devices = null;
|
PageResult<APPDevice> devices = null;
|
||||||
@ -83,7 +91,7 @@ public class APPDeviceController {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping(value = "/unbind")
|
@PostMapping(value = "/unbind")
|
||||||
@ApiOperation("APP用户设备解绑")
|
@ApiOperation("WEB端APP用户设备解绑")
|
||||||
public ResponseVO<String> unbindAPPDevice(@Validated @ModelAttribute APPUnbindDTO deviceForm) {
|
public ResponseVO<String> unbindAPPDevice(@Validated @ModelAttribute APPUnbindDTO deviceForm) {
|
||||||
appDeviceService.unbindAPPDevice(deviceForm);
|
appDeviceService.unbindAPPDevice(deviceForm);
|
||||||
return ResponseVO.success("解绑成功!!!");
|
return ResponseVO.success("解绑成功!!!");
|
||||||
|
@ -22,6 +22,14 @@ import java.util.List;
|
|||||||
**/
|
**/
|
||||||
public interface APPDeviceService extends IService<APPDevice> {
|
public interface APPDeviceService extends IService<APPDevice> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APP/小程序用户设备绑定
|
||||||
|
*
|
||||||
|
* @param mac
|
||||||
|
*/
|
||||||
|
void appBindDevice(String mac);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询APP/小程序设备绑定
|
* 分页查询APP/小程序设备绑定
|
||||||
*
|
*
|
||||||
@ -38,4 +46,5 @@ public interface APPDeviceService extends IService<APPDevice> {
|
|||||||
*/
|
*/
|
||||||
void unbindAPPDevice(APPUnbindDTO deviceForm);
|
void unbindAPPDevice(APPUnbindDTO deviceForm);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,49 +2,30 @@ package com.fuyuanshen.modules.system.service.app;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.fuyuanshen.constants.DeviceConstants;
|
|
||||||
import com.fuyuanshen.constants.ExceptionMessages;
|
|
||||||
import com.fuyuanshen.exception.BadRequestException;
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
|
||||||
import com.fuyuanshen.modules.system.constant.UserConstants;
|
|
||||||
import com.fuyuanshen.modules.system.domain.Device;
|
import com.fuyuanshen.modules.system.domain.Device;
|
||||||
import com.fuyuanshen.modules.system.domain.DeviceType;
|
import com.fuyuanshen.modules.system.domain.DeviceType;
|
||||||
import com.fuyuanshen.modules.system.domain.User;
|
|
||||||
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
import com.fuyuanshen.modules.system.domain.app.APPDeviceType;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.app.APPUnbindDTO;
|
import com.fuyuanshen.modules.system.domain.dto.app.APPUnbindDTO;
|
||||||
import com.fuyuanshen.modules.system.enums.BindingStatusEnum;
|
import com.fuyuanshen.modules.system.enums.BindingStatusEnum;
|
||||||
|
import com.fuyuanshen.modules.system.enums.UserType;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
|
||||||
import com.fuyuanshen.modules.system.mapper.app.APPDeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.app.APPDeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.service.DeviceService;
|
import com.fuyuanshen.utils.PageResult;
|
||||||
import com.fuyuanshen.modules.system.service.UserService;
|
import com.fuyuanshen.utils.SecurityUtils;
|
||||||
import com.fuyuanshen.modules.system.service.impl.DeviceTypeServiceImpl;
|
|
||||||
import com.fuyuanshen.modules.utils.NanoId;
|
|
||||||
import com.fuyuanshen.utils.*;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import java.util.List;
|
||||||
import java.io.*;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:
|
* @Description:
|
||||||
@ -58,6 +39,42 @@ public class APPDeviceServiceImpl extends ServiceImpl<APPDeviceMapper, APPDevice
|
|||||||
|
|
||||||
private final APPDeviceMapper appDeviceMapper;
|
private final APPDeviceMapper appDeviceMapper;
|
||||||
private final DeviceMapper deviceMapper;
|
private final DeviceMapper deviceMapper;
|
||||||
|
private final DeviceTypeMapper deviceTypeMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APP/小程序用户设备绑定
|
||||||
|
*
|
||||||
|
* @param mac
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void appBindDevice(String mac) {
|
||||||
|
List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_mac", mac));
|
||||||
|
if (CollectionUtil.isEmpty(devices)) {
|
||||||
|
throw new BadRequestException("请先将设备入库!!!");
|
||||||
|
}
|
||||||
|
List<APPDevice> appDevices = appDeviceMapper.selectList(new QueryWrapper<APPDevice>()
|
||||||
|
.eq("device_mac", mac).eq("binding_type", UserType.APP.getValue()));
|
||||||
|
if (CollectionUtil.isNotEmpty(appDevices)) {
|
||||||
|
throw new BadRequestException("该设备已绑定!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Device device = devices.get(0);
|
||||||
|
APPDevice appDevice = new APPDevice();
|
||||||
|
BeanUtil.copyProperties(appDevice, device);
|
||||||
|
appDevice.setBindingType(UserType.APP.getValue());
|
||||||
|
appDevice.setBindingStatus(BindingStatusEnum.BOUND.getCode());
|
||||||
|
Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
appDevice.setCustomerId(currentUserId);
|
||||||
|
appDeviceMapper.insert(appDevice);
|
||||||
|
|
||||||
|
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||||
|
APPDeviceType appDeviceType = new APPDeviceType();
|
||||||
|
BeanUtil.copyProperties(appDeviceType, deviceType);
|
||||||
|
deviceTypeMapper.insert(appDeviceType);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,4 +107,5 @@ public class APPDeviceServiceImpl extends ServiceImpl<APPDeviceMapper, APPDevice
|
|||||||
deviceMapper.updateById(device);
|
deviceMapper.updateById(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user