提交修改

This commit is contained in:
LEED
2025-04-13 18:00:19 +08:00
parent 988e68bdc7
commit 4201690d93
60 changed files with 2589 additions and 285 deletions

View File

@@ -7,10 +7,12 @@ import com.xinda.common.config.RuoYiConfig;
import com.xinda.common.constant.HttpStatus;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.core.domain.entity.SysUser;
import com.xinda.common.core.page.TableDataInfo;
import com.xinda.common.enums.BusinessType;
import com.xinda.common.exception.ServiceException;
import com.xinda.common.exception.file.InvalidExtensionException;
import com.xinda.common.utils.MessageUtils;
import com.xinda.common.utils.StringUtils;
import com.xinda.common.utils.file.MimeTypeUtils;
import com.xinda.common.utils.poi.ExcelUtil;
@@ -23,15 +25,13 @@ import com.xinda.iot.service.IDeviceService;
import com.xinda.scada.domain.Scada;
import com.xinda.scada.domain.ScadaDeviceBind;
import com.xinda.scada.domain.ScadaGallery;
import com.xinda.scada.enums.ScadaTypeEnum;
import com.xinda.scada.service.IScadaDeviceBindService;
import com.xinda.scada.service.IScadaService;
import com.xinda.scada.utils.ScadaCollectionUtils;
import com.xinda.scada.utils.ScadaFileUploadUtils;
import com.xinda.scada.utils.ScadaFileUtils;
import com.xinda.scada.vo.DeviceRealDataVO;
import com.xinda.scada.vo.FavoritesVO;
import com.xinda.scada.vo.ScadaDeviceBindDTO;
import com.xinda.scada.vo.ThingsModelHistoryParam;
import com.xinda.scada.vo.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -115,9 +115,9 @@ public class ScadaController extends BaseController
@PreAuthorize("@ss.hasPermi('scada:center:add')")
@Log(title = "组态中心", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Scada scada)
public AjaxResult add(@RequestBody ScadaVO scadaVO)
{
return scadaService.insertScada(scada);
return scadaService.insertScada(scadaVO);
}
/**
@@ -127,9 +127,9 @@ public class ScadaController extends BaseController
@PreAuthorize("@ss.hasPermi('scada:center:edit')")
@Log(title = "组态中心", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Scada scada)
public AjaxResult edit(@RequestBody ScadaVO scadaVO)
{
return toAjax(scadaService.updateScada(scada));
return toAjax(scadaService.updateScada(scadaVO));
}
/**
@@ -164,32 +164,43 @@ public class ScadaController extends BaseController
@Log(title = "组态中心", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermi('scada:center:edit')")
@PostMapping("/save")
public AjaxResult save(@RequestBody Scada scada)
public AjaxResult save(@RequestBody ScadaVO scadaVO)
{
if (StringUtils.isEmpty(scada.getGuid())) {
return AjaxResult.error("guid不能为空");
if (StringUtils.isEmpty(scadaVO.getGuid())) {
return AjaxResult.error(MessageUtils.message("scada.guid.cannot.empty"));
}
if (null == scadaVO.getType()) {
scadaVO.setType(ScadaTypeEnum.PUBLIC.getType());
}
Scada scadaQuery = new Scada();
scadaQuery.setGuid(scada.getGuid());
List<Scada> scadaList = scadaService.selectScadaList(scadaQuery);
if (StringUtils.isNotEmpty(scada.getBase64())) {
MultipartFile multipartFile = ScadaFileUtils.base64toMultipartFile(scada.getBase64());
scadaQuery.setGuid(scadaVO.getGuid());
List<ScadaVO> scadaVOList = scadaService.listScadaVO(scadaQuery);
if (StringUtils.isNotEmpty(scadaVO.getBase64())) {
MultipartFile multipartFile = ScadaFileUtils.base64toMultipartFile(scadaVO.getBase64());
String url;
try {
url = ScadaFileUploadUtils.upload(RuoYiConfig.getUploadPath(), multipartFile, MimeTypeUtils.IMAGE_EXTENSION);
} catch (IOException | InvalidExtensionException e) {
throw new ServiceException("修改组态base64转图片异常" + e.getMessage());
throw new ServiceException(StringUtils.format(MessageUtils.message("scada.base64.change.image.exception"), e.getMessage()));
}
scada.setPageImage(url);
scadaVO.setPageImage(url);
}
if (CollectionUtils.isNotEmpty(scadaList)) {
Scada updateScada = scadaList.get(0);
updateScada.setScadaData(scada.getScadaData());
updateScada.setPageImage(scada.getPageImage());
scadaService.updateScada(updateScada);
if (CollectionUtils.isNotEmpty(scadaVOList)) {
ScadaVO updateScadaVO = scadaVOList.get(0);
updateScadaVO.setScadaData(scadaVO.getScadaData());
updateScadaVO.setPageImage(scadaVO.getPageImage());
scadaService.updateScada(updateScadaVO);
} else {
scadaService.insertScada(scada);
// scadaDeviceBindService.insertScadaDeviceBind()
// 多租户版本使用
SysUser user = getLoginUser().getUser();
if (null != user.getDeptId()) {
scadaVO.setTenantId(user.getDept().getDeptUserId());
scadaVO.setTenantName(user.getDept().getDeptUserName());
} else {
scadaVO.setTenantId(user.getUserId());
scadaVO.setTenantName(user.getUserName());
}
scadaService.insertScada(scadaVO);
}
return AjaxResult.success();
}
@@ -374,39 +385,7 @@ public class ScadaController extends BaseController
// @PreAuthorize("@ss.hasPermi('scada:center:add')")
@PostMapping("/importJson")
public AjaxResult importJson(MultipartFile file, String guid) throws IOException {
InputStream inputStream = file.getInputStream();
if(file.isEmpty()){
return AjaxResult.error("无效的配置文件");
}
if(file.getOriginalFilename().indexOf("json")==-1){
return AjaxResult.error("无效的配置文件");
}
Scada scada = new Scada();
try {
scada = JSON.parseObject(inputStream, Scada.class);
}catch (Exception e){
return AjaxResult.error("无效的配置文件");
}finally {
inputStream.close();
}
Scada oldScada = new Scada();
if (StringUtils.isNotEmpty(guid)) {
Scada queryScada = new Scada();
queryScada.setGuid(guid);
List<Scada> scadaList = scadaService.selectScadaList(queryScada);
if (CollectionUtils.isNotEmpty(scadaList)) {
oldScada = scadaList.get(0);
}
}
if (oldScada == null) {
guid= UUID.randomUUID().toString();
scada.setGuid(guid);
scadaService.insertScada(scada);
} else {
scada.setId(oldScada.getId());
scadaService.updateScada(scada);
}
return AjaxResult.success("导入成功");
return scadaService.importJson(file, guid);
}
/**

View File

@@ -0,0 +1,70 @@
package com.xinda.scada.convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinda.scada.domain.Scada;
import com.xinda.scada.vo.ScadaVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 组态页面Convert转换类
*
* @author zhuangpeng.li
* @date 2024-12-04
*/
@Mapper
public interface ScadaConvert
{
ScadaConvert INSTANCE = Mappers.getMapper(ScadaConvert.class);
/**
* 实体类转换为VO类
*
* @param scada
* @return 组态页面集合
*/
ScadaVO convertScadaVO(Scada scada);
/**
* VO类转换为实体类集合
*
* @param scadaVO
* @return 组态页面集合
*/
Scada convertScada(ScadaVO scadaVO);
/**
* 实体类转换为VO类集合
*
* @param scadaList
* @return 组态页面集合
*/
List<ScadaVO> convertScadaVOList(List<Scada> scadaList);
/**
* VO类转换为实体类
*
* @param scadaVOList
* @return 组态页面集合
*/
List<Scada> convertScadaList(List<ScadaVO> scadaVOList);
/**
* 实体类转换为VO类分页
*
* @param scadaPage
* @return 组态页面分页
*/
Page<ScadaVO> convertScadaVOPage(Page<Scada> scadaPage);
/**
* VO类转换为实体类
*
* @param scadaVOPage
* @return 组态页面分页
*/
Page<Scada> convertScadaPage(Page<ScadaVO> scadaVOPage);
}

