2021与蓝度共同重构项目,服务端
Van333
2022-12-29 727a69f859060093e685582fa10e5de82dcc138a
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -22,6 +22,7 @@
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A1TernaryCodeReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightResetReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A7PlcResetReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.EmptyRequestInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1DeviceMacRespInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1TernaryCodeRespInnerFrame;
@@ -45,6 +46,7 @@
import com.sandu.ximon.dao.domain.*;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.PoleMapper;
import eu.bitwalker.useragentutils.DeviceType;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
@@ -129,24 +131,26 @@
    /**
     * 删除灯杆
     */
    public boolean deletePole(Long poleId) {
        Pole pole = getById(poleId);
        if (pole == null) {
    public boolean deletePole(List<Long> poleIds) {
        List<Pole> poles = listByIds(poleIds);
        if (poles.isEmpty()) {
            throw new BusinessException("未找到该灯杆");
        }
        // 删除灯杆绑定关系
        poleBindingService.remove(Wrappers.<PoleBinding>lambdaQuery().eq(PoleBinding::getPoleId, poleId));
        poleBindingService.remove(Wrappers.<PoleBinding>lambdaQuery().in(PoleBinding::getPoleId, poleIds));
        SpringContextHolder.getBean(LightTaskPoleRelationService.class)
                .remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIds));
        /**
         * 删除灯杆日志记录开始
         */
        String content = "{灯杆Code:" + pole.getDeviceCode() + ", 灯杆名称:" + pole.getPoleName() + " }";
        String content = "{灯杆id:" + poles + " }";
        StoreOperationRecordsUtils.storeOperationData(null, null, "删除灯杆", content);
        /**
         * 删除灯杆日志记录结束
         */
        return removeById(poleId);
        return removeByIds(poleIds);
    }
@@ -745,7 +749,6 @@
//        }
//        return list;
//    }
    public List<Pole> isTrue(List<Pole> list, PoleStatesParam param) {
        //实体灯杆
        List<Pole> isTrue = new ArrayList<>();
@@ -864,8 +867,8 @@
     *
     * @return 是否成功
     */
    public boolean unBindPole(Long poleId, String deviceCode) {
        return poleBindingService.unBindPole(poleId, deviceCode);
    public boolean unBindPole(Long poleId, String deviceCode, Integer deviceType) {
        return poleBindingService.unBindPole(poleId, deviceCode, deviceType);
    }
@@ -884,11 +887,21 @@
        if (deviceName.isEmpty()) {
            throw new BusinessException("该灯杆Mac为空");
        }
        IRequestFrame build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
        Integer deviceType = byId.getDeviceType();
        IRequestFrame build = null;
        if (deviceType < 2){
            build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
        }
        else if (deviceType == 2){
            build = FrameBuilder.builderA7().orderType(A7OrderEnum.REQUEST_PLC_DATA.getCode()).innerFrame(new A7PlcResetReqInnerFrame()).build();
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, build);
        StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "灯杆恢复出厂设置", build, commonFrame);
        System.out.println(commonFrame.toString());
        IRequestFrame iRequestFrame = FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame()).orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build();
        CommonFrame rebootFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, iRequestFrame);
        StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "灯杆重启", iRequestFrame, commonFrame);
@@ -1000,6 +1013,8 @@
            pole.setDeviceType(0);
        } else if ("01".equals(a1DeviceMacRespInnerFrame.getType())) {
            pole.setDeviceType(1);
        } else if ("02".equals(a1DeviceMacRespInnerFrame.getType())) {
            pole.setDeviceType(2);
        }
        pole.setPoleCode(generatePoleCode());
@@ -1007,12 +1022,24 @@
        boolean result = saveOrUpdate(pole);
        if (result) {
            Light light = SpringContextHolder.getBean(LightService.class).getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
            if (light == null) {
                light = new Light();
                light.setDeviceCode(uniqueMac);
                light.setLightCount(2);
                SpringContextHolder.getBean(LightService.class).save(light);
            if (pole.getDeviceType() < 2) {
                Light light = SpringContextHolder.getBean(LightService.class).
                        getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
                if (light == null) {
                    light = new Light();
                    light.setDeviceCode(uniqueMac);
                    light.setLightCount(2);
                    SpringContextHolder.getBean(LightService.class).save(light);
                }
            } else if (pole.getDeviceType() == 2) {
                Plc plc = SpringContextHolder.getBean(PlcService.class).
                        getOne(Wrappers.lambdaQuery(Plc.class).eq(Plc::getDeviceCode,pole.getDeviceCode()).last("limit 1"));
                if (plc == null){
                    plc = new Plc();
                    plc.setDeviceCode(uniqueMac);
                    plc.setPlcCount(3);
                    SpringContextHolder.getBean(PlcService.class).save(plc);
                }
            }
        }
@@ -1418,4 +1445,4 @@
    }
}
}