2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-02 f0601397ed62879820e3f6318acd1641651aea22
Merge remote-tracking branch 'origin/master'
已修改7个文件
130 ■■■■ 文件已修改
dao/src/main/java/com/sandu/ximon/dao/mapper/MenuMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/MenuMapper.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/AirDataController.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/amqp/AmqpMessageListener.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5LightHeartbeatReportInnerFrame.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/mapper/MenuMapper.java
@@ -13,6 +13,10 @@
public interface MenuMapper extends BaseMapper<Menu> {
    List<Long> listMenu();
    List<Long> listMenuIfBinding(Long id);
    List<Long> listMenuIfBinding1(Long id);
}
dao/src/main/resources/mapper/MenuMapper.xml
@@ -30,4 +30,21 @@
    <select id="listMenu" resultType="java.lang.Long">
        SELECT id FROM menu
    </select>
    <select id="listMenuIfBinding" resultType="java.lang.Long">
        SELECT t1.id
        FROM menu t1
        LEFT JOIN role_menu_relation t2 ON t1.id = t2.menu_id
        <where>
            t2.menu_id = #{id}
        </where>
    </select>
    <select id="listMenuIfBinding1" resultType="java.lang.Long" parameterType="java.lang.Long">
        SELECT t1.id
        FROM menu t1
        <where>
            t1.pid = #{id}
        </where>
    </select>
