|
@@ -2,17 +2,29 @@ package com.qmth.themis.admin.api;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TBAttachment;
|
|
|
import com.qmth.themis.business.entity.TBClientVersion;
|
|
|
+import com.qmth.themis.business.entity.TBUser;
|
|
|
+import com.qmth.themis.business.enums.UploadFileEnum;
|
|
|
+import com.qmth.themis.business.service.TBAttachmentService;
|
|
|
import com.qmth.themis.business.service.TBClientVersionService;
|
|
|
+import com.qmth.themis.business.util.OssUtil;
|
|
|
+import com.qmth.themis.business.util.ServletUtil;
|
|
|
+import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.util.Result;
|
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @Description: 客户端 前端控制器
|
|
@@ -30,6 +42,46 @@ public class TBClientVersionController {
|
|
|
@Resource
|
|
|
TBClientVersionService tbClientVersionService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ OssUtil ossUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBAttachmentService tbAttachmentService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "客户端上传附件接口")
|
|
|
+ @RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
+ @Transactional
|
|
|
+ public Result upload(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
|
|
|
+ @ApiParam(value = "版本号", required = true) @RequestParam String version) {
|
|
|
+ if (Objects.isNull(file) || Objects.equals(file, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(version) || Objects.equals(version, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.VERSION_IS_NULL);
|
|
|
+ }
|
|
|
+ Map<String, Object> mapParameter = ossUtil.getAliYunOssPublicDomain().getMap();
|
|
|
+ TBAttachment tbAttachment = null;
|
|
|
+ try {
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
+ mapParameter.put(SystemConstant.VERSION, version);
|
|
|
+ tbAttachment = tbAttachmentService
|
|
|
+ .saveAttachment(file, ServletUtil.getRequestMd5(), ServletUtil.getRequestPath(), mapParameter,
|
|
|
+ UploadFileEnum.client, tbUser.getOrgId(), tbUser.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("请求出错", e);
|
|
|
+ if (Objects.nonNull(tbAttachment)) {
|
|
|
+ tbAttachmentService.deleteAttachment(mapParameter, UploadFileEnum.client, tbAttachment);
|
|
|
+ }
|
|
|
+ if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "客户端版本新增/编辑接口")
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|