Commit 07ddf46d by zzrdark

1.日志上传模块

2.修改数据库
parent c2410dad
...@@ -49,7 +49,7 @@ CREATE TABLE `device_log` ( ...@@ -49,7 +49,7 @@ CREATE TABLE `device_log` (
`create_time` datetime(0) DEFAULT NULL COMMENT '创建时间', `create_time` datetime(0) DEFAULT NULL COMMENT '创建时间',
`device_id` bigint(20) DEFAULT NULL COMMENT '设备id', `device_id` bigint(20) DEFAULT NULL COMMENT '设备id',
`status` int(11) DEFAULT NULL COMMENT '情况-1不可用 0未处理,1已查看', `status` int(11) DEFAULT NULL COMMENT '情况-1不可用 0未处理,1已查看',
`cteate_username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人名字', `create_username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人名字',
`user_id` bigint(20) DEFAULT NULL, `user_id` bigint(20) DEFAULT NULL,
`repetition_steps` varchar(300) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '复现步骤', `repetition_steps` varchar(300) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '复现步骤',
`logfile_url` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '日志文件存放路径', `logfile_url` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '日志文件存放路径',
......
...@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mx.cneeds.server.entity.DeviceInfoEntity; import com.mx.cneeds.server.entity.DeviceInfoEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/** /**
* 设备信息 * 设备信息
* *
...@@ -13,5 +16,6 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -13,5 +16,6 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface DeviceInfoDao extends BaseMapper<DeviceInfoEntity> { public interface DeviceInfoDao extends BaseMapper<DeviceInfoEntity> {
List<DeviceInfoEntity> queryDeviceByIds(Collection<Long> ids);
} }
...@@ -43,7 +43,7 @@ public class DeviceLogEntity implements Serializable { ...@@ -43,7 +43,7 @@ public class DeviceLogEntity implements Serializable {
/** /**
* 创建人名字 * 创建人名字
*/ */
private String cteateUsername; private String createUsername;
/** /**
* *
*/ */
......
...@@ -17,7 +17,16 @@ ...@@ -17,7 +17,16 @@
<result property="channelNums" column="channel_nums"/> <result property="channelNums" column="channel_nums"/>
<result property="channelNumsMessage" column="channel_nums_message"/> <result property="channelNumsMessage" column="channel_nums_message"/>
<result property="channelRules" column="channel_rules"/> <result property="channelRules" column="channel_rules"/>
<result property="seriesNum" column="series_num"/>
</resultMap> </resultMap>
<select id="queryDeviceByIds" parameterType="collection" resultMap="deviceInfoMap">
select d.*,p.series_num from device_info as d, product_series as p
where d.series_id = p.series_id
and d.device_id in
<foreach item="deviceId" collection="collection" open="(" separator="," close=")">
#{deviceId}
</foreach>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="deviceId" column="device_id"/> <result property="deviceId" column="device_id"/>
<result property="status" column="status"/> <result property="status" column="status"/>
<result property="cteateUsername" column="cteate_username"/> <result property="createUsername" column="create_username"/>
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="repetitionSteps" column="repetition_steps"/> <result property="repetitionSteps" column="repetition_steps"/>
<result property="logfileUrl" column="logfile_url"/> <result property="logfileUrl" column="logfile_url"/>
......
package com.mx.cneeds.common.dto;
import lombok.Data;
import java.util.Date;
/**
* @ClassName DeviceLogDto
* @Author zzrdark
* @Date 2020-04-01 17:07
* @Description TODO
**/
@Data
public class DeviceLogDto {
/**
* logId
*/
private Long logId;
/**
* bug名字
*/
private String logName;
/**
* 创建时间
*/
private Date createTime;
/**
* 设备id
*/
private Long deviceId;
/**
* 情况-1不可用 0未处理,1已查看
*/
private Integer status;
/**
* 创建人名字
*/
private String createUsername;
/**
*
*/
private Long userId;
/**
* 复现步骤
*/
private String repetitionSteps;
/**
* 日志文件存放路径
*/
private String logfileUrl;
/**
* 日志文件大小
*/
private Long logfileSize;
/**
* 日志文件上传状态,-1,失败,0上传中,1完成
*/
private Integer logfileStatus;
/**
* 设备版本
*/
private String deviceVersion;
/**
* 产品系列号
*/
private String seriesNum;
}
...@@ -67,6 +67,11 @@ ...@@ -67,6 +67,11 @@
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version> <version>${swagger.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.mx.cneeds.common.converter; package com.mx.cneeds.common.converter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.xml.bind.DatatypeConverter; import javax.xml.bind.DatatypeConverter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -85,8 +88,16 @@ public class RequestParamterConverter { ...@@ -85,8 +88,16 @@ public class RequestParamterConverter {
return String.valueOf(chars); return String.valueOf(chars);
} }
public static Gson getGson(){
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
return gson;
}
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(authorizationConverter("clientapp", "112233")); // System.out.println(authorizationConverter("clientapp", "112233"));
System.out.println(toLine("userName")); System.out.println(toLine("userName"));
} }
} }
...@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @ClassName DeviceClient * @ClassName DeviceClient
...@@ -51,6 +52,9 @@ public interface DeviceClient { ...@@ -51,6 +52,9 @@ public interface DeviceClient {
@PostMapping("/device/info/infoByImei") @PostMapping("/device/info/infoByImei")
DeviceInfoDto queryDeviceByImei(@RequestParam String imei); DeviceInfoDto queryDeviceByImei(@RequestParam String imei);
@PostMapping("/device/info/infoByIds")
List<DeviceInfoDto> queryDeviceByIds(@RequestBody Set<Long> ids);
@PostMapping("/device/info/importDevice") @PostMapping("/device/info/importDevice")
void importDevice(@RequestBody DevicesDto dto); void importDevice(@RequestBody DevicesDto dto);
......
package com.mx.cneeds.server.datashow.client;
import com.mx.cneeds.common.dto.PageDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @ClassName LogFileCleint
* @Author zzrdark
* @Date 2020-04-01 14:53
* @Description TODO
**/
@FeignClient(name = "CNEEDS-SERVER-LOGUPLOAD")
public interface LogFileClient {
@PostMapping("/log/upload/list")
PageDto logFileList(@RequestParam Integer page,
@RequestParam("limit") Integer pageSize,
@RequestParam("sidx") String orderField,
@RequestParam("order") String order);
@PostMapping("/log/upload/delete")
void deleteLogFile(@RequestBody List<Long> ids);
}
package com.mx.cneeds.server.datashow.web.device;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mx.cneeds.common.converter.RequestParamterConverter;
import com.mx.cneeds.common.dto.DeviceInfoDto;
import com.mx.cneeds.common.dto.DeviceLogDto;
import com.mx.cneeds.common.dto.PageDto;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.server.datashow.client.DeviceClient;
import com.mx.cneeds.server.datashow.client.LogFileClient;
import lombok.extern.slf4j.Slf4j;
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 java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @ClassName LogFileController
* @Author zzrdark
* @Date 2020-04-01 15:14
* @Description TODO
**/
@RestController
@Slf4j
@RequestMapping("/remotelog")
public class LogFileController {
@Autowired
private LogFileClient logFileClient;
@Autowired
private DeviceClient deviceClient;
@PostMapping("/logfile/list")
public R logFileList(@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer pageSize,
@RequestParam(required = false) String sort){
String orderField = null;
String order = null;
if (page==null || page==0){
page = new Integer(1);
}
if (pageSize==null || pageSize==0){
pageSize = new Integer(10);
}
if (StringUtils.isNotEmpty(sort) && StringUtils.isNotBlank(sort.trim())){
if (sort.contains("+")){
order = new String("asc");
}
if (sort.contains("-")){
order = new String("desc");
}
orderField = sort.substring(1);
orderField = RequestParamterConverter.toLine(orderField);
}
PageDto pageDto = logFileClient.logFileList(page,pageSize,orderField,order);
Gson gson = RequestParamterConverter.getGson();
List<DeviceLogDto> deviceLogDtos = new ArrayList<>();
for (Object deviceLogDto: pageDto.getList() ) {
String deviceLogDtoStr = gson.toJson(deviceLogDto);
DeviceLogDto dto = gson.fromJson(deviceLogDtoStr,DeviceLogDto.class);
deviceLogDtos.add(dto);
}
Set<Long> deviceSet = new HashSet<>();
deviceLogDtos.forEach(deviceLogDto -> {
deviceSet.add(deviceLogDto.getDeviceId());
});
List<DeviceInfoDto> deviceInfoDtos = deviceClient.queryDeviceByIds(deviceSet);
deviceLogDtos.forEach(deviceLogDto -> {
deviceInfoDtos.forEach(deviceInfoDto -> {
if (deviceLogDto.getDeviceId().equals(deviceInfoDto.getDeviceId()) ){
deviceLogDto.setSeriesNum(deviceInfoDto.getSeriesNum());
deviceLogDto.setDeviceVersion(deviceInfoDto.getDeviceVersion());
}
});
});
pageDto.setList(deviceLogDtos);
return new R().put("data",pageDto);
}
@PostMapping("/logfile/delete")
public R deleteLogFile(@RequestParam(value = "ids",required = false) List<Long> ids){
logFileClient.deleteLogFile(ids);
return R.ok();
}
}
...@@ -6,6 +6,7 @@ import com.mx.cneeds.server.entity.DeviceInfoEntity; ...@@ -6,6 +6,7 @@ import com.mx.cneeds.server.entity.DeviceInfoEntity;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* 设备信息 * 设备信息
...@@ -21,5 +22,7 @@ public interface DeviceInfoService extends IService<DeviceInfoEntity> { ...@@ -21,5 +22,7 @@ public interface DeviceInfoService extends IService<DeviceInfoEntity> {
void updateBatchByImei(List<DeviceInfoEntity> deviceInfoEntityList); void updateBatchByImei(List<DeviceInfoEntity> deviceInfoEntityList);
DeviceInfoEntity queryDeviceByImei(String imei); DeviceInfoEntity queryDeviceByImei(String imei);
List<DeviceInfoEntity> queryDeviceByIds(Set<Long> ids);
} }
...@@ -67,4 +67,11 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfo ...@@ -67,4 +67,11 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfo
return deviceInfoEntity; return deviceInfoEntity;
} }
@Override
public List<DeviceInfoEntity> queryDeviceByIds(Set<Long> ids){
List<DeviceInfoEntity> deviceInfoEntities = getBaseMapper().queryDeviceByIds(ids);
return deviceInfoEntities;
}
} }
...@@ -64,6 +64,19 @@ public class DeviceInfoController { ...@@ -64,6 +64,19 @@ public class DeviceInfoController {
return deviceInfoDto; return deviceInfoDto;
} }
@RequestMapping("/infoByIds")
public List<DeviceInfoDto> infoByIds(@RequestBody Set<Long> ids){
List<DeviceInfoEntity> deviceInfoEntitys = deviceInfoService.queryDeviceByIds(ids);
List<DeviceInfoDto> deviceInfoDtos = new ArrayList<>();
deviceInfoEntitys.forEach(deviceInfoEntity -> {
DeviceInfoDto deviceInfoDto = new DeviceInfoDto();
BeanUtils.copyProperties(deviceInfoEntity,deviceInfoDto);
deviceInfoDtos.add(deviceInfoDto);
});
return deviceInfoDtos;
}
/** /**
* 保存 * 保存
*/ */
......
package com.mx.cneeds.server.logupload; package com.mx.cneeds.server.logupload;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* @ClassName LogUploadApplication * @ClassName LogUploadApplication
...@@ -8,6 +10,8 @@ import org.springframework.boot.SpringApplication; ...@@ -8,6 +10,8 @@ import org.springframework.boot.SpringApplication;
* @Date 2020-03-03 20:59 * @Date 2020-03-03 20:59
* @Description TODO * @Description TODO
**/ **/
@SpringBootApplication
@MapperScan("com.mx.cneeds.server.dao")
public class LogUploadApplication { public class LogUploadApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(LogUploadApplication.class, args); SpringApplication.run(LogUploadApplication.class, args);
......
package com.mx.cneeds.server.logupload.config;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
@Bean
public ISqlInjector sqlInjector() {
return new LogicSqlInjector();
}
}
\ No newline at end of file
package com.mx.cneeds.server.logupload.web; package com.mx.cneeds.server.logupload.web;
import com.mx.cneeds.common.dto.DeviceLogDto;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R; import com.mx.cneeds.common.result.R;
import com.mx.cneeds.server.logupload.service.DeviceLogService; import com.mx.cneeds.server.logupload.service.DeviceLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.File; import java.io.File;
import java.util.List; import java.util.*;
import java.util.Map;
/** /**
* @ClassName LogUploadController * @ClassName LogUploadController
...@@ -19,7 +21,7 @@ import java.util.Map; ...@@ -19,7 +21,7 @@ import java.util.Map;
* @Date 2020-03-27 15:26 * @Date 2020-03-27 15:26
* @Description TODO * @Description TODO
**/ **/
@Controller @RestController
@RequestMapping("/log/upload") @RequestMapping("/log/upload")
public class LogUploadController { public class LogUploadController {
@Autowired @Autowired
...@@ -52,6 +54,13 @@ public class LogUploadController { ...@@ -52,6 +54,13 @@ public class LogUploadController {
@RequestMapping("/list") @RequestMapping("/list")
public PageUtils list(@RequestParam Map<String, Object> params){ public PageUtils list(@RequestParam Map<String, Object> params){
PageUtils page = deviceLogService.queryPage(params); PageUtils page = deviceLogService.queryPage(params);
List<DeviceLogDto> list =new ArrayList<>();
page.getList().forEach(deivceLogEntity -> {
DeviceLogDto deviceLogDto = new DeviceLogDto();
BeanUtils.copyProperties(deivceLogEntity, deviceLogDto);
list.add(deviceLogDto);
});
page.setList(list);
return page; return page;
} }
......
...@@ -50,7 +50,7 @@ eureka: ...@@ -50,7 +50,7 @@ eureka:
defaultZone: http://192.168.2.244:8761/eureka/ defaultZone: http://192.168.2.244:8761/eureka/
instance: instance:
prefer-ip-address: true prefer-ip-address: true
ip-address: 192.168.2.244 # ip-address: 192.168.2.244
......
...@@ -62,7 +62,7 @@ eureka: ...@@ -62,7 +62,7 @@ eureka:
defaultZone: http://192.168.2.244:8761/eureka/ defaultZone: http://192.168.2.244:8761/eureka/
instance: instance:
prefer-ip-address: true prefer-ip-address: true
# ip-address: 192.168.2.244 ip-address: 192.168.2.244
......
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