View File

@@ -4,6 +4,7 @@ import com.xinda.common.annotation.Excel;
import com.xinda.common.core.domain.BaseEntity;
import com.xinda.scada.vo.ScadaBindDeviceSimVO;
import com.xinda.scada.vo.ScadaDeviceBindVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@@ -70,6 +71,8 @@ public class Scada extends BaseEntity
@Excel(name = "页面图片")
private String pageImage;
private Long deptId;
/** 租户id */
@Excel(name = "租户id")
private Long tenantId;
@@ -83,6 +86,10 @@ public class Scada extends BaseEntity
private String base64;
/** 组态类型 1- 模板组态 2- 场景组态 3-公共组态 */
@ApiModelProperty("组态类型 1- 模板组态 2- 场景组态 3-公共组态")
private Integer type;
private List<ScadaBindDeviceSimVO> bindDeviceList;
}

View File

@@ -0,0 +1,38 @@
package com.xinda.scada.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
/**
* 组态类型枚举
* @author fastb
* @date 2024-05-22 10:01
* @version 1.0
*/
@Getter
@AllArgsConstructor
public enum ScadaTypeEnum {
PRODUCT_TEMPLATE(1, "模版组态"),
SCENE_MODEL(2, "场景组态"),
PUBLIC(3, "公共组态");
private final Integer type;
private final String name;
public static ScadaTypeEnum getByType(Integer type) {
for (ScadaTypeEnum scadaTypeEnum : ScadaTypeEnum.values()) {
if (scadaTypeEnum.getType().equals(type)) {
return scadaTypeEnum;
}
}
return null;
}
}

