168 lines
7.2 KiB
Java
168 lines
7.2 KiB
Java
package com.fuyuanshen.app.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
|
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
|
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
|
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
|
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
|
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
|
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
|
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
|
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
|
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
|
import com.fuyuanshen.equipment.domain.Device;
|
|
import com.fuyuanshen.equipment.domain.DeviceType;
|
|
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
|
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
|
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
|
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
|
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
|
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class AppDeviceBizService {
|
|
|
|
private final APPDeviceMapper appDeviceMapper;
|
|
private final DeviceMapper deviceMapper;
|
|
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
|
private final DeviceTypeMapper deviceTypeMapper;
|
|
|
|
|
|
public List<APPDeviceTypeVo> getTypeList() {
|
|
Long userId = AppLoginHelper.getUserId();
|
|
return appDeviceMapper.getTypeList(userId);
|
|
}
|
|
|
|
public void reName(APPReNameDTO reNameDTO) {
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
updateWrapper.eq("id", reNameDTO.getId())
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
.set("device_name", reNameDTO.getDeviceName());
|
|
deviceMapper.update(updateWrapper);
|
|
}
|
|
|
|
|
|
public int sendMessage(AppDeviceBo bo) {
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
updateWrapper.eq("id", bo.getDeviceId())
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
.set("send_msg", bo.getSendMsg());
|
|
return deviceMapper.update(updateWrapper);
|
|
}
|
|
|
|
|
|
public TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
|
if (bo.getBindingUserId() == null) {
|
|
Long userId = AppLoginHelper.getUserId();
|
|
bo.setBindingUserId(userId);
|
|
}
|
|
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
|
return TableDataInfo.build(result);
|
|
}
|
|
|
|
public int bindDevice(AppDeviceBo bo) {
|
|
Integer mode = bo.getCommunicationMode();
|
|
Long userId = AppLoginHelper.getUserId();
|
|
if (mode == CommunicationModeEnum.FOUR_G.getValue()) {
|
|
|
|
String deviceImei = bo.getDeviceImei();
|
|
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
|
.eq("device_imei", deviceImei);
|
|
List<Device> devices = deviceMapper.selectList(qw);
|
|
if (devices.isEmpty()) {
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
}
|
|
Device device = devices.get(0);
|
|
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
|
throw new RuntimeException("设备已绑定");
|
|
}
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
.set("binding_user_id", userId)
|
|
.set("binding_time", new Date());
|
|
|
|
|
|
return deviceMapper.update(null, deviceUpdateWrapper);
|
|
} else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) {
|
|
String deviceMac = bo.getDeviceMac();
|
|
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
|
.eq("device_mac", deviceMac);
|
|
List<Device> devices = deviceMapper.selectList(qw);
|
|
if (devices.isEmpty()) {
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
}
|
|
Device device = devices.get(0);
|
|
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
|
throw new RuntimeException("设备已绑定");
|
|
}
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
.set("binding_user_id", userId)
|
|
.set("binding_time", new Date());
|
|
return deviceMapper.update(null, deviceUpdateWrapper);
|
|
} else {
|
|
throw new RuntimeException("通讯方式错误");
|
|
}
|
|
|
|
}
|
|
|
|
public int unBindDevice(Long id) {
|
|
Device device = deviceMapper.selectById(id);
|
|
if (device == null) {
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
}
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
|
.set("binding_user_id", null)
|
|
.set("binding_time", null);
|
|
return deviceMapper.update(null, deviceUpdateWrapper);
|
|
}
|
|
|
|
public AppDeviceDetailVo getInfo(Long id) {
|
|
Device device = deviceMapper.selectById(id);
|
|
AppDeviceDetailVo vo = new AppDeviceDetailVo();
|
|
vo.setDeviceId(device.getId());
|
|
vo.setDeviceName(device.getDeviceName());
|
|
vo.setDevicePic(device.getDevicePic());
|
|
vo.setDeviceImei(device.getDeviceImei());
|
|
vo.setDeviceMac(device.getDeviceMac());
|
|
vo.setDeviceStatus(device.getDeviceStatus());
|
|
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
|
if(deviceType!=null){
|
|
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
|
vo.setTypeName(deviceType.getTypeName());
|
|
}
|
|
vo.setBluetoothName(device.getBluetoothName());
|
|
|
|
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectById(device.getId());
|
|
if(appPersonnelInfo != null){
|
|
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
|
vo.setPersonnelInfo(personnelInfoVo);
|
|
}
|
|
return vo;
|
|
}
|
|
|
|
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
|
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
|
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
|
}
|
|
}
|