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());
|
}
|
}
|