2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-10 a3acc88a203d505957cd57ce2f508a428d36306b
Changes
已添加2个文件
已修改2个文件
93 ■■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/InterphoneHostSubController.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostSubService.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/InterphoneHostSubController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
package com.sandu.ximon.admin.controller;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.service.InterphoneHostSubService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@AllArgsConstructor
@RequestMapping("/v1/hostBind")
public class InterphoneHostSubController {
    private final InterphoneHostSubService interphoneHostSubService;
    @PostMapping("/bind")
    public ResponseVO<Object> bind(@RequestBody Map map) {
        Integer hostId = (Integer) map.get("hostId");
        Integer subId = (Integer) map.get("subId");
        return ResponseUtil.success(interphoneHostSubService.bindHostSub(hostId, subId));
    }
    @PostMapping("/unbind/{subId}")
    public ResponseVO<Object> unbind(@PathVariable Integer subId) {
        return ResponseUtil.success(interphoneHostSubService.unbindHostSub(subId));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
@@ -1,10 +1,12 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.InterphoneHostParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.InterphoneHostBo;
import com.sandu.ximon.dao.domain.InterphoneHost;
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
import com.sandu.ximon.dao.mapper.InterphoneHostMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
@@ -17,6 +19,8 @@
public class InterphoneHostService extends BaseServiceImpl<InterphoneHostMapper, InterphoneHost> {
    private final InterphoneHostMapper interphoneHostMapper;
    private final InterphoneHostSubService interphoneHostSubService;
    /**
@@ -50,6 +54,11 @@
     */
    public boolean deleteHost(Integer id) {
        InterphoneHost byId = getById(id);
        InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getHostId, id));
        if(one!=null){
            throw new RuntimeException("该主机存在绑定关系,不能删除");
        }
        if (byId == null) {
            return false;
        }
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostSubService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,47 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
import com.sandu.ximon.dao.mapper.InterphoneHostSubPoleMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@AllArgsConstructor
public class InterphoneHostSubService extends BaseServiceImpl<InterphoneHostSubPoleMapper, InterphoneHostSubPole> {
    private InterphoneHostSubPoleMapper interphoneHostSubPoleMapper;
    /**
     * å­è®¾å¤‡ç»‘定主设备
     */
    public boolean bindHostSub(Integer hostId, Integer subId) {
        if (hostId == null || subId == null) {
            throw new BusinessException("主设备id或子设备id不能为空");
        }
        InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId));
        if (one != null) {
            throw new BusinessException("子设备已绑定");
        }
        InterphoneHostSubPole pole = new InterphoneHostSubPole();
        pole.setHostId(hostId);
        pole.setSubId(subId);
        return save(pole);
    }
    /**
     * å­è®¾å¤‡è§£ç»‘主设备
     */
    public boolean unbindHostSub(Integer subId) {
        if (subId == null) {
            throw new BusinessException("子设备id不能为空");
        }
        InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId));
        if (one == null) {
            throw new BusinessException("绑定关系不存在");
        }
        return removeById(one);
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java
@@ -1,10 +1,11 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.InterphoneSubParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.InterphoneHostBo;
import com.sandu.ximon.dao.bo.InterphoneSubBo;
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
import com.sandu.ximon.dao.domain.InterphoneSub;
import com.sandu.ximon.dao.mapper.InterphoneSubMapper;
import lombok.AllArgsConstructor;
@@ -18,6 +19,7 @@
public class InterphoneSubService extends BaseServiceImpl<InterphoneSubMapper, InterphoneSub> {
    private final InterphoneSubMapper interphoneSubMapper;
    private final InterphoneHostSubService interphoneHostSubService;
    /**
     * æ–°å¢žå­è®¾å¤‡
@@ -47,6 +49,10 @@
     */
    public boolean deleteSub(Integer id) {
        InterphoneSub byId = getById(id);
        InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, id));
        if (one != null) {
            throw new RuntimeException("该子设备存在绑定关系,不能删除");
        }
        if (byId == null) {
            return false;
        }