zhangnaisong
2024-07-20 adc9b922c116463d626d8b7094933278ad89e6df
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -1,7 +1,6 @@
package com.ruoyi.sy.controller;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.annotation.PostConstruct;
@@ -9,9 +8,18 @@
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.sy.domain.ArdTankLock;
import com.ruoyi.sy.gps31.PushClientImplSerialPort;
import com.ruoyi.sy.param.ArdSyCarParam;
import com.ruoyi.sy.service.IArdTankAbnormalParkAlarmService;
import com.ruoyi.sy.service.impl.ArdTankLockServiceImpl;
import com.ruoyi.sy.vo.ArdSyCarVo;
import com.ruoyi.sy.domain.ArdSyUser;
import com.ruoyi.sy.gps31.PositionContainer;
import com.ruoyi.sy.gps31.PushClientImplAlarm;
@@ -21,11 +29,13 @@
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.impl.SysConfigServiceImpl;
import com.ruoyi.utils.forest.SYClient;
import com.ruoyi.utils.result.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -36,12 +46,11 @@
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.service.IArdSyCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
 * 三一车辆Controller
 *
 *
 * @author ard
 * @date 2023-06-26
 */
@@ -68,22 +77,36 @@
    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private IArdTankAbnormalParkAlarmService ardTankAbnormalParkAlarmService;
    @Resource
    private SYClient sYClient;
    private ArdSyCarController ardSyCarController;
    @Value("${syCar.enabled}")
    private Boolean syCarEnabled;
    @Value("${syCar.userId}")
    private String userId;
    @Value("${syCar.password}")
    private String password;
    private Timer lockStateTimer;
    @PostConstruct
    public void init(){
        ardSyCarController = this;
        ardSyCarController.sysConfigService = this.sysConfigService;
        ardSyCarController.iArdSyUserService = this.iArdSyUserService;
        SysConfig config = new SysConfig();
        config.setConfigKey("syCarPT");
        List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
        String syURL = "";
        if(sysConfigResult.size() == 0){
        //if(sysConfigResult.size() == 0){
        if(!syCarEnabled){//三一车辆加入开关
            return;
        }else{
            syURL = sysConfigResult.get(0).getConfigValue();
@@ -95,7 +118,8 @@
        {
            return;
        }
        PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
        //PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
        PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,userId,password);
        Thread pushClientImplPositionThread = new Thread(pushClientImplPosition);
        pushClientImplPositionThread.start();
@@ -107,11 +131,72 @@
                ardSyCarService.sendArdSyCarPosition();
            }
        };
        carPositionTimer.scheduleAtFixedRate(carPositionTask,date,3*1000);//启用
        //车辆实时位置线程
        PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
        //carPositionTimer.scheduleAtFixedRate(carPositionTask,date,3*1000);//弃用
        //车辆实时报警线程
        //PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword());
        PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,userId,password);
        Thread pushClientImplAlarmThread = new Thread(pushClientImplAlarm);
        pushClientImplAlarmThread.start();
        //串口线程
        PushClientImplSerialPort pushClientImplSerialPort = new PushClientImplSerialPort(ip,userId,password);
        Thread pushClientImplSerialPortThread = new Thread(pushClientImplSerialPort);
        pushClientImplSerialPortThread.start();
        //删除结束时间为null的记录
        int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
        this.lockStateTimer = new Timer();//定时获取各个锁的状态
        TimerTask lockStateTask =new TimerTask(){
            @Override
            public void run(){
                Thread thread = new Thread(){
                    @Override
                    public void run() {
                        SysConfig config = new SysConfig();
                        config.setConfigKey("syCarPT");
                        List<SysConfig> sysConfigResult = ((SysConfigServiceImpl) SpringUtils.getBean("sysConfigServiceImpl")).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 = ((ArdTankLockServiceImpl)SpringUtils.getBean("ardTankLockServiceImpl")).getArdTankLockAll();//查询全部电磁锁
                        for(ArdTankLock ardTankLock : result){
                            Thread LockThread = new Thread(finalSyURL){
                                @Override
                                public void run() {
                                    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("01", 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() + "01" + checkNum + "%22%7D";
                                    sYClient.sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId);
                                }
                            };
                            LockThread.start();
                        }
                    }
                };
                thread.start();
            }
        };
        //lockStateTimer.scheduleAtFixedRate(lockStateTask,date,1000);
    }
    /**
@@ -119,11 +204,13 @@
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArdSyCar ardSyCar)
    @ApiOperation("查询三一车辆列表")
    public AjaxResult list(ArdSyCarParam ardSyCarParam)
    {
        startPage();
        List<ArdSyCar> list = ardSyCarService.selectArdSyCarList(ardSyCar);
        return getDataTable(list);
        PageHelper.startPage(ardSyCarParam.getPageNum(),ardSyCarParam.getPageSize());
        String userId = SecurityUtils.getUserId();
        Map<String,Object> result = ardSyCarService.getArdSyCarAll(userId);
        return ardSyCarService.ardSyCarList(ardSyCarParam,result);
    }
    /**
@@ -180,7 +267,7 @@
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:remove')")
    @Log(title = "三一车辆", businessType = BusinessType.DELETE)
   @DeleteMapping("/{ids}")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除三一车辆")
    public AjaxResult remove(@PathVariable String[] ids)
    {
@@ -285,7 +372,11 @@
        String usersId = SecurityUtils.getUserId();
        ArdSyUser ardSyUser = iArdSyUserService.userById(usersId);
        String syURL = sysConfigService.getSYURL();
        return ardSyCarService.allListByUser(ardSyUser,syURL,usersId);
        //根据userId查询部门Id
        SysUser sysUser = sysUserService.selectUserById(usersId);
        //根据当前deptId或者当前及所属下级的所有deptId
        List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId());
        return ardSyCarService.allListByUser(ardSyUser,syURL,usersId,deptList);
    }
    @PreAuthorize("@ss.hasPermi('sy:syCar:carList')")
@@ -314,7 +405,7 @@
        }
    }
//    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
    //    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
    @PostMapping("/carListById/{id}")
    @ApiOperation("根据车辆ID获取车辆列表")
    public Results carListById(@PathVariable String id){
@@ -357,7 +448,7 @@
        SysUser sysUser = sysUserService.selectUserById(usersId);
        Map<String, Map<String,Map<String,Object>>> deptPositionMap = PositionContainer.getDeptPositionMap();
        if(deptPositionMap.isEmpty()){
            return Results.succeed();
            return Results.error("31平台无车辆位置返回");
        }else {
//            return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString()).get(map.get("carId")));
            return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString()));
@@ -448,7 +539,7 @@
    @GetMapping("getThreeOne")
    @ApiOperation("获取三一视频地址")
    public AjaxResult getThreeOne() {
        return AjaxResult.success("获取地址成功!",sysConfigService.selectConfigByKey("threeOneVideo"));
        return AjaxResult.success("获取地址成功!",sysConfigService.getSYVideo());
    }
    @PreAuthorize("@ss.hasPermi('sy:syCar:getAlarmHPfmCountDetail')")
@@ -466,4 +557,17 @@
        return AjaxResult.success(mapDetail);
    }
    @GetMapping("/getOnlineSYCarPosition")
    @ApiOperation("单兵端查看已通过审批的在线三一车辆位置")
    public AjaxResult getOnlineSYCarPosition() {
        String soilderId = SecurityUtils.getUserId();
        try{
            Map<String,Object> result = ardSyCarService.getOnlineSYCarPosition(soilderId);
            return AjaxResult.success(result);
        }catch(Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}