View File

@@ -69,4 +69,6 @@ public interface ScadaDeviceBindMapper
* @return java.util.List<com.xinda.scada.vo.ScadaBindDeviceSimVO>
*/
List<ScadaBindDeviceSimVO> listDeviceSimByGuid(String guid);
List<ScadaDeviceBind> selectScadaDeviceBindListByIds(List<String> guidList);
}

View File

@@ -59,6 +59,7 @@ public interface ScadaMapper
*/
public int deleteScadaById(Long id);
public int deleteScadaByGuid(String guid);
/**
* 批量删除组态中心
*
@@ -96,4 +97,20 @@ public interface ScadaMapper
* @return java.util.List<com.xinda.scada.vo.ScadaHistoryModelVO>
*/
List<ScadaHistoryModelVO> listEventLogHistory(EventLog eventLog);
String selectGuidBySceneModelId(Long sceneModelId);
String selectGuidByProductId(Long productId);
void updateProductGuid(@Param("productId") Long productId, @Param("guid") String guid);
void updateSceneModelGuid( @Param("sceneModelId") Long sceneModelId, @Param("guid") String guid);
void deleteProductByGuids(List<String> guids);
void deleteSceneModelByGuids(List<String> guids);
Long selectProductByGuid(String guid);
Long selectSceneModelByGuid(String guid);
}

View File

@@ -3,19 +3,17 @@ package com.xinda.scada.service;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.scada.domain.Scada;
import com.xinda.scada.domain.ScadaGallery;
import com.xinda.scada.vo.FavoritesVO;
import com.xinda.scada.vo.ScadaHistoryModelVO;
import com.xinda.scada.vo.ScadaStatisticVO;
import com.xinda.scada.vo.ThingsModelHistoryParam;
import com.xinda.scada.vo.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* 组态中心Service接口
*
* @author kerwincui
* @author kerwincuiIScadaService
* @date 2023-11-10
*/
public interface IScadaService
@@ -26,7 +24,7 @@ public interface IScadaService
* @param id 组态中心主键
* @return 组态中心
*/
public Scada selectScadaById(Long id);
public ScadaVO selectScadaById(Long id);
/**
* 查询组态中心列表
@@ -39,18 +37,20 @@ public interface IScadaService
/**
* 新增组态中心
*
* @param scada 组态中心
* @param scadaVO 组态中心
* @return 结果
*/
public AjaxResult insertScada(ScadaVO scadaVO);
public AjaxResult insertScada(Scada scada);
/**
* 修改组态中心
*
* @param scada 组态中心
* @param scadaVO 组态中心
* @return 结果
*/
public int updateScada(Scada scada);
public int updateScada(ScadaVO scadaVO);
/**
* 批量删除组态中心
@@ -68,6 +68,8 @@ public interface IScadaService
*/
public int deleteScadaById(Long id);
public int deleteScadaByGuid(String guid);
/**
* 根据guid获取组态详情
* @param guid 组态id
@@ -120,4 +122,8 @@ public interface IScadaService
* @return com.xinda.common.core.domain.AjaxResult
*/
ScadaStatisticVO selectStatistic();
List<ScadaVO> listScadaVO(Scada scadaQuery);
AjaxResult importJson(MultipartFile file, String guid) throws IOException;
}

View File

