Files
FT546MWS/dosc/license/SysLicenseController.java
1009473166@qq.com 0a021caba6 1
2026-07-31 10:16:48 +08:00

128 lines
3.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ruoyi.web.controller.system.license;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.license.domain.SysLicense;
import com.ruoyi.license.service.ISysLicenseService;
import com.ruoyi.license.util.LicenseUtils;
/**
* 授权码Controller
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/license")
public class SysLicenseController extends BaseController
{
@Autowired
private ISysLicenseService sysLicenseService;
/**
* 查询授权码列表
*/
@PreAuthorize("@ss.hasPermi('system:license:list')")
@GetMapping("/list")
public TableDataInfo list(SysLicense sysLicense)
{
startPage();
List<SysLicense> list = sysLicenseService.selectSysLicenseList(sysLicense);
return getDataTable(list);
}
/**
* 新增授权码
*/
@PreAuthorize("@ss.hasPermi('system:license:add')")
@Log(title = "授权码", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(SysLicense sysLicense)
{
return toAjax(sysLicenseService.insertSysLicense(sysLicense));
}
/**
* 修改授权码
*/
@PreAuthorize("@ss.hasPermi('system:license:edit')")
@Log(title = "授权码", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
public AjaxResult edit(SysLicense sysLicense)
{
return toAjax(sysLicenseService.updateSysLicense(sysLicense));
}
/**
* 删除授权码
*/
@PreAuthorize("@ss.hasPermi('system:license:remove')")
@Log(title = "授权码", businessType = BusinessType.DELETE)
@PostMapping("/remove")
public AjaxResult remove(String ids)
{
return toAjax(sysLicenseService.deleteSysLicenseByIds(ids));
}
/**
* 激活授权码(无需登录)
*/
@Log(title = "激活授权码", businessType = BusinessType.UPDATE)
@PostMapping("/active")
public AjaxResult active(String licenseCode)
{
if (!LicenseUtils.validateFormat(licenseCode))
{
return error("授权码格式不正确");
}
int result = sysLicenseService.activeLicense(licenseCode);
if (result > 0)
{
return success("授权码激活成功");
}
return error("授权码激活失败,请检查授权码是否正确或已过期");
}
/**
* 获取当前授权信息
* license 未开启或无有效授权时返回 code=200 data=null,前端静默处理
*/
@PreAuthorize("@ss.hasPermi('system:license:list')")
@GetMapping("/info")
public AjaxResult info()
{
SysLicense license = sysLicenseService.getActiveLicense();
return AjaxResult.success(license);
}
/**
* 生成授权码
*/
@PreAuthorize("@ss.hasPermi('system:license:add')")
@GetMapping("/generate")
public AjaxResult generate(String type, String projectNo)
{
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(projectNo))
{
return error("授权类型和项目编号不能为空");
}
String licenseCode = LicenseUtils.generateLicense(type, projectNo);
if (licenseCode == null)
{
return error("授权码生成失败");
}
return AjaxResult.success("授权码生成成功", licenseCode);
}
}