Преглед изворни кода

文件id存到部件/建筑物记录里面

wuweihao пре 5 година
родитељ
комит
9639a7a474
18 измењених фајлова са 99 додато и 118 уклоњено
  1. 1 1
      museum_application/src/main/resources/application-dev.properties
  2. 4 1
      museum_application/src/main/resources/application-sit.properties
  3. 3 3
      museum_dao/src/main/java/com/museum/dao/Provide/DownloadProvider.java
  4. 2 2
      museum_dao/src/main/java/com/museum/dao/Provide/MessageProvider.java
  5. 1 1
      museum_domain/src/main/java/com/museum/domain/entity/BuildingEntity.java
  6. 2 2
      museum_domain/src/main/java/com/museum/domain/entity/DownloadEntity.java
  7. 2 2
      museum_domain/src/main/java/com/museum/domain/entity/PartEntity.java
  8. 1 1
      museum_domain/src/main/java/com/museum/domain/entity/RoamEntity.java
  9. 9 9
      museum_domain/src/main/java/com/museum/domain/request/DownloadRequest.java
  10. 6 3
      museum_domain/src/main/java/com/museum/domain/request/PartRequest.java
  11. 4 0
      museum_domain/src/main/java/com/museum/domain/request/RoamRequest.java
  12. 6 2
      museum_domain/src/main/java/com/museum/domain/response/BuildingResponse.java
  13. 2 2
      museum_domain/src/main/java/com/museum/domain/response/PartResponse.java
  14. 5 2
      museum_domain/src/main/java/com/museum/domain/response/RoamResponse.java
  15. 6 27
      museum_web/src/main/java/com/museum/web/controller/BaseController.java
  16. 16 21
      museum_web/src/main/java/com/museum/web/controller/BuildingController.java
  17. 10 31
      museum_web/src/main/java/com/museum/web/controller/CommonController.java
  18. 19 8
      museum_web/src/main/java/com/museum/web/controller/PartController.java

+ 1 - 1
museum_application/src/main/resources/application-dev.properties

@@ -54,6 +54,6 @@ logging.level.com.museum=debug
 
 # \u4E0A\u4F20\u6587\u4EF6\u4FDD\u5B58\u8DEF\u5F84
 output.file.path=F:\\test\\sh_museum_cms\\
-oss.file.path=sh_museum
+oss.file.path=sh_museum/
 oss.domain=http://4dkankan.oss-cn-shenzhen.aliyuncs.com/
 

+ 4 - 1
museum_application/src/main/resources/application-sit.properties

@@ -53,5 +53,8 @@ logging.config=classpath:logback-spring.xml
 logging.level.com.museum=debug
 
 # \u4E0A\u4F20\u6587\u4EF6\u4FDD\u5B58\u8DEF\u5F84
-output.file.path=/root/user/sh_museum_data//
+output.file.path=/root/user/sh_museum_data/
+oss.file.path=sh_museum/
+oss.domain=http://4dkankan.oss-cn-shenzhen.aliyuncs.com/
+
 

+ 3 - 3
museum_dao/src/main/java/com/museum/dao/Provide/DownloadProvider.java

