packagecom.ecenter.nyxmsb.modular.money.utils;
importcn.hutool.core.date.DateTime;
importcn.hutool.core.date.DateUtil;
importcom.ecenter.nyxmsb.core.util.ShiroUtils;
importcom.ecenter.nyxmsb.modular.system.entity.SysUser;
importorg.apache.shiro.SecurityUtils;
importorg.springframework.util.StringUtils;
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.*;
publicclassUtilsLin {
publicstaticfinalStringFORMAT_YYYY_MM_DD="yyyy-MM-dd";
publicStringtoday=DateUtil.today();
publicDateTimedate=DateUtil.date();
publicStringmonth=DateUtil.format(date, "M") ;
publicStringweekFirst=UtilsLin.getThisWeekOfFirstDate();
publicStringweekEnd=DateUtil.format(DateUtil.offsetDay(date, 4), "yyyy-MM-dd") ;
publicStringMonthFirst=UtilsLin.getThisMonthOfFirstDate(0);
publicStringMonthEnd=UtilsLin.getThisMouthLastDay();
publicStringlastdateTimSeason=UtilsLin.getCurrQuarter(Integer.valueOf(UtilsLin.getQuarter()))[1];
publicStringfirstdateTimSeason=UtilsLin.getCurrQuarter(Integer.valueOf(UtilsLin.getQuarter()))[0];
publicintdaysInMonth=UtilsLin.getDaysOfMonth();
publicstaticStringchangeSqlNotNull(Stringsql){
String[] strings=sql.split(",");
StringreturnSql="";
for (Stringstr: strings ) {
if (str.contains("''")){
returnSql=returnSql+str+",";
}else {
returnSql=returnSql+"ifnull("+str+",'') "+str+",";
}
}
returnreturnSql.substring(0,returnSql.length()-1);
}
publicstaticStringgetDept(){
SysUserprincipal= (SysUser) SecurityUtils.getSubject().getPrincipal();
returnprincipal.getDeptId().toString();
}
publicstaticSysUsergetUserEntity() {
Objectprincipal=SecurityUtils.getSubject().getPrincipal();
return (SysUser) SecurityUtils.getSubject().getPrincipal();
}
publicstaticList<String>getBetweenDays(StringstartTime, StringendTime) throwsParseException {
if(StringUtils.isEmpty(startTime) ||StringUtils.isEmpty(endTime)){
returnnull;
}
SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-dd");
Datestart=df.parse(startTime);
Dateend=df.parse(endTime);
if(StringUtils.isEmpty(start) ||StringUtils.isEmpty(end)){
returnnull;
}
List<String>result=newArrayList<String>();
CalendartempStart=Calendar.getInstance();
tempStart.setTime(start);
tempStart.add(Calendar.DAY_OF_YEAR, 1);
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
CalendartempEnd=Calendar.getInstance();
tempEnd.setTime(end);
result.add(sdf.format(start));
while (tempStart.before(tempEnd) ||tempStart.equals(tempEnd)) {
result.add(sdf.format(tempStart.getTime()));
tempStart.add(Calendar.DAY_OF_YEAR, 1);
}
returnresult;
}
publicstaticStringgetThisWeekOfFirstDate() {
SimpleDateFormatformat=newSimpleDateFormat(FORMAT_YYYY_MM_DD);
Calendarcalendar=Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
returnformat.format(calendar.getTime());
}
publicstaticStringgetTime1(Integeri){
Calendarcalendar=Calendar.getInstance();
if (i!=null) {
calendar.add(Calendar.MONTH, i);
}
intyear=calendar.get(Calendar.YEAR);
intmonth=calendar.get(Calendar.MONTH);
intday=calendar.get(Calendar.DATE);
returnyear+"-"+ (month+1) +"-"+day;
}
publicstaticStringgetThisMonthOfFirstDate(Integeri) {
SimpleDateFormatformat=newSimpleDateFormat("YYYY-MM-dd");
Calendarcalendar=Calendar.getInstance();
if (i!=null) {
calendar.add(Calendar.MONTH, i);
}
calendar.set(Calendar.DAY_OF_MONTH, Calendar.SUNDAY);
returnformat.format(calendar.getTime());
}
publicstaticStringgetThisMouthLastDay(){
SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");
Calendarca=Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
StringlastDay=format.format(ca.getTime());
returnlastDay;
}
publicstaticMap<String, Object>getFirstLastDayByMonth(Datedate,
Stringpattern, booleanisNeedHms) {
SimpleDateFormatdf=newSimpleDateFormat(pattern);
Calendarcalendar=Calendar.getInstance();
calendar.setTime(date);
DatetheDate=calendar.getTime();
GregorianCalendargcLast= (GregorianCalendar) Calendar.getInstance();
gcLast.setTime(theDate);
gcLast.set(Calendar.DAY_OF_MONTH, 1);
Stringday_first=df.format(gcLast.getTime());
StringBufferstr=newStringBuffer().append(day_first);
if (isNeedHms) {
str.append(" 00:00:00");
}
day_first=str.toString();
calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DATE, 1); calendar.add(Calendar.DATE, -1); Stringday_last=df.format(calendar.getTime());
StringBufferendStr=newStringBuffer().append(day_last);
if (isNeedHms) {
endStr.append(" 23:59:59");
}
day_last=endStr.toString();
Map<String, Object>map=newHashMap<String, Object>();
map.put("first", day_first);
map.put("last", day_last);
returnmap;
}
publicstaticStringgetQuarter() {
Calendarc=Calendar.getInstance();
intmonth=c.get(Calendar.MONTH) +1;
intquarter=0;
if (month>=1&&month<=3) {
quarter=1;
} elseif (month>=4&&month<=6) {
quarter=2;
} elseif (month>=7&&month<=9) {
quarter=3;
} else {
quarter=4;
}
returnquarter+"";
}
publicstaticString[] getCurrQuarter(intnum) {
String[] s=newString[2];
Stringstr="";
CalendarquarterCalendar=null;
switch (num) {
case1: quarterCalendar=Calendar.getInstance();
quarterCalendar.set(Calendar.MONTH, 3);
quarterCalendar.set(Calendar.DATE, 1);
quarterCalendar.add(Calendar.DATE, -1);
str=UtilsLin.formatDate(quarterCalendar.getTime(), "yyyy-MM-dd");
s[0] =str.substring(0, str.length() -5) +"01-01";
s[1] =str;
break;
case2: quarterCalendar=Calendar.getInstance();
quarterCalendar.set(Calendar.MONTH, 6);
quarterCalendar.set(Calendar.DATE, 1);
quarterCalendar.add(Calendar.DATE, -1);
str=UtilsLin.formatDate(quarterCalendar.getTime(), "yyyy-MM-dd");
s[0] =str.substring(0, str.length() -5) +"04-01";
s[1] =str;
break;
case3:quarterCalendar=Calendar.getInstance();
quarterCalendar.set(Calendar.MONTH, 9);
quarterCalendar.set(Calendar.DATE, 1);
quarterCalendar.add(Calendar.DATE, -1);
str=UtilsLin.formatDate(quarterCalendar.getTime(), "yyyy-MM-dd");
s[0] =str.substring(0, str.length() -5) +"07-01";
s[1] =str;
break;
case4:quarterCalendar=Calendar.getInstance();
str=UtilsLin.formatDate(quarterCalendar.getTime(), "yyyy-MM-dd");
s[0] =str.substring(0, str.length() -5) +"10-01";
s[1] =str.substring(0, str.length() -5) +"12-31";
break;
}
returns;
}
publicstaticStringformatDate(DatecurrentDate, Stringpattern){
if(currentDate==null||"".equals(pattern) ||pattern==null){
returnnull;
}
SimpleDateFormatsdf=newSimpleDateFormat(pattern);
returnsdf.format(currentDate);
}
publicstaticList<String>getStartDateToEndDate(StringstartDate,StringendDate) {
List<String>betweenDays=null;
try {
betweenDays=UtilsLin.getBetweenDays(startDate, endDate);
System.out.println(betweenDays);
} catch (ParseExceptione) {
e.printStackTrace();
}
returnbetweenDays;
}
publicstaticintgetDaysOfMonth() {
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
Calendarcalendar=Calendar.getInstance();
calendar.setTime(newDate());
returncalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
}