2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-11 ebecb50ecf3c53428fac4f3bd09d98110d6bc8d7
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneSubService.java
@@ -1,18 +1,29 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.InterphoneSubParam;
import com.sandu.ximon.admin.security.SecurityUtils;
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.enums.PoleBindingEnums;
import com.sandu.ximon.dao.mapper.InterphoneSubMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@AllArgsConstructor
public class InterphoneSubService  extends BaseServiceImpl<InterphoneSubMapper, InterphoneSub> {
public class InterphoneSubService extends BaseServiceImpl<InterphoneSubMapper, InterphoneSub> {
    private final InterphoneSubMapper interphoneSubMapper;
    private final InterphoneHostSubService interphoneHostSubService;
    /**
     * 新增子设备
@@ -26,10 +37,14 @@
    /**
     * 修改子设备
     */
    public boolean updateSub(Integer id,InterphoneSubParam interphoneSubParam) {
    public boolean updateSub(Integer id, InterphoneSubParam interphoneSubParam) {
        InterphoneSub byId = getById(id);
        if (byId == null) {
            return false;
        }
        boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSubMac(), PoleBindingEnums.FOR_HELP);
        if (!belong) {
            throw new RuntimeException("该设备不属于您,不能修改设备信息");
        }
        InterphoneSub interphoneSub = new InterphoneSub();
        BeanUtils.copyProperties(interphoneSubParam, interphoneSub);
@@ -42,6 +57,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;
        }
@@ -58,4 +77,20 @@
        }
        return byId;
    }
    /**
     * 查询主机列表
     */
    public List<InterphoneSubBo> getInterphoneSubList(BaseConditionVO baseConditionVO, String keyword) {
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        }
        List<InterphoneSubBo> list;
        if (SecurityUtils.getClientId() == null) {
            list = interphoneSubMapper.getInterphoneSubList(keyword, null);
        } else {
            list = interphoneSubMapper.getInterphoneSubList(keyword, SecurityUtils.getUserId());
        }
        return list;
    }
}