Browse Source

编写收入/成本数据导出模板

ljx 4 years ago
parent
commit
f9c30b2511

+ 1792 - 0
src/main/java/com/imed/costaccount/common/util/DateUtils.java

@@ -0,0 +1,1792 @@
+package com.imed.costaccount.common.util;
+
+import com.imed.costaccount.enums.DateStyleEnum;
+import com.imed.costaccount.enums.WeekEnum;
+import lombok.extern.slf4j.Slf4j;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Slf4j
+public class DateUtils {
+    public static final SimpleDateFormat DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    public static final SimpleDateFormat monthSdf = new SimpleDateFormat("yyyy-MM");
+    public static final SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
+    public static final SimpleDateFormat DATE_FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
+
+    /**
+     * 通用的一个DateFormat
+     */
+    public final static SimpleDateFormat commonDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+    /**
+     * 处理时分秒的DateFormat
+     */
+    public final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+    /**
+     * 不显示秒的DateFormat
+     */
+    public final static SimpleDateFormat noSecondFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+
+    /**
+     * 获取SimpleDateFormat
+     *
+     * @param parttern 日期格式
+     * @return SimpleDateFormat对象
+     * @throws RuntimeException 异常:非法日期格式
+     */
+    private static SimpleDateFormat getDateFormat(String parttern) throws RuntimeException {
+        return new SimpleDateFormat(parttern);
+    }
+
+    /**
+     * 获取日期中的某数值。如获取月份
+     *
+     * @param date     日期
+     * @param dateType 日期格式
+     * @return 数值
+     */
+    public static int getInteger(Date date, int dateType) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(dateType);
+    }
+
+    /**
+     * 当前时间转换.
+     *
+     * @return 时间字符串
+     */
+    public static String getDateString() {
+        Date date = new Date();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+        String strDate = sdf.format(date);
+        return strDate;
+    }
+
+    /**
+     * 获取时间的字符串
+     *
+     * @param date
+     * @param simpleDateFormat
+     * @return 时间字符串
+     */
+    public static String getDateString(Date date, SimpleDateFormat simpleDateFormat) {
+        String strDate = simpleDateFormat.format(date);
+        return strDate;
+    }
+
+    /**
+     * 增加日期中某类型的某数值。如增加日期
+     *
+     * @param date     日期字符串
+     * @param dateType 类型
+     * @param amount   数值
+     * @return 计算后日期字符串
+     */
+    private static String addInteger(String date, int dateType, int amount) {
+        String dateString = null;
+        DateStyleEnum dateStyle = getDateStyle(date);
+        if (dateStyle != null) {
+            Date myDate = StringToDate(date, dateStyle);
+            myDate = addInteger(myDate, dateType, amount);
+            dateString = DateToString(myDate, dateStyle);
+        }
+        return dateString;
+    }
+
+    /**
+     * 增加日期中某类型的某数值。如增加日期
+     *
+     * @param date     日期字符串
+     * @param dateType 类型
+     * @param amount   数值
+     * @return 计算后日期字符串
+     */
+    private static String addInteger(String date, DateStyleEnum dateStyle, int dateType, int amount) {
+        String dateString = null;
+        if (dateStyle != null) {
+            Date myDate = StringToDate(date, dateStyle);
+            myDate = addInteger(myDate, dateType, amount);
+            dateString = DateToString(myDate, dateStyle);
+        }
+        return dateString;
+    }
+
+    /**
+     * 增加日期中某类型的某数值。如增加日期
+     *
+     * @param date     日期
+     * @param dateType 类型
+     * @param amount   数值
+     * @return 计算后日期
+     */
+    private static Date addInteger(Date date, int dateType, int amount) {
+        Date myDate = null;
+        if (date != null) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.add(dateType, amount);
+            myDate = calendar.getTime();
+        }
+        return myDate;
+    }
+
+    /**
+     * 获取本周开始时间
+     *
+     * @param date
+     *
+     * @return
+     */
+    public static Date getBeginDayOfWeek(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
+        if (dayofweek == 1) {
+            dayofweek += 7;
+        }
+        cal.add(Calendar.DATE, 2 - dayofweek);
+        return getDayStartTime(cal.getTime());
+    }
+
+    /**
+     * 获取某个日期的开始时间
+     *
+     * @param date
+     *
+     * @return
+     */
+    public static Timestamp getDayStartTime(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        if (null != date) {
+            calendar.setTime(date);
+        }
+        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        calendar.set(Calendar.MILLISECOND, 0);
+        return new Timestamp(calendar.getTimeInMillis());
+    }
+
+    /**
+     * 获取本周结束时间
+     *
+     * @param date
+     *
+     * @return
+     */
+    public static Date getEndDayOfWeek(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getBeginDayOfWeek(date));
+        cal.add(Calendar.DAY_OF_WEEK, 6);
+        Date weekEndSta = cal.getTime();
+        return getDayEndTime(weekEndSta);
+    }
+
+    /**
+     * 获取某个日期的结束时间
+     *
+     * @param date
+     *
+     * @return
+     */
+    private static Date getDayEndTime(Date date) {
+        Calendar calendar = Calendar.getInstance();
+         if(null != date){
+             calendar.setTime(date);
+         }
+         calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),    calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
+         calendar.set(Calendar.MILLISECOND, 999);
+         return new Timestamp(calendar.getTimeInMillis());
+    }
+
+    /**
+     * 获取精确的日期
+     *
+     * @param timestamps 时间long集合
+     * @return 日期
+     */
+    private static Date getAccurateDate(List<Long> timestamps) {
+        Date date = null;
+        long timestamp = 0;
+        Map<Long, long[]> map = new HashMap<Long, long[]>();
+        List<Long> absoluteValues = new ArrayList<Long>();
+        if (timestamps != null && timestamps.size() > 0) {
+            if (timestamps.size() > 1) {
+                for (int i = 0; i < timestamps.size(); i++) {
+                    for (int j = i + 1; j < timestamps.size(); j++) {
+                        long absoluteValue = Math.abs(timestamps.get(i) - timestamps.get(j));
+                        absoluteValues.add(absoluteValue);
+                        long[] timestampTmp = {timestamps.get(i), timestamps.get(j)};
+                        map.put(absoluteValue, timestampTmp);
+                    }
+                }
+                // 有可能有相等的情况。如2012-11和2012-11-01。时间戳是相等的
+                long minAbsoluteValue = -1;
+                if (!absoluteValues.isEmpty()) {
+                    // 如果timestamps的size为2,这是差值只有一个,因此要给默认值
+                    minAbsoluteValue = absoluteValues.get(0);
+                }
+                for (int i = 0; i < absoluteValues.size(); i++) {
+                    for (int j = i + 1; j < absoluteValues.size(); j++) {
+                        if (minAbsoluteValue > absoluteValues.get(j)) {
+                            minAbsoluteValue = absoluteValues.get(j);
+                        }
+                    }
+                }
+                if (minAbsoluteValue != -1) {
+                    long[] timestampsLastTmp = map.get(minAbsoluteValue);
+                    if (absoluteValues.size() > 1) {
+                        timestamp = Math.max(timestampsLastTmp[0], timestampsLastTmp[1]);
+                    } else if (absoluteValues.size() == 1) {
+                        // 当timestamps的size为2,需要与当前时间作为参照
+                        long dateOne = timestampsLastTmp[0];
+                        long dateTwo = timestampsLastTmp[1];
+                        if ((Math.abs(dateOne - dateTwo)) < 100000000000L) {
+                            timestamp = Math.max(timestampsLastTmp[0], timestampsLastTmp[1]);
+                        } else {
+                            long now = new Date().getTime();
+                            if (Math.abs(dateOne - now) <= Math.abs(dateTwo - now)) {
+                                timestamp = dateOne;
+                            } else {
+                                timestamp = dateTwo;
+                            }
+                        }
+                    }
+                }
+            } else {
+                timestamp = timestamps.get(0);
+            }
+        }
+        if (timestamp != 0) {
+            date = new Date(timestamp);
+        }
+        return date;
+    }
+
+    /**
+     * 判断字符串是否为日期字符串
+     *
+     * @param date 日期字符串
+     * @return true or false
+     */
+    public static boolean isDate(String date) {
+        boolean isDate = false;
+        if (date != null) {
+            if (StringToDate(date) != null) {
+                isDate = true;
+            }
+        }
+        return isDate;
+    }
+
+
+    /**
+     * 获取日期字符串的日期风格。失敗返回null。
+     *
+     * @param date 日期字符串
+     * @return 日期风格
+     */
+    public static DateStyleEnum getDateStyle(String date) {
+        DateStyleEnum dateStyle = null;
+        Map<Long, DateStyleEnum> map = new HashMap<Long, DateStyleEnum>();
+        List<Long> timestamps = new ArrayList<Long>();
+        for (DateStyleEnum style : DateStyleEnum.values()) {
+            Date dateTmp = StringToDate(date, style.getValue());
+            if (dateTmp != null) {
+                timestamps.add(dateTmp.getTime());
+                map.put(dateTmp.getTime(), style);
+            }
+        }
+        dateStyle = map.get(getAccurateDate(timestamps).getTime());
+        return dateStyle;
+    }
+
+    /**
+     * 将日期字符串转化为日期。失败返回null。
+     *
+     * @param date 日期字符串
+     * @return 日期
+     */
+    public static Date StringToDate(String date) {
+        DateStyleEnum dateStyle = null;
+        return StringToDate(date, dateStyle);
+    }
+
+    /**
+     * 将日期字符串转化为日期。失败返回null。
+     *
+     * @param date     日期字符串
+     * @param parttern 日期格式
+     * @return 日期
+     */
+    public static Date StringToDate(String date, String parttern) {
+        Date myDate = null;
+        if (date != null) {
+            try {
+                myDate = getDateFormat(parttern).parse(date);
+            } catch (Exception e) {
+            }
+        }
+        return myDate;
+    }
+
+
+    /**
+     * 将日期字符串转化为日期。失败返回null。
+     *
+     * @param date      日期字符串
+     * @param dateStyle 日期风格
+     * @return 日期
+     */
+    public static Date StringToDate(String date, DateStyleEnum dateStyle) {
+        Date myDate = null;
+        if (dateStyle == null) {
+            List<Long> timestamps = new ArrayList<Long>();
+            for (DateStyleEnum style : DateStyleEnum.values()) {
+                Date dateTmp = StringToDate(date, style.getValue());
+                if (dateTmp != null) {
+                    timestamps.add(dateTmp.getTime());
+                }
+            }
+            myDate = getAccurateDate(timestamps);
+        } else {
+            myDate = StringToDate(date, dateStyle.getValue());
+        }
+        return myDate;
+    }
+
+    /**
+     * 将日期转化为日期字符串。失败返回null。
+     *
+     * @param date     日期
+     * @param parttern 日期格式
+     * @return 日期字符串
+     */
+    public static String DateToString(Date date, String parttern) {
+        String dateString = null;
+        if (date != null) {
+            try {
+                dateString = getDateFormat(parttern).format(date);
+            } catch (Exception e) {
+            }
+        }
+        return dateString;
+    }
+
+    /**
+     * 将日期转化为日期字符串。失败返回null。
+     *
+     * @param date      日期
+     * @param dateStyle 日期风格
+     * @return 日期字符串
+     */
+    public static String DateToString(Date date, DateStyleEnum dateStyle) {
+        String dateString = null;
+        if (dateStyle != null) {
+            dateString = DateToString(date, dateStyle.getValue());
+        }
+        return dateString;
+    }
+
+    /**
+     * 将日期字符串转化为另一日期字符串。失败返回null。
+     *
+     * @param date     旧日期字符串
+     * @param parttern 新日期格式
+     * @return 新日期字符串
+     */
+    public static String StringToString(String date, String parttern) {
+        return StringToString(date, null, parttern);
+    }
+
+    /**
+     * 将日期字符串转化为另一日期字符串。失败返回null。
+     *
+     * @param date      旧日期字符串
+     * @param dateStyle 新日期风格
+     * @return 新日期字符串
+     */
+    public static String StringToString(String date, DateStyleEnum dateStyle) {
+        return StringToString(date, null, dateStyle);
+    }
+
+    /**
+     * 将日期字符串转化为另一日期字符串。失败返回null。
+     *
+     * @param date         旧日期字符串
+     * @param olddParttern 旧日期格式
+     * @param newParttern  新日期格式
+     * @return 新日期字符串
+     */
+    public static String StringToString(String date, String olddParttern, String newParttern) {
+        String dateString = null;
+        if (olddParttern == null) {
+            DateStyleEnum style = getDateStyle(date);
+            if (style != null) {
+                Date myDate = StringToDate(date, style.getValue());
+                dateString = DateToString(myDate, newParttern);
+            }
+        } else {
+            Date myDate = StringToDate(date, olddParttern);
+            dateString = DateToString(myDate, newParttern);
+        }
+        return dateString;
+    }
+
+    /**
+     * 将日期字符串转化为另一日期字符串。失败返回null。
+     *
+     * @param date         旧日期字符串
+     * @param olddDteStyle 旧日期风格
+     * @param newDateStyle 新日期风格
+     * @return 新日期字符串
+     */
+    public static String StringToString(String date, DateStyleEnum olddDteStyle, DateStyleEnum newDateStyle) {
+        String dateString = null;
+        if (olddDteStyle == null) {
+            DateStyleEnum style = getDateStyle(date);
+            dateString = StringToString(date, style.getValue(), newDateStyle.getValue());
+        } else {
+            dateString = StringToString(date, olddDteStyle.getValue(), newDateStyle.getValue());
+        }
+        return dateString;
+    }
+
+    /**
+     * 增加日期的年份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return 增加年份后的日期字符串
+     */
+    public static String addYear(String date, int yearAmount) {
+        return addInteger(date, Calendar.YEAR, yearAmount);
+    }
+
+    /**
+     * 增加日期的年份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return 增加年份后的日期
+     */
+    public static Date addYear(Date date, int yearAmount) {
+        return addInteger(date, Calendar.YEAR, yearAmount);
+    }
+
+    /**
+     * 增加日期的月份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return 增加月份后的日期字符串
+     */
+    public static String addMonth(String date, int yearAmount) {
+        return addInteger(date, Calendar.MONTH, yearAmount);
+    }
+
+    /**
+     * 增加日期的月份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return 增加月份后的日期
+     */
+    public static Date addMonth(Date date, int yearAmount) {
+        return addInteger(date, Calendar.MONTH, yearAmount);
+    }
+
+    /**
+     * 增加日期的天数。失败返回null。
+     *
+     * @param date      日期字符串
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期字符串
+     * @deprecated use {@link #addDay(String, int, DateStyleEnum)}
+     */
+    @Deprecated
+    public static String addDay(String date, int dayAmount) {
+        return addInteger(date, Calendar.DATE, dayAmount);
+    }
+
+    /**
+     * 增加日期的天数。失败返回null。
+     *
+     * @param date      日期字符串
+     * @param dayAmount 增加数量。可为负数
+     * @param style     日期样式
+     * @return 增加天数后的日期字符串
+     */
+    public static String addDay(String date, int dayAmount, DateStyleEnum style) {
+        return addInteger(date, style, Calendar.DATE, dayAmount);
+    }
+
+    /**
+     * 增加日期的天数。失败返回null。
+     *
+     * @param date      日期
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期
+     */
+    public static Date addDay(Date date, int dayAmount) {
+        return addInteger(date, Calendar.DATE, dayAmount);
+    }
+
+    /**
+     * 增加日期的小时。失败返回null。
+     *
+     * @param date       日期字符串
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加小时后的日期字符串
+     */
+    public static String addHour(String date, int hourAmount) {
+        return addInteger(date, Calendar.HOUR_OF_DAY, hourAmount);
+    }
+
+    /**
+     * 增加日期的小时。失败返回null。
+     *
+     * @param date       日期
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加小时后的日期
+     */
+    public static Date addHour(Date date, int hourAmount) {
+        return addInteger(date, Calendar.HOUR_OF_DAY, hourAmount);
+    }
+
+    /**
+     * 增加日期的分钟。失败返回null。
+     *
+     * @param date       日期字符串
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加分钟后的日期字符串
+     */
+    public static String addMinute(String date, int hourAmount) {
+        return addInteger(date, Calendar.MINUTE, hourAmount);
+    }
+
+    /**
+     * 增加日期的分钟。失败返回null。
+     *
+     * @param date       日期
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加分钟后的日期
+     */
+    public static Date addMinute(Date date, int hourAmount) {
+        return addInteger(date, Calendar.MINUTE, hourAmount);
+    }
+
+    /**
+     * 增加日期的秒钟。失败返回null。
+     *
+     * @param date       日期字符串
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加秒钟后的日期字符串
+     */
+    public static String addSecond(String date, int hourAmount) {
+        return addInteger(date, Calendar.SECOND, hourAmount);
+    }
+
+    /**
+     * 增加日期的秒钟。失败返回null。
+     *
+     * @param date       日期
+     * @param hourAmount 增加数量。可为负数
+     * @return 增加秒钟后的日期
+     */
+    public static Date addSecond(Date date, int hourAmount) {
+        return addInteger(date, Calendar.SECOND, hourAmount);
+    }
+
+    /**
+     * 获取日期的年份。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 年份
+     */
+    public static int getYear(String date) {
+        return getYear(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的年份。失败返回0。
+     *
+     * @param date 日期
+     * @return 年份
+     */
+    public static int getYear(Date date) {
+        return getInteger(date, Calendar.YEAR);
+    }
+
+    /**
+     * 获取日期的月份。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 月份
+     */
+    public static int getMonth(String date) {
+        return getMonth(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的月份
+     *
+     * @param date 日期字符串
+     * @return 月份
+     */
+    public static String getMonthStr(Date date) {
+        return monthSdf.format(date);
+    }
+
+    /**
+     * 获取日期的月份。失败返回0。
+     *
+     * @param date 日期
+     * @return 月份
+     */
+    public static int getMonth(Date date) {
+        return getInteger(date, Calendar.MONTH);
+    }
+
+    /**
+     * 获取日期的天数。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 天
+     */
+    public static int getDay(String date) {
+        return getDay(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的天数。失败返回0。
+     *
+     * @param date 日期
+     * @return 天
+     */
+    public static int getDay(Date date) {
+        return getInteger(date, Calendar.DATE);
+    }
+
+    /**
+     * 获取日期的小时。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 小时
+     */
+    public static int getHour(String date) {
+        return getHour(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的小时。失败返回0。
+     *
+     * @param date 日期
+     * @return 小时
+     */
+    public static int getHour(Date date) {
+        return getInteger(date, Calendar.HOUR_OF_DAY);
+    }
+
+    /**
+     * 获取日期的分钟。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 分钟
+     */
+    public static int getMinute(String date) {
+        return getMinute(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的分钟。失败返回0。
+     *
+     * @param date 日期
+     * @return 分钟
+     */
+    public static int getMinute(Date date) {
+        return getInteger(date, Calendar.MINUTE);
+    }
+
+    /**
+     * 获取日期的秒钟。失败返回0。
+     *
+     * @param date 日期字符串
+     * @return 秒钟
+     */
+    public static int getSecond(String date) {
+        return getSecond(StringToDate(date));
+    }
+
+    /**
+     * 获取日期的秒钟。失败返回0。
+     *
+     * @param date 日期
+     * @return 秒钟
+     */
+    public static int getSecond(Date date) {
+        return getInteger(date, Calendar.SECOND);
+    }
+
+    /**
+     * 获取日期 。默认yyyy-MM-dd格式。失败返回null。
+     *
+     * @param date 日期字符串
+     * @return 日期
+     */
+    public static String getDate(String date) {
+        return StringToString(date, DateStyleEnum.YYYY_MM_DD);
+    }
+
+    /**
+     * 获取日期。默认yyyy-MM-dd格式。失败返回null。
+     *
+     * @param date 日期
+     * @return 日期
+     */
+    public static String getDate(Date date) {
+        return DateToString(date, DateStyleEnum.YYYY_MM_DD);
+    }
+
+    /**
+     * 获取日期。默认yyyy-MM-dd HH:mm:ss格式。失败返回null。
+     *
+     * @param date 日期
+     * @return 日期
+     */
+    public static String getDateTime(Date date) {
+        return DateToString(date, DateStyleEnum.YYYY_MM_DD_HH_MM_SS);
+    }
+
+    /**
+     * 获取日期。默认yyyy-MM-dd HH:mm格式。失败返回null。
+     *
+     * @param date 日期
+     * @return 日期
+     */
+    public static String getDateTimeExcludeSec(Date date) {
+        return DateToString(date, DateStyleEnum.YYYY_MM_DD_HH_MM);
+    }
+
+    /**
+     * 获取日期。默认yyyy-MM-dd HH:mm格式。失败返回null。
+     *
+     * @param date 日期
+     * @return 日期
+     */
+    public static Date getDateTimeExcludeSec(String date) {
+        return StringToDate(date, DateStyleEnum.YYYY_MM_DD_HH_MM);
+    }
+
+    /**
+     * 获取日期的时间。默认HH:mm:ss格式。失败返回null。
+     *
+     * @param date 日期字符串
+     * @return 时间
+     */
+    public static String getTime(String date) {
+        return StringToString(date, DateStyleEnum.HH_MM_SS);
+    }
+
+    /**
+     * 获取日期的时间。默认HH:mm:ss格式。失败返回null。
+     *
+     * @param date 日期
+     * @return 时间
+     */
+    public static String getTime(Date date) {
+        return DateToString(date, DateStyleEnum.HH_MM_SS);
+    }
+
+    /**
+     * 获取日期的星期。失败返回null。
+     *
+     * @param date 日期字符串
+     * @return 星期
+     */
+    public static WeekEnum getWeek(String date) {
+        WeekEnum week = null;
+        DateStyleEnum dateStyle = getDateStyle(date);
+        if (dateStyle != null) {
+            Date myDate = StringToDate(date, dateStyle);
+            week = getWeek(myDate);
+        }
+        return week;
+    }
+
+    /**
+     * 获取日期的星期。失败返回null。
+     *
+     * @param date 日期
+     * @return 星期
+     */
+    public static WeekEnum getWeek(Date date) {
+        WeekEnum week = null;
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        int weekNumber = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+        switch (weekNumber) {
+            case 0:
+                week = WeekEnum.SUNDAY;
+                break;
+            case 1:
+                week = WeekEnum.MONDAY;
+                break;
+            case 2:
+                week = WeekEnum.TUESDAY;
+                break;
+            case 3:
+                week = WeekEnum.WEDNESDAY;
+                break;
+            case 4:
+                week = WeekEnum.THURSDAY;
+                break;
+            case 5:
+                week = WeekEnum.FRIDAY;
+                break;
+            case 6:
+                week = WeekEnum.SATURDAY;
+                break;
+        }
+        return week;
+    }
+
+    /**
+     * 获取两个日期相差的天数
+     *
+     * @param date      日期字符串
+     * @param otherDate 另一个日期字符串
+     * @return 相差天数
+     */
+    public static int getIntervalDays(String date, String otherDate) {
+        return getIntervalDays(StringToDate(date), StringToDate(otherDate));
+    }
+
+    /**
+     * @param date      日期
+     * @param otherDate 另一个日期mingt
+     * @return 相差天数
+     */
+    public static int getIntervalDays(Date date, Date otherDate) {
+        //date = DateUtil.StringToDate(DateUtil.getDate(date));
+        long time = Math.abs(date.getTime() - otherDate.getTime());
+        long day = time / (24 * 60 * 60 * 1000);
+        return (int) day;
+    }
+
+
+    /**
+     * @param date
+     * @param otherDate
+     * @return 相差年数
+     */
+    public static long getIntervalYear(Date date, Date otherDate) {
+        Calendar cal = Calendar.getInstance();
+        int yearNow = cal.get(Calendar.YEAR);
+        cal.setTime(otherDate);
+        int yearOther = cal.get(Calendar.YEAR);
+        long year = yearNow - yearOther;
+        return year;
+    }
+
+    /**
+     * 获取月份差
+     *
+     * @param date
+     * @param otherDate
+     * @return
+     */
+    public static long getIntervalMonths(Date date, Date otherDate) {
+        long months;
+        Calendar cal = Calendar.getInstance();
+        int yearNow = cal.get(Calendar.YEAR);
+        int monthNow = cal.get(Calendar.MONTH);
+        cal.setTime(otherDate);
+        int yearOther = cal.get(Calendar.YEAR);
+        int monthOther = cal.get(Calendar.MONTH);
+        long year = yearNow - yearOther;
+        if (year >= 1) {
+            months = year * 12 + monthNow - monthOther;
+        } else {
+            months = monthNow - monthOther;
+        }
+
+
+        return months;
+    }
+
+    public static String getWeekFromDate(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        int week = c.get(Calendar.DAY_OF_WEEK);
+        switch (week) {
+            case 1:
+                return "星期日";
+            case 2:
+                return "星期一";
+            case 3:
+                return "星期二";
+            case 4:
+                return "星期三";
+            case 5:
+                return "星期四";
+            case 6:
+                return "星期五";
+            case 7:
+                return "星期六";
+            default:
+                return "";
+        }
+    }
+
+    /**
+     * 获取指定天数之前的时间(相对于当前天数)
+     *
+     * @param currentDate 当前时间
+     * @param dayNo       当前时间的几天之前
+     * @return
+     * @Title: getLastDays
+     * @date 2014-3-26 下午11:23:57
+     * @author Lawrence
+     */
+    public static Date getLastTimeForDays(Date currentDate, Integer dayNo) {
+        if (null == currentDate || null == dayNo) {
+            return null;
+        }
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.DATE, -dayNo);
+        return c.getTime();
+    }
+
+    /**
+     * 获取指定月数之前的时间(相对于当前天数)
+     *
+     * @param currentDate 当前时间
+     * @param monthNo     当前时间的几月之前
+     * @return
+     * @Title: getLastDays
+     * @date 2014-3-26 下午11:23:57
+     * @author Lawrence
+     */
+    public static Date getLastTimeForMonths(Date currentDate, Integer monthNo) {
+        if (null == currentDate || null == monthNo) {
+            return null;
+        }
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.MONTH, -monthNo);
+        return c.getTime();
+    }
+
+    /**
+     * 获取指定月数之前的时间(相对于当前天数)
+     *
+     * @param currentDate 当前时间
+     * @param yearNo      当前时间的几年之前
+     * @return
+     * @Title: getLastDays
+     * @date 2014-3-26 下午11:23:57
+     * @author Lawrence
+     */
+    public static Date getLastTimeForYears(Date currentDate, Integer yearNo) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(currentDate);
+        c.add(Calendar.YEAR, -yearNo);
+        return c.getTime();
+    }
+
+
+    /**
+     * 获取当天00:00:00
+     *
+     * @param currentDate
+     * @return
+     * @Title: getZeroPoint
+     * @Description: (这里用一句话描述这个方法的作用)
+     * @date 2014年10月10日 上午11:09:35
+     * @author Administrator
+     */
+    public static Date getZeroPoint(Date currentDate) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(currentDate);
+        cal.set(Calendar.HOUR_OF_DAY, 0); // 把当前时间小时变成0
+        cal.set(Calendar.MINUTE, 0); // 把当前时间分钟变成0
+        cal.set(Calendar.SECOND, 0); // 把当前时间秒数变成0
+        cal.set(Calendar.MILLISECOND, 0); // 把当前时间毫秒变成0
+        return cal.getTime();
+    }
+
+    /**
+     * 获取当天00:00:00
+     *
+     * @param currentDate
+     * @return
+     * @Title: getZeroPoint
+     * @Description: (这里用一句话描述这个方法的作用)
+     * @date 2014年10月10日 上午11:09:35
+     * @author Administrator
+     */
+    public static Date getZeroPoint(String currentDate) {
+        return getZeroPoint(DateUtils.StringToDate(currentDate, DateStyleEnum.YYYY_MM_DD));
+    }
+
+    /**
+     * 获取日期的最后一秒时间
+     *
+     * @param currentDate
+     * @return
+     */
+    public static Date getLastPoint(String currentDate) {
+        return getLastPoint(DateUtils.StringToDate(currentDate, DateStyleEnum.YYYY_MM_DD));
+    }
+
+    /**
+     * 获取日期的最后一秒时间
+     *
+     * @param currentDate
+     * @return
+     */
+    public static Date getLastPoint(Date currentDate) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(currentDate);
+        cal.set(Calendar.HOUR_OF_DAY, 23); // 把当前时间小时变成
+        cal.set(Calendar.MINUTE, 59); // 把当前时间分钟变成
+        cal.set(Calendar.SECOND, 59); // 把当前时间秒数变成
+        return cal.getTime();
+    }
+
+
+    /**
+     * 获取指定分钟最后一秒时间
+     *
+     * @param currentDate
+     * @return
+     */
+    public static Date getDateEndTime(Date currentDate) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(currentDate);
+        cal.set(Calendar.SECOND, 59); // 把当前时间秒数变成
+        return cal.getTime();
+    }
+
+    /**
+     * 获取指定分钟最后一秒时间
+     *
+     * @param currentDate
+     * @return
+     */
+    public static Date getDateBegTime(Date currentDate) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(currentDate);
+        cal.set(Calendar.SECOND, 00); // 把当前时间秒数变成
+        return cal.getTime();
+    }
+
+    /**
+     * 时间比较大小工具类
+     *
+     * @param date1
+     * @param date2
+     * @return
+     */
+    public static Boolean compareDate(Date date1, Date date2) {
+        try {
+            if (date1.getTime() >= date2.getTime()) {
+                return true;
+            } else if (date1.getTime() < date2.getTime()) {
+                return false;
+            }
+        } catch (Exception e) {
+            log.error(e.toString(), e);
+        }
+        return false;
+    }
+
+    /**
+     * 把毫秒转化成日期
+     *
+     * @param millSec(毫秒数)
+     * @return
+     */
+    public static Date LongToDate(Long millSec) {
+        return LongToDate(millSec, "yyyy-MM-dd HH:mm:ss");
+    }
+
+    /**
+     * 把毫秒转化成日期
+     *
+     * @param parttern(日期格式,例如:MM/ dd/yyyy HH:mm:ss)
+     * @param millSec(毫秒数)
+     * @return
+     */
+    public static Date LongToDate(Long millSec, String parttern) {
+        return new Date(millSec);
+    }
+
+/*    public static void main(String[] args){
+//    	Long currentTime = System.currentTimeMillis();
+//    	System.out.println(LongToDate(currentTime));
+    	
+        // Date currentDate = new Date();
+        // currentDate = getZeroPoint(currentDate);
+        // //得到一天前
+        // Date dd = getLastTimeForDays(currentDate, 1);
+        // System.out.println(dd.toLocaleString());
+        // //得到前一周
+        // Date dw = getLastTimeForDays(currentDate, 7);
+        // System.out.println(dw.toLocaleString());
+        // //得到前一个月
+        // Date dm = getLastTimeForMonths(currentDate, 1);
+        // System.out.println(dm.toLocaleString());
+        // //得到前一年
+        // Date dy = getLastTimeForYears(currentDate, 1);
+        // System.out.println(dy.toLocaleString());
+        String date = DateToString(new Date(), "yyyyMMddHHmmss");
+        System.out.println(date);
+        System.out.println(getZeroPoint(new Date()));
+    }*/
+
+    /**
+     * 截取时间getTime的后N位
+     *
+     * @param time 时间
+     * @return
+     * @Title: getTimeToSix
+     * @date 2016年9月21日 下午5:14:00
+     * @author Chris_He
+     */
+    public static String getTimeToNumber(Date time, Integer n) {
+        String s = String.valueOf(time.getTime());
+        return s.substring(s.length() - n, s.length());
+    }
+
+    /**
+     * 获取当前时间上下午
+     *
+     * @return
+     * @Title: getNowDateAmPm
+     * @date 2017年8月29日 下午5:08:37
+     * @author Chris_He
+     */
+    public static DateStyleEnum getNowDateAmPm() {
+        GregorianCalendar ca = new GregorianCalendar();
+        int i = ca.get(GregorianCalendar.AM_PM);
+        if (i == 0) {
+            return DateStyleEnum.AM;
+        } else {
+            return DateStyleEnum.PM;
+        }
+    }
+
+    public static Date getAfterMinuteDate(Date date, int amount) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.MINUTE, amount);
+        date = cal.getTime();
+//        String theDate = sdf.format(date);
+        return date;
+    }
+
+    public static Date getAfterSecondDate(Date date, int amount) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.SECOND, amount);
+        date = cal.getTime();
+//        String theDate = sdf.format(date);
+        return date;
+    }
+
+    public static String formatFull(Date date) {
+        if (date != null) {
+            return DATE_FORMAT_YYYY_MM_DD_HH_MM_SS.format(date);
+        }
+        return null;
+    }
+
+    /**
+     * 获取下一天00:00:00
+     *
+     * @return
+     * @Title: getNextDay
+     * @date 2018年12月22日 下午5:08:37
+     * @author Chris_He
+     */
+    public static Date getNextDay(Date date) {
+        return addDay(StringToDate(DateToString(date, DateStyleEnum.YYYY_MM_DD), DateStyleEnum.YYYY_MM_DD), 1);
+    }
+
+    public static void main(String[] args) {
+//        System.out.println(DateUtil.getYear(new Date()));
+        System.out.println(getHour("7:00"));
+    }
+
+
+    /**
+     * 获取下一天指定时间
+     *
+     * @return
+     * @Title: getNextDay
+     * @date 2018年12月22日 下午5:08:37
+     * @author Chris_He
+     */
+    public static Date getNextDayHour(Date date, int hour, int amount) {
+        Date myDate = null;
+        if (date != null) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.add(Calendar.DATE, amount);
+            calendar.set(Calendar.HOUR_OF_DAY, hour); // 把当前时间小时变成0
+            calendar.set(Calendar.MINUTE, 0); // 把当前时间分钟变成0
+            calendar.set(Calendar.SECOND, 0); // 把当前时间秒数变成0
+            calendar.set(Calendar.MILLISECOND, 0); // 把当前时间毫秒变成0
+            myDate = calendar.getTime();
+        }
+        return myDate;
+    }
+
+    /**
+     * 获取yyyy-MM
+     *
+     * @return
+     */
+    public static String getMonthStr() {
+        return monthSdf.format(new Date());
+    }
+
+    /**
+     * 获取时间范围内所有天数 yyyy-MM-dd
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Date> getDayList(String startDate, String endDate) {
+        Date dBegin = getZeroPoint(startDate);
+        Date dEnd = getZeroPoint(endDate);
+        List<Date> dateList = new ArrayList<>();
+        Calendar calBegin = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calBegin.setTime(dBegin);
+        Calendar calEnd = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calEnd.setTime(dEnd);
+        // 此日期是否在指定日期之后
+        dateList.add(dBegin);
+        while (dEnd.after(calBegin.getTime())) {
+            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
+            calBegin.add(Calendar.DAY_OF_MONTH, 1);
+            dateList.add(calBegin.getTime());
+        }
+        return dateList;
+    }
+
+    /**
+     * 获取时间范围内所有天 yyyy-MM-dd
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Date> getDayList(Date startDate, Date endDate) {
+        Date dBegin = getZeroPoint(startDate);
+        Date dEnd = getZeroPoint(endDate);
+        List<Date> dateList = new ArrayList<>();
+        Calendar calBegin = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calBegin.setTime(dBegin);
+        Calendar calEnd = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calEnd.setTime(dEnd);
+        // 此日期是否在指定日期之后
+        dateList.add(dBegin);
+        while (dEnd.after(calBegin.getTime())) {
+            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
+            calBegin.add(Calendar.DAY_OF_MONTH, 1);
+            dateList.add(calBegin.getTime());
+        }
+        return dateList;
+    }
+
+    /**
+     * 获取时间范围内所有天 yyyy-MM-dd
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<String> getDayStrList(Date startDate, Date endDate) {
+        Date dBegin = getZeroPoint(startDate);
+        Date dEnd = getZeroPoint(endDate);
+        List<String> dateList = new ArrayList<>();
+        Calendar calBegin = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calBegin.setTime(dBegin);
+        Calendar calEnd = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calEnd.setTime(dEnd);
+        // 此日期是否在指定日期之后
+        dateList.add(getDate(dBegin));
+        while (dEnd.after(calBegin.getTime())) {
+            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
+            calBegin.add(Calendar.DAY_OF_MONTH, 1);
+            dateList.add(getDate(calBegin.getTime()));
+        }
+        return dateList;
+    }
+
+    /**
+     * 获取某个时间段内所有月份
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Date> getMonthList(String startDate, String endDate) {
+        List<Date> result = new ArrayList<>();
+        Calendar min = Calendar.getInstance();
+        Calendar max = Calendar.getInstance();
+        min.setTime(StringToDate(startDate, DateStyleEnum.YYYY_MM));
+        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
+        max.setTime(StringToDate(endDate, DateStyleEnum.YYYY_MM));
+        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
+        Calendar curr = min;
+        while (curr.before(max)) {
+            result.add(curr.getTime());
+            curr.add(Calendar.MONTH, 1);
+        }
+        return result;
+    }
+
+    /**
+     * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
+     *
+     * @param date
+     * @return
+     */
+    public static int getSeason(Date date) {
+
+        int season = 0;
+
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        int month = c.get(Calendar.MONTH);
+        switch (month) {
+            case Calendar.JANUARY:
+            case Calendar.FEBRUARY:
+            case Calendar.MARCH:
+                season = 1;
+                break;
+            case Calendar.APRIL:
+            case Calendar.MAY:
+            case Calendar.JUNE:
+                season = 2;
+                break;
+            case Calendar.JULY:
+            case Calendar.AUGUST:
+            case Calendar.SEPTEMBER:
+                season = 3;
+                break;
+            case Calendar.OCTOBER:
+            case Calendar.NOVEMBER:
+            case Calendar.DECEMBER:
+                season = 4;
+                break;
+            default:
+                break;
+        }
+        return season;
+    }
+
+    /**
+     * 取得季度月
+     *
+     * @param date
+     * @return
+     */
+    public static Date[] getSeasonDate(Date date) {
+        Date[] season = new Date[3];
+
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+
+        int nSeason = getSeason(date);
+        if (nSeason == 1) {// 第一季度
+            c.set(Calendar.MONTH, Calendar.JANUARY);
+            season[0] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.FEBRUARY);
+            season[1] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.MARCH);
+            season[2] = c.getTime();
+        } else if (nSeason == 2) {// 第二季度
+            c.set(Calendar.MONTH, Calendar.APRIL);
+            season[0] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.MAY);
+            season[1] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.JUNE);
+            season[2] = c.getTime();
+        } else if (nSeason == 3) {// 第三季度
+            c.set(Calendar.MONTH, Calendar.JULY);
+            season[0] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.AUGUST);
+            season[1] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.SEPTEMBER);
+            season[2] = c.getTime();
+        } else if (nSeason == 4) {// 第四季度
+            c.set(Calendar.MONTH, Calendar.OCTOBER);
+            season[0] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.NOVEMBER);
+            season[1] = c.getTime();
+            c.set(Calendar.MONTH, Calendar.DECEMBER);
+            season[2] = c.getTime();
+        }
+        return season;
+    }
+
+    /**
+     * 取得季度第一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getFirstDateOfSeason(Date date) {
+        return getFirstDateOfMonth(getSeasonDate(date)[0]);
+    }
+
+    /**
+     * 取得季度最后一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getLastDateOfSeason(Date date) {
+        return getLastDateOfMonth(getSeasonDate(date)[2]);
+    }
+
+    /**
+     * 取得月第一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getFirstDateOfMonth(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
+        return c.getTime();
+    }
+
+    /**
+     * 取得月最后一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getLastDateOfMonth(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
+        return c.getTime();
+    }
+
+    /**
+     * 时间范围内的每个季度开始时间
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Date> getSeasonDateList(Date startDate, Date endDate) {
+        List<Date> list = new ArrayList<>();
+        Date firstDateOfSeason = getFirstDateOfSeason(startDate);
+        list.add(firstDateOfSeason);
+        Date lastDateOfSeason = getFirstDateOfSeason(endDate);
+        Calendar c = Calendar.getInstance();
+        c.setTime(firstDateOfSeason);
+        while (c.getTime().before(lastDateOfSeason)) {
+            c.add(Calendar.MONTH, 3);
+            list.add(c.getTime());
+        }
+        return list;
+    }
+
+    /**
+     * 获取所在年第一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getFirstDayOfYear(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.DAY_OF_YEAR, cal.getActualMinimum(Calendar.DAY_OF_YEAR));
+        return cal.getTime();
+    }
+
+    /**
+     * 获取所在年第一天
+     *
+     * @param
+     * @return
+     */
+    public static Date getFirstDayOfYear(String year) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(StringToDate(year, DateStyleEnum.YYYY));
+        cal.set(Calendar.DAY_OF_YEAR, cal.getActualMinimum(Calendar.DAY_OF_YEAR));
+        return cal.getTime();
+    }
+
+    /**
+     * 获取所在年最后一天
+     *
+     * @param date
+     * @return
+     */
+    public static Date getLastDayOfYear(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR));
+        return cal.getTime();
+    }
+
+    /**
+     * 获取所在年最后一天
+     *
+     * @param year
+     * @return
+     */
+    public static Date getLastDayOfYear(String year) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(StringToDate(year, DateStyleEnum.YYYY));
+        cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR));
+        return cal.getTime();
+    }
+
+    /**
+     * 时间范围内的每个年开始时间列表
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Date> getYearDateList(Date startDate, Date endDate) {
+        List<Date> list = new ArrayList<>();
+        Date firstDate = getFirstDayOfYear(startDate);
+        list.add(firstDate);
+        Date lastDate = getFirstDayOfYear(endDate);
+        Calendar c = Calendar.getInstance();
+        c.setTime(firstDate);
+        while (c.getTime().before(lastDate)) {
+            c.add(Calendar.YEAR, 1);
+            list.add(c.getTime());
+        }
+        return list;
+    }
+
+
+    public static String getChineseDate(Date date) {
+        String chineseDate = null;
+        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD");
+
+
+        return chineseDate;
+    }
+
+    public static StringBuilder getChineseTime(Date date) {
+        String sign;
+        StringBuilder chineseTime = new StringBuilder();
+        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
+        String time = sdf.format(date);
+
+        String[] split = time.split(":");
+
+
+        if(split[0].equals("00")){
+            chineseTime.append("零时");
+        }else{
+            String s = formatDigit(split[0]);
+            String substring1 = s.substring(0, 1);
+            String substring2 = s.substring(1, 2);
+            if(substring1.equals("零")){
+
+            }else if(substring1.equals("一")){
+                chineseTime.append("十");
+            }else{
+                chineseTime.append(substring1).append("十");
+            }
+
+            if(!substring2.equals("零")){
+                chineseTime.append(substring2);
+            }
+
+
+            chineseTime.append("时");
+
+        }
+
+        if(split[1].equals("00")){
+            chineseTime.append("整");
+        }else {
+
+            String s = formatDigit(split[1]);
+
+            String substring1 = s.substring(0, 1);
+            String substring2 = s.substring(1, 2);
+
+            if(substring1.equals("零")){
+
+            }else if(substring1.equals("一")){
+                chineseTime.append("十");
+            }else{
+                chineseTime.append(substring1).append("十");
+            }
+
+            if(!substring2.equals("零")){
+                chineseTime.append(substring2);
+            }
+
+
+
+            chineseTime.append("分");
+        }
+//
+
+        return chineseTime;
+    }
+
+
+    private static String formatDigit(String sign) {
+        StringBuilder sb = new StringBuilder();
+        for(int i=0;i<sign.length();i++){
+            String substring = sign.substring(i, i + 1);
+            switch (substring){
+                case "0":
+                    sb.append("零");
+                    break;
+                case "1":
+                    sb.append("一");
+                    break;
+                case "2":
+                    sb.append("二");
+                    break;
+                case "3":
+                    sb.append("三");
+                    break;
+                case "4":
+                    sb.append("四");
+                    break;
+                case "5":
+                    sb.append("五");
+                    break;
+                case "6":
+                    sb.append("六");
+                    break;
+                case "7":
+                    sb.append("七");
+                    break;
+                case "8":
+                    sb.append("八");
+                    break;
+                case "9":
+                    sb.append("九");
+                    break;
+            }
+
+
+        }
+
+        sign = sb.toString();
+
+
+        return sign;
+    }
+
+    /**
+     * 取出当前日期到指定日期的周数据差值
+     *
+     * @param date      指日 定日期
+     * @param otherDate 当前日期
+     * @return 周数差
+     */
+    public static long intervalWeeks(Date date, Date otherDate) {
+        int intervalDays = getIntervalDays(date, otherDate) + 1;
+        int i = intervalDays % 7;
+        long weekNum = Math.abs((date.getTime() - otherDate.getTime()) / (7 * 60 * 60 * 24 * 1000));
+
+        weekNum += 1;
+
+        return weekNum;
+
+
+    }
+
+    public static long intervalWeeks(String date, String otherDate) {
+        Date date1 = DateUtils.StringToDate(date, DateStyleEnum.YYYY_MM_DD);
+        Date date2 = DateUtils.StringToDate(otherDate, DateStyleEnum.YYYY_MM_DD);
+
+
+        return intervalWeeks(date1, date2);
+
+
+    }
+
+    /**
+     * 获取两个时间相差多少小时多少分钟
+     *
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public static String getDistanceHourMin(Date startTime, Date endTime) {
+        long hour = 0;
+        long min = 0;
+        try {
+            long time1 = startTime.getTime();
+            long time2 = endTime.getTime();
+            long diff;
+            if (time1 < time2) {
+                diff = time2 - time1;
+            } else {
+                diff = time1 - time2;
+            }
+            hour = (diff / (60 * 60 * 1000));
+            min = ((diff / (60 * 1000)) - hour * 60);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return hour + "小时" + min + "分";
+    }
+
+    public static Date getDateHourMin(Date date) {
+        if (date == null) {
+            return null;
+        }
+        return StringToDate(DateToString(date, DateStyleEnum.YYYY_MM_DD_HH_MM), DateStyleEnum.YYYY_MM_DD_HH_MM);
+    }
+
+    /**
+     * 判断一个日期是否是周六、周日
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int isWeekend(String date) throws ParseException {
+        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
+        Date bdate = format1.parse(date);
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(bdate);
+        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+}

+ 8 - 0
src/main/java/com/imed/costaccount/model/CostIncomeGroup.java

@@ -59,6 +59,14 @@ public class CostIncomeGroup implements Serializable {
 	 * 是否直接收入
 	 * 是否直接收入
 	 */
 	 */
 	private Integer isIncome;
 	private Integer isIncome;
