zhangnaisong
2024-07-24 58ed1a6894e8fc6896c1ce297a86adac3bbd999e
电磁锁实时状态暂提交
已修改7个文件
226 ■■■■ 文件已修改
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCar.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/service/IArdTankLockService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockStateServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/resources/mapper/sy/ArdSyCarMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -53,6 +53,8 @@
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
/**
 * 三一车辆Controller
 *
@@ -204,7 +206,126 @@
                thread.start();
            }
        };
        lockStateTimer.scheduleAtFixedRate(lockStateTask,date,1000);
        lockStateTimer.scheduleAtFixedRate(lockStateTask,date,3000);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Timer lockCheckTimeTimer = new Timer();//定时校准时间
        TimerTask lockCheckTimeTask =new TimerTask(){
            @Override
            public void run() {
                SysConfig config = new SysConfig();
                config.setConfigKey("syCarPT");
                List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
                String syURL = "";
                if(sysConfigResult.size() == 0){
                    return;
                }else{
                    syURL = sysConfigResult.get(0).getConfigValue();
                }
                String passwordMd5 = DigestUtils.md5Hex(password);
                Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, userId);
                String sessionId = (String) LogInResult.get("sessionId");
                String finalSyURL = syURL;
                List<ArdTankLock> result = ardTankLockService.getArdTankLockAll();//查询全部电磁锁
                for(ArdTankLock ardTankLock : result){
                    Thread LockThread = new Thread(finalSyURL){
                        @Override
                        public void run() {
                            //获取时间并拆分年月日时分秒
                            String nowTime = sdf.format(new Date());
                            String nowYear = nowTime.substring(2,4);
                            String nowMonth = nowTime.substring(5,7);
                            String nowDay = nowTime.substring(8,10);
                            String nowHour = nowTime.substring(11,13);
                            String nowMinute = nowTime.substring(14,16);
                            String nowSecond = nowTime.substring(17,19);
                            String nowYearHex = Integer.toHexString(Integer.parseInt(nowYear));
                            if(nowYearHex.length() == 1){
                                nowYearHex = "0" + nowYearHex;
                            }
                            String nowMonthHex = Integer.toHexString(Integer.parseInt(nowMonth));
                            if(nowMonthHex.length() == 1){
                                nowMonthHex = "0" + nowMonthHex;
                            }
                            String nowDayHex = Integer.toHexString(Integer.parseInt(nowDay));
                            if(nowDayHex.length() == 1){
                                nowDayHex = "0" + nowDayHex;
                            }
                            String nowHourHex = Integer.toHexString(Integer.parseInt(nowHour));
                            if(nowHourHex.length() == 1){
                                nowHourHex = "0" + nowHourHex;
                            }
                            String nowMinuteHex = Integer.toHexString(Integer.parseInt(nowMinute));
                            if(nowMinuteHex.length() == 1){
                                nowMinuteHex = "0" + nowMinuteHex;
                            }
                            String nowSecondHex = Integer.toHexString(Integer.parseInt(nowSecond));
                            if(nowSecondHex.length() == 1){
                                nowSecondHex = "0" + nowSecondHex;
                            }
                            //16进制时间
                            String timeHex = nowYearHex + nowMonthHex + nowDayHex + nowHourHex + nowMinuteHex + nowSecondHex;
                            String lockNumHead = ardTankLock.getLockNum().substring(0,2);
                            String lockNumTail = ardTankLock.getLockNum().substring(2,4);
                            //计算校验
                            String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt("08", 16) +
                                    Integer.parseInt(nowYearHex, 16) + Integer.parseInt(nowMonthHex, 16) + Integer.parseInt(nowDayHex, 16) +
                                    Integer.parseInt(nowHourHex, 16) + Integer.parseInt(nowMinuteHex, 16) + Integer.parseInt(nowSecondHex, 16));
                            if(checkNum.length() == 1){
                                checkNum = "0" + checkNum;
                            }else if(checkNum.length() > 2){
                                checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length());
                            }
                            String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "08" + timeHex + checkNum + "%22%7D";
                            sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
                        }
                    };
                    LockThread.start();
                }
            }
        };
        lockCheckTimeTimer.scheduleAtFixedRate(lockCheckTimeTask,date,10000);
        Timer sendTimer = new Timer();//定时发送锁状态
        TimerTask sendLockStateTask =new TimerTask(){
            @Override
            public void run() {
                SysConfig config = new SysConfig();
                config.setConfigKey("syCarPT");
                List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
                String syURL = "";
                if(sysConfigResult.size() == 0){
                    return;
                }else{
                    syURL = sysConfigResult.get(0).getConfigValue();
                }
                String passwordMd5 = DigestUtils.md5Hex(password);
                Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, userId);
                String sessionId = (String) LogInResult.get("sessionId");
                String finalSyURL = syURL;
                for (String key : ONLINE_USER_SESSIONS.keySet()){
                    Thread lockThread = new Thread(finalSyURL) {
                        @Override
                        public void run() {
                            String usersId = key.split("_")[0];
                            ardTankLockService.sendLockState(usersId,userId,password);
                        }
                    };
                    lockThread.start();
                }
            }
        };
        sendTimer.scheduleAtFixedRate(sendLockStateTask,date,3000);
    }
    /**
ard-work/src/main/java/com/ruoyi/sy/domain/ArdSyCar.java
@@ -6,6 +6,8 @@
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.util.List;
/**
 * 三一车辆对象 ard_sy_car
 * 
@@ -58,6 +60,8 @@
    @TableField("reserved_3")
    private String reserved3;
    private List<ArdTankLock> ardTankLockList;
    public void setId(String id) 
    {
@@ -150,6 +154,14 @@
        return reserved3;
    }
    public List<ArdTankLock> getArdTankLockList() {
        return ardTankLockList;
    }
    public void setArdTankLockList(List<ArdTankLock> ardTankLockList) {
        this.ardTankLockList = ardTankLockList;
    }
    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java
@@ -182,80 +182,66 @@
                            }
                            long cha = now.getTime() - sdf.parse(time).getTime();
                            System.out.println("////////////////");
                            /*System.out.println("////////////////");
                            System.out.println(time);
                            System.out.println(cha);
                            /*if(Math.abs(cha) >= 5 * 1000){
                            System.out.println(cha);*/
                            if(Math.abs(cha) >= 5 * 1000){
                                //时间校准
                                String url = "http://" + ip + ":9999";
                                /*String url = "http://" + ip + ":9999";
                                String passwordMd5 = DigestUtils.md5Hex(password);
                                Map<String, Object> LogInResult = loginIn(url, userId, passwordMd5);
                                String sessionId = (String) LogInResult.get("sessionId");
                                //获取时间并拆分年月日时分秒
                                String nowTime = sdf.format(now);
                                String nowYear = nowTime.substring(2,4);
                                System.out.println(nowYear);
                                String nowMonth = nowTime.substring(5,7);
                                System.out.println(nowMonth);
                                String nowDay = nowTime.substring(8,10);
                                System.out.println(nowDay);
                                String nowHour = nowTime.substring(11,13);
                                System.out.println(nowHour);
                                String nowMinute = nowTime.substring(14,16);
                                System.out.println(nowMinute);
                                String nowSecond = nowTime.substring(17,19);
                                System.out.println(nowSecond);
                                String nowYearHex = Integer.toHexString(Integer.parseInt(nowYear));
                                if(nowYearHex.length() == 1){
                                    nowYearHex = "0" + nowYearHex;
                                }
                                System.out.println(nowYearHex);
                                String nowMonthHex = Integer.toHexString(Integer.parseInt(nowMonth));
                                if(nowMonthHex.length() == 1){
                                    nowMonthHex = "0" + nowMonthHex;
                                }
                                System.out.println(nowMonthHex);
                                String nowDayHex = Integer.toHexString(Integer.parseInt(nowDay));
                                if(nowDayHex.length() == 1){
                                    nowDayHex = "0" + nowDayHex;
                                }
                                System.out.println(nowDayHex);
                                String nowHourHex = Integer.toHexString(Integer.parseInt(nowHour));
                                if(nowHourHex.length() == 1){
                                    nowHourHex = "0" + nowHourHex;
                                }
                                System.out.println(nowHourHex);
                                String nowMinuteHex = Integer.toHexString(Integer.parseInt(nowMinute));
                                if(nowMinuteHex.length() == 1){
                                    nowMinuteHex = "0" + nowMinuteHex;
                                }
                                System.out.println(nowMinuteHex);
                                String nowSecondHex = Integer.toHexString(Integer.parseInt(nowSecond));
                                if(nowSecondHex.length() == 1){
                                    nowSecondHex = "0" + nowSecondHex;
                                }
                                System.out.println(nowSecondHex);
                                //16进制时间
                                String timeHex = nowYearHex + nowMonthHex + nowDayHex + nowHourHex + nowMinuteHex + nowSecondHex;
                                System.out.println(timeHex);
                                String lockNumHead = ardTankLockResult.get(0).getLockNum().substring(0,2);
                                String lockNumTail = ardTankLockResult.get(0).getLockNum().substring(2,4);
                                //计算校验
                                String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt("08", 16) +
                                        Integer.parseInt(nowYearHex, 16) + Integer.parseInt(nowMonthHex, 16) + Integer.parseInt(nowDayHex, 16) +
                                        Integer.parseInt(nowHourHex, 16) + Integer.parseInt(nowMinuteHex, 16) + Integer.parseInt(nowSecondHex, 16));
                                System.out.println(checkNum);
                                if(checkNum.length() == 1){
                                    checkNum = "0" + checkNum;
                                }else if(checkNum.length() > 2){
                                    checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length());
                                }
                                System.out.println(checkNum);
                                String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "08" + timeHex + checkNum + "%22%7D";
                                System.out.println(ardTankLock.getLockNum() + "08" + timeHex + checkNum);
                                sendCmd(url,userId,ardTankLockResult.get(0).getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
                            }else{*/
                                sendCmd(url,userId,ardTankLockResult.get(0).getCarId(),199,"DataDownTransfer", paramsStr,sessionId);*/
                                return;
                            }else{
                                ArdTankLockState ardTankLockState = new ArdTankLockState();
                                ardTankLockState.setId(IdUtils.simpleUUID());
                                ardTankLockState.setLockId(ardTankLockResult.get(0).getId());
@@ -264,6 +250,7 @@
                                    case "01": ardTankLockState.setLockState("开锁状态");break;
                                    case "02": ardTankLockState.setLockState("关锁状态");break;
                                    case "03": ardTankLockState.setLockState("异常状态");break;
                                    case "04": ardTankLockState.setLockState("动作状态");break;
                                    default:
                                        break;
                                }
