TSAuthController.java 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.qmth.distributed.print.api;
  2. import com.qmth.boot.api.constant.ApiConstant;
  3. import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
  4. import com.qmth.distributed.print.business.bean.dto.TSAuthDto;
  5. import com.qmth.distributed.print.business.service.AuthInfoService;
  6. import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
  7. import com.qmth.teachcloud.common.contant.SystemConstant;
  8. import com.qmth.teachcloud.common.entity.BasicSchool;
  9. import com.qmth.teachcloud.common.service.CommonCacheService;
  10. import com.qmth.teachcloud.common.util.Result;
  11. import com.qmth.teachcloud.common.util.ResultUtil;
  12. import com.qmth.teachcloud.common.util.ServletUtil;
  13. import io.swagger.annotations.*;
  14. import org.apache.commons.io.IOUtils;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.validation.annotation.Validated;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestMethod;
  20. import org.springframework.web.bind.annotation.RequestParam;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import javax.annotation.Resource;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.io.ByteArrayInputStream;
  26. import java.io.IOException;
  27. import java.util.Objects;
  28. /**
  29. * <p>
  30. * 激活授权配置表 前端控制器
  31. * </p>
  32. *
  33. * @author wangliang
  34. * @since 2022-04-26
  35. */
  36. @Api(tags = "授权配置Controller")
  37. @RestController
  38. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.auth}")
  39. @Validated
  40. public class TSAuthController {
  41. private final static Logger log = LoggerFactory.getLogger(TSAuthController.class);
  42. @Resource
  43. AuthInfoService authInfoService;
  44. @Resource
  45. CommonCacheService commonCacheService;
  46. @ApiOperation(value = "导出硬件信息")
  47. @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = TSAuthDto.class)})
  48. @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)
  49. public void info() {
  50. try {
  51. HttpServletResponse response = ServletUtil.getResponse();
  52. response.setHeader("Content-Disposition", "attachment; filename=" + SystemConstant.urlEncode("device.info"));
  53. IOUtils.copy(new ByteArrayInputStream(AppLicenseUtil.buildDeviceInfo().value()), response.getOutputStream());
  54. } catch (Exception e) {
  55. log.error(SystemConstant.LOG_ERROR, e);
  56. }
  57. }
  58. @ApiOperation(value = "离线激活")
  59. @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
  60. @RequestMapping(value = "/offline/activation", method = RequestMethod.POST)
  61. public Result offlineActivation(@ApiParam(value = "上传文件", required = true) @RequestParam(required = true) MultipartFile file) {
  62. try {
  63. authInfoService.updateLicense(file.getBytes());
  64. } catch (IOException e) {
  65. e.printStackTrace();
  66. }
  67. return ResultUtil.ok(true);
  68. }
  69. @ApiOperation(value = "查询激活信息")
  70. @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
  71. @RequestMapping(value = "/select", method = RequestMethod.POST)
  72. public Result select() {
  73. Long schoolId = SystemConstant.getHeadOrUserSchoolId();
  74. Long expireTime = null;
  75. if (Objects.nonNull(schoolId)) {
  76. BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
  77. AuthOrgInfoDto authOrgInfoDto = commonCacheService.authInfoCache(basicSchool.getCode());
  78. if (Objects.nonNull(authOrgInfoDto) && Objects.nonNull(authOrgInfoDto.getControl())) {
  79. expireTime = authOrgInfoDto.getControl().getExpireTime();
  80. }
  81. }
  82. return ResultUtil.ok(expireTime);
  83. }
  84. }