das接口修改,映射表相关

This commit is contained in:
chenhaojie 2024-07-29 17:33:56 +08:00
parent bbccc14fd8
commit ddec414dbe
4 changed files with 46 additions and 8 deletions

View File

@ -190,10 +190,10 @@ public class SysNodeController {
public R<Void> bindMeas(@RequestBody BindEquipmentDto bindEquipmentDto) {
//判断是否有权限
// boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
// if(!hasPermission){
// return R.fail("没有节点管理权限");
// }
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
if(!hasPermission){
return R.fail("没有节点管理权限");
}
sysNodeService.bindDeviceMeas(bindEquipmentDto.getEquipmentId(), bindEquipmentDto.getLinkId());
return R.success();
}

View File

@ -3,6 +3,7 @@ package com.das.modules.node.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.das.modules.auth.mapper.BaseMapperPlus;
import com.das.modules.node.domain.dto.SysCommunicationLinkDto;
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
import com.das.modules.node.domain.vo.SysImptabmappingVo;
@ -14,8 +15,10 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysImptabmappingMapper extends BaseMapper<SysImptabmapping> {
public interface SysImptabmappingMapper extends BaseMapperPlus<SysImptabmapping, SysImptabmapping> {
List<SysImptabmappingVo> getMappingList(Long linkId);
List<SysImptabmappingVo> getBindDevice(Long linkId);
void deleteBindDevice(Long linkId);
}

View File

@ -25,6 +25,7 @@ import com.das.modules.node.service.SysNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
@ -169,9 +170,38 @@ public class SysNodeServiceImpl implements SysNodeService {
@Override
public void bindDeviceMeas(List<Long> equipmentId, Long linkId) {
List<SysImptabmapping> insertList = new ArrayList<>();
List<Long> deleteList = new ArrayList<>();
List<SysImptabmapping> deleteMeasList = new ArrayList<>();
List<SysImptabmapping> addList = new ArrayList<>();
//获取已经绑定的设备
List<SysImptabmappingVo> bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId);
// SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
SysUserVo sysUserVo = new SysUserVo();
sysUserVo.setAccount("测试");
if (CollectionUtils.isEmpty(bindDeviceList)) {
addSysImptabmapping(equipmentId, linkId, sysUserVo, addList);
} else {
// 删除原来绑定的设备信息
sysImptabmappingMapper.deleteBindDevice(linkId);
addSysImptabmapping(equipmentId, linkId, sysUserVo, addList);
}
if (!CollectionUtils.isEmpty(addList)) {
sysImptabmappingMapper.insertBatch(addList);
}
}
private static void addSysImptabmapping(List<Long> equipmentId, Long linkId, SysUserVo sysUserVo, List<SysImptabmapping> addList) {
for (int i = 0; i< equipmentId.size(); i++) {
SysImptabmapping sysImptabmapping = new SysImptabmapping();
sysImptabmapping.setEquipmentId(equipmentId.get(i));
sysImptabmapping.setLinkId(linkId);
sysImptabmapping.setId(SequenceUtils.generateId());
sysImptabmapping.setCreatedTime(new Date());
sysImptabmapping.setUpdatedTime(new Date());
sysImptabmapping.setCreatedBy(sysUserVo.getAccount());
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
sysImptabmapping.setRevision(1);
sysImptabmapping.setPorder(i + 1);
addList.add(sysImptabmapping);
}
}
}

View File

@ -28,6 +28,11 @@
</select>
<delete id="deleteBindDevice" >
delete from sys_imptabmapping where link_id = #{linkId}
</delete>