mqtt通讯修改 增加模板 计算属性

This commit is contained in:
LEED
2025-03-09 12:39:52 +08:00
parent 20c17b772d
commit 6a8cbff440
41 changed files with 2359 additions and 31 deletions

View File

@@ -156,7 +156,11 @@
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.36</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl3</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>

View File

@@ -27,6 +27,21 @@ public class Category extends BaseEntity
@Excel(name = "产品分类名称")
private String categoryName;
/** 产品分类名称 */
@ApiModelProperty("产品型号")
@Excel(name = "产品型号")
private String modelName;
/** 产品分类ID */
@ApiModelProperty("标准模板ID")
private Long standardId;
@ApiModelProperty("标准模板")
@Excel(name = "标准模板")
private String standardName;
/** 租户ID */
@ApiModelProperty("租户ID")
@Excel(name = "租户ID")
@@ -107,6 +122,14 @@ public class Category extends BaseEntity
this.tenantId = tenantId;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public Long getTenantId()
{
return tenantId;
@@ -147,6 +170,22 @@ public class Category extends BaseEntity
return delFlag;
}
public Long getStandardId() {
return standardId;
}
public void setStandardId(Long standardId) {
this.standardId = standardId;
}
public String getStandardName() {
return standardName;
}
public void setStandardName(String standardName) {
this.standardName = standardName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

View File

@@ -33,6 +33,10 @@ public class Product extends BaseEntity {
@Excel(name = "产品名称")
private String productName;
@Excel(name = "产品型号")
@ApiModelProperty("产品型号")
private String productModel;;
// 判断的未分类
private String productNameExclude;
@@ -421,6 +425,14 @@ public class Product extends BaseEntity {
this.productNameExclude = productNameExclude;
}
public String getProductModel() {
return productModel;
}
public void setProductModel(String productModel) {
this.productModel = productModel;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

View File

@@ -0,0 +1,167 @@
package com.xinda.iot.domain;
import com.xinda.common.annotation.Excel;
import com.xinda.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 产品分类对象 iot_standard
*
* @author kerwincui
* @date 2021-12-16
*/
@ApiModel(value = "Standard", description = "产品分类对象 iot_standard")
public class Standard extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 产品分类ID */
@ApiModelProperty("产品分类ID")
private Long standardId;
/** 产品分类名称 */
@ApiModelProperty("产品分类名称")
@Excel(name = "产品分类名称")
private String standardName;
/** 租户ID */
@ApiModelProperty("租户ID")
@Excel(name = "租户ID")
private Long tenantId;
/** 租户名称 */
@ApiModelProperty("租户名称")
@Excel(name = "租户名称")
private String tenantName;
/** 是否系统通用0-否1-是) */
@ApiModelProperty("是否系统通用0-否1-是)")
@Excel(name = "是否系统通用", readConverterExp = "0=-否1-是")
private Integer isSys;
/** 显示顺序 */
@ApiModelProperty("显示顺序")
@Excel(name = "显示顺序")
private Integer orderNum;
/** 删除标志0代表存在 2代表删除 */
@ApiModelProperty("删除标志0代表存在 2代表删除")
private String delFlag;
@ApiModelProperty("是否显示上级品类")
private Boolean showSenior;
@ApiModelProperty("是否是总账号")
private Boolean isAdmin;
@ApiModelProperty("机构ID")
private Long deptId;
public Boolean getShowSenior() {
return showSenior;
}
public void setShowSenior(Boolean showSenior) {
this.showSenior = showSenior;
}
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public Boolean getAdmin() {
return isAdmin;
}
public void setAdmin(Boolean admin) {
isAdmin = admin;
}
public void setStandardId(Long standardId)
{
this.standardId = standardId;
}
public Long getStandardId()
{
return standardId;
}
public void setStandardName(String standardName)
{
this.standardName = standardName;
}
public String getStandardName()
{
return standardName;
}
public void setTenantId(Long tenantId)
{
this.tenantId = tenantId;
}
public Long getTenantId()
{
return tenantId;
}
public void setTenantName(String tenantName)
{
this.tenantName = tenantName;
}
public String getTenantName()
{
return tenantName;
}
public void setIsSys(Integer isSys)
{
this.isSys = isSys;
}
public Integer getIsSys()
{
return isSys;
}
public void setOrderNum(Integer orderNum)
{
this.orderNum = orderNum;
}
public Integer getOrderNum()
{
return orderNum;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getDelFlag()
{
return delFlag;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("standardId", getStandardId())
.append("standardName", getStandardName())
.append("tenantId", getTenantId())
.append("tenantName", getTenantName())
.append("isSys", getIsSys())
.append("orderNum", getOrderNum())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}

View File

@@ -81,6 +81,11 @@ public class ThingsModel extends BaseEntity
@ApiModelProperty("数据定义")
private String specs;
/** 是否计算属性0-否1-是) */
@ApiModelProperty(value = "是否计算属性", notes = "0-否1-是)")
@Excel(name = "是否计算属性", readConverterExp = "0=否,1=是")
private Integer isCalc;
/** 是否图表显示0-否1-是) */
@ApiModelProperty(value = "是否图表显示", notes = "0-否1-是)")
@Excel(name = "是否图表显示", readConverterExp = "0=否,1=是")

View File

@@ -0,0 +1,128 @@
package com.xinda.iot.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.xinda.common.annotation.Excel;
import com.xinda.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 通用物模型对象 iot_things_model_standard
*
* @author kerwincui
* @date 2023-01-15
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ThingsModelStandard", description = "通用物模型对象 iot_things_model_standard")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class ThingsModelStandard extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 物模型ID */
@ApiModelProperty("物模型ID")
private Long templateId;
/** 物模型名称 */
@ApiModelProperty("物模型名称")
@Excel(name = "物模型名称" ,prompt = "必填")
private String templateName;
/** 租户ID */
@ApiModelProperty("标准模板ID")
private Long standardId;
/** 租户名称 */
@ApiModelProperty("标准模板")
private String standardName;
/** 租户ID */
@ApiModelProperty("租户ID")
private Long tenantId;
/** 租户名称 */
@ApiModelProperty("租户名称")
private String tenantName;
/** 标识符,产品下唯一 */
@ApiModelProperty("标识符,产品下唯一")
@Excel(name = "标识符",prompt = "modbus不填,默认为寄存器地址")
private String identifier;
/** 模型类别1-属性2-功能3-事件) */
@ApiModelProperty(value = "模型类别", notes = "1-属性2-功能3-事件)")
@Excel(name = "模型类别", readConverterExp = "1=属性,2=功能,3=事件",prompt ="1=属性2-功能3-事件")
private Integer type;
/** 计算公式 */
@ApiModelProperty("计算公式")
@Excel(name = "计算公式",prompt = "选填,例如:%s*10,%s是占位符")
private String formula;
/** 数据定义 */
@ApiModelProperty("数据定义")
private String specs;
/** 是否系统通用0-否1-是) */
@ApiModelProperty("是否系统通用0-否1-是)")
private Integer isSys;
/** 是否图表显示0-否1-是) */
@ApiModelProperty("是否图表显示0-否1-是)")
//@Excel(name = "是否图表显示", readConverterExp = "0=否,1=是")
private Integer isChart;
/** 是否历史存储0-否1-是) */
@ApiModelProperty("是否历史存储0-否1-是)")
@Excel(name = "是否历史存储", readConverterExp = "0=否,1=是")
private Integer isHistory;
/** 是否实时监测0-否1-是) */
@ApiModelProperty("是否实时监测0-否1-是)")
private Integer isMonitor;
/** 是否分享设备权限0-否1-是) */
@ApiModelProperty(value = "是否分享设备权限", notes = "0-否1-是) ")
private Integer isSharePerm;
/** 是否分享设备权限0-否1-是) */
@ApiModelProperty(value = "是否分享设备权限", notes = "0-否1-是) ")
@Excel(name = "是否分享设备权限", readConverterExp = "0=否,1=是")
private Integer isApp;
/** 删除标志0代表存在 2代表删除 */
@ApiModelProperty("删除标志0代表存在 2代表删除")
private String delFlag;
@Excel(name = "单位")
private String unit;
/** 数据类型integer、decimal、string、bool、array、enum */
@ApiModelProperty(value = "数据类型", notes = "integer、decimal、string、bool、array、enum")
@Excel(name = "数据类型", prompt = "integer、decimal、string、bool、array、enum")
private String datatype;
@ApiModelProperty("有效值范围")
@Excel(name = "有效值范围")
private String limitValue;
/** 是否只读数据(0-否1-是) */
@ApiModelProperty("是否只读数据(0-否1-是)")
@Excel(name = "是否只读", readConverterExp = "0=否,1=是",prompt = "0=否,1=是")
private Integer isReadonly;
private Integer modelOrder;
private String language;
/**
* 同一租户或用户为true
*/
private Boolean owner;
}

View File

@@ -0,0 +1,81 @@
package com.xinda.iot.mapper;
import com.xinda.iot.domain.Standard;
import com.xinda.iot.model.IdAndName;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 产品分类Mapper接口
*
* @author kerwincui
* @date 2021-12-16
*/
@Repository
public interface StandardMapper
{
/**
* 查询产品分类
*
* @param standardId 产品分类主键
* @return 产品分类
*/
public Standard selectStandardByStandardId(Long standardId);
/**
* 查询产品分类列表
*
* @param standard 产品分类
* @return 产品分类集合
*/
public List<Standard> selectStandardList(Standard standard);
/**
* 查询产品简短分类列表
*
* @return 产品分类集合
*/
public List<IdAndName> selectStandardShortList(Standard standard);
/**
* 新增产品分类
*
* @param standard 产品分类
* @return 结果
*/
public int insertStandard(Standard standard);
/**
* 修改产品分类
*
* @param standard 产品分类
* @return 结果
*/
public int updateStandard(Standard standard);
/**
* 删除产品分类
*
* @param standardId 产品分类主键
* @return 结果
*/
public int deleteStandardByStandardId(Long standardId);
/**
* 批量删除产品分类
*
* @param standardIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteStandardByStandardIds(Long[] standardIds);
/**
* 分类下的产品数量
*
* @param standardIds 需要删除的数据主键集合
* @return 结果
*/
public int productCountInStandards(Long[] standardIds);
}

View File

@@ -0,0 +1,86 @@
package com.xinda.iot.mapper;
import com.xinda.iot.domain.ThingsModelStandard;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 通用物模型Mapper接口
*
* @author kerwincui
* @date 2021-12-16
*/
@Repository
public interface ThingsModelStandardMapper
{
/**
* 查询通用物模型
*
* @param templateId 通用物模型主键
* @param language 语言
* @return 通用物模型
*/
public ThingsModelStandard selectThingsModelStandardByTemplateId(@Param("templateId") Long templateId, @Param("language") String language);
/**
* 根据id数组查询通用物模型集合
* @param templateIds
* @param language 语言
* @return
*/
public List<ThingsModelStandard> selectThingsModelStandardByTemplateIds (@Param("templateIds") Long[] templateIds, @Param("language") String language);
/**
* 查询通用物模型列表
*
* @param thingsModelTemplate 通用物模型
* @return 通用物模型集合
*/
public List<ThingsModelStandard> selectThingsModelStandardList(ThingsModelStandard thingsModelTemplate);
/**
* 新增通用物模型
*
* @param thingsModelTemplate 通用物模型
* @return 结果
*/
public int insertThingsModelStandard(ThingsModelStandard thingsModelTemplate);
/**
* 修改通用物模型
*
* @param thingsModelTemplate 通用物模型
* @return 结果
*/
public int updateThingsModelStandard(ThingsModelStandard thingsModelTemplate);
/**
* 删除通用物模型
*
* @param templateId 通用物模型主键
*
*
*
*
* @return 结果
*/
public int deleteThingsModelStandardByTemplateId(Long templateId);
/**
* 批量删除通用物模型
*
* @param templateIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteThingsModelStandardByTemplateIds(Long[] templateIds);
List<ThingsModelStandard> selectModelListByStandardId(Long standardId);
int batchThingsModelStandards(List<ThingsModelStandard> thingsModelStandards);
}

View File

@@ -0,0 +1,43 @@
package com.xinda.iot.model;
/**
* 导入产品物模型的输入对象
*
* @author kerwincui
* @date 2021-12-16
*/
public class ImportStandardModelInput
{
/** 产品ID */
private Long productId;
/** 产品名称 */
private String productName;
/** 通用物模型ID集合 */
private Long standardId;
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public Long getStandardId() {
return standardId;
}
public void setStandardId(Long standardId) {
this.standardId = standardId;
}
}

View File

@@ -60,6 +60,11 @@ public class ThingsModelValueItem {
**/
private Integer isHistory;
/**
* 是否为图表展示
**/
private Integer isCalc;
/**
* 是否为图表展示
**/

View File

@@ -59,6 +59,27 @@ public class RuleProcess {
//返回处理完的消息上下文
return scriptService.execRuleScript(scriptCondition, context);
}
public MsgContext processNoRuleScript(String serialNumber, int event, String topic, String payload) {
ProductCode productCode = getDeviceDetail(serialNumber);
if (Objects.isNull(productCode)) {
return new MsgContext();
}
// 查询数据流脚本组件
ScriptCondition scriptCondition = ScriptCondition.builder()
.scriptPurpose(1)
.scriptEvent(event)
.productId(productCode.getProductId())
.build();
MsgContext context = MsgContext.builder()
.serialNumber(serialNumber)
.productId(productCode.getProductId())
.protocolCode(productCode.getProtocolCode())
.payload(payload)
.topic(topic)
.build();
//返回处理完的消息上下文
return context;
}
/**

View File

@@ -0,0 +1,73 @@
package com.xinda.iot.service;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.iot.domain.Standard;
import com.xinda.iot.model.IdAndName;
import java.util.List;
/**
* 产品分类Service接口
*
* @author kerwincui
* @date 2021-12-16
*/
public interface IStandardService
{
/**
* 查询产品分类
*
* @param standardId 产品分类主键
* @return 产品分类
*/
public Standard selectStandardByStandardId(Long standardId);
/**
* 查询产品分类列表
*
* @param standard 产品分类
* @return 产品分类集合
*/
public List<Standard> selectStandardList(Standard standard);
/**
* 查询产品简短分类列表
*
* @return 产品分类集合
*/
public List<IdAndName> selectStandardShortList(Standard standard);
/**
* 新增产品分类
*
* @param standard 产品分类
* @return 结果
*/
public int insertStandard(Standard standard);
/**
* 修改产品分类
*
* @param standard 产品分类
* @return 结果
*/
public int updateStandard(Standard standard);
/**
* 批量删除产品分类
*
* @param standardIds 需要删除的产品分类主键集合
* @return 结果
*/
public AjaxResult deleteStandardByStandardIds(Long[] standardIds);
/**
* 删除产品分类信息
*
* @param standardId 产品分类主键
* @return 结果
*/
public int deleteStandardByStandardId(Long standardId);
public int cloneStandard(Standard standard);
}

View File

@@ -2,6 +2,7 @@ package com.xinda.iot.service;
import com.xinda.common.core.iot.response.IdentityAndName;
import com.xinda.iot.domain.ThingsModel;
import com.xinda.iot.model.ImportStandardModelInput;
import com.xinda.iot.model.ImportThingsModelInput;
import com.xinda.iot.model.ThingsModelPerm;
import com.xinda.iot.model.ThingsModelSimVO;
@@ -188,8 +189,9 @@ public interface IThingsModelService
/**
* 根据设备编号获取读写物模型
* @param serialNumber
* @return
*/
List<ThingsModel> selectThingsModelBySerialNumber(Long deviceId);
public int importByStandardId(ImportStandardModelInput input);
}

View File

@@ -0,0 +1,83 @@
package com.xinda.iot.service;
import com.xinda.iot.domain.ThingsModelStandard;
import com.xinda.iot.model.ImportStandardModelInput;
import java.util.List;
/**
* 通用物模型Service接口
*
* @author kerwincui
* @date 2021-12-16
*/
public interface IThingsModelStandardService
{
/**
* 查询通用物模型
*
* @param templateId 通用物模型主键
* @return 通用物模型
*/
public ThingsModelStandard selectThingsModelStandardByTemplateId(Long templateId);
/**
* 查询通用物模型列表
*
* @param thingsModelStandard 通用物模型
* @return 通用物模型集合
*/
public List<ThingsModelStandard> selectThingsModelStandardList(ThingsModelStandard thingsModelStandard);
public List<ThingsModelStandard> selectModelListByStandardId(Long standardId);
/**
* 新增通用物模型
*
* @param thingsModelStandard 通用物模型
* @return 结果
*/
public int insertThingsModelStandard(ThingsModelStandard thingsModelStandard);
/**
* 修改通用物模型
*
* @param thingsModelStandard 通用物模型
* @return 结果
*/
public int updateThingsModelStandard(ThingsModelStandard thingsModelStandard);
/**
* 批量删除通用物模型
*
* @param templateIds 需要删除的通用物模型主键集合
* @return 结果
*/
public int deleteThingsModelStandardByTemplateIds(Long[] templateIds);
/**
* 删除通用物模型信息
*
* @param templateId 通用物模型主键
* @return 结果
*/
public int deleteThingsModelStandardByTemplateId(Long templateId);
/**
* 导入采集点数据
* @param lists 数据列表
* @param tempSlaveId 从机编码
* @return 结果
*/
public String importData(List<ThingsModelStandard> lists,String tempSlaveId);
/**
* 导出采集点数据
*
* @param thingsModelStandard 通用物模型
* @return 通用物模型集合
*/
public List<ThingsModelStandard> selectThingsModelStandardExport(ThingsModelStandard thingsModelStandard);
}

View File

@@ -49,6 +49,8 @@ public interface IToolService
*/
public ResponseEntity simpleMqttAuthentication(MqttAuthenticationModel mqttModel, ProductAuthenticateModel productModel);
ResponseEntity miniMqttAuthentication(MqttAuthenticationModel mqttModel);
/**
* 设备加密认证
*
@@ -67,4 +69,6 @@ public interface IToolService
* 返回认证信息
*/
public ResponseEntity returnUnauthorized(MqttAuthenticationModel mqttModel, String message);
public ResponseEntity clientAuthNoClient(String clientId, String username, String password);
}

View File

@@ -62,6 +62,7 @@ import java.util.stream.Collectors;
import static com.xinda.common.utils.SecurityUtils.getLoginUser;
import static com.xinda.common.utils.SecurityUtils.isAdmin;
import com.xinda.iot.util.FormulaCalculator;
/**
* 设备Service业务层处理
@@ -242,6 +243,7 @@ public class DeviceServiceImpl implements IDeviceService {
public List<ThingsModelSimpleItem> reportDeviceThingsModelValue(ThingsModelValuesInput input, int type, boolean isShadow) {
String key = RedisKeyBuilder.buildTSLVCacheKey(input.getProductId(), input.getDeviceNumber());
Map<String, String> maps = new HashMap<String, String>();
Map<String, String> variables = new HashMap<String, String>();
List<ThingsModelSimpleItem> list = new ArrayList<>();
//属性存储集合
@@ -267,11 +269,19 @@ public class DeviceServiceImpl implements IDeviceService {
/* ★★★★★★★★★★★★★★★★★★★★★★ 数据计算 -开始 ★★★★★★★★★★★★★★★★★★★★★★*/
//有计算公式的,经过计算公式
// if (thingModels.getFormula() != null && !"".equals(thingModels.getFormula())) {
// Map<String, String> params = new HashMap<>();
// params.put("%s", value);
// value = String.valueOf(CaculateUtils.execute(thingModels.getFormula(), params));
// item.setValue(value);
// }
if (thingModels.getFormula() != null && !"".equals(thingModels.getFormula())) {
Map<String, String> params = new HashMap<>();
params.put("%s", value);
value = String.valueOf(CaculateUtils.execute(thingModels.getFormula(), params));
item.setValue(value);
params.put(thingModels.getId(), value);
if(FormulaCalculator.containsAllVariables(thingModels.getFormula(), params)) {
value = FormulaCalculator.evaluate(thingModels.getFormula(), params);
item.setValue(value);
}
}
/* ★★★★★★★★★★★★★★★★★★★★★★ 数据计算 -结束 ★★★★★★★★★★★★★★★★★★★★★★*/
@@ -312,6 +322,7 @@ public class DeviceServiceImpl implements IDeviceService {
valueItem.setTs(DateUtils.getNowDate());
}
maps.put(identity, JSONObject.toJSONString(valueItem));
variables.put(identity,value);
}
/* ★★★★★★★★★★★★★★★★★★★★★★ 处理数据 - 结束 ★★★★★★★★★★★★★★★★★★★★★★*/
@@ -374,6 +385,58 @@ public class DeviceServiceImpl implements IDeviceService {
}
list.add(item);
}
/*★★★★★★★★★★★★★★★★★★★★★★ 处理计算属性 - 开始 ★★★★★★★★★★★★★★★★★★★★★★*/
//1、根据产品ID获取计算属性列表
List<ThingsModelValueItem> thingsModelList = itslCache.getThingsModelList(input.getProductId());
for (ThingsModelValueItem mItem : thingsModelList) {
if (mItem.getIsCalc() == 1) {
if (mItem.getFormula() != null && !"".equals(mItem.getFormula())) {
//2、获取计算属性列表的变量 检查每个变量都存在maps里 如果不存在则不计算,如果存在则计算
if(FormulaCalculator.containsAllVariables(mItem.getFormula(), variables)){
//3、先执行 上面的★★ 处理数据 - 开始 ★★
String calcValue = FormulaCalculator.evaluate(mItem.getFormula(), variables);
ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem();
simpleItem.setId(mItem.getId());
simpleItem.setName(mItem.getName());
simpleItem.setValue(calcValue);
simpleItem.setTs(DateUtils.getNowDate());
list.add(simpleItem);
ValueItem valueItem = new ValueItem();
valueItem.setId(mItem.getId());
valueItem.setValue(calcValue);
valueItem.setShadow(calcValue);
valueItem.setTs(DateUtils.getNowDate());
maps.put(mItem.getId(), JSONObject.toJSONString(valueItem));
Device device = this.selectDeviceBySerialNumber(input.getDeviceNumber());
//4、★★★ 存储数据 - 开始 ★★(属性部分)
if (1 == mItem.getIsHistory()) {
DeviceLog deviceLog = new DeviceLog();
deviceLog.setSerialNumber(input.getDeviceNumber());
deviceLog.setLogType(type);
// 1=影子模式2=在线模式3=其他
deviceLog.setMode(isShadow ? 1 : 2);
// 设备日志值
deviceLog.setLogValue(calcValue);
//deviceLog.setRemark(mItem.getRemark());
deviceLog.setIdentity(mItem.getId());
deviceLog.setCreateTime(DateUtils.getNowDate());
deviceLog.setUserId(device.getTenantId());
deviceLog.setUserName(device.getTenantName());
deviceLog.setTenantId(device.getTenantId());
deviceLog.setTenantName(device.getTenantName());
deviceLog.setModelName(mItem.getName());
deviceLog.setIsMonitor(mItem.getIsMonitor());
deviceLogList.add(deviceLog);
}
}
}
}
}
/*★★★★★★★★★★★★★★★★★★★★★★ 处理计算属性 - 结束 ★★★★★★★★★★★★★★★★★★★★★★*/
// 缓存最新一条数据到redis
redisCache.hashPutAll(key, maps);
//存储历史数据

View File

@@ -61,7 +61,7 @@ public class ProductServiceImpl implements IProductService
* @param productId 产品主键
* @return 产品
*/
@Cacheable(value = "product", key = "#root.methodName + '_' + #productId", unless = "#result == null")
// @Cacheable(value = "product", key = "#root.methodName + '_' + #productId", unless = "#result == null")
@Override
public Product selectProductByProductId(Long productId)
{

View File

@@ -0,0 +1,178 @@
package com.xinda.iot.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.core.domain.entity.SysUser;
import com.xinda.common.utils.DateUtils;
import com.xinda.iot.domain.Standard;
import com.xinda.iot.domain.ThingsModelStandard;
import com.xinda.iot.mapper.StandardMapper;
import com.xinda.iot.mapper.ThingsModelStandardMapper;
import com.xinda.iot.model.IdAndName;
import com.xinda.iot.service.IStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.xinda.common.utils.SecurityUtils.getLoginUser;
import static com.xinda.common.utils.SecurityUtils.isAdmin;
/**
* 产品分类Service业务层处理
*
* @author kerwincui
* @date 2021-12-16
*/
@Service
public class StandardServiceImpl implements IStandardService
{
@Autowired
private StandardMapper standardMapper;
@Autowired
private ThingsModelStandardMapper thingsModelStandardMapper;
/**
* 查询产品分类
*
* @param standardId 产品分类主键
* @return 产品分类
*/
@Override
public Standard selectStandardByStandardId(Long standardId)
{
return standardMapper.selectStandardByStandardId(standardId);
}
/**
* 查询产品分类列表
*
* @param standard 产品分类
* @return 产品分类
*/
@Override
public List<Standard> selectStandardList(Standard standard)
{
return standardMapper.selectStandardList(standard);
}
/**
* 查询产品分简短类列表
*
* @return 产品分类
*/
@Override
public List<IdAndName> selectStandardShortList(Standard standard)
{
return standardMapper.selectStandardShortList(standard);
}
/**
* 新增产品分类
*
* @param standard 产品分类
* @return 结果
*/
@Override
public int insertStandard(Standard standard)
{
// 判断是否为管理员
standard.setIsSys(1);
SysUser user = getLoginUser().getUser();
// List<SysRole> roles=user.getRoles();
// for(int i=0;i<roles.size();i++){
// if(roles.get(i).getRoleKey().equals("tenant") || roles.get(i).getRoleKey().equals("general")){
// standard.setIsSys(0);
// break;
// }
// }
if (null != user.getDeptId()) {
standard.setTenantId(user.getDept().getDeptUserId());
standard.setTenantName(user.getDept().getDeptUserName());
} else {
standard.setTenantId(user.getUserId());
standard.setTenantName(user.getUserName());
}
if (!isAdmin(user.getUserId())) {
standard.setIsSys(0);
}
standard.setCreateTime(DateUtils.getNowDate());
return standardMapper.insertStandard(standard);
}
@Override
public int cloneStandard(Standard standard)
{
// 判断是否为管理员
standard.setIsSys(1);
SysUser user = getLoginUser().getUser();
Standard cloneStandard = new Standard();
BeanUtil.copyProperties(standard, cloneStandard, "standardId","standardName","orderNum");
cloneStandard.setStandardName(standard.getStandardName()+"_副本");
if (null != standard.getOrderNum()) {
cloneStandard.setOrderNum(standard.getOrderNum()+1);
}
// cloneStandard.setOrderNum(standard.getOrderNum()+1);
// if (null != user.getDeptId()) {
// standard.setTenantId(user.getDept().getDeptUserId());
// standard.setTenantName(user.getDept().getDeptUserName());
// } else {
// standard.setTenantId(user.getUserId());
// standard.setTenantName(user.getUserName());
// }
// if (!isAdmin(user.getUserId())) {
// standard.setIsSys(0);
// }
cloneStandard.setCreateTime(DateUtils.getNowDate());
standardMapper.insertStandard(cloneStandard);
List<ThingsModelStandard> thingsModelStandards = thingsModelStandardMapper.selectModelListByStandardId(standard.getStandardId());
thingsModelStandardMapper.selectModelListByStandardId(standard.getStandardId()).forEach(model -> {
model.setStandardId(cloneStandard.getStandardId());
thingsModelStandards.add(model);
});
return thingsModelStandardMapper.batchThingsModelStandards(thingsModelStandards);
}
/**
* 修改产品分类
*
* @param standard 产品分类
* @return 结果
*/
@Override
public int updateStandard(Standard standard)
{
standard.setUpdateTime(DateUtils.getNowDate());
return standardMapper.updateStandard(standard);
}
/**
* 批量删除产品分类
*
* @param standardIds 需要删除的产品分类主键
* @return 结果
*/
@Override
public AjaxResult deleteStandardByStandardIds(Long[] standardIds)
{
int productCount=standardMapper.productCountInStandards(standardIds);
if(productCount>0){
return AjaxResult.error("删除失败,请先删除对应分类下的产品");
}
if(standardMapper.deleteStandardByStandardIds(standardIds)>0){
return AjaxResult.success("删除成功");
}
return AjaxResult.error("删除失败");
}
/**
* 删除产品分类信息
*
* @param standardId 产品分类主键
* @return 结果
*/
@Override
public int deleteStandardByStandardId(Long standardId)
{
return standardMapper.deleteStandardByStandardId(standardId);
}
}

View File

@@ -15,6 +15,7 @@ import com.xinda.common.utils.StringUtils;
import com.xinda.iot.cache.ITSLCache;
import com.xinda.iot.domain.*;
import com.xinda.iot.mapper.*;
import com.xinda.iot.model.ImportStandardModelInput;
import com.xinda.iot.model.ImportThingsModelInput;
import com.xinda.iot.model.ThingsModelItem.Datatype;
import com.xinda.iot.model.ThingsModelPerm;
@@ -54,6 +55,9 @@ public class ThingsModelServiceImpl implements IThingsModelService {
@Resource
private ThingsModelTemplateMapper thingsModelTemplateMapper;
@Autowired
private ThingsModelStandardMapper thingsModelStandardMapper;
@Autowired
private ProductMapper productMapper;
@@ -240,6 +244,63 @@ public class ThingsModelServiceImpl implements IThingsModelService {
return repeatCount;
}
@Override
public int importByStandardId(ImportStandardModelInput input) {
ThingsModel inputParameter = new ThingsModel();
inputParameter.setLanguage(SecurityUtils.getLanguage());
inputParameter.setProductId(input.getProductId());
List<ThingsModel> dbList = thingsModelMapper.selectThingsModelList(inputParameter);
SysUser user = getLoginUser().getUser();
// 根据ID集合获取通用物模型列表
List<ThingsModelStandard> templateList = thingsModelStandardMapper.selectModelListByStandardId(input.getStandardId());
//转换为产品物模型,并批量插入
List<ThingsModel> list = new ArrayList<>();
int repeatCount = 0;
for (ThingsModelStandard template : templateList) {
ThingsModel thingsModel = new ThingsModel();
BeanUtils.copyProperties(template, thingsModel);
thingsModel.setTenantId(user.getUserId());
thingsModel.setTenantName(user.getUserName());
thingsModel.setCreateTime(DateUtils.getNowDate());
thingsModel.setProductId(input.getProductId());
thingsModel.setProductName(input.getProductName());
thingsModel.setModelId(template.getTemplateId());
thingsModel.setModelName(template.getTemplateName());
thingsModel.setIsReadonly(template.getIsReadonly());
thingsModel.setIsMonitor(template.getIsMonitor());
thingsModel.setIsChart(template.getIsChart());
thingsModel.setIsHistory(template.getIsHistory());
thingsModel.setModelOrder(template.getModelOrder());
Boolean isRepeat = dbList.stream().anyMatch(x -> x.getIdentifier().equals(thingsModel.getIdentifier()));
if (isRepeat) {
repeatCount = repeatCount + 1;
} else {
list.add(thingsModel);
}
}
if (list.size() > 0) {
int result = thingsModelMapper.insertBatchThingsModel(list);
if (result > 0) {
// 更新场景管理变量
List<SceneModelDevice> sceneModelDeviceList = sceneModelDeviceMapper.listDeviceByProductId(input.getProductId());
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(sceneModelDeviceList)) {
List<SceneModelData> sceneModelDataList = new ArrayList<>();
for (ThingsModel thingsModel : list) {
List<ThingsModelDTO> thingsModelDTOList = this.changeObjectOrArray(thingsModel);
for (SceneModelDevice sceneModelDevice : sceneModelDeviceList) {
sceneModelDataList.addAll(getSceneModelData(sceneModelDevice, thingsModelDTOList));
}
}
sceneModelDataMapper.insertBatchSceneModelData(sceneModelDataList);
}
}
//更新redis缓存
itslCache.setCacheThingsModelByProductId(input.getProductId());
}
return repeatCount;
}
/**
* 修改物模型
*

View File

@@ -0,0 +1,290 @@
package com.xinda.iot.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.xinda.common.core.domain.entity.SysUser;
import com.xinda.common.exception.ServiceException;
import com.xinda.common.utils.DateUtils;
import com.xinda.common.utils.SecurityUtils;
import com.xinda.iot.domain.*;
import com.xinda.iot.mapper.ThingsModelStandardMapper;
import com.xinda.iot.model.ImportStandardModelInput;
import com.xinda.iot.model.ThingsModelItem.Datatype;
import com.xinda.iot.model.ThingsModelItem.EnumItem;
import com.xinda.iot.model.dto.ThingsModelDTO;
import com.xinda.iot.model.varTemp.EnumClass;
import com.xinda.iot.service.IThingsModelStandardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static com.xinda.common.utils.SecurityUtils.getLoginUser;
import static com.xinda.common.utils.SecurityUtils.isAdmin;
/**
* 通用物模型Service业务层处理
*
* @author kerwincui
* @date 2021-12-16
*/
@Service
@Slf4j
public class ThingsModelStandardServiceImpl implements IThingsModelStandardService
{
@Autowired
private ThingsModelStandardMapper thingsModelStandardMapper;
/**
* 查询通用物模型
*
* @param templateId 通用物模型主键
* @return 通用物模型
*/
@Override
public ThingsModelStandard selectThingsModelStandardByTemplateId(Long templateId)
{
return thingsModelStandardMapper.selectThingsModelStandardByTemplateId(templateId, SecurityUtils.getLanguage());
}
/**
* 查询通用物模型列表
*
* @param thingsModelStandard 通用物模型
* @return 通用物模型
*/
@Override
public List<ThingsModelStandard> selectThingsModelStandardList(ThingsModelStandard thingsModelStandard)
{
SysUser user = getLoginUser().getUser();
// List<SysRole> roles=user.getRoles();
// 租户
// if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){
// thingsModelStandard.setTenantId(user.getUserId());
// }
thingsModelStandard.setLanguage(SecurityUtils.getLanguage());
List<ThingsModelStandard> list = thingsModelStandardMapper.selectThingsModelStandardList(thingsModelStandard);
for (ThingsModelStandard modelTemplate : list) {
if (null != user.getDeptId()) {
modelTemplate.setOwner(user.getDept().getDeptUserId().equals(modelTemplate.getTenantId()));
} else {
modelTemplate.setOwner(user.getUserId().equals(modelTemplate.getTenantId()));
}
}
return list;
}
@Override
public List<ThingsModelStandard> selectModelListByStandardId(Long standardId)
{
SysUser user = getLoginUser().getUser();
List<ThingsModelStandard> list = thingsModelStandardMapper.selectModelListByStandardId(standardId);
for (ThingsModelStandard modelTemplate : list) {
if (null != user.getDeptId()) {
modelTemplate.setOwner(user.getDept().getDeptUserId().equals(modelTemplate.getTenantId()));
} else {
modelTemplate.setOwner(user.getUserId().equals(modelTemplate.getTenantId()));
}
}
return list;
}
/**
* 新增通用物模型
*
* @param template 通用物模型
* @return 结果
*/
@Override
public int insertThingsModelStandard(ThingsModelStandard template)
{
try {
// 判断是否为管理员
SysUser user = getLoginUser().getUser();
if (isAdmin(user.getUserId())) {
template.setIsSys(1);
} else {
template.setIsSys(0);
}
// List<SysRole> roles=user.getRoles();
// for(int i=0;i<roles.size();i++){
// if(roles.get(i).getRoleKey().equals("tenant") || roles.get(i).getRoleKey().equals("general")){
// template.setIsSys(0);
// break;
// }
// }
if (null != user.getDeptId()) {
template.setTenantId(user.getDept().getDeptUserId());
template.setTenantName(user.getDept().getDeptUserName());
} else {
template.setTenantId(user.getUserId());
template.setTenantName(user.getUserName());
}
template.setCreateTime(DateUtils.getNowDate());
return thingsModelStandardMapper.insertThingsModelStandard(template);
}catch (Exception e){
if (e.getMessage().contains("iot_things_modes_slaveId_reg")){
throw new ServiceException("同一个采集点模板下,寄存器地址重复,请检查导入变量寄存器地址");
}else {
throw new ServiceException(e.getMessage());
}
}
}
/**
* 修改通用物模型
*
* @param template 通用物模型
* @return 结果
*/
@Override
public int updateThingsModelStandard(ThingsModelStandard template)
{
template.setUpdateTime(DateUtils.getNowDate());
return thingsModelStandardMapper.updateThingsModelStandard(template);
}
/**
* 批量删除通用物模型
*
* @param templateIds 需要删除的通用物模型主键
* @return 结果
*/
@Override
public int deleteThingsModelStandardByTemplateIds(Long[] templateIds)
{
return thingsModelStandardMapper.deleteThingsModelStandardByTemplateIds(templateIds);
}
/**
* 删除通用物模型信息
*
* @param templateId 通用物模型主键
* @return 结果
*/
@Override
public int deleteThingsModelStandardByTemplateId(Long templateId)
{
return thingsModelStandardMapper.deleteThingsModelStandardByTemplateId(templateId);
}
/**
* 导入采集点数据
*
* @param lists 数据列表
* @param tempSlaveId 从机编码
* @return 结果
*/
public String importData(List<ThingsModelStandard> lists, String tempSlaveId) {
if (null == tempSlaveId || CollectionUtils.isEmpty(lists)) {
throw new ServiceException("导入数据异常");
}
int success = 0;
int failure = 0;
StringBuilder succSb = new StringBuilder();
StringBuilder failSb = new StringBuilder();
for (ThingsModelStandard model : lists) {
try {
//处理数据定义
this.parseSpecs(model);
this.insertThingsModelStandard(model);
success++;
succSb.append("<br/>").append(success).append(",采集点: ").append(model.getTemplateName());
} catch (Exception e) {
log.error("导入错误:", e);
failure++;
failSb.append("<br/>").append(failure).append(",采集点: ").append(model.getTemplateName()).append("导入失败");
}
}
if (failure > 0) {
throw new ServiceException(failSb.toString());
}
return succSb.toString();
}
private void parseSpecs(ThingsModelStandard model) {
JSONObject specs = new JSONObject();
String datatype = model.getDatatype();
String limitValue = model.getLimitValue();
if (limitValue != null && !"".equals(limitValue)) {
String[] values = limitValue.trim().split("/");
switch (datatype) {
case "integer":
specs.put("max", new BigDecimal(values[1]));
specs.put("min", new BigDecimal(values[0]));
specs.put("type", datatype);
specs.put("unit", model.getUnit());
specs.put("step", 0);
break;
case "bool":
specs.put("type",datatype);
specs.put("trueText",values[1]);
specs.put("falseText",values[0]);
break;
case "enum":
List<EnumClass> list = new ArrayList<>();
for (String value : values) {
String[] params = value.trim().split(":");
EnumClass enumCls = new EnumClass();
enumCls.setText(params[1]);
enumCls.setValue(params[0]);
list.add(enumCls);
}
specs.put("type",datatype);
specs.put("enumList",list);
break;
}
model.setSpecs(specs.toJSONString());
}
}
/**
* 导出采集点数据
*
* @param thingsModelStandard 通用物模型
* @return 通用物模型集合
*/
@Override
public List<ThingsModelStandard> selectThingsModelStandardExport(ThingsModelStandard thingsModelStandard){
thingsModelStandard.setLanguage(SecurityUtils.getLanguage());
List<ThingsModelStandard> thingsModelStandards = thingsModelStandardMapper.selectThingsModelStandardList(thingsModelStandard);
for (ThingsModelStandard template : thingsModelStandards) {
Datatype datatype = JSONObject.parseObject(template.getSpecs(), Datatype.class);
switch (datatype.getType()) {
case "integer":
template.setLimitValue(datatype.getMin()+ "/"+ datatype.getMax());
template.setDatatype(datatype.getType());
template.setUnit(datatype.getUnit());
break;
case "bool":
template.setLimitValue("0:"+datatype.getFalseText()+ "/" + "1:"+datatype.getTrueText());
template.setDatatype(datatype.getType());
break;
case "enum":
List<EnumItem> enumList = datatype.getEnumList();
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < enumList.size(); i++) {
EnumItem item = enumList.get(i);
String s = item.getValue() + ":" + item.getText();
buffer.append(s);
if (i < enumList.size() -1){
buffer.append("/");
}
}
template.setLimitValue(buffer.toString());
template.setDatatype(datatype.getType());
break;
}
}
return thingsModelStandards;
}
}

View File

@@ -5,7 +5,6 @@ import com.alibaba.fastjson2.JSONObject;
import com.xinda.common.constant.CacheConstants;
import com.xinda.common.constant.Constants;
import com.xinda.common.constant.UserConstants;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.core.domain.entity.SysUser;
import com.xinda.common.core.redis.RedisCache;
import com.xinda.common.exception.user.CaptchaException;
@@ -29,6 +28,7 @@ import com.xinda.system.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -50,6 +50,12 @@ public class ToolServiceImpl implements IToolService
{
private static final Logger log = LoggerFactory.getLogger(ToolServiceImpl.class);
@Value("${spring.mqtt.gen-username}")
private String genUsername;
@Value("${spring.mqtt.gen-password}")
private String genPassword;
@Autowired
private RedisCache redisCache;
@@ -70,6 +76,7 @@ public class ToolServiceImpl implements IToolService
@Resource
private ISysDeptService sysDeptService;
/**
* 生成随机数字和字母
*/
@@ -371,6 +378,26 @@ public class ToolServiceImpl implements IToolService
}
}
/**
* 设备简单认证
*/
@Override
public ResponseEntity miniMqttAuthentication(MqttAuthenticationModel mqttModel) {
// 验证用户名
if (!mqttModel.getUserName().equals(genUsername)) {
return returnUnauthorized(mqttModel, "设备简单认证设备mqtt用户名错误");
}
// 验证密码
if (!mqttModel.getPassword().equals(genPassword)) {
return returnUnauthorized(mqttModel, "设备简单认证设备mqtt密码错误");
}
log.info("-----------设备简单认证成功,clientId:" + mqttModel.getClientId() + "---------------");
return ResponseEntity.ok().body("ok");
}
/**
* 设备加密认证
*
@@ -468,6 +495,13 @@ public class ToolServiceImpl implements IToolService
}
}
@Override
public ResponseEntity clientAuthNoClient(String clientid,String username,String password) {
// 设备简单认证
return this.miniMqttAuthentication(new MqttAuthenticationModel(clientid, username, password));
}
@Override
public ResponseEntity clientAuthv5(String clientid,String username,String password) throws Exception {
JSONObject ret = new JSONObject();

View File

@@ -0,0 +1,116 @@
package com.xinda.iot.util;
import org.apache.commons.jexl3.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FormulaCalculator {
private static final JexlEngine jexl = new JexlBuilder()
.cache(512)
.silent(false)
.strict(true)
.create();
// 匹配字母开头包含字母、数字的变量名至少1位
private static final Pattern VAR_PATTERN = Pattern.compile("\\b[a-zA-Z][a-zA-Z0-9]*\\b");
public static String evaluate(String formula, Map<String, String> variables) {
// 校验公式安全性
// validateFormula(formula, variables.keySet());
// 创建上下文并注入变量
JexlContext context = new MapContext();
variables.forEach((name, value) -> {
Number num = parseNumber(value);
context.set(name, num);
});
try {
// 执行计算
JexlExpression expr = jexl.createExpression(formula);
return expr.evaluate(context).toString();
} catch (JexlException e) {
throw new RuntimeException("Formula evaluation failed: " + e.getMessage());
}
}
private static Number parseNumber(String value) {
try {
if (value.contains(".")) {
return Double.parseDouble(value);
}
return Long.parseLong(value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid number format: " + value);
}
}
private static void validateFormula(String formula, Set<String> validVars) {
// 安全字符校验(允许变量名、运算符、数字和括号)
if (!formula.matches("^[\\w+\\-*/%().]+$")) {
throw new IllegalArgumentException("包含非法字符");
}
// 提取公式中的变量
Matcher matcher = VAR_PATTERN.matcher(formula);
Set<String> formulaVars = new HashSet<>();
while (matcher.find()) {
String var = matcher.group();
// 排除纯数字的情况
if (!var.matches("\\d+")) {
formulaVars.add(var);
}
}
// 校验变量是否存在
formulaVars.removeAll(validVars);
if (!formulaVars.isEmpty()) {
throw new IllegalArgumentException("未定义的变量: " + formulaVars);
}
}
/**
* 校验变量集合是否包含公式所需全部参数
* @param formula 运算公式
* @param variables 变量集合key为变量名
* @return true-变量完整 | false-存在缺失
*/
public static boolean containsAllVariables(String formula, Map<String, String> variables) {
// 提取公式中的有效变量名(过滤纯数字)
Set<String> requiredVars = extractFormulaVariables(formula);
// 空值安全校验
if (variables == null) return requiredVars.isEmpty();
// 检查所有必要变量是否存在
return variables.keySet().containsAll(requiredVars);
}
/**
* 公开的变量提取方法
*/
public static Set<String> extractFormulaVariables(String formula) {
Matcher matcher = VAR_PATTERN.matcher(formula);
Set<String> vars = new HashSet<>();
while (matcher.find()) {
String var = matcher.group();
if (!isPureNumber(var)) { // 过滤纯数字
vars.add(var);
}
}
return Collections.unmodifiableSet(vars);
}
/**
* 判断字符串是否为纯数字
*/
private static boolean isPureNumber(String str) {
return str.matches("^\\d+$");
}
}

