package com.ruoyi.app.application.service.impl;
|
|
import java.util.*;
|
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
import com.ruoyi.common.utils.uuid.IdUtils;
|
import com.ruoyi.system.mapper.SysRoleMapper;
|
import com.ruoyi.utils.websocket.util.WebSocketUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.app.application.mapper.ArdAppApplicationMapper;
|
import com.ruoyi.app.application.domain.ArdAppApplication;
|
import com.ruoyi.app.application.service.IArdAppApplicationService;
|
|
import javax.annotation.PostConstruct;
|
import javax.annotation.Resource;
|
import javax.websocket.Session;
|
|
import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
|
|
/**
|
* 单兵端申请查看指挥端位置或三一车辆位置Service业务层处理
|
*
|
* @author ard
|
* @date 2024-01-25
|
*/
|
@Service
|
public class ArdAppApplicationServiceImpl implements IArdAppApplicationService {
|
@Resource
|
private ArdAppApplicationMapper ardAppApplicationMapper;
|
|
@Resource
|
private SysRoleMapper sysRoleMapper;
|
|
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);
|
}
|
}
|
}
|
|
/**
|
* 查询单兵端申请查看指挥端位置或三一车辆位置
|
*
|
* @param soilderId 单兵端申请查看指挥端位置或三一车辆位置主键
|
* @return 单兵端申请查看指挥端位置或三一车辆位置
|
*/
|
@Override
|
public ArdAppApplication selectArdAppApplicationBySoilderId(String soilderId) {
|
return ardAppApplicationMapper.selectArdAppApplicationBySoilderId(soilderId);
|
}
|
|
/**
|
* 查询单兵端申请查看指挥端位置或三一车辆位置列表
|
*
|
* @param ardAppApplication 单兵端申请查看指挥端位置或三一车辆位置
|
* @return 单兵端申请查看指挥端位置或三一车辆位置
|
*/
|
@Override
|
public List<ArdAppApplication> selectArdAppApplicationList(ArdAppApplication ardAppApplication) {
|
return ardAppApplicationMapper.selectArdAppApplicationList(ardAppApplication);
|
}
|
|
/**
|
* 新增单兵端申请查看指挥端位置或三一车辆位置
|
*
|
* @param ardAppApplication 单兵端申请查看指挥端位置或三一车辆位置
|
* @return 结果
|
*/
|
@Override
|
public int insertArdAppApplication(ArdAppApplication ardAppApplication) {
|
return ardAppApplicationMapper.insertArdAppApplication(ardAppApplication);
|
}
|
|
/**
|
* 修改单兵端申请查看指挥端位置或三一车辆位置
|
*
|
* @param ardAppApplication 单兵端申请查看指挥端位置或三一车辆位置
|
* @return 结果
|
*/
|
@Override
|
public int updateArdAppApplication(ArdAppApplication ardAppApplication) {
|
return ardAppApplicationMapper.updateArdAppApplication(ardAppApplication);
|
}
|
|
/**
|
* 批量删除单兵端申请查看指挥端位置或三一车辆位置
|
*
|
* @param soilderIds 需要删除的单兵端申请查看指挥端位置或三一车辆位置主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdAppApplicationBySoilderIds(String[] soilderIds) {
|
return ardAppApplicationMapper.deleteArdAppApplicationBySoilderIds(soilderIds);
|
}
|
|
/**
|
* 删除单兵端申请查看指挥端位置或三一车辆位置信息
|
*
|
* @param soilderId 单兵端申请查看指挥端位置或三一车辆位置主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdAppApplicationBySoilderId(String soilderId) {
|
return ardAppApplicationMapper.deleteArdAppApplicationBySoilderId(soilderId);
|
}
|
|
@Override
|
public int sendCheckCommandersPosition(String usersId, Map<String, Object> para) {
|
String reason = (String) para.get("reason");
|
List<String> usersIdList = (List<String>) para.get("usersIdList");
|
int result = 0;
|
for(String commanderId : usersIdList){
|
ArdAppApplication ardAppApplication = new ArdAppApplication();
|
ardAppApplication.setCommanderId(commanderId);
|
ardAppApplication.setSoilderId(usersId);
|
ardAppApplication.setReason(reason);
|
ardAppApplication.setApplicationType("Commander");
|
ardAppApplication.setBegin("");
|
ardAppApplication.setState("0");
|
ardAppApplication.setSoilderCheck("true");//指挥端未审批也设为true,不需要单兵端查看
|
int resultSingle = ardAppApplicationMapper.updateArdAppApplicationByCommanderIdAndSoilderIdAndType(ardAppApplication);
|
result = result + resultSingle;
|
if(resultSingle == 0){
|
ardAppApplication.setApplicationId(IdUtils.simpleUUID());
|
resultSingle = ardAppApplicationMapper.insertArdAppApplication(ardAppApplication);
|
result = result + resultSingle;
|
}
|
}
|
return result;
|
}
|
|
@Override
|
public int sendCheckSYCarsPosition(String usersId, Map<String, Object> para) {
|
String reason = (String) para.get("reason");
|
List<String> usersIdList = (List<String>) para.get("usersIdList");
|
int result = 0;
|
for(String commanderId : usersIdList){
|
ArdAppApplication ardAppApplication = new ArdAppApplication();
|
ardAppApplication.setCommanderId(commanderId);
|
ardAppApplication.setSoilderId(usersId);
|
ardAppApplication.setReason(reason);
|
ardAppApplication.setApplicationType("SYCar");
|
ardAppApplication.setBegin("");
|
ardAppApplication.setState("0");
|
ardAppApplication.setSoilderCheck("true");//指挥端未审批也设为true,不需要单兵端查看
|
int resultSingle = ardAppApplicationMapper.updateArdAppApplicationByCommanderIdAndSoilderIdAndType(ardAppApplication);
|
result = result + resultSingle;
|
if(resultSingle == 0){
|
ardAppApplication.setApplicationId(IdUtils.simpleUUID());
|
resultSingle = ardAppApplicationMapper.insertArdAppApplication(ardAppApplication);
|
result = result + resultSingle;
|
}
|
//加入给pc端websocket转发
|
List<SysRole> sysRoleList = sysRoleMapper.selectRolePermissionByUserId(commanderId);
|
for(SysRole sysRole : sysRoleList){
|
if(!sysRole.getRoleKey().equals("appLeader")){
|
Map<String,Object> resultMap = ardAppApplicationMapper.selectSYCarApplicationByPCIdAndSoilderId(commanderId,usersId);
|
Map<String,Map<String,Object>> msg = new HashMap();
|
msg.put("60000",resultMap);
|
for(String id : ONLINE_USER_SESSIONS.keySet()){
|
if(id.startsWith(commanderId)){
|
Session session = ONLINE_USER_SESSIONS.get(id);
|
WebSocketUtils.sendMessage(session,msg);
|
break;
|
}
|
}
|
break;//一个pc端用户可能挂接多个角色,每个pc端只转发一次
|
}
|
}
|
}
|
return result;
|
}
|
|
@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")){
|
resultCommanderPosition.add(map);
|
}
|
}
|
//查看车辆位置申请
|
List<Map<String, Object>> resultSYCarsPosition = new ArrayList();
|
for(Map<String, Object> map : ardAppApplicationList){
|
if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}
|
result.put("commander",resultCommanderPosition);
|
result.put("SYCars",resultSYCarsPosition);
|
return result;
|
}
|
|
@Override
|
public int approvalCheckPosition(String commanderId, Map<String, String> para) {
|
String applicationType = para.get("applicationType");
|
String soilderId = para.get("soilderId");
|
String state = para.get("state");
|
String begin = "";
|
if(state.equals("1")){//state为1,即同意
|
begin = String.valueOf(new Date().getTime());//设置开始时间
|
int result = ardAppApplicationMapper.updateArdAppApplicationBeginByCommanderIdAndSoilderIdAndType(commanderId,soilderId,applicationType,begin,state);
|
String key = commanderId + "," + soilderId + "," + applicationType;
|
Thread thread = new Thread(key){//创建线程计时24小时
|
@Override
|
public void run() {
|
try {
|
Thread.sleep(24*60*60*1000);
|
//Thread.sleep(3*60*1000);
|
} 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);
|
return result;
|
}else if(state.equals("-1")){//state为1,即驳回
|
int result = ardAppApplicationMapper.updateArdAppApplicationBeginByCommanderIdAndSoilderIdAndType(commanderId,soilderId,applicationType,"",state);
|
return result;
|
}else if(state.equals("00")){//state为00,即撤销
|
String key = commanderId + "," + soilderId + "," + applicationType;
|
try{
|
this.threadMap.get(key).interrupt();//撤销后线程销毁
|
}catch(Exception e){
|
e.printStackTrace();
|
}
|
this.threadMap.remove(key);
|
int result = ardAppApplicationMapper.updateArdAppApplicationBeginByCommanderIdAndSoilderIdAndType(commanderId,soilderId,applicationType,"",state);
|
return result;
|
}
|
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();
|
//查看车辆位置申请
|
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);
|
Long second = (interval - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000;
|
map.put("time",hour + "时" + min + "分" + second + "秒");
|
if(((String)map.get("applicationType")).equals("Commander")){
|
resultCommanderPosition.add(map);
|
}else if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}
|
result.put("commander",resultCommanderPosition);
|
result.put("SYCars",resultSYCarsPosition);
|
return result;
|
}
|
|
@Override
|
public Map<String, List<Map<String, Object>>> getSendPositionTrue(String soilderId) {
|
Map<String, List<Map<String, Object>>> result = new HashMap();
|
List<Map<String,Object>> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationBySoilderIdTrue(soilderId);
|
Date date = new Date();
|
//查看指挥端位置申请
|
List<Map<String, Object>> resultCommanderPosition = new ArrayList();
|
//查看车辆位置申请
|
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);
|
Long second = (interval - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000;
|
map.put("time",hour + "时" + min + "分" + second + "秒");
|
if(((String)map.get("applicationType")).equals("Commander")){
|
resultCommanderPosition.add(map);
|
}else if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}
|
result.put("commander",resultCommanderPosition);
|
result.put("SYCars",resultSYCarsPosition);
|
return result;
|
}
|
|
@Override
|
public Map<String, List<Map<String, Object>>> getCheckPositionOwn(String soilderId) {
|
Map<String, List<Map<String, Object>>> result = new HashMap();
|
List<Map<String,Object>> ardAppApplicationList = ardAppApplicationMapper.selectArdAppApplicationBySoilderIdFalse(soilderId);
|
Date date = new Date();
|
//查看指挥端位置申请
|
List<Map<String, Object>> resultCommanderPosition = new ArrayList();
|
//查看车辆位置申请
|
List<Map<String, Object>> resultSYCarsPosition = new ArrayList();
|
for(Map<String, Object> map : ardAppApplicationList){
|
/*if(((String)map.get("state")).equals("1")){
|
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);
|
}else if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}else{
|
map.put("time","");
|
if(((String)map.get("applicationType")).equals("Commander")){
|
resultCommanderPosition.add(map);
|
}else if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}*/
|
if(((String)map.get("applicationType")).equals("Commander")){
|
resultCommanderPosition.add(map);
|
}else if(((String)map.get("applicationType")).equals("SYCar")){
|
resultSYCarsPosition.add(map);
|
}
|
}
|
result.put("commander",resultCommanderPosition);
|
result.put("SYCars",resultSYCarsPosition);
|
return result;
|
}
|
|
@Override
|
public int approvalCheckPositionOwn(String soilderId, Map<String, String> para) {
|
String applicationType = para.get("applicationType");
|
String commanderId = para.get("commanderId");
|
int result = ardAppApplicationMapper.updateSoilderCheckByCommanderIdAndSoilderIdAndType(soilderId,commanderId,applicationType);
|
return result;
|
}
|
}
|