Commit 794f18da by huangjy

feat: 查看设备日志

parent 393622ea
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));
}
}
...@@ -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;
@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> {
}
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);
}
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 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 +26,7 @@ import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO; ...@@ -24,6 +26,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 +50,7 @@ import com.makeit.module.system.service.SysDictionaryCategoryService; ...@@ -47,6 +50,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;
...@@ -130,6 +134,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -130,6 +134,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;
/** /**
* 平台设备列表 * 平台设备列表
...@@ -866,6 +872,18 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -866,6 +872,18 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override @Override
public void devicePushLog(MultipartFile multipartFile, String deviceId) { public void devicePushLog(MultipartFile multipartFile, String deviceId) {
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 url = aliyunOSSRepository.save(multipartFile, deviceId, multipartFile.getOriginalFilename());
PlatDevice platDevice = getOne(new QueryWrapper<PlatDevice>().lambda().eq(PlatDevice::getOriDeviceId, deviceId)
.orderByDesc(BaseEntity::getCreateDate)
.last("limit 1"));
PlatDeviceLog platDeviceLog = new PlatDeviceLog();
platDeviceLog.setDeviceId(deviceId);
platDeviceLog.setProductName(platDevice.getProductName());
platDeviceLog.setType("1");
platDeviceLog.setTenantId(platDevice.getTenantId());
platDeviceLog.setUrl(url);
platDeviceLogService.save(platDeviceLog);
} }
} }
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