提交 7c55db22 authored 作者: 孙洁清's avatar 孙洁清

输入输出查询接口

测评报告分页条件接口 删除报告接口 新增接口todo...
上级 962b79f9
package com.zjty.autotest; package com.zjty.autotest;
import com.zjty.autotest.util.IdWorker;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
public class AutotestApplication { public class AutotestApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AutotestApplication.class, args); SpringApplication.run(AutotestApplication.class, args);
} }
@Bean
public IdWorker idWorkker(){
return new IdWorker(1, 1);
}
} }
package com.zjty.autotest.controller;
import com.zjty.autotest.pojo.sjq.AutoResultSet;
import com.zjty.autotest.pojo.sjq.TestChannel;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.PageResult;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.AutoResultSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("/auto")
@Api(value = "自动测评管理接口",description = "自动测评管理接口,提供页面的增、删、改、查")
public class AutoResultSetController {
@Autowired
private AutoResultSetService autoResultSetService;
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
* @param page 页码
* @param size 页大小
* @return 分页结果
*/
@ApiOperation("根据条件分页排序查询")
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public ResponseResult findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<AutoResultSet> pageList = autoResultSetService.findSearch(searchMap, page, size);
return ResponseResult.okResult( new PageResult<AutoResultSet>(pageList.getTotalElements(), pageList.getContent()) );
}
@ApiOperation("根据id删除")
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public ResponseResult delete(@PathVariable String id ){
return autoResultSetService.deleteByid(id);
}
@ApiOperation("新增")
@RequestMapping(method=RequestMethod.POST)
public ResponseResult add(@RequestBody TestChannel testChannel ){
return autoResultSetService.addResultSet(testChannel);
}
}
package com.zjty.autotest.controller;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.TestReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* 控制器层
* @author Administrator
*
*/
@RestController
@CrossOrigin
@RequestMapping("/report")
@Api(value = "报告管理接口",description = "提供输入输出查询接口")
public class TestReportController {
@Autowired
private TestReportService testReportService;
/**
* 根据ID查询
* @param id ID
* @return*/
@ApiOperation("根据AutoResultId查询输入")
@RequestMapping(value="/in/{id}",method= RequestMethod.GET)
public ResponseResult findByIdInData(@PathVariable String id){
return testReportService.findByIdInData(id);
}
/**
* 根据ID查询
* @param id ID
* @return*/
@ApiOperation("根据AutoResultId查询输出")
@RequestMapping(value="/out/{id}",method= RequestMethod.GET)
public ResponseResult findByIdOutData(@PathVariable String id){
return testReportService.findByIdOutData(id);
}
}
package com.zjty.autotest.dao;
import com.zjty.autotest.pojo.sjq.AutoResultSet;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface AutoResultSetDao extends JpaRepository<AutoResultSet,String>, JpaSpecificationExecutor<AutoResultSet> {
}
package com.zjty.autotest.dao;
import com.zjty.autotest.pojo.sjq.TestReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
* 数据访问接口
* @author Administrator
*
*/
public interface TestReportDao extends JpaRepository<TestReport,String>, JpaSpecificationExecutor<TestReport> {
@Query(value = "SELECT input_report FROM test_report WHERE result_id = :resultId",nativeQuery = true)
String findByInResultId(String resultId);
@Query(value = "select out_report from test_report where result_id =:resultId",nativeQuery = true)
String findByOutResultId(String resultId);
@Modifying
int deleteByResultId(String resultId);
}
package com.zjty.autotest.pojo.sjq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel(description = "自动化评测报告管理类")
public class AutoResultSet {
@Id
@ApiModelProperty(value = "系统id")
private String id;
@ApiModelProperty(value = "系统名称")
private String projectName;
@ApiModelProperty(value = "用户名")
private String user;
@ApiModelProperty(value = "报告状态 0:正在生成 1:可以查看",example = "0")
private Integer status;
@ApiModelProperty(value = "记录创建时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ApiModelProperty(value = "记录修改时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package com.zjty.autotest.pojo.sjq;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel(description = "参数填写类")
public class RuleSet {
private String command;
private String target;
private String value;
private String des;
}
package com.zjty.autotest.pojo.sjq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "测试输入类")
public class TestChannel {
/**
* 主键
*/
private String id;
/**
* 用户名
*/
private String user;
/**
* 项目名称
*/
private String name;
/**
* 浏览器
*/
private String browser;
/**
* 测试入口地址
*/
private String url;
@ApiModelProperty(value = "上传代码路径地址")
private String codeUrl;
/**
* 参数填写
*/
private List<RuleSet> ruleSets;
}
package com.zjty.autotest.pojo.sjq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel(description = "自动化评测报告管理类")
public class TestReport{
@Id
private String id;
@ApiModelProperty(value = "AutoResultSetId")
private String resultId;
@ApiModelProperty(value = "输入内容")
@Column(columnDefinition = "TEXT")
private String inputReport;
@ApiModelProperty(value = "测试报告")
@Column(columnDefinition = "TEXT")
private String outReport;
}
package com.zjty.autotest.pojo.sjq.common;
public enum AppHttpCodeEnum {
// 成功段0
SUCCESS(200,"操作成功"),
// 登录段1~50
NEED_LOGIN(1,"需要登录后操作"),
LOGIN_PASSWORD_ERROR(2,"密码错误"),
// TOKEN50~100
TOKEN_INVALID(50,"无效的TOKEN"),
TOKEN_EXPIRE(51,"TOKEN已过期"),
TOKEN_REQUIRE(52,"TOKEN是必须的"),
// SIGN验签 100~120
SIGN_INVALID(100,"无效的SIGN"),
SIG_TIMEOUT(101,"SIGN已过期"),
// 参数错误 500~1000
PARAM_REQUIRE(500,"缺少参数"),
PARAM_INVALID(501,"无效参数"),
PARAM_IMAGE_FORMAT_ERROR(502,"图片格式有误"),
SERVER_ERROR(503,"服务器内部错误"),
SAVE_ERROR(504,"删除错误"),
// 数据错误 1000~2000
DATA_EXIST(1000,"数据已经存在"),
AP_USER_DATA_NOT_EXIST(1001,"ApUser数据不存在"),
DATA_NOT_EXIST(1002,"数据不存在"),
// 数据错误 3000~3500
NO_OPERATOR_AUTH(3000,"无权限操作");
int code;
String errorMessage;
AppHttpCodeEnum(int code, String errorMessage){
this.code = code;
this.errorMessage = errorMessage;
}
public int getCode() {
return code;
}
public String getErrorMessage() {
return errorMessage;
}
}
package com.zjty.autotest.pojo.sjq.common;
import java.util.List;
public class PageResult<T> {
private Long total;
private List<T> rows;
public PageResult(Long total, List<T> rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
package com.zjty.autotest.pojo.sjq.common;
import java.io.Serializable;
/**
* 通用的结果返回类
* @param <T>
*/
public class ResponseResult<T> implements Serializable {
private String host;
private Integer code;
private String errorMessage;
private T data;
public ResponseResult() {
this.code = 200;
}
public ResponseResult(Integer code, T data) {
this.code = code;
this.data = data;
}
public ResponseResult(Integer code, String msg, T data) {
this.code = code;
this.errorMessage = msg;
this.data = data;
}
public ResponseResult(Integer code, String msg) {
this.code = code;
this.errorMessage = msg;
}
public static ResponseResult errorResult(int code, String msg) {
ResponseResult result = new ResponseResult();
return result.error(code, msg);
}
public static ResponseResult okResult(int code, String msg) {
ResponseResult result = new ResponseResult();
return result.ok(code, null, msg);
}
public static ResponseResult okResult(Object data) {
ResponseResult result = setAppHttpCodeEnum(AppHttpCodeEnum.SUCCESS, AppHttpCodeEnum.SUCCESS.getErrorMessage());
if(data!=null) {
result.setData(data);
}
return result;
}
public static ResponseResult errorResult(AppHttpCodeEnum enums){
return setAppHttpCodeEnum(enums,enums.getErrorMessage());
}
public static ResponseResult errorResult(AppHttpCodeEnum enums, String errorMessage){
return setAppHttpCodeEnum(enums,errorMessage);
}
public static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums){
return okResult(enums.getCode(),enums.getErrorMessage());
}
private static ResponseResult setAppHttpCodeEnum(AppHttpCodeEnum enums, String errorMessage){
return okResult(enums.getCode(),errorMessage);
}
public ResponseResult<?> error(Integer code, String msg) {
this.code = code;
this.errorMessage = msg;
return this;
}
public ResponseResult<?> ok(Integer code, T data) {
this.code = code;
this.data = data;
return this;
}
public ResponseResult<?> ok(Integer code, T data, String msg) {
this.code = code;
this.data = data;
this.errorMessage = msg;
return this;
}
public ResponseResult<?> ok(T data) {
this.data = data;
return this;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
}
package com.zjty.autotest.service;
import com.zjty.autotest.pojo.sjq.AutoResultSet;
import com.zjty.autotest.pojo.sjq.TestChannel;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface AutoResultSetService {
/**
* 根据条件分页排序查询
*/
Page<AutoResultSet> findSearch(Map whereMap, int page, int size);
/**
* 根据id删除
*/
ResponseResult deleteByid(String id);
/**
* 新增
*/
ResponseResult addResultSet(TestChannel testChannel);
/**
* 上传前端源代码
*/
}
package com.zjty.autotest.service;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
public interface TestReportService{
ResponseResult deleteByResultId(String id);
/**
* 根据id查询输入
*/
ResponseResult findByIdInData(String resultId);
/**
* 根据id查询输出
*/
ResponseResult findByIdOutData(String resultId);
}
package com.zjty.autotest.service.impl;
import com.zjty.autotest.dao.AutoResultSetDao;
import com.zjty.autotest.pojo.sjq.AutoResultSet;
import com.zjty.autotest.pojo.sjq.TestChannel;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.AppHttpCodeEnum;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.AutoResultSetService;
import com.zjty.autotest.service.TestReportService;
import com.zjty.autotest.util.IdWorker;
import com.zjty.autotest.util.TimeUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class AutoResultSetServiceImpl implements AutoResultSetService {
@Autowired
private AutoResultSetDao autoResultSetDao;
@Autowired
private TestReportService testReportService;
@Autowired
private IdWorker idWorker;
@Override
public Page<AutoResultSet> findSearch(Map whereMap, int page, int size) {
Specification<AutoResultSet> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.Direction.DESC,"createTime");
return autoResultSetDao.findAll(specification, pageRequest);
}
/**
* 动态条件构建
* @param searchMap
* @return
*/
private Specification<AutoResultSet> createSpecification(Map searchMap) {
return new Specification<AutoResultSet>() {
@Override
public Predicate toPredicate(Root<AutoResultSet> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
if (searchMap.get("projectName") != null && !"".equals(searchMap.get("projectName"))) {
predicateList.add(cb.like(root.get("projectName").as(String.class), "%" + (String) searchMap.get("projectName") + "%"));
}
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
@Override
public ResponseResult deleteByid(String id) {
try {
autoResultSetDao.deleteById(id);
testReportService.deleteByResultId(id);
}catch (Exception e){
return ResponseResult.okResult(AppHttpCodeEnum.SAVE_ERROR);
}
return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
}
@Override
public ResponseResult addResultSet(TestChannel testChannel) {
AutoResultSet autoResultSet=new AutoResultSet();
autoResultSet.setId(idWorker.nextId()+"");
autoResultSet.setProjectName(testChannel.getName());
autoResultSet.setUser(testChannel.getUser());
autoResultSet.setCreateTime(new Date());
autoResultSet.setUpdateTime(new Date());
autoResultSet.setStatus(0);
autoResultSetDao.save(autoResultSet);
//将数据保存到队列
//定时去读取
//调用黄承天代码
//修改状态为1
//发送websocket
return null;
}
}
package com.zjty.autotest.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.zjty.autotest.dao.TestReportDao;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.AppHttpCodeEnum;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.TestReportService;
import com.zjty.autotest.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
/**
* 服务层
*
* @author Administrator
*
*/
@Service
public class TestReportServiceImpl implements TestReportService {
@Autowired
private TestReportDao testReportDao;
@Autowired
private IdWorker idWorker;
/**
* 查询全部列表
* @return
*/
public List<TestReport> findAll() {
return testReportDao.findAll();
}
/**
* 根据ID查询实体
* @param id
* @return
*/
public TestReport findById(String id) {
return testReportDao.findById(id).get();
}
/**
* 增加
* @param testReport
*/
public void add(TestReport testReport) {
testReport.setId( idWorker.nextId()+"" );
testReportDao.save(testReport);
}
/**
* 修改
* @param testReport
*/
public void update(TestReport testReport) {
testReportDao.save(testReport);
}
/**
* 删除
* @param resultId
*/
public ResponseResult deleteByResultId(String resultId) {
int i = testReportDao.deleteByResultId(resultId);
return ResponseResult.okResult(i);
}
@Override
public ResponseResult findByIdInData(String resultId) {
String in = testReportDao.findByInResultId(resultId);
if(StringUtils.isEmpty(in)){
return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
}
return ResponseResult.okResult(in);
}
@Override
public ResponseResult findByIdOutData(String resultId) {
String out = testReportDao.findByOutResultId(resultId);
if(StringUtils.isEmpty(out)){
return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
}
return ResponseResult.okResult(out);
}
}
package com.zjty.autotest.util;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
* <p>名称:IdWorker.java</p>
* <p>描述:分布式自增长ID</p>
* <pre>
* Twitter的 Snowflake JAVA实现方案
* </pre>
* 核心代码为其IdWorker这个类实现,其原理结构如下,我分别用一个0表示一位,用—分割开部分的作用:
* 1||0---0000000000 0000000000 0000000000 0000000000 0 --- 00000 ---00000 ---000000000000
* 在上面的字符串中,第一位为未使用(实际上也可作为long的符号位),接下来的41位为毫秒级时间,
* 然后5位datacenter标识位,5位机器ID(并不算标识符,实际是为线程标识),
* 然后12位该毫秒内的当前毫秒内的计数,加起来刚好64位,为一个Long型。
* 这样的好处是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由datacenter和机器ID作区分),
* 并且效率较高,经测试,snowflake每秒能够产生26万ID左右,完全满足需要。
* <p>
* 64位ID (42(毫秒)+5(机器ID)+5(业务编码)+12(重复累加))
*
* @author Polim
*/
public class IdWorker {
// 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
private final static long twepoch = 1288834974657L;
// 机器标识位数
private final static long workerIdBits = 5L;
// 数据中心标识位数
private final static long datacenterIdBits = 5L;
// 机器ID最大值
private final static long maxWorkerId = -1L ^ (-1L << workerIdBits);
// 数据中心ID最大值
private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
// 毫秒内自增位
private final static long sequenceBits = 12L;
// 机器ID偏左移12位
private final static long workerIdShift = sequenceBits;
// 数据中心ID左移17位
private final static long datacenterIdShift = sequenceBits + workerIdBits;
// 时间毫秒左移22位
private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
/* 上次生产id时间戳 */
private static long lastTimestamp = -1L;
// 0,并发控制
private long sequence = 0L;
private final long workerId;
// 数据标识id部分
private final long datacenterId;
public IdWorker(){
this.datacenterId = getDatacenterId(maxDatacenterId);
this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
}
/**
* @param workerId
* 工作机器ID
* @param datacenterId
* 序列号
*/
public IdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 获取下一个ID
*
* @return
*/
public synchronized long nextId() {
long timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
if (lastTimestamp == timestamp) {
// 当前毫秒内,则+1
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
// 当前毫秒内计数满了,则等待下一秒
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0L;
}
lastTimestamp = timestamp;
// ID偏移组合生成最终的ID,并返回ID
long nextId = ((timestamp - twepoch) << timestampLeftShift)
| (datacenterId << datacenterIdShift)
| (workerId << workerIdShift) | sequence;
return nextId;
}
private long tilNextMillis(final long lastTimestamp) {
long timestamp = this.timeGen();
while (timestamp <= lastTimestamp) {
timestamp = this.timeGen();
}
return timestamp;
}
private long timeGen() {
return System.currentTimeMillis();
}
/**
* <p>
* 获取 maxWorkerId
* </p>
*/
protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
StringBuffer mpid = new StringBuffer();
mpid.append(datacenterId);
String name = ManagementFactory.getRuntimeMXBean().getName();
if (!name.isEmpty()) {
/*
* GET jvmPid
*/
mpid.append(name.split("@")[0]);
}
/*
* MAC + PID 的 hashcode 获取16个低位
*/
return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
}
/**
* <p>
* 数据标识id部分
* </p>
*/
protected static long getDatacenterId(long maxDatacenterId) {
long id = 0L;
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
if (network == null) {
id = 1L;
} else {
byte[] mac = network.getHardwareAddress();
id = ((0x000000FF & (long) mac[mac.length - 1])
| (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
id = id % (maxDatacenterId + 1);
}
} catch (Exception e) {
System.out.println(" getDatacenterId: " + e.getMessage());
}
return id;
}
}
package com.zjty.autotest.util;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeUtil {
public static String getTime(){
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("当前时间:" + sdf.format(d));
return sdf.format(d);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论