Explorar el Código

新增上传安装包回调接口

wangliang hace 2 años
padre
commit
7a3117908d

+ 1 - 4
themis-admin/src/main/java/com/qmth/themis/admin/api/TSNotifyController.java

@@ -29,7 +29,6 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Objects;
@@ -100,8 +99,6 @@ public class TSNotifyController {
 
     /**
      * 刷新缓存信息并写入json文件
-     *
-     * @throws IOException
      */
     public void updateTsNotifyCache() {
         File file = null;
@@ -116,7 +113,7 @@ public class TSNotifyController {
             IOUtils.write(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
             ossUtil.upload(true, UploadFileEnum.client.name() + "/" + SystemConstant.EXAM_CONFIG_FILE_NAME, file);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof BusinessException) {
                 throw new BusinessException(e.getMessage());
             } else {

+ 24 - 7
themis-business/src/main/java/com/qmth/themis/business/dto/response/TBOrgBean.java

@@ -1,28 +1,33 @@
 package com.qmth.themis.business.dto.response;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import io.swagger.annotations.ApiModelProperty;
 
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
-/** 
-* @Description: 机构 bean
-* @Param:  
-* @return:  
-* @Author: wangliang
-* @Date: 2020/8/3 
-*/ 
+/**
+ * @Description: 机构 bean
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/8/3
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class TBOrgBean implements Serializable {
 
     @JsonSerialize(using = ToStringSerializer.class)
     @ApiModelProperty(name = "机构id")
+    @NotNull(message = "机构id不能为空")
     private Long id;//机构id
 
     @ApiModelProperty(name = "机构名称")
     private String name;//机构名称
 
     @ApiModelProperty(name = "机构代码")
+    @NotNull(message = "机构代码不能为空")
     private String code;//机构代码
 
     @ApiModelProperty(name = "机构logo")
@@ -31,6 +36,10 @@ public class TBOrgBean implements Serializable {
     @ApiModelProperty(name = "是否启用,0:停用,1:启用")
     private Integer enable;//是否启用
 
+    @ApiModelProperty(name = "安装包地址")
+    @NotNull(message = "安装包地址不能为空")
+    private String packagePath;
+
     public String getLogo() {
         return logo;
     }
@@ -70,4 +79,12 @@ public class TBOrgBean implements Serializable {
     public void setEnable(Integer enable) {
         this.enable = enable;
     }
+
+    public String getPackagePath() {
+        return packagePath;
+    }
+
+    public void setPackagePath(String packagePath) {
+        this.packagePath = packagePath;
+    }
 }

+ 12 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TBOrg.java

@@ -8,6 +8,7 @@ import com.qmth.themis.business.util.UidUtil;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import javax.validation.constraints.NotNull;
 import java.util.Objects;
 
 /**
@@ -69,6 +70,9 @@ public class TBOrg extends BaseEntity {
     @TableField(value = "enable_monitor_record")
     private Integer enableMonitorRecord;
 
+    @ApiModelProperty(name = "安装包地址")
+    private String packagePath;
+
     public TBOrg() {
 
     }
@@ -182,6 +186,14 @@ public class TBOrg extends BaseEntity {
         this.accessSecret = accessSecret;
     }
 
+    public String getPackagePath() {
+        return packagePath;
+    }
+
+    public void setPackagePath(String packagePath) {
+        this.packagePath = packagePath;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;

+ 2 - 7
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -20,10 +20,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -107,9 +104,7 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
     @Cacheable(value = SystemConstant.orgCodeCache, key = "#p0", unless = "#result == null")
     public TBOrg addOrgCodeCache(String code) {
         TBOrg tbOrg = tbOrgService.getOne(new QueryWrapper<TBOrg>().lambda().eq(TBOrg::getCode, code));
-        if (Objects.isNull(tbOrg)) {
-            throw new BusinessException(ExceptionResultEnum.ORG_NO);
-        }
+        Optional.ofNullable(tbOrg).orElseThrow(() -> new BusinessException(ExceptionResultEnum.ORG_NO));
         return tbOrg;
     }
 

+ 23 - 1
themis-exam/src/main/java/com/qmth/themis/exam/api/SysController.java

@@ -15,12 +15,15 @@ import com.qmth.themis.business.enums.UploadFileEnum;
 import com.qmth.themis.business.service.TBClientVersionService;
 import com.qmth.themis.business.service.TBOrgService;
 import com.qmth.themis.business.service.ThemisCacheService;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.GsonUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.DictionaryConfig;
 import io.swagger.annotations.*;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -36,6 +39,7 @@ import java.util.Optional;
 @Api(tags = "系统信息Controller")
 @RestController
 @RequestMapping(SystemConstant.PREFIX_URL_OE + "/sys")
+@Validated
 public class SysController {
 
     @Resource
@@ -92,11 +96,29 @@ public class SysController {
 
     @ApiOperation(value = "获取所有学校接口")
     @RequestMapping(value = "/school/list", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "系统通知信息", response = TBOrg.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "学校信息", response = TBOrgBean.class)})
     public Result schoolList() {
         List<TBOrg> tbOrgList = tbOrgService.list();
         List<TBOrgBean> tbOrgBeanList = GsonUtil.fromJson(GsonUtil.toJson(tbOrgList), new TypeToken<List<TBOrgBean>>() {
         }.getType());
         return ResultUtil.ok(tbOrgBeanList);
     }
+
+    @ApiOperation(value = "上传安装包回调接口")
+    @RequestMapping(value = "/upload/package/callback", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    public Result uploadPackageCallback(@Validated @ApiParam(value = "学校信息", required = true) @RequestBody TBOrgBean tbOrgBean, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        TBOrg tbOrg = themisCacheService.addOrgCache(tbOrgBean.getId());
+        Optional.ofNullable(tbOrg).orElseThrow(() -> new BusinessException(ExceptionResultEnum.ORG_NO));
+
+        tbOrg.setPackagePath(tbOrgBean.getPackagePath());
+        tbOrgService.updateById(tbOrg);
+
+        themisCacheService.updateOrgCache(tbOrgBean.getId());
+        themisCacheService.updateOrgCodeCache(tbOrgBean.getCode());
+        return ResultUtil.ok(true);
+    }
 }