Browse Source

增加文档实体

wuweihao 3 years ago
parent
commit
c48e236d09

+ 6 - 6
gis_application/src/main/resources/logback-spring.xml

@@ -7,7 +7,7 @@
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
-            <pattern>${LOG_PATH}/%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <pattern>${LOG_PATH}/%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{50} - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
     </appender>
@@ -26,7 +26,7 @@
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
-            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{500} - %msg%n</pattern>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{500} - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
     </appender>
@@ -45,7 +45,7 @@
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %method 方法名  %L 行数 %msg:日志消息,%n是换行符-->
-            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{56}.%method:%L - %msg%n</pattern>
+            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{56}.%method:%L - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
         <!-- 此日志文件只记录info级别的 -->
@@ -71,7 +71,7 @@
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %method 方法名  %L 行数 %msg:日志消息,%n是换行符-->
-            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{56}.%method:%L - %msg%n</pattern>
+            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{56}.%method:%L - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
         <!-- 此日志文件只记录error级别的 -->
@@ -97,7 +97,7 @@
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %method 方法名  %L 行数 %msg:日志消息,%n是换行符-->
-            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{56}.%method:%L - %msg%n</pattern>
+            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{56}.%method:%L - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
         <!-- 此日志文件只记录warn级别的 -->
@@ -123,7 +123,7 @@
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %method 方法名  %L 行数 %msg:日志消息,%n是换行符-->
-            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{56}.%method:%L - %msg%n</pattern>
+            <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{TRACE_ID} %-5level %logger{56}.%method:%L - %msg%n</pattern>
             <!--<charset>utf-8</charset>-->
         </encoder>
         <!-- 此日志文件只记录debug级别的 -->

+ 65 - 0
gis_cms/src/main/java/com/gis/cms/controller/DocController.java

@@ -0,0 +1,65 @@
+package com.gis.cms.controller;
+
+import com.gis.cms.entity.dto.DocDto;
+import com.gis.cms.entity.dto.GoodsDto;
+import com.gis.cms.entity.dto.GoodsPageDto;
+import com.gis.cms.entity.dto.ModelDto;
+import com.gis.cms.entity.po.GoodsEntity;
+import com.gis.cms.entity.po.SceneEntity;
+import com.gis.cms.entity.vo.NameVo;
+import com.gis.cms.mapper.MyBaseMapper;
+import com.gis.cms.service.DocService;
+import com.gis.cms.service.FileService;
+import com.gis.cms.service.GoodsService;
+import com.gis.common.base.aop.WebControllerLog;
+import com.gis.common.util.Result;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.validation.Valid;
+import java.util.List;
+
+
+/**
+ * Created by owen on 2021/11/17 0008 9:54
+ */
+@Slf4j
+@Api(tags = "文物管理")
+@RestController
+@RequestMapping("cms/doc")
+public class DocController {
+
+    @Autowired
+    private DocService entityService;
+
+    @ApiOperation("根据项目Id获取列表")
+    @GetMapping("findByProjectId/{projectId}")
+    public Result findByProjectId(@PathVariable Long projectId) {
+        return Result.success(entityService.findByProjectId(projectId));
+    }
+
+    @ApiOperation("上传文件")
+    @PostMapping("upload")
+    public Result upload(MultipartFile file) {
+        return entityService.upload(file, null, null);
+    }
+
+    @ApiOperation("编辑保存")
+    @PostMapping("edit")
+    public Result edit(@RequestBody DocDto param) {
+        return entityService.edit(param);
+    }
+
+
+
+
+
+
+
+
+
+}

+ 39 - 17
gis_cms/src/main/java/com/gis/cms/controller/GoodsController.java

@@ -1,5 +1,6 @@
 package com.gis.cms.controller;
 
+import cn.hutool.core.util.StrUtil;
 import com.gis.cms.entity.dto.*;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.cms.entity.po.SceneEntity;
@@ -11,6 +12,8 @@ import com.gis.common.util.Result;
 import com.gis.cms.service.GoodsService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -21,7 +24,9 @@ import java.util.List;
 
 /**
  * Created by owen on 2021/9/22 0008 9:54
+ * 文物、文档公用一张表
  */
+@Slf4j
 @Api(tags = "文物管理")
 @RestController
 @RequestMapping("cms/goods")
@@ -46,20 +51,21 @@ public class GoodsController  {
     }
 
 
-    @ApiOperation("详情")
+    @ApiOperation("根据项目id获取详情")
     @GetMapping("project/detail/{projectId}")
     public Result<SceneEntity> projectDetail(@PathVariable Long projectId) {
         return entityService.projectId(projectId);
     }
 
-//    @ApiOperation("列表-文档&文物公用")
-//    @GetMapping("listByProjectId/{type}/{projectId}")
-//    public Result<GoodsEntity> listByProjectId(@PathVariable Long projectId, @PathVariable String type) {
-//        return entityService.listByProjectId(projectId, type);
-//    }
+    @ApiOperation("根据id获取详情")
+    @GetMapping("detail/{id}")
+    public Result<GoodsEntity> detail(@PathVariable Long id) {
+        return entityService.detail(id);
+    }
+
 
 
-    @ApiOperation("文物-新增&编辑")
+    @ApiOperation(value = "文物-新增&编辑", notes = "默认封面图是第一张")
     @PostMapping("modelSave")
     public Result modelSave(@Valid @RequestBody ModelDto param) {
         return entityService.saveModel(param);
@@ -72,6 +78,12 @@ public class GoodsController  {
     }
 
 
+    @ApiOperation("上传文件")
+    @PostMapping("upload")
+    public Result upload(MultipartFile file) {
+        return entityService.upload(file, "img", null);
+    }
+
     @ApiOperation("文物-上传文件")
     @PostMapping("modelUpload/{projectId}")
     public Result modelUpload(MultipartFile file, @PathVariable String projectId) {
@@ -84,17 +96,18 @@ public class GoodsController  {
         return entityService.setIndex(fileId);
     }
 
-    @ApiOperation(value = "文档-删除", notes = "多个以逗号分隔开")
-    @GetMapping("docRemoves/{ids}")
-    public Result docRemoves(@PathVariable String ids) {
-        return entityService.removes(ids);
-    }
+//    @ApiOperation(value = "文档-删除", notes = "多个以逗号分隔开")
+//    @GetMapping("docRemoves/{ids}")
+//    public Result docRemoves(@PathVariable String ids) {
+//        return entityService.removes(ids);
+//    }
+//
+//    @ApiOperation("文档-编辑保存")
+//    @PostMapping("docSave")
+//    public Result docSave(@RequestBody GoodsDto param) {
+//        return entityService.save(param);
+//    }
 
-    @ApiOperation("文档-编辑保存")
-    @PostMapping("docSave")
-    public Result docSave(@RequestBody GoodsDto param) {
-        return entityService.save(param);
-    }
 
     @WebControllerLog(description = "文件服务-删除文件")
     @ApiOperation(value = "文物-删除文件", notes = "数据软删除,物理文件硬删除")
@@ -113,5 +126,14 @@ public class GoodsController  {
     }
 
 
+    @ApiOperation("test-测试多文件上传")
+    @PostMapping("testUpload")
+    public Result testUpload(List<MultipartFile> files) {
+        for (MultipartFile file : files) {
+            log.warn("文件名称:{}", file.getOriginalFilename());
+        }
+        return Result.success(files.size());
+    }
+
 
 }

+ 25 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/DocDto.java

@@ -0,0 +1,25 @@
+package com.gis.cms.entity.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.util.List;
+
+/**
+ * Created by owen on 2021/10/20 0020 14:40
+ */
+@Data
+public class DocDto {
+
+    @ApiModelProperty(value = "删除文档id, 多个以逗号分隔")
+    private String removeIds;
+
+    @ApiModelProperty(value = "编辑后全部文档id, 多个以逗号分隔")
+    private String docIds;
+
+    @NotBlank(message = "项目id不能为空")
+    @ApiModelProperty(value = "项目ID", required = true)
+    private Long projectId;
+
+}

+ 4 - 4
gis_cms/src/main/java/com/gis/cms/entity/dto/ModelDto.java

@@ -19,21 +19,21 @@ public class ModelDto {
     @ApiModelProperty(value = "名称", required = true)
     private String name;
 
-    @NotNull(message = "文物类型id不能为空")
-    @ApiModelProperty(value = "文物类型id", required = true)
+//    @NotNull(message = "文物类型id不能为空")
+    @ApiModelProperty(value = "文物类型id")
     private Long goodsTypeId;
 
     @NotBlank(message = "链接不能为空")
     @ApiModelProperty(value = "链接", required = true)
     private String url;
 
-    @ApiModelProperty(value = "缩略图")
+    @ApiModelProperty(value = "缩略图(封面图),前端维护")
     private String thumb;
 
     @ApiModelProperty(value = "图片id, 多个以逗号隔开")
     private String fileIds;
 
-    @NotNull(message = "项目id不能为空")
+//    @NotNull(message = "项目id不能为空")
     @ApiModelProperty(value = "项目id")
     private Long projectId;
 

+ 2 - 8
gis_cms/src/main/java/com/gis/cms/entity/dto/ProjectAddDto.java

@@ -1,14 +1,9 @@
 package com.gis.cms.entity.dto;
 
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import io.swagger.annotations.ApiOperation;
 import lombok.Data;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.io.Serializable;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -48,9 +43,8 @@ public class ProjectAddDto implements Serializable {
     @ApiModelProperty(value = "三维场景")
     private Map<String, String> scenes;
 
-
-    @ApiModelProperty(value = "资料文档")
-    private List<MultipartFile> docs;
+    @ApiModelProperty(value = "资料文档ids, 多个以逗号分隔")
+    private String docIds;
 
     @ApiModelProperty(value = "文物id, 多个以逗号分隔")
     private String goodsIds;

+ 28 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/DocEntity.java

@@ -0,0 +1,28 @@
+package com.gis.cms.entity.po;
+
+import com.gis.common.base.entity.po.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+/**
+ * Created by owen on 2021/11/17 0010 17:39
+ * 文档
+ */
+@Data
+@Table(name = "tb_doc")
+public class DocEntity extends BaseEntity {
+
+
+    @ApiModelProperty(value = "名称" )
+    private String name;
+
+    @ApiModelProperty(value = "文件地址")
+    private String filePath;
+
+    @ApiModelProperty(value = "项目id")
+    private Long projectId;
+
+}

+ 1 - 1
gis_cms/src/main/java/com/gis/cms/entity/po/GoodsEntity.java

@@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
 
 /**
  * Created by owen on 2021/4/20 0010 17:39
- * 文物、资料表
+ * 文物
  */
 @Data
 @Table(name = "tb_goods")

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/ProjectEntity.java

@@ -42,6 +42,9 @@ public class ProjectEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "文物id, 多个以逗号分隔")
     private String goodsIds;
 
+    @ApiModelProperty(value = "文档id, 多个以逗号分隔")
+    private String docIds;
+
     @Transient
     @ApiModelProperty(value = "项目分类名称")
     private String projectTypeName;

+ 31 - 0
gis_cms/src/main/java/com/gis/cms/mapper/DocMapper.java

@@ -0,0 +1,31 @@
+package com.gis.cms.mapper;
+
+
+import com.gis.cms.entity.po.DocEntity;
+import com.gis.cms.entity.po.FileEntity;
+import com.gis.cms.mapper.provider.DocProvider;
+import com.gis.cms.mapper.provider.GoodsProvider;
+import com.gis.common.base.mapper.IBaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.SelectProvider;
+import org.apache.ibatis.annotations.Update;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+
+@Component
+@Mapper
+public interface DocMapper extends IBaseMapper<DocEntity, Long> {
+
+
+    @SelectProvider(type = DocProvider.class, method = "removes")
+    void removes(String ids);
+
+    @Select("select * from tb_doc where is_delete=0 and project_id=#{projectId}")
+    List<DocEntity> findByProjectId(Long projectId);
+
+    @SelectProvider(type = DocProvider.class, method = "strSql")
+    void strSql(String strSql);
+}

+ 33 - 0
gis_cms/src/main/java/com/gis/cms/mapper/provider/DocProvider.java

@@ -0,0 +1,33 @@
+package com.gis.cms.mapper.provider;
+
+import lombok.extern.log4j.Log4j2;
+
+
+/**
+ * Created by owen on 2020/6/13 0013 10:56
+ */
+@Log4j2
+public class DocProvider {
+
+
+    public String removes(String ids) {
+        StringBuffer sql = new StringBuffer(
+                "update tb_doc set is_delete=1, update_time=NOW() WHERE is_delete=0 and id in (");
+        sql.append(ids).append(")");
+
+        log.info("sql: {}", sql.toString());
+        return sql.toString();
+    }
+
+
+    public String strSql(String strSql) {
+        log.info("sql: {}", strSql);
+        return strSql;
+    }
+
+
+
+}
+
+
+

+ 30 - 0
gis_cms/src/main/java/com/gis/cms/service/DocService.java

@@ -0,0 +1,30 @@
+package com.gis.cms.service;
+
+
+import com.gis.cms.entity.dto.DocDto;
+import com.gis.cms.entity.po.DocEntity;
+import com.gis.cms.entity.po.FileEntity;
+import com.gis.common.base.service.IBaseService;
+import com.gis.common.util.Result;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Created by owen on 2021/11/11 0011 16:14
+ */
+public interface DocService extends IBaseService<DocEntity, Long> {
+
+    Result upload(MultipartFile file, String type, String dirCode);
+
+
+    Result removes(String ids);
+
+    List<DocEntity> findByProjectId(Long projectId);
+
+    Result edit(DocDto param);
+
+    void bindingProjectId(String ids, Long projectId);
+}

+ 1 - 30
gis_cms/src/main/java/com/gis/cms/service/GoodsService.java

@@ -20,11 +20,8 @@ public interface GoodsService extends IBaseService<GoodsEntity, Long> {
 
     Result<GoodsEntity> search(GoodsPageDto param, Integer display);
 
-
-
     Result upload(MultipartFile file, String type, String dirCode);
 
-    Result removeFile(Long fileId);
 
     Result detail(Long id);
 
@@ -32,32 +29,6 @@ public interface GoodsService extends IBaseService<GoodsEntity, Long> {
 
     Result setIndex(Long fileId);
 
-    Result uploadImg(MultipartFile file, String code);
-
-
-
-
-
-
-    Result fileList(Long id, String type);
-
-    Result isStorage(Long id, Integer status);
-
-    Result isStorages(Map<String, Integer> param);
-
-//    Result<GoodsEntity> passList(LedgerPageDto param);
-
-    Result<GoodsEntity> findByRegisterId(Long registerId);
-
-    void updateIsStorage(Map<String, Integer> param);
-
-    void updateStatusByIds(int status, String goodsIds);
-
-    List<String> findIdsByIsStorageAndStatus(int isStorage, int status);
-
-//    Result<GoodsEntity> collectList(LedgerPageDto param);
-
-    Result save(GoodsDto param);
 
     Result<SceneEntity> projectId(Long projectId);
 
@@ -70,5 +41,5 @@ public interface GoodsService extends IBaseService<GoodsEntity, Long> {
 
     Result modelBinding(String projectId, String goodsIds);
 
-    Result<GoodsEntity> listByProjectId(Long projectId, String type);
+
 }

+ 151 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/DocServiceImpl.java

@@ -0,0 +1,151 @@
+package com.gis.cms.service.impl;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import com.gis.cms.entity.dto.DocDto;
+import com.gis.cms.entity.po.DocEntity;
+import com.gis.cms.entity.po.FileEntity;
+import com.gis.cms.entity.po.ProjectEntity;
+import com.gis.cms.mapper.DocMapper;
+import com.gis.cms.mapper.FileMapper;
+import com.gis.cms.service.DocService;
+import com.gis.cms.service.FileService;
+import com.gis.cms.service.ProjectService;
+import com.gis.common.base.exception.BaseRuntimeException;
+import com.gis.common.base.mapper.IBaseMapper;
+import com.gis.common.base.service.impl.IBaseServiceImpl;
+import com.gis.common.constant.TypeCode;
+import com.gis.common.util.RegexUtil;
+import com.gis.common.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Created by owen on 2021/6/21 0011 16:16
+ */
+@Slf4j
+@Service
+public class DocServiceImpl extends IBaseServiceImpl<DocEntity, Long> implements DocService {
+
+    @Autowired
+    private DocMapper entityMapper;
+
+    @Autowired
+    ProjectService projectService;
+
+
+    @Override
+    public IBaseMapper<DocEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+
+    @Override
+    public Result upload(MultipartFile file, String type, String dirCode) {
+
+        // 检查非法文件上传
+        boolean checkFile = fileUtils.checkFile(file);
+        if (!checkFile) {
+            return Result.failure("上传文件格式有误, 请重新上传");
+        }
+
+        // 判断类型合法性
+        String [] typeCheck = {"video","model","doc","audio","img"};
+        if (!Arrays.asList(typeCheck).contains(type)) {
+            return Result.failure("非法类型");
+        }
+
+        // 文件目录
+        String fileName = file.getOriginalFilename();
+        String suffix = StringUtils.substringAfterLast(fileName, ".");
+
+        // 视频、模型使用原名存储(中文转拼音)
+        String newName;
+        if ("video".equals(type) || "model".equals(type) || "audio".equals(type)) {
+            newName = RegexUtil.getPinyinName(fileName);
+        } else {
+            newName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
+            newName = newName + "." + suffix;
+        }
+
+        StringBuilder urlPath = new StringBuilder();
+        urlPath.append("/").append(TypeCode.MODULE_DOC);
+        if (StringUtils.isNotBlank(dirCode)){
+            urlPath.append("/").append(dirCode);
+        }
+        if (StringUtils.isNotBlank(type)){
+            urlPath.append("/").append(type);
+        }
+
+        urlPath.append("/").append(newName);
+
+
+        String savePath = configConstant.serverBasePath + urlPath;
+        log.info("保存文件地址:{}", savePath);
+
+        try {
+            FileUtil.writeFromStream(file.getInputStream(), savePath);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        // 保存文件对象
+        DocEntity docEntity = saveEntity(fileName, urlPath.toString());
+        return Result.success(docEntity);
+    }
+
+    @Override
+    public Result removes(String ids) {
+        entityMapper.removes(ids);
+        return Result.success();
+    }
+
+    @Override
+    public List<DocEntity> findByProjectId(Long projectId) {
+        return entityMapper.findByProjectId(projectId);
+    }
+
+    @Override
+    public Result edit(DocDto param) {
+        // 删除文档
+        String removeIds = param.getRemoveIds();
+        if (StringUtils.isNotBlank(removeIds)){
+            entityMapper.removes(removeIds);
+        }
+        // 绑定项目id
+        String docIds = param.getDocIds();
+        if (StringUtils.isNotBlank(docIds)){
+            ProjectEntity entity = projectService.findById(param.getProjectId());
+            entity.setDocIds(docIds);
+            projectService.update(entity);
+        }
+        return Result.success();
+    }
+
+    @Override
+    public void bindingProjectId(String ids, Long projectId){
+        String sql = String.format("update tb_doc set project_id={}, update_time=NOW() where is_delete=0 and id in ({})", projectId, ids);
+        entityMapper.strSql(sql);
+    }
+
+    private DocEntity saveEntity(String name, String path){
+        DocEntity entity = new DocEntity();
+        entity.setName(name);
+        entity.setFilePath(path);
+        this.save(entity);
+        return entity;
+    }
+}

+ 33 - 171
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsServiceImpl.java

@@ -33,10 +33,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.time.LocalDateTime;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
@@ -63,8 +60,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
     private final static String PREFIX_PATH = "/goods";
 
 
-
-
     @Override
     public IBaseMapper<GoodsEntity, Long> getBaseMapper() {
         return this.entityMapper;
@@ -77,11 +72,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         return Result.success(new PageInfo<>(entityMapper.search(param, display)));
     }
 
-
-
-
-
-
     @Override
     public Result removes(String ids) {
         String[] split = StrUtil.split(ids, ",");
@@ -103,19 +93,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         return Result.success();
     }
 
-    @Override
-    public Result removeFile(Long fileId) {
-        FileEntity entity = fileService.findById(fileId);
-        if (entity == null){
-            return Result.success();
-        }
-
-        entity.setIsDelete(1);
-        entity.setIsIndex(0);
-        entity.setUpdateTime(LocalDateTime.now());
-        fileService.update(entity);
-        return Result.success();
-    }
 
     /**
      * 设置封面图
@@ -133,165 +110,37 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         fileService.indexDisable(goodId, entity.getModule());
         fileService.indexEnabled(fileId);
 
-        // 设置缩略图
-//        setThumbByIndex(goodId, entity.getFilePath());
         Object thumb = entity.getFilePath();
         return Result.success(thumb);
     }
 
 
-    /**
-     * 将封面图更新为缩略图
-     */
-    private void setThumbByIndex(Long goodId, String thumb){
-        GoodsEntity entity = this.findById(goodId);
-//        entity.setThumb(thumb);
-        entity.setUpdateTime(LocalDateTime.now());
-        this.update(entity);
-    }
-
-    @Override
-    public Result uploadImg(MultipartFile file, String code) {
-        if (!fileUtils.checkFile(file)) {
-            throw new BaseRuntimeException("非法文件, 请重新上传");
-        }
-
-        String originalFilename = file.getOriginalFilename();
-        String suffix = StringUtils.substringAfterLast(originalFilename, ".");
-
-        String savePath = null;
-        String time = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
-        if ("null".equals(code) || StringUtils.isBlank(code)) {
-             savePath = "/goods/thumb/thumb_" + time  + "." + suffix;
-        } else {
-            savePath = "/goods/" + code + "/thumb/thumb_" + time  + "." + suffix;
-        }
-
-        Map<String, Object> result = new HashMap<>();
-        try {
-            FileUtil.writeFromStream(file.getInputStream(), configConstant.serverBasePath + savePath);
-            result.put("fileName", originalFilename);
-            result.put("filePath", savePath);
-            return Result.success(result);
-
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-
-        return null;
-    }
-
     @Override
     public Result detail(Long id) {
         GoodsEntity entity = this.findById(id);
         if (entity == null) {
             return Result.failure(MsgCode.e3001,"对象不存在,id: " + id);
         }
-        return Result.success(entity);
-    }
-
-
-
-
-
-
-
-
-    @Override
-    public Result isStorage(Long id, Integer status) {
-        GoodsEntity entity = this.findById(id);
-        if (entity == null) {
-            log.error("对象id不存在 : {}", id);
-            return Result.failure("对象id不存在");
-        }
-
-//        entity.setIsStorage(status);
-        this.update(entity);
-        return Result.success(entity);
-    }
-
-
-    @Override
-    public Result isStorages(Map<String, Integer> param) {
-        for (Map.Entry<String, Integer> m : param.entrySet()) {
-            entityMapper.setIsStorage(m.getKey(), m.getValue());
-        }
-        return Result.success();
-    }
 
-    @Override
-    public void updateIsStorage(Map<String, Integer> param){
-        for (Map.Entry<String, Integer> m : param.entrySet()) {
-            entityMapper.setIsStorage(m.getKey(), m.getValue());
+        List<FileEntity> files = new ArrayList<>();
+        String fileIds = entity.getFileIds();
+        if (StringUtils.isNotBlank(fileIds)){
+            files = fileService.findByIds(fileIds);
         }
-    }
 
-    @Override
-    public void updateStatusByIds(int status, String goodsIds) {
-        goodsIds = StringUtils.trim(goodsIds);
-        entityMapper.updateStatusByIds(status, goodsIds);
-    }
-
-    @Override
-    public List<String> findIdsByIsStorageAndStatus(int isStorage, int status) {
-
-        return entityMapper.findIdsByIsStorageAndStatus(isStorage, status);
+        HashMap<Object, Object> result = new HashMap<>();
+        result.put("entity", entity);
+        result.put("file", files);
+        return Result.success(result);
     }
 
-//    @Override
-//    public Result<GoodsEntity> collectList(LedgerPageDto param) {
-//        startPage(param);
-//        GoodsBo conditionDto = new GoodsBo();
-//        conditionDto.setSearchKey(param.getSearchKey());
-//        conditionDto.setIsStorage(0);
-//        List<GoodsEntity> list = entityMapper.searchByCondition(conditionDto);
-//        return Result.success(new PageInfo<>(list));
-//    }
-
-    @Override
-    public Result save(GoodsDto param) {
-
-        // 删除数据
-        this.delByIds(param.getDelIds());
-
-        // 更新保存数据
-        Long projectId = param.getProjectId();
-        String type = param.getType();
-        List<MultipartFile> files = param.getFiles();
-        this.saveAndUpload(projectId, type, files);
 
-        return Result.success();
-    }
 
     @Override
     public Result<SceneEntity> projectId(Long projectId) {
         return null;
     }
 
-//    @Override
-//    public Result<GoodsEntity> passList(LedgerPageDto param) {
-//        startPage(param);
-//        GoodsBo conditionDto = new GoodsBo();
-//        conditionDto.setSearchKey(param.getSearchKey());
-//        conditionDto.setIsStorage(1);
-//        List<GoodsEntity> list = entityMapper.searchByCondition(conditionDto);
-//        return Result.success(new PageInfo<>(list));
-//    }
-
-    @Override
-    public Result<GoodsEntity> findByRegisterId(Long registerId) {
-        return Result.success(entityMapper.findByRegisterId(registerId));
-    }
-
-
-
-    @Override
-    public Result fileList(Long id, String type) {
-        List<FileEntity> list = fileService.findByType(id, type, TypeCode.MODULE_GOODS);
-        return Result.success(list);
-    }
-
-
 
     @Override
     public Result upload(MultipartFile file, String type, String dirCode) {
@@ -344,6 +193,8 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         return Result.success(result);
     }
 
+
+
     /**
      * 保存文件且保存文件信息
      * @param projectId 项目id
@@ -366,26 +217,48 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         }
     }
 
+    /**
+     * 封面图默认是第一张(若果文件id没有index值时),只有前端设置了封面,才会更新文件封面
+     * @param param
+     * @return
+     */
     @Override
     public Result saveModel(ModelDto param) {
         Long id = param.getId();
         GoodsEntity entity;
+        boolean flag = false; // 更新文件id 开关
         if (id == null){
             entity = new GoodsEntity();
             BeanUtils.copyProperties(param, entity);
             entity.setType(TypeCode.MODULE_MODEL);
             this.save(entity);
+            flag = true;
         } else {
             entity = this.findById(id);
             if (entity == null){
                 return Result.failure("对象不存在");
             }
+            if (!StrUtil.equals(param.getFileIds(), entity.getFileIds())){
+                flag = true;
+            }
             BeanUtils.copyProperties(param, entity);
             this.update(entity);
         }
+
+        if (flag){ // 绑定文件id
+            fileService.addModuleIdToFile(entity.getFileIds(), entity.getId(), TypeCode.MODULE_GOODS);
+            log.info("绑定文件id完成");
+        }
+
         return Result.success(entity);
     }
 
+
+
+
+
+
+
     @Override
     public Result modelUpload(MultipartFile file, String projectId) {
         String savePath = PREFIX_PATH + "/" + projectId + "/" + TypeCode.GOODS_MODEL;
@@ -404,17 +277,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         return Result.success();
     }
 
-    @Override
-    public Result<GoodsEntity> listByProjectId(Long projectId, String type) {
-        List<GoodsEntity> list = entityMapper.findByTypeAndProjectId(type, projectId);
-        return Result.success(list);
-    }
-
-    private void delByIds(String ids){
-        if (StringUtils.isNotBlank(ids)){
-            entityMapper.delByIds(ids);
-        }
-    }
 
 
 

+ 22 - 7
gis_cms/src/main/java/com/gis/cms/service/impl/ProjectServiceImpl.java

@@ -3,12 +3,15 @@ package com.gis.cms.service.impl;
 
 import com.gis.cms.entity.bo.StorageInBo;
 import com.gis.cms.entity.dto.*;
+import com.gis.cms.entity.po.DocEntity;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.cms.entity.po.ProjectEntity;
 import com.gis.cms.entity.po.SceneEntity;
+import com.gis.cms.mapper.DocMapper;
 import com.gis.cms.mapper.GoodsMapper;
 import com.gis.cms.mapper.ProjectMapper;
 import com.gis.cms.mapper.SceneMapper;
+import com.gis.cms.service.DocService;
 import com.gis.cms.service.GoodsService;
 import com.gis.cms.service.ProjectService;
 import com.gis.cms.service.SceneService;
@@ -18,11 +21,13 @@ import com.gis.common.constant.TypeCode;
 import com.gis.common.util.Result;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -53,6 +58,12 @@ public class ProjectServiceImpl extends IBaseServiceImpl<ProjectEntity, Long> im
     @Autowired
     SceneMapper sceneMapper;
 
+    @Autowired
+    DocMapper docMapper;
+
+    @Autowired
+    DocService docService;
+
 
 
     @Override
@@ -94,17 +105,25 @@ public class ProjectServiceImpl extends IBaseServiceImpl<ProjectEntity, Long> im
         List<SceneEntity> scenes = sceneMapper.findByTypeAndProjectId(TypeCode.SCENE_SENCE, id);
 
         // 文档
-        List<GoodsEntity> docs = goodsMapper.findByTypeAndProjectId(TypeCode.GOODS_DOC, id);
+        String docIds = entity.getDocIds();
+        List<DocEntity> docs = new ArrayList<>();
+        if (StringUtils.isNotBlank(docIds)){
+            docs = docService.findByIds(docIds);
+        }
 
         // 文物
-        List<GoodsEntity> models = goodsMapper.findByTypeAndProjectId(TypeCode.GOODS_MODEL, id);
+        String goodsIds = entity.getGoodsIds();
+        List<GoodsEntity> goods = new ArrayList<>();
+        if (StringUtils.isNotBlank(goodsIds)){
+            goods = goodsService.findByIds(goodsIds);
+        }
 
         HashMap<String, Object> result = new HashMap<>();
         result.put("entity", entity);
         result.put("website", websites);
         result.put("scene", scenes);
         result.put("doc", docs);
-        result.put("model", models);
+        result.put("goods", goods);
 
         return Result.success(result);
     }
@@ -130,10 +149,6 @@ public class ProjectServiceImpl extends IBaseServiceImpl<ProjectEntity, Long> im
         // 保存场景信息
         this.saveSceneInfo(id, param.getScenes(), "scene");
 
-        // 保存文档、文件
-        goodsService.saveAndUpload(id, "doc", param.getDocs());
-
-
         return Result.success();
     }
 

+ 5 - 0
gis_common/src/main/java/com/gis/common/base/aop/WebLogAspect.java

@@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.AfterReturning;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.aspectj.lang.annotation.Pointcut;
+import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -47,6 +48,10 @@ public class WebLogAspect {
     @Before("controllerLog()") //在切入点的方法run之前要干的
     public void logBeforeController(JoinPoint joinPoint) throws Exception {
         startTime = System.currentTimeMillis();
+
+        // 设置链路id, 在logback-spring.xml里用
+        MDC.put("TRACE_ID", startTime+"");
+
         // 记录下请求内容
         String remoteAddr = request.getRemoteAddr();
         log.warn("start : {}, {}, uuid: {}" , request.getMethod(), request.getRequestURI(), startTime);

+ 6 - 3
gis_common/src/main/java/com/gis/common/constant/TypeCode.java

@@ -9,12 +9,15 @@ public class TypeCode {
 
     public static final String MODULE_MARTYR = "martyr";
 
-    public static final String MODULE_GOODS = "GOODS";
+    public static final String MODULE_GOODS = "goods";
 
-    public static final String MODULE_MODEL = "MODEL";
+    public static final String MODULE_MODEL = "model";
+
+    /**文档模块*/
+    public static final String MODULE_DOC = "doc";
 
     // 资料类型
-    public static final String GOODS_DOC = "doc";
+//    public static final String GOODS_DOC = "doc";
 
     // 文物类型
     public static final String GOODS_MODEL = "model";

+ 11 - 11
gis_common/src/main/java/com/gis/common/util/Result.java

@@ -22,7 +22,7 @@ public class Result<T> implements Serializable {
     public static int CODE_SUCCESS = 0;
     public static int CODE_FAILURE = -1;
     public static String[] NOOP = new String[]{};
-    public static LocalDateTime dataTime = LocalDateTime.now();
+//    public static LocalDateTime dataTime = LocalDateTime.now();
 
     /**
      * 处理状态:0: 成功, 1: 失败
@@ -49,7 +49,7 @@ public class Result<T> implements Serializable {
      * @return data
      */
     public static Result success(Object data) {
-        return new Result(CODE_SUCCESS, SUCCESS_MSG, data, dataTime);
+        return new Result(CODE_SUCCESS, SUCCESS_MSG, data, LocalDateTime.now());
     }
     /**
      * 处理成功
@@ -57,7 +57,7 @@ public class Result<T> implements Serializable {
      * @return data
      */
     public static Result success() {
-        return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP, dataTime);
+        return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP, LocalDateTime.now());
     }
     /**
      * 处理成功
@@ -66,7 +66,7 @@ public class Result<T> implements Serializable {
      * @return data
      */
     public static Result success(String msg) {
-        return new Result(CODE_SUCCESS, msg, NOOP, dataTime);
+        return new Result(CODE_SUCCESS, msg, NOOP, LocalDateTime.now());
     }
     /**
      * 处理成功
@@ -76,7 +76,7 @@ public class Result<T> implements Serializable {
      * @return data
      */
     public static Result success(String msg, Object data) {
-        return new Result(CODE_SUCCESS, msg, data, dataTime);
+        return new Result(CODE_SUCCESS, msg, data, LocalDateTime.now());
     }
     /**
      * 处理失败,并返回数据(一般为错误信息)
@@ -86,7 +86,7 @@ public class Result<T> implements Serializable {
      * @return data
      */
     public static Result failure(int code, String msg) {
-        return new Result(code, msg, NOOP , dataTime);
+        return new Result(code, msg, NOOP , LocalDateTime.now());
     }
     /**
      * 处理失败
@@ -98,9 +98,9 @@ public class Result<T> implements Serializable {
         return failure(CODE_FAILURE, msg);
     }
 
-    @Override
-    public String toString() {
-        return "JsonResult [code=" + code + ", msg=" + msg + ", data="
-                + data + ", timestamp="+ dataTime + "]";
-    }
+//    @Override
+//    public String toString() {
+//        return "JsonResult [code=" + code + ", msg=" + msg + ", data="
+//                + data + ", timestamp="+ timestamp + "]";
+//    }
 }