+	/**
+	 * 开单科室收到的钱
+	 */
+	private BigDecimal openDepartmentAmount;
+	/**
+	 * 执行科室收到的钱
+	 */
+	private BigDecimal startDepartmentAmount;
 	/**
 	/**
 	 * 金额
 	 * 金额
 	 */
 	 */

+ 71 - 0
src/main/java/com/imed/costaccount/model/vo/CostIncomeGroupBeforeVO.java

@@ -0,0 +1,71 @@
+package com.imed.costaccount.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author 李加喜
+ * @Package com.imed.costaccount.model.vo
+ * @date 2021-08-04 9:29
+ */
+@Data
+@ApiModel("收入归集前返回实体类")
+public class CostIncomeGroupBeforeVO {
+
+    @ApiModelProperty(name = "收入归集id",value = "主键")
+    private Long id;
+
+    @ApiModelProperty(name = "openDepartmentCode",value = "开单科室的代码")
+    private String openDepartmentCode;
+
+    @ApiModelProperty(name = "openDepartmentCodeName",value = "开单科室的代码+名称")
+    private String openDepartmentCodeName;
+
+    @ApiModelProperty(name = "openResponsibilityCode",value = "开单责任中心的代码")
+    private String openResponsibilityCode;
+
+    @ApiModelProperty(name = "openResponsibilityCodeName",value = "开单责任中心的代码+名称")
+    private String openResponsibilityCodeName;
+
+    @ApiModelProperty(name = "startDepartmentCode",value = "执行科室的代码")
+    private String startDepartmentCode;
+
+    @ApiModelProperty(name = "startDepartmentCodeName",value = "执行科室代码+名称")
+    private String startDepartmentCodeName;
+
+    @ApiModelProperty(name = "startResponsibilityCode",value = "执行责任中心代码")
+    private String startResponsibilityCode;
+
+    @ApiModelProperty(name = "startResponsibilityCodeName",value = "执行责任中心代码+名称")
+    private String startResponsibilityCodeName;
+
+    @ApiModelProperty(name = "productCode",value = "成本项目的代码")
+    private String productCode;
+
+    @ApiModelProperty(name = "productCodeName",value = "成本项目的代码+名称")
+    private String productCodeName;
+
+    @ApiModelProperty(name = "accountCode",value = "会计科目的代码")
+    private String accountCode;
+
+    @ApiModelProperty(name = "accountCodeName",value = "会计科目的代码+名称")
+    private String accountCodeName;
+
+    @ApiModelProperty(name = "openDepartmentAmount",value = "开单科室金额")
+    private BigDecimal openDepartmentAmount;
+
+    @ApiModelProperty(name = "startDepartmentAmount",value = "执行科室金额")
+    private BigDecimal startDepartmentAmount;
+
+    @ApiModelProperty(name = "amount",value = "总金额")
+    private BigDecimal amount;
+
+    @ApiModelProperty(name = "dateYear",value = "年")
+    private Integer dateYear;
+
+    @ApiModelProperty(name = "dateMonth",value = "月")
+    private Integer dateMonth;
+}

