|
@@ -3,22 +3,36 @@ package com.diagbot.facade;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.dto.FileDTO;
|
|
|
import com.diagbot.entity.MrqcToken;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.UploadService;
|
|
|
import com.diagbot.service.impl.MrqcTokenServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.RSAEncrypt;
|
|
|
import com.diagbot.vo.MrqcTokenDeleteVO;
|
|
|
import com.diagbot.vo.MrqcTokenIndexVO;
|
|
|
import com.diagbot.vo.MrqcTokenPageVO;
|
|
|
import com.diagbot.vo.MrqcTokenVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.Date;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@Component
|
|
|
public class MrqcTokenFacade extends MrqcTokenServiceImpl {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ UploadService uploadService;
|
|
|
+
|
|
|
/**
|
|
|
* token保存
|
|
|
*
|
|
@@ -28,16 +42,61 @@ public class MrqcTokenFacade extends MrqcTokenServiceImpl {
|
|
|
Date date = DateUtil.now();
|
|
|
MrqcToken mrqcToken = new MrqcToken();
|
|
|
BeanUtil.copyProperties(mrqcTokenVO, mrqcToken);
|
|
|
- // id为空表示新增
|
|
|
+ // 重复性校验
|
|
|
+ int num = this.count(new QueryWrapper<MrqcToken>()
|
|
|
+ .eq("ip", mrqcTokenVO.getIp())
|
|
|
+ .eq("cpu", mrqcTokenVO.getCpu())
|
|
|
+ .eq("server", mrqcTokenVO.getServer())
|
|
|
+ .eq("hospital", mrqcTokenVO.getHospital())
|
|
|
+ .eq("mainboard", mrqcTokenVO.getMainboard())
|
|
|
+ .eq("disk", mrqcTokenVO.getDisk())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .ne(mrqcTokenVO.getId() != null, "id", mrqcTokenVO.getId())
|
|
|
+ );
|
|
|
+ if (num > 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前token信息已存在");
|
|
|
+ }
|
|
|
+ // id为空表示新增,只有新增时才生成loginKey
|
|
|
+ String uuid = "";
|
|
|
if (mrqcTokenVO.getId() == null) {
|
|
|
mrqcToken.setGmtCreate(date);
|
|
|
+ uuid = UUID.randomUUID().toString();
|
|
|
+ mrqcToken.setLoginKey(uuid); // 生成登录获取token需要的key
|
|
|
}
|
|
|
mrqcToken.setGmtModified(date);
|
|
|
mrqcToken.setModifier(mrqcTokenVO.getCreator());
|
|
|
+
|
|
|
+ // 创建文件
|
|
|
+ FileDTO fileDTO = null;
|
|
|
+ try {
|
|
|
+ MultipartFile file = fileToMultipartFile(
|
|
|
+ RSAEncrypt.encrypt(mrqcTokenVO.getIp())
|
|
|
+ + System.getProperty("line.separator")
|
|
|
+ + RSAEncrypt.encrypt(mrqcTokenVO.getCpu()),
|
|
|
+ "sys.proterties");
|
|
|
+ fileDTO = uploadService.singleFileUpload(file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "文件上传失败!");
|
|
|
+ }
|
|
|
+ mrqcToken.setUrl(fileDTO.getUrl());
|
|
|
this.saveOrUpdate(mrqcToken);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param content 文件内容
|
|
|
+ * @param fileName
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public MultipartFile fileToMultipartFile(String content, String fileName) throws Exception {
|
|
|
+ InputStream inputstream = new ByteArrayInputStream(content.getBytes());
|
|
|
+ MultipartFile toMultipartFile = new MockMultipartFile(fileName, fileName, "text/plain", inputstream);
|
|
|
+ return toMultipartFile;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* token删除
|
|
|
*
|
|
@@ -67,7 +126,11 @@ public class MrqcTokenFacade extends MrqcTokenServiceImpl {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取明细
|
|
|
+ * @param mrqcTokenIndexVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public MrqcToken getById(MrqcTokenIndexVO mrqcTokenIndexVO) {
|
|
|
return this.getOne(new QueryWrapper<MrqcToken>()
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())
|