|
@@ -1,17 +1,24 @@
|
|
|
package com.fdkankan.fusion.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
|
+import com.fdkankan.fusion.common.PageInfo;
|
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.common.util.DateUtils;
|
|
|
+import com.fdkankan.fusion.common.util.FileMd5Util;
|
|
|
import com.fdkankan.fusion.common.util.ShellUtil;
|
|
|
import com.fdkankan.fusion.common.util.UploadToOssUtil;
|
|
|
import com.fdkankan.fusion.entity.CameraVersion;
|
|
|
+import com.fdkankan.fusion.entity.TmUser;
|
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import com.fdkankan.fusion.mapper.ICameraVersionMapper;
|
|
|
+import com.fdkankan.fusion.request.CameraVersionParam;
|
|
|
+import com.fdkankan.fusion.response.CameraVersionVo;
|
|
|
import com.fdkankan.fusion.service.ICameraVersionService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.fusion.service.ITmUserService;
|
|
@@ -43,12 +50,10 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
|
|
|
|
|
|
public static String DIR_NAME = "camera_version/";
|
|
|
|
|
|
- @Value("${fyun.host:https://4dkk.4dage.com/}")
|
|
|
+ @Value("${upload.query-path}")
|
|
|
private String ossUrlPrefix;
|
|
|
@Autowired
|
|
|
- private UploadToOssUtil uploadToOssUtil;
|
|
|
- @Autowired
|
|
|
- ITmUserService sysUserService;
|
|
|
+ ITmUserService tmUserService;
|
|
|
|
|
|
@Override
|
|
|
public void addAndUpload(MultipartFile file, String version, String description, String minVersion, Integer type) {
|
|
@@ -59,52 +64,60 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
|
|
|
if (!file.isEmpty()&& file.getSize() <= 0) {
|
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR);
|
|
|
}
|
|
|
- // 文件名全名
|
|
|
- String fullFileName = file.getOriginalFilename();
|
|
|
- String resourcePath = FilePath.LOCAL_BASE_PATH ;
|
|
|
- log.info("resourcePath: {}", resourcePath);
|
|
|
- // 创建目录
|
|
|
- String dirPath = resourcePath + DIR_NAME;
|
|
|
- FileUtils.createDir(dirPath);
|
|
|
- // 拼接唯一文件名
|
|
|
- String fileName = DateUtil.dateStr() + fullFileName;
|
|
|
- // 文件保存路径
|
|
|
- String filePath = dirPath + DateUtil.dateStr() + fullFileName;
|
|
|
- // 写文件到本地
|
|
|
- File file1 = new File(filePath);
|
|
|
- file.transferTo(file1);
|
|
|
-
|
|
|
- // 添加对象信息
|
|
|
+ try {
|
|
|
+ // 文件名全名
|
|
|
+ String fullFileName = file.getOriginalFilename();
|
|
|
+ String resourcePath = FilePath.LOCAL_BASE_PATH ;
|
|
|
+ log.info("resourcePath: {}", resourcePath);
|
|
|
+ // 创建目录
|
|
|
+ String dirPath = resourcePath + DIR_NAME;
|
|
|
+ FileUtil.mkdir(dirPath);
|
|
|
+ // 拼接唯一文件名
|
|
|
+ String fileName = DateUtils.dateStr() + fullFileName;
|
|
|
+ // 文件保存路径
|
|
|
+ String filePath = dirPath + DateUtils.dateStr() + fullFileName;
|
|
|
+ // 写文件到本地
|
|
|
+ File file1 = new File(filePath);
|
|
|
+ file.transferTo(file1);
|
|
|
+
|
|
|
+ // 添加对象信息
|
|
|
// switch (type){
|
|
|
// case 1: type = 1;break;
|
|
|
// case 2: type = 9;break;
|
|
|
// case 3: type = 10;break;
|
|
|
// default: throw new BusinessException(ResultCode.CAMERA_TYPE_ERROR);
|
|
|
// }
|
|
|
- List<CameraVersion> cameraVersions = this.getByVersion(version,type);
|
|
|
- if(cameraVersions != null && cameraVersions.size() >0){
|
|
|
- throw new BusinessException(ResultCode.VISION_EXIST.code(),ResultCode.VISION_EXIST.message());
|
|
|
+ List<CameraVersion> cameraVersions = this.getByVersion(version,type);
|
|
|
+ if(cameraVersions != null && cameraVersions.size() >0){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_VERSION_EXIT);
|
|
|
+ }
|
|
|
+ log.info("filePath: {}", filePath);
|
|
|
+ // 上传到阿里云sso
|
|
|
+ ShellUtil.yunUpload(filePath,DIR_NAME + fileName);
|
|
|
+ log.info("upload success");
|
|
|
+ String url = ossUrlPrefix + DIR_NAME + fileName;
|
|
|
+ log.info("upload url: {}" + url);
|
|
|
+
|
|
|
+ CameraVersion versionEntity = new CameraVersion();
|
|
|
+ versionEntity.setName(fileName);
|
|
|
+ versionEntity.setFileUrl(url);
|
|
|
+ versionEntity.setVersion(version);
|
|
|
+ versionEntity.setDescription(description);
|
|
|
+ versionEntity.setType(type);
|
|
|
+ versionEntity.setMinVersion(minVersion);
|
|
|
+ versionEntity.setStatus("I");
|
|
|
+ versionEntity.setFileMd5(FileMd5Util.getFileMD5(new File(filePath)));
|
|
|
+ versionEntity.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ this.save(versionEntity);
|
|
|
+ // 删除本地文件
|
|
|
+ FileUtil.del(filePath);
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }finally {
|
|
|
+
|
|
|
}
|
|
|
- log.info("filePath: {}", filePath);
|
|
|
- // 上传到阿里云sso
|
|
|
- ShellUtil.yunUpload(filePath,DIR_NAME + fileName);
|
|
|
- log.info("upload success");
|
|
|
- String url = ossUrlPrefix + DIR_NAME + fileName;
|
|
|
- log.info("upload url: {}" + url);
|
|
|
-
|
|
|
- CameraVersion versionEntity = new CameraVersion();
|
|
|
- versionEntity.setName(fileName);
|
|
|
- versionEntity.setFileUrl(url);
|
|
|
- versionEntity.setVersion(version);
|
|
|
- versionEntity.setDescription(description);
|
|
|
- versionEntity.setType(type);
|
|
|
- versionEntity.setMinVersion(minVersion);
|
|
|
- versionEntity.setStatus("I");
|
|
|
- versionEntity.setFileMd5(FileMd5Util.getFileMD5(new File(filePath)));
|
|
|
- versionEntity.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
- this.save(versionEntity);
|
|
|
- // 删除本地文件
|
|
|
- FileUtils.deleteFile(filePath);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private List<CameraVersion> getByVersion(String version,Integer type) {
|
|
@@ -136,7 +149,7 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
|
|
|
CameraVersionVo vo = new CameraVersionVo();
|
|
|
BeanUtils.copyProperties(record,vo);
|
|
|
if(record.getSysUserId() !=null){
|
|
|
- SysUser user = sysUserService.getById(record.getSysUserId());
|
|
|
+ TmUser user = tmUserService.getById(record.getSysUserId());
|
|
|
if(user != null){
|
|
|
vo.setCreateName(user.getNickName());
|
|
|
}
|
|
@@ -158,13 +171,13 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
|
|
|
}
|
|
|
CameraVersion cameraVersion = this.getById(param.getId());
|
|
|
if(cameraVersion == null){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_VERSION_NOT_EXIST);
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_VERSION_NOTEXIT);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(param.getStatus()) && !param.getStatus().equals(cameraVersion.getStatus())){
|
|
|
if(StringUtils.isBlank(param.getStatus()) || param.getType() == null){
|
|
|
throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
- if (!ValidationUtils.validateRecStatus(param.getStatus())) {
|
|
|
+ if (!validateRecStatus(param.getStatus())) {
|
|
|
throw new BusinessException(ResultCode.CAMERA_VERSION_STATUS_ERROR);
|
|
|
}
|
|
|
// 仅有有一台相机是活动状态
|
|
@@ -181,4 +194,12 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
|
|
|
}
|
|
|
this.saveOrUpdate(param);
|
|
|
}
|
|
|
+
|
|
|
+ public static boolean validateRecStatus(String str) {
|
|
|
+ if (StringUtils.isEmpty(str)) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ } else {
|
|
|
+ return !"A".equals(str) && !"I".equals(str) ? Boolean.FALSE : Boolean.TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|