package org.sxkj.system.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import feign.codec.Encoder;
|
import feign.form.spring.SpringFormEncoder;
|
import org.springblade.core.oss.model.BladeFile;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestPart;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.sxkj.common.utils.license.LicenseData;
|
import org.sxkj.common.utils.license.LicenseUtils;
|
import org.sxkj.resource.feign.IAttachClient;
|
import org.sxkj.system.entity.ManageLicense;
|
import org.sxkj.system.mapper.ManageLicenseMapper;
|
import org.sxkj.system.service.IManageLicenseService;
|
|
import java.io.ByteArrayInputStream;
|
import java.io.IOException;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class ManageLicenseServiceImpl extends ServiceImpl<ManageLicenseMapper, ManageLicense> implements IManageLicenseService {
|
@Autowired
|
private IAttachClient attachClient;
|
|
@Override
|
public void createLicense(ManageLicense manageLicense) throws IOException {
|
LicenseData licenseData = new LicenseData();
|
licenseData.setLicenseId(manageLicense.getLicenseId());
|
licenseData.setLicenseName(manageLicense.getLicenseName());
|
licenseData.setLicenseType(manageLicense.getLicenseType());
|
licenseData.setExpireDay(manageLicense.getExpireDay());
|
String machineCode = manageLicense.getMachineCode();
|
if (!StringUtils.isEmpty(machineCode)) {
|
String[] codes = machineCode.split("\n");
|
licenseData.setMachineCode(Arrays.stream(codes).distinct().collect(Collectors.toList()));
|
}
|
licenseData.setCheckMachineCode(manageLicense.getCheckMachineCode());
|
licenseData.setPrintClientCount(manageLicense.getPrintClientCount());
|
//上传数据
|
byte[] bytes = LicenseUtils.genLicenseFile(licenseData);
|
//进行文件上传
|
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
String fileName = "License" + System.currentTimeMillis() + ".lic";
|
// 使用MinIO客户端上传图片
|
MockMultipartFile mockMultipartFile
|
= new MockMultipartFile("__init__.py", fileName, "application/octet-stream", stream);
|
// 关闭流
|
stream.close();
|
BladeFile bladeFile = attachClient.saveAttachFile(mockMultipartFile, fileName);
|
manageLicense.setUrl(bladeFile.getLink());
|
//上传
|
save(manageLicense);
|
|
}
|
|
|
|
}
|