zhangnaisong
2024-01-24 15a51e0af4a4864fcf30ebd927864147e278181a
ard-work/src/main/java/com/ruoyi/app/application/service/impl/ArdAppApplicationServiceImpl.java
@@ -14,6 +14,7 @@
import com.ruoyi.app.application.domain.ArdAppApplication;
import com.ruoyi.app.application.service.IArdAppApplicationService;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
@@ -28,6 +29,48 @@
    private ArdAppApplicationMapper ardAppApplicationMapper;
    private Map<String,Thread> threadMap = new HashMap();
    @PostConstruct
    public void init(){
        ArdAppApplication para = new ArdAppApplication();
        para.setState("1");//查询同意的申请
        List<ArdAppApplication> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationList(para);
        Date date = new Date();
        Long now = date.getTime();
        for(ArdAppApplication ardAppApplication : ardAppApplicationList){
            Long begin = Long.parseLong(ardAppApplication.getBegin());
            //判断是否超时
            if(now - begin <= 24*60*60*1000){//未超时从新创建线程
                String key = ardAppApplication.getCommanderId() + "," + ardAppApplication.getSoilderId() + "," + ardAppApplication.getApplicationType();
                Thread thread = new Thread(key){//创建线程计时剩余时长
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(24*60*60*1000 - (now - begin));//剩余时长
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            return;
                        }
                        Thread currentThread = Thread.currentThread();
                        String state = "000";//state为000,即超时
                        String commanderId = currentThread.getName().split(",")[0];
                        String soilderId = currentThread.getName().split(",")[1];
                        String applicationType = currentThread.getName().split(",")[2];
                        int result = ardAppApplicationMapper.updateArdAppApplicationBeginByCommanderIdAndSoilderIdAndType(commanderId,soilderId,applicationType,"",state);
                        threadMap.remove(currentThread.getName());
                    }
                };
                thread.start();
                this.threadMap.put(key,thread);
            }else{//超时更改状态
                String state = "000";//state为000,即超时
                String commanderId = ardAppApplication.getCommanderId();
                String soilderId = ardAppApplication.getSoilderId();
                String applicationType = ardAppApplication.getApplicationType();
                int result = ardAppApplicationMapper.updateArdAppApplicationBeginByCommanderIdAndSoilderIdAndType(commanderId,soilderId,applicationType,"",state);
            }
        }
    }
    /**
     * 查询单兵端申请查看指挥端位置或三一车辆位置
@@ -146,8 +189,8 @@
    @Override
    public Map<String, List<Map<String, Object>>> getCheckPosition(String usersId) {
        Map<String, List<Map<String, Object>>> result = new HashMap();
        //查看指挥端位置申请
        List<Map<String,Object>> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationByCommanderId(usersId);
        //查看指挥端位置申请
        List<Map<String, Object>> resultCommanderPosition = new ArrayList();
        for(Map<String, Object> map : ardAppApplicationList){
            if(((String)map.get("applicationType")).equals("Commander")){
@@ -214,4 +257,38 @@
        }
        return 0;
    }
    @Override
    public Map<String, List<Map<String, Object>>> getCheckPositionTrue(String commanderId) {
        Map<String, List<Map<String, Object>>> result = new HashMap();
        List<Map<String,Object>> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationByCommanderIdTrue(commanderId);
        Date date = new Date();
        //查看指挥端位置申请
        List<Map<String, Object>> resultCommanderPosition = new ArrayList();
        for(Map<String, Object> map : ardAppApplicationList){
            Long interval = date.getTime() - Long.parseLong((String)map.get("begin"));
            interval = 24 * 60 * 60 * 1000 - interval;
            Long hour = interval / (60 * 60 * 1000);
            Long min = (interval - hour * 60 * 60 * 1000) / (60 * 1000);
            map.put("time",hour + "时" + min + "分");
            if(((String)map.get("applicationType")).equals("Commander")){
                resultCommanderPosition.add(map);
            }
        }
        //查看车辆位置申请
        List<Map<String, Object>> resultSYCarsPosition = new ArrayList();
        for(Map<String, Object> map : ardAppApplicationList){
            Long interval = date.getTime() - Long.parseLong((String)map.get("begin"));
            interval = 24 * 60 * 60 * 1000 - interval;
            Long hour = interval / (60 * 60 * 1000);
            Long min = (interval - hour * 60 * 60 * 1000) / (60 * 1000);
            map.put("time",hour + "时" + min + "分");
            if(((String)map.get("applicationType")).equals("SYCar")){
                resultSYCarsPosition.add(map);
            }
        }
        result.put("commander",resultCommanderPosition);
        result.put("SYCars",resultSYCarsPosition);
        return result;
    }
}