package org.jeecg.modules.iot.service.impl; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.iot.entity.Equipment; import org.jeecg.modules.iot.entity.ParameterGroup; import org.jeecg.modules.iot.entity.RealParameter; import org.jeecg.modules.iot.mapper.ParameterGroupMapper; import org.jeecg.modules.iot.service.IEquipmentService; import org.jeecg.modules.iot.service.IParameterGroupService; import org.jeecg.modules.iot.service.IRealParameterService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @Description: 参数组 * @Author: cuikaidong * @Date: 2024-12-31 * @Version: V1.0 */ @Service public class ParameterGroupServiceImpl extends ServiceImpl implements IParameterGroupService { @Autowired private IRealParameterService realParameterService; @Autowired @Lazy private IEquipmentService equipmentService; @Override public List findParameterGroupByServerId(String serverDeployId) { return new LambdaQueryChainWrapper<>(baseMapper).eq(ParameterGroup::getServerDeployId,serverDeployId).list(); } @Override public Boolean findParameterGroupByName(ParameterGroup parameterGroup) { List equipmentList = new LambdaQueryChainWrapper<>(baseMapper) .eq(ParameterGroup::getEquipmentId, parameterGroup.getEquipmentId()) .eq(ParameterGroup::getName, parameterGroup.getName()) .list(); return equipmentList.size() > 0; } @Override public Boolean findParameterGroupByCode(ParameterGroup parameterGroup) { List equipmentList = new LambdaQueryChainWrapper<>(baseMapper) .eq(ParameterGroup::getEquipmentId, parameterGroup.getEquipmentId()) .eq(ParameterGroup::getCode, parameterGroup.getCode()) .list(); return equipmentList.size() > 0; } @Override @Transactional(rollbackFor = Exception.class) public Result addParameterGroup(ParameterGroup parameterGroup) { // 验证编码名称是否重复 if (findParameterGroupByName(parameterGroup)){ return Result.error("参数组名称已存在!"); } if (findParameterGroupByCode(parameterGroup)){ return Result.error("参数组编号已存在!"); } Equipment equipment = equipmentService.getById(parameterGroup.getEquipmentId()); parameterGroup.setServerDeployId(equipment.getServerId()); baseMapper.insert(parameterGroup); RealParameter realParameter = new RealParameter(); realParameter.setParameterGroupId(parameterGroup.getId()); realParameter.setParameterName("IsConnected"); realParameter.setParameterDescribe("连接状态"); realParameter.setParameterCode(0); realParameter.setParameterType("Bool"); realParameter.setAddress("IsConnected"); realParameter.setSystemDataType("bool"); realParameter.setReadWriteType("只读"); realParameterService.save(realParameter); return Result.ok("添加成功!"); } }