lyhzzz 3 лет назад
Родитель
Сommit
9fcc45811c

+ 1 - 1
4dkankan-center-manage/src/main/java/com/fdkankan/manage/controller/CameraVersionController.java

@@ -32,7 +32,7 @@ public class CameraVersionController {
                          @RequestParam("version") String version,
                          @RequestParam("description") String description,
                          @RequestParam("minVersion") String minVersion,
-                         @RequestParam("type") String type) throws IOException {
+                         @RequestParam(value = "type",defaultValue = "1") Integer type) throws IOException {
         cameraVersionService.addAndUpload(file,version,description,minVersion,type);
         return ResultData.ok();
     }

+ 1 - 1
4dkankan-center-manage/src/main/java/com/fdkankan/manage/service/ICameraVersionService.java

@@ -18,7 +18,7 @@ import java.io.IOException;
  */
 public interface ICameraVersionService extends IService<CameraVersion> {
 
-    void addAndUpload(MultipartFile file, String version, String description, String minVersion, String type) throws IOException;
+    void addAndUpload(MultipartFile file, String version, String description, String minVersion, Integer type) throws IOException;
 
     PageInfo pageList(CameraVersionParam param);
 

+ 11 - 11
4dkankan-center-manage/src/main/java/com/fdkankan/manage/service/impl/CameraVersionServiceImpl.java

@@ -50,8 +50,7 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
     private UploadToOssUtil uploadToOssUtil;
 
     @Override
-    public void addAndUpload(MultipartFile file, String version, String description, String minVersion, String type) throws IOException {
-        String cameraType = StringUtils.isNotBlank(type) ? type : "1";
+    public void addAndUpload(MultipartFile file, String version, String description, String minVersion, Integer type) throws IOException {
         log.info("run upload");
         if (!file.isEmpty()&& file.getSize() <= 0) {
             throw new BusinessException(ErrorCode.FILE_NOT_EXIST);
@@ -87,7 +86,7 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
         versionEntity.setFileUrl(url);
         versionEntity.setVersion(version);
         versionEntity.setDescription(description);
-        versionEntity.setType(Integer.parseInt(cameraType));
+        versionEntity.setType(type);
         versionEntity.setMinVersion(minVersion);
         versionEntity.setStatus("I");
         versionEntity.setFileMd5(FileMd5Util.getFileMD5(new File(filePath)));
@@ -120,7 +119,7 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
         if(cameraVersion == null){
             throw new BusinessException(ErrorCode.NOT_RECORD);
         }
-        if(StringUtils.isNotBlank(param.getStatus())){
+        if(StringUtils.isNotBlank(param.getStatus()) && !param.getStatus().equals(cameraVersion.getStatus())){
             if(StringUtils.isBlank(param.getStatus()) || param.getType() == null){
                 throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
             }
@@ -129,14 +128,15 @@ public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper,
             }
             // 仅有有一台相机是活动状态
             // 查找所以活动状态相机
-            LambdaUpdateWrapper<CameraVersion> updateWrapper = new LambdaUpdateWrapper<>();
-            updateWrapper.set(CameraVersion::getStatus,"I")
-                    .eq(CameraVersion::getStatus,"A")
-                    .eq(CameraVersion::getType,param.getType());
-            this.update(updateWrapper);
-
+            if(param.getStatus().equals("A")){
+                LambdaUpdateWrapper<CameraVersion> updateWrapper = new LambdaUpdateWrapper<>();
+                updateWrapper.set(CameraVersion::getStatus,"I")
+                        .eq(CameraVersion::getStatus,"A")
+                        .eq(CameraVersion::getType,param.getType());
+                this.update(updateWrapper);
+            }
             cameraVersion.setStatus(param.getStatus());
-            this.updateById(cameraVersion);
+            this.updateById(param);
             return;
         }
         this.saveOrUpdate(param);