|
|
@@ -1,14 +1,18 @@
|
|
|
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.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
|
|
|
+import com.xunmei.common.core.exception.SystemException;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
-import com.xunmei.iot.dto.serverInfo.IotServerInfoAddDto;
|
|
|
+import com.xunmei.iot.dto.serverInfo.IotServerInfoEditDto;
|
|
|
import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
|
|
|
import com.xunmei.iot.mapper.IotServerInfoMapper;
|
|
|
import com.xunmei.iot.service.IotServerInfoService;
|
|
|
@@ -20,7 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -49,10 +56,10 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public int addIotServer(IotServerInfoAddDto req) {
|
|
|
+ public int addIotServer(IotServerInfoEditDto req) {
|
|
|
SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
val serverInfo = new IotServerInfo();
|
|
|
- serverInfo.setIotCode(UUID.fastUUID().toString());
|
|
|
+ serverInfo.setIotCode(UUID.fastUUID().toString());//分配后不可变更
|
|
|
serverInfo.setIotName(req.getIotName());
|
|
|
serverInfo.setIotStatus(0);
|
|
|
serverInfo.setOrgPath(sysOrg.getPath());
|
|
|
@@ -65,4 +72,43 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
|
|
|
serverInfo.setUpdateTime(LocalDateTime.now());
|
|
|
return baseMapper.insert(serverInfo);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void editIot(IotServerInfoEditDto req) {
|
|
|
+ if (ObjectUtil.isEmpty(req.getId())){
|
|
|
+ throw new RuntimeException("请选择具体iot服务进行查看!");
|
|
|
+ }
|
|
|
+ IotServerInfo info = getById(req.getId());
|
|
|
+ if (ObjectUtil.isEmpty(info)){
|
|
|
+ throw new RuntimeException("未找到具体iot服务!");
|
|
|
+ }
|
|
|
+ info.setIotName(req.getIotName());
|
|
|
+ updateById(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(IotServerInfoPageDto req, HttpServletResponse response) {
|
|
|
+ req.setPageSize(Integer.MAX_VALUE);
|
|
|
+ TableDataInfo<IotServerInfoPageVo> tableDataInfo = this.serverPage(req);
|
|
|
+ List<IotServerInfoPageVo> list = tableDataInfo.getRows();
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ throw new SystemException("暂无可用数据导出!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 设置响应头
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("Iot服务", "utf-8"));
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ // 数据导出
|
|
|
+ EasyExcel.write(response.getOutputStream(), IotServerInfoPageVo.class)
|
|
|
+ .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("Iot服务").doWrite(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 重置response
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|