@@ -13,16 +13,16 @@ public class DownloadProvider {
 
     public String findBySearchKey(PageRequest param, Long applyId, Long auditId){
         StringBuffer sql = new StringBuffer(
-                "select z.name, z.reason, z.create_time, z.type, u.user_name, z.file_ids, z.status from tb_download z " +
+                "select z.id, z.name, z.reason, z.create_time, z.type, u.user_name, z.file_ids, z.status from tb_download z " +
                         "left join tb_user u on z.apply_id = u.id " +
                         "where z.rec_status = 'A' ");
 
         if (applyId != null) {
-            sql.append("and apply_id = ").append(applyId);
+            sql.append("and z.apply_id = ").append(applyId);
         }
 
         if (auditId != null) {
-            sql.append("and audit_id = ").append(auditId);
+            sql.append("and z.audit_id = ").append(auditId);
         }
 
         String searchKey = param.getSearchKey();

+ 2 - 2
museum_dao/src/main/java/com/museum/dao/Provide/MessageProvider.java

@@ -19,8 +19,8 @@ public class MessageProvider {
 
         if(StringUtils.isNotBlank(param.getStartTime()) && StringUtils.isNotBlank(param.getEndTime())){
 
-            sql.append(" and z.create_time >= ").append("'").append(param.getStartTime()).append("'");
-            sql.append(" and z.create_time <= ").append("'").append(param.getEndTime()).append("'");
+            sql.append(" and create_time >= ").append("'").append(param.getStartTime()).append("'");
+            sql.append(" and create_time <= ").append("'").append(param.getEndTime()).append("'");
         }
 
         String searchKey = param.getSearchKey();

+ 1 - 1
museum_domain/src/main/java/com/museum/domain/entity/BuildingEntity.java

@@ -28,7 +28,7 @@ public class BuildingEntity extends BaseEntity implements Serializable {
 
     /** 模型链接 */
     @ApiModelProperty(value = "模型链接")
-    private String web_site;
+    private String webSite;
 
     /** 展示封面 */
     @ApiModelProperty(value = "展示封面")

+ 2 - 2
museum_domain/src/main/java/com/museum/domain/entity/DownloadEntity.java

@@ -14,8 +14,8 @@ public class DownloadEntity extends BaseEntity implements Serializable {
 
     private static final long serialVersionUID = -5191918181588231778L;
 
-    /** 部件id */
-    private Long fkId;
+//    /** 部件id */
+//    private Long fkId;
 
     /** 模块名称 */
     private String name;

+ 2 - 2
museum_domain/src/main/java/com/museum/domain/entity/PartEntity.java

@@ -37,8 +37,8 @@ public class PartEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "程序显示, 0:显示,1:不显示")
     private Integer display;
 
-    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片")
-    private Integer displayModel;
+//    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片")
+//    private Integer displayModel;
 
     @JsonIgnore
     @ApiModelProperty(value = "高清图")

+ 1 - 1
museum_domain/src/main/java/com/museum/domain/entity/RoamEntity.java

@@ -31,7 +31,7 @@ public class RoamEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "高清图/场景/模型/url")
     private String webSite;
 
-    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片, 2:场景漫游")
+    @ApiModelProperty(value = "程序显示, 0:显示模型,1:场景漫游")
     private Integer displayModel;
 
     @JsonIgnore

+ 9 - 9
museum_domain/src/main/java/com/museum/domain/request/DownloadRequest.java

@@ -13,21 +13,21 @@ public class DownloadRequest implements Serializable {
 
     private static final long serialVersionUID = -5191918184589231778L;
 
-    @ApiModelProperty(value = "模块id", name = "fkId", required = true)
-    private Long fkId;
+//    @ApiModelProperty(value = "模块id", name = "fkId", required = true)
+//    private Long fkId;
 
-    @ApiModelProperty(value = "名称", name = "name", required = true)
-    private Long name;
+    @ApiModelProperty(value = "名称", required = true)
+    private String name;
 
-    @ApiModelProperty(value = "模块类型,part:部件, building:建筑物", name = "type", required = true)
-    private Long type;
+    @ApiModelProperty(value = "模块名称,part:部件, building:建筑物",  required = true)
+    private String type;
 
-    @ApiModelProperty(value = "申请原因", name = "reason", required = true)
+    @ApiModelProperty(value = "申请原因",  required = true)
     private String reason;
 
-    @ApiModelProperty(value = "审核人id", name = "auditId", required = true)
+    @ApiModelProperty(value = "审核人id", required = true)
     private Long auditId;
 
-    @ApiModelProperty(value = "多媒体资料id, 多个id用“,“隔开,例如:1,2,3", name = "fileIds", required = true)
+    @ApiModelProperty(value = "多媒体资料id, 多个id用“,“隔开,例如:1,2,3", required = true)
     private String fileIds;
 }

+ 6 - 3
museum_domain/src/main/java/com/museum/domain/request/PartRequest.java

@@ -17,9 +17,7 @@ public class PartRequest  {
     private Long id;
 
     @NotNull(message = "名称不能为空")
-//    @ApiModelProperty(value = "名称", name = "name", required = true)
     @ApiModelProperty(value = "名称", required = true)
-//    @ApiModelProperty(notes = "用户名", example = "123", required = true)
     private String name;
 
     @NotNull(message = "楼体不能为空")
@@ -48,9 +46,14 @@ public class PartRequest  {
     @ApiModelProperty(value = "程序显示, 0:显示,1:不显示", name = "display", required = true)
     private Integer display;
 
-    @ApiModelProperty(value = "场景ico")
+    @NotNull(message = "封面图不能为空")
+    @ApiModelProperty(value = "封面ico")
     private String ico;
 
+    @NotNull(message = "缩略图不能为空")
+    @ApiModelProperty(value = "缩略图")
+    private String thumb;
+
     @ApiModelProperty(value = "材料", name = "material")
     private String material;
 

+ 4 - 0
museum_domain/src/main/java/com/museum/domain/request/RoamRequest.java

@@ -43,4 +43,8 @@ public class RoamRequest implements Serializable {
     @ApiModelProperty(value = "程序显示, 0:显示,1:不显示", name = "display", required = true)
     private Integer display;
 
+    @NotNull(message = "显示类型")
+    @ApiModelProperty(value = "程序显示, 0:显示模型,1:场景漫游")
+    private Integer displayModel;
+
 }

+ 6 - 2
museum_domain/src/main/java/com/museum/domain/response/BuildingResponse.java

@@ -7,6 +7,7 @@ import lombok.Data;
 
 import javax.persistence.Table;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -27,7 +28,7 @@ public class BuildingResponse extends BaseEntity implements Serializable {
 
     /** 模型链接 */
     @ApiModelProperty(value = "模型链接")
-    private String web_site;
+    private String webSite;
 
     /** 展示封面 */
     @ApiModelProperty(value = "展示封面")
@@ -36,8 +37,11 @@ public class BuildingResponse extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "多媒体资料ID, 多个以','逗号隔开 ")
     private String fileIds;
 
+    /**
+     * 不new 一个的话,序列化后返回值没有这个字段
+     */
     @ApiModelProperty(value = "多媒体资料")
-    private List<FileEntity> files;
+    private List<FileEntity> files = new ArrayList<>();
 
 
 

+ 2 - 2
museum_domain/src/main/java/com/museum/domain/response/PartResponse.java

@@ -36,8 +36,8 @@ public class PartResponse extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "程序显示, 0:显示,1:不显示")
     private Integer display;
 
-    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片")
-    private Integer displayModel;
+//    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片")
+//    private Integer displayModel;
 
     @JsonIgnore
     @ApiModelProperty(value = "高清图")

+ 5 - 2
museum_domain/src/main/java/com/museum/domain/response/RoamResponse.java

@@ -5,6 +5,7 @@ import com.museum.domain.entity.BaseEntity;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 /**
@@ -30,8 +31,8 @@ public class RoamResponse extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "高清图/场景/模型/url")
     private String webSite;
 
-//    @ApiModelProperty(value = "程序显示, 0:显示模型,1:显示图片, 2:场景漫游")
-//    private Integer displayModel;
+    @ApiModelProperty(value = "程序显示, 0:显示模型,1:场景漫游")
+    private Integer displayModel;
 
     @JsonIgnore
     @ApiModelProperty(value = "高清图")
@@ -48,4 +49,6 @@ public class RoamResponse extends BaseEntity implements Serializable {
 
     @ApiModelProperty(value = "展示类型名称")
     private String typeName;
+
+
 }

+ 6 - 27
museum_web/src/main/java/com/museum/web/controller/BaseController.java

@@ -8,9 +8,9 @@ import com.museum.domain.entity.LogEntity;
 import com.museum.domain.request.PageRequest;
 import com.museum.service.FileService;
 import com.museum.service.LogService;
+import com.museum.service.TypeService;
 import com.museum.web.shiro.JwtUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 
@@ -33,6 +33,9 @@ public class BaseController {
     @Autowired
     public FileService fileService;
 
+    @Autowired
+    public TypeService typeService;
+
     @Value("${output.file.path}")
     public String OUT_PATH;
 
@@ -100,39 +103,15 @@ public class BaseController {
     }
 
 
-    /**
-     * 文件上传
-     */
-//    String upload(MultipartFile[] files, Long id, String type) throws IOException {
-//        if (files == null) {
-//            log.error("文件不能为空");
-//            return "";
-//        }
-//
-//        String dir = "";
-//        List<Map<String, String>> list = FileUtils.upload(files, OUT_PATH);
-//        for (Map<String, String> map : list) {
-//            FileEntity entity = new FileEntity();
-//            entity.setFkId(id);
-//            entity.setFileName(map.get("name"));
-//            entity.setFilePath(map.get("path"));
-//            entity.setType(type);
-//            fileService.save(entity);
-//            dir = map.get("dir");
-//        }
-//
-//        return dir;
-//
-//    }
-
     // 删除文件
     void removeFile(String ids) throws IOException {
         // 删除oss物理文件
         List<FileEntity> files = fileService.findByIds(ids);
         for (FileEntity entity: files) {
             String filePath = entity.getFilePath();
-            filePath = OSS_PATH + StringUtils.substringAfterLast(filePath, "/");
+            filePath = filePath.replace(OSS_DOMAIN, "");
             log.info("remove oss file: {}", filePath);
+            // 删除只要域名后面的路径就可以了
             AliyunOssUtil.delete(filePath);
         }
 

+ 16 - 21
museum_web/src/main/java/com/museum/web/controller/BuildingController.java

@@ -27,10 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
@@ -47,15 +44,6 @@ public class BuildingController extends BaseController {
     private BuildingService buildingService;
 
 
-//    @ApiOperation("列表")
-//    @PostMapping("list")
-//    public Result<BuildingEntity> list(@RequestBody PageRequest param) {
-//        startPage(param);
-//        PageInfo<BuildingEntity> page = new PageInfo<>(buildingService.findAll());
-//        return Result.success(page);
-//    }
-
-
     @ApiOperation("列表")
     @PostMapping("list")
     public Result<BuildingResponse> list(@RequestBody PageRequest param) {
@@ -63,11 +51,17 @@ public class BuildingController extends BaseController {
 
         List<BuildingResponse> entityList = buildingService.findByAll();
 
-        for (BuildingResponse entity : entityList) {
-            List<FileEntity> files = fileService.findByIds(entity.getFileIds());
-            entity.setFiles(files);
+        if (entityList.size() > 0) {
+            for (BuildingResponse entity : entityList) {
+                if (entity.getFileIds() != null) {
+                    List<FileEntity> files = fileService.findByIds(entity.getFileIds());
+                    entity.setFiles(files);
+                }
+            }
+
         }
 
+
         PageInfo<BuildingResponse> page = new PageInfo<>(entityList);
         return Result.success(page);
     }
@@ -82,9 +76,10 @@ public class BuildingController extends BaseController {
         if (id == null) {
             entity = new BuildingEntity();
             BeanUtils.copyProperties(param, entity);
+
             buildingService.save(entity);
         } else {
-             entity = buildingService.findById(id);
+            entity = buildingService.findById(id);
             if (entity == null) {
                 log.error("建筑信息不存在: {}", id);
                 return Result.failure("对象不存在");
@@ -98,9 +93,6 @@ public class BuildingController extends BaseController {
     }
 
 
-
-
-
     @ApiOperation("详情")
     @GetMapping("detail/{id}")
     public Result detail(@PathVariable Long id) {
@@ -112,7 +104,10 @@ public class BuildingController extends BaseController {
         }
 
         // 查找文件
-        List<FileEntity> files = fileService.findByFkIdAndType(id, TypeCode.MODEL_PART);
+        List<FileEntity> files = new ArrayList<>();
+        if (entity.getFileIds() != null) {
+            files = fileService.findByIds(entity.getFileIds());
+        }
 
         HashMap<String, Object> resultMap = new HashMap<>();
         resultMap.put("building", entity);

+ 10 - 31
museum_web/src/main/java/com/museum/web/controller/CommonController.java

@@ -47,60 +47,50 @@ import java.util.*;
 @Log4j2
 @Api(tags = "共用接口")
 @RestController
-//@RequestMapping("manage/common")
-@RequestMapping("/common")
+@RequestMapping("manage/common")
+//@RequestMapping("/common")
 //@Transactional
 public class CommonController extends BaseController {
 
-//    @ApiImplicitParams({
-//            @ApiImplicitParam(name = "type", value = "模型类型, roam:自由漫游,part:部件欣赏,building: 建筑物,ico时不用传", required = false),
-//            @ApiImplicitParam(name = "files", value = "可以接收多个文件", required = true),
-//    })
+
     @ApiOperation("上传, 可以接收多个文件")
     @PostMapping(value = "upload", consumes = {"multipart/form-data"})
-    public Result upload(MultipartFile [] files ) throws IOException {
+    public Result upload(MultipartFile [] file ) throws IOException {
 
-        if (files == null) {
+        if (file.length <= 0) {
             log.error("文件不能为空");
             return Result.failure("文件不能为空");
         }
 
         // 写入本地服务器
-        List<Map<String, String>> uploads = FileUtils.upload(files, OUT_PATH);
+        List<Map<String, String>> uploads = FileUtils.upload(file, OUT_PATH);
 
-        HashMap<Long, String> resultMap = new HashMap<>();
+        HashMap<String, String> resultMap = new HashMap<>();
         String dir = null;
-        int a = 0;
         for (Map<String, String> map: uploads) {
             String fileName = map.get("name");
             String newName = map.get("newName");
-            String ossPath = OSS_PATH+"/image/" + newName;
+            String ossPath = OSS_PATH+"image/" + newName;
             log.info("local {}, ", map.get("path"));
             // 上传到oss
             AliyunOssUtil.upload(map.get("path"), ossPath);
 
             // 保存db
             FileEntity entity = new FileEntity();
-
             entity.setFileName(fileName);
-
             String ossUrl = OSS_DOMAIN+ossPath;
             entity.setFilePath(ossUrl);
 
             fileService.save(entity);
 
             // 返回前端数据
-            resultMap.put(entity.getId(), ossUrl);
+            resultMap.put(entity.getId().toString(), ossUrl);
             dir = map.get("dir");
-            ++ a;
         }
 
         // 删除本地服务器物理文件,用删除目录的方式
         FileUtil.del(OUT_PATH + dir);
 
-//        log.info("resultMap {}, ", resultMap);
-
-        // 用swagger测试有bug, 不显示返回值;使用postman可以
         return Result.success(resultMap);
 
     }
@@ -108,18 +98,7 @@ public class CommonController extends BaseController {
     @ApiOperation("删除文件")
     @GetMapping("removes/{ids}")
     public Result removes(@PathVariable String ids) throws IOException {
-
-//        // 删除oss物理文件
-//        List<FileEntity> files = fileService.findByIds(ids);
-//        for (FileEntity entity: files) {
-//            String filePath = entity.getFilePath();
-//            filePath = OSS_PATH + StringUtils.substringAfterLast(filePath, "/");
-//            log.info("remove oss file: {}", filePath);
-//            AliyunOssUtil.delete(filePath);
-//        }
-//
-//        // 删除db记录
-//        fileService.deleteByIds(ids);
+        // 删除oss物理文件
         removeFile(ids);
 
         return Result.success();

+ 19 - 8
museum_web/src/main/java/com/museum/web/controller/PartController.java

@@ -7,6 +7,7 @@ import com.museum.common.constant.TypeCode;
 import com.museum.common.util.Result;
 import com.museum.domain.entity.PartEntity;
 import com.museum.domain.entity.FileEntity;
+import com.museum.domain.entity.TypeEntity;
 import com.museum.domain.request.NavRequest;
 import com.museum.domain.request.PartRequest;
 import com.museum.domain.response.PartResponse;
@@ -17,7 +18,6 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -65,6 +66,9 @@ public class PartController extends BaseController {
         if (id == null) {
             entity = new PartEntity();
             BeanUtils.copyProperties(param, entity);
+
+
+
             partService.save(entity);
 
 
@@ -90,26 +94,33 @@ public class PartController extends BaseController {
     @GetMapping("detail/{id}")
     public Result detail(@PathVariable Long id) {
         PartEntity entity = partService.findById(id);
-
         if (entity == null) {
             log.error("对象不存在: {}", id);
             return Result.failure("对象不存在");
         }
 
+        PartResponse partResponse = new PartResponse();
+        BeanUtils.copyProperties(entity, partResponse);
+
+        TypeEntity typeEntity = typeService.findById(entity.getTypeId());
+        String typeName = typeEntity != null ? typeEntity.getName() : "";
+        partResponse.setTypeName(typeName);
+
+
+
+
         // 查找文件
-//        List<FileEntity> files = fileService.findByFkIdAndType(id, TypeCode.MODEL_PART);
+        String fileIds = entity.getFileIds();
+        List<FileEntity> files  = (fileIds != null) ? fileService.findByIds(fileIds) : new ArrayList<>();
 
-        List<FileEntity> files =  fileService.findByIds(entity.getFileIds());
         HashMap<String, Object> resultMap = new HashMap<>();
-        resultMap.put("part", entity);
+        resultMap.put("part", partResponse);
         resultMap.put("file", files);
 
         return Result.success(resultMap);
     }
 
-    /**
-     * 是否要删除文件?再考虑
-     */
+
     @ApiImplicitParams({
             @ApiImplicitParam(name = "ids", value = "部件id,多个id用逗号隔开,如: 1,2,3", required = true)
     })