+ 12 - 1
src/main/java/com/imed/costaccount/service/CostIncomeGroupService.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.service;
 package com.imed.costaccount.service;
 
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.CostIncomeGroup;
 import com.imed.costaccount.model.CostIncomeGroup;
 
 
 /**
 /**
@@ -11,6 +12,16 @@ import com.imed.costaccount.model.CostIncomeGroup;
  * @date 2021-08-03 16:15:20
  * @date 2021-08-03 16:15:20
  */
  */
 public interface CostIncomeGroupService extends IService<CostIncomeGroup> {
 public interface CostIncomeGroupService extends IService<CostIncomeGroup> {
-
+    /**
+     * 分页查询收入归集前的数据
+     * @param current 当前页
+     * @param pageSize 当前页大小
+     * @param dateTime 年月
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode 会计科目的Code
+     * @param hospId 医院Id
+     * @return
+     */
+    PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId);
 }
 }
 
 

+ 12 - 10
src/main/java/com/imed/costaccount/service/impl/CostAccountShareServiceImpl.java

@@ -16,10 +16,9 @@ import com.imed.costaccount.model.vo.CostAccountShareVO;
 import com.imed.costaccount.model.vo.CostShareParamStatusVO;
 import com.imed.costaccount.model.vo.CostShareParamStatusVO;
 import com.imed.costaccount.model.vo.CostShareParamVO;
 import com.imed.costaccount.model.vo.CostShareParamVO;
 import com.imed.costaccount.model.vo.ShareParamProportionVO;
 import com.imed.costaccount.model.vo.ShareParamProportionVO;