@@ -326,8 +313,7 @@
                                ardTankLockState.setUploadTime(time);
                                ardTankLockState.setUniqueMark(uniqueMark);
                                ((ArdTankLockStateServiceImpl)SpringUtils.getBean("ardTankLockStateServiceImpl")).insertOrUpdateArdTankLockState(ardTankLockState);
                            //}
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
ard-work/src/main/java/com/ruoyi/sy/service/IArdTankLockService.java
@@ -74,4 +74,6 @@
    public Map<String,Object> getLockByCarPlate(String usersId, String carPlate, Integer pageNum, Integer pageSize);
    public List<ArdTankLock> getArdTankLockAll();
    public void sendLockState(String userId,String syUserId,String syPassword);
}
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockServiceImpl.java
@@ -458,4 +458,23 @@
        List<ArdTankLock> result = ardTankLockMapper.getAll();
        return result;
    }
    @Override
    public void sendLockState(String userId, String syUserId, String syPassword) {
        /*List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT");
        String syURL = "";
        if(syURLResult.size() != 0){
            syURL = syURLResult.get(0).getConfigValue();
        }else{
            return;
        }
        String passwordMd5 = DigestUtils.md5Hex(syPassword);
        Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId);
        String sessionId = (String) LogInResult.get("sessionId");
        List<ArdTankLock> ardTankLockList = ardTankLockMapper.getLockByCarId(carId);
        Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, carId, ardSyUser.getUserId(), sessionId);*/
    }
}
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockStateServiceImpl.java
@@ -3,6 +3,8 @@
import java.util.List;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.sy.domain.ArdTankLock;
import com.ruoyi.sy.mapper.ArdTankLockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -24,6 +26,9 @@
public class ArdTankLockStateServiceImpl implements IArdTankLockStateService {
    @Resource
    private ArdTankLockStateMapper ardTankLockStateMapper;
    @Resource
    private ArdTankLockMapper ardTankLockMapper;
    /**
     * 查询罐车锁状态
@@ -95,6 +100,13 @@
    @Override
    public int insertOrUpdateArdTankLockState(ArdTankLockState ardTankLockState) {
        int result = ardTankLockStateMapper.insertOrUpdateArdTankLockState(ardTankLockState);
        return result;
        try{
            return result;
        }finally {
            ArdTankLock ardTankLock = new ArdTankLock();
            ardTankLock.setId(ardTankLockState.getLockId());
            ardTankLock.setOnlineTime(ardTankLockState.getUploadTime());
            ardTankLockMapper.updateArdTankLock(ardTankLock);//更改状态
        }
    }
}
ard-work/src/main/resources/mapper/sy/ArdSyCarMapper.xml
@@ -17,6 +17,30 @@
        <result property="reserved3"    column="reserved_3"    />
    </resultMap>
    <resultMap type="ArdSyCar" id="ArdSyCarLockResult">
        <result property="id"    column="id"    />
        <result property="carId"    column="car_id"    />
        <result property="carModel"    column="car_model"    />
        <result property="carType"    column="car_type"    />
        <result property="carBrand"    column="car_brand"    />
        <result property="deptId"    column="dept_id"    />
        <result property="carPicture"    column="car_picture"    />
        <result property="reserved1"    column="reserved_1"    />
        <result property="reserved2"    column="reserved_2"    />
        <result property="reserved3"    column="reserved_3"    />
        <collection property="ardTankLockList" ofType="com.ruoyi.sy.domain.ArdTankLock">
            <result property="id"    column="lid"    />
            <result property="lockNum"    column="lock_num"    />
            <result property="lockName"    column="lock_name"    />
            <result property="imgPositionTop"    column="img_position_top"    />
            <result property="imgPositionLeft"    column="img_position_left"    />
            <result property="carId"    column="lcar_id"    />
            <result property="enable"    column="enable"    />
            <result property="restartState"    column="restart_state"    />
            <result property="onlineTime"    column="online_time"    />
        </collection>
    </resultMap>
    <sql id="selectArdSyCarVo">
        select id, car_id, car_model, car_type, car_brand, dept_id, car_picture, reserved_1, reserved_2, reserved_3 from ard_sy_car
    </sql>