90 lines
4.4 KiB
Plaintext
90 lines
4.4 KiB
Plaintext
package com.sercurityControl.proteam.util;
|
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 计算站班会开工时长
|
|
*/
|
|
public class CountWorkTimeUtil {
|
|
|
|
/**
|
|
* @return double
|
|
* @author cw chen
|
|
* @description 计算站班会开工时长
|
|
* @Param list 3完工 2暂停 1完工
|
|
* @date 2023-04-23 9:31
|
|
*/
|
|
public static Double countWorkTime(String sgStatus, String startTime, List<Map<String, Object>> list) throws Exception {
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
BigDecimal workTime = new BigDecimal(new Double(0).toString());
|
|
String nowTime = DateTimeHelper.getNowTime();
|
|
for (int i = 0; i < list.size(); i++) {
|
|
int type = Integer.parseInt(String.valueOf(list.get(i).get("type")));
|
|
if ((type == 3 && i == 0) || (type == 2 && i == 0)) {
|
|
Double time = DateTimeHelper.getTimeHours(String.valueOf(list.get(i).get("time")), startTime);
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time);
|
|
workTime = workTime.add(bigDecimal);
|
|
continue;
|
|
} else if (type == 1 && i == 0) {
|
|
Double time = DateTimeHelper.getTimeHours(nowTime, String.valueOf(list.get(i).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time);
|
|
workTime = workTime.add(bigDecimal);
|
|
continue;
|
|
} else if ((type == 3 && i != 0) || (type == 2 && i != 0)) {
|
|
int lastType = Integer.parseInt(String.valueOf(list.get(i - 1).get("type")));
|
|
if (lastType == 1) {
|
|
if (compareTime()) {
|
|
Double time = DateTimeHelper.getTimeHours(nowTime, String.valueOf(list.get(i).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time);
|
|
workTime = workTime.subtract(bigDecimal);
|
|
continue;
|
|
} else {
|
|
Double time = DateTimeHelper.getTimeHours(DateTimeHelper.getNowDate() + " 21:00:00", String.valueOf(list.get(i).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time);
|
|
workTime = workTime.subtract(bigDecimal);
|
|
continue;
|
|
}
|
|
} else if (lastType == 2 || lastType == 3) {
|
|
continue;
|
|
}
|
|
} else if (type == 1 && i != 0) {
|
|
int lastType = Integer.parseInt(String.valueOf(list.get(i - 1).get("type")));
|
|
if (lastType == 1) {
|
|
Double time = DateTimeHelper.getTimeHours(String.valueOf(list.get(i).get("time")), String.valueOf(list.get(i - 1).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time);
|
|
workTime = workTime.subtract(bigDecimal);
|
|
} else if (lastType == 2) {
|
|
if (compareTime()) {
|
|
Double time2 = DateTimeHelper.getTimeHours(nowTime, String.valueOf(list.get(i).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time2);
|
|
workTime = workTime.add(bigDecimal);
|
|
} else if (!compareTime()) {
|
|
Double time2 = DateTimeHelper.getTimeHours(DateTimeHelper.getNowDate() + " 21:00:00", String.valueOf(list.get(i).get("time")));
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(time2);
|
|
workTime = workTime.add(bigDecimal);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return workTime.doubleValue();
|
|
}
|
|
return new Double(0);
|
|
}
|
|
|
|
public static boolean compareTime() throws Exception {
|
|
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
String nowDate = DateTimeHelper.getNowDate() + " 21:00:00";
|
|
String nowTime = DateTimeHelper.getNowTime();
|
|
long time = simpleFormat.parse(nowDate).getTime();
|
|
long time2 = simpleFormat.parse(nowTime).getTime();
|
|
return time > time2;
|
|
}
|
|
}
|