From e0d09a46855ee27e098abf44456c8d31e26e4a64 Mon Sep 17 00:00:00 2001 From: xs Date: Mon, 6 Jan 2025 10:22:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?3.0.6=20=E5=9C=BA=E6=99=AF=E5=8C=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=9A=E5=9C=BA=E6=99=AF=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=A3=8E=E6=A0=BC=E6=9F=A5=E8=AF=A2=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E3=80=81=E5=A2=9E=E5=8A=A0=E3=80=81=E4=BF=AE=E6=94=B9=E5=92=8C?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HwTemplateStyleController.java | 105 ++++++++++++++++++ .../business/domain/HwTemplateStyle.java | 97 ++++++++++++++++ .../mapper/HwTemplateStyleMapper.java | 61 ++++++++++ .../service/IHwTemplateStyleService.java | 61 ++++++++++ .../impl/HwTemplateStyleServiceImpl.java | 99 +++++++++++++++++ .../mapper/business/HwTemplateStyleMapper.xml | 87 +++++++++++++++ 6 files changed, 510 insertions(+) create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTemplateStyleController.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTemplateStyle.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwTemplateStyleMapper.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwTemplateStyleService.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTemplateStyleServiceImpl.java create mode 100644 ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTemplateStyleMapper.xml diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTemplateStyleController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTemplateStyleController.java new file mode 100644 index 0000000..c4cc546 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTemplateStyleController.java @@ -0,0 +1,105 @@ +package com.ruoyi.business.controller; + +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import com.ruoyi.business.domain.HwTemplateStyle; +import com.ruoyi.business.service.IHwTemplateStyleService; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.utils.poi.ExcelUtil; +import com.ruoyi.common.core.web.page.TableDataInfo; + +/** + * 场景化图风格信息Controller + * + * @author xins + * @date 2025-01-06 + */ +@RestController +@RequestMapping("/templateStyle") +public class HwTemplateStyleController extends BaseController +{ + @Autowired + private IHwTemplateStyleService hwTemplateStyleService; + + /** + * 查询场景化图风格信息列表 + */ +// @RequiresPermissions("business:templateStyle:list") + @GetMapping("/list") + public TableDataInfo list(HwTemplateStyle hwTemplateStyle) + { + startPage(); + List list = hwTemplateStyleService.selectHwTemplateStyleList(hwTemplateStyle); + return getDataTable(list); + } + + /** + * 导出场景化图风格信息列表 + */ + @RequiresPermissions("business:templateStyle:export") + @Log(title = "场景化图风格信息", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, HwTemplateStyle hwTemplateStyle) + { + List list = hwTemplateStyleService.selectHwTemplateStyleList(hwTemplateStyle); + ExcelUtil util = new ExcelUtil(HwTemplateStyle.class); + util.exportExcel(response, list, "场景化图风格信息数据"); + } + + /** + * 获取场景化图风格信息详细信息 + */ +// @RequiresPermissions("business:templateStyle:query") + @GetMapping(value = "/{templateStyleId}") + public AjaxResult getInfo(@PathVariable("templateStyleId") Long templateStyleId) + { + return success(hwTemplateStyleService.selectHwTemplateStyleByTemplateStyleId(templateStyleId)); + } + + /** + * 新增场景化图风格信息 + */ +// @RequiresPermissions("business:templateStyle:add") + @Log(title = "场景化图风格信息", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody HwTemplateStyle hwTemplateStyle) + { + return toAjax(hwTemplateStyleService.insertHwTemplateStyle(hwTemplateStyle)); + } + + /** + * 修改场景化图风格信息 + */ +// @RequiresPermissions("business:templateStyle:edit") + @Log(title = "场景化图风格信息", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody HwTemplateStyle hwTemplateStyle) + { + return toAjax(hwTemplateStyleService.updateHwTemplateStyle(hwTemplateStyle)); + } + + /** + * 删除场景化图风格信息 + */ + @RequiresPermissions("business:templateStyle:remove") + @Log(title = "场景化图风格信息", businessType = BusinessType.DELETE) + @DeleteMapping("/{templateStyleIds}") + public AjaxResult remove(@PathVariable Long[] templateStyleIds) + { + return toAjax(hwTemplateStyleService.deleteHwTemplateStyleByTemplateStyleIds(templateStyleIds)); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTemplateStyle.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTemplateStyle.java new file mode 100644 index 0000000..dd6f198 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTemplateStyle.java @@ -0,0 +1,97 @@ +package com.ruoyi.business.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.annotation.Excel; +import com.ruoyi.common.core.web.domain.BaseEntity; + +/** + * 场景化图风格信息对象 hw_template_style + * + * @author xins + * @date 2025-01-06 + */ +public class HwTemplateStyle extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 风格信息ID */ + private Long templateStyleId; + + /** 风格类型(0自定义,1风格1,2风格2,3风格3) */ + @Excel(name = "风格类型(0自定义,1风格1,2风格2,3风格3)") + private String templateStyleType; + + /** 基准颜色 */ + @Excel(name = "基准颜色") + private String baseColor; + + /** 字体颜色 */ + @Excel(name = "字体颜色") + private String fontColor; + + /** 颜色库,多个以,隔开 */ + @Excel(name = "颜色库,多个以,隔开") + private String colors; + + public void setTemplateStyleId(Long templateStyleId) + { + this.templateStyleId = templateStyleId; + } + + public Long getTemplateStyleId() + { + return templateStyleId; + } + public void setTemplateStyleType(String templateStyleType) + { + this.templateStyleType = templateStyleType; + } + + public String getTemplateStyleType() + { + return templateStyleType; + } + public void setBaseColor(String baseColor) + { + this.baseColor = baseColor; + } + + public String getBaseColor() + { + return baseColor; + } + public void setFontColor(String fontColor) + { + this.fontColor = fontColor; + } + + public String getFontColor() + { + return fontColor; + } + public void setColors(String colors) + { + this.colors = colors; + } + + public String getColors() + { + return colors; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("templateStyleId", getTemplateStyleId()) + .append("templateStyleType", getTemplateStyleType()) + .append("baseColor", getBaseColor()) + .append("fontColor", getFontColor()) + .append("colors", getColors()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwTemplateStyleMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwTemplateStyleMapper.java new file mode 100644 index 0000000..55ddbea --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwTemplateStyleMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.business.mapper; + +import java.util.List; +import com.ruoyi.business.domain.HwTemplateStyle; + +/** + * 场景化图风格信息Mapper接口 + * + * @author xins + * @date 2025-01-06 + */ +public interface HwTemplateStyleMapper +{ + /** + * 查询场景化图风格信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 场景化图风格信息 + */ + public HwTemplateStyle selectHwTemplateStyleByTemplateStyleId(Long templateStyleId); + + /** + * 查询场景化图风格信息列表 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 场景化图风格信息集合 + */ + public List selectHwTemplateStyleList(HwTemplateStyle hwTemplateStyle); + + /** + * 新增场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + public int insertHwTemplateStyle(HwTemplateStyle hwTemplateStyle); + + /** + * 修改场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + public int updateHwTemplateStyle(HwTemplateStyle hwTemplateStyle); + + /** + * 删除场景化图风格信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 结果 + */ + public int deleteHwTemplateStyleByTemplateStyleId(Long templateStyleId); + + /** + * 批量删除场景化图风格信息 + * + * @param templateStyleIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteHwTemplateStyleByTemplateStyleIds(Long[] templateStyleIds); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwTemplateStyleService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwTemplateStyleService.java new file mode 100644 index 0000000..172d07e --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwTemplateStyleService.java @@ -0,0 +1,61 @@ +package com.ruoyi.business.service; + +import java.util.List; +import com.ruoyi.business.domain.HwTemplateStyle; + +/** + * 场景化图风格信息Service接口 + * + * @author xins + * @date 2025-01-06 + */ +public interface IHwTemplateStyleService +{ + /** + * 查询场景化图风格信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 场景化图风格信息 + */ + public HwTemplateStyle selectHwTemplateStyleByTemplateStyleId(Long templateStyleId); + + /** + * 查询场景化图风格信息列表 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 场景化图风格信息集合 + */ + public List selectHwTemplateStyleList(HwTemplateStyle hwTemplateStyle); + + /** + * 新增场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + public int insertHwTemplateStyle(HwTemplateStyle hwTemplateStyle); + + /** + * 修改场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + public int updateHwTemplateStyle(HwTemplateStyle hwTemplateStyle); + + /** + * 批量删除场景化图风格信息 + * + * @param templateStyleIds 需要删除的场景化图风格信息主键集合 + * @return 结果 + */ + public int deleteHwTemplateStyleByTemplateStyleIds(Long[] templateStyleIds); + + /** + * 删除场景化图风格信息信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 结果 + */ + public int deleteHwTemplateStyleByTemplateStyleId(Long templateStyleId); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTemplateStyleServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTemplateStyleServiceImpl.java new file mode 100644 index 0000000..58649a9 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTemplateStyleServiceImpl.java @@ -0,0 +1,99 @@ +package com.ruoyi.business.service.impl; + +import java.util.List; +import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.security.utils.SecurityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.business.mapper.HwTemplateStyleMapper; +import com.ruoyi.business.domain.HwTemplateStyle; +import com.ruoyi.business.service.IHwTemplateStyleService; + +/** + * 场景化图风格信息Service业务层处理 + * + * @author xins + * @date 2025-01-06 + */ +@Service +public class HwTemplateStyleServiceImpl implements IHwTemplateStyleService +{ + @Autowired + private HwTemplateStyleMapper hwTemplateStyleMapper; + + /** + * 查询场景化图风格信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 场景化图风格信息 + */ + @Override + public HwTemplateStyle selectHwTemplateStyleByTemplateStyleId(Long templateStyleId) + { + return hwTemplateStyleMapper.selectHwTemplateStyleByTemplateStyleId(templateStyleId); + } + + /** + * 查询场景化图风格信息列表 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 场景化图风格信息 + */ + @Override + public List selectHwTemplateStyleList(HwTemplateStyle hwTemplateStyle) + { + return hwTemplateStyleMapper.selectHwTemplateStyleList(hwTemplateStyle); + } + + /** + * 新增场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + @Override + public int insertHwTemplateStyle(HwTemplateStyle hwTemplateStyle) + { + hwTemplateStyle.setCreateBy(SecurityUtils.getUsername()); + hwTemplateStyle.setCreateTime(DateUtils.getNowDate()); + return hwTemplateStyleMapper.insertHwTemplateStyle(hwTemplateStyle); + } + + /** + * 修改场景化图风格信息 + * + * @param hwTemplateStyle 场景化图风格信息 + * @return 结果 + */ + @Override + public int updateHwTemplateStyle(HwTemplateStyle hwTemplateStyle) + { + hwTemplateStyle.setUpdateBy(SecurityUtils.getUsername()); + hwTemplateStyle.setUpdateTime(DateUtils.getNowDate()); + return hwTemplateStyleMapper.updateHwTemplateStyle(hwTemplateStyle); + } + + /** + * 批量删除场景化图风格信息 + * + * @param templateStyleIds 需要删除的场景化图风格信息主键 + * @return 结果 + */ + @Override + public int deleteHwTemplateStyleByTemplateStyleIds(Long[] templateStyleIds) + { + return hwTemplateStyleMapper.deleteHwTemplateStyleByTemplateStyleIds(templateStyleIds); + } + + /** + * 删除场景化图风格信息信息 + * + * @param templateStyleId 场景化图风格信息主键 + * @return 结果 + */ + @Override + public int deleteHwTemplateStyleByTemplateStyleId(Long templateStyleId) + { + return hwTemplateStyleMapper.deleteHwTemplateStyleByTemplateStyleId(templateStyleId); + } +} diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTemplateStyleMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTemplateStyleMapper.xml new file mode 100644 index 0000000..f526e7e --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTemplateStyleMapper.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + select template_style_id, template_style_type, base_color, font_color, colors, create_by, create_time, update_by, update_time from hw_template_style + + + + + + + + insert into hw_template_style + + template_style_type, + base_color, + font_color, + colors, + create_by, + create_time, + update_by, + update_time, + + + #{templateStyleType}, + #{baseColor}, + #{fontColor}, + #{colors}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update hw_template_style + + template_style_type = #{templateStyleType}, + base_color = #{baseColor}, + font_color = #{fontColor}, + colors = #{colors}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where template_style_id = #{templateStyleId} + + + + delete from hw_template_style where template_style_id = #{templateStyleId} + + + + delete from hw_template_style where template_style_id in + + #{templateStyleId} + + + \ No newline at end of file From afddf2994e3c2d9fa5028362927e09b87202f612 Mon Sep 17 00:00:00 2001 From: xs Date: Mon, 6 Jan 2025 10:55:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?3.0.7=20=E5=9C=BA=E6=99=AF=E5=8C=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE:=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E6=95=B0?= =?UTF-8?q?=E6=8D=AETDengine=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TdEngineController.java | 39 +++++++++++++++++++ .../ruoyi/tdengine/mapper/TdEngineMapper.java | 11 ++++++ .../tdengine/service/ITdEngineService.java | 10 +++++ .../service/impl/TdEngineServiceImpl.java | 22 +++++++++++ .../mapper/tdengine/TdEngineMapper.xml | 13 +++++++ 5 files changed, 95 insertions(+) diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java index 03b8c3a..df7059b 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java @@ -529,4 +529,43 @@ public class TdEngineController { return R.fail(message); } } + + + + /** + * @param tdGroupSelectDto + * @return R + * @MethodDescription 按日期分组获取数据(1s,1m,1d,1w,30d) 返回格式,时间,数值列 + * 历史数据 SELECT _WSTART as time, _WEND,max(value1) as maxValue,min(value1) as minValue,avg(value1) as avgValue,sum(value1) as sumValue from db_hwsaas.t_device_260 + * where ts>=now-10d and ts getGroupDeviceData(@Validated @RequestBody TdGroupSelectDto tdGroupSelectDto) { + try { +// if (selectVisualDto.getType() == 0) {//查询历史 +// return R.ok(this.tdEngineService.getHistoryData(selectVisualDto)); +// }else if(selectVisualDto.getType() == 1) {//查询实时 +// return R.ok(this.tdEngineService.getRealtimeData(selectVisualDto)); +// }else {//查询聚合 +// return R.ok(this.tdEngineService.getAggregateData(selectVisualDto)); +// } + TdReturnDataVo returnDataVo = new TdReturnDataVo(); + returnDataVo.setDataList(this.tdEngineService.getGroupDeviceData(tdGroupSelectDto)); + return R.ok(returnDataVo); + } catch (UncategorizedSQLException e) { + String message = e.getCause().getMessage(); + try { + message = message.substring(message.lastIndexOf("invalid operation")); + } catch (Exception ex) { + } + log.error(message); + return R.fail(message); + } catch (Exception e) { + log.error(e.getMessage()); + return R.fail(e.getMessage()); + } + } + + } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java index 70b638f..ca39a2a 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java @@ -165,6 +165,17 @@ public interface TdEngineMapper { Map getDeviceLocation(TdSelectDto tdSelectDto); + + /** + * @return List> + * @param: tdGroupSelectDto + * @description 按时间分组获取设备历史数据 + * @author xins + * @date 2024-12-31 16:11 + */ + List> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto); + + // /** // * 检查表是否存在 // * @param dataBaseName diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java index 5aa074c..90d8a0e 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java @@ -142,6 +142,16 @@ public interface ITdEngineService { */ public void dropTable(String databaseName, String tableName) throws Exception; + /** + * @return List> + * @param: tdGroupSelectDto + * @description 根据日期分组获取历史数据 + * @author xins + * @date 2023-08-29 15:52 + */ + public List> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto); + + Map getDeviceLocation(TdSelectDto tdSelectDto); // void initSTableFrame(String msg) throws Exception; diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java index a1859d8..b029b4a 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java @@ -261,6 +261,28 @@ public class TdEngineServiceImpl implements ITdEngineService { } + /** + * @return List> + * @param: tdGroupSelectDto + * @description 根据日期分组获取历史数据 + * @author xins + * @date 2023-08-29 15:52 + */ + @Override + public List> getGroupDeviceData(TdGroupSelectDto tdGroupSelectDto) { +// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByFieldName())) { +// tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); +// } +// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByMode())) { +// tdHistorySelectDto.setOrderByMode(TdEngineConstants.DEFAULT_ORDER_BY_MODE); +// } + + List> groupDataMaps = this.tdEngineMapper.getGroupDeviceData(tdGroupSelectDto); + + return groupDataMaps; + } + + // // /** // * 检查数据库表是否存在 diff --git a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml index e5d99c3..5d57b55 100644 --- a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml +++ b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml @@ -319,6 +319,19 @@ drop table #{databaseName}.#{tableName} + + + + - - - diff --git a/ruoyi-ui/src/views/portal/contactUsInfo/index.vue b/ruoyi-ui/src/views/portal/contactUsInfo/index.vue index 7c41f04..f298e8d 100644 --- a/ruoyi-ui/src/views/portal/contactUsInfo/index.vue +++ b/ruoyi-ui/src/views/portal/contactUsInfo/index.vue @@ -40,16 +40,6 @@ - - 新增 - - + Date: Mon, 6 Jan 2025 12:22:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?3.0.9=20PLC=E5=8D=8F=E8=AE=AE=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PlcDeviceController.java | 147 +++++ .../controller/PlcDeviceModeController.java | 111 ++++ .../PlcDeviceModeFunctionController.java | 87 +++ .../com/ruoyi/business/domain/PlcDevice.java | 247 ++++++++ .../ruoyi/business/domain/PlcDeviceMode.java | 147 +++++ .../domain/PlcDeviceModeFunction.java | 134 +++++ .../service/PlcDeviceModeFunctionService.java | 55 ++ .../service/PlcDeviceModeService.java | 66 +++ .../business/service/PlcDeviceService.java | 77 +++ .../PlcDeviceModeFunctionServiceImpl.java | 252 ++++++++ .../impl/PlcDeviceModeServiceImpl.java | 189 ++++++ .../service/impl/PlcDeviceServiceImpl.java | 551 ++++++++++++++++++ .../mapper/business/PlcDeviceDao.xml | 280 +++++++++ .../mapper/business/PlcDeviceModeDao.xml | 206 +++++++ .../business/PlcDeviceModeFunctionDao.xml | 182 ++++++ 15 files changed, 2731 insertions(+) create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java create mode 100644 ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml create mode 100644 ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml create mode 100644 ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java new file mode 100644 index 0000000..a45ee4a --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java @@ -0,0 +1,147 @@ +package com.ruoyi.business.controller; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.PlcDevice; +import com.ruoyi.business.domain.PlcDeviceMode; +import com.ruoyi.business.service.PlcDeviceService; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.web.page.TableDataInfo; +import com.ruoyi.common.security.utils.SecurityUtils; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * plc设备信息(PlcDevice)表控制层 + * + * @author makejava + * @since 2024-12-19 16:22:43 + */ +@RestController +@RequestMapping("plcDevice") +public class PlcDeviceController extends BaseController { + /** + * 服务对象 + */ + @Resource + private PlcDeviceService plcDeviceService; + + /** + * 分页查询 + * + * @param plcDevice 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @GetMapping + public ResponseEntity> queryByPage(PlcDevice plcDevice, PageRequest pageRequest) { + return ResponseEntity.ok(this.plcDeviceService.queryByPage(plcDevice, pageRequest)); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{deviceId}") + public AjaxResult queryById(@PathVariable("deviceId") Long id) throws JsonProcessingException { + return AjaxResult.success(this.plcDeviceService.queryById(id)); + } + + /** + * 新增数据 + * + * @param plcDevice 实体 + * @return 新增结果 + */ + @PostMapping + public AjaxResult add(@RequestBody PlcDevice plcDevice) { + return toAjax(this.plcDeviceService.insert(plcDevice)); + } + + @PutMapping("/changeDeviceStatus") + public AjaxResult changeDeviceStatus(@RequestBody PlcDevice device) { + return toAjax(plcDeviceService.changeDeviceStatus(device)); + } + + /** + * 编辑数据 + * + * @param plcDevice 实体 + * @return 编辑结果 + */ +// @PutMapping +// public AjaxResult edit(PlcDevice plcDevice) { +// return AjaxResult.success(plcDeviceService.update(plcDevice)); +// } + @GetMapping("getProtocols") + public AjaxResult getProtocols(){ + HashMap map = new HashMap<>(); + map.put("protocolName","mc"); + map.put("protocolValue","1"); + HashMap map1 = new HashMap<>(); + map1.put("protocolName","modbus"); + map1.put("protocolValue","2"); + ArrayList objects = new ArrayList<>(); + objects.add(map); + objects.add(map1); + return AjaxResult.success(objects); + } + /** + * 删除数据 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping("{deviceId}") + public AjaxResult deleteById(@PathVariable("deviceId") Long deviceId) { + return AjaxResult.success(this.plcDeviceService.deleteById(deviceId)); + } + @GetMapping("/modbusDataProcess") + public AjaxResult modbusDataProcess() throws JsonProcessingException { + return AjaxResult.success(plcDeviceService.modbusDataProcess()); + } + + @GetMapping("/mcDataProcess") + public AjaxResult mcDataProcess() throws JsonProcessingException { + return AjaxResult.success(plcDeviceService.mcDataProcess()); + } + @GetMapping("/aeDataProcess") + public AjaxResult aeDataProcess() throws JsonProcessingException { + return AjaxResult.success(plcDeviceService.aeDataProcess()); + } + @GetMapping("/linkDataProcess") + public AjaxResult linkDataProcess() throws JsonProcessingException { + return AjaxResult.success(plcDeviceService.linkDataProcess()); + } + @GetMapping("/list") + public TableDataInfo list(PlcDevice hwDevice) { + startPage(); + List list = plcDeviceService.selectHwDeviceJoinList(hwDevice); + return getDataTable(list); + } + @GetMapping(value = {"/getDeviceModes/", "/getDeviceModes/{sceneId}"}) + public AjaxResult getDeviceModes(@PathVariable(value = "sceneId", required = false) Long sceneId) { + PlcDeviceMode queryDeviceMode = new PlcDeviceMode(); + queryDeviceMode.setSceneId(sceneId); + return success(plcDeviceService.selectHwDeviceModeList(queryDeviceMode)); + } + + @PutMapping + public AjaxResult edit(@RequestBody PlcDevice hwDevice) { + hwDevice.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(plcDeviceService.updateDevice(hwDevice)); + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java new file mode 100644 index 0000000..0ae49e6 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java @@ -0,0 +1,111 @@ +package com.ruoyi.business.controller; + +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.HwDeviceModeFunction; +import com.ruoyi.business.domain.PlcDeviceMode; +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import com.ruoyi.business.service.PlcDeviceModeService; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.web.page.TableDataInfo; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * plc设备模型(PlcDeviceMode)表控制层 + * + * @author makejava + * @since 2024-12-19 16:23:27 + */ +@RestController +@RequestMapping("plcDeviceMode") +public class PlcDeviceModeController extends BaseController { + /** + * 服务对象 + */ + @Resource + private PlcDeviceModeService plcDeviceModeService; + + /** + * 分页查询 + * + * @param plcDeviceMode 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @GetMapping + public ResponseEntity> queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) { + return ResponseEntity.ok(this.plcDeviceModeService.queryByPage(plcDeviceMode, pageRequest)); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{deviceModeId}") + public AjaxResult queryById(@PathVariable("deviceModeId") Long deviceModeId) { + PlcDeviceMode hwDeviceMode = plcDeviceModeService.selectHwDeviceModeByDeviceModeId(deviceModeId); + List hwDeviceModeFunctions = plcDeviceModeService.selectFunctionList(deviceModeId); + hwDeviceMode.setFunctionList(null); + Map map = new HashMap<>(); + map.put("deviceMode", hwDeviceMode); + map.put("deviceModeFunctionMap", hwDeviceModeFunctions); + return success(map); + } + + /** + * 新增数据 + * + * @param plcDeviceMode 实体 + * @return 新增结果 + */ + @PostMapping + public AjaxResult add(@RequestBody PlcDeviceMode plcDeviceMode) { + return toAjax(this.plcDeviceModeService.insert(plcDeviceMode)); + } + + @RequiresPermissions("business:deviceMode:list") + @GetMapping("/list") + public TableDataInfo list(PlcDeviceMode hwDeviceMode) { + startPage(); + hwDeviceMode.setDeviceModeStatus(HwDictConstants.DEVICE_MODE_STATUS_NORMAL); + List list = plcDeviceModeService.selectList(hwDeviceMode); + return getDataTable(list); + } + + /** + * 编辑数据 + * + * @param plcDeviceMode 实体 + * @return 编辑结果 + */ + @PutMapping + public AjaxResult edit(@RequestBody PlcDeviceMode plcDeviceMode) { + return toAjax(this.plcDeviceModeService.update(plcDeviceMode)); + } + + /** + * 删除数据 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping("/{deviceModeIds}") + public ResponseEntity deleteById(@PathVariable Long[] deviceModeIds) { + return ResponseEntity.ok(this.plcDeviceModeService.deleteHwDeviceModeByDeviceModeIds(deviceModeIds)); + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java new file mode 100644 index 0000000..4cfe0b6 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java @@ -0,0 +1,87 @@ +package com.ruoyi.business.controller; + + +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import com.ruoyi.business.service.PlcDeviceModeFunctionService; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * plc设备模型功能(PlcDeviceModeFunction)表控制层 + * + * @author makejava + * @since 2024-12-19 16:23:52 + */ +@RestController +@RequestMapping("plcDeviceModeFunction") +public class PlcDeviceModeFunctionController extends BaseController { + /** + * 服务对象 + */ + @Resource + private PlcDeviceModeFunctionService plcDeviceModeFunctionService; + + /** + * 分页查询 + * + * @param plcDeviceModeFunction 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @GetMapping + public ResponseEntity> queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) { + return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryByPage(plcDeviceModeFunction, pageRequest)); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + public ResponseEntity queryById(@PathVariable("id") Long id) { + return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryById(id)); + } + + /** + * 新增数据 + * + * @param plcDeviceModeFunction 实体 + * @return 新增结果 + */ + @PostMapping + public AjaxResult add(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) { + return toAjax(this.plcDeviceModeFunctionService.insert(plcDeviceModeFunction)); + } + + /** + * 编辑数据 + * + * @param plcDeviceModeFunction 实体 + * @return 编辑结果 + */ + @PutMapping + public AjaxResult edit(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) { + return toAjax(this.plcDeviceModeFunctionService.update(plcDeviceModeFunction)); + } + + /** + * 删除数据 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping("/{modeFunctionId}") + public AjaxResult deleteById(@PathVariable("modeFunctionId") Long modeFunctionId) { + return toAjax(this.plcDeviceModeFunctionService.deleteById(modeFunctionId)); + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java new file mode 100644 index 0000000..2f977a3 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java @@ -0,0 +1,247 @@ +package com.ruoyi.business.domain; + +import com.ruoyi.common.core.annotation.Excel; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * plc设备信息(PlcDevice)实体类 + * + * @author makejava + * @since 2024-12-19 16:22:47 + */ +@Data +public class PlcDevice implements Serializable { + private static final long serialVersionUID = -11771385039084146L; + /** + * 设备ID + */ + private Long deviceId; + /** + * 设备编号 + */ + private String deviceCode; + /** + * 设备名称 + */ + private String deviceName; + /** + * 租户ID,关联hw_tenant的tenant_id + */ + private Long tenantId; + /** + * 所属场景,关联hw_scene表的scene_id字段 + */ + private Long sceneId; + /** + * ip地址 + */ + private String ip; + /** + * 端口 + */ + private Integer port1; + /** + * 读取寄存器位置 + */ + private String location; + /** + * 协议类型,1mc,2modbus + */ + private Integer accessProtocol; + private Integer station; + /** + * 长度 + */ + private Integer length; + private String dataType; + private String tenantName; + private String sceneName; + private String deviceModeName; + /** + * 设备模型,关联表hw_device_mode的字段device_mode_id + */ + @Excel(name = "设备模型") + private Long deviceModeId; + /** + * 设备状态(0、测试,1、发布,9、删除) + */ + private String deviceStatus; + /** + * 创建人 + */ + private String createBy; + /** + * 创建时间 + */ + private Date createTime; + private Date publishTime; + /** + * 更新人 + */ + private String updateBy; + /** + * 更新时间 + */ + private Date updateTime; + public void setDeviceModeId(Long deviceModeId) { + this.deviceModeId = deviceModeId; + } + + public Long getDeviceModeId() { + return deviceModeId; + } + + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getDeviceCode() { + return deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } +// public String getdLocation() { +// return dLocation; +// } +// +// public void setdLocation(String dLocation) { +// this.dLocation = dLocation; +// } + + public Long getTenantId() { + return tenantId; + } + + public void setTenantId(Long tenantId) { + this.tenantId = tenantId; + } + + public Long getSceneId() { + return sceneId; + } + + public void setSceneId(Long sceneId) { + this.sceneId = sceneId; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public Integer getPort1() { + return port1; + } + + public void setPort1(Integer port1) { + this.port1 = port1; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Integer getAccessProtocol() { + return accessProtocol; + } + + public void setAccessProtocol(Integer accessProtocol) { + this.accessProtocol = accessProtocol; + } + public Integer getStation() { + return station; + } + + public void setStation(Integer station) { + this.station = station; + } + + public Integer getLength() { + return length; + } + + public void setLength(Integer length) { + this.length = length; + } + + public String getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(String deviceStatus) { + this.deviceStatus = deviceStatus; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + public Date getPublishTime() { + return publishTime; + } + + public void setPublishTime(Date publishTime) { + this.publishTime = publishTime; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java new file mode 100644 index 0000000..78c3cc1 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java @@ -0,0 +1,147 @@ +package com.ruoyi.business.domain; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * plc设备模型(PlcDeviceMode)实体类 + * + * @author makejava + * @since 2024-12-19 16:23:27 + */ +@Data +public class PlcDeviceMode implements Serializable { + private static final long serialVersionUID = 441335518091339874L; + /** + * 设备模型ID + */ + private Long deviceModeId; + /** + * 设备模型名称 + */ + private String deviceModeName; + /** + * 租户ID,关联hw_tenant的tenant_id + */ + private Long tenantId; + /** + * 所属场景,关联hw_scene表的scene_id字段 + */ + private Long sceneId; + /** + * 设备模型状态(1:启用,9:删除) + */ + private String deviceModeStatus; + /** + * 创建人 + */ + private String createBy; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新人 + */ + private String updateBy; + /** + * 更新时间 + */ + private Date updateTime; + + private List functionList; + private String tenantName; + private String sceneName; + + + public Long getDeviceModeId() { + return deviceModeId; + } + + public void setDeviceModeId(Long deviceModeId) { + this.deviceModeId = deviceModeId; + } + + public String getDeviceModeName() { + return deviceModeName; + } + + public void setDeviceModeName(String deviceModeName) { + this.deviceModeName = deviceModeName; + } + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + public String getSceneName() { + return sceneName; + } + + public void setSceneName(String sceneName) { + this.sceneName = sceneName; + } + + public Long getTenantId() { + return tenantId; + } + + public void setTenantId(Long tenantId) { + this.tenantId = tenantId; + } + + public Long getSceneId() { + return sceneId; + } + + public void setSceneId(Long sceneId) { + this.sceneId = sceneId; + } + + public String getDeviceModeStatus() { + return deviceModeStatus; + } + + public void setDeviceModeStatus(String deviceModeStatus) { + this.deviceModeStatus = deviceModeStatus; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java new file mode 100644 index 0000000..43b7211 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java @@ -0,0 +1,134 @@ +package com.ruoyi.business.domain; + +import com.ruoyi.common.core.annotation.Excel; + +import java.io.Serializable; + +/** + * plc设备模型功能(PlcDeviceModeFunction)实体类 + * + * @author makejava + * @since 2024-12-19 16:23:52 + */ +public class PlcDeviceModeFunction implements Serializable { + private static final long serialVersionUID = -19875863077506718L; + /** + * 设备模型功能ID + */ + private Long modeFunctionId; + /** + * 设备模型ID,关联表plc_device_mode的device_mode_id + */ + private Long deviceModeId; + /** + * 功能名称 + */ + private String functionName; + /** + * 标识符(支持大小写字母、数字和下划线,对外暂时不超过50个字符) + */ + private String functionIdentifier; + /** + * 数据类型(2、int,4、float,5、double,6、binary(image/base64),9、bool,10、string) + */ + private Integer dataType; + /** + * 数据定义,按json保存,示例如下: + 1、取值范围:{'minValue':1,'maxValue':100}, + 2、枚举型: + {'1':'成功','2','失败','3','提示} + 3、bool型: + {'0':'关','1','开'} + 4、Text型: + {'dataLength':1024} + 5、String类型(此类型需要定义在数据字典中,支持多语言): + {'dateFormat':'String类型的UTC时间戳(毫秒)'} + */ + private String dataDefinition; + /** + * 单位 + */ + private String propertyUnit; + /** + * 描述 + */ + private String remark; + /** 功能模式(1、属性,2、服务,3、事件) */ +// @Excel(name = "功能模式", readConverterExp = "1=属性,2=服务,3=事件") + private String functionMode; + + public void setFunctionMode(String functionMode) + { + this.functionMode = functionMode; + } + + public String getFunctionMode() + { + return functionMode; + } + public Long getModeFunctionId() { + return modeFunctionId; + } + + public void setModeFunctionId(Long modeFunctionId) { + this.modeFunctionId = modeFunctionId; + } + + public Long getDeviceModeId() { + return deviceModeId; + } + + public void setDeviceModeId(Long deviceModeId) { + this.deviceModeId = deviceModeId; + } + + public String getFunctionName() { + return functionName; + } + + public void setFunctionName(String functionName) { + this.functionName = functionName; + } + + public String getFunctionIdentifier() { + return functionIdentifier; + } + + public void setFunctionIdentifier(String functionIdentifier) { + this.functionIdentifier = functionIdentifier; + } + + public Integer getDataType() { + return dataType; + } + + public void setDataType(Integer dataType) { + this.dataType = dataType; + } + + public String getDataDefinition() { + return dataDefinition; + } + + public void setDataDefinition(String dataDefinition) { + this.dataDefinition = dataDefinition; + } + + public String getPropertyUnit() { + return propertyUnit; + } + + public void setPropertyUnit(String propertyUnit) { + this.propertyUnit = propertyUnit; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + +} + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java new file mode 100644 index 0000000..9985e1f --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java @@ -0,0 +1,55 @@ +package com.ruoyi.business.service; +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +/** + * plc设备模型功能(PlcDeviceModeFunction)表服务接口 + * + * @author makejava + * @since 2024-12-19 16:23:52 + */ +public interface PlcDeviceModeFunctionService { + + /** + * 通过ID查询单条数据 + * + * @param modeFunctionId 主键 + * @return 实例对象 + */ + PlcDeviceModeFunction queryById(Long modeFunctionId); + + /** + * 分页查询 + * + * @param plcDeviceModeFunction 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + Page queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest); + + /** + * 新增数据 + * + * @param plcDeviceModeFunction 实例对象 + * @return 实例对象 + */ + int insert(PlcDeviceModeFunction plcDeviceModeFunction); + + /** + * 修改数据 + * + * @param plcDeviceModeFunction 实例对象 + * @return 实例对象 + */ + int update(PlcDeviceModeFunction plcDeviceModeFunction); + + /** + * 通过主键删除数据 + * + * @param modeFunctionId 主键 + * @return 是否成功 + */ + int deleteById(Long modeFunctionId); + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java new file mode 100644 index 0000000..92d87e6 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java @@ -0,0 +1,66 @@ +package com.ruoyi.business.service; +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.PlcDeviceMode; +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +/** + * plc设备模型(PlcDeviceMode)表服务接口 + * + * @author makejava + * @since 2024-12-19 16:23:27 + */ +public interface PlcDeviceModeService { + + /** + * 通过ID查询单条数据 + * + * @param deviceModeId 主键 + * @return 实例对象 + */ + PlcDeviceMode queryById(Long deviceModeId); + + /** + * 分页查询 + * + * @param plcDeviceMode 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + Page queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest); + + /** + * 新增数据 + * + * @param plcDeviceMode 实例对象 + * @return 实例对象 + */ + int insert(PlcDeviceMode plcDeviceMode); + + /** + * 修改数据 + * + * @param plcDeviceMode 实例对象 + * @return 实例对象 + */ + int update(PlcDeviceMode plcDeviceMode); + + /** + * 通过主键删除数据 + * + * @param deviceModeId 主键 + * @return 是否成功 + */ + boolean deleteById(Long deviceModeId); + + List selectList(PlcDeviceMode hwDeviceMode); + + PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId); + + List selectFunctionList(Long deviceModeId); + + int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java new file mode 100644 index 0000000..b4b3451 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java @@ -0,0 +1,77 @@ +package com.ruoyi.business.service; + + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.PlcDevice; +import com.ruoyi.business.domain.PlcDeviceMode; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +/** + * plc设备信息(PlcDevice)表服务接口 + * + * @author makejava + * @since 2024-12-19 16:22:51 + */ +public interface PlcDeviceService { + + /** + * 通过ID查询单条数据 + * + * @param deviceId 主键 + * @return 实例对象 + */ + PlcDevice queryById(Long deviceId) throws JsonProcessingException; + + /** + * 分页查询 + * + * @param plcDevice 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + Page queryByPage(PlcDevice plcDevice, PageRequest pageRequest); + + /** + * 新增数据 + * + * @param plcDevice 实例对象 + * @return 实例对象 + */ + int insert(PlcDevice plcDevice); + + /** + * 修改数据 + * + * @param plcDevice 实例对象 + * @return 实例对象 + */ + PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException; + + /** + * 通过主键删除数据 + * + * @param deviceId 主键 + * @return 是否成功 + */ + int deleteById(Long deviceId); + + String modbusDataProcess() throws JsonProcessingException; + + String mcDataProcess() throws JsonProcessingException; + + List selectHwDeviceJoinList(PlcDevice hwDevice); + + List selectHwDeviceModeList(PlcDeviceMode queryDeviceMode); + + int changeDeviceStatus(PlcDevice device); + + int updateDevice(PlcDevice hwDevice); + + String aeDataProcess() throws JsonProcessingException; + + String linkDataProcess(); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java new file mode 100644 index 0000000..38fb992 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java @@ -0,0 +1,252 @@ +package com.ruoyi.business.service.impl; + +import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.HwDeviceModeFunction; +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao; +import com.ruoyi.business.service.PlcDeviceModeFunctionService; +import com.ruoyi.common.core.constant.Constants; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; +import com.ruoyi.common.core.constant.TdEngineConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.enums.DataTypeEnums; +import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.tdengine.api.RemoteTdEngineService; +import com.ruoyi.tdengine.api.domain.TdField; +import com.ruoyi.tdengine.api.domain.TdSuperTableVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * plc设备模型功能(PlcDeviceModeFunction)表服务实现类 + * + * @author makejava + * @since 2024-12-19 16:23:52 + */ +@Service("plcDeviceModeFunctionService") +public class PlcDeviceModeFunctionServiceImpl implements PlcDeviceModeFunctionService { + @Resource + private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao; + @Autowired + private RemoteTdEngineService remoteTdEngineService; + + /** + * 通过ID查询单条数据 + * + * @param modeFunctionId 主键 + * @return 实例对象 + */ + @Override + public PlcDeviceModeFunction queryById(Long modeFunctionId) { + return this.plcDeviceModeFunctionDao.queryById(modeFunctionId); + } + + /** + * 分页查询 + * + * @param plcDeviceModeFunction 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @Override + public Page queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) { + long total = this.plcDeviceModeFunctionDao.count(plcDeviceModeFunction); + return new PageImpl<>(this.plcDeviceModeFunctionDao.queryAllByLimit(plcDeviceModeFunction, pageRequest), pageRequest, total); + } + + /** + * 新增数据 + * + * @param plcDeviceModeFunction 实例对象 + * @return 实例对象 + */ + @Override + public int insert(PlcDeviceModeFunction plcDeviceModeFunction) { + checkDuplicateIdentifiers(plcDeviceModeFunction); + int functionId = this.plcDeviceModeFunctionDao.insert(plcDeviceModeFunction); + this.addTdSuperTableColumn(plcDeviceModeFunction); + return functionId; + } + private void addTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) { + String functionMode = hwDeviceModeFunction.getFunctionMode(); + if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); + String dbName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId; + TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); + TdField schemaField = new TdField(); + String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier()); + String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer; + schemaField.setFieldName(functionIdentifier); + Integer dataType = hwDeviceModeFunction.getDataType(); + schemaField.setDataTypeCode(dataType); + //一个integer类型,一个long类型,需要转换为string类型比较 + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition())); + } + tdSuperTableVo.setDatabaseName(dbName); + tdSuperTableVo.setSuperTableName(superTableName); + tdSuperTableVo.setField(schemaField); + R tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + } + + /** + * 修改数据 + * + * @param plcDeviceModeFunction 实例对象 + * @return 实例对象 + */ + @Override + public int update(PlcDeviceModeFunction plcDeviceModeFunction) { + //校验有没有重复标识符 + checkDuplicateIdentifiers(plcDeviceModeFunction); + + //与数据库中的数据判断标识符有没有修改,如果修改则在tdengine超级表删除老的字段,增加修改的字段 + String functionMode = plcDeviceModeFunction.getFunctionMode(); + if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + PlcDeviceModeFunction dbHwDeviceModeFunction = plcDeviceModeFunctionDao + .queryById(plcDeviceModeFunction.getModeFunctionId()); + + String dbFunctionIdentifier = dbHwDeviceModeFunction.getFunctionIdentifier(); + String functionIdentifier = plcDeviceModeFunction.getFunctionIdentifier(); + Integer dbDataType = dbHwDeviceModeFunction.getDataType(); + Integer dataType = plcDeviceModeFunction.getDataType(); + //标识符或数据类型变化时需要先删除超级表column,再增加新的column,删除的column数据将会清空(有事务问题,暂时不支持) + if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier) + || !dbDataType.equals(dataType)) { +// this.dropTdSuperTableColumn(dbHwDeviceModeFunction); +// this.addTdSuperTableColumn(hwDeviceModeFunction); + throw new RuntimeException("标识符和数据类型不支持修改,可删除再新建"); + } else { + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + int dbDataDefinition = Integer.parseInt(dbHwDeviceModeFunction.getDataDefinition()); + int dataDefinition = Integer.parseInt(plcDeviceModeFunction.getDataDefinition()); + if (dbDataDefinition > dataDefinition) { + throw new ServiceException("数据长度只能改大"); + } else if (dbDataDefinition < dataDefinition) { + this.modifyTdSuperTableColumn(plcDeviceModeFunction); + } + } + } + } else { + plcDeviceModeFunctionDao.deleteById(plcDeviceModeFunction.getModeFunctionId()); + List hwDeviceModeFunctions = new ArrayList<>(); + hwDeviceModeFunctions.add(plcDeviceModeFunction); +// batchInsertHwDeviceModeParameters(hwDeviceModeFunctions); + } + + return plcDeviceModeFunctionDao.update(plcDeviceModeFunction); + } + private void modifyTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) { + String functionMode = hwDeviceModeFunction.getFunctionMode(); + if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); + String dbName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId; + TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); + TdField schemaField = new TdField(); + String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier()); + String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer; + schemaField.setFieldName(functionIdentifier); + Integer dataType = hwDeviceModeFunction.getDataType(); + schemaField.setDataTypeCode(dataType.intValue()); + //一个integer类型,一个long类型,需要转换为string类型比较 + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition())); + } + tdSuperTableVo.setDatabaseName(dbName); + tdSuperTableVo.setSuperTableName(superTableName); + tdSuperTableVo.setField(schemaField); + R tdReturnMsg = this.remoteTdEngineService.modifySuperTableColumn(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + } + /** + * @param: hwDeviceModeFunction + * @description 在编辑设备模型添加功能或者编辑功能时判断属性值 + * @author xins + * @date 2023-09-13 13:38 + */ + private void checkDuplicateIdentifiers(PlcDeviceModeFunction hwDeviceModeFunction) { + String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier(); + if (TdEngineConstants.ABNDON_FUNCTION_IDENTIFIERS.contains(functionIdentifier.toLowerCase())) { + throw new ServiceException("标识符不能等于:" + functionIdentifier); + } + +// R keyLongitudeR = remoteConfigService.getConfigKeyStr("hw.gps.longitude"); +// R keyLatitudeR = remoteConfigService.getConfigKeyStr("hw.gps.latitude"); +// String keyLongitude = keyLongitudeR.getData(); +// String keyLatitude = keyLatitudeR.getData(); + +// if (StringUtils.isEmpty(hwDeviceModeFunction.getCoordinate()) && +// (hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLongitude) +// || hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLatitude))) { +// throw new ServiceException("非定位设备模型标识符不能等于:" + keyLongitude + "或" + keyLatitude); +// } + + Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); + HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction(); + queryDeviceModeFunction.setDeviceModeId(deviceModeId); + List hwDeviceModeFunctions = plcDeviceModeFunctionDao.selectFunctionList(deviceModeId); + + /** + * 判断时如果是修改的标识符则不能跟自己比较 + */ + long duplicateCount = hwDeviceModeFunctions.stream().filter(dmf -> + ((hwDeviceModeFunction.getModeFunctionId() == null) || + (hwDeviceModeFunction.getModeFunctionId() != null && !hwDeviceModeFunction.getModeFunctionId().equals(dmf.getModeFunctionId()))) + && dmf.getFunctionIdentifier().equalsIgnoreCase(hwDeviceModeFunction.getFunctionIdentifier())).count(); + if (duplicateCount > 0) { + throw new ServiceException("标识符重复"); + } + } + + /** + * 通过主键删除数据 + * + * @param modeFunctionId 主键 + * @return 是否成功 + */ + @Override + public int deleteById(Long modeFunctionId) { + PlcDeviceModeFunction hwDeviceModeFunction = plcDeviceModeFunctionDao.queryById(modeFunctionId); + //查询是否有已发布的设备关联此设备模型 + int rows = plcDeviceModeFunctionDao.deleteById(modeFunctionId); + this.dropTdSuperTableColumn(hwDeviceModeFunction); + return rows; + } + private void dropTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) { + String functionMode = hwDeviceModeFunction.getFunctionMode(); + if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); + String dbName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId; + TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); + TdField schemaField = new TdField(); + schemaField.setFieldName(hwDeviceModeFunction.getFunctionIdentifier()); + tdSuperTableVo.setDatabaseName(dbName); + tdSuperTableVo.setSuperTableName(superTableName); + tdSuperTableVo.setField(schemaField); + + R tdReturnMsg = this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java new file mode 100644 index 0000000..d404ee4 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java @@ -0,0 +1,189 @@ +package com.ruoyi.business.service.impl; + +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.HwDeviceModeFunction; +import com.ruoyi.business.domain.PlcDeviceMode; +import com.ruoyi.business.domain.PlcDeviceModeFunction; +import com.ruoyi.business.mapper.PlcDeviceModeDao; +import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao; +import com.ruoyi.business.service.PlcDeviceModeService; +import com.ruoyi.common.core.constant.Constants; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; +import com.ruoyi.common.core.constant.TdEngineConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.enums.DataTypeEnums; +import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.tdengine.api.RemoteTdEngineService; +import com.ruoyi.tdengine.api.domain.TdField; +import com.ruoyi.tdengine.api.domain.TdSuperTableVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * plc设备模型(PlcDeviceMode)表服务实现类 + * + * @author makejava + * @since 2024-12-19 16:23:27 + */ +@Service("plcDeviceModeService") +public class PlcDeviceModeServiceImpl implements PlcDeviceModeService { + @Autowired + private PlcDeviceModeDao plcDeviceModeDao; + @Autowired + private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao; + @Autowired + private RemoteTdEngineService remoteTdEngineService; + + /** + * 通过ID查询单条数据 + * + * @param deviceModeId 主键 + * @return 实例对象 + */ + @Override + public PlcDeviceMode queryById(Long deviceModeId) { + return this.plcDeviceModeDao.queryById(deviceModeId); + } + + /** + * 分页查询 + * + * @param plcDeviceMode 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @Override + public Page queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) { + long total = this.plcDeviceModeDao.count(plcDeviceMode); + return new PageImpl<>(this.plcDeviceModeDao.queryAllByLimit(plcDeviceMode, pageRequest), pageRequest, total); + } + + /** + * 新增数据 + * + * @param plcDeviceMode 实例对象 + * @return 实例对象 + */ + @Override + public int insert(PlcDeviceMode plcDeviceMode) { + Long tenantId = SecurityUtils.getTenantId(); + plcDeviceMode.setTenantId(tenantId); + plcDeviceMode.setDeviceModeStatus("1"); + int rows = plcDeviceModeDao.insert(plcDeviceMode); + List functionList = plcDeviceMode.getFunctionList(); + for (PlcDeviceModeFunction function : functionList) { + function.setDeviceModeId(plcDeviceMode.getDeviceModeId()); + } + int i = plcDeviceModeFunctionDao.insertBatch(functionList); + this.createTdSuperTable(plcDeviceMode); + return rows; + } + private void createTdSuperTable(PlcDeviceMode plcDeviceMode) { + TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); + String dbName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + plcDeviceMode.getDeviceModeId(); + + List tagFields = new ArrayList(); + TdField tagField = new TdField(); + tagField.setFieldName(TdEngineConstants.PLC_TAG_IP); + tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_IP_TYPE); + tagField.setSize(TdEngineConstants.PLC_TAG_IP_SIZE); + tagFields.add(tagField); + + tagField = new TdField(); + tagField.setFieldName(TdEngineConstants.PLC_TAG_PORT); + tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_PORT_TYPE); +// tagField.setSize(TdEngineConstants.ST_TAG_DEVICENAME_SIZE); + tagFields.add(tagField); + + tagField = new TdField(); + tagField.setFieldName(TdEngineConstants.PLC_TAG_LOCATION); + tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_LOCATION_TYPE); + tagField.setSize(TdEngineConstants.PLC_TAG_LOCATION_SIZE); + tagFields.add(tagField); + + + List schemaFields = new ArrayList(); + List hwDeviceModeFunctions = plcDeviceMode.getFunctionList(); + TdField schemaField; + for (PlcDeviceModeFunction hwDeviceModeFunction : hwDeviceModeFunctions) { + String functionMode = hwDeviceModeFunction.getFunctionMode(); + if (functionMode.equalsIgnoreCase(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + schemaField = new TdField(); +// String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier()); +// String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer; + String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier(); + schemaField.setFieldName(functionIdentifier); + Integer dataType = hwDeviceModeFunction.getDataType(); + schemaField.setDataTypeCode(dataType); + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition())); + } + schemaFields.add(schemaField); + } + } + + tdSuperTableVo.setDatabaseName(dbName); + tdSuperTableVo.setSuperTableName(superTableName); + tdSuperTableVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + tdSuperTableVo.setSchemaFields(schemaFields); + tdSuperTableVo.setTagsFields(tagFields); + + R tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + /** + * 修改数据 + * + * @param plcDeviceMode 实例对象 + * @return 实例对象 + */ + @Override + public int update(PlcDeviceMode plcDeviceMode) { + + return this.plcDeviceModeDao.update(plcDeviceMode); + } + + @Override + public int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds) { + plcDeviceModeFunctionDao.deleteHwDeviceModeFunctionByDeviceModeIds(deviceModeIds); + return plcDeviceModeDao.deleteHwDeviceModeByDeviceModeIds(deviceModeIds); + } + + @Override + public List selectFunctionList(Long deviceModeId) { + return plcDeviceModeFunctionDao.selectFunctionList(deviceModeId); + } + + @Override + public PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId) { + return plcDeviceModeDao.queryById(deviceModeId); + } + + @Override + public List selectList(PlcDeviceMode hwDeviceMode) { + return plcDeviceModeDao.selectList(hwDeviceMode); + } + + /** + * 通过主键删除数据 + * + * @param deviceModeId 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(Long deviceModeId) { + return this.plcDeviceModeDao.deleteById(deviceModeId) > 0; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java new file mode 100644 index 0000000..58a3c5c --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java @@ -0,0 +1,551 @@ +package com.ruoyi.business.service.impl; + +import HslCommunication.Core.Transfer.DataFormat; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.ModBus.ModbusTcpNet; +import HslCommunication.Profinet.Melsec.MelsecA1ENet; +import HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp; +import HslCommunication.Profinet.Melsec.MelsecHelper; +import HslCommunication.Profinet.Melsec.MelsecMcNet; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ruoyi.business.domain.*; +import com.ruoyi.business.mapper.PlcDeviceDao; +import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao; +import com.ruoyi.business.service.PlcDeviceService; +import com.ruoyi.common.core.constant.Constants; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; +import com.ruoyi.common.core.constant.TdEngineConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.enums.DataTypeEnums; +import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.model.LoginUser; +import com.ruoyi.tdengine.api.RemoteTdEngineService; +import com.ruoyi.tdengine.api.domain.AlterTagVo; +import com.ruoyi.tdengine.api.domain.TdField; +import com.ruoyi.tdengine.api.domain.TdTableVo; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * plc设备信息(PlcDevice)表服务实现类 + * + * @author makejava + * @since 2024-12-19 16:22:51 + */ +@Service("plcDeviceService") +public class PlcDeviceServiceImpl implements PlcDeviceService { + @Resource + private PlcDeviceDao plcDeviceDao; + @Autowired + private RemoteTdEngineService remoteTdEngineService; + @Autowired + private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao; + + /** + * 通过ID查询单条数据 + * + * @param deviceId 主键 + * @return 实例对象 + */ + @Override + public PlcDevice queryById(Long deviceId) throws JsonProcessingException { +// List plcDevices = this.plcDeviceDao.queryPlcDevices(1); +// for (PlcDevice plcDevice : plcDevices) { +// int station = plcDevice.getStation(); +// byte a = (byte)station; +// int length = plcDevice.getLength(); +// short b = (short)length; +// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a); +// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB); +// TdTableVo tdTableVo = new TdTableVo(); +// List schemaFields = new ArrayList<>(); +// TdField firstTdField = new TdField(); +// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); +// long currentTimeMillis = System.currentTimeMillis(); +// firstTdField.setFieldValue(currentTimeMillis); +// String databaseName = TdEngineConstants.getDatabaseName(); +// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId(); +// // firstTdField.setFieldValue(ts); +// schemaFields.add(firstTdField); +// List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId()); +// if (plcDevice.getDataType().equals("10")){ +// OperateResultExOne resultExOne = tcpNet.ReadString(plcDevice.getDLocation(),b, StandardCharsets.UTF_8); +// String content = resultExOne.Content; +// ObjectMapper objectMapper = new ObjectMapper(); +// Map map = objectMapper.readValue(content, Map.class); +// for (PlcDeviceModeFunction function : list) { +// Object value = map.get(function.getFunctionIdentifier()); +// TdField tdField = new TdField(); +// tdField.setFieldName(function.getFunctionIdentifier()); +// tdField.setFieldValue(value); +// schemaFields.add(tdField); +// } +// }else if (plcDevice.getDataType().equals("2")){ +// OperateResultExOne exOne = tcpNet.ReadInt32(plcDevice.getDLocation()); +// TdField tdField = new TdField(); +// tdField.setFieldName(list.get(0).getFunctionIdentifier()); +// tdField.setFieldValue(exOne.Content); +// schemaFields.add(tdField); +// }else if (plcDevice.getDataType().equals("4")){ +// OperateResultExOne floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getDLocation()); +// TdField tdField = new TdField(); +// tdField.setFieldName(list.get(0).getFunctionIdentifier()); +// tdField.setFieldValue(floatOperateResultExOne.Content); +// schemaFields.add(tdField); +// } +// tdTableVo.setDatabaseName(databaseName); +// tdTableVo.setTableName(tableName); +// tdTableVo.setSchemaFields(schemaFields); +// final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER); +// } + +// OperateResultExOne exOne = tcpNet.ReadFloat("100"); +// System.out.println(exOne.Content); + return this.plcDeviceDao.selectHwDeviceByDeviceId(deviceId); + } + + @Override + public int updateDevice(PlcDevice hwDevice) { + PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(hwDevice.getDeviceId()); + if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) { + throw new ServiceException("已发布状态不能修改"); + } + hwDevice.setUpdateTime(DateUtils.getNowDate()); + int rows = plcDeviceDao.update(hwDevice); + this.updateTdEngine(hwDevice, dbDevice); + return rows; + } + public void updateTdEngine(PlcDevice hwDevice, PlcDevice dbDevice) { + + String databaseName = TdEngineConstants.getDatabaseName(); + String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + hwDevice.getDeviceId(); + AlterTagVo alterTagVo = new AlterTagVo(); + alterTagVo.setDatabaseName(databaseName); + alterTagVo.setTableName(tableName); + R tdReturnMsg; + if (!hwDevice.getIp().equals(dbDevice.getIp())) { + alterTagVo.setTagName(TdEngineConstants.PLC_TAG_IP); + alterTagVo.setTagValue("'" + hwDevice.getIp() + "'"); + + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + if (!hwDevice.getPort1().equals(dbDevice.getPort1())) { + alterTagVo.setTagName(TdEngineConstants.PLC_TAG_PORT); + alterTagVo.setTagValue(hwDevice.getPort1()); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + if (!hwDevice.getLocation().equals(dbDevice.getLocation())) { + alterTagVo.setTagName(TdEngineConstants.PLC_TAG_LOCATION); + alterTagVo.setTagValue("'" + hwDevice.getLocation() + "'"); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + } + + @Override + public int changeDeviceStatus(PlcDevice device) { + PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(device.getDeviceId()); + if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH) && !device.getDeviceStatus().equals("0")) { + throw new ServiceException("已发布状态不能修改"); + } + device.setUpdateBy(SecurityUtils.getUsername()); + Date currentDate = new Date(); + device.setUpdateTime(currentDate); + device.setPublishTime(currentDate); + return plcDeviceDao.update(device); + } + + @Override + public List selectHwDeviceModeList(PlcDeviceMode queryDeviceMode) { + return plcDeviceDao.selectPlcDeviceMode(queryDeviceMode); + } + + @Override + public List selectHwDeviceJoinList(PlcDevice hwDevice) { + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUser sysUser = loginUser.getSysUser(); + Long tenantId = sysUser.getTenantId(); + hwDevice.setTenantId(tenantId); + return plcDeviceDao.selectHwDeviceJoinList(hwDevice); + } + + // mc协议获取处理plc数据 + @Override + public String mcDataProcess() throws JsonProcessingException { + List plcDevices = this.plcDeviceDao.queryPlcDevices(1); + for (PlcDevice plcDevice : plcDevices) { + int station = plcDevice.getStation(); + byte a = (byte)station; + int length = plcDevice.getLength(); + short b = (short)length; + MelsecMcNet melsecMcNet = new MelsecMcNet(plcDevice.getIp(),plcDevice.getPort1()); +// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a); +// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB); + TdTableVo tdTableVo = new TdTableVo(); + List schemaFields = new ArrayList<>(); + TdField firstTdField = new TdField(); + firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + long currentTimeMillis = System.currentTimeMillis(); + firstTdField.setFieldValue(currentTimeMillis); + String databaseName = TdEngineConstants.getDatabaseName(); + String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId(); + // firstTdField.setFieldValue(ts); + schemaFields.add(firstTdField); + List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId()); + if (plcDevice.getDataType().equals("10")){ + OperateResultExOne resultExOne = melsecMcNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8); + String content = resultExOne.Content; + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.readValue(content, Map.class); + for (PlcDeviceModeFunction function : list) { + Object value = map.get(function.getFunctionIdentifier()); + TdField tdField = new TdField(); + tdField.setFieldName(function.getFunctionIdentifier()); + tdField.setFieldValue(value); + schemaFields.add(tdField); + } + }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){ + OperateResultExOne exOne = melsecMcNet.ReadInt32(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(exOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("4")){ + OperateResultExOne floatOperateResultExOne = melsecMcNet.ReadFloat(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(floatOperateResultExOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("5")){ + OperateResultExOne doubleOperateResultExOne = melsecMcNet.ReadDouble(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(doubleOperateResultExOne.Content); + schemaFields.add(tdField); + } + tdTableVo.setDatabaseName(databaseName); + tdTableVo.setTableName(tableName); + tdTableVo.setSchemaFields(schemaFields); + final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER); + } + return null; + } +// modbus协议获取处理plc数据 + @Override + public String modbusDataProcess() throws JsonProcessingException { + List plcDevices = this.plcDeviceDao.queryPlcDevices(2); + for (PlcDevice plcDevice : plcDevices) { + int station = plcDevice.getStation(); + byte a = (byte)station; + int length = plcDevice.getLength(); + short b = (short)length; + ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a); + tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB); + TdTableVo tdTableVo = new TdTableVo(); + List schemaFields = new ArrayList<>(); + TdField firstTdField = new TdField(); + firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + long currentTimeMillis = System.currentTimeMillis(); + firstTdField.setFieldValue(currentTimeMillis); + String databaseName = TdEngineConstants.getDatabaseName(); + String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId(); + // firstTdField.setFieldValue(ts); + schemaFields.add(firstTdField); + List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId()); + if (plcDevice.getDataType().equals("10")){ + OperateResultExOne resultExOne = tcpNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8); + String content = resultExOne.Content; + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.readValue(content, Map.class); + for (PlcDeviceModeFunction function : list) { + Object value = map.get(function.getFunctionIdentifier()); + TdField tdField = new TdField(); + tdField.setFieldName(function.getFunctionIdentifier()); + tdField.setFieldValue(value); + schemaFields.add(tdField); + } + }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){ + OperateResultExOne exOne = tcpNet.ReadInt32(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(exOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("4")){ + OperateResultExOne floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(floatOperateResultExOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("5")){ + OperateResultExOne doubleOperateResultExOne = tcpNet.ReadDouble(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(doubleOperateResultExOne.Content); + schemaFields.add(tdField); + } + tdTableVo.setDatabaseName(databaseName); + tdTableVo.setTableName(tableName); + tdTableVo.setSchemaFields(schemaFields); + final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER); + } + return null; + } +//link数据读取 + @Override + public String linkDataProcess() { +// List plcDevices = this.plcDeviceDao.queryPlcDevices(1); +// for (PlcDevice plcDevice : plcDevices) { +// int station = plcDevice.getStation(); +// byte a = (byte)station; +// int length = plcDevice.getLength(); +// short b = (short)length; +// // ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a); +// // tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB); +// MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1()); +// MelsecFxSerialOverTcp melsecFxSerialOverTcp = new MelsecFxSerialOverTcp(); +// TdTableVo tdTableVo = new TdTableVo(); +// List schemaFields = new ArrayList<>(); +// TdField firstTdField = new TdField(); +// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); +// long currentTimeMillis = System.currentTimeMillis(); +// firstTdField.setFieldValue(currentTimeMillis); +// String databaseName = TdEngineConstants.getDatabaseName(); +// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId(); +// // firstTdField.setFieldValue(ts); +// schemaFields.add(firstTdField); +// List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId()); +// if (plcDevice.getDataType().equals("10")){ +// OperateResultExOne resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8); +// String content = resultExOne.Content; +// ObjectMapper objectMapper = new ObjectMapper(); +// Map map = objectMapper.readValue(content, Map.class); +// for (PlcDeviceModeFunction function : list) { +// Object value = map.get(function.getFunctionIdentifier()); +// TdField tdField = new TdField(); +// tdField.setFieldName(function.getFunctionIdentifier()); +// tdField.setFieldValue(value); +// schemaFields.add(tdField); +// } +// }else if (plcDevice.getDataType().equals("2")){ +// OperateResultExOne exOne = net.ReadInt32(plcDevice.getLocation()); +// TdField tdField = new TdField(); +// tdField.setFieldName(list.get(0).getFunctionIdentifier()); +// tdField.setFieldValue(exOne.Content); +// schemaFields.add(tdField); +// }else if (plcDevice.getDataType().equals("4")){ +// OperateResultExOne floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation()); +// TdField tdField = new TdField(); +// tdField.setFieldName(list.get(0).getFunctionIdentifier()); +// tdField.setFieldValue(floatOperateResultExOne.Content); +// schemaFields.add(tdField); +// } +// tdTableVo.setDatabaseName(databaseName); +// tdTableVo.setTableName(tableName); +// tdTableVo.setSchemaFields(schemaFields); +// final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER); +// } + return null; + } + + // A1E协议 + public String aeDataProcess() throws JsonProcessingException { + List plcDevices = this.plcDeviceDao.queryPlcDevices(3); + for (PlcDevice plcDevice : plcDevices) { + int station = plcDevice.getStation(); + byte a = (byte)station; + int length = plcDevice.getLength(); + short b = (short)length; + // ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a); + // tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB); + MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1()); + TdTableVo tdTableVo = new TdTableVo(); + List schemaFields = new ArrayList<>(); + TdField firstTdField = new TdField(); + firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + long currentTimeMillis = System.currentTimeMillis(); + firstTdField.setFieldValue(currentTimeMillis); + String databaseName = TdEngineConstants.getDatabaseName(); + String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId(); + // firstTdField.setFieldValue(ts); + schemaFields.add(firstTdField); + List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId()); + if (plcDevice.getDataType().equals("10")){ + OperateResultExOne resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8); + String content = resultExOne.Content; + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.readValue(content, Map.class); + for (PlcDeviceModeFunction function : list) { + Object value = map.get(function.getFunctionIdentifier()); + TdField tdField = new TdField(); + tdField.setFieldName(function.getFunctionIdentifier()); + tdField.setFieldValue(value); + schemaFields.add(tdField); + } + }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){ + OperateResultExOne exOne = net.ReadInt32(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(exOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("4")){ + OperateResultExOne floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(floatOperateResultExOne.Content); + schemaFields.add(tdField); + }else if (plcDevice.getDataType().equals("5")){ + OperateResultExOne doubleOperateResultExOne = net.ReadDouble(plcDevice.getLocation()); + TdField tdField = new TdField(); + tdField.setFieldName(list.get(0).getFunctionIdentifier()); + tdField.setFieldValue(doubleOperateResultExOne.Content); + schemaFields.add(tdField); + } + tdTableVo.setDatabaseName(databaseName); + tdTableVo.setTableName(tableName); + tdTableVo.setSchemaFields(schemaFields); + final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER); + } + return null; + } + /** + * 分页查询 + * + * @param plcDevice 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @Override + public Page queryByPage(PlcDevice plcDevice, PageRequest pageRequest) { + long total = this.plcDeviceDao.count(plcDevice); + return new PageImpl<>(this.plcDeviceDao.queryAllByLimit(plcDevice, pageRequest), pageRequest, total); + } + + /** + * 新增数据 + * + * @param plcDevice 实例对象 + * @return 实例对象 + */ + @Override + public int insert(PlcDevice plcDevice) { + String username = SecurityUtils.getUsername(); + plcDevice.setCreateBy(username); + plcDevice.setCreateTime(new Date()); + Long tenantId = SecurityUtils.getTenantId(); + plcDevice.setTenantId(tenantId); + plcDevice.setDeviceStatus("0"); + int deviceId = this.plcDeviceDao.insert(plcDevice); + this.createTdTable(plcDevice); + return deviceId; + } + +// public void createTdDeviceStatusTable(HwDevice hwDevice) { +// TdTableVo tdTableVo = new TdTableVo(); +// tdTableVo.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME); +// tdTableVo.setSuperTableName(TdEngineConstants.DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME); +// tdTableVo.setTableName(TdEngineConstants.getDeviceStatusTableName(hwDevice.getDeviceId())); +// +// List tagsFields = getTdTagsFields(hwDevice); +// +// TdField sceneIdTag = new TdField(); +// sceneIdTag.setFieldName(TdEngineConstants.ST_TAG_SCENEID); +// sceneIdTag.setFieldValue(hwDevice.getSceneId()); +// tagsFields.add(sceneIdTag); +// +// tdTableVo.setTagsFieldValues(tagsFields); +// +// R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER); +// if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 +// throw new RuntimeException(tdReturnMsg.getMsg()); +// } +// } + public void createTdTable(PlcDevice hwDevice) { + TdTableVo tdTableVo = new TdTableVo(); + String databaseName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX+hwDevice.getDeviceModeId(); + String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX+hwDevice.getDeviceId(); + + List tagsFields = getTdTagsFields(hwDevice); + + tdTableVo.setDatabaseName(databaseName); + tdTableVo.setSuperTableName(superTableName); + tdTableVo.setTableName(tableName); + tdTableVo.setTagsFieldValues(tagsFields); + + R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + private List getTdTagsFields(PlcDevice hwDevice) { + List tagFields = new ArrayList(); + TdField ipTag = new TdField(); + ipTag.setFieldName(TdEngineConstants.PLC_TAG_IP); + ipTag.setFieldValue(hwDevice.getIp()); + ipTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode()); + tagFields.add(ipTag); + + TdField portTag = new TdField(); + portTag.setFieldName(TdEngineConstants.PLC_TAG_PORT); + portTag.setFieldValue(hwDevice.getPort1()); + tagFields.add(portTag); + + TdField locationTag = new TdField(); + locationTag.setFieldName(TdEngineConstants.PLC_TAG_LOCATION); + locationTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode()); + locationTag.setFieldValue(hwDevice.getLocation()); + tagFields.add(locationTag); + return tagFields; + } + + /** + * 修改数据 + * + * @param plcDevice 实例对象 + * @return 实例对象 + */ + @Override + public PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException { + this.plcDeviceDao.update(plcDevice); + return this.queryById(plcDevice.getDeviceId()); + } + + + /** + * 通过主键删除数据 + * + * @param deviceId 主键 + * @return 是否成功 + */ + @Override + public int deleteById(Long deviceId) { + return this.plcDeviceDao.deleteById(deviceId); + } +} diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml new file mode 100644 index 0000000..76162c0 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml @@ -0,0 +1,280 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,station,data_type,device_mode_id) + values (#{deviceCode}, #{deviceName}, #{tenantId}, #{sceneId}, #{ip}, #{port1}, #{location}, #{accessProtocol}, #{length}, #{deviceStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime},#{station},#{dataType},#{deviceModeId}) + + + + insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time) + values + + (#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}) + + + + + insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time) + values + + (#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}) + + on duplicate key update + device_code = values(device_code), + device_name = values(device_name), + tenant_id = values(tenant_id), + scene_id = values(scene_id), + ip = values(ip), + port1 = values(port1), + location = values(location), + access_protocol = values(access_protocol), + length = values(length), + device_status = values(device_status), + create_by = values(create_by), + create_time = values(create_time), + update_by = values(update_by), + update_time = values(update_time) + + + + + update plc_device + + + device_code = #{deviceCode}, + + + device_name = #{deviceName}, + + + tenant_id = #{tenantId}, + + + scene_id = #{sceneId}, + + + ip = #{ip}, + + + port1 = #{port1}, + + + location = #{location}, + + + access_protocol = #{accessProtocol}, + + + length = #{length}, + + + device_status = #{deviceStatus}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + data_type = #{dataType}, + + + station = #{station}, + + + where device_id = #{deviceId} + + + + + delete from plc_device where device_id = #{deviceId} + + + + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml new file mode 100644 index 0000000..e3d9a95 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time) + values (#{deviceModeName}, #{tenantId}, #{sceneId}, #{deviceModeStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}) + + + + insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time) + values + + (#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}) + + + + + insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time) + values + + (#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime}) + + on duplicate key update + device_mode_name = values(device_mode_name), + tenant_id = values(tenant_id), + scene_id = values(scene_id), + device_mode_status = values(device_mode_status), + create_by = values(create_by), + create_time = values(create_time), + update_by = values(update_by), + update_time = values(update_time) + + + + + update plc_device_mode + + + device_mode_name = #{deviceModeName}, + + + tenant_id = #{tenantId}, + + + scene_id = #{sceneId}, + + + device_mode_status = #{deviceModeStatus}, + + + create_by = #{createBy}, + + + create_time = #{createTime}, + + + update_by = #{updateBy}, + + + update_time = #{updateTime}, + + + where device_mode_id = #{deviceModeId} + + + + + delete from plc_device_mode where device_mode_id = #{deviceModeId} + + + delete from plc_device_mode where device_mode_id in + + #{deviceModeId} + + + + + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml new file mode 100644 index 0000000..611b23c --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode) + values (#{deviceModeId}, #{functionName}, #{functionIdentifier}, #{dataType}, #{dataDefinition}, #{propertyUnit}, #{remark},#{functionMode}) + + + + insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode) + values + + (#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark},#{entity.functionMode}) + + + + + insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark) + values + + (#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark}) + + on duplicate key update + device_mode_id = values(device_mode_id), + function_name = values(function_name), + function_identifier = values(function_identifier), + data_type = values(data_type), + data_definition = values(data_definition), + property_unit = values(property_unit), + remark = values(remark) + + + + + update plc_device_mode_function + + + device_mode_id = #{deviceModeId}, + + + function_name = #{functionName}, + + + function_identifier = #{functionIdentifier}, + + + data_type = #{dataType}, + + + data_definition = #{dataDefinition}, + + + property_unit = #{propertyUnit}, + + + remark = #{remark}, + + + where mode_function_id = #{modeFunctionId} + + + + + delete from plc_device_mode_function where mode_function_id = #{modeFunctionId} + + + + + + delete from plc_device_mode_function where device_mode_id in + + #{deviceModeId} + + + + +