237 lines
11 KiB
Plaintext
237 lines
11 KiB
Plaintext
package com.sercurityControl.proteam.dutyTask.service;
|
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
|
import com.sercurityControl.proteam.dutyTask.domain.*;
|
|
import com.sercurityControl.proteam.dutyTask.mapper.BallStatusStatisticMapper;
|
|
import com.sercurityControl.proteam.dutyTask.mapper.TodayTaskMapper;
|
|
import com.sercurityControl.proteam.util.CountWorkTimeUtil;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.text.DecimalFormat;
|
|
import java.text.ParseException;
|
|
import java.util.*;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.Future;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 球机运行状态业务逻辑层
|
|
*/
|
|
@Service(value = "BallStatusStatisticService")
|
|
public class BallStatusStatisticServiceImpl implements BallStatusStatisticService {
|
|
@Resource(name = "testTaskExecutor")
|
|
private ThreadPoolTaskExecutor testTaskExecutor;
|
|
|
|
@Resource(name = "BallStatusStatisticMapper")
|
|
private BallStatusStatisticMapper mapper;
|
|
|
|
@Resource(name = "TodayTaskMapper")
|
|
private TodayTaskMapper todayTaskMapper;
|
|
|
|
@Override
|
|
public PageInfo<BallStatusStatisticEntity> getBallKjList(BallStatusStatisticEntity entity) throws Exception {
|
|
// 多线程执行操作,存放的数据集合
|
|
List<Future> futureList = new ArrayList<>();
|
|
List<BallStatusStatisticEntity> newList = new ArrayList<>();
|
|
List<BallStatusStatisticEntity> list = mapper.getBallKjList(entity);
|
|
PageInfo<BallStatusStatisticEntity> pageInfo = new PageInfo<>(list);
|
|
for (BallStatusStatisticEntity vo : list) {
|
|
Future<BallStatusStatisticEntity> future = testTaskExecutor.submit(new Callable<BallStatusStatisticEntity>() {
|
|
@Override
|
|
public BallStatusStatisticEntity call() throws Exception {
|
|
// 球机总数、今日开机数、今日未开机数量
|
|
int num = mapper.getBallNum(vo.getOrgId(), 1);
|
|
int num2 = mapper.getBallNum(vo.getOrgId(), 2);
|
|
vo.setBallNum(num);
|
|
vo.setBallOnNum(num2);
|
|
vo.setBallOffNum(num - num2);
|
|
vo.setRate(countRate(num2, num));
|
|
return vo;
|
|
}
|
|
});
|
|
futureList.add(future);
|
|
}
|
|
for (Future<BallStatusStatisticEntity> future : futureList) {
|
|
BallStatusStatisticEntity vo = future.get();
|
|
newList.add(vo);
|
|
}
|
|
pageInfo.setList(newList);
|
|
return pageInfo;
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<BallStatusDetailEntity> getBallOffLineList(BallStatusDetailEntity entity) {
|
|
if (StringUtils.isNotBlank(entity.getRiskLevel())) {
|
|
String[] riskLevelArr = entity.getRiskLevel().split(",");
|
|
List<String> riskLevelList = Arrays.asList(riskLevelArr);
|
|
entity.setRiskLevelList(riskLevelList);
|
|
}
|
|
List<BallStatusDetailEntity> list = mapper.getBallOffLineList(entity);
|
|
PageInfo<BallStatusDetailEntity> pageInfo = new PageInfo<>(list);
|
|
return pageInfo;
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<BallOnlineStatisticEntity> getBallHgList(BallOnlineStatisticEntity entity) throws Exception {
|
|
// 多线程执行操作,存放的数据集合
|
|
List<Future> futureList = new ArrayList<>();
|
|
List<BallOnlineStatisticEntity> newList = new ArrayList<>();
|
|
List<BallOnlineStatisticEntity> list = mapper.getBallHgList(entity);
|
|
PageInfo<BallOnlineStatisticEntity> pageInfo = new PageInfo<>(list);
|
|
for (BallOnlineStatisticEntity vo : list) {
|
|
Future<BallOnlineStatisticEntity> future = testTaskExecutor.submit(new Callable<BallOnlineStatisticEntity>() {
|
|
@Override
|
|
public BallOnlineStatisticEntity call() throws Exception {
|
|
// 根据地市获取站班会(绑定球机)
|
|
List<Map<String, Object>> list2 = mapper.getClassByOrg(vo.getOrgId());
|
|
vo.setBallNum(list2 == null ? 0 : list2.size());
|
|
Map<String, Object> map = heNum(list2);
|
|
vo.setBallTimeHgNum((Integer) map.get("heNum"));
|
|
vo.setBallTimeBhgNum(list2 == null ? 0 : list2.size() - (Integer) map.get("heNum"));
|
|
vo.setRate(countRate((Integer) map.get("heNum"), list == null ? 0 : list2.size()));
|
|
vo.setClassIdList((List<String>) map.get("classIdList"));
|
|
return vo;
|
|
}
|
|
});
|
|
futureList.add(future);
|
|
}
|
|
for (Future<BallOnlineStatisticEntity> future : futureList) {
|
|
BallOnlineStatisticEntity vo = future.get();
|
|
newList.add(vo);
|
|
}
|
|
List<BallOnlineStatisticEntity> sortList = newList.stream().sorted(Comparator.comparing(BallOnlineStatisticEntity::getBallTimeHgNum).reversed()).collect(Collectors.toList());
|
|
pageInfo.setList(sortList);
|
|
return pageInfo;
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<BallOnlineDetailEntity> getBallBhgDetailList(BallOnlineDetailEntity entity) throws Exception {
|
|
if (StringUtils.isNotBlank(entity.getRiskLevel())) {
|
|
String[] riskLevelArr = entity.getRiskLevel().split(",");
|
|
List<String> riskLevelList = Arrays.asList(riskLevelArr);
|
|
entity.setRiskLevelList(riskLevelList);
|
|
}
|
|
if (StringUtils.isNotBlank(entity.getId())) {
|
|
String[] classIdArr = entity.getId().split(",");
|
|
List<String> classIdList = Arrays.asList(classIdArr);
|
|
entity.setClassIdList(classIdList);
|
|
}
|
|
// 多线程执行操作,存放的数据集合
|
|
List<Future> futureList = new ArrayList<>();
|
|
List<BallOnlineDetailEntity> newList = new ArrayList<>();
|
|
List<BallOnlineDetailEntity> list = mapper.getBallBhgDetailList(entity);
|
|
PageInfo<BallOnlineDetailEntity> pageInfo = new PageInfo<>(list);
|
|
for (BallOnlineDetailEntity vo : list) {
|
|
Future<BallOnlineDetailEntity> future = testTaskExecutor.submit(new Callable<BallOnlineDetailEntity>() {
|
|
@Override
|
|
public BallOnlineDetailEntity call() throws Exception {
|
|
Map<String, Object> map = getWorkAndOnlineTime(vo);
|
|
vo.setKgTime(map.get("workHours").toString());
|
|
vo.setBallOnlineTime(map.get("ballTime").toString());
|
|
return vo;
|
|
}
|
|
});
|
|
futureList.add(future);
|
|
}
|
|
for (Future<BallOnlineDetailEntity> future : futureList) {
|
|
BallOnlineDetailEntity vo = future.get();
|
|
newList.add(vo);
|
|
}
|
|
pageInfo.setList(newList);
|
|
return pageInfo;
|
|
}
|
|
|
|
/**
|
|
* @return java.lang.String
|
|
* @author cw chen
|
|
* @description 计算占比率
|
|
* @Param num
|
|
* @Param totalNum
|
|
* @date 2023-04-21 16:47
|
|
*/
|
|
public static String countRate(Integer num, Integer totalNum) {
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
if (totalNum == 0 || num == 0) {
|
|
return "0%";
|
|
} else if (totalNum.equals(num)) {
|
|
return "100%";
|
|
} else {
|
|
return decimalFormat.format(num * 1.0 / totalNum * 1.0);
|
|
}
|
|
}
|
|
|
|
public Map<String, Object> heNum(List<Map<String, Object>> list) throws Exception {
|
|
int heNum = 0;
|
|
List<String> classIdList = new ArrayList<>();
|
|
HashMap<String, Object> map1 = new HashMap<>(16);
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
for (Map<String, Object> map : list) {
|
|
String classId = (String) map.get("classId");
|
|
String puid = (String) map.get("puid");
|
|
String workDay = (String) map.get("workDay");
|
|
String startTime = (String) map.get("startTime");
|
|
String sgStatus = (String) map.get("sgStatus");
|
|
List<Map<String, Object>> workHoursList = todayTaskMapper.getWorkHours(classId, workDay);
|
|
List<Map<String, String>> timeList = todayTaskMapper.getTime(puid, workDay);
|
|
Double workHours = CountWorkTimeUtil.countWorkTime(sgStatus, startTime, workHoursList);
|
|
Double ballTime = getBallTime(timeList);
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(workHours);
|
|
BigDecimal bigDecimal2 = BigDecimal.valueOf(ballTime);
|
|
if (bigDecimal.subtract(bigDecimal2).doubleValue() <= 0.5) {
|
|
heNum++;
|
|
} else {
|
|
classIdList.add(classId);
|
|
}
|
|
}
|
|
}
|
|
map1.put("heNum", heNum);
|
|
map1.put("classIdList", classIdList);
|
|
return map1;
|
|
}
|
|
|
|
public Map<String, Object> getWorkAndOnlineTime(BallOnlineDetailEntity vo) throws Exception {
|
|
HashMap<String, Object> map1 = new HashMap<>(16);
|
|
Double workHours = new Double(0);
|
|
Double ballTime = new Double(0);
|
|
String classId = vo.getClassId();
|
|
String puid = vo.getPuid();
|
|
String workDay = vo.getWorkDay();
|
|
String startTime = vo.getStartTime();
|
|
String sgStatus = vo.getSgStatus();
|
|
List<Map<String, Object>> workHoursList = todayTaskMapper.getWorkHours(classId, workDay);
|
|
List<Map<String, String>> timeList = todayTaskMapper.getTime(puid, workDay);
|
|
workHours = CountWorkTimeUtil.countWorkTime(sgStatus, startTime, workHoursList);
|
|
ballTime = getBallTime(timeList);
|
|
map1.put("workHours", workHours);
|
|
map1.put("ballTime", ballTime);
|
|
return map1;
|
|
}
|
|
|
|
public static Double getBallTime(List<Map<String, String>> list) throws ParseException {
|
|
BigDecimal ballTime = new BigDecimal(new Double(0).toString());
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
for (Map<String, String> map : list) {
|
|
String upTime = map.get("upTime");
|
|
String downTime = map.get("downTime");
|
|
if (StringUtils.isNotBlank(downTime)) {
|
|
Double timeHours = DateTimeHelper.getTimeHours(downTime, upTime);
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(timeHours);
|
|
ballTime = ballTime.add(bigDecimal);
|
|
} else {
|
|
Double timeHours = DateTimeHelper.getTimeHours(DateTimeHelper.getNowTime(), upTime);
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(timeHours);
|
|
ballTime = ballTime.add(bigDecimal);
|
|
}
|
|
}
|
|
}
|
|
return ballTime.doubleValue();
|
|
}
|
|
|
|
}
|