Commit 2e87fffd by zzrdark

1.add device log oos

parent 87ce018e
......@@ -15,10 +15,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
......@@ -48,13 +45,20 @@ public class LogFlieController {
private HdfsTemplate hdfsTemplate;
@PostMapping("/logfile/wechatDeviceLogUpload")
public R wechatUploadLog(WechatDeviceLogVo vo, MultipartFile[] file){
@ResponseBody
public R wechatUploadLog(WechatDeviceLogVo vo, MultipartFile[] file) throws IOException {
WechatDeviceLogDto dto = new WechatDeviceLogDto();
BeanUtils.copyProperties(vo, dto);
// 把图片存入oos 返回路径
// dto.setLogfileUrl()
List<String> listUrl = new ArrayList<>();
for (MultipartFile f : file){
// 把图片存入 oos 返回路径
StringBuffer dir = new StringBuffer(FilePath.LogFilePath);
dir.append(vo.getLogAcceptId());
hdfsTemplate.saveFile(dir.toString(),f.getOriginalFilename(),f.getInputStream(),f.getSize(), (short) 2);
listUrl.add(dir.toString()+"/"+f.getOriginalFilename());
}
dto.setLocationUrls(listUrl);
DeviceInfoDto deviceInfoDto = deviceClient.queryDeviceByImei(dto.getImei());
dto.setDeviceId(deviceInfoDto.getDeviceId());
logFileClient.wechatUploadLog(dto);
......@@ -62,24 +66,18 @@ public class LogFlieController {
}
@PostMapping("/logfile/DeviceLogFileUpload")
@ResponseBody
public R uploadLogFile(DeviceLogFileVo vo, MultipartFile file) throws IOException {
DeviceLogFileDto dto = new DeviceLogFileDto();
BeanUtils.copyProperties(vo, dto);
// 把图片存入oos 返回路径
// dto.setLogfileUrl()
StringBuffer dir = new StringBuffer(FilePath.LogFilePath);
dir.append(vo.getLogAcceptId());
hdfsTemplate.saveFile(dir.toString(),file.getOriginalFilename(),file.getInputStream(),file.getSize(), (short) 2);
dto.setLogfileUrl(dir.toString()+"/"+file.getOriginalFilename());
// 1. 读取系统时间
Calendar calendar = Calendar.getInstance();
Date time = calendar.getTime();
// 2. 格式化系统时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String fileName = format.format(time);
dir.append(fileName);
hdfsTemplate.saveFile(dir.toString(),file.getName(),file.getInputStream(),file.getSize(), (short) 2);
DeviceInfoDto deviceInfoDto = deviceClient.queryDeviceByImei(dto.getImei());
dto.setDeviceId(deviceInfoDto.getDeviceId());
logFileClient.uploadLogFile(dto);
......
......@@ -50,13 +50,13 @@ public class WechatController {
httpServletRequest.getServerName() + ":" +
httpServletRequest.getServerPort()+
"/wechat/wechatDownload/"+fileName+"/"
+file.getOriginalFilename();
+file.getSize()+"/"+file.getOriginalFilename();
return R.ok().put("data",sufUrl);
}
@RequestMapping("/wechatDownload/{dir}/{fileName}")
@RequestMapping("/wechatDownload/{dir}/{fileSize}/{fileName}")
public void download(@PathVariable("dir") String dir, @PathVariable("fileName") String fileName,
HttpServletResponse response) throws IOException {
@PathVariable("fileSize") String fileSize, HttpServletResponse response) throws IOException {
StringBuffer dirPath = new StringBuffer(FilePath.wechatFilePath);
dirPath.append(dir);
InputStream inputStream = hdfsTemplate.openFile(dirPath.toString(), fileName);
......@@ -68,11 +68,12 @@ public class WechatController {
byte[] bytes = new byte[1024];
int i = 0;
while ((i = inputStream.read(bytes)) != -1) {
outputStream.write(bytes,0, i);
long total = Long.valueOf(fileSize);
while (total>0) {
inputStream.read(bytes);
outputStream.write(bytes,0, total>1024?1024: (int) total);
outputStream.flush();
total-=1024;
}
outputStream.close();
......
spring:
profiles:
active: prod
active: dev
application:
name: cneeds-server-datashow
server:
......
package com.mx.cneeds.server.logupload.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mx.cneeds.server.entity.DeviceLogmediaEntity;
import java.util.List;
public interface DeviceLogMediaService extends IService<DeviceLogmediaEntity> {
void savewechatMedia(Long logId, List<String> urls);
}
......@@ -15,7 +15,7 @@ public interface DeviceLogService extends IService<DeviceLogEntity> {
void changeStatus(Long logId);
void wechatUploadLog(DeviceLogEntity deviceLogEntity);
Long wechatUploadLog(DeviceLogEntity deviceLogEntity);
void deviceUploadLogFile(DeviceLogEntity deviceLogEntity);
......
package com.mx.cneeds.server.logupload.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mx.cneeds.server.dao.DeviceLogmediaDao;
import com.mx.cneeds.server.entity.DeviceLogEntity;
import com.mx.cneeds.server.entity.DeviceLogmediaEntity;
import com.mx.cneeds.server.logupload.service.DeviceLogMediaService;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* @ClassName DeviceLogMediaServiceImpl
* @Author zzrdark
* @Date 2020-04-23 17:19
* @Description TODO
**/
@Service
public class DeviceLogMediaServiceImpl extends ServiceImpl<DeviceLogmediaDao, DeviceLogmediaEntity> implements DeviceLogMediaService {
@Override
public void savewechatMedia(Long logId, List<String> urls){
List<DeviceLogmediaEntity> deviceLogmediaEntities = new LinkedList<DeviceLogmediaEntity>();
for (String url:urls){
DeviceLogmediaEntity deviceLogmediaEntity = new DeviceLogmediaEntity();
deviceLogmediaEntity.setLocationUrl(url);
deviceLogmediaEntity.setLogId(logId);
deviceLogmediaEntity.setType(url.substring(url.indexOf(".")));
deviceLogmediaEntities.add(deviceLogmediaEntity);
}
saveBatch(deviceLogmediaEntities);
}
}
......@@ -14,6 +14,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
......@@ -54,7 +56,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogDao, DeviceLogEnt
}
@Override
public void wechatUploadLog(DeviceLogEntity deviceLogEntity){
public Long wechatUploadLog(DeviceLogEntity deviceLogEntity){
DeviceLogEntity logEntity = queryOneBylogAcceptId(deviceLogEntity.getLogAcceptId());
if(logEntity != null){
getBaseMapper().update(deviceLogEntity,
......@@ -62,9 +64,14 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogDao, DeviceLogEnt
.eq("log_accept_id", deviceLogEntity.getLogAcceptId()));
}else {
getBaseMapper().insert(deviceLogEntity);
logEntity = queryOneBylogAcceptId(deviceLogEntity.getLogAcceptId());
}
return logEntity.getLogId();
}
@Override
public void deviceUploadLogFile(DeviceLogEntity deviceLogEntity){
DeviceLogEntity logEntity = queryOneBylogAcceptId(deviceLogEntity.getLogAcceptId());
......
......@@ -6,6 +6,7 @@ import com.mx.cneeds.common.dto.WechatDeviceLogDto;
import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.server.entity.DeviceLogEntity;
import com.mx.cneeds.server.logupload.service.DeviceLogMediaService;
import com.mx.cneeds.server.logupload.service.DeviceLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -30,9 +31,12 @@ public class LogUploadController {
@Autowired
private DeviceLogService deviceLogService;
@Autowired
private DeviceLogMediaService deviceLogMediaService;
@RequestMapping("/wechatUploadLog")
public void wechatUploadLog(WechatDeviceLogDto dto){
public void wechatUploadLog(@RequestBody WechatDeviceLogDto dto){
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
......@@ -41,8 +45,11 @@ public class LogUploadController {
deviceLogEntity.setLogName(dto.getBugTitle());
deviceLogEntity.setRepetitionProbability(dto.getProbability());
deviceLogEntity.setRepetitionSteps(dto.getSteps());
deviceLogService.wechatUploadLog(deviceLogEntity);
Long logId = deviceLogService.wechatUploadLog(deviceLogEntity);
if (dto.getLocationUrls()!=null && dto.getLocationUrls().size() != 0){
deviceLogMediaService.savewechatMedia(logId, dto.getLocationUrls());
}
}
......
spring:
profiles:
active: prod
active: dev
application:
name: cneeds-server-logupload
......
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 to comment