feat: 激活码导入
This commit is contained in:
@@ -18,6 +18,7 @@ import org.agt.framework.dict.core.DictFrameworkUtils;
|
||||
import org.agt.framework.excel.core.util.ExcelUtils;
|
||||
import org.agt.framework.translate.core.TranslateUtils;
|
||||
import org.agt.module.license.controller.admin.license.vo.ImportRespVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseCodeImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseDetailVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
|
||||
@@ -244,6 +245,19 @@ public class LicenseController {
|
||||
return success(licenseService.importList(list, updateSupport));
|
||||
}
|
||||
|
||||
@PostMapping("/code-import")
|
||||
@Operation(summary = "导入License的激活码")
|
||||
@Parameters({
|
||||
@Parameter(name = "file", description = "Excel 文件", required = true),
|
||||
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('license:license:import')")
|
||||
public CommonResult<ImportRespVO> importCodeExcel(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||
List<LicenseCodeImportExcelVO> list = ExcelUtils.read(file, LicenseCodeImportExcelVO.class);
|
||||
return success(licenseService.importCodeList(list, updateSupport));
|
||||
}
|
||||
|
||||
@PutMapping("/update-detail")
|
||||
@Operation(summary = "更新License明细")
|
||||
@PreAuthorize("@ss.hasPermission('license:license:update')")
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.agt.module.license.controller.admin.license.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @description: 导入激活码excelVO
|
||||
* @author: cyc
|
||||
* @since: 2025-08-28
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = false) // 设置 chain = false,避免导入有问题
|
||||
@ExcelIgnoreUnannotated
|
||||
public class LicenseCodeImportExcelVO {
|
||||
|
||||
@Schema(description = "SN")
|
||||
@ExcelProperty("SN")
|
||||
private String serialNo;
|
||||
|
||||
@Schema(description = "Customer")
|
||||
@ExcelProperty("Customer")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "Activation Code")
|
||||
@ExcelProperty("Activation Code")
|
||||
private String activationCode;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.agt.module.license.service.license;
|
||||
import jakarta.validation.Valid;
|
||||
import org.agt.framework.common.pojo.PageResult;
|
||||
import org.agt.module.license.controller.admin.license.vo.ImportRespVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseCodeImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseDetailVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
|
||||
@@ -95,5 +96,7 @@ public interface LicenseService {
|
||||
|
||||
ImportRespVO importList(List<LicenseImportExcelVO> list, Boolean updateSupport);
|
||||
|
||||
ImportRespVO importCodeList(List<LicenseCodeImportExcelVO> list, Boolean updateSupport);
|
||||
|
||||
void updateDetailById(LicenseDetailVO licenseDetail);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import org.agt.framework.dict.core.DictFrameworkUtils;
|
||||
import org.agt.framework.web.core.util.WebFrameworkUtils;
|
||||
import org.agt.module.infra.api.file.FileApi;
|
||||
import org.agt.module.license.controller.admin.license.vo.ImportRespVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseCodeImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseDetailVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicenseImportExcelVO;
|
||||
import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
|
||||
@@ -818,6 +819,104 @@ public class LicenseServiceImpl implements LicenseService {
|
||||
return respVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImportRespVO importCodeList(List<LicenseCodeImportExcelVO> list, Boolean updateSupport) {
|
||||
|
||||
ImportRespVO respVO = ImportRespVO.builder().creates(new ArrayList<>())
|
||||
.updates(new ArrayList<>()).failures(new LinkedHashMap<>()).build();
|
||||
// list = list.stream().filter(c -> StrUtil.isNotBlank(c.getSerialNo())).collect(Collectors.toList());
|
||||
|
||||
String lastSn = "";
|
||||
String lastCustomer = "";
|
||||
for (LicenseCodeImportExcelVO importVO : list) {
|
||||
if (StrUtil.isBlank(importVO.getSerialNo())) {
|
||||
importVO.setSerialNo(lastSn);
|
||||
}
|
||||
if (StrUtil.isBlank(importVO.getCustomerName())) {
|
||||
importVO.setCustomerName(lastCustomer);
|
||||
}
|
||||
lastSn = importVO.getSerialNo();
|
||||
lastCustomer = importVO.getCustomerName();
|
||||
}
|
||||
for (LicenseCodeImportExcelVO importExcelVO : list) {
|
||||
String serialNo = importExcelVO.getSerialNo().trim();
|
||||
if (StrUtil.isBlank(importExcelVO.getCustomerName())) {
|
||||
continue;
|
||||
}
|
||||
String customerName = importExcelVO.getCustomerName().trim();
|
||||
String regex = "\\d{8}";
|
||||
|
||||
if (!serialNo.matches(regex) && customerName.matches(regex)) {
|
||||
importExcelVO.setSerialNo(customerName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<String, List<LicenseCodeImportExcelVO>> map = list.stream().collect(Collectors.groupingBy(LicenseCodeImportExcelVO::getSerialNo));
|
||||
|
||||
List<LicenseCodeImportExcelVO> newImportList = new ArrayList<>();
|
||||
for (Map.Entry<String, List<LicenseCodeImportExcelVO>> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
List<LicenseCodeImportExcelVO> value = entry.getValue();
|
||||
|
||||
List<String> codeList = new ArrayList<>();
|
||||
for (LicenseCodeImportExcelVO importVO : value) {
|
||||
if (StrUtil.isBlank(importVO.getActivationCode())) {
|
||||
respVO.getFailures().put(key, "没有找到激活码");
|
||||
continue;
|
||||
}
|
||||
String activationCode = importVO.getActivationCode();
|
||||
if (activationCode.contains(":")) {
|
||||
activationCode = activationCode.substring(activationCode.indexOf(":") + 1);
|
||||
}
|
||||
if (activationCode.matches("^[A-Z0-9]{20,}$")) {
|
||||
codeList.add(activationCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (CollUtil.isEmpty(codeList)) {
|
||||
respVO.getFailures().put(key, "没有找到激活码");
|
||||
continue;
|
||||
}
|
||||
if (CollUtil.isNotEmpty(codeList) && codeList.size() > 1) {
|
||||
respVO.getFailures().put(key, "激活码有多个");
|
||||
continue;
|
||||
}
|
||||
LicenseCodeImportExcelVO newImportVO = new LicenseCodeImportExcelVO();
|
||||
newImportVO.setSerialNo(key);
|
||||
newImportVO.setActivationCode(codeList.get(0));
|
||||
newImportList.add(newImportVO);
|
||||
}
|
||||
|
||||
for (LicenseCodeImportExcelVO newImportVO : newImportList) {
|
||||
List<LicenseDO> licenseDOS = licenseMapper.selectList(Wrappers.<LicenseDO>lambdaQuery()
|
||||
.eq(LicenseDO::getSerialNo, newImportVO.getSerialNo()).eq(LicenseDO::getDataType, 1));
|
||||
Optional<LicenseDO> first = licenseDOS.stream().findFirst();
|
||||
if (!first.isPresent()) {
|
||||
respVO.getFailures().put(newImportVO.getSerialNo(), "没有找到该SN");
|
||||
continue;
|
||||
}
|
||||
LicenseDO licenseDO = first.get();
|
||||
LicenseDetailDO licenseDetailDO = licenseDetailMapper.selectOne(Wrappers.<LicenseDetailDO>lambdaQuery().eq(LicenseDetailDO::getLicenseId, licenseDO.getId()), false);
|
||||
if (licenseDetailDO == null) {
|
||||
respVO.getFailures().put(newImportVO.getSerialNo(), "没有找到网元");
|
||||
continue;
|
||||
}
|
||||
if (!updateSupport && StrUtil.isNotBlank(licenseDetailDO.getActivationCode())) {
|
||||
respVO.getFailures().put(newImportVO.getSerialNo(), "激活码已存在");
|
||||
continue;
|
||||
}
|
||||
licenseDetailDO.setActivationCode(newImportVO.getActivationCode());
|
||||
// licenseDetailMapper.updateById(licenseDetailDO);
|
||||
if (StrUtil.isNotBlank(licenseDetailDO.getActivationCode())) {
|
||||
respVO.getCreates().add(newImportVO.getSerialNo());
|
||||
}
|
||||
}
|
||||
|
||||
return respVO;
|
||||
}
|
||||
|
||||
private static LocalDateTime getCreateTime(LicenseImportExcelVO importVO) {
|
||||
LocalDateTime createTime = LocalDateTime.now();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user