Commit 649dba4d by 卓清洪

Merge remote-tracking branch 'origin/dev' into dev

parents 5f420599 32e634b0
package com.makeit.controller.device;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.entity.platform.device.PlatDeviceLog;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 设备日志 前端控制器
* </p>
*
* @author eugene young
* @since 2023-12-01
*/
@RestController
@RequestMapping("/saas/deviceLog")
@Api(tags = "租户管理-查看设备日志")
public class PlatDeviceLogController {
@Autowired
private PlatDeviceLogService platDeviceLogService;
@ApiOperation("列表")
@PostMapping("page")
@TenantIdIgnore
public ApiResponseEntity<PageVO<PlatDeviceLog>> page(@RequestBody PageReqDTO<PlatDeviceLog> pageReqDTO) {
return ApiResponseUtils.success(platDeviceLogService.pageList(pageReqDTO));
}
}
...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
@Api(tags = "租户管理-租户设备管理") @Api(tags = "租户管理-租户设备管理")
...@@ -121,8 +122,8 @@ public class SaasDeviceController { ...@@ -121,8 +122,8 @@ public class SaasDeviceController {
@PostMapping("devicePushLog") @PostMapping("devicePushLog")
@TenantIdIgnore @TenantIdIgnore
@AuthIgnore @AuthIgnore
public ApiResponseEntity devicePushLog(@RequestParam(value = "file", required = false) MultipartFile multipartFile, public ApiResponseEntity devicePushLog(@RequestParam(value = "rawData", required = false) MultipartFile multipartFile,
@RequestParam(value = "deviceId") String deviceId) { @RequestParam(value = "deviceId") String deviceId) throws IOException {
platDeviceService.devicePushLog(multipartFile,deviceId); platDeviceService.devicePushLog(multipartFile,deviceId);
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
......
...@@ -31,6 +31,8 @@ public class IotCommonService { ...@@ -31,6 +31,8 @@ public class IotCommonService {
@Value("${iot.url:}") @Value("${iot.url:}")
public String iotUrl; public String iotUrl;
@Value("${iot.uploadUrl:}")
public String uploadUrl;
protected static HttpClient httpClient = HttpClientBuilder.create().build(); protected static HttpClient httpClient = HttpClientBuilder.create().build();
......
...@@ -101,4 +101,26 @@ public class IotDevicePropertiesOperateService extends IotCommonService { ...@@ -101,4 +101,26 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
} }
return ""; return "";
} }
public String deviceFunctionAttr(String deviceId, Long timestamp) {
String url = iotUrl + "device/invoked/" + deviceId + "/function/misinformation";
Map<String,Map<String,Object>> map = Maps.newHashMap();
Map<String,Object> reqMap = Maps.newHashMap();
reqMap.put("timestamp",timestamp);
reqMap.put("url", uploadUrl);
map.put("misinformationNotify",reqMap);
HttpRequest request = buildRequest(url, JSON.toJSONString(map));
try {
ResponseMessage responseMessage = sendPut(url, request);
log.info("发送误报通知到设备返回信息:{}", responseMessage.getMessage());
if (responseMessage.getStatus() != 200) {
String errorMsg = responseMessage.getMessage();
log.error("发送误报通知失败:{}",errorMsg);
return errorMsg;
}
} catch (IOException e) {
log.error("调用:{}接口异常:{}", url, e.getMessage());
}
return "";
}
} }
...@@ -64,7 +64,7 @@ public interface AccessoryRepository { ...@@ -64,7 +64,7 @@ public interface AccessoryRepository {
* @Param file * @Param file
* @Param fileName * @Param fileName
**/ **/
File save(MultipartFile file, String path, String fileName); String save(MultipartFile file, String path, String fileName);
/** /**
* 保存输入流为文件对象 * 保存输入流为文件对象
......
...@@ -138,7 +138,7 @@ public class AliyunOSSRepository implements AccessoryRepository { ...@@ -138,7 +138,7 @@ public class AliyunOSSRepository implements AccessoryRepository {
* @Date 2020/8/20 14:49 * @Date 2020/8/20 14:49
*/ */
@Override @Override
public File save(MultipartFile file, String path, String fileName) { public String save(MultipartFile file, String path, String fileName) {
logger.debug("开始向aliyun-oss保存文件: {}", fileName); logger.debug("开始向aliyun-oss保存文件: {}", fileName);
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
try { try {
...@@ -152,7 +152,7 @@ public class AliyunOSSRepository implements AccessoryRepository { ...@@ -152,7 +152,7 @@ public class AliyunOSSRepository implements AccessoryRepository {
e.printStackTrace(); e.printStackTrace();
} }
logger.debug("完成向aliyun-oss保存文件: {}", System.currentTimeMillis() - begin); logger.debug("完成向aliyun-oss保存文件: {}", System.currentTimeMillis() - begin);
return null; return endpoint + "/" + bucketName + "/" + accessoryBaseDir + "/" +path + "/" + fileName;
} }
/** /**
......
...@@ -106,7 +106,7 @@ public class CodeGenerator { ...@@ -106,7 +106,7 @@ public class CodeGenerator {
// 使用重点 下列字段填写表名 运行方法 // 使用重点 下列字段填写表名 运行方法
// strategy.setInclude("edu_teacher","..."); // 多表-逆向工程 // strategy.setInclude("edu_teacher","..."); // 多表-逆向工程
strategy.setInclude("plat_region_setting_fix","plat_elder_coordinate_record"); strategy.setInclude("plat_device_log");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体属性时去掉表"_"前缀并且第一个字母大写 如:gmt_create -> gmtCreate strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体属性时去掉表"_"前缀并且第一个字母大写 如:gmt_create -> gmtCreate
......
package com.makeit.entity.platform.device;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.makeit.common.entity.BaseBusEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* <p>
* 设备日志
* </p>
*
* @author eugene young
* @since 2023-12-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="PlatDeviceLog对象", description="设备日志")
public class PlatDeviceLog extends BaseBusEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "iot设备sn")
private String deviceId;
@ApiModelProperty(value = "类型 1 误报")
private String type;
@ApiModelProperty(value = "产品名称")
private String productName;
@ApiModelProperty(value = "日志url")
private String url;
@ApiModelProperty(value = "文件名称")
private String fileName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("开始时间")
@TableField(exist = false)
private LocalDateTime startTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("结束时间")
@TableField(exist = false)
private LocalDateTime endTime;
}
package com.makeit.mapper.platform.device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.makeit.entity.platform.device.PlatDeviceLog;
/**
* <p>
* 设备日志 Mapper 接口
* </p>
*
* @author eugene young
* @since 2023-12-01
*/
public interface PlatDeviceLogMapper extends BaseMapper<PlatDeviceLog> {
}
...@@ -31,6 +31,7 @@ import com.makeit.enums.CommonEnum; ...@@ -31,6 +31,7 @@ import com.makeit.enums.CommonEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper; import com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.service.platform.alarm.PlatAlarmConfigService; import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
...@@ -66,6 +67,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; ...@@ -66,6 +67,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -111,9 +113,9 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -111,9 +113,9 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
@Autowired @Autowired
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
@Autowired @Autowired
private ShengwangProperties shengwangProperties;
@Autowired
private ShengwangService shengwangService; private ShengwangService shengwangService;
@Autowired
private IotDevicePropertiesOperateService iotDevicePropertiesOperateService;
@Override @Override
...@@ -581,7 +583,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -581,7 +583,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
platAlarmRecord.setDealUser(user.getName()); platAlarmRecord.setDealUser(user.getName());
updateById(platAlarmRecord); updateById(platAlarmRecord);
// todo 误报结果写入设备 String deviceId = platAlarmRecord.getDeviceId();
PlatDevice platDevice = platDeviceService.getById(deviceId);
if (platDevice == null) {
throw new RuntimeException("找不到告警关联的设备,设备已解绑" + deviceId);
}
Timestamp timestamp = Timestamp.valueOf(platAlarmRecord.getCreateDate());
iotDevicePropertiesOperateService.deviceFunctionAttr(platDevice.getOriDeviceId(),timestamp.getTime());
} }
@Override @Override
......
package com.makeit.service.platform.device;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.entity.platform.device.PlatDeviceLog;
/**
* <p>
* 设备日志 服务类
* </p>
*
* @author eugene young
* @since 2023-12-01
*/
public interface PlatDeviceLogService extends IService<PlatDeviceLog> {
PageVO<PlatDeviceLog> pageList(PageReqDTO<PlatDeviceLog> pageReqDTO);
}
...@@ -18,6 +18,7 @@ import com.makeit.vo.platform.device.PlatDeviceListVO; ...@@ -18,6 +18,7 @@ import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.device.PlatDeviceViewVO; import com.makeit.vo.platform.device.PlatDeviceViewVO;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
...@@ -90,5 +91,5 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -90,5 +91,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatAlarmCallDeviceVO callingDevice(PlatCallingDeviceDTO dto); PlatAlarmCallDeviceVO callingDevice(PlatCallingDeviceDTO dto);
void devicePushLog(MultipartFile multipartFile, String deviceId); void devicePushLog(MultipartFile multipartFile, String deviceId) throws IOException;
} }
package com.makeit.service.platform.device.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.device.PlatDeviceLog;
import com.makeit.mapper.platform.device.PlatDeviceLogMapper;
import com.makeit.service.platform.device.PlatDeviceLogService;
import com.makeit.utils.data.convert.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 设备日志 服务实现类
* </p>
*
* @author eugene young
* @since 2023-12-01
*/
@Service
public class PlatDeviceLogServiceImpl extends ServiceImpl<PlatDeviceLogMapper, PlatDeviceLog> implements PlatDeviceLogService {
@Autowired
private PlatDeviceLogMapper platDeviceLogMapper;
@Override
public PageVO<PlatDeviceLog> pageList(PageReqDTO<PlatDeviceLog> pageReqDTO) {
PlatDeviceLog dto = pageReqDTO.getData();
Page<PlatDeviceLog> p = PageUtil.toMpPage(pageReqDTO);
LambdaQueryWrapper<PlatDeviceLog> lambdaQueryWrapper = new QueryWrapper<PlatDeviceLog>().lambda()
.eq(StringUtils.isNotEmpty(dto.getDeviceId()), PlatDeviceLog::getDeviceId, dto.getDeviceId())
.eq(StringUtils.isNotEmpty(dto.getProductName()), PlatDeviceLog::getProductName, dto.getProductName())
.eq(StringUtils.isNotEmpty(dto.getTenantId()), PlatDeviceLog::getTenantId, dto.getTenantId())
.ge(dto.getStartTime() != null, PlatDeviceLog::getCreateDate, dto.getStartTime())
.ge(dto.getEndTime() != null, PlatDeviceLog::getCreateDate, dto.getEndTime());
Page<PlatDeviceLog> deviceLogPage = platDeviceLogMapper.selectPage(p, lambdaQueryWrapper);
return PageUtil.toPageVO(deviceLogPage.getRecords(), deviceLogPage);
}
}
package com.makeit.service.platform.device.impl; package com.makeit.service.platform.device.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -24,6 +27,7 @@ import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO; ...@@ -24,6 +27,7 @@ import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO;
import com.makeit.dto.wechat.device.*; import com.makeit.dto.wechat.device.*;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.device.PlatDeviceLog;
import com.makeit.entity.platform.device.PlatDeviceOther; import com.makeit.entity.platform.device.PlatDeviceOther;
import com.makeit.entity.platform.elder.PlatElder; import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting; import com.makeit.entity.platform.space.PlatRegionSetting;
...@@ -47,6 +51,7 @@ import com.makeit.module.system.service.SysDictionaryCategoryService; ...@@ -47,6 +51,7 @@ import com.makeit.module.system.service.SysDictionaryCategoryService;
import com.makeit.module.system.vo.DictionaryVo; import com.makeit.module.system.vo.DictionaryVo;
import com.makeit.oss.AliyunOSSRepository; import com.makeit.oss.AliyunOSSRepository;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.device.PlatDeviceLogService;
import com.makeit.service.platform.device.PlatDeviceOtherService; import com.makeit.service.platform.device.PlatDeviceOtherService;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderService; import com.makeit.service.platform.elder.PlatElderService;
...@@ -77,6 +82,7 @@ import org.springframework.stereotype.Service; ...@@ -77,6 +82,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
...@@ -130,6 +136,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -130,6 +136,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private ShengwangProperties shengwangProperties; private ShengwangProperties shengwangProperties;
@Autowired @Autowired
private AliyunOSSRepository aliyunOSSRepository; private AliyunOSSRepository aliyunOSSRepository;
@Autowired
private PlatDeviceLogService platDeviceLogService;
/** /**
* 平台设备列表 * 平台设备列表
...@@ -864,8 +872,28 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -864,8 +872,28 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
} }
@Override @Override
public void devicePushLog(MultipartFile multipartFile, String deviceId) { public void devicePushLog(MultipartFile file, String deviceId) throws IOException {
log.info("接受到设备上传的文件,设备id:{}",deviceId); log.info("接受到设备上传的文件,设备id:{}",deviceId);
aliyunOSSRepository.save(multipartFile,deviceId,multipartFile.getOriginalFilename()); String uploadPath = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
String name = file.getOriginalFilename();
String md5 = SecureUtil.md5(file.getInputStream()).substring(8, 24);
String type = name.substring(name.lastIndexOf("."));
String fileName = md5 + type;
String url = aliyunOSSRepository.save(file, uploadPath, fileName);
PlatDevice platDevice = getOne(new QueryWrapper<PlatDevice>().lambda().eq(PlatDevice::getOriDeviceId, deviceId)
.orderByDesc(BaseEntity::getCreateDate)
.last("limit 1"));
if (platDevice == null) {
throw new RuntimeException("找不到设备id:" + deviceId);
}
PlatDeviceLog platDeviceLog = new PlatDeviceLog();
platDeviceLog.setDeviceId(deviceId);
platDeviceLog.setProductName(platDevice.getProductName());
platDeviceLog.setType("1");
platDeviceLog.setTenantId(platDevice.getTenantId());
platDeviceLog.setUrl(url);
platDeviceLog.setFileName(name);
platDeviceLogService.save(platDeviceLog);
} }
} }
...@@ -114,6 +114,7 @@ libreOffice: C:\\Program Files\\LibreOffice\\program\\soffice ...@@ -114,6 +114,7 @@ libreOffice: C:\\Program Files\\LibreOffice\\program\\soffice
iot: iot:
url: https://iot.qa.insightica.cn/api/ url: https://iot.qa.insightica.cn/api/
uploadUrl: https://saas.qa.insightica.cn/api/saas/device/devicePushLog
clientId: fyxmb5h52iKwE2Hi clientId: fyxmb5h52iKwE2Hi
secureKey: 22fZbnH36wdHn7ZTyKKHraFw233npcez secureKey: 22fZbnH36wdHn7ZTyKKHraFw233npcez
sync: sync:
......
...@@ -105,6 +105,7 @@ libreOffice: /home/group1_lzy/iot-server/LibreOffice/program/soffice ...@@ -105,6 +105,7 @@ libreOffice: /home/group1_lzy/iot-server/LibreOffice/program/soffice
iot: iot:
url: https://iot.qa.insightica.cn/api/ url: https://iot.qa.insightica.cn/api/
uploadUrl: https://saas.qa.insightica.cn/api/saas/device/devicePushLog
clientId: fyxmb5h52iKwE2Hi clientId: fyxmb5h52iKwE2Hi
secureKey: 22fZbnH36wdHn7ZTyKKHraFw233npcez secureKey: 22fZbnH36wdHn7ZTyKKHraFw233npcez
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment