Sfoglia il codice sorgente

新增场景音频模块

wuweihao 4 anni fa
parent
commit
4c4637e530

+ 8 - 0
gis_application/src/main/resources/application-dev.properties

@@ -59,6 +59,14 @@ server.file.path=F:\\test\\ngin\\${project.name}_data\\
 
 # url info
 server.url.prefix=/data/
+# domain dev \u4F7F\u7528\u7684\u662Fnginx, \u5176\u4ED6\u73AF\u5883\u4F7F\u7528tomcat\uFF0C\u9700\u8981ip+port
+server.domain =http://192.168.0.135:${server.port}${server.url.prefix}
+
+
+# \u5339\u914D\u89C4\u5219 dev \u73AF\u5883\u662F\u7528jar\u5305\uFF0C sit\u662F\u7528tomcat\uFF0C \u6240\u4EE5\u914D\u7F6E\u8FD9\u4E2A\u9759\u6001\u8D44\u6E90\u8BBF\u95EE
+spring.mvc.static-path-pattern=/${server.url.prefix}/**
+### \u5339\u914D\u8DEF\u5F84
+spring.resources.static-locations=file:\\${server.file.path}
 
 # swagger2 \u8BBE\u7F6E\u5168\u5C40\u5B57\u4F53\u683C\u5F0F\u4E3Autf-8
 swagger.package=com.gis.web.controller

+ 2 - 0
gis_application/src/main/resources/application-sit.properties

@@ -59,6 +59,8 @@ server.file.path=/root/user/${project.name}_data/
 
 # url prefix
 server.url.prefix=/data/
+# domain
+server.domain=http://192.168.0.44:8110/
 
 # swagger2 \u8BBE\u7F6E\u5168\u5C40\u5B57\u4F53\u683C\u5F0F\u4E3Autf-8
 swagger.package=com.gis.web.controller

File diff suppressed because it is too large
+ 0 - 1186
gis_application/src/main/resources/db/army_cms.sql


+ 6 - 0
gis_common/pom.xml

@@ -164,6 +164,12 @@
             <version>2.5.1</version>
         </dependency>
 
+        <!-- 二维码 -->
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>core</artifactId>
+        </dependency>
+
 
 
     </dependencies>

+ 2 - 2
gis_common/src/main/java/com/gis/common/constant/ConfigConstant.java

@@ -16,8 +16,8 @@ public class ConfigConstant {
     public  String serverBasePath;
 
     /** 服务器域名*/
-//    @Value("${server.domain}")
-//    public  String serverDomain;
+    @Value("${server.domain}")
+    public  String serverDomain;
 
     @Value("${server.url.prefix}")
     public String serverUrlPrefix;

+ 16 - 0
gis_common/src/main/java/com/gis/common/constant/MsgCode.java

@@ -0,0 +1,16 @@
+package com.gis.common.constant;
+
+/**
+ * Created by owen on 2021/6/1 0001 16:45
+ */
+public class MsgCode {
+
+    /** 对象不存在*/
+    public static final Integer e3001 = 3001;
+
+    /** 长传文件非法*/
+    public static final Integer e3002 = 3002;
+
+    /** 空目录*/
+    public static final Integer e3003 = 30023;
+}

+ 19 - 0
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -207,4 +207,23 @@ public class FileUtils {
         // 默认返回类型
         return "image";
     }
+
+    public static boolean checkFile(MultipartFile file) {
+        //设置允许上传文件类型
+        String suffixList = ".jpg,.gif,.png,.ico,.bmp,.jpeg,.zip,.zp,.rar,.mp3,.mp4,.avi,.mov,.4dage";
+        // 获取文件后缀
+        if(file == null){
+            log.info("文件流为空不可上传");
+            return false;
+        }
+        String fileName = file.getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf(".")
+                + 1, fileName.length());
+        if (suffixList.contains(suffix.trim().toLowerCase())) {
+            log.info("无非法参数可以放行!!!");
+            return true;
+        }
+        log.info("存在非法参数不能放行!请核对上传文件格式,重新刷新页面再次上传!");
+        return false;
+    }
 }

+ 36 - 0
gis_domain/src/main/java/com/gis/domain/dto/SceneAudioDto.java

@@ -0,0 +1,36 @@
+package com.gis.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * Created by owen on 2020/5/9 0009 12:20
+ */
+@Data
+public class SceneAudioDto {
+
+    @ApiModelProperty(value = "id, 修改时必须传,新增忽略", name = "id")
+    private Long id;
+
+    @NotBlank(message = "名称不能为空")
+    @ApiModelProperty(value = "名称", required = true)
+    private String name;
+
+    @ApiModelProperty(value = "类型,1:主厅, 2:附厅, 3:序厅")
+    private Integer type;
+
+    @NotBlank(message = "音频图标不能为空")
+    @ApiModelProperty(value = "音频图标url", required = true)
+    private String icon;
+
+//    @ApiModelProperty(value = "二维码url")
+//    private String qrCode;
+
+    @NotBlank(message = "音频文件不能为空")
+    @ApiModelProperty(value = "音频文件url", required = true)
+    private String audio;
+
+
+}

+ 35 - 0
gis_domain/src/main/java/com/gis/domain/po/SceneAudioEntity.java

@@ -0,0 +1,35 @@
+package com.gis.domain.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import java.io.Serializable;
+
+/**
+ * 场景音频
+ */
+@Data
+@Entity
+@Table(name = "tb_scene_audio")
+public class SceneAudioEntity extends BaseEntity implements Serializable {
+    private static final long serialVersionUID = 213587760750772822L;
+
+    @ApiModelProperty(value = "名称")
+    private String name;
+
+    @ApiModelProperty(value = "类型,1:主厅, 2:附厅, 3:序厅")
+    private Integer type;
+
+    @ApiModelProperty(value = "音频图标url")
+    private String icon;
+
+    @ApiModelProperty(value = "二维码url")
+    private String qrCode;
+
+    @ApiModelProperty(value = "音频文件url")
+    private String audio;
+
+
+}

+ 15 - 0
gis_mapper/src/main/java/com/gis/mapper/SceneAudioMapper.java

@@ -0,0 +1,15 @@
+package com.gis.mapper;
+
+
+import com.gis.domain.po.SceneAudioEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@Mapper
+public interface SceneAudioMapper extends IBaseMapper<SceneAudioEntity, Long> {
+
+
+
+}

+ 22 - 0
gis_service/src/main/java/com/gis/service/SceneAudioService.java

@@ -0,0 +1,22 @@
+package com.gis.service;
+
+
+import com.gis.common.util.Result;
+import com.gis.domain.dto.PageDateDto;
+import com.gis.domain.dto.SceneAudioDto;
+import com.gis.domain.po.SceneAudioEntity;
+import org.springframework.web.multipart.MultipartFile;
+
+
+/**
+ * Created by owen on 2020/5/12 0011 16:14
+ */
+public interface SceneAudioService extends IBaseService<SceneAudioEntity, Long> {
+
+
+    Result<SceneAudioEntity> search(PageDateDto param);
+
+    Result saveEntity(SceneAudioDto param);
+
+    Result upload(MultipartFile file, String type);
+}

+ 138 - 0
gis_service/src/main/java/com/gis/service/impl/SceneAudioServiceImpl.java

