From 48a62ed1badc7b68a81e253240672b15d4c3d74a Mon Sep 17 00:00:00 2001 From: fengjin <1435304038@qq.com> Date: 星期二, 18 十月 2022 18:31:01 +0800 Subject: [PATCH] 修改获取节假日依赖及代码 --- flower_city/src/main/java/com/dg/core/util/presence/Year2002.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2017.java | 31 + flower_city/src/main/java/com/dg/core/util/TestDate.java | 6 flower_city/src/main/java/com/dg/core/util/presence/Year2013.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/YearMap.java | 84 +++ flower_city/src/main/java/com/dg/core/util/presence/Year2010.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2019.java | 39 + flower_city/src/main/java/com/dg/core/util/presence/Year2005.java | 31 + flower_city/src/main/java/com/dg/core/util/workday/WorkUtils.java | 699 +++++++++++++++++++++++++ flower_city/src/main/java/com/dg/core/util/presence/Year2016.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year20xx.java | 7 flower_city/src/main/java/com/dg/core/util/presence/Year2008.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2018.java | 41 + flower_city/src/main/java/com/dg/core/util/workday/Data.java | 19 flower_city/src/main/java/com/dg/core/util/workday/WorkdayGen.java | 74 ++ flower_city/src/main/java/com/dg/core/util/presence/Year2001.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2015.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2007.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2004.java | 31 + flower_city/src/main/java/com/dg/core/service/impl/GuideRepairOrderServiceImpl.java | 5 flower_city/src/main/java/com/dg/core/util/presence/Year2012.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2020.java | 42 + flower_city/src/main/java/com/dg/core/util/presence/Year2003.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2009.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2006.java | 31 + flower_city/src/main/java/com/dg/core/util/presence/Year2014.java | 31 + flower_city/src/main/java/com/dg/core/controller/CommonController.java | 21 flower_city/src/main/java/com/dg/core/util/presence/Year2011.java | 31 + flower_city/pom.xml | 6 29 files changed, 1,557 insertions(+), 13 deletions(-) diff --git a/flower_city/pom.xml b/flower_city/pom.xml index 5826be7..41ffebc 100644 --- a/flower_city/pom.xml +++ b/flower_city/pom.xml @@ -92,6 +92,12 @@ <version>2.7.1</version> </dependency> + <dependency> + <groupId>com.icexxx</groupId> + <artifactId>iceworkday</artifactId> + <version>2.0.2.0</version> + </dependency> + <dependency> <groupId>cn.afterturn</groupId> diff --git a/flower_city/src/main/java/com/dg/core/controller/CommonController.java b/flower_city/src/main/java/com/dg/core/controller/CommonController.java index 98d31e0..9c89361 100644 --- a/flower_city/src/main/java/com/dg/core/controller/CommonController.java +++ b/flower_city/src/main/java/com/dg/core/controller/CommonController.java @@ -9,6 +9,7 @@ import com.dg.core.file.MimeTypeUtils; import com.dg.core.file.SFTPUtil; import com.dg.core.util.TestDate; +import com.iceyyy.workday.WorkUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -22,7 +23,9 @@ import javax.annotation.Resource; import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.UUID; @@ -141,21 +144,19 @@ /** * 判断当前时间是否是工作日,格式为“2022-10-16”,不传默认为今天 */ - @ApiOperation("判断当前时间是否是工作日,格式为“2022-10-16”,不传默认为今天") + @ApiOperation("判断当前时间是否是工作日,格式为“20221016”,不传默认为今天") @GetMapping("/isWeekday") public ResultData isWeekday(@RequestParam(value = "dateTime",required = false) String dateTime) { - TestDate td=new TestDate(); - DateTime dateTimeUser; - if (dateTime==null) - dateTimeUser=DateTime.now(); - else{ - dateTimeUser=DateUtil.parse(dateTime); + if (dateTime==null){ + Date date = new Date(); + SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); + dateTime = fmt.format(date); } - if (td.isWeekday(dateTimeUser)) - return success("工作日"); - else + if (WorkUtils.isWorkendDay(dateTime)) return success("休息日或者周末"); + else + return success("工作日"); } diff --git a/flower_city/src/main/java/com/dg/core/service/impl/GuideRepairOrderServiceImpl.java b/flower_city/src/main/java/com/dg/core/service/impl/GuideRepairOrderServiceImpl.java index 15a91a7..69b31a4 100644 --- a/flower_city/src/main/java/com/dg/core/service/impl/GuideRepairOrderServiceImpl.java +++ b/flower_city/src/main/java/com/dg/core/service/impl/GuideRepairOrderServiceImpl.java @@ -12,6 +12,7 @@ import com.dg.core.util.Snowflake; import com.dg.core.util.TestDate; import com.dg.core.util.WxUtil; +import com.iceyyy.workday.WorkUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -278,7 +279,9 @@ LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);//今天结束时间 TestDate td = new TestDate(); DateTime dateTimeUser= DateTime.now(); - if (td.isWeekday(dateTimeUser)){ + String format="YYYYMMdd"; + String dateTimeToday=dateTimeUser.toString(format); + if (!WorkUtils.isWorkendDay(dateTimeToday)){ if ( LocalDateTime.now().isAfter(startTime)&&LocalDateTime.now().isBefore(morningStartTime)){//提交时间是上午上班前 guideRepairOrder.setTimeoutTime(LocalDate.now(). atTime(9+automessageSysSettings.getTimeoutNotificationNum(),0,0)); diff --git a/flower_city/src/main/java/com/dg/core/util/TestDate.java b/flower_city/src/main/java/com/dg/core/util/TestDate.java index 0c31040..1a13a9a 100644 --- a/flower_city/src/main/java/com/dg/core/util/TestDate.java +++ b/flower_city/src/main/java/com/dg/core/util/TestDate.java @@ -3,6 +3,7 @@ import cn.hutool.core.date.DateTime; import com.alibaba.fastjson.JSONObject; +import com.iceyyy.workday.WorkUtils; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; @@ -137,12 +138,13 @@ * @return */ public DateTime nextWeekDay(DateTime dateTime){ - TestDate td=new TestDate(); Calendar calendar = Calendar.getInstance(); calendar.setTime(dateTime); while (true){ calendar.add(calendar.DATE,1); - if (td.isWeekday(new DateTime(calendar))){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + String dateTimeToday = sdf.format(calendar.getTime()); + if (!WorkUtils.isWorkendDay(dateTimeToday)){ return new DateTime(calendar);//返回日期 } } diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2001.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2001.java new file mode 100644 index 0000000..bdb7382 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2001.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2001 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20010120", false); // 班 + map.put("20010121", false); // 班 + map.put("20010124", true); // 休 + map.put("20010125", true); // 休 + map.put("20010126", true); // 休 + map.put("20010129", true); // 休 + map.put("20010130", true); // 休 + map.put("20010428", false); // 班 + map.put("20010429", false); // 班 + map.put("20010501", true); // 休 + map.put("20010502", true); // 休 + map.put("20010503", true); // 休 + map.put("20010504", true); // 休 + map.put("20010507", true); // 休 + map.put("20010929", false); // 班 + map.put("20010930", false); // 班 + map.put("20011001", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2002.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2002.java new file mode 100644 index 0000000..bb8ec95 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2002.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2002 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20020101", true); // 休 + map.put("20020102", true); // 休 + map.put("20020103", true); // 休 + map.put("20020209", false); // 班 + map.put("20020210", false); // 班 + map.put("20020212", true); // 休 + map.put("20020213", true); // 休 + map.put("20020214", true); // 休 + map.put("20020215", true); // 休 + map.put("20020218", true); // 休 + map.put("20020427", false); // 班 + map.put("20020428", false); // 班 + map.put("20020501", true); // 休 + map.put("20020502", true); // 休 + map.put("20020503", true); // 休 + map.put("20020506", true); // 休 + map.put("20020507", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2003.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2003.java new file mode 100644 index 0000000..c3b38e1 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2003.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2003 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20030101", true); // 休 + map.put("20030203", true); // 休 + map.put("20030204", true); // 休 + map.put("20030205", true); // 休 + map.put("20030206", true); // 休 + map.put("20030207", true); // 休 + map.put("20030208", false); // 班 + map.put("20030209", false); // 班 + map.put("20030426", false); // 班 + map.put("20030427", false); // 班 + map.put("20030501", true); // 休 + map.put("20030502", true); // 休 + map.put("20030505", true); // 休 + map.put("20030506", true); // 休 + map.put("20030507", true); // 休 + map.put("20030927", false); // 班 + map.put("20030928", false); // 班 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2004.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2004.java new file mode 100644 index 0000000..db9a9f5 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2004.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2004 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20040101", true); // 休 + map.put("20040117", false); // 班 + map.put("20040118", false); // 班 + map.put("20040122", true); // 休 + map.put("20040123", true); // 休 + map.put("20040126", true); // 休 + map.put("20040127", true); // 休 + map.put("20040128", true); // 休 + map.put("20040503", true); // 休 + map.put("20040504", true); // 休 + map.put("20040505", true); // 休 + map.put("20040506", true); // 休 + map.put("20040507", true); // 休 + map.put("20040508", false); // 班 + map.put("20040509", false); // 班 + map.put("20041001", true); // 休 + map.put("20041003", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2005.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2005.java new file mode 100644 index 0000000..05d2f89 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2005.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2005 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20050103", true); // 休 + map.put("20050205", false); // 班 + map.put("20050206", false); // 班 + map.put("20050209", true); // 休 + map.put("20050210", true); // 休 + map.put("20050211", true); // 休 + map.put("20050214", true); // 休 + map.put("20050215", true); // 休 + map.put("20050430", false); // 班 + map.put("20050502", true); // 休 + map.put("20050503", true); // 休 + map.put("20050504", true); // 休 + map.put("20050505", true); // 休 + map.put("20050506", true); // 休 + map.put("20050508", false); // 班 + map.put("20051003", true); // 休 + map.put("20051004", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2006.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2006.java new file mode 100644 index 0000000..45c1a30 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2006.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2006 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20060102", true); // 休 + map.put("20060103", true); // 休 + map.put("20060128", false); // 班 + map.put("20060130", true); // 休 + map.put("20060131", true); // 休 + map.put("20060201", true); // 休 + map.put("20060202", true); // 休 + map.put("20060203", true); // 休 + map.put("20060205", false); // 班 + map.put("20060429", false); // 班 + map.put("20060430", false); // 班 + map.put("20060501", true); // 休 + map.put("20060502", true); // 休 + map.put("20060503", true); // 休 + map.put("20060504", true); // 休 + map.put("20060505", true); // 休 + map.put("20060930", false); // 班 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2007.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2007.java new file mode 100644 index 0000000..4aba4ec --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2007.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2007 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20070101", true); // 休 + map.put("20070102", true); // 休 + map.put("20070103", true); // 休 + map.put("20070217", false); // 班 + map.put("20070219", true); // 休 + map.put("20070220", true); // 休 + map.put("20070221", true); // 休 + map.put("20070222", true); // 休 + map.put("20070223", true); // 休 + map.put("20070225", false); // 班 + map.put("20070428", false); // 班 + map.put("20070429", false); // 班 + map.put("20070501", true); // 休 + map.put("20070502", true); // 休 + map.put("20070503", true); // 休 + map.put("20070504", true); // 休 + map.put("20070507", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2008.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2008.java new file mode 100644 index 0000000..44618ea --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2008.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2008 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20080101", true); // 休 + map.put("20080203", false); // 班 + map.put("20080206", true); // 休 + map.put("20080207", true); // 休 + map.put("20080208", true); // 休 + map.put("20080211", true); // 休 + map.put("20080212", true); // 休 + map.put("20080404", true); // 休 + map.put("20080501", true); // 休 + map.put("20080502", true); // 休 + map.put("20080504", false); // 班 + map.put("20080609", true); // 休 + map.put("20080915", true); // 休 + map.put("20080927", false); // 班 + map.put("20080928", false); // 班 + map.put("20080929", true); // 休 + map.put("20080930", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2009.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2009.java new file mode 100644 index 0000000..39e507a --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2009.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2009 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20090101", true); // 休 + map.put("20090102", true); // 休 + map.put("20090104", false); // 班 + map.put("20090124", false); // 班 + map.put("20090126", true); // 休 + map.put("20090127", true); // 休 + map.put("20090128", true); // 休 + map.put("20090129", true); // 休 + map.put("20090130", true); // 休 + map.put("20090201", false); // 班 + map.put("20090406", true); // 休 + map.put("20090501", true); // 休 + map.put("20090528", true); // 休 + map.put("20090529", true); // 休 + map.put("20090531", false); // 班 + map.put("20090927", false); // 班 + map.put("20091001", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2010.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2010.java new file mode 100644 index 0000000..3956873 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2010.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2010 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20100101", true); // 休 + map.put("20100215", true); // 休 + map.put("20100216", true); // 休 + map.put("20100217", true); // 休 + map.put("20100218", true); // 休 + map.put("20100219", true); // 休 + map.put("20100220", false); // 班 + map.put("20100221", false); // 班 + map.put("20100405", true); // 休 + map.put("20100503", true); // 休 + map.put("20100612", false); // 班 + map.put("20100613", false); // 班 + map.put("20100614", true); // 休 + map.put("20100615", true); // 休 + map.put("20100616", true); // 休 + map.put("20100919", false); // 班 + map.put("20100922", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2011.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2011.java new file mode 100644 index 0000000..20889dd --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2011.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2011 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20110103", true); // 休 + map.put("20110130", false); // 班 + map.put("20110202", true); // 休 + map.put("20110203", true); // 休 + map.put("20110204", true); // 休 + map.put("20110207", true); // 休 + map.put("20110208", true); // 休 + map.put("20110212", false); // 班 + map.put("20110402", false); // 班 + map.put("20110404", true); // 休 + map.put("20110405", true); // 休 + map.put("20110502", true); // 休 + map.put("20110606", true); // 休 + map.put("20110912", true); // 休 + map.put("20111003", true); // 休 + map.put("20111004", true); // 休 + map.put("20111005", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2012.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2012.java new file mode 100644 index 0000000..f03ac13 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2012.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2012 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20120102", true); // 休 + map.put("20120103", true); // 休 + map.put("20120121", false); // 班 + map.put("20120123", true); // 休 + map.put("20120124", true); // 休 + map.put("20120125", true); // 休 + map.put("20120126", true); // 休 + map.put("20120127", true); // 休 + map.put("20120129", false); // 班 + map.put("20120331", false); // 班 + map.put("20120401", false); // 班 + map.put("20120402", true); // 休 + map.put("20120403", true); // 休 + map.put("20120404", true); // 休 + map.put("20120428", false); // 班 + map.put("20120430", true); // 休 + map.put("20120501", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2013.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2013.java new file mode 100644 index 0000000..417e4f1 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2013.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2013 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20130101", true); // 休 + map.put("20130102", true); // 休 + map.put("20130103", true); // 休 + map.put("20130105", false); // 班 + map.put("20130106", false); // 班 + map.put("20130211", true); // 休 + map.put("20130212", true); // 休 + map.put("20130213", true); // 休 + map.put("20130214", true); // 休 + map.put("20130215", true); // 休 + map.put("20130216", false); // 班 + map.put("20130217", false); // 班 + map.put("20130404", true); // 休 + map.put("20130405", true); // 休 + map.put("20130407", false); // 班 + map.put("20130427", false); // 班 + map.put("20130428", false); // 班 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2014.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2014.java new file mode 100644 index 0000000..86b9af7 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2014.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2014 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20140101", true); // 休 + map.put("20140126", false); // 班 + map.put("20140131", true); // 休 + map.put("20140203", true); // 休 + map.put("20140204", true); // 休 + map.put("20140205", true); // 休 + map.put("20140206", true); // 休 + map.put("20140208", false); // 班 + map.put("20140407", true); // 休 + map.put("20140501", true); // 休 + map.put("20140502", true); // 休 + map.put("20140504", false); // 班 + map.put("20140602", true); // 休 + map.put("20140908", true); // 休 + map.put("20140928", false); // 班 + map.put("20141001", true); // 休 + map.put("20141002", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2015.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2015.java new file mode 100644 index 0000000..9dac9d5 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2015.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2015 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20150101", true); // 休 + map.put("20150102", true); // 休 + map.put("20150104", false); // 班 + map.put("20150215", false); // 班 + map.put("20150218", true); // 休 + map.put("20150219", true); // 休 + map.put("20150220", true); // 休 + map.put("20150223", true); // 休 + map.put("20150224", true); // 休 + map.put("20150228", false); // 班 + map.put("20150406", true); // 休 + map.put("20150501", true); // 休 + map.put("20150622", true); // 休 + map.put("20150903", true); // 休 + map.put("20150904", true); // 休 + map.put("20150906", false); // 班 + map.put("20151001", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2016.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2016.java new file mode 100644 index 0000000..6cb2e0b --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2016.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2016 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20160101", true); // 休 + map.put("20160206", false); // 班 + map.put("20160208", true); // 休 + map.put("20160209", true); // 休 + map.put("20160210", true); // 休 + map.put("20160211", true); // 休 + map.put("20160212", true); // 休 + map.put("20160214", false); // 班 + map.put("20160404", true); // 休 + map.put("20160502", true); // 休 + map.put("20160609", true); // 休 + map.put("20160610", true); // 休 + map.put("20160612", false); // 班 + map.put("20160915", true); // 休 + map.put("20160916", true); // 休 + map.put("20160918", false); // 班 + map.put("20161003", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2017.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2017.java new file mode 100644 index 0000000..dfbebcc --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2017.java @@ -0,0 +1,31 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2017 implements Year20xx { + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20170102", true); // 休 + map.put("20170122", false); // 班 + map.put("20170127", true); // 休 + map.put("20170130", true); // 休 + map.put("20170131", true); // 休 + map.put("20170201", true); // 休 + map.put("20170202", true); // 休 + map.put("20170204", false); // 班 + map.put("20170401", false); // 班 + map.put("20170403", true); // 休 + map.put("20170404", true); // 休 + map.put("20170501", true); // 休 + map.put("20170527", false); // 班 + map.put("20170529", true); // 休 + map.put("20170530", true); // 休 + map.put("20170930", false); // 班 + map.put("20171002", true); // 休 + return map; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2018.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2018.java new file mode 100644 index 0000000..4a92ace --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2018.java @@ -0,0 +1,41 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2018 implements Year20xx { + + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20180101", true); // 休 + map.put("20180211", false); // 班 + map.put("20180215", true); // 休 + map.put("20180216", true); // 休 + map.put("20180219", true); // 休 + map.put("20180220", true); // 休 + map.put("20180221", true); // 休 + map.put("20180224", false); // 班 + map.put("20180405", true); // 休 + map.put("20180406", true); // 休 + map.put("20180408", false); // 班 + map.put("20180428", false); // 班 + map.put("20180430", true); // 休 + map.put("20180501", true); // 休 + map.put("20180618", true); // 休 + map.put("20180924", true); // 休 + map.put("20180929", false); // 班 + map.put("20180930", false); // 班 + map.put("20181001", true); // 休 + map.put("20181002", true); // 休 + map.put("20181003", true); // 休 + map.put("20181004", true); // 休 + map.put("20181005", true); // 休 + map.put("20181229", false); // 班 + map.put("20181231", true); // 休 + return map; + } + +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2019.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2019.java new file mode 100644 index 0000000..f296d62 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2019.java @@ -0,0 +1,39 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2019 implements Year20xx { + + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20190101", true); // 休 + map.put("20190202", false); // 班 + map.put("20190203", false); // 班 + map.put("20190204", true); // 休 + map.put("20190205", true); // 休 + map.put("20190206", true); // 休 + map.put("20190207", true); // 休 + map.put("20190208", true); // 休 + map.put("20190405", true); // 休 + map.put("20190428", false); // 班 + map.put("20190501", true); // 休 + map.put("20190502", true); // 休 + map.put("20190503", true); // 休 + map.put("20190505", false); // 班 + map.put("20190607", true); // 休 + map.put("20190913", true); // 休 + map.put("20190929", false); // 班 + map.put("20191001", true); // 休 + map.put("20191002", true); // 休 + map.put("20191003", true); // 休 + map.put("20191004", true); // 休 + map.put("20191007", true); // 休 + map.put("20191012", false); // 班 + return map; + } + +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year2020.java b/flower_city/src/main/java/com/dg/core/util/presence/Year2020.java new file mode 100644 index 0000000..de2a26e --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year2020.java @@ -0,0 +1,42 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year20xx; + +import java.util.HashMap; +import java.util.Map; + +public class Year2020 implements Year20xx { + + @Override + public Map<String, Boolean> getYearMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + map.put("20200101", true); // 休 + map.put("20200119", false); // 班 + map.put("20200124", true); // 休 + map.put("20200127", true); // 休 + map.put("20200128", true); // 休 + map.put("20200129", true); // 休 + map.put("20200130", true); // 休 + map.put("20200131", true); // 休(+) + // map.put("20200201", false); // 班 + map.put("20200406", true); // 休 + map.put("20200426", false); // 班 + map.put("20200501", true); // 休 + map.put("20200504", true); // 休 + map.put("20200505", true); // 休 + map.put("20200509", false); // 班 + map.put("20200625", true); // 休 + map.put("20200626", true); // 休 + map.put("20200628", false); // 班 + map.put("20200927", false); // 班 + map.put("20201001", true); // 休 + map.put("20201002", true); // 休 + map.put("20201005", true); // 休 + map.put("20201006", true); // 休 + map.put("20201007", true); // 休 + map.put("20201008", true); // 休 + map.put("20201010", false); // 班 + return map; + } + +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/Year20xx.java b/flower_city/src/main/java/com/dg/core/util/presence/Year20xx.java new file mode 100644 index 0000000..7946d3c --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/Year20xx.java @@ -0,0 +1,7 @@ +package com.dg.core.util.presence; + +import java.util.Map; + +public interface Year20xx { + public Map<String, Boolean> getYearMap(); +} diff --git a/flower_city/src/main/java/com/dg/core/util/presence/YearMap.java b/flower_city/src/main/java/com/dg/core/util/presence/YearMap.java new file mode 100644 index 0000000..a6bf1f3 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/presence/YearMap.java @@ -0,0 +1,84 @@ +package com.dg.core.util.presence; + +import com.iceyyy.icework.presence.Year2001; +import com.iceyyy.icework.presence.Year2002; +import com.iceyyy.icework.presence.Year2003; +import com.iceyyy.icework.presence.Year2004; +import com.iceyyy.icework.presence.Year2005; +import com.iceyyy.icework.presence.Year2006; +import com.iceyyy.icework.presence.Year2007; +import com.iceyyy.icework.presence.Year2008; +import com.iceyyy.icework.presence.Year2009; +import com.iceyyy.icework.presence.Year2010; +import com.iceyyy.icework.presence.Year2011; +import com.iceyyy.icework.presence.Year2012; +import com.iceyyy.icework.presence.Year2013; +import com.iceyyy.icework.presence.Year2014; +import com.iceyyy.icework.presence.Year2015; +import com.iceyyy.icework.presence.Year2016; +import com.iceyyy.icework.presence.Year2017; +import com.iceyyy.icework.presence.Year2018; +import com.iceyyy.icework.presence.Year2019; +import com.iceyyy.icework.presence.Year2020; +import com.iceyyy.icework.presence.Year20xx; + +import java.util.Map; + +public class YearMap { + + public static void main(String[] args) { + int year = 2001; + System.out.println(YearMap.yearMap(year)); + } + + public static Map<String, Boolean> yearMap(int year) { + com.iceyyy.icework.presence.Year20xx createMap = createMap(year); + return createMap.getYearMap(); + } + + private static Year20xx createMap(int year) { + if (year == 2001) { + return new Year2001(); + } else if (year == 2002) { + return new Year2002(); + } else if (year == 2003) { + return new Year2003(); + } else if (year == 2004) { + return new Year2004(); + } else if (year == 2005) { + return new Year2005(); + } else if (year == 2006) { + return new Year2006(); + } else if (year == 2007) { + return new Year2007(); + } else if (year == 2008) { + return new Year2008(); + } else if (year == 2009) { + return new Year2009(); + } else if (year == 2010) { + return new Year2010(); + } else if (year == 2011) { + return new Year2011(); + } else if (year == 2012) { + return new Year2012(); + } else if (year == 2013) { + return new Year2013(); + } else if (year == 2014) { + return new Year2014(); + } else if (year == 2015) { + return new Year2015(); + } else if (year == 2016) { + return new Year2016(); + } else if (year == 2017) { + return new Year2017(); + } else if (year == 2018) { + return new Year2018(); + } else if (year == 2019) { + return new Year2019(); + } else if (year == 2020) { + return new Year2020(); + } + return null; + } + +} diff --git a/flower_city/src/main/java/com/dg/core/util/workday/Data.java b/flower_city/src/main/java/com/dg/core/util/workday/Data.java new file mode 100644 index 0000000..a832c39 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/workday/Data.java @@ -0,0 +1,19 @@ +package com.dg.core.util.workday; + +public class Data { + private int date; + private boolean repose; + + public Data(int date, boolean repose) { + this.date = date; + this.repose = repose; + } + + public int getDate() { + return date; + } + + public boolean getRepose() { + return repose; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/workday/WorkUtils.java b/flower_city/src/main/java/com/dg/core/util/workday/WorkUtils.java new file mode 100644 index 0000000..63d3f40 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/workday/WorkUtils.java @@ -0,0 +1,699 @@ +package com.dg.core.util.workday; + +import com.iceyyy.icework.presence.YearMap; +import com.iceyyy.nongli.NongLi; +import com.iceyyy.workday.Data; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Map.Entry; + +/** + * iceworkday工作日算法 + * @author IceWater zxcyhn@126.com + */ +public class WorkUtils { + + public static Map<String, Boolean> weekendMap(String year) { + if (year == null || "".equals(year.trim())) { + throw new RuntimeException("传入的参数为空"); + } + if (year.length() != 4) { + throw new RuntimeException("传入的参数格式错误,应传入yyyyMMdd格式的日期"); + } + int yearNum = Integer.parseInt(year.substring(0, 4)); + if (yearNum < 2001) { + throw new RuntimeException("工作日计算年份需要大于等于2001"); + } else if (yearNum > 2017) { + Map<String, Boolean> mapFromFile = weekMapFromFile(); + mapFromFile = filterMap(mapFromFile, yearNum); + Map<String, Boolean> map = complexCalculate(yearNum); + if (mapFromFile.size() != 0) { + map.putAll(mapFromFile); + } + return map; + } else { + Map<String, Boolean> map = YearMap.yearMap(yearNum); + return map; + } + } + + public static boolean isWorkendDay(String ymd) { + if (ymd == null || "".equals(ymd)) { + throw new RuntimeException("输入的日期不能为空"); + } + ymd = convertDate(ymd); + if("19991230".equals(ymd)) { + return true; + } + if("19991231".equals(ymd)) { + return true; + } + String yearStr = ymd.substring(0, 4); + Map<String, Boolean> weekendMap = weekendMap(yearStr); + Boolean isWeekend = weekendMap.get(ymd); + if (isWeekend == null) { + int day = getWeekDay(ymd); + if (day == 0 || day == 6) { + return true; + } else { + return false; + } + } else { + return isWeekend; + } + } + + private static String convertDate(String dateStr) { + String[] array = null; + if (dateStr.contains("-")) { + array = dateStr.split("-"); + } else if (dateStr.contains(".")) { + array = dateStr.split("\\."); + } else if (dateStr.contains("/")) { + array = dateStr.split("/"); + } else if (dateStr.contains("_")) { + array = dateStr.split("_"); + } else if (dateStr.contains("年")) { + if (dateStr.endsWith("日")) { + dateStr = dateStr.substring(0, dateStr.length() - 1); + } + array = dateStr.split("年|月"); + } else { + if (dateStr.length() == 8) { + return dateStr; + } + } + String yearStr = array[0]; + String monthStr = array[1]; + String dayStr = array[2]; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 4 - yearStr.length(); i++) { + sb.append("0"); + } + sb.append(yearStr); + if (monthStr.length() == 1) { + sb.append("0"); + } + sb.append(monthStr); + if (dayStr.length() == 1) { + sb.append("0"); + } + sb.append(dayStr); + return sb.toString(); + } + + private static Map<String, Boolean> complexCalculate(int yearNum) { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + String newYear = "0101"; + String chingming = "0405"; + String labor = "0501"; + String dragon = "0505L"; + String autumn = "0815L"; + Map<String, Boolean> newYearMap = gregorianNewYearMap(yearNum, newYear); + Map<String, Boolean> nextYearMap = gregorianNewYearMap(yearNum + 1, newYear); + map.putAll(currentYearMap(newYearMap, nextYearMap, yearNum)); + map.putAll(festivalMap(yearNum, chingming)); + map.putAll(newYearLunarMap(yearNum)); + map.putAll(festivalMap(yearNum, labor)); + map.putAll(festivalMap(yearNum, dragon)); + map.putAll(nationalAutumnMap(yearNum, autumn)); + return map; + } + + private static Map<String, Boolean> nationalAutumnMap(int yearNum, String autumn) { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + String ymd = yearNum + "0815";// 中秋节 + String ymdNational = yearNum + "1001";// 国庆节 + String ymdAutumn = convertGregorian(ymd); + int day = getWeekDay(ymdNational); + Map<String, Boolean> mapHistory = getHistoryMap(); + String key = ymdAutumn.substring(4, 8) + "_" + day; + if (mapHistory.get(key) != null) { + // TODO 此处希望从近几年相似的月份中进行类比,是一种优化算法,暂未实现,但不影响算法使用。 + } + String monthAutumn = ymdAutumn.substring(4, 6); + String dateAutumn = ymdAutumn.substring(6, 8); + int monthAutumnNum = Integer.parseInt(monthAutumn); + int dateAutumnNum = Integer.parseInt(dateAutumn); + if (dateAutumnNum < 25 && monthAutumnNum == 9) {// 中秋在9.25以前 + // 中秋最早9.7 最晚10.8 + map.putAll(festivalMap(yearNum, "0815L"));// 中秋 + map.putAll(nationalMap(yearNum));// 国庆 + } else if (monthAutumnNum == 10) {// 中秋节在10月份 + map.putAll(nationalOctMap(yearNum));// 国庆 + } else if (dateAutumnNum >= 25 && monthAutumnNum == 9) {// 中秋节在9.25 9.26 + // 9.27 9.28 + // 9.29 9.30 + // 1. 中秋 25 全部两段 周一~周日 + // 2. 中秋 26 全部两段 周二~周一 + // 3. 中秋 27 最复杂 周三~周二 + // 4. 中秋 28 全部休8天 周四~周三 + // 5. 中秋 29 全部休8天 周五~周四 + // 6. 中秋 30 全部休8天 周六~周五 + // 补班 最早 9.22 最迟 10.12 + int dayAutumn = getWeekDay(ymdAutumn); + map.putAll(complexMap(yearNum, dateAutumnNum, dayAutumn));// 国庆 + } else { + throw new RuntimeException("中秋日期格式错误"); + } + return map; + } + + private static Map<String, Boolean> complexMap(int yearNum, int dateAutumnNum, int dayAutumn) { + com.iceyyy.workday.Data[][] table = getAutumnTable(dateAutumnNum); + com.iceyyy.workday.Data[] row = getRow(table, dateAutumnNum, dayAutumn); + return row2map(row, yearNum); + } + + private static Map<String, Boolean> row2map(com.iceyyy.workday.Data[] row, int yearNum) { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + for (int i = 0; i < row.length; i++) { + com.iceyyy.workday.Data data = row[i]; + int date = data.getDate(); + boolean repose = data.getRepose(); + String monthStr = "10";// 10月份 + if (date > 15) { + monthStr = "09";// 9月份 + } + String dateStr = date + ""; + if (date < 10) { + dateStr = "0" + date; + } + String key = yearNum + monthStr + dateStr; + map.put(key, repose); + } + return map; + } + + /** + * 根据中秋的星期获取具体的某一行的数据 + * + * @param table + * @param dayAutumn + * @return + */ + private static com.iceyyy.workday.Data[] getRow(com.iceyyy.workday.Data[][] table, int dateAutumnNum, int dayAutumn) { + // 25 1 [0] + // 25 2 [1] + // 25 3 [2] + + // 26 1 [6] + // 26 2 [0] + // 26 3 [1] + // 26 4 [2] + // date+index-23=day + // index=day+23-date + int index = (dayAutumn + 31 - dateAutumnNum) % 7; + return table[index]; + } + + private static com.iceyyy.workday.Data[][] getAutumnTable(int dateAutumnNum) { + com.iceyyy.workday.Data[][] days1 = { + { new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(30, false), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(22, false), new com.iceyyy.workday.Data(24, true), new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(29, false), new com.iceyyy.workday.Data(30, false), + new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true) }, + { new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(29, false), + new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(12, false) }, + { new com.iceyyy.workday.Data(21, false), new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(1, true), + new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(11, false) }, + { new com.iceyyy.workday.Data(20, false), new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(9, false), new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(8, false), new com.iceyyy.workday.Data(9, false) } }; + com.iceyyy.workday.Data[][] days2 = { + { new com.iceyyy.workday.Data(23, false), new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(30, false), new com.iceyyy.workday.Data(2, true), + new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(23, false), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(29, false), + new com.iceyyy.workday.Data(30, false), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(13, false) }, + { new com.iceyyy.workday.Data(22, false), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(29, false), new com.iceyyy.workday.Data(1, true), + new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(7, true) }, + { new com.iceyyy.workday.Data(21, false), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true) }, + { new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(9, false) }, + { new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(8, false), new com.iceyyy.workday.Data(9, false) } }; + com.iceyyy.workday.Data[][] days3 = { + { new com.iceyyy.workday.Data(23, false), new com.iceyyy.workday.Data(24, false), new com.iceyyy.workday.Data(25, true), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(27, true), + new com.iceyyy.workday.Data(30, false), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), + new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(6, false), new com.iceyyy.workday.Data(7, false) }, + { new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), + new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, false), new com.iceyyy.workday.Data(6, false) }, + { new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(11, false) }, + { new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), + new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(9, false), new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(24, false), new com.iceyyy.workday.Data(26, true), new com.iceyyy.workday.Data(27, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(8, false), + new com.iceyyy.workday.Data(9, false) } }; + com.iceyyy.workday.Data[][] days4 = { + { new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(7, false), new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, false), new com.iceyyy.workday.Data(7, false) }, + { new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(6, false) }, + { new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), + new com.iceyyy.workday.Data(3, true) }, + { new com.iceyyy.workday.Data(26, false), new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), + new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true) }, + { new com.iceyyy.workday.Data(25, false), new com.iceyyy.workday.Data(26, false), new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), + new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true) }, + { new com.iceyyy.workday.Data(25, false), new com.iceyyy.workday.Data(28, true), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(3, true), + new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(8, false) } }; + com.iceyyy.workday.Data[][] days5 = { + { new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, false), new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(7, false) }, + { new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), + new com.iceyyy.workday.Data(4, true) }, + { new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), + new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(6, true) }, + { new com.iceyyy.workday.Data(26, false), new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), + new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true) }, + { new com.iceyyy.workday.Data(26, false), new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(9, false) }, + { new com.iceyyy.workday.Data(29, true), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(8, false), new com.iceyyy.workday.Data(9, false) } }; + com.iceyyy.workday.Data[][] days6 = { + { new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(8, false) }, + { new com.iceyyy.workday.Data(29, false), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), + new com.iceyyy.workday.Data(5, true) }, + { new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(29, false), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), + new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(7, true) }, + { new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(28, false), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), + new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true) }, + { new com.iceyyy.workday.Data(27, false), new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(2, true), new com.iceyyy.workday.Data(5, true), + new com.iceyyy.workday.Data(6, true), new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(1, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(9, false), new com.iceyyy.workday.Data(10, false) }, + { new com.iceyyy.workday.Data(30, true), new com.iceyyy.workday.Data(3, true), new com.iceyyy.workday.Data(4, true), new com.iceyyy.workday.Data(5, true), new com.iceyyy.workday.Data(6, true), + new com.iceyyy.workday.Data(7, true), new com.iceyyy.workday.Data(8, false), new Data(9, false) } }; + if (dateAutumnNum == 25) { + return days1; + } else if (dateAutumnNum == 26) { + return days2; + } else if (dateAutumnNum == 27) { + return days3; + } else if (dateAutumnNum == 28) { + return days4; + } else if (dateAutumnNum == 29) { + return days5; + } else if (dateAutumnNum == 30) { + return days6; + } + throw new RuntimeException("中秋日期格式错误"); + } + + private static Map<String, Boolean> nationalOctMap(int yearNum) { + String ymd = yearNum + "1001"; + int day = getWeekDay(ymd); + Map<String, Boolean> map = new HashMap<String, Boolean>(); + int[][] correction = { { 30 }, { 29, 30 }, { 28, 29 }, { 28, 11 }, { 27, 10 }, { 9, 10 }, { 9 } }; + for (int i = 0; i < correction[day].length; i++) { + int corr = correction[day][i]; + if (corr <= 15) { + String key = yearNum + "10" + convertNum(corr); + map.put(key, false); + } else { + String key = yearNum + "09" + convertNum(corr); + map.put(key, false); + } + } + int start = 0; + if (day == 0 || day == 1) { + start = -1; + } + int end = 0; + if (day == 5) { + end = 1; + } + for (int i = 0 + start; i < 8 + end; i++) {// 国庆节一般为7天 + String curDate = addDay(ymd, i); + int curDay = getWeekDay(curDate); + if (curDay > 0 && curDay < 6) { + map.put(curDate, true); + } + } + return map; + } + + private static Map<String, Boolean> nationalMap(int yearNum) { + String ymd = yearNum + "1001"; + int day = getWeekDay(ymd); + Map<String, Boolean> map = new HashMap<String, Boolean>(); + int[][] correction = { { 30, 8 }, { 29, 14 }, { 29, 12 }, { 28, 11 }, { 10 }, { 26, 9 }, { 8, 9 } }; + if (day > 0 && day < 6) { + map.put(ymd, true); + } + for (int i = 0; i < correction[day].length; i++) { + int corr = correction[day][i]; + if (corr <= 15) { + String key = yearNum + "10" + convertNum(corr); + map.put(key, false); + } else { + String key = yearNum + "09" + convertNum(corr); + map.put(key, false); + } + } + for (int i = 0; i < 7; i++) {// 国庆节一般为7天 + String curDate = addDay(ymd, i); + int curDay = getWeekDay(curDate); + if (curDay > 0 && curDay < 6) { + map.put(curDate, true); + } + } + return map; + } + + private static String convertNum(int num) { + if (num < 10) { + return "0" + num; + } else { + return num + ""; + } + } + + private static Map<String, Boolean> getHistoryMap() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + return map; + } + + private static Map<String, Boolean> newYearLunarMap(int yearNum) { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + String ymd = yearNum + "0101"; + ymd = convertGregorian(ymd); + int day = getWeekDay(ymd); + int[][] correction = { { 6, 7 }, { -2, 6 }, { -3, 12 }, { -3, 10 }, { -4, 9 }, { -5, 8 }, { -6, 7 } }; + int correct = -1; + if (yearNum == 2014 || yearNum <= 2007) { + correction = new int[][] { { 6, 7 }, { -2, 6 }, { -3, 12 }, { -3, 10 }, { -4, 9 }, { -5, 8 }, { -6, 7 } }; + correct = 0; + } + for (int i = 0; i < correction[day].length; i++) { + map.put(addDay(ymd, correction[day][i]), false); + } + for (int i = 0; i < 7; i++) { + String curYmd = addDay(ymd, i + correct); + int dayCur = getWeekDay(curYmd); + if (dayCur > 0 && dayCur < 6) { + map.put(curYmd, true); + } + } + return map; + } + + private static Map<String, Boolean> currentYearMap(Map<String, Boolean> newYearMap, + Map<String, Boolean> nextYearMap, int yearNum) { + String yearStr = yearNum + ""; + Set<String> setCur = newYearMap.keySet(); + Set<String> setNext = nextYearMap.keySet(); + Map<String, Boolean> map = new HashMap<String, Boolean>(); + for (String key : setCur) { + if (key.startsWith(yearStr)) { + map.put(key, newYearMap.get(key)); + } + } + for (String key : setNext) { + if (key.startsWith(yearStr)) { + map.put(key, nextYearMap.get(key)); + } + } + return map; + } + + private static Map<String, Boolean> festivalMap(int yearNum, String festival) { + String ymd = yearNum + festival; + if (festival.endsWith("L")) { + festival = festival.substring(0, festival.length() - 1); + ymd = convertGregorian(ymd); + } else if ("0405".equals(festival)) { + ymd = chingming(yearNum); + } + return small(ymd); + } + + private static Map<String, Boolean> gregorianNewYearMap(int yearNum, String festival) { + String ymd = yearNum + festival; + return gregorianNewYearSmall(ymd); + } + + private static String chingming(int yearNum) { + return yearNum + "040" + qing(yearNum); + } + + /** + * 计算清明节的日期(可计算范围: 1700-3100) + * + * @param year + * 需要计算的年份 + * @return 清明节在公历中的日期 + */ + private static int qing(int year) { + if (year == 2232) { + return 4; + } + if (year < 1700) { + throw new RuntimeException("1700年以前暂时不支持"); + } + if (year >= 3100) { + throw new RuntimeException("3100年以后暂时不支持"); + } + double[] coefficient = { 5.15, 5.37, 5.59, 4.82, 5.02, 5.26, 5.48, 4.70, 4.92, 5.135, 5.36, 4.60, 4.81, 5.04, + 5.26 }; + int mod = year % 100; + return (int) (mod * 0.2422 + coefficient[year / 100 - 17] - mod / 4); + } + + private static Map<String, Boolean> small(String ymd) { + int day = getWeekDay(ymd); + Map<String, Boolean> map = new HashMap<String, Boolean>(); + int[][] correction = { { 1 }, {}, { -1, -3 }, { -1, -2, -3, -4 }, { 1, 3 }, {}, { 2 } }; + // 6.取-1 2014年清明 2015年端午 6. 取2 2012年端午 + if (day > 0 && day < 6) { + map.put(ymd, true); + } + if (day == 3) { + map.put(addDay(ymd, -1), true); + map.put(addDay(ymd, -2), true); + map.put(addDay(ymd, -3), false); + map.put(addDay(ymd, -4), false); + } else { + boolean flag = true; + for (int i = 0; i < correction[day].length; i++) { + map.put(addDay(ymd, correction[day][i]), flag); + flag = false; + } + } + return map; + } + + private static Map<String, Boolean> gregorianNewYearSmall(String ymd) { + int day = getWeekDay(ymd); + Map<String, Boolean> map = new HashMap<String, Boolean>(); + int[][] correction = { { 1 }, {}, { 1, 2, 4, 5 }, {}, { 1, 2, 3 }, {}, { 2 } }; + // 6.取-1 2014年清明 2015年端午 6. 取2 2012年端午 0{+1}1{} 2{+1+2 +4b+5b} 3{} + // 4{+1,+2,+3b}5{}6{+2} + if (day > 0 && day < 6) { + map.put(ymd, true); + } + if (day == 2) { + map.put(addDay(ymd, 1), true); + map.put(addDay(ymd, 2), true); + map.put(addDay(ymd, 4), false); + map.put(addDay(ymd, 5), false); + } else if (day == 3) { + + } else if (day == 4) { + map.put(addDay(ymd, 1), true); + map.put(addDay(ymd, 3), false); + } else { + boolean flag = true; + for (int i = 0; i < correction[day].length; i++) { + map.put(addDay(ymd, correction[day][i]), flag); + flag = false; + } + } + return map; + } + + private static int getWeekDay(String ymd) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + Date date = null; + try { + date = sdf.parse(ymd); + } catch (ParseException e) { + e.printStackTrace(); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int day = calendar.get(Calendar.DAY_OF_WEEK) - 1; + return day; + } + + private static String convertGregorian(String ymd) {// private + String cnYmd = convertCnYmd(ymd); + int start = 18; + int len = 60;// 公历农历按最多相差60天计算。 + for (int i = start; i < start + len; i++) { + String gregorianDate = addDay(ymd, i); + String lunarDate = NongLi.getDate(gregorianDate); + if (cnYmd.equals(lunarDate)) { + return gregorianDate; + } + } + return null; + } + + private static String convertCnYmd(String ymd) {// private + String numArray = "零一二三四五六七八九十"; + String m = ymd.substring(4, 6); + String d = ymd.substring(6, 8); + int month = Integer.parseInt(m); + int day = Integer.parseInt(d); + String yearStr = ""; + for (int i = 0; i < 4; i++) { + yearStr += numArray.charAt(ymd.charAt(i) - '0') + ""; + } + yearStr += "年"; + String monthStr = ""; + if ("11".equals(m)) { + monthStr = "冬"; + } else if ("12".equals(m)) { + monthStr = "腊"; + } else if ("01".equals(m)) { + monthStr = "正"; + } else { + monthStr = numArray.charAt(month) + ""; + } + monthStr += "月"; + String dayStr = ""; + if (day <= 10) { + dayStr = "初" + numArray.charAt(day); + } else if (day < 20) { + dayStr = "十" + numArray.charAt(day - 10); + } else if (day == 20) { + dayStr = "二十"; + } else if (day == 30) { + dayStr = "三十"; + } else { + dayStr = "廿" + numArray.charAt(day - 20); + } + return yearStr + monthStr + dayStr; + } + + private static String addDay(String date, int dayLength) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + Date dateSrc = null; + try { + dateSrc = sdf.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + Calendar cal = Calendar.getInstance(); + cal.setTime(dateSrc); + cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + dayLength); + return sdf.format(cal.getTime()); + } + + private static String[] read(String fileName) { + BufferedReader br = null; + ArrayList<String> list = new ArrayList<String>(); + + try { + br = new BufferedReader( + new InputStreamReader(WorkUtils.class.getClassLoader().getResourceAsStream(fileName))); + String every = null; + while ((every = br.readLine()) != null) { + if (!every.startsWith("#")) { + list.add(every); + } + } + String[] datas = new String[list.size()]; + for (int i = 0; i < datas.length; i++) { + datas[i] = list.get(i); + } + return datas; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + + private static Map<String, Boolean> weekMapFromFile() { + Map<String, Boolean> map = new HashMap<String, Boolean>(); + String fileName = "iceweek.txt"; + String[] lines = WorkUtils.read(fileName); + for (String line : lines) { + if (line == null || line.length() != 9) { + continue; + } + String key = line.substring(0, 8); + Boolean value = convertWork(line.substring(8)); + map.put(key, value); + } + return map; + } + + private static Boolean convertWork(String str) { + if ("b".equals(str)) { + return false; + } else if ("x".equals(str)) { + return true; + } + return null; + } + + private static Map<String, Boolean> filterMap(Map<String, Boolean> map, int year) { + String yearStr = year + ""; + Map<String, Boolean> newMap = new HashMap<String, Boolean>(); + Set<Entry<String, Boolean>> entrySet = map.entrySet(); + for (Entry<String, Boolean> entry : entrySet) { + String key = entry.getKey(); + Boolean value = entry.getValue(); + if (key != null && key.startsWith(yearStr)) { + newMap.put(key, value); + } + } + return newMap; + } + + /** + * 提示语 + * @return 提示语 + */ + protected static String warn() { + return "注意:该算法对于将来的时间仅是预测,并不能完全精确。"; + } +} diff --git a/flower_city/src/main/java/com/dg/core/util/workday/WorkdayGen.java b/flower_city/src/main/java/com/dg/core/util/workday/WorkdayGen.java new file mode 100644 index 0000000..e279939 --- /dev/null +++ b/flower_city/src/main/java/com/dg/core/util/workday/WorkdayGen.java @@ -0,0 +1,74 @@ +package com.dg.core.util.workday; + +import com.iceyyy.workday.WorkUtils; + +import java.util.*; + +public class WorkdayGen { + + public static void main(String[] args) { + int year = 2021; + String code = genYearCode(year); + System.out.println(code); + } + + protected static String gen(int year) { + String yearStr = String.valueOf(year); + Map<String, Boolean> weekendMap = WorkUtils.weekendMap(yearStr); + Set<String> keySet = weekendMap.keySet(); + List<String> list = new ArrayList<>(keySet); + Collections.sort(list); + StringBuilder sb = new StringBuilder(); + for (String ymd : list) { + boolean weekendDay = WorkUtils.isWorkendDay(ymd); + String itemCode = genItemCode(ymd, weekendDay); + sb.append(itemCode); + } + return sb.toString(); + } + + private static String genItemCode(String ymd, boolean weekendDay) { + StringBuilder sb = new StringBuilder(); + String tab = " "; + String nl = "\r\n"; + sb.append(tab); + sb.append("map.put(\""); + sb.append(ymd); + sb.append("\", "); + sb.append(weekendDay); + sb.append("); // "); + sb.append(wordCode(weekendDay)); + sb.append(nl); + return sb.toString(); + } + + private static String wordCode(boolean weekday) { + if (weekday) { + return "休"; + } else { + return "班"; + } + } + + private static String genYearCode(int year) { + StringBuilder sb = new StringBuilder(); + String nl = "\r\n"; + sb.append("package com.iceyyy.icework.presence;" + nl); + sb.append("" + nl); + sb.append("import java.util.HashMap;" + nl); + sb.append("import java.util.Map;" + nl); + sb.append(""); + sb.append("public class Year" + year + " implements Year20xx {" + nl); + sb.append("" + nl); + sb.append(" @Override" + nl); + sb.append(" public Map<String, Boolean> getYearMap() {" + nl); + sb.append(" Map<String, Boolean> map = new HashMap<String, Boolean>();" + nl); + String gen = gen(year); + sb.append(gen); + sb.append(" return map;" + nl); + sb.append(" }" + nl); + sb.append("" + nl); + sb.append("}" + nl); + return sb.toString(); + } +} -- Gitblit v1.7.1