1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package com.qmth.distributed.print.api;
- import com.qmth.boot.api.constant.ApiConstant;
- import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
- import com.qmth.distributed.print.business.bean.dto.TSAuthDto;
- import com.qmth.distributed.print.business.service.AuthInfoService;
- import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
- import com.qmth.teachcloud.common.contant.SystemConstant;
- import com.qmth.teachcloud.common.entity.BasicSchool;
- import com.qmth.teachcloud.common.service.CommonCacheService;
- import com.qmth.teachcloud.common.util.Result;
- import com.qmth.teachcloud.common.util.ResultUtil;
- import com.qmth.teachcloud.common.util.ServletUtil;
- import io.swagger.annotations.*;
- import org.apache.commons.io.IOUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.util.Objects;
- /**
- * <p>
- * 激活授权配置表 前端控制器
- * </p>
- *
- * @author wangliang
- * @since 2022-04-26
- */
- @Api(tags = "授权配置Controller")
- @RestController
- @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.auth}")
- @Validated
- public class TSAuthController {
- private final static Logger log = LoggerFactory.getLogger(TSAuthController.class);
- @Resource
- AuthInfoService authInfoService;
- @Resource
- CommonCacheService commonCacheService;
- @ApiOperation(value = "导出硬件信息")
- @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = TSAuthDto.class)})
- @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)
- public void info() {
- try {
- HttpServletResponse response = ServletUtil.getResponse();
- response.setHeader("Content-Disposition", "attachment; filename=" + SystemConstant.urlEncode("device.info"));
- IOUtils.copy(new ByteArrayInputStream(AppLicenseUtil.buildDeviceInfo().value()), response.getOutputStream());
- } catch (Exception e) {
- log.error(SystemConstant.LOG_ERROR, e);
- }
- }
- @ApiOperation(value = "离线激活")
- @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
- @RequestMapping(value = "/offline/activation", method = RequestMethod.POST)
- public Result offlineActivation(@ApiParam(value = "上传文件", required = true) @RequestParam(required = true) MultipartFile file) {
- try {
- authInfoService.updateLicense(file.getBytes());
- } catch (IOException e) {
- e.printStackTrace();
- }
- return ResultUtil.ok(true);
- }
- @ApiOperation(value = "查询激活信息")
- @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
- @RequestMapping(value = "/select", method = RequestMethod.POST)
- public Result select() {
- Long schoolId = SystemConstant.getHeadOrUserSchoolId();
- Long expireTime = null;
- if (Objects.nonNull(schoolId)) {
- BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
- AuthOrgInfoDto authOrgInfoDto = commonCacheService.authInfoCache(basicSchool.getCode());
- if (Objects.nonNull(authOrgInfoDto) && Objects.nonNull(authOrgInfoDto.getControl())) {
- expireTime = authOrgInfoDto.getControl().getExpireTime();
- }
- }
- return ResultUtil.ok(expireTime);
- }
- }
|