qushaowei
2023-11-07 094a9290c836827bc1f45fd3549e7cd2ea1e1e45
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcNoplanCloseServiceImpl.java
@@ -9,9 +9,7 @@
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.entity.MdcEquipmentRepair;
import org.jeecg.modules.mdc.entity.MdcNoplanClose;
import org.jeecg.modules.mdc.entity.MdcTorqueConfig;
import org.jeecg.modules.mdc.mapper.MdcNoplanCloseMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.service.IMdcNoplanCloseService;
@@ -25,6 +23,10 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -317,4 +319,30 @@
        mv.addObject(NormalExcelConstants.DATA_LIST, mdcNoplanCloses);
        return mv;
    }
    @Override
    public BigDecimal findNoplanTimeDuration(String equipmentId, String validDate, String noplanType) {
        BigDecimal result = new BigDecimal("0");
        String startDate = DateUtils.format(DateUtils.toDate(validDate + "-01", DateUtils.STR_DATE), DateUtils.STR_DATE) + " 00:00:00";
        Date startTime = DateUtils.toDate(startDate, DateUtils.STR_DATE_TIME_SMALL);
        String endDate = DateUtils.format(DateUtils.addMonth(1, DateUtils.toDate(startDate, DateUtils.STR_DATE_TIME_SMALL)), DateUtils.STR_DATE_TIME_SMALL);
        Date endTime = DateUtils.toDate(endDate, DateUtils.STR_DATE_TIME_SMALL);
        List<MdcNoplanClose> mdcNoplanCloseList = this.baseMapper.findNoplanTimeDuration(equipmentId, noplanType, startDate, endDate);
        // 时间修正 并计算
        if (mdcNoplanCloseList != null && !mdcNoplanCloseList.isEmpty()) {
            for (MdcNoplanClose mdcNoplanClose : mdcNoplanCloseList) {
                if (mdcNoplanClose.getStartTime().before(startTime)) {
                    mdcNoplanClose.setStartTime(startTime);
                }
                if (mdcNoplanClose.getEndTime().after(endTime)) {
                    mdcNoplanClose.setEndTime(endTime);
                }
                LocalDateTime localStartDate = LocalDateTime.ofInstant(mdcNoplanClose.getStartTime().toInstant(), ZoneId.systemDefault());
                LocalDateTime localEndDate = LocalDateTime.ofInstant(mdcNoplanClose.getEndTime().toInstant(), ZoneId.systemDefault());
                int minutes = Math.toIntExact(Duration.between(localStartDate, localEndDate).toMinutes());
                result = result.add(new BigDecimal(minutes));
            }
        }
        return result;
    }
}