@@ -0,0 +1,138 @@
+package com.gis.service.impl;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.extra.qrcode.QrCodeUtil;
+import com.gis.common.constant.MsgCode;
+import com.gis.common.exception.BaseRuntimeException;
+import com.gis.common.util.FileUtils;
+import com.gis.common.util.Result;
+import com.gis.domain.dto.PageDateDto;
+import com.gis.domain.dto.SceneAudioDto;
+import com.gis.domain.po.SceneAudioEntity;
+import com.gis.mapper.IBaseMapper;
+import com.gis.mapper.SceneAudioMapper;
+import com.gis.service.SceneAudioService;
+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.web.multipart.MultipartFile;
+import tk.mybatis.mapper.entity.Condition;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+
+
+/**
+ * Created by owen on 2021/6/2 0011 16:16
+ */
+@Slf4j
+@Service
+public class SceneAudioServiceImpl extends IBaseServiceImpl<SceneAudioEntity, Long> implements SceneAudioService {
+
+    @Autowired
+    private SceneAudioMapper entityMapper;
+
+    @Override
+    public IBaseMapper<SceneAudioEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+    @Override
+    public Result<SceneAudioEntity> search(PageDateDto param) {
+        Condition condition = new Condition(SceneAudioEntity.class);
+        String searchKey = param.getSearchKey();
+        if (StringUtils.isNotBlank(searchKey)) {
+            condition.and().orLike("name", "%" + searchKey + "%");
+        }
+        String startTime = param.getStartTime();
+        String endTime = param.getEndTime();
+        if (StringUtils.isNotBlank(startTime) ) {
+            condition.and().andBetween("create_time", startTime, endTime);
+        }
+
+        return Result.success(this.findAll(condition, param.getPageNum(), param.getPageSize()));
+    }
+
+    @Override
+    public Result saveEntity(SceneAudioDto param) {
+        SceneAudioEntity entity = null;
+        Long id = param.getId();
+        if (id == null) {
+            entity = new SceneAudioEntity();
+            BeanUtils.copyProperties(param, entity);
+            entity.setQrCode(createQrCode(param.getAudio()));
+
+            // 默认值
+            this.save(entity);
+        } else {
+            entity = this.findById(id);
+            if (entity == null) {
+                return Result.failure("对象id不存在");
+            }
+
+            BeanUtils.copyProperties(param, entity);
+            entity.setUpdateTime(new Date());
+            this.update(entity);
+
+        }
+        return Result.success(entity);
+    }
+
+    private String createQrCode(String path){
+        String domian = configConstant.serverDomain + path;
+        log.info("domina: {}", domian);
+        String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
+        String middlePath = "sceneAudio/qrCode/";
+
+        String basePath = configConstant.serverBasePath + middlePath;
+        // 二维码工具不会自动创建目录
+        if (!FileUtil.isDirectory(basePath)) {
+            FileUtil.mkdir(basePath);
+        }
+        String url = middlePath + time + ".jpg";
+        String savePath = configConstant.serverBasePath + url;
+        QrCodeUtil.generate(domian, 200, 200, new File(savePath));
+        return url;
+    }
+
+    @Override
+    public Result upload(MultipartFile file, String type) {
+
+        if (!FileUtils.checkFile(file)) {
+            throw new BaseRuntimeException(MsgCode.e3002, "非法文件");
+        }
+        String middlePath = "sceneAudio/" + type + "/";
+        String basePath = configConstant.serverBasePath + middlePath;
+        String originalFilename = file.getOriginalFilename();
+        String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
+        String suffix = StringUtils.substringAfterLast(originalFilename, ".");
+        String fileName = time + "." + suffix;
+
+        String savePath = basePath + fileName;
+        try {
+            FileUtil.writeFromStream(file.getInputStream(), savePath);
+            HashMap<Object, Object> result = new HashMap<>();
+
+            // 前端访问url: ip + port/data + path, 需要使用data 前缀访问, data让前端自己配置
+//            Object urlPath = configConstant.serverUrlPrefix + middlePath + fileName;
+            Object urlPath = middlePath + fileName;
+            result.put("fileName", originalFilename);
+            result.put("path", urlPath);
+            log.info("upload result: {}", result);
+            return Result.success(result);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+
+        return null;
+    }
+
+
+}

+ 0 - 4
gis_web/pom.xml

@@ -17,10 +17,6 @@
             <groupId>com.gis</groupId>
             <artifactId>gis_service</artifactId>
         </dependency>
-        <!--<dependency>-->
-            <!--<groupId>junit</groupId>-->
-            <!--<artifactId>junit</artifactId>-->
-        <!--</dependency>-->
     </dependencies>
 
 

+ 89 - 0
gis_web/src/main/java/com/gis/web/controller/SceneAudioController.java

@@ -0,0 +1,89 @@
+package com.gis.web.controller;
+
+import com.gis.common.util.Result;
+import com.gis.domain.dto.SceneAudioDto;
+import com.gis.domain.dto.PageDateDto;
+import com.gis.domain.po.SceneAudioEntity;
+import com.gis.service.SceneAudioService;
+import com.gis.web.aop.WebControllerLog;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.validation.Valid;
+
+/**
+ * Created by owen on 2021/6/2 0008 9:54
+ */
+@Log4j2
+@Api(tags = "场景音频管理")
+@RestController
+@RequestMapping("manage/sceneAudio")
+public class SceneAudioController extends BaseController {
+
+    @Autowired
+    private SceneAudioService sceneAudioService;
+
+    @ApiOperation(value = "列表")
+    @PostMapping("list")
+    public Result<SceneAudioEntity> list(@RequestBody PageDateDto param) {
+        return sceneAudioService.search(param);
+    }
+
+    /**
+     * 图片类型,需要用到fileId
+     * 模型、视频 直接把信息放到entity里
+     * @param param
+     * @return
+     */
+    @WebControllerLog(description = "场景音频管理-新增/修改")
+    @ApiOperation("新增/修改")
+    @PostMapping("save")
+    public Result save(@Valid @RequestBody SceneAudioDto param) {
+        return sceneAudioService.saveEntity(param);
+    }
+
+    @WebControllerLog(description = "场景音频管理-删除")
+    @ApiOperation("删除")
+    @GetMapping("remove/{id}")
+    public Result remove(@PathVariable Long id) {
+
+        SceneAudioEntity entity = sceneAudioService.findById(id);
+
+        if (entity == null) {
+            log.error("对象id不存在: {}", id);
+            return Result.failure("对象id不存在");
+        }
+
+        deleteFile(entity.getAudio());
+        deleteFile(entity.getIcon());
+        deleteFile(entity.getQrCode());
+        sceneAudioService.deleteById(id);
+        return Result.success();
+    }
+
+        @ApiOperation("详情")
+    @GetMapping("detail/{id}")
+    public Result detail(@PathVariable Long id) {
+            SceneAudioEntity entity = sceneAudioService.findById(id);
+        if (entity == null) {
+            log.error("对象id不存在 : {}", id);
+            return Result.failure("对象id不存在");
+        }
+        return Result.success(entity);
+    }
+
+    @WebControllerLog(description = "场景音频管理-上传")
+    @ApiOperation(value = "上传文件", notes = "type: audio:音频, img:图片, 重命名文件, 前端访问:ip+port/data+path")
+    @PostMapping("material/upload/{type}")
+    public Result materialUpload(MultipartFile file, @PathVariable String type) {
+        return sceneAudioService.upload(file, type);
+    }
+
+}
+
+
+

+ 9 - 0
pom.xml

@@ -48,6 +48,7 @@
         <tk.mybatis.version>2.0.2</tk.mybatis.version>
         <tk.mapper.version>4.0.3</tk.mapper.version>
         <pagehelper.version>1.2.5</pagehelper.version>
+        <zxing.version>3.3.3</zxing.version>
 
     </properties>
 
@@ -236,6 +237,14 @@
                 <version>${pagehelper.version}</version>
             </dependency>
 
+
+            <!-- 二维码 -->
+            <dependency>
+                <groupId>com.google.zxing</groupId>
+                <artifactId>core</artifactId>
+                <version>${zxing.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>