feat: license管理模块添加
This commit is contained in:
@@ -14,4 +14,5 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode PROJECT_NOT_EXISTS = new ErrorCode(1_100_002_001, "项目不存在");
|
||||
ErrorCode PROJECT_NAME_DUPLICATE = new ErrorCode(1_100_001_002, "项目名称`{}`已存在");
|
||||
ErrorCode PROJECT_CODE_DUPLICATE = new ErrorCode(1_100_001_003, "项目编号`{}`已存在");
|
||||
ErrorCode LICENSE_NOT_EXISTS = new ErrorCode(1_100_002_001, "License不存在");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.agt.module.license.controller.admin.license;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.agt.framework.common.pojo.PageParam;
|
||||
import org.agt.framework.common.pojo.PageResult;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import org.agt.framework.common.util.object.BeanUtils;
|
||||
import static org.agt.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import org.agt.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import org.agt.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static org.agt.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import org.agt.module.license.controller.admin.license.vo.*;
|
||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||
import org.agt.module.license.service.license.LicenseService;
|
||||
|
||||
@Tag(name = "管理后台 - License")
|
||||
@RestController
|
||||
@RequestMapping("/license/license")
|
||||
@Validated
|
||||
public class LicenseController {
|
||||
|
||||
@Resource
|
||||
private LicenseService licenseService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建License")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:create')")
|
||||
public CommonResult<Long> createLicense(@Valid @RequestBody LicenseSaveReqVO createReqVO) {
|
||||
return success(licenseService.createLicense(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新License")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:update')")
|
||||
public CommonResult<Boolean> updateLicense(@Valid @RequestBody LicenseSaveReqVO updateReqVO) {
|
||||
licenseService.updateLicense(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除License")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('license:license:delete')")
|
||||
public CommonResult<Boolean> deleteLicense(@RequestParam("id") Long id) {
|
||||
licenseService.deleteLicense(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得License")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:query')")
|
||||
public CommonResult<LicenseRespVO> getLicense(@RequestParam("id") Long id) {
|
||||
LicenseDO license = licenseService.getLicense(id);
|
||||
return success(BeanUtils.toBean(license, LicenseRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得License分页")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:query')")
|
||||
public CommonResult<PageResult<LicenseRespVO>> getLicensePage(@Valid LicensePageReqVO pageReqVO) {
|
||||
PageResult<LicenseDO> pageResult = licenseService.getLicensePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, LicenseRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出License Excel")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportLicenseExcel(@Valid LicensePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<LicenseDO> list = licenseService.getLicensePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "License.xls", "数据", LicenseRespVO.class,
|
||||
BeanUtils.toBean(list, LicenseRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.agt.module.license.controller.admin.license.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.agt.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.agt.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - License分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LicensePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "客户ID", example = "31667")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "项目ID", example = "2496")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "sn")
|
||||
private String sn;
|
||||
|
||||
@Schema(description = "到期时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] expirationTime;
|
||||
|
||||
@Schema(description = "网元开关")
|
||||
private String neSwitch;
|
||||
|
||||
@Schema(description = "用户数")
|
||||
private Integer userNum;
|
||||
|
||||
@Schema(description = "基站数")
|
||||
private Integer baseStationNum;
|
||||
|
||||
@Schema(description = "激活码")
|
||||
private String activationCode;
|
||||
|
||||
@Schema(description = "License内容")
|
||||
private String licenseContent;
|
||||
|
||||
@Schema(description = "申请人")
|
||||
private Long applicant;
|
||||
|
||||
@Schema(description = "审批人")
|
||||
private Long approver;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.agt.module.license.controller.admin.license.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import org.agt.framework.excel.core.annotations.DictFormat;
|
||||
import org.agt.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - License Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class LicenseRespVO {
|
||||
|
||||
@Schema(description = "客户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31667")
|
||||
@ExcelProperty("客户ID")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2496")
|
||||
@ExcelProperty("项目ID")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "sn", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("sn")
|
||||
private String sn;
|
||||
|
||||
@Schema(description = "到期时间")
|
||||
@ExcelProperty("到期时间")
|
||||
private LocalDateTime expirationTime;
|
||||
|
||||
@Schema(description = "网元开关")
|
||||
@ExcelProperty(value = "网元开关", converter = DictConvert.class)
|
||||
@DictFormat("lic_ne_switch") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private String neSwitch;
|
||||
|
||||
@Schema(description = "用户数")
|
||||
@ExcelProperty("用户数")
|
||||
private Integer userNum;
|
||||
|
||||
@Schema(description = "基站数")
|
||||
@ExcelProperty("基站数")
|
||||
private Integer baseStationNum;
|
||||
|
||||
@Schema(description = "激活码")
|
||||
@ExcelProperty("激活码")
|
||||
private String activationCode;
|
||||
|
||||
@Schema(description = "License内容")
|
||||
@ExcelProperty("License内容")
|
||||
private String licenseContent;
|
||||
|
||||
@Schema(description = "申请人")
|
||||
@ExcelProperty("申请人")
|
||||
private Long applicant;
|
||||
|
||||
@Schema(description = "审批人")
|
||||
@ExcelProperty("审批人")
|
||||
private Long approver;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat("lic_license_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.agt.module.license.controller.admin.license.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - License新增/修改 Request VO")
|
||||
@Data
|
||||
public class LicenseSaveReqVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "24876")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "客户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31667")
|
||||
@NotNull(message = "客户ID不能为空")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2496")
|
||||
@NotNull(message = "项目ID不能为空")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "sn", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "sn不能为空")
|
||||
private String sn;
|
||||
|
||||
@Schema(description = "到期时间")
|
||||
private LocalDateTime expirationTime;
|
||||
|
||||
@Schema(description = "网元开关")
|
||||
private String neSwitch;
|
||||
|
||||
@Schema(description = "用户数")
|
||||
private Integer userNum;
|
||||
|
||||
@Schema(description = "基站数")
|
||||
private Integer baseStationNum;
|
||||
|
||||
@Schema(description = "激活码")
|
||||
private String activationCode;
|
||||
|
||||
@Schema(description = "License内容")
|
||||
private String licenseContent;
|
||||
|
||||
@Schema(description = "申请人")
|
||||
private Long applicant;
|
||||
|
||||
@Schema(description = "审批人")
|
||||
private Long approver;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.agt.module.license.dal.dataobject.license;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import org.agt.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* License DO
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@TableName("lic_license")
|
||||
@KeySequence("lic_license_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LicenseDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
private Long customerId;
|
||||
/**
|
||||
* 项目ID
|
||||
*/
|
||||
private Long projectId;
|
||||
/**
|
||||
* sn
|
||||
*/
|
||||
private String sn;
|
||||
/**
|
||||
* 到期时间
|
||||
*/
|
||||
private LocalDateTime expirationTime;
|
||||
/**
|
||||
* 网元开关
|
||||
*
|
||||
* 枚举 {@link TODO lic_ne_switch 对应的类}
|
||||
*/
|
||||
private String neSwitch;
|
||||
/**
|
||||
* 用户数
|
||||
*/
|
||||
private Integer userNum;
|
||||
/**
|
||||
* 基站数
|
||||
*/
|
||||
private Integer baseStationNum;
|
||||
/**
|
||||
* 激活码
|
||||
*/
|
||||
private String activationCode;
|
||||
/**
|
||||
* License内容
|
||||
*/
|
||||
private String licenseContent;
|
||||
/**
|
||||
* 申请人
|
||||
*/
|
||||
private Long applicant;
|
||||
/**
|
||||
* 审批人
|
||||
*/
|
||||
private Long approver;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link TODO lic_license_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.agt.module.license.dal.mysql.license;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.agt.framework.common.pojo.PageResult;
|
||||
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.agt.module.license.controller.admin.license.vo.*;
|
||||
|
||||
/**
|
||||
* License Mapper
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface LicenseMapper extends BaseMapperX<LicenseDO> {
|
||||
|
||||
default PageResult<LicenseDO> selectPage(LicensePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<LicenseDO>()
|
||||
.eqIfPresent(LicenseDO::getCustomerId, reqVO.getCustomerId())
|
||||
.eqIfPresent(LicenseDO::getProjectId, reqVO.getProjectId())
|
||||
.likeIfPresent(LicenseDO::getSn, reqVO.getSn())
|
||||
.betweenIfPresent(LicenseDO::getExpirationTime, reqVO.getExpirationTime())
|
||||
.eqIfPresent(LicenseDO::getNeSwitch, reqVO.getNeSwitch())
|
||||
.eqIfPresent(LicenseDO::getUserNum, reqVO.getUserNum())
|
||||
.eqIfPresent(LicenseDO::getBaseStationNum, reqVO.getBaseStationNum())
|
||||
.eqIfPresent(LicenseDO::getActivationCode, reqVO.getActivationCode())
|
||||
.eqIfPresent(LicenseDO::getLicenseContent, reqVO.getLicenseContent())
|
||||
.eqIfPresent(LicenseDO::getApplicant, reqVO.getApplicant())
|
||||
.eqIfPresent(LicenseDO::getApprover, reqVO.getApprover())
|
||||
.eqIfPresent(LicenseDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(LicenseDO::getRemark, reqVO.getRemark())
|
||||
.betweenIfPresent(LicenseDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(LicenseDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.agt.module.license.service.license;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import org.agt.module.license.controller.admin.license.vo.*;
|
||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||
import org.agt.framework.common.pojo.PageResult;
|
||||
import org.agt.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* License Service 接口
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
public interface LicenseService {
|
||||
|
||||
/**
|
||||
* 创建License
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createLicense(@Valid LicenseSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新License
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateLicense(@Valid LicenseSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除License
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteLicense(Long id);
|
||||
|
||||
/**
|
||||
* 获得License
|
||||
*
|
||||
* @param id 编号
|
||||
* @return License
|
||||
*/
|
||||
LicenseDO getLicense(Long id);
|
||||
|
||||
/**
|
||||
* 获得License分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return License分页
|
||||
*/
|
||||
PageResult<LicenseDO> getLicensePage(LicensePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.agt.module.license.service.license;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import org.agt.module.license.controller.admin.license.vo.*;
|
||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||
import org.agt.framework.common.pojo.PageResult;
|
||||
import org.agt.framework.common.pojo.PageParam;
|
||||
import org.agt.framework.common.util.object.BeanUtils;
|
||||
|
||||
import org.agt.module.license.dal.mysql.license.LicenseMapper;
|
||||
|
||||
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static org.agt.module.license.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* License Service 实现类
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class LicenseServiceImpl implements LicenseService {
|
||||
|
||||
@Resource
|
||||
private LicenseMapper licenseMapper;
|
||||
|
||||
@Override
|
||||
public Long createLicense(LicenseSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
LicenseDO license = BeanUtils.toBean(createReqVO, LicenseDO.class);
|
||||
licenseMapper.insert(license);
|
||||
// 返回
|
||||
return license.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLicense(LicenseSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateLicenseExists(updateReqVO.getId());
|
||||
// 更新
|
||||
LicenseDO updateObj = BeanUtils.toBean(updateReqVO, LicenseDO.class);
|
||||
licenseMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLicense(Long id) {
|
||||
// 校验存在
|
||||
validateLicenseExists(id);
|
||||
// 删除
|
||||
licenseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateLicenseExists(Long id) {
|
||||
if (licenseMapper.selectById(id) == null) {
|
||||
throw exception(LICENSE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LicenseDO getLicense(Long id) {
|
||||
return licenseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<LicenseDO> getLicensePage(LicensePageReqVO pageReqVO) {
|
||||
return licenseMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.agt.module.license.dal.mysql.license.LicenseMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user