Compare commits
7 Commits
prod
...
346792d5c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 346792d5c1 | |||
| cb87871982 | |||
| b280038502 | |||
| 3e119b1dd8 | |||
| cab0884d7f | |||
| ca11ef0e35 | |||
| ef2dc6a6f6 |
@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HBY670设备控制类
|
* HBY670设备控制类
|
||||||
@ -133,7 +134,7 @@ public class AppDeviceXinghanController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @Log("新增设备")
|
// @Log("新增设备")
|
||||||
@Operation(summary = "新增设备")
|
@Log(title = "新增设备")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public R<Void> addDevice(@RequestBody DeviceForm deviceForm) {
|
public R<Void> addDevice(@RequestBody DeviceForm deviceForm) {
|
||||||
try {
|
try {
|
||||||
@ -144,4 +145,26 @@ public class AppDeviceXinghanController extends BaseController {
|
|||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/GetDeviceByName")
|
||||||
|
@Operation(summary = "通过蓝牙名/设备名称查询设备")
|
||||||
|
public R<Object> GetDeviceByName(@RequestBody DeviceForm deviceForm) {
|
||||||
|
Object device = appDeviceService.GetDeviceByName(deviceForm);
|
||||||
|
return R.ok(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/getEquipCountByType")
|
||||||
|
@Operation(summary = "查询某个类型下的设备总数量")
|
||||||
|
public R<Object> getEquipCountByType(@RequestBody DeviceForm deviceForm) {
|
||||||
|
Object device = appDeviceService.getEquipCountByType(deviceForm);
|
||||||
|
return R.ok(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/getEquipAllByType")
|
||||||
|
@Operation(summary = "查询某个类型下的设备")
|
||||||
|
public R<List<Map<String,Object>>> getEquipAllByType(@RequestBody DeviceForm deviceForm){
|
||||||
|
List<Map<String,Object>> list=appDeviceService.getEquipAllByType(deviceForm);
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,9 +57,11 @@ import com.fuyuanshen.web.domain.Dto.DeviceDebugLogoUploadDto;
|
|||||||
import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto;
|
import com.fuyuanshen.web.domain.Dto.DeviceXinghanInstructDto;
|
||||||
import com.fuyuanshen.web.domain.vo.DeviceXinghanDetailVo;
|
import com.fuyuanshen.web.domain.vo.DeviceXinghanDetailVo;
|
||||||
import com.fuyuanshen.web.enums.AlarmTypeEnum;
|
import com.fuyuanshen.web.enums.AlarmTypeEnum;
|
||||||
|
import com.fuyuanshen.web.util.AliyunVoiceUtil;
|
||||||
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.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
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.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@ -93,6 +95,7 @@ public class DeviceXinghanBizService {
|
|||||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
private final AliyunVoiceUtil voiceUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有档位的描述表
|
* 所有档位的描述表
|
||||||
@ -135,7 +138,6 @@ public class DeviceXinghanBizService {
|
|||||||
public void upSOSGradeSettings(DeviceXinghanInstructDto dto) {
|
public void upSOSGradeSettings(DeviceXinghanInstructDto dto) {
|
||||||
if(dto.getIsBluetooth()){
|
if(dto.getIsBluetooth()){
|
||||||
long deviceId = dto.getDeviceId();
|
long deviceId = dto.getDeviceId();
|
||||||
|
|
||||||
// 1. 使用Optional简化空值检查,使代码更简洁
|
// 1. 使用Optional简化空值检查,使代码更简洁
|
||||||
Device device = Optional.ofNullable(deviceMapper.selectById(deviceId))
|
Device device = Optional.ofNullable(deviceMapper.selectById(deviceId))
|
||||||
.orElseThrow(() -> new ServiceException("设备不存在"));
|
.orElseThrow(() -> new ServiceException("设备不存在"));
|
||||||
@ -147,6 +149,24 @@ public class DeviceXinghanBizService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发异步报警
|
||||||
|
* Spring 会自动调用 AsyncConfig.getAsyncExecutor() 来执行此方法
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
public void executeSosCall(String phone) {
|
||||||
|
log.info("[SOS业务] 准备发起语音拨号 -> 目标: {}", phone);
|
||||||
|
Map<String, String> params = Map.of("device", "670");
|
||||||
|
String callId = voiceUtil.sendTtsSync(phone, "TTS_328730104", params);
|
||||||
|
|
||||||
|
if (callId != null) {
|
||||||
|
log.info("[SOS业务] 拨号指令下发成功, callId: {}", callId);
|
||||||
|
// 这里可以记录拨打日志到数据库
|
||||||
|
} else {
|
||||||
|
log.error("[SOS业务] 拨号指令下发失败,请检查配置或余额");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置强制报警
|
* 设置强制报警
|
||||||
*/
|
*/
|
||||||
@ -739,6 +759,7 @@ public class DeviceXinghanBizService {
|
|||||||
device.setCreateByName(loginUser.getNickname());
|
device.setCreateByName(loginUser.getNickname());
|
||||||
device.setTypeName(deviceTypes.getTypeName());
|
device.setTypeName(deviceTypes.getTypeName());
|
||||||
device.setDeviceType(deviceTypes.getId());
|
device.setDeviceType(deviceTypes.getId());
|
||||||
|
device.setDevicePic(deviceTypes.getDevicePic());
|
||||||
if (device.getDeviceImei() != null) {
|
if (device.getDeviceImei() != null) {
|
||||||
device.setPubTopic("A/" + device.getDeviceImei());
|
device.setPubTopic("A/" + device.getDeviceImei());
|
||||||
device.setSubTopic("B/" + device.getDeviceImei());
|
device.setSubTopic("B/" + device.getDeviceImei());
|
||||||
@ -767,4 +788,23 @@ public class DeviceXinghanBizService {
|
|||||||
return uuidStr.replaceAll("-", "");
|
return uuidStr.replaceAll("-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> GetDeviceByName(DeviceForm deviceForm){
|
||||||
|
List<Map<String, Object>> list= deviceMapper.GetDeviceByName(deviceForm);
|
||||||
|
Map<String, Object> device=null;
|
||||||
|
if(list!=null && list.size()>0){
|
||||||
|
device=list.get(0);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEquipCountByType(DeviceForm form){
|
||||||
|
var res=deviceMapper.getEquipCountByType(form);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String,Object>> getEquipAllByType(DeviceForm deviceForm){
|
||||||
|
List<Map<String, Object>> list= deviceMapper.getEquipAllByType(deviceForm);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,87 @@
|
|||||||
|
package com.fuyuanshen.web.util;
|
||||||
|
|
||||||
|
import com.aliyun.dyvmsapi20170525.Client;
|
||||||
|
import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest;
|
||||||
|
import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsResponse;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AliyunVoiceUtil {
|
||||||
|
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Value("${alibaba.tts.akId}")
|
||||||
|
private String akId;
|
||||||
|
@Value("${alibaba.tts.akSecret}")
|
||||||
|
private String akSecret;
|
||||||
|
// @Value("${alibaba.tts.calledShowNumber:}")
|
||||||
|
private String calledShowNumber;
|
||||||
|
|
||||||
|
// ========== 核心:单例客户端(类似 OkHttpClient) ==========
|
||||||
|
private volatile Client client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户端(双重检查锁实现单例)
|
||||||
|
* 只有在第一次调用时才会根据配置实例化,后续直接返回复用
|
||||||
|
*/
|
||||||
|
private Client getClient() throws Exception {
|
||||||
|
if (client == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (client == null) {
|
||||||
|
log.info("[AliyunVoice] 正在初始化阿里云语音客户端...");
|
||||||
|
Config config = new Config()
|
||||||
|
.setAccessKeyId(akId)
|
||||||
|
.setAccessKeySecret(akSecret)
|
||||||
|
.setEndpoint("dyvmsapi.aliyuncs.com");
|
||||||
|
this.client = new Client(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步发送方法:由异步架构调用
|
||||||
|
*/
|
||||||
|
public String sendTtsSync(String phone, String templateCode, Map<String, String> params) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. 获取(或初始化)单例客户端
|
||||||
|
Client voiceClient = getClient();
|
||||||
|
|
||||||
|
SingleCallByTtsRequest request = new SingleCallByTtsRequest()
|
||||||
|
.setCalledNumber(phone)
|
||||||
|
.setTtsCode(templateCode)
|
||||||
|
.setTtsParam(objectMapper.writeValueAsString(params));
|
||||||
|
|
||||||
|
if (StringUtils.hasText(calledShowNumber)) {
|
||||||
|
request.setCalledShowNumber(calledShowNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生产级超时配置
|
||||||
|
RuntimeOptions runtime = new RuntimeOptions();
|
||||||
|
runtime.setConnectTimeout(5000);
|
||||||
|
runtime.setReadTimeout(10000);
|
||||||
|
|
||||||
|
SingleCallByTtsResponse response = voiceClient.singleCallByTtsWithOptions(request, runtime);
|
||||||
|
|
||||||
|
if ("OK".equalsIgnoreCase(response.getBody().getCode())) {
|
||||||
|
return response.getBody().getCallId();
|
||||||
|
} else {
|
||||||
|
log.error("[AliyunVoice] 拨号失败: {}", response.getBody().getMessage());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[AliyunVoice] 接口异常", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -140,6 +140,18 @@
|
|||||||
<version>3.3.1</version>
|
<version>3.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 电话语音通知 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>dyvmsapi20170525</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>tea-openapi</artifactId>
|
||||||
|
<version>0.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- fastjson2 -->
|
<!-- fastjson2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.fastjson2</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +51,7 @@ public class DeviceTypeController {
|
|||||||
// @Log("新增设备类型")
|
// @Log("新增设备类型")
|
||||||
@Operation(summary = "新增设备类型")
|
@Operation(summary = "新增设备类型")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public R<Void> createDeviceType(@Validated @RequestBody DeviceType resources) {
|
public R<Void> createDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
|
||||||
deviceTypeService.create(resources);
|
deviceTypeService.create(resources);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ public class DeviceTypeController {
|
|||||||
// @Log("修改设备类型")
|
// @Log("修改设备类型")
|
||||||
@Operation(summary = "修改设备类型")
|
@Operation(summary = "修改设备类型")
|
||||||
@PutMapping(value = "/update")
|
@PutMapping(value = "/update")
|
||||||
public R<Void> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) {
|
public R<Void> updateDeviceType(@Validated @ModelAttribute DeviceTypeForm resources) throws IOException {
|
||||||
deviceTypeService.update(resources);
|
deviceTypeService.update(resources);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,5 +85,8 @@ public class DeviceType extends TenantEntity {
|
|||||||
@Schema(title = "型号字典用于PC页面跳转")
|
@Schema(title = "型号字典用于PC页面跳转")
|
||||||
private String pcModelDictionary;
|
private String pcModelDictionary;
|
||||||
|
|
||||||
|
@Schema(title = "设备图片")
|
||||||
|
private String devicePic;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,9 @@ public class DeviceForm {
|
|||||||
@Schema(title = "备注")
|
@Schema(title = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(title = "商户号")
|
||||||
|
private Long tenant_id;
|
||||||
|
|
||||||
|
|
||||||
// 设备类型相关字段
|
// 设备类型相关字段
|
||||||
@Schema(title = "设备类型名称")
|
@Schema(title = "设备类型名称")
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.form;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 设备类型
|
* @Description: 设备类型
|
||||||
@ -48,5 +49,10 @@ public class DeviceTypeForm {
|
|||||||
*/
|
*/
|
||||||
@Schema(title = "型号字典用于PC页面跳转")
|
@Schema(title = "型号字典用于PC页面跳转")
|
||||||
private String pcModelDictionary;
|
private String pcModelDictionary;
|
||||||
|
@Schema(title = "设备图片")
|
||||||
|
private String devicePic;
|
||||||
|
|
||||||
|
@Schema(title = "设备图片")
|
||||||
|
private MultipartFile file;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import com.fuyuanshen.equipment.domain.DeviceType;
|
|||||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
import com.fuyuanshen.equipment.domain.dto.DeviceExcelImportDTO;
|
||||||
import com.fuyuanshen.equipment.domain.dto.ImportResult;
|
import com.fuyuanshen.equipment.domain.dto.ImportResult;
|
||||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||||
|
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||||
import com.fuyuanshen.equipment.handler.ImageWriteHandler;
|
import com.fuyuanshen.equipment.handler.ImageWriteHandler;
|
||||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -437,8 +438,10 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
|||||||
newDeviceType.setAppModelDictionary(originalDto.getAppModelDictionary());
|
newDeviceType.setAppModelDictionary(originalDto.getAppModelDictionary());
|
||||||
newDeviceType.setPcModelDictionary(originalDto.getPcModelDictionary());
|
newDeviceType.setPcModelDictionary(originalDto.getPcModelDictionary());
|
||||||
|
|
||||||
|
DeviceTypeForm deviceTypeForm = new DeviceTypeForm();
|
||||||
|
BeanUtil.copyProperties(newDeviceType, deviceTypeForm, true);
|
||||||
// 创建新的设备类型
|
// 创建新的设备类型
|
||||||
params.getDeviceTypeService().create(newDeviceType);
|
params.getDeviceTypeService().create(deviceTypeForm);
|
||||||
|
|
||||||
// 重新查询确保获取到正确的ID
|
// 重新查询确保获取到正确的ID
|
||||||
deviceType = params.getDeviceTypeService().queryByName(device.getTypeName());
|
deviceType = params.getDeviceTypeService().queryByName(device.getTypeName());
|
||||||
|
|||||||
@ -5,6 +5,7 @@ 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.fuyuanshen.equipment.domain.Device;
|
import com.fuyuanshen.equipment.domain.Device;
|
||||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||||
|
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||||
import com.fuyuanshen.equipment.domain.vo.*;
|
import com.fuyuanshen.equipment.domain.vo.*;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
@ -148,4 +149,10 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
|||||||
*/
|
*/
|
||||||
int countByDeviceTypeId(@Param("deviceTypeId") Long deviceTypeId);
|
int countByDeviceTypeId(@Param("deviceTypeId") Long deviceTypeId);
|
||||||
|
|
||||||
|
List<Map<String, Object>> GetDeviceByName(DeviceForm deviceForm);
|
||||||
|
|
||||||
|
int getEquipCountByType(DeviceForm deviceForm);
|
||||||
|
|
||||||
|
List<Map<String,Object>> getEquipAllByType(DeviceForm deviceForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -8,6 +8,7 @@ import com.fuyuanshen.equipment.domain.DeviceType;
|
|||||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,14 +64,14 @@ public interface DeviceTypeService extends IService<DeviceType> {
|
|||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(DeviceType resources);
|
void create(DeviceTypeForm resources) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改设备类型
|
* 修改设备类型
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(DeviceTypeForm resources);
|
void update(DeviceTypeForm resources) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多选删除
|
* 多选删除
|
||||||
|
|||||||
@ -325,6 +325,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
device.setCreateByName(loginUser.getNickname());
|
device.setCreateByName(loginUser.getNickname());
|
||||||
device.setTypeName(deviceType.getTypeName());
|
device.setTypeName(deviceType.getTypeName());
|
||||||
device.setDeviceType(deviceType.getId());
|
device.setDeviceType(deviceType.getId());
|
||||||
|
device.setDevicePic(deviceType.getDevicePic());
|
||||||
if (device.getDeviceImei() != null) {
|
if (device.getDeviceImei() != null) {
|
||||||
device.setPubTopic("A/" + device.getDeviceImei());
|
device.setPubTopic("A/" + device.getDeviceImei());
|
||||||
device.setSubTopic("B/" + device.getDeviceImei());
|
device.setSubTopic("B/" + device.getDeviceImei());
|
||||||
|
|||||||
@ -19,12 +19,16 @@ import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
|||||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||||
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
import com.fuyuanshen.equipment.service.DeviceTypeService;
|
||||||
|
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||||
|
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||||
import com.fuyuanshen.system.domain.vo.SysRoleVo;
|
import com.fuyuanshen.system.domain.vo.SysRoleVo;
|
||||||
|
import com.fuyuanshen.system.service.ISysOssService;
|
||||||
import com.fuyuanshen.system.service.ISysRoleService;
|
import com.fuyuanshen.system.service.ISysRoleService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -46,6 +50,8 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
|||||||
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
||||||
|
|
||||||
private final ISysRoleService roleService;
|
private final ISysRoleService roleService;
|
||||||
|
private final ISysOssService ossService;
|
||||||
|
private final FileHashUtil fileHashUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,24 +187,38 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(DeviceType resources) {
|
public void create(DeviceTypeForm resources) throws IOException {
|
||||||
|
|
||||||
// 校验设备类型名称
|
// 校验设备类型名称
|
||||||
List<DeviceType> typeName = deviceTypeMapper.selectList(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
|
List<DeviceType> typeName = deviceTypeMapper.selectList(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
|
||||||
if (CollectionUtil.isNotEmpty(typeName)) {
|
if (CollectionUtil.isNotEmpty(typeName)) {
|
||||||
throw new RuntimeException("设备类型名称已存在,无法新增!!!");
|
throw new RuntimeException("设备类型名称已存在,无法新增!!!");
|
||||||
}
|
}
|
||||||
|
// 保存图片并获取URL
|
||||||
|
if (resources.getFile() != null) {
|
||||||
|
String fileHash = fileHashUtil.hash(resources.getFile());
|
||||||
|
SysOssVo upload = ossService.updateHash(resources.getFile(), fileHash);
|
||||||
|
// 强制将HTTP替换为HTTPS
|
||||||
|
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
|
||||||
|
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
|
||||||
|
}
|
||||||
|
// 设置图片路径
|
||||||
|
resources.setDevicePic(upload.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
BeanUtil.copyProperties(resources, deviceType, true);
|
||||||
|
|
||||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
resources.setCustomerId(loginUser.getUserId());
|
deviceType.setCustomerId(loginUser.getUserId());
|
||||||
resources.setOwnerCustomerId(loginUser.getUserId());
|
deviceType.setOwnerCustomerId(loginUser.getUserId());
|
||||||
resources.setOriginalOwnerId(loginUser.getUserId());
|
deviceType.setOriginalOwnerId(loginUser.getUserId());
|
||||||
resources.setCreateByName(loginUser.getNickname());
|
deviceType.setCreateByName(loginUser.getNickname());
|
||||||
deviceTypeMapper.insert(resources);
|
deviceTypeMapper.insert(deviceType);
|
||||||
|
|
||||||
// 自动授权给自己
|
// 自动授权给自己
|
||||||
DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
|
DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
|
||||||
deviceTypeGrants.setDeviceTypeId(resources.getId());
|
deviceTypeGrants.setDeviceTypeId(deviceType.getId());
|
||||||
deviceTypeGrants.setCustomerId(loginUser.getUserId());
|
deviceTypeGrants.setCustomerId(loginUser.getUserId());
|
||||||
deviceTypeGrants.setGrantorCustomerId(loginUser.getUserId());
|
deviceTypeGrants.setGrantorCustomerId(loginUser.getUserId());
|
||||||
deviceTypeGrants.setGrantedAt(new Date());
|
deviceTypeGrants.setGrantedAt(new Date());
|
||||||
@ -213,7 +233,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(DeviceTypeForm resources) {
|
public void update(DeviceTypeForm resources) throws IOException {
|
||||||
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(resources.getId());
|
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(resources.getId());
|
||||||
if (deviceTypeGrants == null) {
|
if (deviceTypeGrants == null) {
|
||||||
throw new RuntimeException("设备类型不存在");
|
throw new RuntimeException("设备类型不存在");
|
||||||
@ -244,6 +264,17 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
|||||||
throw new RuntimeException("无权修改该设备类型");
|
throw new RuntimeException("无权修改该设备类型");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 保存图片并获取URL
|
||||||
|
if (resources.getFile() != null) {
|
||||||
|
String fileHash = fileHashUtil.hash(resources.getFile());
|
||||||
|
SysOssVo upload = ossService.updateHash(resources.getFile(), fileHash);
|
||||||
|
// 强制将HTTP替换为HTTPS
|
||||||
|
if (upload.getUrl() != null && upload.getUrl().startsWith("http://")) {
|
||||||
|
upload.setUrl(upload.getUrl().replaceFirst("^http://", "https://"));
|
||||||
|
}
|
||||||
|
// 设置图片路径
|
||||||
|
resources.setDevicePic(upload.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
BeanUtil.copyProperties(resources, deviceType);
|
BeanUtil.copyProperties(resources, deviceType);
|
||||||
deviceTypeMapper.updateById(deviceType);
|
deviceTypeMapper.updateById(deviceType);
|
||||||
|
|||||||
@ -264,6 +264,44 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="GetDeviceByName" resultType="map" >
|
||||||
|
select a.id,
|
||||||
|
a.device_type,
|
||||||
|
a.device_name,
|
||||||
|
a.device_mac,
|
||||||
|
a.type_name,
|
||||||
|
a.bluetooth_name,
|
||||||
|
a.device_imei
|
||||||
|
from device a
|
||||||
|
<where>
|
||||||
|
a.tenant_id = #{tenant_id} and
|
||||||
|
a.device_type = #{deviceType}
|
||||||
|
AND (
|
||||||
|
a.device_name=#{deviceName} or
|
||||||
|
a.bluetooth_name=#{deviceName}
|
||||||
|
)
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getEquipCountByType" resultType="int">
|
||||||
|
select count(1) cnt
|
||||||
|
from device a
|
||||||
|
<where>
|
||||||
|
a.tenant_id = #{tenant_id} and
|
||||||
|
a.device_type = #{deviceType}
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getEquipAllByType" resultType="map">
|
||||||
|
select device_mac,bluetooth_name,device_name
|
||||||
|
from device a
|
||||||
|
<where>
|
||||||
|
a.tenant_id = #{tenant_id} and
|
||||||
|
a.device_type = #{deviceType}
|
||||||
|
</where>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- 获取分配设备的客户 -->
|
<!-- 获取分配设备的客户 -->
|
||||||
<select id="getAssignCustomer" resultType="com.fuyuanshen.equipment.domain.Device">
|
<select id="getAssignCustomer" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|||||||
Reference in New Issue
Block a user