-import com.imed.costaccount.service.CostAccountShareService;
+import com.imed.costaccount.service.*;
 import com.imed.costaccount.utils.BeanUtil;
 import com.imed.costaccount.utils.BeanUtil;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.SecurityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -37,17 +36,20 @@ import java.util.stream.Collectors;
 @Service("costAccountShareService")
 @Service("costAccountShareService")
 public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMapper, CostAccountShare> implements CostAccountShareService {
 public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMapper, CostAccountShare> implements CostAccountShareService {
 
 
-    @Autowired
-    private ResponsibilityServiceImpl responsibilityService;
+    private final ResponsibilityService responsibilityService;
 
 
-    @Autowired
-    private AccountingServiceImpl accountingService;
+    private final AccountingService accountingService;
 
 
-    @Autowired
-    private CostShareLevelServiceImpl costShareLevelService;
+    private final CostShareLevelService costShareLevelService;
 
 
-    @Autowired
-    private CostShareParamServiceImpl costShareParamService;
+    private final CostShareParamService costShareParamService;
+
+    public CostAccountShareServiceImpl(ResponsibilityService responsibilityService, AccountingService accountingService, CostShareLevelService costShareLevelService, CostShareParamService costShareParamService) {
+        this.responsibilityService = responsibilityService;
+        this.accountingService = accountingService;
+        this.costShareLevelService = costShareLevelService;
+        this.costShareParamService = costShareParamService;
+    }
 
 
     /**
     /**
      * 分页查询责任中心成本对照相关数据
      * 分页查询责任中心成本对照相关数据

+ 59 - 1
src/main/java/com/imed/costaccount/service/impl/CostIncomeGroupServiceImpl.java

@@ -1,14 +1,72 @@
 package com.imed.costaccount.service.impl;
 package com.imed.costaccount.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.imed.costaccount.common.util.BeanUtil;
+import com.imed.costaccount.common.util.DateUtils;
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.mapper.CostIncomeGroupMapper;
 import com.imed.costaccount.mapper.CostIncomeGroupMapper;
 import com.imed.costaccount.model.CostIncomeGroup;
 import com.imed.costaccount.model.CostIncomeGroup;
-import com.imed.costaccount.service.CostIncomeGroupService;
+import com.imed.costaccount.model.Department;
+import com.imed.costaccount.model.Responsibility;
+import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO;
+import com.imed.costaccount.service.*;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
 
 
 
 
 @Service("costIncomeGroupService")
 @Service("costIncomeGroupService")
 public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMapper, CostIncomeGroup> implements CostIncomeGroupService {
 public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMapper, CostIncomeGroup> implements CostIncomeGroupService {
 
 
+    private final DepartmentService departmentService;
+
+    private final ResponsibilityService responsibilityService;
+
+    private final ProductService productService;
+
+    private final AccountingService accountingService;
+
+    public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService) {
+        this.departmentService = departmentService;
+        this.responsibilityService = responsibilityService;
+        this.productService = productService;
+        this.accountingService = accountingService;
+    }
+
+    /**
+     * 分页查询收入归集前的数据
+     *
+     * @param current            当前页
+     * @param pageSize           当前页大小
+     * @param dateTime           年月
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode        会计科目的Code
+     * @param hospId             医院Id
+     * @return
+     */
+    @Override
+    public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId) {
+        int year = DateUtils.getYear(dateTime);
+        int month=DateUtils.getMonth(dateTime);
+        Page<CostIncomeGroup> costIncomeGroupPage = new Page<>(current, pageSize);
+        QueryWrapper<CostIncomeGroup> wrapper = new QueryWrapper<>();
+        wrapper.eq("hosp_id",hospId);
+        wrapper.eq("date_year",year);
+        wrapper.eq("date_month",month);
+        wrapper.like(!StringUtils.isEmpty(responsibilityCode),"open_responsibility_code",responsibilityCode)
+                .or()
+                .like(!StringUtils.isEmpty(responsibilityCode),"start_responsibility_code",responsibilityCode);
+        wrapper.like(!StringUtils.isEmpty(accountCode),"account_code",accountCode);
+        Page<CostIncomeGroup> pages = this.page(costIncomeGroupPage, wrapper);
+        List<CostIncomeGroup> records = pages.getRecords();
+        List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class);
+        // 查询所有的责任中心 科室 会计科目  成本项目的数据
+        List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
+        List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
 
 
+        return null;
+    }
 }
 }