@@ -1,12 +1,17 @@
package com.xinda.scada.service.impl;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinda.common.config.RuoYiConfig;
import com.xinda.common.constant.HttpStatus;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.core.domain.entity.SysRole;
import com.xinda.common.core.domain.entity.SysUser;
import com.xinda.common.core.domain.model.LoginUser;
import com.xinda.common.core.redis.RedisCache;
import com.xinda.common.exception.ServiceException;
import com.xinda.common.utils.DateUtils;
import com.xinda.common.utils.MessageUtils;
import com.xinda.common.utils.StringUtils;
import com.xinda.common.utils.bean.BeanUtils;
import com.xinda.common.utils.file.FileUploadUtils;
@@ -15,8 +20,11 @@ import com.xinda.iot.domain.EventLog;
import com.xinda.iot.domain.FunctionLog;
import com.xinda.iot.model.HistoryModel;
import com.xinda.iot.service.IDeviceLogService;
import com.xinda.scada.convert.ScadaConvert;
import com.xinda.scada.domain.Scada;
import com.xinda.scada.domain.ScadaDeviceBind;
import com.xinda.scada.domain.ScadaGallery;
import com.xinda.scada.enums.ScadaTypeEnum;
import com.xinda.scada.mapper.ScadaDeviceBindMapper;
import com.xinda.scada.mapper.ScadaGalleryMapper;
import com.xinda.scada.mapper.ScadaMapper;
@@ -27,6 +35,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
@@ -59,9 +69,21 @@ public class ScadaServiceImpl implements IScadaService
* @return 组态中心
*/
@Override
public Scada selectScadaById(Long id)
public ScadaVO selectScadaById(Long id)
{
return scadaMapper.selectScadaById(id);
Scada scada = scadaMapper.selectScadaById(id);
if (Objects.isNull(scada)) {
return null;
}
ScadaVO scadaVO = ScadaConvert.INSTANCE.convertScadaVO(scada);
if (ScadaTypeEnum.PRODUCT_TEMPLATE.getType().equals(scada.getType())) {
Long productId = scadaMapper.selectProductByGuid(scada.getGuid());
scadaVO.setProductId(productId);
} else if (ScadaTypeEnum.SCENE_MODEL.getType().equals(scada.getType())) {
Long sceneModelId = scadaMapper.selectSceneModelByGuid(scada.getGuid());
scadaVO.setSceneModelId(sceneModelId);
}
return scadaVO;
}
/**
@@ -79,32 +101,126 @@ public class ScadaServiceImpl implements IScadaService
/**
* 新增组态中心
*
* @param scada 组态中心
* @param scadaVO 组态中心
* @return 结果
*/
@Override
public AjaxResult insertScada(Scada scada)
public AjaxResult insertScada(ScadaVO scadaVO)
{
// scadaVO.setPageName("综合测试GKB-29813组态");
// scadaVO.setProductId(219L);
// scadaVO.setType(1);
LoginUser loginUser = getLoginUser();
if (loginUser == null) {
return AjaxResult.error("请登录后重试!");
return AjaxResult.error(MessageUtils.message("scada.please.login"));
}
if (ScadaTypeEnum.PRODUCT_TEMPLATE.getType().equals(scadaVO.getType())) {
String guid = scadaMapper.selectGuidByProductId(scadaVO.getProductId());
if (StringUtils.isNotEmpty(guid)){
return AjaxResult.warn(MessageUtils.message("scada.product.has.relate.please.select.again"));
}
}
if (ScadaTypeEnum.SCENE_MODEL.getType().equals(scadaVO.getType())) {
String guid = scadaMapper.selectGuidBySceneModelId(scadaVO.getSceneModelId());
if (StringUtils.isNotEmpty(guid)){
return AjaxResult.warn(MessageUtils.message("scada.scene.has.relate.please.select.again"));
}
}
// 多租户版本使用
SysUser user = getLoginUser().getUser();
if (null != user.getDeptId()) {
scadaVO.setTenantId(user.getDept().getDeptUserId());
scadaVO.setTenantName(user.getDept().getDeptUserName());
} else {
scadaVO.setTenantId(user.getUserId());
scadaVO.setTenantName(user.getUserName());
}
scadaVO.setCreateBy(loginUser.getUserId().toString());
UUID uuid = UUID.randomUUID();
scadaVO.setGuid(uuid.toString());
Scada scada = ScadaConvert.INSTANCE.convertScada(scadaVO);
int result = scadaMapper.insertScada(scada);
if (result >0){
if (ScadaTypeEnum.PRODUCT_TEMPLATE.getType().equals(scadaVO.getType())) {
scadaMapper.updateProductGuid(scadaVO.getProductId(), uuid.toString());
}
if (ScadaTypeEnum.SCENE_MODEL.getType().equals(scadaVO.getType())) {
scadaMapper.updateSceneModelGuid(scadaVO.getSceneModelId(), uuid.toString());
}
return AjaxResult.success(uuid.toString());
}else {
return AjaxResult.error();
}
}
@Override
public AjaxResult insertScada(Scada scada){
LoginUser loginUser = getLoginUser();
if (loginUser == null) {
return AjaxResult.error(MessageUtils.message("scada.please.login"));
}
// 多租户版本使用
SysUser user = getLoginUser().getUser();
if (null != user.getDeptId()) {
scada.setTenantId(user.getDept().getDeptUserId());
scada.setTenantName(user.getDept().getDeptUserName());
} else {
scada.setTenantId(user.getUserId());
scada.setTenantName(user.getUserName());
}
scada.setCreateBy(loginUser.getUserId().toString());
UUID uuid = UUID.randomUUID();
scada.setGuid(uuid.toString());
return scadaMapper.insertScada(scada) > 0 ? AjaxResult.success() : AjaxResult.error();
int result = scadaMapper.insertScada(scada);
if (result >0){
return AjaxResult.success(scada.getGuid());
}else {
return AjaxResult.error();
}
}
/**
* 查询组态页面列表
*
* @param scada 组态页面
* @return 组态页面
*/
@Override
public List<ScadaVO> listScadaVO(Scada scada) {
List<Scada> scadaList = scadaMapper.selectScadaList(scada);
return ScadaConvert.INSTANCE.convertScadaVOList(scadaList);
}
/**
* 修改组态中心
*
* @param scada 组态中心
* @param scadaVO 组态中心
* @return 结果
*/
@Override
public int updateScada(Scada scada)
public int updateScada(ScadaVO scadaVO)
{
scada.setUpdateTime(DateUtils.getNowDate());
if (ScadaTypeEnum.PRODUCT_TEMPLATE.getType().equals(scadaVO.getType()) && null != scadaVO.getProductId()) {
String guid = scadaMapper.selectGuidByProductId(scadaVO.getProductId());
if (StringUtils.isNotEmpty(guid) && !guid.equals(scadaVO.getGuid())){
throw new ServiceException(MessageUtils.message("scada.product.has.relate.please.select.again"), HttpStatus.WARN);
}
if (StringUtils.isEmpty(guid)) {
scadaMapper.deleteProductByGuids(Collections.singletonList(scadaVO.getGuid()));
scadaMapper.updateProductGuid(scadaVO.getProductId(), scadaVO.getGuid());
}
}
if (ScadaTypeEnum.SCENE_MODEL.getType().equals(scadaVO.getType()) && null != scadaVO.getSceneModelId()) {
String guid = scadaMapper.selectGuidBySceneModelId(scadaVO.getSceneModelId());
if (StringUtils.isNotEmpty(guid) && !guid.equals(scadaVO.getGuid())){
throw new ServiceException(MessageUtils.message("scada.scene.has.relate.please.select.again"), HttpStatus.WARN);
}
if (StringUtils.isEmpty(guid)) {
scadaMapper.deleteSceneModelByGuids(Collections.singletonList(scadaVO.getGuid()));
scadaMapper.updateSceneModelGuid(scadaVO.getSceneModelId(), scadaVO.getGuid());
}
}
Scada scada = ScadaConvert.INSTANCE.convertScada(scadaVO);
return scadaMapper.updateScada(scada);
}
@@ -132,6 +248,11 @@ public class ScadaServiceImpl implements IScadaService
return scadaMapper.deleteScadaById(id);
}
@Override
public int deleteScadaByGuid(String guid) {
return scadaMapper.deleteScadaByGuid(guid);
}
/**
* 根据guid获取组态详情
* @param guid 组态id
@@ -301,4 +422,60 @@ public class ScadaServiceImpl implements IScadaService
}
return statistic;
}
@Override
public AjaxResult importJson(MultipartFile file, String guid) throws IOException {
InputStream inputStream = file.getInputStream();
if(file.isEmpty()){
return AjaxResult.error(MessageUtils.message("scada.invalid.profile"));
}
if(file.getOriginalFilename().indexOf("json")==-1){
return AjaxResult.error(MessageUtils.message("scada.invalid.profile"));
}
Scada scada = new Scada();
try {
scada = JSON.parseObject(inputStream, Scada.class);
}catch (Exception e){
return AjaxResult.error(MessageUtils.message("scada.invalid.profile"));
}finally {
inputStream.close();
}
Scada oldScada = new Scada();
if (StringUtils.isNotEmpty(guid)) {
Scada queryScada = new Scada();
queryScada.setGuid(guid);
List<Scada> scadaList = scadaMapper.selectScadaList(queryScada);
if (CollectionUtils.isNotEmpty(scadaList)) {
oldScada = scadaList.get(0);
}
}
String importGuid = scada.getGuid();
Long tenantId = scada.getTenantId();
oldScada.setScadaData(scada.getScadaData());
int i = scadaMapper.updateScada(oldScada);
if (i <= 0) {
return AjaxResult.error(MessageUtils.message("import.fail"));
}
if (!tenantId.equals(oldScada.getTenantId())) {
return AjaxResult.success(MessageUtils.message("scada.import.success.need.replace.variable"));
}
if (StringUtils.isNotEmpty(importGuid) && ScadaTypeEnum.PUBLIC.getType().equals(oldScada.getType())
&& ScadaTypeEnum.PUBLIC.getType().equals(scada.getType())) {
List<String> guidList = Arrays.asList(guid, importGuid);
List<ScadaDeviceBind> scadaDeviceBinds = scadaDeviceBindMapper.selectScadaDeviceBindListByIds(guidList);
if (CollectionUtils.isNotEmpty(scadaDeviceBinds)) {
List<String> serialNumbers = scadaDeviceBinds.stream().filter(d -> guid.equals(d.getScadaGuid())).map(ScadaDeviceBind::getSerialNumber).collect(Collectors.toCollection(ArrayList::new));
List<String> importSerialNumbers = scadaDeviceBinds.stream().filter(d -> importGuid.equals(d.getScadaGuid())).map(ScadaDeviceBind::getSerialNumber).collect(Collectors.toCollection(ArrayList::new));
importSerialNumbers.removeAll(serialNumbers);
for (String importSerialNumber : importSerialNumbers) {
ScadaDeviceBind scadaDeviceBind = new ScadaDeviceBind();
scadaDeviceBind.setScadaGuid(guid);
scadaDeviceBind.setSerialNumber(importSerialNumber);
scadaDeviceBindMapper.insertScadaDeviceBind(scadaDeviceBind);
}
}
return AjaxResult.success(MessageUtils.message("import.success"));
}
return AjaxResult.success(MessageUtils.message("scada.import.success.need.replace.variable"));
}
}

View File

@@ -0,0 +1,162 @@
package com.xinda.scada.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.xinda.common.annotation.Excel;
import com.xinda.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import java.io.Serializable;
import java.util.*;
/**
* 组态页面对象 scada
*
* @author zhuangpeng.li
* @date 2024-12-04
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ScadaVO", description = "组态页面 scada")
@Data
public class ScadaVO extends BaseEntity {
/** id唯一标识 */
@Excel(name = "id唯一标识")
@ApiModelProperty("id唯一标识")
private Long id;
/** 组态id */
@Excel(name = "组态id")
@ApiModelProperty("组态id")
private String guid;
/** 组态信息 */
@Excel(name = "组态信息")
@ApiModelProperty("组态信息")
private String scadaData;
/** 设备编号 */
@Excel(name = "设备编号")
@ApiModelProperty("设备编号")
private String serialNumbers;
/** 设备名称 */
@Excel(name = "设备名称")
@ApiModelProperty("设备名称")
private String deviceName;
/** 是否主界面 */
@Excel(name = "是否主界面")
@ApiModelProperty("是否主界面")
private Integer isMainPage;
/** 页面名称 */
@Excel(name = "页面名称")
@ApiModelProperty("页面名称")
private String pageName;
/** 页面大小 */
@Excel(name = "页面大小")
@ApiModelProperty("页面大小")
private String pageResolution;
/** 是否分享 */
@Excel(name = "是否分享")
@ApiModelProperty("是否分享")
private Integer isShare;
/** 分享链接 */
@Excel(name = "分享链接")
@ApiModelProperty("分享链接")
private String shareUrl;
/** 分享密码 */
@Excel(name = "分享密码")
@ApiModelProperty("分享密码")
private String sharePass;
/** 页面图片 */
@Excel(name = "页面图片")
@ApiModelProperty("页面图片")
private String pageImage;
/** 租户id */
@Excel(name = "租户id")
@ApiModelProperty("租户id")
private Long tenantId;
/** 租户名称 */
@Excel(name = "租户名称")
@ApiModelProperty("租户名称")
private String tenantName;
/** 创建人 */
@Excel(name = "创建人")
@ApiModelProperty("创建人")
private String createBy;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
@Excel(name = "创建时间")
private Date createTime;
/** 更新人 */
@Excel(name = "更新人")
@ApiModelProperty("更新人")
private String updateBy;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("更新时间")
@Excel(name = "更新时间")
private Date updateTime;
/** 逻辑删除标识 */
@Excel(name = "逻辑删除标识")
@ApiModelProperty("逻辑删除标识")
private Integer delFlag;
/** 备注 */
@Excel(name = "备注")
@ApiModelProperty("备注")
private String remark;
/** 组态类型 1- 模板组态 2- 场景组态 3-公共组态 */
@Excel(name = "组态类型 1- 模板组态 2- 场景组态 3-公共组态")
@ApiModelProperty("组态类型 1- 模板组态 2- 场景组态 3-公共组态")
private Integer type;
/** 分享短链接 */
@Excel(name = "分享短链接")
@ApiModelProperty("分享短链接")
private String shareShortUrl;
/**
* 绑定的产品id
*/
private Long productId;
/**
* 场景id
*/
private Long sceneModelId;
private List<ScadaBindDeviceSimVO> bindDeviceList = new ArrayList<>();
private String base64;
/**
* 设备编号
*/
private String serialNumber;
}

