2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-01-12 e6679745b914ead22c88295276555a72745b4ba2
灯杆绑定用户
已修改2个文件
57 ■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java
@@ -102,19 +102,25 @@
    }
    @PostMapping("/listStatusByDeviceCode")
    public ResponseVO<Object> getStatusById(@RequestBody String[] deviceCodeList){
        for (String s: deviceCodeList) {
            if(s==null){
    public ResponseVO<Object> getStatusById(@RequestBody String[] deviceCodeList) {
        for (String s : deviceCodeList) {
            if (s == null) {
                return ResponseUtil.fail("参数不能为空");
            }
        }
        if(ArrayUtil.isEmpty(deviceCodeList)) {
        if (ArrayUtil.isEmpty(deviceCodeList)) {
            return ResponseUtil.fail("参数不能为空");
        }
        List<DeviceStatus> statusList = poleService.listStatusByDeviceCode(CollectionUtil.toList(deviceCodeList));
        return ResponseUtil.success(statusList);
    }
    @GetMapping("/ClientBindingPole")
    public ResponseVO<Object> ClientBindingPole(@RequestParam long clientId, @RequestParam int poleId) {
        return ResponseUtil.success(poleService.ClientBindingPole(clientId, poleId));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -35,6 +35,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -110,10 +111,10 @@
     *
     * @return
     */
    public List<Pole> queryStatesAndList(Integer pageNo,Integer pageSize) {
    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);
        PageHelper.startPage(pageNo, pageSize);
        List<Pole> list = new ArrayList<>();
        if (SecurityUtils.getClientId() == null) {
            list = list(Wrappers.lambdaQuery(Pole.class));
@@ -214,7 +215,7 @@
        }*/
        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);
@@ -226,7 +227,7 @@
        String uniqueMac = a1DeviceMacRespInnerFrame.getMac();
        uniqueMac = uniqueMac.toLowerCase();
        if(uniqueMac.isEmpty()){
        if (uniqueMac.isEmpty()) {
            throw new BusinessException("读取设备唯一ID失败!");
        }
        log.info("唯一码{}", uniqueMac);
@@ -281,28 +282,28 @@
                        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 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);
        String strm = uniqueMac.substring(0, uniqueMac.length() - 2);
        int i = Integer.parseInt(strm);
        pole.setPoleCode(generatePoleCode());
        pole.setDeviceType(i);
        setMac= save(pole);
        setMac = save(pole);
        return setMac;
    }
    public List<String> listDeviceCodeByIds(List<Long> poleIdList) {
        if(CollectionUtil.isEmpty(poleIdList)){
        if (CollectionUtil.isEmpty(poleIdList)) {
            return null;
        }
        List<Pole> list = list(Wrappers.lambdaQuery(Pole.class).in(Pole::getId, poleIdList).select(Pole::getDeviceCode));
@@ -312,6 +313,7 @@
    /**
     * 批量获取阿里云设备的状态
     *
     * @param deviceCodeList 阿里云设备码
     * @return 设备状态列表
     */
@@ -321,7 +323,7 @@
        List<DeviceStatus> statusList = new ArrayList<>();
        for (List<String> list : split) {
            List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(list);
            if(CollectionUtil.isNotEmpty(deviceStatuses)){
            if (CollectionUtil.isNotEmpty(deviceStatuses)) {
                for (BatchGetDeviceStateResponse.DeviceStatus d : deviceStatuses) {
                    DeviceStatus deviceStatus = new DeviceStatus();
                    deviceStatus.setDeviceCode(d.getDeviceName());
@@ -332,4 +334,21 @@
        }
        return statusList;
    }
    /**
     * 用户绑定灯杆
     *
     * @param clientId 用户ID
     * @param poleId   灯杆ID
     * @return
     */
    public boolean ClientBindingPole(long clientId, int poleId) {
        Pole pole = getById(poleId);
        if (pole == null) {
            throw new BusinessException("灯杆不存在");
        }
        pole.setClientId(clientId);
        return updateById(pole);
    }
}