View File

@@ -7,6 +7,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.xinda.iot.domain.Category" id="CategoryResult">
<result property="categoryId" column="category_id" />
<result property="categoryName" column="category_name" />
<result property="modelName" column="model_name" />
<result property="standardId" column="standard_id" />
<result property="standardName" column="standard_name" />
<result property="tenantId" column="tenant_id" />
<result property="tenantName" column="tenant_name" />
<result property="isSys" column="is_sys" />
@@ -19,14 +22,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.xinda.iot.model.IdAndName" id="CategoryShortResult">
<result property="id" column="category_id" />
<result property="name" column="category_name" />
<!-- <result property="modelName" column="model_name" />-->
<!-- <result property="standardId" column="standard_id" />-->
</resultMap>
<sql id="selectCategoryVo">
select category_id, category_name, tenant_id, tenant_name, is_sys,order_num, create_time, update_time, remark from iot_category
select category_id, category_name,model_name, standard_id,standard_name,tenant_id, tenant_name, is_sys,order_num, create_time, update_time, remark from iot_category
</sql>
<select id="selectCategoryList" parameterType="com.xinda.iot.domain.Category" resultMap="CategoryResult">
select c.category_id, c.category_name, c.tenant_id, c.tenant_name,
select c.category_id, c.category_name,c.model_name,c.standard_id,c.standard_name, c.tenant_id, c.tenant_name,
c.is_sys,c.order_num, c.create_time, c.update_time, c.remark
from iot_category c
<where>
@@ -48,6 +53,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and c.tenant_id = #{tenantId}
</if>
<if test="categoryName != null and categoryName != ''"> and c.category_name like concat('%', #{categoryName}, '%')</if>
<if test="modelName != null and modelName != ''"> and c.model_name like concat('%', #{modelName}, '%')</if>
<if test="standardId != null and standardId != ''"> and (c.standard_id = #{standardId})</if>
<if test="tenantId != null and tenantId != ''"> and (c.tenant_id = #{tenantId} or c.is_sys = 1)</if>
</where>
order by order_num
@@ -55,6 +62,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCategoryShortList" resultMap="CategoryShortResult">
select c.category_id, c.category_name
-- select c.category_id, CONCAT_WS('-', c.category_name, c.model_name) AS category_name
-- ,c.model_name,c.standard_id
from iot_category c
<where>
<if test="deptId != null and showSenior and !isAdmin">
@@ -75,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and c.tenant_id = #{tenantId}
</if>
<if test="categoryName != null and categoryName != ''"> and c.category_name like concat('%', #{categoryName}, '%')</if>
<if test="modelName != null and modelName != ''"> and c.model_name like concat('%', #{modelName}, '%')</if>
<!-- <if test="standardId != null and standardId != ''"> and (m.standard_id = #{standardId})</if>-->
<if test="tenantId != null and tenantId != ''"> and (c.tenant_id = #{tenantId} or c.is_sys = 1)</if>
</where>
order by order_num
@@ -89,6 +100,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into iot_category
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="categoryName != null and categoryName != ''">category_name,</if>
<if test="modelName != null and modelName != ''">model_name,</if>
<if test="standardId != null">standard_id,</if>
<if test="standardName != null and standardName != ''">standard_name,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="tenantName != null and tenantName != ''">tenant_name,</if>
<if test="isSys != null">is_sys,</if>
@@ -101,6 +115,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="categoryName != null and categoryName != ''">#{categoryName},</if>
<if test="modelName != null and modelName != ''">#{modelName},</if>
<if test="standardId != null">#{standardId},</if>
<if test="standardName != null and standardName != ''">#{standardName},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="tenantName != null and tenantName != ''">#{tenantName},</if>
<if test="isSys != null">#{isSys},</if>
@@ -117,6 +134,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update iot_category
<trim prefix="SET" suffixOverrides=",">
<if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
<if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
<if test="standardId != null">standard_id = #{standardId},</if>
<if test="standardName != null and standardName != ''">standard_name = #{standardName},</if>
<if test="tenantId != null">tenant_id = #{tenantId},</if>
<if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
<if test="isSys != null">is_sys = #{isSys},</if>

View File

@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xinda.iot.mapper.StandardMapper">
<resultMap type="com.xinda.iot.domain.Standard" id="StandardResult">
<result property="standardId" column="standard_id" />
<result property="standardName" column="standard_name" />
<result property="tenantId" column="tenant_id" />
<result property="tenantName" column="tenant_name" />
<result property="isSys" column="is_sys" />
<result property="orderNum" column="order_num" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<resultMap type="com.xinda.iot.model.IdAndName" id="StandardShortResult">
<result property="id" column="standard_id" />
<result property="name" column="standard_name" />
</resultMap>
<sql id="selectStandardVo">
select standard_id, standard_name, tenant_id, tenant_name, is_sys,order_num, create_time, update_time, remark from iot_standard
</sql>
<select id="selectStandardList" parameterType="com.xinda.iot.domain.Standard" resultMap="StandardResult">
select c.standard_id, c.standard_name, c.tenant_id, c.tenant_name,
c.is_sys,c.order_num, c.create_time, c.update_time, c.remark
from iot_standard c
<where>
<if test="deptId != null and showSenior and !isAdmin">
and ( c.tenant_id = #{tenantId}
or (c.tenant_id in (
SELECT de.dept_user_id
FROM sys_dept de
WHERE FIND_IN_SET( de.dept_id,(
SELECT d.ancestors
FROM sys_dept d
WHERE d.dept_id = #{deptId} )
)
)
)
)
</if>
<if test="!showSenior and tenantId != null and tenantId != 0 and !isAdmin">
and c.tenant_id = #{tenantId}
</if>
<if test="standardName != null and standardName != ''"> and c.standard_name like concat('%', #{standardName}, '%')</if>
<if test="tenantId != null and tenantId != ''"> and (c.tenant_id = #{tenantId} or c.is_sys = 1)</if>
</where>
order by order_num
</select>
<select id="selectStandardShortList" resultMap="StandardShortResult">
select c.standard_id, c.standard_name
from iot_standard c
<where>
<if test="deptId != null and showSenior and !isAdmin">
and ( c.tenant_id = #{tenantId}
or (c.tenant_id in (
SELECT de.dept_user_id
FROM sys_dept de
WHERE FIND_IN_SET( de.dept_id,(
SELECT d.ancestors
FROM sys_dept d
WHERE d.dept_id = #{deptId} )
)
)
)
)
</if>
<if test="!showSenior and tenantId != null and tenantId != 0 and !isAdmin">
and c.tenant_id = #{tenantId}
</if>
<if test="standardName != null and standardName != ''"> and c.standard_name like concat('%', #{standardName}, '%')</if>
<if test="tenantId != null and tenantId != ''"> and (c.tenant_id = #{tenantId} or c.is_sys = 1)</if>
</where>
order by order_num
</select>
<select id="selectStandardByStandardId" parameterType="Long" resultMap="StandardResult">
<include refid="selectStandardVo"/>
where standard_id = #{standardId}
</select>
<insert id="insertStandard" parameterType="com.xinda.iot.domain.Standard" useGeneratedKeys="true" keyProperty="standardId">
insert into iot_standard
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="standardName != null and standardName != ''">standard_name,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="tenantName != null and tenantName != ''">tenant_name,</if>
<if test="isSys != null">is_sys,</if>
<if test="orderNum != null">order_num,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="standardName != null and standardName != ''">#{standardName},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="tenantName != null and tenantName != ''">#{tenantName},</if>
<if test="isSys != null">#{isSys},</if>
<if test="orderNum != null">#{orderNum},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateStandard" parameterType="com.xinda.iot.domain.Standard">
update iot_standard
<trim prefix="SET" suffixOverrides=",">
<if test="standardName != null and standardName != ''">standard_name = #{standardName},</if>
<if test="tenantId != null">tenant_id = #{tenantId},</if>
<if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
<if test="isSys != null">is_sys = #{isSys},</if>
<if test="orderNum != null">order_num = #{orderNum},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where standard_id = #{standardId}
</update>
<delete id="deleteStandardByStandardId" parameterType="Long">
delete from iot_standard where standard_id = #{standardId}
</delete>
<delete id="deleteStandardByStandardIds" parameterType="String">
delete from iot_standard where standard_id in
<foreach item="standardId" collection="array" open="(" separator="," close=")">
#{standardId}
</foreach>
</delete>
<select id="productCountInStandards" parameterType="String" resultType="int">
select count(*) from iot_product where standard_id in
<foreach item="standardId" collection="array" open="(" separator="," close=")">
#{standardId}
</foreach>
</select>
</mapper>

View File

@@ -0,0 +1,232 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xinda.iot.mapper.ThingsModelStandardMapper">
<resultMap type="com.xinda.iot.domain.ThingsModelStandard" id="ThingsModelStandardResult">
<result property="templateId" column="template_id" />
<result property="templateName" column="template_name" />
<result property="standardId" column="standard_id" />
<result property="standardName" column="standard_name" />
<result property="tenantId" column="tenant_id" />
<result property="tenantName" column="tenant_name" />
<result property="identifier" column="identifier" />
<result property="type" column="type" />
<result property="datatype" column="datatype" />
<result property="specs" column="specs" />
<result property="isSys" column="is_sys" />
<result property="isReadonly" column="is_readonly" />
<result property="isSharePerm" column="is_share_perm" />
<result property="isHistory" column="is_history" />
<result property="isMonitor" column="is_monitor" />
<result property="isApp" column="is_app"/>
<result property="formula" column="formula" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="modelOrder" column="model_order" />
</resultMap>
<sql id="selectThingsModelStandardVo">
select template_id, template_name, standard_id, standard_name, tenant_id, tenant_name, identifier, type, datatype, specs, is_sys, is_readonly, is_chart,is_share_perm, is_history, formula, del_flag, create_by, create_time, update_by, update_time, remark, model_order from iot_things_model_standard
</sql>
<select id="selectThingsModelStandardList" parameterType="com.xinda.iot.domain.ThingsModelStandard" resultMap="ThingsModelStandardResult">
select m.template_id,m.template_name,m.standard_id,m.standard_name,
m.tenant_id, m.tenant_name, m.identifier, m.type, m.datatype, m.specs, m.is_sys, m.is_readonly, m.is_chart, m.is_share_perm, m.is_history, m.formula, m.del_flag, m.create_by, m.create_time, m.update_by, m.update_time, m.remark, m.model_order, m.is_monitor
from iot_things_model_standard m
<where>
<if test="templateName != null and templateName != ''"> and m.template_name like concat('%', #{templateName}, '%')</if>
<if test="type != null "> and m.type = #{type}</if>
<if test="specs != null and specs != ''"> and m.specs = #{specs}</if>
<if test="tenantId != null and tenantId != ''"> and (m.tenant_id = #{tenantId} or m.is_sys = 1)</if>
<if test="standardId != null and standardId != ''"> and (m.standard_id = #{standardId})</if>
</where>
order by m.template_id desc, m.create_time desc
</select>
<select id="selectModelListByStandardId" parameterType="Long" resultMap="ThingsModelStandardResult">
select m.template_id,m.template_name,m.standard_id,m.standard_name,
m.tenant_id, m.tenant_name, m.identifier, m.type, m.datatype, m.specs, m.is_sys, m.is_readonly, m.is_chart, m.is_share_perm, m.is_history, m.formula, m.del_flag, m.create_by, m.create_time, m.update_by, m.update_time, m.remark, m.model_order, m.is_monitor
from iot_things_model_standard m
<where>
m.standard_id = #{standardId}
</where>
order by m.template_id desc, m.create_time desc
</select>
<select id="selectThingsModelStandardByTemplateId" resultMap="ThingsModelStandardResult">
select m.template_id,m.template_name, m.standard_id, m.standard_name,m.tenant_id, m.tenant_name, m.identifier, m.type, m.datatype, m.specs, m.is_sys, m.is_readonly, m.is_chart, m.is_share_perm, m.is_history, m.formula, m.del_flag, m.create_by, m.create_time, m.update_by, m.update_time, m.remark, m.model_order
from iot_things_model_standard m
where m.template_id = #{templateId}
</select>
<select id="selectThingsModelStandardByTemplateIds" resultMap="ThingsModelStandardResult">
select m.template_id, m.template_name, m.standard_id, m.standard_name,m.tenant_id, m.tenant_name, m.identifier, m.type, m.datatype, m.specs, m.is_sys, m.is_readonly, m.is_chart, m.is_share_perm, m.is_history, m.formula, m.del_flag, m.create_by, m.create_time, m.update_by, m.update_time, m.remark, m.model_order, m.is_monitor
from iot_things_model_standard m
where m.template_id in
<foreach item="templateId" collection="templateIds" open="(" separator="," close=")">
#{templateId}
</foreach>
</select>
<insert id="insertThingsModelStandard" parameterType="com.xinda.iot.domain.ThingsModelStandard" useGeneratedKeys="true" keyProperty="templateId">
insert into iot_things_model_standard
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="templateName != null and templateName != ''">template_name,</if>
<if test="standardId != null">standard_id,</if>
<if test="standardName != null and standardName != ''">standard_name,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="tenantName != null and tenantName != ''">tenant_name,</if>
<if test="identifier != null and identifier != ''">identifier,</if>
<if test="type != null">type,</if>
<if test="datatype != null and datatype != ''">datatype,</if>
<if test="specs != null and specs != ''">specs,</if>
<if test="isSys != null">is_sys,</if>
<if test="isReadonly != null">is_readonly,</if>
<if test="isChart != null">is_chart,</if>
<if test="isSharePerm != null">is_share_perm,</if>
<if test="isHistory != null">is_history,</if>
<if test="isMonitor != null">is_monitor,</if>
<if test="isApp != null">is_app,</if>
<if test="formula != null">formula,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="modelOrder != null">model_order,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="templateName != null and templateName != ''">#{templateName},</if>
<if test="standardId != null">#{standardId},</if>
<if test="standardName != null and standardName != ''">#{standardName},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="tenantName != null and tenantName != ''">#{tenantName},</if>
<if test="identifier != null and identifier != ''">#{identifier},</if>
<if test="type != null">#{type},</if>
<if test="datatype != null and datatype != ''">#{datatype},</if>
<if test="specs != null and specs != ''">#{specs},</if>
<if test="isSys != null">#{isSys},</if>
<if test="isReadonly != null">#{isReadonly},</if>
<if test="isChart != null">#{isChart},</if>
<if test="isSharePerm != null">#{isSharePerm},</if>
<if test="isHistory != null">#{isHistory},</if>
<if test="isMonitor != null">#{isMonitor},</if>
<if test="isApp != null">#{isApp},</if>
<if test="formula != null">#{formula},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="modelOrder != null">#{modelOrder},</if>
</trim>
</insert>
<update id="updateThingsModelStandard" parameterType="com.xinda.iot.domain.ThingsModelStandard">
update iot_things_model_standard
<trim prefix="SET" suffixOverrides=",">
<if test="templateName != null and templateName != ''">template_name = #{templateName},</if>
<if test="standardId != null">standard_id = #{standardId},</if>
<if test="standardName != null and standardName != ''">standard_name = #{standardName},</if>
<if test="tenantId != null">tenant_id = #{tenantId},</if>
<if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
<if test="identifier != null and identifier != ''">identifier = #{identifier},</if>
<if test="type != null">type = #{type},</if>
<if test="datatype != null and datatype != ''">datatype = #{datatype},</if>
<if test="specs != null and specs != ''">specs = #{specs},</if>
<if test="isSys != null">is_sys = #{isSys},</if>
<if test="isReadonly != null">is_readonly = #{isReadonly},</if>
<if test="isChart != null">is_chart = #{isChart},</if>
<if test="isSharePerm != null">is_share_perm = #{isSharePerm},</if>
<if test="isHistory != null">is_history = #{isHistory},</if>
<if test="isMonitor != null">is_Monitor = #{isMonitor},</if>
<if test="isApp != null">is_app = #{isApp},</if>
<if test="formula != null">formula = #{formula},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where template_id = #{templateId}
</update>
<delete id="deleteThingsModelStandardByTemplateId" parameterType="Long">
delete from iot_things_model_standard where template_id = #{templateId}
</delete>
<delete id="deleteThingsModelStandardByTemplateIds" parameterType="String">
delete from iot_things_model_standard where template_id in
<foreach item="templateId" collection="array" open="(" separator="," close=")">
#{templateId}
</foreach>
</delete>
<insert id="batchThingsModelStandards" parameterType="java.util.List">
INSERT INTO iot_things_model_standard (
template_name,
standard_id,
standard_name,
tenant_id,
tenant_name,
identifier,
type,
datatype,
specs,
is_sys,
is_readonly,
is_share_perm,
is_history,
is_monitor,
is_app,
formula,
del_flag,
create_by,
create_time,
update_by,
update_time,
remark,
model_order
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.templateName},
#{item.standardId},
#{item.standardName},
#{item.tenantId},
#{item.tenantName},
#{item.identifier},
#{item.type},
#{item.datatype},
#{item.specs},
#{item.isSys},
#{item.isReadonly},
#{item.isSharePerm},
#{item.isHistory},
#{item.isMonitor},
#{item.isApp},
#{item.formula},
#{item.delFlag},
#{item.createBy},
#{item.createTime},
#{item.updateBy},
#{item.updateTime},
#{item.remark},
#{item.modelOrder}
)
</foreach>
</insert>
</mapper>