yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.qianwen.smartman.modules.cps.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.smartboot.license.client.License;
import org.smartboot.license.client.LicenseEntity;
import org.smartboot.license.client.LicenseException;
import com.qianwen.smartman.common.utils.LicenseUtil;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.tool.api.R;
import com.qianwen.smartman.modules.cps.enums.AppEnum;
import com.qianwen.smartman.modules.cps.service.IInitService;
import com.qianwen.smartman.modules.cps.vo.AppVO;
import com.qianwen.smartman.modules.cps.vo.ConfigVO;
import com.qianwen.smartman.modules.cps.vo.InitSettingVO;
import com.qianwen.smartman.modules.system.convert.LicenseConverter;
import com.qianwen.smartman.modules.system.dto.AppNameDesDTO;
import com.qianwen.smartman.modules.system.dto.LicenseDetailDTO;
import com.qianwen.smartman.modules.system.vo.LicenseDetailVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
@RequestMapping({"smis/init"})
@Api(value = "引导页初始化", tags = {"引导页初始化"})
@RestController
@Validated
public class InitController extends BladeController {
    private final IInitService initService;
 
    public InitController(final IInitService initService) {
        this.initService = initService;
    }
 
    @GetMapping({"/checkIsNeedInit"})
    @ApiOperation("判断是否需要进入引导页")
    public R<Boolean> checkIsNeedInit() {
        return R.data(this.initService.checkIsNeedInit());
    }
 
    @GetMapping({"/get-config"})
    @ApiOperation("获得配置")
    public R<ConfigVO> getConfig() {
        return R.data(this.initService.getConfig());
    }
 
    @GetMapping({"/get-app"})
    @ApiOperation("获得APP设置")
    public R<List<AppVO>> getApp() {
        return R.data(this.initService.getApp());
    }
 
    @PostMapping({"/init-system"})
    @ApiOperation("初始化")
    public R<Boolean> initSystem(@Validated @RequestBody InitSettingVO initSettingVO) {
        initSettingVO.setAppList(this.initService.getApp().stream().map(AppVO::getCode).collect(Collectors.toList()));
        return R.data(this.initService.init(initSettingVO));
        
    }
 
    @PostMapping({"/license-upload"})
    @ApiOperation("上传系统密钥文件")
    public R<Boolean> licenseUpload(@RequestParam MultipartFile file) throws IOException {
        String text = new String(file.getBytes());
        try {
            LicenseEntity licenseEntity = new License().loadLicense(text);
            LicenseUtil.macValid(licenseEntity);
            LicenseUtil.getLicenseMap().put("000000", text);
            return R.success("上传成功");
        } catch (LicenseException e) {
            return R.fail(MessageUtils.message("system.license.expired", new Object[0]));
        }
    }
 
    @GetMapping({"license-detail"})
    @ApiOperation("获取上传密钥详情")
    public R<LicenseDetailVO> licenseDetail() {
        LicenseDetailDTO detailDTO = this.initService.licenseDetail();
        if (detailDTO == null) {
            return R.data( null);
        }
        
        List<AppEnum> enums = AppEnum.of(detailDTO.getModules().toArray(new Integer[0]));
        Map<String, List<String>> collect = enums.stream().map(e -> AppNameDesDTO.builder().business(e.getBusiness()).desc(e.getDesc()).build()).collect(Collectors.groupingBy(AppNameDesDTO::getBusiness, 
              Collectors.mapping(AppNameDesDTO::getDesc, Collectors.toList())));
        LicenseDetailVO detailVO = LicenseConverter.INSTANCE.convert(detailDTO, collect);
        return R.data(detailVO);
        /*
        List<AppEnum> enums = AppEnum.of((Integer[]) detailDTO.getModules().toArray(new Integer[0]));
        Map<String, List<String>> collect = (Map) enums.stream().map(e -> {
            return AppNameDesDTO.builder().business(e.getBusiness()).desc(e.getDesc()).build();
        }).collect(Collectors.groupingBy((v0) -> {
            return v0.getBusiness();
        }, Collectors.mapping((v0) -> {
            return v0.getDesc();
        }, Collectors.toList())));
        LicenseDetailVO detailVO = LicenseConverter.INSTANCE.convert(detailDTO, collect);
        return R.data(detailVO);
        */
    }
 
    @GetMapping({"/license-device"})
    @ApiOperation("获取设备mac地址")
    public R<String> licenseDevice() {
        return R.data(LicenseUtil.getMac());
    }
}