</mapper>
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/AirDataController.java
@@ -1,8 +1,10 @@
package com.sandu.ximon.admin.controller;
import com.alibaba.fastjson.JSON;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.manager.iot.amqp.processor.AirDataProcessor;
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.AirDataReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
@@ -54,7 +56,6 @@
    public ResponseVO<Object> updataAirEquipmentInfo(@RequestBody List<String> listMac) {
        AirDataReqInnerFrame airDataReqInnerFrame = new AirDataReqInnerFrame();
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), airDataReqInnerFrame);
//        WrapResponseCommonFrame<A5AtmosphereHeartbeatReportInnerFrame> wrapResponseCommonFrame =
//                MainBoardInvokeSyncService.getInstance().sendRRPC(listMac.get(0), a5Frame, A5AtmosphereHeartbeatReportInnerFrame.class);
@@ -62,9 +63,13 @@
        List<String> failed = new ArrayList<>();
        listMac.parallelStream().forEach(macStr -> {
//            System.out.println(System.currentTimeMillis()+"       -------------");
            try {
                CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(macStr, a5Frame);
//                //测试用的
//                String s = "{\"connectType\":\"FE\",\"crc32\":\"8685DF1B\",\"functionCode\":\"A5\",\"orderType\":\"84\",\"payload\":\"F0010022FFFF0101016666640000000000000000419D000000360089000000000002019300008CA14C69\",\"payloadLength\":\"002A\",\"validate\":true}";
//                CommonFrame commonFrame1 = JSON.parseObject(s, CommonFrame.class);
//                AirDataProcessor.getInstance().process("a1JsfPG4iKW",macStr,commonFrame1);
                AirDataProcessor.getInstance().process("a1JsfPG4iKW",macStr,commonFrame);
                if (commonFrame != null) {
                    success.add(macStr);
                } else {
@@ -73,24 +78,7 @@
            } catch (Exception e) {
                failed.add(macStr);
            }
//            System.out.println(System.currentTimeMillis());
        });
//        for (String macStr : listMac) {
//            System.out.println(System.currentTimeMillis()+"       -------------");
//            try {
//                CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(macStr, a5Frame);
//                if (commonFrame != null) {
//                    success.add(macStr);
//                } else {
//                    failed.add(macStr);
//                }
//            } catch (Exception e) {
//                failed.add(macStr);
//            }
//            System.out.println(System.currentTimeMillis());
//        }
        Map<String, List> resultMap = new HashMap<>();
        resultMap.put("success", success);
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/amqp/AmqpMessageListener.java
@@ -90,8 +90,8 @@
        if (frame == null) {
            return;
        }
        log.info("处理订阅");
        log.info(frame.toString());
//        log.info("处理订阅");
//        log.info(frame.toString());
        if (frame.getOrderType().equals(A5OrderEnum.RESPONSE_LIGHT_DATA.getCode())) {
            // 单灯数据上报处理
            LightDataProcessor.getInstance().process(productKey, deviceName, frame);
@@ -99,6 +99,9 @@
            // C3充电桩上报处理
            c3ChargingReportAnalysis(productKey, deviceName, frame);
        } else if (frame.getOrderType().equals(A5OrderEnum.RESPONSE_ATMOSPHERE_DATA.getCode())) {
//            //测试用的
//            String s = "{\"connectType\":\"FE\",\"crc32\":\"8685DF1B\",\"functionCode\":\"A5\",\"orderType\":\"84\",\"payload\":\"F0010022FFFF0101010907640000000000000000419D000000360089000000000002019300008CA14C69\",\"payloadLength\":\"002A\",\"validate\":true}";
//            CommonFrame commonFrame1 = JSON.parseObject(s, CommonFrame.class);
            // 大气数据指令上报
            AirDataProcessor.getInstance().process(productKey, deviceName, frame);
//            atmosphereAnalysis(productKey, deviceName, frame);
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5LightHeartbeatReportInnerFrame.java
@@ -108,7 +108,9 @@
            this.min = HexUtil.hexToInt(hex.substring(8, 10));
            this.sec = HexUtil.hexToInt(hex.substring(10, 12));
            this.deviceTemperature = NumberUtil.round(HexUtil.hexToInt(hex.substring(12, 16)) * 0.01, 2).doubleValue();
//            //需要把十六进制转二进制
//            this.deviceTemperature = NumberUtil.round(HexUtil.hexToInt(hex.substring(12, 16)) * 0.01, 2).doubleValue();
            this.deviceTemperature = NumberUtil.round(temperatureTransition(hex.substring(12, 16)), 2).doubleValue();
            this.lightPercent = HexUtil.hexToInt(hex.substring(16, 18));
            this.voltage = NumberUtil.round(HexUtil.hexToInt(hex.substring(18, 22)) * 0.1, 1).doubleValue();
            this.electricCurrent = NumberUtil.round(HexUtil.hexToInt(hex.substring(22, 26)) * 0.001, 3).doubleValue();
@@ -124,6 +126,50 @@
            this.retain = hex.substring(76, 96);
            return this;
        }
        /**
         * 将16进制转成2进制,进行补码(反码基础上+1),得到正确数值
         * 传入16进制的温度,类型为String
         * 如F500
         */
        public static Double temperatureTransition(String temperature) {
            //将传进来的16进制的转为2进制
            String twoBinStr = hexStr2BinStr(temperature);
            if ("1".equals(twoBinStr.substring(0, 1))) {
                //最高位是1,为负数,将16进制的进行补码,返回
                int max = 0b1111111111111111;
                double result = (max-HexUtil.hexToInt(temperature))*(-0.01);
                return result;
            } else if ("0".equals(twoBinStr.substring(0, 1))) {
                //最高位是0,正数,直接返回
                double result = (HexUtil.hexToInt(temperature))*(0.01);
                return result;
            }
            //
            return 0.00;
        }
        /**
         * 16进制字符串转为二进制
         * */
        public static String hexStr2BinStr(String hexStr)
        {
            if (hexStr == null || hexStr.length() % 2 != 0)
            {
                return null;
            }
            String bString = "", tmp;
            for (int i = 0; i < hexStr.length(); i++)
            {
                tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexStr.substring(i, i + 1), 16));
                bString += tmp.substring(tmp.length() - 4);
            }
            return bString;
        }
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java
@@ -35,6 +35,7 @@
public class MenuService extends BaseServiceImpl<MenuMapper, Menu> {
    private final RoleMenuRelationService roleMenuRelationService;
    /**
     * 获取角色下的菜单
     */
@@ -49,7 +50,7 @@
    public boolean addMenu(MenuParam param) {
        Menu menu = new Menu();
        BeanUtils.copyProperties(param,menu);
        BeanUtils.copyProperties(param, menu);
        return save(menu);
    }
@@ -78,7 +79,7 @@
        return node;
    }
    public boolean updateMenu(Long menuId,MenuParam param) {
    public boolean updateMenu(Long menuId, MenuParam param) {
        Menu one = getById(menuId);
        if (one == null) {
            throw new BusinessException("找不到菜单信息");
@@ -86,12 +87,12 @@
        List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
        Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
        if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
        if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
            throw new BusinessException("超级管理员才可以编辑菜单");
        }
        Menu menu = new Menu();
        BeanUtils.copyProperties(param,menu);
        BeanUtils.copyProperties(param, menu);
        menu.setId(menuId);
        return updateById(menu);
    }
@@ -103,6 +104,8 @@
                .map(menu -> covertMenuNode(menu, list)).collect(Collectors.toList());
    }
    private MenuMapper menuMapper;
    public boolean delMenu(Long menuId) {
        Menu one = getById(menuId);
        if (one == null) {
@@ -111,9 +114,17 @@
        List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
        Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
        if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
        if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
            throw new BusinessException("超级管理员才可以删除菜单");
        }
        return removeById(menuId);
        List<Long> list = menuMapper.listMenuIfBinding(menuId);
        List<Long> list1 = menuMapper.listMenuIfBinding1(menuId);
        if (list.size() == 0 && list1.size() == 0) {
            return removeById(menuId);
        } else {
            throw new BusinessException("菜单正在使用,请勿删除");
        }
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
@@ -148,6 +148,11 @@
        if (role == null) {
            throw new BusinessException("找不到角色");
        }
        //超级管理员不能删除
        if(RoleLevelStatus.SUPER.getCode().equals(role.getLevel())){
            throw new BusinessException("当前角色为超级管理员,无法删除");
        }
        assertLevels(role.getLevel());
        List<AdminRoleRelation> list = adminRoleRelationService.list(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getRoleId, role));
        if (CollectionUtil.isNotEmpty(list)) {