View File

@@ -22,6 +22,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="selectScadaDeviceBindListByIds" parameterType="String" resultMap="ScadaDeviceBindResult">
<include refid="selectScadaDeviceBindVo"/>
where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="selectScadaDeviceBindById" parameterType="Long" resultMap="ScadaDeviceBindResult">
<include refid="selectScadaDeviceBindVo"/>
where id = #{id}
@@ -54,6 +62,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<select id="selectProductByGuid" resultType="java.lang.Long">
select product_id
from iot_product
where guid = #{guid}
and del_flag = '0'
</select>
<select id="selectSceneModelByGuid" resultType="java.lang.Long">
select scene_model_id
from scene_model
where guid = #{guid}
and del_flag = 0
</select>
<update id="updateScadaDeviceBind" parameterType="ScadaDeviceBind">
update scada_device_bind
<trim prefix="SET" suffixOverrides=",">

View File

@@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="shareUrl" column="share_url" />
<result property="sharePass" column="share_pass" />
<result property="pageImage" column="page_image" />
<result property="deptId" column="dept_id" />
<result property="tenantId" column="tenant_id" />
<result property="tenantName" column="tenant_name" />
<result property="createBy" column="create_by" />
@@ -24,28 +25,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="type" column="type"/>
</resultMap>
<sql id="selectScadaVo">
select id, guid, scada_data, serial_numbers, device_name, is_main_page, page_name, page_resolution, is_share, share_url, share_pass, page_image, tenant_id, tenant_name, create_by, create_time, update_by, update_time, del_flag from scada
select id, guid, scada_data, serial_numbers, device_name, is_main_page, page_name, page_resolution, is_share, share_url, share_pass, page_image, dept_id,tenant_id, tenant_name, create_by, create_time, update_by, update_time, del_flag, type from scada
</sql>
<select id="selectScadaList" parameterType="Scada" resultMap="ScadaResult">
<include refid="selectScadaVo"/>
select s.id, s.guid, s.scada_data, s.serial_numbers, s.device_name, s.is_main_page, s.page_name, s.page_resolution, s.is_share, s.share_url, s.share_pass, s.page_image, s.dept_id, s.tenant_id, s.tenant_name, s.create_by, s.create_time, s.update_by, s.update_time, s.del_flag, s.type
from scada s
<where>
<if test="guid != null and guid != ''"> and guid = #{guid}</if>
<if test="scadaData != null and scadaData != ''"> and scada_data = #{scadaData}</if>
<if test="serialNumbers != null and serialNumbers != ''"> and serial_numbers = #{serialNumbers}</if>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
<if test="isMainPage != null "> and is_main_page = #{isMainPage}</if>
<if test="pageName != null and pageName != ''"> and page_name like concat('%', #{pageName}, '%')</if>
<if test="pageResolution != null and pageResolution != ''"> and page_resolution = #{pageResolution}</if>
<if test="isShare != null "> and is_share = #{isShare}</if>
<if test="shareUrl != null and shareUrl != ''"> and share_url = #{shareUrl}</if>
<if test="sharePass != null and sharePass != ''"> and share_pass = #{sharePass}</if>
<if test="pageImage != null and pageImage != ''"> and page_image = #{pageImage}</if>
<if test="tenantId != null "> and tenant_id = #{tenantId}</if>
<if test="tenantName != null and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
<if test="guid != null and guid != ''"> and s.guid = #{guid}</if>
<if test="scadaData != null and scadaData != ''"> and s.scada_data = #{scadaData}</if>
<if test="serialNumbers != null and serialNumbers != ''"> and s.serial_numbers = #{serialNumbers}</if>
<if test="deviceName != null and deviceName != ''"> and s.device_name like concat('%', #{deviceName}, '%')</if>
<if test="isMainPage != null "> and s.is_main_page = #{isMainPage}</if>
<if test="pageName != null and pageName != ''"> and s.page_name like concat('%', #{pageName}, '%')</if>
<if test="pageResolution != null and pageResolution != ''"> and s.page_resolution = #{pageResolution}</if>
<if test="isShare != null "> and s.is_share = #{isShare}</if>
<if test="shareUrl != null and shareUrl != ''"> and s.share_url = #{shareUrl}</if>
<if test="sharePass != null and sharePass != ''"> and s.share_pass = #{sharePass}</if>
<if test="pageImage != null and pageImage != ''"> and s.page_image = #{pageImage}</if>
<if test="deptId != null ">
and ( s.dept_id in (SELECT de.dept_id FROM sys_dept de
WHERE FIND_IN_SET(#{deptId}, de.ancestors) OR de.dept_id = #{deptId})
)
</if>
<!-- <if test="tenantName != null and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>-->
<if test="type != null">and s.type = #{type}</if>
</where>
</select>
@@ -74,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="userId != null and userId != 0"> and u.user_id = #{userId}</if>
<if test="tenantId != null and tenantId != 0"> and d.tenant_id = #{tenantId}</if>
</where>
) as deviceCount,
@@ -216,6 +225,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="shareUrl != null">share_url,</if>
<if test="sharePass != null">share_pass,</if>
<if test="pageImage != null">page_image,</if>
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="tenantName != null">tenant_name,</if>
<if test="createBy != null">create_by,</if>
@@ -224,6 +234,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
<if test="delFlag != null">del_flag,</if>
<if test="remark != null">remark,</if>
<if test="type != null">type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="guid != null">#{guid},</if>
@@ -237,6 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="shareUrl != null">#{shareUrl},</if>
<if test="sharePass != null">#{sharePass},</if>
<if test="pageImage != null">#{pageImage},</if>
<if test="deptId != null">#{deptId},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="tenantName != null">#{tenantName},</if>
<if test="createBy != null">#{createBy},</if>
@@ -245,6 +257,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="remark != null">#{remark},</if>
<if test="type != null">#{type},</if>
</trim>
</insert>
@@ -262,6 +275,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="shareUrl != null">share_url = #{shareUrl},</if>
<if test="sharePass != null">share_pass = #{sharePass},</if>
<if test="pageImage != null">page_image = #{pageImage},</if>
<if test="deptId != null ">dept_id = #{deptId},</if>
<if test="tenantId != null">tenant_id = #{tenantId},</if>
<if test="tenantName != null">tenant_name = #{tenantName},</if>
<if test="createBy != null">create_by = #{createBy},</if>
@@ -270,6 +284,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="type != null">type = #{type},</if>
</trim>
where id = #{id}
</update>
@@ -278,10 +293,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from scada where id = #{id}
</delete>
<delete id="deleteScadaByGuid" parameterType="String">
delete from scada where guid = #{guid}
</delete>
<delete id="deleteScadaByIds" parameterType="String">
delete from scada where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectUserIdByDeptId" resultType="java.lang.Long">
select user_id
from sys_user
where dept_id = #{deptId}
and status = 0
and del_flag = 0
</select>
<select id="selectGuidByProductId" resultType="java.lang.String">
select p.guid from iot_product p
where p.product_id = #{productId}
and p.del_flag = '0'
</select>
<select id="selectGuidBySceneModelId" resultType="java.lang.String">
select guid
from scene_model
where scene_model_id = #{sceneModelId}
and del_flag = 0
</select>
<select id="selectProductByGuid" resultType="java.lang.Long">
select product_id
from iot_product
where guid = #{guid}
and del_flag = '0'
</select>
<select id="selectSceneModelByGuid" resultType="java.lang.Long">
select scene_model_id
from scene_model
where guid = #{guid}
and del_flag = 0
</select>
<update id="updateProductGuid">
update iot_product
set guid = #{guid}
where product_id = #{productId}
</update>
<update id="updateSceneModelGuid">
update scene_model
set guid = #{guid}
where scene_model_id = #{sceneModelId}
</update>
<update id="deleteSceneModelByGuids">
update scene_model
set guid = null
where guid in
<foreach collection="guids" item="guid" open="(" separator="," close=")">
#{guid}
</foreach>
</update>
<update id="deleteProductByGuids">
update iot_product
set guid = null
where guid in
<foreach collection="guids" item="guid" open="(" separator="," close=")">
#{guid}
</foreach>
</update>
</mapper>