吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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);
 
    }
 
 
 
}