+ 7 - 3
src/main/java/com/imed/costaccount/web/CostIncomeGroupController.java

@@ -1,9 +1,11 @@
 package com.imed.costaccount.web;
 package com.imed.costaccount.web;
 
 
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.model.CostIncomeGroup;
 import com.imed.costaccount.model.CostIncomeGroup;
 import com.imed.costaccount.service.CostIncomeGroupService;
 import com.imed.costaccount.service.CostIncomeGroupService;
+import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -18,13 +20,15 @@ import java.util.Arrays;
  * @date 2021-08-03 16:15:20
  * @date 2021-08-03 16:15:20
  */
  */
 @RestController
 @RestController
-@RequestMapping("/costincomegroup")
+@RequestMapping("/costAccount/costincomegroup")
+@Api(tags = "收入归集操作")
 public class CostIncomeGroupController {
 public class CostIncomeGroupController {
     @Autowired
     @Autowired
     private CostIncomeGroupService costIncomeGroupService;
     private CostIncomeGroupService costIncomeGroupService;
 
 
     /**
     /**
      * 分页查询列表
      * 分页查询列表
+     * 根据年月  下拉选择的责任中心Code 会计科目的Code
      */
      */
     @GetMapping("/list")
     @GetMapping("/list")
     @ApiOperation("分页获取收入归集前数据")
     @ApiOperation("分页获取收入归集前数据")
@@ -34,8 +38,8 @@ public class CostIncomeGroupController {
                        @RequestParam(value = "responsibilityCode",required = false) String responsibilityCode,
                        @RequestParam(value = "responsibilityCode",required = false) String responsibilityCode,
                        @RequestParam(value = "accountCode",required = false) String accountCode){
                        @RequestParam(value = "accountCode",required = false) String accountCode){
         Long hospId = UserContext.getHospId();
         Long hospId = UserContext.getHospId();
-
-        return Result.ok();
+        PageUtils pageUtils = costIncomeGroupService.queryList(current,pageSize,dateTime,responsibilityCode,accountCode,hospId);
+        return Result.ok(pageUtils);
     }
     }
 
 
 
 

+ 108 - 10
src/main/java/com/imed/costaccount/web/ExcelController.java

@@ -1,13 +1,22 @@
 package com.imed.costaccount.web;
 package com.imed.costaccount.web;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.poi.excel.ExcelReader;
 import cn.hutool.poi.excel.ExcelReader;
 import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelWriter;
 import cn.hutool.poi.excel.ExcelWriter;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.common.util.UserContext;
+import com.imed.costaccount.constants.NumberConstant;
+import com.imed.costaccount.model.Accounting;
+import com.imed.costaccount.model.AccountingProduct;
+import com.imed.costaccount.model.Product;
 import com.imed.costaccount.model.User;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.service.AccountingProductService;
+import com.imed.costaccount.service.AccountingService;
 import com.imed.costaccount.service.UserService;
 import com.imed.costaccount.service.UserService;
 import com.imed.costaccount.service.impl.DepartmentServiceImpl;
 import com.imed.costaccount.service.impl.DepartmentServiceImpl;
 import com.imed.costaccount.service.impl.ProductServiceImpl;
 import com.imed.costaccount.service.impl.ProductServiceImpl;
@@ -16,7 +25,6 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.SecurityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
@@ -25,9 +33,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * 相关导入导出操作
  * 相关导入导出操作
@@ -38,16 +45,22 @@ import java.util.UUID;
 @RequestMapping("/costAccount/excel")
 @RequestMapping("/costAccount/excel")
 public class ExcelController {
 public class ExcelController {
 
 
-    private UserService userService;
+    private final UserService userService;
 
 
-    @Autowired
-    private DepartmentServiceImpl departmentService;
+    private final DepartmentServiceImpl departmentService;
 
 
-    @Autowired
-    private ProductServiceImpl productService;
+    private final ProductServiceImpl productService;
 
 
-    public ExcelController(UserService userService) {
+    private final AccountingService accountingService;
+
+    private final AccountingProductService accountingProductService;
+
+    public ExcelController(UserService userService, DepartmentServiceImpl departmentService, ProductServiceImpl productService, AccountingService accountingService, AccountingProductService accountingProductService) {
         this.userService = userService;
         this.userService = userService;
+        this.departmentService = departmentService;
+        this.productService = productService;
+        this.accountingService = accountingService;
+        this.accountingProductService = accountingProductService;
     }
     }
 
 
     @ApiOperation("用户导出模板设置")
     @ApiOperation("用户导出模板设置")
@@ -210,4 +223,89 @@ public class ExcelController {
             throw new CostException(500, "导入失败");
             throw new CostException(500, "导入失败");
         }
         }
     }
     }
