package com.qianwen.smartman.modules.mdc.service.impl; import java.math.BigDecimal; import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time.chrono.ChronoLocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.qianwen.core.excel.util.ExcelUtil; import com.qianwen.core.mp.base.BaseEntity; import com.qianwen.core.oss.model.BladeFile; import com.qianwen.core.tool.utils.DateUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.cache.cps.WorkstationCache; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.DateConstant; import com.qianwen.smartman.common.constant.ExcelConstant; import com.qianwen.smartman.common.constant.MdcConstant; import com.qianwen.smartman.common.utils.CommonUtil; import com.qianwen.smartman.common.utils.ListUtils; import com.qianwen.smartman.common.utils.LocalDateTimeUtils; import com.qianwen.smartman.modules.smis.entity.GlobalWcs; import com.qianwen.smartman.modules.smis.entity.Workstation; import com.qianwen.smartman.modules.smis.enums.WorkstationTypeEnum; import com.qianwen.smartman.modules.smis.service.IWorkstationService; import com.qianwen.smartman.modules.mdc.convert.StatusRecordConvert; import com.qianwen.smartman.modules.mdc.dto.GroupWorkDTO; import com.qianwen.smartman.modules.mdc.dto.ShiftIndexNameDTO; import com.qianwen.smartman.modules.mdc.entity.SuperAggregateState; import com.qianwen.smartman.modules.mdc.enums.ProductivityTypeEnum; import com.qianwen.smartman.modules.mdc.excel.StatusRecordExport; import com.qianwen.smartman.modules.mdc.service.IStatusRecordService; import com.qianwen.smartman.modules.mdc.service.ISuperAggregateStateService; import com.qianwen.smartman.modules.mdc.service.ITimeUsedAnalysisService; import com.qianwen.smartman.modules.mdc.utils.EifficiencyUtils; import com.qianwen.smartman.modules.mdc.vo.ChartDataVO; import com.qianwen.smartman.modules.mdc.vo.CrossDayStateVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordDateSelectVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordDateTimeSelectVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordDateVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordDetailSelectVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordShiftIndexChartVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordWorkstationSelectVO; import com.qianwen.smartman.modules.mdc.vo.StatusRecordWorkstationVO; import com.qianwen.smartman.modules.mdc.vo.SuperAggregateStateVO; import com.qianwen.smartman.modules.mdc.vo.WorkstationInfoVO; import com.qianwen.smartman.modules.mdc.vo.excel.StatusRecordExcelVO; import com.qianwen.smartman.modules.mdc.wrapper.WorkstationFeedbackWrapper; import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder; import cn.hutool.core.util.NumberUtil; @Service public class StatusRecordServiceImpl implements IStatusRecordService { private static final Logger log = LoggerFactory.getLogger(StatusRecordServiceImpl.class); private final ISuperAggregateStateService superAggregateStateService; private final ITimeUsedAnalysisService timeUsedAnalysisService; private final IWorkstationService workstationService; private final OssBuilder ossBuilder; public StatusRecordServiceImpl(final ISuperAggregateStateService superAggregateStateService, final ITimeUsedAnalysisService timeUsedAnalysisService, final IWorkstationService workstationService, final OssBuilder ossBuilder) { this.superAggregateStateService = superAggregateStateService; this.timeUsedAnalysisService = timeUsedAnalysisService; this.workstationService = workstationService; this.ossBuilder = ossBuilder; } @Override public IPage getStatusRecordByDate(IPage page, StatusRecordDateSelectVO statusRecordDateSelectVO) { List result = new ArrayList<>(); List workstationList = statusRecordDateSelectVO.getWorkstationInfoList(); if (Func.isEmpty(workstationList)) { workstationList = this.workstationService.list(Wrappers.lambdaQuery().eq(Workstation::getType, WorkstationTypeEnum.MACHINE.getCode()).eq(BaseEntity::getStatus, CommonConstant.ENABLE)).stream().map(s -> { WorkstationInfoVO workstationInfoVO = new WorkstationInfoVO(); workstationInfoVO.setId(s.getId()); workstationInfoVO.setName(s.getName()); workstationInfoVO.setCode(s.getCode()); return workstationInfoVO; }).collect(Collectors.toList()); /* workstationList = (List) this.workstationService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getType(); }, WorkstationTypeEnum.MACHINE.getCode())).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).stream().map(s -> { WorkstationInfoVO workstationInfoVO = new WorkstationInfoVO(); workstationInfoVO.setId(s.getId()); workstationInfoVO.setName(s.getName()); workstationInfoVO.setCode(s.getCode()); return workstationInfoVO; }).collect(Collectors.toList());*/ } page.setTotal(workstationList.size()); List workstationList2 = workstationList.stream().skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList()); List workstationIdList = workstationList2.stream().map(WorkstationInfoVO::getId).collect(Collectors.toList()); List superAggregateStateList = this.superAggregateStateService.getStatusData(workstationIdList, null, statusRecordDateSelectVO.getDate(), statusRecordDateSelectVO.getDate()); Map> workstationStatusMap = superAggregateStateList.stream().collect(Collectors.groupingBy(SuperAggregateState::getWorkstationId)); workstationList2.forEach(x -> { StatusRecordDateVO statusRecord = new StatusRecordDateVO().setWorkstationInfo(x).setStatusRecordList(StatusRecordConvert.INSTANCE.convert(workstationStatusMap.get(x.getId()))); result.add(statusRecord); }); return page.setRecords(result); } @Override public IPage getStatusRecordByWorkstation(IPage page, StatusRecordWorkstationSelectVO statusRecordWorkstationSelectVO) { List result = new ArrayList<>(); Long workstationId = statusRecordWorkstationSelectVO.getWorkstationId(); List dateList = LocalDateTimeUtils.getDateList(statusRecordWorkstationSelectVO.getStartDate(), statusRecordWorkstationSelectVO.getEndDate()); page.setTotal(dateList.size()); List dateList2 = dateList.stream().skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList()); statusRecordWorkstationSelectVO.setStartDate((LocalDate) ListUtils.getFirst(dateList2)); statusRecordWorkstationSelectVO.setEndDate((LocalDate) ListUtils.getLast(dateList2)); List superAggregateStateList = this.superAggregateStateService.getStatusData(Arrays.asList(workstationId), null, statusRecordWorkstationSelectVO.getStartDate(), statusRecordWorkstationSelectVO.getEndDate()); Map> dateStatusMap = superAggregateStateList.stream().collect(Collectors.groupingBy(x -> { return DateUtil.format(x.getStartTime(), DateConstant.PATTERN_DATE); }, LinkedHashMap::new, Collectors.toList())); long daysBetween = LocalDateTimeUtils.getDifference(statusRecordWorkstationSelectVO.getStartDate(), statusRecordWorkstationSelectVO.getEndDate()).intValue(); for (int i = 0; i <= daysBetween; i++) { String date = DateUtil.format(statusRecordWorkstationSelectVO.getStartDate().plusDays(i), DateConstant.PATTERN_DATE); StatusRecordWorkstationVO statusRecord = new StatusRecordWorkstationVO().setDate(date).setStatusRecordList(statusRecordWorkstationSelectVO.isMachineFeedback() ? StatusRecordConvert.INSTANCE.convert(dateStatusMap.get(date)) : null); result.add(statusRecord); } return page.setRecords(result); } @Override public List getTimeDistribution(StatusRecordDetailSelectVO statusRecordDetailSelectVO) { List result = new ArrayList<>(); List superAggregateStateList = this.superAggregateStateService.getStatusData(Arrays.asList(statusRecordDetailSelectVO.getWorkstationId()), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); Map wcsMap = superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWcs(); }, HashMap::new, Collectors.summingLong((v0) -> { return v0.getDurationCollect(); }))); for (Map.Entry entry : wcsMap.entrySet()) { ChartDataVO chartData = new ChartDataVO<>().setName(entry.getKey() + "").setValue(Double.valueOf(BigDecimal.valueOf(entry.getValue().longValue()).divide(BigDecimal.valueOf(60000L), 2, 4).doubleValue())); result.add(chartData); } return result; } @Override public List getEquipmentEfficiency(StatusRecordDetailSelectVO statusRecordDetailSelectVO) { List result = new ArrayList<>(); List superAggregateStateList = this.superAggregateStateService.getStatusData(Arrays.asList(statusRecordDetailSelectVO.getWorkstationId()), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); //下面一行不用了,应为稼动率再分析设置界面和这里不相符,我们同意使用状态数据,不用feedback的 //List oeeAggregateStateList = this.superAggregateStateService.getStatusDataWithFeedback(Arrays.asList(statusRecordDetailSelectVO.getWorkstationId()), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); ProductivityTypeEnum[] values = ProductivityTypeEnum.values(); int length = values.length; for (int i = 0; i < length; i++) { ProductivityTypeEnum productivityTypeEnum = values[i]; //ChartDataVO chartData = new ChartDataVO().setName(productivityTypeEnum.getMessage()).setValue(EifficiencyUtils.calculationResults(productivityTypeEnum == ProductivityTypeEnum.OEE ? oeeAggregateStateList : superAggregateStateList, productivityTypeEnum)); //上面一行,去掉oee的传值 ChartDataVO chartData = new ChartDataVO().setName(productivityTypeEnum.getMessage()).setValue(EifficiencyUtils.calculationResults(superAggregateStateList, productivityTypeEnum)); result.add(chartData); } return result; } @Override public List getShiftIndexStatusRecordChart(StatusRecordDetailSelectVO statusRecordDetailSelectVO) { List statusData; List result = new ArrayList<>(); Long workstationId = statusRecordDetailSelectVO.getWorkstationId(); if (statusRecordDetailSelectVO.isHumanFeedback()) { statusData = this.superAggregateStateService.getStatusDataWithFeedback(Arrays.asList(workstationId), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); } else { statusData = this.superAggregateStateService.getStatusData(Arrays.asList(workstationId), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); } List superAggregateStateList = statusData; List shiftIndexList = getWorkstationShiftIndexList(workstationId, statusRecordDetailSelectVO.getDate()); Optional.ofNullable(shiftIndexList).ifPresent(p -> { Map> shiftIndexStatusMap =superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getShiftIndex(); })); p.forEach(x -> { List listRecord = Optional.ofNullable(StatusRecordConvert.INSTANCE.convert( shiftIndexStatusMap.get(x.getShiftIndex()))).map(list -> { return statusRecordDetailSelectVO.isHumanFeedback() ? WorkstationFeedbackWrapper.entityVO(list) : list; }).orElse(null); StatusRecordShiftIndexChartVO statusRecord = new StatusRecordShiftIndexChartVO().setShiftIndex(x.getShiftIndex()).setShiftIndexName(x.getShiftIndexName()).setStatusRecordList(listRecord); result.add(statusRecord); }); }); return result; } @Override public List> getShiftIndexStatusRecordTable(StatusRecordDetailSelectVO statusRecordDetailSelectVO) { List statusData; List> result = new ArrayList<>(); Long workstationId = statusRecordDetailSelectVO.getWorkstationId(); if (statusRecordDetailSelectVO.isHumanFeedback()) { statusData = this.superAggregateStateService.getStatusDataWithFeedback(Arrays.asList(workstationId), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); } else { statusData = this.superAggregateStateService.getStatusData(Arrays.asList(workstationId), null, statusRecordDetailSelectVO.getDate(), statusRecordDetailSelectVO.getDate()); } List superAggregateStateList = statusData; List shiftIndexList = getWorkstationShiftIndexList(workstationId, statusRecordDetailSelectVO.getDate()); Optional.ofNullable(shiftIndexList).ifPresent(p -> { Map> shiftIndexStatusMap = superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getShiftIndex(); })); p.forEach(x -> { HashMap hashMap = new HashMap<>(16); hashMap.put("shiftIndex", x.getShiftIndex() + ""); hashMap.put("shiftIndexName", x.getShiftIndexName()); List shiftIndexStatusList = shiftIndexStatusMap.get(x.getShiftIndex());//null if (Func.isNotEmpty(shiftIndexStatusList)) { hashMap.put("oee", EifficiencyUtils.calculationResults(shiftIndexStatusList, ProductivityTypeEnum.OEE) + ""); hashMap.put("fault", EifficiencyUtils.calculationResults(shiftIndexStatusList, ProductivityTypeEnum.ALARM) + ""); HashMap wcsMap = shiftIndexStatusList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWcs(); }, HashMap::new, Collectors.summingLong((v0) -> { return v0.getDurationCollect(); }))); for (Map.Entry entry : wcsMap.entrySet()) { hashMap.put(entry.getKey() + "", CommonUtil.secToTime(Integer.valueOf(wcsMap.get(entry.getKey()) + ""))); } } result.add(hashMap); }); }); return result; } @Override public BladeFile exportStatusRecord(StatusRecordExcelVO vo) { List ids; List workstations; List infoList = vo.getWorkstationInfoList(); if (Func.isEmpty(infoList)) { workstations = this.workstationService.list(Wrappers.lambdaQuery() .eq(Workstation::getType, WorkstationTypeEnum.MACHINE.getCode()) .eq(Workstation::getStatus, CommonConstant.ENABLE)); /* workstations = this.workstationService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getType(); }, WorkstationTypeEnum.MACHINE.getCode())).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE));*/ ids = workstations.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); } else { ids = infoList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); workstations = this.workstationService.listByIds(ids); } if (Func.isEmpty(workstations)) { return exportEmpty(); } Map workstationMap = workstations.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, v -> { return v; })); LocalDate startTime = vo.getStartTime(); Map wcsMap = getWcs(); Map groupWorkMap = this.workstationService.queryGroupWorkStation(ids); List exportList = Lists.newArrayList(); for (LocalDate endTime = vo.getEndTime(); endTime.compareTo((ChronoLocalDate) startTime) >= 0; endTime = endTime.minusDays(1L)) { List superAggregateStateList = this.superAggregateStateService.getStatusData(ids, null, endTime, endTime); LocalDate finalEndTime = endTime; //SuperAggregateState state; List collect = superAggregateStateList.stream().sorted(Comparator.comparing(SuperAggregateState::getWorkstationId).thenComparing(SuperAggregateState::getStartTime)).map(state -> { Long workstationId = state.getWorkstationId(); GroupWorkDTO groupWorkDTO = (GroupWorkDTO) groupWorkMap.getOrDefault(workstationId, new GroupWorkDTO()); Workstation infoVO = (Workstation) workstationMap.getOrDefault(workstationId, new Workstation()); StatusRecordExport export = new StatusRecordExport(); export.setDate(DateUtil.format(finalEndTime, DateConstant.PATTERN_DATE)); export.setGroupName(groupWorkDTO.getName()); export.setWorkstationCode(infoVO.getCode()); export.setWorkstationName(infoVO.getName()); export.setStatus((String) wcsMap.get(String.valueOf(state.getWcs()))); export.setStartTime(DateUtil.format(state.getStartTime(), "yyyy-MM-dd HH:mm:ss.SSS")); export.setEndTime(DateUtil.format(state.getEndTime(), "yyyy-MM-dd HH:mm:ss.SSS")); export.setDuration(getMinute(state.getDurationCollect().longValue())); return export; }).collect(Collectors.toList()); exportList.addAll(collect); } String fileName = String.format("%s-%s.xlsx", ExcelConstant.STATUS_RECORD, DateUtil.time()); MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, ExcelConstant.STATUS_RECORD, exportList, StatusRecordExport.class); return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile); } private BladeFile exportEmpty() { List exportList = Lists.newArrayList(); String fileName = String.format("%s-%s.xlsx", ExcelConstant.STATUS_RECORD, DateUtil.time()); MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, ExcelConstant.STATUS_RECORD, exportList, StatusRecordExport.class); return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile); } /* @Override public List> crossDayState(CrossDayStateVO vo) { LocalDate date = vo.getDate(); LocalDateTime start = LocalDateTime.of(date, LocalTime.MIN); LocalDateTime end = LocalDateTime.of(date, LocalTime.MAX); List res = this.superAggregateStateService.crossDay(start, end); if (Func.isEmpty(res)) { return new ArrayList<>(); } List> list = Lists.newArrayList(); List collect = res.stream().flatMap(state -> { List states = crossState(state, date); List vos = StatusRecordConvert.INSTANCE.convertState(states); list.add(vos); return states.stream(); }).collect(Collectors.toList()); this.superAggregateStateService.saveState(collect); return list; }*/ @Override public IPage getStatusRecordByDates(IPage page, StatusRecordDateTimeSelectVO statusRecordDateTimeSelectVO) { List result = new ArrayList<>(); List workstationList = statusRecordDateTimeSelectVO.getWorkstationInfoList(); if (Func.isEmpty(workstationList)) { workstationList = this.workstationService.list(Wrappers.lambdaQuery() .eq(Workstation::getType, WorkstationTypeEnum.MACHINE.getCode()) .eq(Workstation::getStatus, CommonConstant.ENABLE)).stream().map(s -> { WorkstationInfoVO workstationInfoVO = new WorkstationInfoVO(); workstationInfoVO.setId(s.getId()); workstationInfoVO.setName(s.getName()); workstationInfoVO.setCode(s.getCode()); return workstationInfoVO; }).collect(Collectors.toList()); /* workstationList = (List) this.workstationService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getType(); }, WorkstationTypeEnum.MACHINE.getCode())).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).stream().map(s -> { WorkstationInfoVO workstationInfoVO = new WorkstationInfoVO(); workstationInfoVO.setId(s.getId()); workstationInfoVO.setName(s.getName()); workstationInfoVO.setCode(s.getCode()); return workstationInfoVO; }).collect(Collectors.toList());*/ } page.setTotal(workstationList.size()); List workstationList2 = workstationList.stream().skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList()); List workstationIdList = workstationList2.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); List superAggregateStateList = this.superAggregateStateService.getStatusDataByTime(workstationIdList, statusRecordDateTimeSelectVO.getStartTime(), statusRecordDateTimeSelectVO.getEndTime()); Map> workstationStatusMap = superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })); workstationList2.forEach(x -> { StatusRecordDateVO statusRecord = new StatusRecordDateVO().setWorkstationInfo(x).setStatusRecordList(StatusRecordConvert.INSTANCE.convert(workstationStatusMap.get(x.getId()))); result.add(statusRecord); }); return page.setRecords(result); } private String getMinute(long duration) { return NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, duration / 60000.0d); } private Map getWcs() { List defaultWcs = WorkstationCache.getDefaultWcs(); return defaultWcs.stream().collect(Collectors.toMap((v0) -> { return v0.getCode(); }, (v0) -> { return v0.getName(); })); } private List getWorkstationShiftIndexList(Long workstationId, LocalDate date) { Map> workstationShiftIndexMap = this.timeUsedAnalysisService.queryWorkStationShiftIndex(Arrays.asList(workstationId), date); return workstationShiftIndexMap.get(workstationId); } private List crossState(SuperAggregateState state, LocalDate date) { Timestamp startTime = state.getStartTime(); Timestamp endTime = state.getEndTime(); int days = betweenDays(startTime, endTime); List res = Lists.newArrayList(); if (days == 1) { SuperAggregateState state1 = StatusRecordConvert.INSTANCE.convert(state); LocalDateTime time = LocalDateTime.of(date, LocalTime.MAX); state1.setEndTime(new Timestamp(time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); state1.setDurationCollect(Long.valueOf(DateUtil.between(state1.getStartTime(), state1.getEndTime()).getSeconds())); res.add(state1); SuperAggregateState state2 = StatusRecordConvert.INSTANCE.convert(state); state2.setStartTime(getStartTime(state2.getEndTime())); state2.setDurationCollect(Long.valueOf(DateUtil.between(state2.getStartTime(), state2.getEndTime()).getSeconds())); res.add(state2); } else { for (int i = 0; i <= days; i++) { if (i == 0) { SuperAggregateState state12 = StatusRecordConvert.INSTANCE.convert(state); LocalDateTime time2 = LocalDateTime.of(date, LocalTime.MAX); state12.setEndTime(new Timestamp(time2.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); state12.setDurationCollect(Long.valueOf(DateUtil.between(state12.getStartTime(), state12.getEndTime()).getSeconds())); res.add(state12); } else if (i == days) { SuperAggregateState state13 = StatusRecordConvert.INSTANCE.convert(state); state13.setStartTime(getStartTime(state13.getEndTime())); state13.setDurationCollect(Long.valueOf(DateUtil.between(state13.getStartTime(), state13.getEndTime()).getSeconds())); res.add(state13); } else { SuperAggregateState state14 = StatusRecordConvert.INSTANCE.convert(state); LocalDate localDate = date.plusDays(i); LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN); LocalDateTime end = LocalDateTime.of(localDate, LocalTime.MAX); state14.setStartTime(new Timestamp(start.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); state14.setEndTime(new Timestamp(end.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); state14.setDurationCollect(Long.valueOf(DateUtil.between(state14.getStartTime(), state14.getEndTime()).getSeconds())); res.add(state14); } } } return res; } private Timestamp getStartTime(Timestamp endTime) { Calendar instance = Calendar.getInstance(); instance.setTime(endTime); int year = instance.get(1); int month = instance.get(2); int day = instance.get(5); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day, 0, 0, 0); return new Timestamp(calendar.getTimeInMillis()); } private int betweenDays(Timestamp startTime, Timestamp endTime) { Calendar c1 = Calendar.getInstance(); c1.setTime(startTime); Calendar c2 = Calendar.getInstance(); c2.setTime(endTime); int day1 = c1.get(5); int day2 = c2.get(5); return day2 - day1; } }