zm
2024-10-15 032ab98c53cd1448f81d1e8be04423d6b46c4fa1
src/main/java/com/product/administration/service/LeaveRequestService.java
@@ -9,6 +9,9 @@
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -80,6 +83,31 @@
      }
   }
   /**
    * 计算请假天数
    * @param fs
    * @return
    * @throws BaseException
    */
   public FieldSetEntity getDay(FieldSetEntity fs) throws BaseException {
      DataTableEntity dt = baseDao.listTable(com.product.org.admin.config.CmnConst.PRODUCT_SYS_COMPANY_HOLIDAY, "date_holiday >=? and date_holiday<=?", new String[]{fs.getString("start_time"), fs.getString("end_time")});
      String dateStr1 = fs.getString("start_time");
      String dateStr2 = fs.getString("end_time");
      // 使用DateTimeFormatter解析日期字符串
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
      // 将字符串解析为LocalDate对象
      LocalDate date1 = LocalDate.parse(dateStr1, formatter);
      LocalDate date2 = LocalDate.parse(dateStr2, formatter);
      // 计算两个日期之间的天数差
      long daysBetween = java.time.Duration.between(date1.atStartOfDay(), date2.atStartOfDay()).toDays()+1;
      fs.setValue("day",daysBetween-dt.getRows());
      return fs;
   }
   /**
    * @Date: 2020-03-30 16:43
    * @Author: ZhouJie