+    /**
+     * 收入成本数据导出模板
+     * @param accountType 1收入数据  2 成本数据(支出数据)
+     */
+    @ApiOperation("收入数据导出模板设置")
+    @GetMapping("/getImportProductAccountTemplate")
+    public void getImportProductAccountTemplate(HttpServletResponse response,Integer accountType) throws IOException {
+        Long hospId = UserContext.getHospId();
+        String uuid = UUID.randomUUID().toString();
+        String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
+        FileUtil.del(FileUtil.file(url));
+
+        ExcelWriter writer = new ExcelWriter(url);
+        // 样式
+        Sheet sheet = writer.getSheet();
+        // 内容
+        writer.merge(0, 1, 0, 6, "为了保证成功导入,请勿修改模板格式", false);
+        writer.passCurrentRow();
+        writer.passCurrentRow();
+        String stateType= NumberConstant.ONE.equals(accountType)?"医院收入数据批量导入":"医院成本数据批量导入";
+        writer.merge(2, 2, 0, 6, stateType, false);
+        writer.passCurrentRow();
+        // 冻结前四行
+        writer.setFreezePane(4);
+        writer.writeRow(Arrays.asList("","","开单科室","开单科室代码", "执行科室","执行科室代码","金额"));
+        // 所有的成本项目
+        List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
+        // 所有成本会计对照数据
+        List<AccountingProduct> accountingProductList = accountingProductService.list(new QueryWrapper<AccountingProduct>().lambda().eq(AccountingProduct::getHospId, hospId));
+        // 所有会计科目列表数据
+        List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
+        List<Product> products = new ArrayList<>();
+        Map<Long, List<AccountingProduct>> accountProductMap = accountingProductList.stream().collect(Collectors.groupingBy(AccountingProduct::getProductId));
+        Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
+        productList.forEach(i->{
+            Long productId = i.getId();
+            List<AccountingProduct> accountingProducts = accountProductMap.get(productId);
+            if (CollUtil.isNotEmpty(accountingProducts)){
+                Long accountingId = accountingProducts.get(0).getAccountingId();
+                List<Accounting> accountings = accountMap.get(accountingId);
+                if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())){
+                    products.add(i);
+                }
+            }
+        });
+        // 写入响应第一列 第二列的数据
+        for (int j = 0; j<products.size(); j++){
+            writer.writeCellValue(0,j+4,productList.get(j).getProductCode());
+            writer.writeCellValue(1,j+4,productList.get(j).getProductName());
+        }
+        writer.setColumnWidth(0,10);
+        writer.setColumnWidth(1,10);
+        writer.setColumnWidth(2,20);
+        writer.setColumnWidth(3,20);
+        writer.setColumnWidth(4,20);
+        writer.setColumnWidth(5,20);
+        writer.setColumnWidth(6,20);
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
+        response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
+        ServletOutputStream out = null;
+        out = response.getOutputStream();
+        writer.flush(out, true);
+        writer.close();
+        IoUtil.close(out);
+    }
+    /**
+     *  收入成本项目批量导入
+     */
+    @PostMapping("/importProductAccount")
+    @ApiOperation("批量导入收入数据信息")
+    public Result importProductAccount(@RequestParam("file") MultipartFile file){
+        InputStream in;
+        try {
+            in = file.getInputStream();
+            ExcelReader reader = ExcelUtil.getReader(in);
+            List<List<Object>> read = reader.read();
+            log.info("最开始:read={}",read);
+            log.info("-------------------------------------------------------------------");
+            Long hospId = UserContext.getHospId();
+            return productService.importProduct(read, hospId);
+        }catch (IOException e){
+            e.printStackTrace();;
+            throw new CostException(500, "导入失败");
+        }
+    }
 }
 }

+ 2 - 0
src/main/resources/mapper/CostIncomeGroupMapper.xml

@@ -13,6 +13,8 @@
         <result property="productCode" column="product_code"/>
         <result property="productCode" column="product_code"/>
         <result property="accountCode" column="account_code"/>
         <result property="accountCode" column="account_code"/>
         <result property="isIncome" column="is_income"/>
         <result property="isIncome" column="is_income"/>
+        <result property="openDepartmentAmount" column="open_department_amount"/>
+        <result property="startDepartmentAmount" column="start_department_amount"/>
         <result property="amount" column="amount"/>
         <result property="amount" column="amount"/>
         <result property="hospId" column="hosp_id"/>
         <result property="hospId" column="hosp_id"/>
         <result property="dateYear" column="date_year"/>
         <result property="dateYear" column="date_year"/>