2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-01-12 3fa847083d45461b4e5ee7ec3dbd9247e8a5047c
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -5,6 +5,7 @@
import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse;
import com.aliyuncs.iot.model.v20180120.QueryDeviceDetailResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.redis.RedisService;
import com.sandu.common.service.impl.BaseServiceImpl;
@@ -39,6 +40,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -108,9 +110,10 @@
     *
     * @return
     */
    public List<Pole> queryStatesAndList() {
    public List<Pole> queryStatesAndList(Integer pageNo,Integer pageSize) {
        // List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class).eq(LampPost::getClientId, SecurityUtils.getUserId()));
        //List<Pole> list = list(Wrappers.lambdaQuery(Pole.class));
        PageHelper.startPage(pageNo,pageSize);
        List<Pole> list = new ArrayList<>();
        if (SecurityUtils.getClientId() == null) {
            list = list(Wrappers.lambdaQuery(Pole.class));
@@ -204,14 +207,14 @@
     */
    public boolean setMac(Long poleId) {
        Pole pole = getById(poleId);
        if (pole == null) {
    public boolean setMac(String baseMac) {
        //Pole pole = getById(poleId);
       /* if (pole == null) {
            throw new BusinessException("未找到该灯杆");
        }
        }*/
        boolean setMac = false;
        String baseMac = "baseDevice";
       // String baseMac = "baseDevice";
        A1Frame a1Frame = new A1Frame(A1OrderEnum.REQUEST_READ_DEVICE_UNIQUE_MAC.getCode(), new EmptyRequestInnerFrame());
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance()
                .sendRRPC(baseMac, a1Frame);
@@ -222,6 +225,10 @@
        log.info(commonFrame.toString());
        String uniqueMac = a1DeviceMacRespInnerFrame.getMac();
        uniqueMac = uniqueMac.toLowerCase();
        if(uniqueMac.isEmpty()){
            throw new BusinessException("读取设备唯一ID失败!");
        }
        log.info("唯一码{}", uniqueMac);
        // 2  从阿里注册
@@ -274,12 +281,23 @@
                        FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame())
                                .orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build());
        if ("00".equals(rebootFrame.getPayload())) {
            pole.setDeviceCode(uniqueMac);
          //  pole.setDeviceCode(uniqueMac);
            setMac = updateById(pole);
           // setMac = updateById(pole);
            System.out.println("重启成功");
        }
        Pole pole=new Pole();
        String strh = uniqueMac.substring(uniqueMac.length() -2,uniqueMac.length());
        pole.setDeviceCode(strh);
        pole.setPoleName(strh);
        String strm = uniqueMac.substring(0,uniqueMac.length()-2);
        int i = Integer.parseInt(strm);
        pole.setPoleCode(generatePoleCode());
        pole.setDeviceType(i);
        setMac= save(pole);
        return setMac;
    }
@@ -287,8 +305,9 @@
        if(CollectionUtil.isEmpty(poleIdList)){
            return null;
        }
        return list(Wrappers.lambdaQuery(Pole.class).in(Pole::getId, poleIdList).select(Pole::getDeviceCode))
                .stream().map(Pole::getDeviceCode).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
        List<Pole> list = list(Wrappers.lambdaQuery(Pole.class).in(Pole::getId, poleIdList).select(Pole::getDeviceCode));
        return list
                .stream().filter(Objects::nonNull).map(Pole::getDeviceCode).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
    }
    /**