|
|
@@ -1,9 +1,9 @@
|
|
|
package com.xunmei.iot.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -20,7 +20,6 @@ import com.xunmei.iot.service.IotServerInfoService;
|
|
|
import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
-import lombok.val;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -29,6 +28,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -46,11 +47,11 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<IotServerInfoPageVo> serverPage(IotServerInfoPageDto request) {
|
|
|
- if (request.getCheckSub()){
|
|
|
+ if (request.getCheckSub()) {
|
|
|
SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
|
|
|
request.setOrgPath(sysOrg.getPath());
|
|
|
}
|
|
|
- Page<IotServerInfoPageVo> page = baseMapper.selectServerPage(request.getPageRequest(),request);
|
|
|
+ Page<IotServerInfoPageVo> page = baseMapper.selectServerPage(request.getPageRequest(), request);
|
|
|
return TableDataInfo.build(page);
|
|
|
}
|
|
|
|
|
|
@@ -58,15 +59,20 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int addIotServer(IotServerInfoEditDto req) {
|
|
|
+ List<IotServerInfo> list = baseMapper.selectList(new LambdaQueryWrapper<IotServerInfo>()
|
|
|
+ .eq(IotServerInfo::getRegisterCodeStatus, 0)
|
|
|
+ .select(IotServerInfo::getRegisterCode));
|
|
|
+ List<String> collect = list.stream().map(IotServerInfo::getRegisterCode).collect(Collectors.toList());
|
|
|
SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
- val serverInfo = new IotServerInfo();
|
|
|
- serverInfo.setIotCode(UUID.fastUUID().toString());//分配后不可变更
|
|
|
+ IotServerInfo serverInfo = new IotServerInfo();
|
|
|
serverInfo.setIotName(req.getIotName());
|
|
|
serverInfo.setIotStatus(IotServerConnectStatus.UNKNOWN.getIdx());
|
|
|
serverInfo.setOrgPath(sysOrg.getPath());
|
|
|
serverInfo.setOrgName(sysOrg.getShortName());
|
|
|
serverInfo.setOrgId(sysOrg.getId());
|
|
|
serverInfo.setId(IdWorker.getId());
|
|
|
+ serverInfo.setRegisterCode(getVerificationCode(collect));
|
|
|
+ serverInfo.setRegisterCodeStatus(0);
|
|
|
serverInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
serverInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
serverInfo.setCreateTime(LocalDateTime.now());
|
|
|
@@ -74,14 +80,34 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
return baseMapper.insert(serverInfo);
|
|
|
}
|
|
|
|
|
|
+ private String getVerificationCode(List<String> usedCodeList){
|
|
|
+ while (true) {
|
|
|
+ String numericCode = numericCode();
|
|
|
+ if (!usedCodeList.contains(numericCode)) {
|
|
|
+ return numericCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String numericCode() {
|
|
|
+ Random random = new Random();
|
|
|
+ int length = 6 + random.nextInt(3);
|
|
|
+ StringBuilder code = new StringBuilder(length);
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
+ code.append(random.nextInt(10));
|
|
|
+ }
|
|
|
+ return code.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void editIot(IotServerInfoEditDto req) {
|
|
|
- if (ObjectUtil.isEmpty(req.getId())){
|
|
|
+ if (ObjectUtil.isEmpty(req.getId())) {
|
|
|
throw new RuntimeException("请选择具体iot服务进行查看!");
|
|
|
}
|
|
|
IotServerInfo info = getById(req.getId());
|
|
|
- if (ObjectUtil.isEmpty(info)){
|
|
|
+ if (ObjectUtil.isEmpty(info)) {
|
|
|
throw new RuntimeException("未找到具体iot服务!");
|
|
|
}
|
|
|
info.setIotName(req.getIotName());
|