pom.xml
@@ -112,6 +112,11 @@ <artifactId>kaptcha</artifactId> <version>2.3.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> </dependencies> screen-common/src/main/java/com/moral/constant/Constants.java
@@ -7,56 +7,81 @@ /* * 被删除标识 * */ public static String DELETE = "1"; public static final String DELETE = "1"; /* * 未删除标识 * */ public static String NOT_DELETE = "0"; public static final String NOT_DELETE = "0"; /* * 后台系统验证码配置列名 * */ public static String MANAGE_VERIFICATIONCODE_COLUMN = "type"; public static final String MANAGE_VERIFICATIONCODE_COLUMN = "type"; /* * 后台系统验证码列对应的值 * */ public static String MANAGE_VERIFICATIONCODE_VALUE = "manage_verificationCode"; public static final String MANAGE_VERIFICATIONCODE_VALUE = "manage_verificationCode"; /* * 验证码开启标识 * */ public static String VERFICATIONCODE_OPEN = "1"; public static final String VERFICATIONCODE_OPEN = "1"; /* * 验证码关闭标识 * */ public static String VERFICATIONCODE_CLOSE = "0"; public static final String VERFICATIONCODE_CLOSE = "0"; /* * 查询正序标识 * */ public static String ORDER_ASC = "0"; public static final String ORDER_ASC = "0"; /* * 查询倒序标识 * */ public static String ORDER_DESC = "1"; public static final String ORDER_DESC = "1"; /* * 删除子组织标识 * */ public static Integer DELETE_CHILDREN_ORG = 1; /* * web端通道 * 删除子组织标识 * */ public static Integer WEB_CHANNEL = 1; public static final Integer DELETE_CHILDREN_ORG = 1; /* * 网页端渠道 * */ public static final Integer WEB_CHANNEL = 1; /* * web端验证码配置列名 * */ public static String VERIFICATION_TYPE = "front_verificationCode"; public static final String VERIFICATION_TYPE = "front_verificationCode"; /* * 添加操作类型 * */ public static final String INSERT_OPERATE_TYPE = "添加"; /* * 删除操作类型 * */ public static final String DELETE_OPERATE_TYPE = "删除"; /* * 更新操作类型 * */ public static final String UPDATE_OPERATE_TYPE = "更新"; /* * 查询操作类型 * */ public static final String QUERY_OPERATE_TYPE = "查询"; /* * Organization模块名称 * */ public static final String ORGANIZATION_MODULE_NAME = "组织"; } screen-common/src/main/java/com/moral/util/ConvertUtils.java
New file @@ -0,0 +1,88 @@ package com.moral.util; import org.mockito.internal.util.StringUtil; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @ClassName ConvertUtils * @Description TODO * @Author 陈凯裕 * @Date 2021/3/26 14:52 * @Version TODO **/ public class ConvertUtils { /** * @Description: 下划线转驼峰 * @Param: [underscore] * @return: java.lang.String * @Author: 陈凯裕 * @Date: 2021/3/26 */ public static String underscoreToCamelCase(String underscore) { String[] ss = underscore.split("_"); if (ss.length == 1) { return underscore; } StringBuffer sb = new StringBuffer(); sb.append(ss[0]); for (int i = 1; i < ss.length; i++) { sb.append(upperFirstCase(ss[i])); } return sb.toString(); } /** * @Description: 驼峰转下划线 * @Param: [camelCase] * @return: java.lang.String * @Author: 陈凯裕 * @Date: 2021/3/26 */ public static String toLine(String camelCase) { Pattern humpPattern = Pattern.compile("[A-Z]"); Matcher matcher = humpPattern.matcher(camelCase); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase()); } matcher.appendTail(sb); return sb.toString(); } /** * @Description: 首字母转为小写 * @Param: [str] * @return: java.lang.String * @Author: 陈凯裕 * @Date: 2021/3/26 */ private static String lowerFirstCase(String str) { char[] chars = str.toCharArray(); chars[0] += 32; return String.valueOf(chars); } /** * @Description: 首字母转为大写 * @Param: [str] * @return: java.lang.String * @Author: 陈凯裕 * @Date: 2021/3/26 */ private static String upperFirstCase(String str) { char[] chars = str.toCharArray(); chars[0] -= 32; return String.valueOf(chars); } } screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -1,7 +1,6 @@ package com.moral.util; import org.springframework.util.StringUtils; import java.math.BigDecimal; @@ -16,1254 +15,1289 @@ public class DateUtils { /** 日期格式(yyyy-MM-dd) */ public static final String yyyy_MM_dd_EN = "yyyy-MM-dd"; /** 日期格式(yyyy/MM/dd) */ public static final String yyyy_MM_dd_decline = "yyyy/MM/dd"; /** 日期格式(yyyyMMdd) */ public static final String yyyyMMdd_EN = "yyyyMMdd"; /** 日期格式(yyyy-MM) */ public static final String yyyy_MM_EN = "yyyy-MM"; /** 日期格式(yyyyMM) */ public static final String yyyyMM_EN = "yyyyMM"; /** 日期格式(yyyy-MM-dd HH:mm:ss) */ public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss"; /** 日期格式(yyyy-MM-dd HH:mm:ss.S) */ public static final String yyyy_MM_dd_HH_mm_ss_S_EN = "yyyy-MM-dd HH:mm:ss.S"; /** 日期格式(yyyyMMddHHmmss) */ public static final String yyyyMMddHHmmss_EN = "yyyyMMddHHmmss"; /** 日期格式(yyyy年MM月dd日) */ public static final String yyyy_MM_dd_CN = "yyyy年MM月dd日"; /** 日期格式(yyyy年MM月dd日HH时mm分ss秒) */ public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy年MM月dd日HH时mm分ss秒"; /** 日期格式(yyyy年MM月dd日HH时mm分) */ public static final String yyyy_MM_dd_HH_mm_CN = "yyyy年MM月dd日HH时mm分"; /** 北京boss订购接口报文头日期格式 */ public static final String BJBOSS_DATE = "yyyy-MM-dd'T'HH:mm:ss'Z'"; /** 日期格式(HH:mm:ss) */ public static final String HH_mm_ss_EN = "HH:mm:ss"; /** DateFormat缓存 */ private static Map<String, DateFormat> dateFormatMap = new HashMap<String, DateFormat>(); /** * 日期格式(yyyy-MM-dd) */ public static final String yyyy_MM_dd_EN = "yyyy-MM-dd"; /** * 日期格式(yyyy/MM/dd) */ public static final String yyyy_MM_dd_decline = "yyyy/MM/dd"; /** * 日期格式(yyyyMMdd) */ public static final String yyyyMMdd_EN = "yyyyMMdd"; /** * 日期格式(yyyy-MM) */ public static final String yyyy_MM_EN = "yyyy-MM"; /** * 日期格式(yyyyMM) */ public static final String yyyyMM_EN = "yyyyMM"; /** * 日期格式(yyyy-MM-dd HH:mm:ss) */ public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss"; /** * 日期格式(yyyy-MM-dd HH:mm:ss.S) */ public static final String yyyy_MM_dd_HH_mm_ss_S_EN = "yyyy-MM-dd HH:mm:ss.S"; /** * 日期格式(yyyyMMddHHmmss) */ public static final String yyyyMMddHHmmss_EN = "yyyyMMddHHmmss"; /** * 日期格式(yyyy年MM月dd日) */ public static final String yyyy_MM_dd_CN = "yyyy年MM月dd日"; /** * 日期格式(yyyy年MM月dd日HH时mm分ss秒) */ public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy年MM月dd日HH时mm分ss秒"; /** * 日期格式(yyyy年MM月dd日HH时mm分) */ public static final String yyyy_MM_dd_HH_mm_CN = "yyyy年MM月dd日HH时mm分"; /** * 北京boss订购接口报文头日期格式 */ public static final String BJBOSS_DATE = "yyyy-MM-dd'T'HH:mm:ss'Z'"; /** * 日期格式(HH:mm:ss) */ public static final String HH_mm_ss_EN = "HH:mm:ss"; /** * DateFormat缓存 */ private static Map<String, DateFormat> dateFormatMap = new HashMap<String, DateFormat>(); /** * 获取DateFormat * * @param formatStr * @return */ public static DateFormat getDateFormat(String formatStr) { DateFormat df = dateFormatMap.get(formatStr); if (df == null) { df = new SimpleDateFormat(formatStr); dateFormatMap.put(formatStr, df); } return df; } public static Date getDate() { return Calendar.getInstance().getTime(); } /** * 获取DateFormat * * @param formatStr * @return */ public static DateFormat getDateFormat(String formatStr) { DateFormat df = dateFormatMap.get(formatStr); if (df == null) { df = new SimpleDateFormat(formatStr); dateFormatMap.put(formatStr, df); } return df; } /** * 按照默认formatStr的格式,转化dateTimeStr为Date类型 dateTimeStr必须是formatStr的形式 * * @param dateTimeStr * @param formatStr * @return */ public static Date getDate(String dateTimeStr, String formatStr) { try { if (dateTimeStr == null || dateTimeStr.equals("")) { return null; } DateFormat sdf = getDateFormat(formatStr); return sdf.parse(dateTimeStr); } catch (ParseException e) { throw new RuntimeException(e); } } public static Date getDate() { return Calendar.getInstance().getTime(); } /** * 转化dateTimeStr为Date类型 * * @param dateTimeStr * @return */ public static Date convertDate(String dateTimeStr) { try { if (dateTimeStr == null || dateTimeStr.equals("")) { return null; } DateFormat sdf = getDateFormat(yyyy_MM_dd_EN); Date d = sdf.parse(dateTimeStr); return d; } catch (ParseException e) { throw new RuntimeException(e); } } /** * 按照默认formatStr的格式,转化dateTimeStr为Date类型 dateTimeStr必须是formatStr的形式 * * @param dateTimeStr * @param formatStr * @return */ public static Date getDate(String dateTimeStr, String formatStr) { try { if (dateTimeStr == null || dateTimeStr.equals("")) { return null; } DateFormat sdf = getDateFormat(formatStr); return sdf.parse(dateTimeStr); } catch (ParseException e) { throw new RuntimeException(e); } } /** * 按照默认显示日期时间的格式"yyyy-MM-dd",转化dateTimeStr为Date类型 dateTimeStr必须是"yyyy-MM-dd"的形式 * * @param dateTimeStr * @return */ public static Date getDate(String dateTimeStr) { return getDate(dateTimeStr, yyyy_MM_dd_EN); } /** * 转化dateTimeStr为Date类型 * * @param dateTimeStr * @return */ public static Date convertDate(String dateTimeStr) { try { if (dateTimeStr == null || dateTimeStr.equals("")) { return null; } DateFormat sdf = getDateFormat(yyyy_MM_dd_EN); Date d = sdf.parse(dateTimeStr); return d; } catch (ParseException e) { throw new RuntimeException(e); } } /** * 将YYYYMMDD转换成Date日期 * * @param date * @return * @throws Exception */ public static Date transferDate(String date) throws Exception { if (date == null || date.length() < 1) return null; /** * 按照默认显示日期时间的格式"yyyy-MM-dd",转化dateTimeStr为Date类型 dateTimeStr必须是"yyyy-MM-dd"的形式 * * @param dateTimeStr * @return */ public static Date getDate(String dateTimeStr) { return getDate(dateTimeStr, yyyy_MM_dd_EN); } if (date.length() != 8) throw new Exception("日期格式错误"); String con = "-"; /** * 将YYYYMMDD转换成Date日期 * * @param date * @return * @throws Exception */ public static Date transferDate(String date) throws Exception { if (date == null || date.length() < 1) return null; String yyyy = date.substring(0, 4); String mm = date.substring(4, 6); String dd = date.substring(6, 8); if (date.length() != 8) throw new Exception("日期格式错误"); String con = "-"; int month = Integer.parseInt(mm); int day = Integer.parseInt(dd); if (month < 1 || month > 12 || day < 1 || day > 31) throw new Exception("日期格式错误"); String yyyy = date.substring(0, 4); String mm = date.substring(4, 6); String dd = date.substring(6, 8); String str = yyyy + con + mm + con + dd; return getDate(str, yyyy_MM_dd_EN); } int month = Integer.parseInt(mm); int day = Integer.parseInt(dd); if (month < 1 || month > 12 || day < 1 || day > 31) throw new Exception("日期格式错误"); /** * 将Date转换成字符串“yyyy-mm-dd hh:mm:ss”的字符串 * * @param date * @return */ public static String dateToDateString(Date date) { return dateToDateString(date, yyyy_MM_dd_HH_mm_ss_EN); } String str = yyyy + con + mm + con + dd; return getDate(str, yyyy_MM_dd_EN); } /** * 将Date转换成字符串“yyyymmddhhmmss”的字符串 * * @param date * @return */ public static String dateToDateFullString(Date date) { if (null == date) return null; else return dateToDateString(date, yyyyMMddHHmmss_EN); } /** * 将Date转换成字符串“yyyy-mm-dd hh:mm:ss”的字符串 * * @param date * @return */ public static String dateToDateString(Date date) { return dateToDateString(date, yyyy_MM_dd_HH_mm_ss_EN); } /** * 将Date转换成formatStr格式的字符串 * * @param date * @param formatStr * @return */ public static String dateToDateString(Date date, String formatStr) { DateFormat df = getDateFormat(formatStr); return df.format(date); } /** * 将Date转换成字符串“yyyymmddhhmmss”的字符串 * * @param date * @return */ public static String dateToDateFullString(Date date) { if (null == date) return null; else return dateToDateString(date, yyyyMMddHHmmss_EN); } /** * 将String转换成formatStr格式的字符串 * * @param date * @param formatStr1 * @param formatStr2 * @return */ public static String stringToDateString(String date, String formatStr1, String formatStr2) { Date d = getDate(date, formatStr1); DateFormat df = getDateFormat(formatStr2); return df.format(d); } /** * 将Date转换成formatStr格式的字符串 * * @param date * @param formatStr * @return */ public static String dateToDateString(Date date, String formatStr) { DateFormat df = getDateFormat(formatStr); return df.format(date); } /** * 获取当前日期yyyy-MM-dd的形式 * * @return */ public static String getCurDate() { return dateToDateString(new Date(), yyyy_MM_dd_EN); } /** * 将String转换成formatStr格式的字符串 * * @param date * @param formatStr1 * @param formatStr2 * @return */ public static String stringToDateString(String date, String formatStr1, String formatStr2) { Date d = getDate(date, formatStr1); DateFormat df = getDateFormat(formatStr2); return df.format(d); } /** * 获取当前日期 * * @return */ public static String getCurDate(String formatStr) { return dateToDateString(new Date(), formatStr); } /** * 获取当前日期yyyy-MM-dd的形式 * * @return */ public static String getCurDate() { return dateToDateString(new Date(), yyyy_MM_dd_EN); } /** * 获取当前日期yyyy年MM月dd日的形式 * * @return */ public static String getCurCNDate() { return dateToDateString(new Date(), yyyy_MM_dd_CN); } /** * 获取当前日期 * * @return */ public static String getCurDate(String formatStr) { return dateToDateString(new Date(), formatStr); } /** * 获取当前日期时间yyyy-MM-dd HH:mm:ss的形式 * * @return */ public static String getCurDateTime() { return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_EN); } /** * 获取当前日期yyyy年MM月dd日的形式 * * @return */ public static String getCurCNDate() { return dateToDateString(new Date(), yyyy_MM_dd_CN); } /** * 获取当前日期时间yyyy年MM月dd日HH时mm分ss秒的形式 * * @return */ public static String getCurZhCNDateTime() { return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_CN); } /** * 获取当前日期时间yyyy-MM-dd HH:mm:ss的形式 * * @return */ public static String getCurDateTime() { return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_EN); } /** * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1 * * @param time1 * @param time2 * @return */ public static long compareDateStr(String time1, String time2) { Date d1 = getDate(time1); Date d2 = getDate(time2); return d2.getTime() - d1.getTime(); } /** * 获取当前日期时间yyyy年MM月dd日HH时mm分ss秒的形式 * * @return */ public static String getCurZhCNDateTime() { return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_CN); } /** * 比较任意格式时间相差毫秒数 * * @param time1 * @param time2 * @param format * @return */ public static long compareDateStr(String time1, String time2, String format) { Date d1 = getDate(time1, format); Date d2 = getDate(time2, format); return d2.getTime() - d1.getTime(); } /** * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1 * * @param time1 * @param time2 * @return */ public static long compareDateStr(String time1, String time2) { Date d1 = getDate(time1); Date d2 = getDate(time2); return d2.getTime() - d1.getTime(); } /** * 比较起始时间与当前时间相差毫秒数 * * @param time * @param format * @return */ public static long compareDateNow(String time, String format) { Date date = getDate(time, format); return new Date().getTime() - date.getTime(); } /** * 比较任意格式时间相差毫秒数 * * @param time1 * @param time2 * @param format * @return */ public static long compareDateStr(String time1, String time2, String format) { Date d1 = getDate(time1, format); Date d2 = getDate(time2, format); return d2.getTime() - d1.getTime(); } /** * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1 * * @param time1 * @param time2 * @return */ public static long compareDateStr(Date time1, Date time2) { return time2.getTime() - time1.getTime(); } /** * 比较起始时间与当前时间相差毫秒数 * * @param time * @param format * @return */ public static long compareDateNow(String time, String format) { Date date = getDate(time, format); return new Date().getTime() - date.getTime(); } /** * nows时间大于date时间 为true * * @param nows * @param date * @return */ public static boolean isTimeBefor(Date nows, Date date) { long hous = nows.getTime() - date.getTime(); if (hous > 0) { return true; } else { return false; } } /** * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1 * * @param time1 * @param time2 * @return */ public static long compareDateStr(Date time1, Date time2) { return time2.getTime() - time1.getTime(); } /** * 将小时数换算成返回以毫秒为单位的时间 * * @param hours * @return */ public static long getMicroSec(BigDecimal hours) { BigDecimal bd; bd = hours.multiply(new BigDecimal(3600 * 1000)); return bd.longValue(); } /** * nows时间大于date时间 为true * * @param nows * @param date * @return */ public static boolean isTimeBefor(Date nows, Date date) { long hous = nows.getTime() - date.getTime(); if (hous > 0) { return true; } else { return false; } } /** * 获取当前日期years年后的一个(formatStr)的字符串 * * @param years * @param formatStr * @return */ public static String getDateStringOfYear(int years, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.YEAR, years); return dateToDateString(now.getTime(), formatStr); } /** * 将小时数换算成返回以毫秒为单位的时间 * * @param hours * @return */ public static long getMicroSec(BigDecimal hours) { BigDecimal bd; bd = hours.multiply(new BigDecimal(3600 * 1000)); return bd.longValue(); } /** * 获取当前日期mon月后的一个(formatStr)的字符串 * * @param months * @param formatStr * @return */ public static String getDateStringOfMon(int months, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MONTH, months); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期years年后的一个(formatStr)的字符串 * * @param years * @param formatStr * @return */ public static String getDateStringOfYear(int years, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.YEAR, years); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期days天后的一个(formatStr)的字符串 * * @param days * @param formatStr * @return */ public static String getDateStringOfDay(int days, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.DATE, days); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期mon月后的一个(formatStr)的字符串 * * @param months * @param formatStr * @return */ public static String getDateStringOfMon(int months, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MONTH, months); return dateToDateString(now.getTime(), formatStr); } /** * 判断日期是否是今天 * * @param date * @return */ public static int theDateIsToday(String date, String format) { String theDate = stringToDateString(date, format, yyyyMMdd_EN); String today = getDateStringOfDay(0, yyyyMMdd_EN); if (theDate.equals(today)) { return 1; } else { return 0; } } /** * 获取当前日期days天后的一个(formatStr)的字符串 * * @param days * @param formatStr * @return */ public static String getDateStringOfDay(int days, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.DATE, days); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期hours小时后的一个(formatStr)的字符串 * * @param hours * @param formatStr * @return */ public static String getDateStringOfHour(int hours, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.HOUR_OF_DAY, hours); return dateToDateString(now.getTime(), formatStr); } /** * 判断日期是否是今天 * * @param date * @return */ public static int theDateIsToday(String date, String format) { String theDate = stringToDateString(date, format, yyyyMMdd_EN); String today = getDateStringOfDay(0, yyyyMMdd_EN); if (theDate.equals(today)) { return 1; } else { return 0; } } /** * 获取指定日期mon月后的一个(formatStr)的字符串 * * @param date * @param mon * @param formatStr * @return */ public static String getDateOfMon(String date, int mon, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.MONTH, mon); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期hours小时后的一个(formatStr)的字符串 * * @param hours * @param formatStr * @return */ public static String getDateStringOfHour(int hours, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.HOUR_OF_DAY, hours); return dateToDateString(now.getTime(), formatStr); } /** * 获取指定日期day天后的一个(formatStr)的字符串 * * @param date * @param day * @param formatStr * @return */ public static String getDateOfDay(String date, int day, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.DATE, day); return dateToDateString(now.getTime(), formatStr); } /** * 获取指定日期mon月后的一个(formatStr)的字符串 * * @param date * @param mon * @param formatStr * @return */ public static String getDateOfMon(String date, int mon, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.MONTH, mon); return dateToDateString(now.getTime(), formatStr); } /** * @Description: 获取指定日期day天后的日期 * @Param: [date, day] * @return: java.util.Date * @Author: 陈凯裕 * @Date: 2021/3/30 */ public static Date getDateOfDay(Date date, int day) { if(date==null) return null; Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(date); now.add(Calendar.DAY_OF_MONTH, day); return now.getTime(); } /** * 获取指定日期day天后的一个(formatStr)的字符串 * * @param date * @param day * @param formatStr * @return */ public static String getDateOfDay(String date, int day, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.DATE, day); return dateToDateString(now.getTime(), formatStr); } public static Date getDate(Date beginDate, int ds) { if (ds == 0) return new Date(); try { SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); Calendar date = Calendar.getInstance(); date.setTime(beginDate); date.set(Calendar.DATE, date.get(Calendar.DATE) - ds); Date endDate = dft.parse(dft.format(date.getTime())); return endDate; } catch (ParseException e) { e.printStackTrace(); } return new Date(); } public static Date getDate(Date beginDate, int ds) { if (ds == 0) return new Date(); try { SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); Calendar date = Calendar.getInstance(); date.setTime(beginDate); date.set(Calendar.DATE, date.get(Calendar.DATE) - ds); Date endDate = dft.parse(dft.format(date.getTime())); return endDate; } catch (ParseException e) { e.printStackTrace(); } return new Date(); } public static String getAfterNDays(Date date, int n, String formateStr) { SimpleDateFormat sdf = new SimpleDateFormat(formateStr); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE, n); return sdf.format(calendar.getTime()); } public static String getAfterNDays(Date date, int n, String formateStr) { SimpleDateFormat sdf = new SimpleDateFormat(formateStr); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE, n); return sdf.format(calendar.getTime()); } /** * 获取指定日期mins分钟后的一个(formatStr)的字符串 * * @param date * @param mins * @param formatStr * @return */ public static String getDateOfMin(String date, int mins, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.SECOND, mins * 60); return dateToDateString(now.getTime(), formatStr); } /** * 获取指定日期mins分钟后的一个(formatStr)的字符串 * * @param date * @param mins * @param formatStr * @return */ public static String getDateOfMin(String date, int mins, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(getDate(date, formatStr)); now.add(Calendar.SECOND, mins * 60); return dateToDateString(now.getTime(), formatStr); } /** * 获取指定日期mins分钟后的一个日期 * * @param date * @param mins * @return */ public static Date getDateOfMin(Date date, int mins) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(date); now.add(Calendar.SECOND, mins * 60); return now.getTime(); } /** * 获取指定日期mins分钟后的一个日期 * * @param date * @param mins * @return */ public static Date getDateOfMin(Date date, int mins) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(date); now.add(Calendar.SECOND, mins * 60); return now.getTime(); } /** * 获取当前日期mins分钟后的一个(formatStr)的字符串 * * @param mins * @param formatStr * @return */ public static String getDateStringOfMin(int mins, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MINUTE, mins); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期mins分钟后的一个(formatStr)的字符串 * * @param mins * @param formatStr * @return */ public static String getDateStringOfMin(int mins, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MINUTE, mins); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期mins分钟后的一个日期 * * @param mins * @return */ public static Date getDateOfMin(int mins) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MINUTE, mins); return now.getTime(); } /** * 获取当前日期mins分钟后的一个日期 * * @param mins * @return */ public static Date getDateOfMin(int mins) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.MINUTE, mins); return now.getTime(); } /** * 获取当前日期sec秒后的一个(formatStr)的字符串 * * @param sec * @param formatStr * @return */ public static String getDateStringOfSec(int sec, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.SECOND, sec); return dateToDateString(now.getTime(), formatStr); } /** * 获取当前日期sec秒后的一个(formatStr)的字符串 * * @param sec * @param formatStr * @return */ public static String getDateStringOfSec(int sec, String formatStr) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(new Date()); now.add(Calendar.SECOND, sec); return dateToDateString(now.getTime(), formatStr); } /** * 获得指定日期月份的天数 * * @return */ public static int getMonthDay(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.getActualMaximum(Calendar.DAY_OF_MONTH); /** * 获得指定日期月份的天数 * * @return */ public static int getMonthDay(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.getActualMaximum(Calendar.DAY_OF_MONTH); } } /** * 获得系统当前月份的天数 * * @return */ public static int getCurentMonthDay() { Date date = Calendar.getInstance().getTime(); return getMonthDay(date); } /** * 获得系统当前月份的天数 * * @return */ public static int getCurentMonthDay() { Date date = Calendar.getInstance().getTime(); return getMonthDay(date); } /** * 获得指定日期月份的天数 yyyy-mm-dd * * @return */ public static int getMonthDay(String date) { Date strDate = getDate(date, yyyy_MM_dd_EN); return getMonthDay(strDate); } /** * 获得指定日期月份的天数 yyyy-mm-dd * * @return */ public static int getMonthDay(String date) { Date strDate = getDate(date, yyyy_MM_dd_EN); return getMonthDay(strDate); } /** * 获取19xx,20xx形式的年 * * @param d * @return */ public static int getYear(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.YEAR); } /** * 获取19xx,20xx形式的年 * * @param d * @return */ public static int getYear(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.YEAR); } /** * 获取月份,1-12月 * * @param d * @return */ public static int getMonth(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.MONTH) + 1; } /** * 获取月份,1-12月 * * @param d * @return */ public static int getMonth(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.MONTH) + 1; } /** * 获取xxxx-xx-xx的日 * * @param d * @return */ public static int getDay(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.DAY_OF_MONTH); } /** * 获取xxxx-xx-xx的日 * * @param d * @return */ public static int getDay(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.DAY_OF_MONTH); } /** * 获取Date中的小时(24小时) * * @param d * @return */ public static int getHour(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.HOUR_OF_DAY); } /** * 获取Date中的小时(24小时) * * @param d * @return */ public static int getHour(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.HOUR_OF_DAY); } /** * 获取Date中的分钟 * * @param d * @return */ public static int getMin(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.MINUTE); } /** * 获取Date中的分钟 * * @param d * @return */ public static int getMin(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.MINUTE); } /** * 获取Date中的秒 * * @param d * @return */ public static int getSecond(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.SECOND); } /** * 得到本周周一 * * @return yyyy-MM-dd */ public static String getMondayOfThisWeek() { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + 1); return dateToDateString(c.getTime(), yyyy_MM_dd_EN); } /** * 得到本周周日 * * @return yyyy-MM-dd */ public static String getSundayOfThisWeek() { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + 7); return dateToDateString(c.getTime()); } /** * 得到本周周(*) * * @return yyyy-MM-dd */ public static String getDayOfThisWeek(int num) { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + num); return dateToDateString(c.getTime(), yyyy_MM_dd_EN); } /** * 得到本月指定天 * * @return yyyy-MM-dd */ public static String getDayOfThisMoon(String num) { String date = dateToDateString(new Date(), yyyy_MM_EN); date = date + "-" + num; return date; } /** * 获取Date中的秒 * * @param d * @return */ public static int getSecond(Date d) { Calendar now = Calendar.getInstance(TimeZone.getDefault()); now.setTime(d); return now.get(Calendar.SECOND); } /** * 获取两个日期相差的天数 * * @param beginDate * @param endDate * @return */ public static long getQuotByDays(String beginDate, String endDate) { long quot = 0; DateFormat df = getDateFormat(yyyy_MM_dd_EN); try { Date d1 = df.parse(beginDate); Date d2 = df.parse(endDate); quot = d2.getTime() - d1.getTime(); quot = quot / 1000 / 60 / 60 / 24; } catch (ParseException e) { throw new RuntimeException(e); } return quot; } /** * 得到本周周一 * * @return yyyy-MM-dd */ public static String getMondayOfThisWeek() { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + 1); return dateToDateString(c.getTime(), yyyy_MM_dd_EN); } /** * 根据日期追加的天数,得到一个新日期 * * @param date * @param days * @return */ public static String getDateAddDay(String date, int days, String format) { DateFormat df = getDateFormat(format); try { Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(date)); cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + days); /** * 得到本周周日 * * @return yyyy-MM-dd */ public static String getSundayOfThisWeek() { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + 7); return dateToDateString(c.getTime()); } date = df.format(cal.getTime()); } catch (ParseException e) { throw new RuntimeException(e); } return date; } /** * 得到本周周(*) * * @return yyyy-MM-dd */ public static String getDayOfThisWeek(int num) { Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + num); return dateToDateString(c.getTime(), yyyy_MM_dd_EN); } /** * 获取当前月的最后一天 * * @return */ public static Date getLastDayOfCurrMonth() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 0); /** * 得到本月指定天 * * @return yyyy-MM-dd */ public static String getDayOfThisMoon(String num) { String date = dateToDateString(new Date(), yyyy_MM_EN); date = date + "-" + num; return date; } return cal.getTime(); } /** * 获取两个日期相差的天数 * * @param beginDate * @param endDate * @return */ public static long getQuotByDays(String beginDate, String endDate) { long quot = 0; DateFormat df = getDateFormat(yyyy_MM_dd_EN); try { Date d1 = df.parse(beginDate); Date d2 = df.parse(endDate); quot = d2.getTime() - d1.getTime(); quot = quot / 1000 / 60 / 60 / 24; } catch (ParseException e) { throw new RuntimeException(e); } return quot; } /** * 根据日期追加的天数,得到一个新日期 * * @param date * @param m * @return */ public static String getDateAddMonth(String date, int m) { DateFormat df = getDateFormat(yyyyMM_EN); try { Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(date)); cal.add(Calendar.MONTH, m); date = df.format(cal.getTime()); } catch (ParseException e) { throw new RuntimeException(e); } return date; } /** * 根据日期追加的天数,得到一个新日期 * * @param date * @param days * @return */ public static String getDateAddDay(String date, int days, String format) { DateFormat df = getDateFormat(format); try { Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(date)); cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + days); /** * 获取指定年月的第一天 * * @param year * @param month * @return */ public static String getFirstDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); // 设置年份 cal.set(Calendar.YEAR, year); // 设置月份 cal.set(Calendar.MONTH, month - 1); // 获取某月最小天数 int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); // 设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); // 格式化日期 DateFormat df = getDateFormat(yyyy_MM_dd_EN); return df.format(cal.getTime()); } date = df.format(cal.getTime()); } catch (ParseException e) { throw new RuntimeException(e); } return date; } /** * 获取指定年月的第一天 * * @param year * @param month * @return */ public static String getLastDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); // 设置年份 cal.set(Calendar.YEAR, year); // 设置月份 cal.set(Calendar.MONTH, month - 1); // 获取某月最大天数 int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); // 格式化日期 DateFormat df = getDateFormat(yyyy_MM_dd_EN); return df.format(cal.getTime()); } /** * 获取当前月的最后一天 * * @return */ public static Date getLastDayOfCurrMonth() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 0); /** * 获取昨天日期 * * @param date * @return * @throws ParseException */ public static String getYesterday(Date date) throws ParseException { DateFormat df = getDateFormat(yyyy_MM_dd_EN); Calendar calendar = Calendar.getInstance(); calendar.setTime(df.parse(df.format(date))); calendar.add(Calendar.DAY_OF_MONTH, -1); return df.format(calendar.getTime()); } return cal.getTime(); } /** * 根据日期追加的天数,得到一个新日期 * * @param date * @param m * @return */ public static String getDateAddMonth(String date, int m) { DateFormat df = getDateFormat(yyyyMM_EN); try { Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(date)); cal.add(Calendar.MONTH, m); date = df.format(cal.getTime()); } catch (ParseException e) { throw new RuntimeException(e); } return date; } /** * 10位时间戳转时间 * * @param dateInt * @param format * @return */ public static String getIntToStr(String dateInt, String format) { DateFormat df = getDateFormat(format); long times = Integer.parseInt(dateInt) * 1000L; Date date = new Date(times); return df.format(date); } /** * 获取指定年月的第一天 * * @param year * @param month * @return */ public static String getFirstDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); // 设置年份 cal.set(Calendar.YEAR, year); // 设置月份 cal.set(Calendar.MONTH, month - 1); // 获取某月最小天数 int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); // 设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); // 格式化日期 DateFormat df = getDateFormat(yyyy_MM_dd_EN); return df.format(cal.getTime()); } /** * 获取 10位时间戳 * * @return */ public static Integer getDateInt() { return (int) (System.currentTimeMillis() / 1000); } /** * 获取指定年月的第一天 * * @param year * @param month * @return */ public static String getLastDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); // 设置年份 cal.set(Calendar.YEAR, year); // 设置月份 cal.set(Calendar.MONTH, month - 1); // 获取某月最大天数 int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); // 格式化日期 DateFormat df = getDateFormat(yyyy_MM_dd_EN); return df.format(cal.getTime()); } /** * 13位时间戳转时间 * * @param time * @param format * @return */ public static String getLongToStr(long time, String format) { Date date = new Date(time); return dateToDateString(date, format); } /** * 获取昨天日期 * * @param date * @return * @throws ParseException */ public static String getYesterday(Date date) throws ParseException { DateFormat df = getDateFormat(yyyy_MM_dd_EN); Calendar calendar = Calendar.getInstance(); calendar.setTime(df.parse(df.format(date))); calendar.add(Calendar.DAY_OF_MONTH, -1); return df.format(calendar.getTime()); } /** * 获取两个小时间的间隔秒杀 * * @param start * @param end * @return */ public static int getIntervalSec(int start, int end) { return (end - start) * 60 * 60; } /** * 毫秒时间戳毫秒加小数点 * * @param time * @return */ public static String getMillsStr(long time) { String timeStr = String.valueOf(time); String suffix = timeStr.substring(0, timeStr.length() - 3); String prefix = timeStr.substring(timeStr.length() - 3, timeStr.length()); return suffix + "." + prefix; } /** * 10位时间戳转时间 * * @param dateInt * @param format * @return */ public static String getIntToStr(String dateInt, String format) { DateFormat df = getDateFormat(format); long times = Integer.parseInt(dateInt) * 1000L; Date date = new Date(times); return df.format(date); } /** * 带小数点的毫秒时间戳转时间格式 * * @param timeStr * @param formatStr * @return */ public static String longToString(String timeStr, String formatStr) { long times = Long.parseLong(timeStr.replace(".", "")); Date date = new Date(times); return dateToDateString(date, formatStr); } /** * 获取 10位时间戳 * * @return */ public static Integer getDateInt() { return (int) (System.currentTimeMillis() / 1000); } /** * 获取当天起始时间 * * @return */ public static Long getTodayTime() { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, 0); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } /** * 13位时间戳转时间 * * @param time * @param format * @return */ public static String getLongToStr(long time, String format) { Date date = new Date(time); return dateToDateString(date, format); } public static Integer getTodayInt() { return (int) (getTodayTime() / 1000); } /** * 获取两个小时间的间隔秒杀 * * @param start * @param end * @return */ public static int getIntervalSec(int start, int end) { return (end - start) * 60 * 60; } /** * 获取当天结束时间 * * @return */ public static Long getEndTime() { Calendar todayEnd = Calendar.getInstance(); todayEnd.set(Calendar.HOUR, 23); todayEnd.set(Calendar.MINUTE, 59); todayEnd.set(Calendar.SECOND, 59); todayEnd.set(Calendar.MILLISECOND, 999); return todayEnd.getTime().getTime(); } /** * 毫秒时间戳毫秒加小数点 * * @param time * @return */ public static String getMillsStr(long time) { String timeStr = String.valueOf(time); String suffix = timeStr.substring(0, timeStr.length() - 3); String prefix = timeStr.substring(timeStr.length() - 3, timeStr.length()); return suffix + "." + prefix; } public static Integer getTomorrowInt() { return (int) (getTomorrowTime() / 1000); } /** * 带小数点的毫秒时间戳转时间格式 * * @param timeStr * @param formatStr * @return */ public static String longToString(String timeStr, String formatStr) { long times = Long.parseLong(timeStr.replace(".", "")); Date date = new Date(times); return dateToDateString(date, formatStr); } /** * 获取第二天起始时间 * * @return */ public static Long getTomorrowTime() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.DAY_OF_MONTH, 1); return cal.getTime().getTime(); } /** * 获取当天起始时间 * * @return */ public static Long getTodayTime() { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, 0); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } /** * 获取当天指定小时的时间 * * @param hour * @return */ public static Long getPointHourTime(int hour) { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, hour); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } public static Integer getTodayInt() { return (int) (getTodayTime() / 1000); } /** * 获取当天n天后的h小时 * * @param days * @param hour * @return */ public static Long getPointDateHourTime(int days, int hour) { Calendar todayStart = Calendar.getInstance(); todayStart.add(Calendar.DATE, days); todayStart.set(Calendar.HOUR_OF_DAY, hour); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } /** * 获取当天结束时间 * * @return */ public static Long getEndTime() { Calendar todayEnd = Calendar.getInstance(); todayEnd.set(Calendar.HOUR, 23); todayEnd.set(Calendar.MINUTE, 59); todayEnd.set(Calendar.SECOND, 59); todayEnd.set(Calendar.MILLISECOND, 999); return todayEnd.getTime().getTime(); } /** * 时分秒转成秒数 * * @param time * @return */ public static Integer hourTosec(String time) { if ("null".equals(time) || StringUtils.isEmpty(time)) { return null; } if (time.length() <= 5) { time += ":00"; } int index1 = time.indexOf(":"); int index2 = time.indexOf(":", index1 + 1); int hh = Integer.parseInt(time.substring(0, index1)); int mi = Integer.parseInt(time.substring(index1 + 1, index2)); int ss = Integer.parseInt(time.substring(index2 + 1)); return hh * 60 * 60 + mi * 60 + ss; } public static Integer getTomorrowInt() { return (int) (getTomorrowTime() / 1000); } /** * 时分秒转成秒数 * * @param time * @return */ public static Integer minTosec(String time) { if (time.length() <= 5) { time += ":00"; } int index1 = time.indexOf(":"); int index2 = time.indexOf(":", index1 + 1); int mi = Integer.parseInt(time.substring(0, index1)); int ss = Integer.parseInt(time.substring(index1 + 1, index2)); return mi * 60 + ss; } /** * 获取第二天起始时间 * * @return */ public static Long getTomorrowTime() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.DAY_OF_MONTH, 1); return cal.getTime().getTime(); } /** * 获取当天指定小时的时间 * * @param hour * @return */ public static Long getPointHourTime(int hour) { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, hour); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } public static boolean isDate(String dateTimeStr, String formatStr) { DateFormat df = getDateFormat(formatStr); try { df.parse(dateTimeStr); return true; } catch (Exception e) { return false; } } /** * 获取当天n天后的h小时 * * @param days * @param hour * @return */ public static Long getPointDateHourTime(int days, int hour) { Calendar todayStart = Calendar.getInstance(); todayStart.add(Calendar.DATE, days); todayStart.set(Calendar.HOUR_OF_DAY, hour); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime().getTime(); } /** * 判断时间是否在时间段内 * * @param strDate 当前时间 yyyy-MM-dd HH:mm:ss * @param strDateBegin 开始时间 00:00:00 * @param strDateEnd 结束时间 00:05:00 * @return */ public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) { // 截取当前时间时分秒 int strDateH = Integer.parseInt(strDate.substring(11, 13)); int strDateM = Integer.parseInt(strDate.substring(14, 16)); int strDateS = Integer.parseInt(strDate.substring(17, 19)); // 截取开始时间时分秒 int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2)); int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5)); int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8)); // 截取结束时间时分秒 int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2)); int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5)); int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8)); if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) { // 当前时间小时数在开始时间和结束时间小时数之间 if (strDateH > strDateBeginH && strDateH < strDateEndH) { return true; // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) { return true; // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) { return true; } // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数 else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) { return true; // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数 } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM && strDateS <= strDateEndS) { return true; } else { return false; } } else { return false; } } /** * 时分秒转成秒数 * * @param time * @return */ public static Integer hourTosec(String time) { if ("null".equals(time) || StringUtils.isEmpty(time)) { return null; } if (time.length() <= 5) { time += ":00"; } int index1 = time.indexOf(":"); int index2 = time.indexOf(":", index1 + 1); int hh = Integer.parseInt(time.substring(0, index1)); int mi = Integer.parseInt(time.substring(index1 + 1, index2)); int ss = Integer.parseInt(time.substring(index2 + 1)); return hh * 60 * 60 + mi * 60 + ss; } /** * 判断时间是否在时间段内 * * @param date 当前时间 yyyy-MM-dd HH:mm:ss * @param strDateBegin 开始时间 00:00:00 * @param strDateEnd 结束时间 00:05:00 * @return */ public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String strDate = sdf.format(date); // 截取当前时间时分秒 int strDateH = Integer.parseInt(strDate.substring(11, 13)); int strDateM = Integer.parseInt(strDate.substring(14, 16)); int strDateS = Integer.parseInt(strDate.substring(17, 19)); // 截取开始时间时分秒 int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2)); int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5)); int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8)); // 截取结束时间时分秒 int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2)); int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5)); int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8)); if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) { // 当前时间小时数在开始时间和结束时间小时数之间 if (strDateH > strDateBeginH && strDateH < strDateEndH) { return true; // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) { return true; // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) { return true; } // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数 else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) { return true; // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数 } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM && strDateS <= strDateEndS) { return true; } else { return false; } } else { return false; } } /** * 时分秒转成秒数 * * @param time * @return */ public static Integer minTosec(String time) { if (time.length() <= 5) { time += ":00"; } int index1 = time.indexOf(":"); int index2 = time.indexOf(":", index1 + 1); int mi = Integer.parseInt(time.substring(0, index1)); int ss = Integer.parseInt(time.substring(index1 + 1, index2)); return mi * 60 + ss; } public static boolean isInTime(int time, int begin, int end) { if (time >= begin && time < end) { return true; } return false; } public static int getMinutest(String begin, String format) { String nowMinutes = getCurDate("HH:mm"); long time = compareDateStr("09:00", nowMinutes, "HH:mm"); return (int) time; } /** * <p> * Title: addDays * </p> * <p> * Description: 加减天数 * </p> * * @param days * @return */ public static Date addDays(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DATE, days); return calendar.getTime(); } public static boolean isDate(String dateTimeStr, String formatStr) { DateFormat df = getDateFormat(formatStr); try { df.parse(dateTimeStr); return true; } catch (Exception e) { return false; } } /** * <p> * Title: addMonths * </p> * <p> * Description: 加减月份 * </p> * * @param date * @param months * @return */ public static Date addMonths(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, months); return calendar.getTime(); } /** * 判断时间是否在时间段内 * * @param strDate * 当前时间 yyyy-MM-dd HH:mm:ss * @param strDateBegin * 开始时间 00:00:00 * @param strDateEnd * 结束时间 00:05:00 * @return */ public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) { // 截取当前时间时分秒 int strDateH = Integer.parseInt(strDate.substring(11, 13)); int strDateM = Integer.parseInt(strDate.substring(14, 16)); int strDateS = Integer.parseInt(strDate.substring(17, 19)); // 截取开始时间时分秒 int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2)); int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5)); int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8)); // 截取结束时间时分秒 int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2)); int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5)); int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8)); if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) { // 当前时间小时数在开始时间和结束时间小时数之间 if (strDateH > strDateBeginH && strDateH < strDateEndH) { return true; // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) { return true; // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) { return true; } // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数 else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) { return true; // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数 } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM && strDateS <= strDateEndS) { return true; } else { return false; } } else { return false; } } /** * <p> * Title: getDays * </p> * <p> * Description: 获取两个日期之前相差的天数 * </p> * * @param minDate * @param maxDate * @return */ public static int getDays(Date minDate, Date maxDate) { int days = 0; if (null == minDate || null == maxDate) return days; days = (int) ((maxDate.getTime() - minDate.getTime()) / (24 * 60 * 60 * 1000)); return days; } /** * 判断时间是否在时间段内 * * @param date * 当前时间 yyyy-MM-dd HH:mm:ss * @param strDateBegin * 开始时间 00:00:00 * @param strDateEnd * 结束时间 00:05:00 * @return */ public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String strDate = sdf.format(date); // 截取当前时间时分秒 int strDateH = Integer.parseInt(strDate.substring(11, 13)); int strDateM = Integer.parseInt(strDate.substring(14, 16)); int strDateS = Integer.parseInt(strDate.substring(17, 19)); // 截取开始时间时分秒 int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2)); int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5)); int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8)); // 截取结束时间时分秒 int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2)); int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5)); int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8)); if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) { // 当前时间小时数在开始时间和结束时间小时数之间 if (strDateH > strDateBeginH && strDateH < strDateEndH) { return true; // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) { return true; // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间 } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) { return true; } // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数 else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) { return true; // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数 } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM && strDateS <= strDateEndS) { return true; } else { return false; } } else { return false; } } /** * 时间戳转 date * * @param longDate 时间戳 * @return */ public static Date getConversionDateByLong(long longDate) { //1529398742830 ZoneId zid = ZoneId.systemDefault(); LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(longDate), zid); ZonedDateTime zdt = time.atZone(zid); Date date = Date.from(zdt.toInstant()); return date; } public static boolean isInTime(int time, int begin, int end) { if (time >= begin && time < end) { return true; } return false; } /** * yyyyMMdd 转 yyyy_MM_dd * * @param strData 时间戳 * @return */ public static String getdatefor_yyyy_MM_dd(String strData) { //1529398742830 //20180205 String yyyy_MM_dd = ""; if (null == strData || strData.length() == 0) { return yyyy_MM_dd; } else { String yyyy = strData.substring(0, 4); String mm = strData.substring(4, 6); String dd = strData.substring(6, 8); yyyy_MM_dd = yyyy + "-" + mm + "-" + dd; } return yyyy_MM_dd; } public static int getMinutest(String begin, String format) { String nowMinutes = getCurDate("HH:mm"); long time = compareDateStr("09:00", nowMinutes, "HH:mm"); return (int) time; } public static String getdatefor_HH_mm_ss(String strData) { //1529398742830 //20180205 String HH_mm_ss = ""; if (null == strData || strData.length() == 0) { return HH_mm_ss; } else { String HH = strData.substring(0, 2); String mm = strData.substring(2, 4); String ss = strData.substring(4, 6); HH_mm_ss = HH + ":" + mm + ":" + ss; } return HH_mm_ss; } /** * <p> * Title: addDays * </p> * <p> * Description: 加减天数 * </p> * * @param days * @return */ public static Date addDays(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DATE, days); return calendar.getTime(); } /** * yyyyMMdd * * @return */ public static String getdatefor_yyyyMMdd() { Date newdate = new Date(); SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd"); String date = dft.format(newdate); return date; } /** * <p> * Title: addMonths * </p> * <p> * Description: 加减月份 * </p> * * @param date * @param months * @return */ public static Date addMonths(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, months); return calendar.getTime(); } /** * yyyyMMdd * * @return */ public static String getdatefor_yyyy_MM_dd() { Date newdate = new Date(); SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); String date = dft.format(newdate); return date; } /** * <p> * Title: getDays * </p> * <p> * Description: 获取两个日期之前相差的天数 * </p> * * @param minDate * @param maxDate * @return */ public static int getDays(Date minDate, Date maxDate) { int days = 0; if (null == minDate || null == maxDate) return days; days = (int) ((maxDate.getTime() - minDate.getTime()) / (24 * 60 * 60 * 1000)); return days; } /** * 时间戳转 date * * @param longDate 时间戳 * @return */ public static Date getConversionDateByLong(long longDate) { //1529398742830 ZoneId zid = ZoneId.systemDefault(); LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(longDate), zid); ZonedDateTime zdt = time.atZone(zid); Date date = Date.from(zdt.toInstant()); return date; } /** * yyyyMMdd 转 yyyy_MM_dd * * @param strData 时间戳 * @return */ public static String getdatefor_yyyy_MM_dd(String strData) { //1529398742830 //20180205 String yyyy_MM_dd=""; if (null == strData || strData.length()==0) { return yyyy_MM_dd; }else { String yyyy = strData.substring(0, 4); String mm = strData.substring(4, 6); String dd = strData.substring(6, 8); yyyy_MM_dd = yyyy+"-"+mm +"-"+dd; } return yyyy_MM_dd; } public static String getdatefor_HH_mm_ss(String strData) { //1529398742830 //20180205 String HH_mm_ss=""; if (null == strData || strData.length()==0) { return HH_mm_ss; }else { String HH = strData.substring(0, 2); String mm = strData.substring(2, 4); String ss = strData.substring(4, 6); HH_mm_ss = HH+":"+mm +":"+ss; } return HH_mm_ss; } /** * yyyyMMdd * * @return */ public static String getdatefor_yyyyMMdd() { Date newdate = new Date(); SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd"); String date = dft.format(newdate); return date; } /** * yyyyMMdd * * @return */ public static String getdatefor_yyyy_MM_dd() { Date newdate = new Date(); SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); String date = dft.format(newdate); return date; } public static void main(String[] args) throws InterruptedException { Date date1 = new Date(); Thread.sleep(1000); Date date2 = new Date(); System.out.println(DateUtils.compareDateStr(date1,date2)); } public static void main(String[] args) throws InterruptedException { Date date1 = new Date(); Thread.sleep(1000); Date date2 = new Date(); System.out.println(DateUtils.compareDateStr(date1, date2)); } } screen-common/src/main/java/com/moral/util/WebUtils.java
@@ -1,14 +1,24 @@ package com.moral.util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Enumeration; import java.util.Map; import java.util.TreeMap; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @Slf4j public class WebUtils extends org.springframework.web.util.WebUtils { public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { Assert.notNull(request, "Request must not be null"); @@ -41,4 +51,27 @@ } return params; } /** * @Description: 获取请求IP地址 * @Param: [request] * @return: java.lang.String * @Author: 陈凯裕 * @Date: 2021/3/31 */ public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ ip = request.getRemoteAddr(); } return ip.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip; } } screen-manage/src/main/java/com/moral/api/aop/log/OperationLogAnno.java
New file @@ -0,0 +1,20 @@ package com.moral.api.aop.log; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface OperationLogAnno { /* * 操作的模块 * */ String module() default ""; /* * 操作的类型 * */ String type() default ""; } screen-manage/src/main/java/com/moral/api/aop/log/OperationLogAspect.java
New file @@ -0,0 +1,117 @@ package com.moral.api.aop.log; import com.alibaba.fastjson.JSON; import com.moral.api.entity.ManageLog; import com.moral.api.entity.Organization; import com.moral.api.mapper.ManageLogMapper; import com.moral.api.pojo.form.organization.OrganizationInsertForm; import com.moral.constant.Constants; import com.moral.util.WebUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; /** * @ClassName OperationLogAspect * @Description 操作日志切面类 * @Author 陈凯裕 * @Date 2021/3/31 13:54 * @Version TODO **/ @Aspect @Component public class OperationLogAspect { @Autowired ManageLogMapper manageLogMapper; /** * @Description: 设置切入点为OperationLogAnno注解使用的地方 * @Param: [] * @return: void * @Author: 陈凯裕 * @Date: 2021/3/31 */ @Pointcut("@annotation(com.moral.api.aop.log.OperationLogAnno)") public void pointCut() { } /** * @Description: 后置通知,存日志到数据库 * @Param: [joinPoint, result]方法切入点,方法返回值 * @return: void * @Author: 陈凯裕 * @Date: 2021/3/31 */ @AfterReturning(returning = "result", value = "pointCut()") public void saveOperLog(JoinPoint joinPoint, Object result) throws Throwable { //获取请求参数 RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); Object parameters = request.getAttribute("parameters"); //获取module和type MethodSignature signature = (MethodSignature) joinPoint.getSignature();//获取切入点方法信号 Method method = signature.getMethod();//获取切入点的方法 OperationLogAnno anno = method.getAnnotation(OperationLogAnno.class);//获取方法的注解 String module = anno.module();//获取操作的模块 String type = anno.type();//获取操作的类型 saveLog(request,parameters, module, type); } /** * @Description: 判断模块 * @Param: [paramters, module, type] * @return: void * @Author: 陈凯裕 * @Date: 2021/3/31 */ public void saveLog(HttpServletRequest request,Object paramters, String module, String type) { if (module.equals(Constants.ORGANIZATION_MODULE_NAME)) { saveOrganizationLog(request,paramters, module, type); } } /** * @Description: 处理组织日志 * @Param: [paramters, module, type] * @return: void * @Author: 陈凯裕 * @Date: 2021/3/31 */ @Transactional public void saveOrganizationLog(HttpServletRequest request,Object paramters, String module, String type) { if (type.equals(Constants.INSERT_OPERATE_TYPE)) {//处理组织添加日志插入 OrganizationInsertForm form = JSON.parseObject(JSON.toJSONString(paramters), OrganizationInsertForm.class); Integer accountId = 1;//固定 尚未更改 String accountName = "测试人员"; String organizationName = form.getName(); String ip = WebUtils.getIpAddr(request); String content = accountName+"添加了新组织:"+organizationName; ManageLog manageLog = new ManageLog(); manageLog.setContent(content); manageLog.setIp(ip); manageLog.setAccountId(accountId); manageLog.setModule(module); manageLog.setType(type); manageLogMapper.insert(manageLog); } else if (type.equals(Constants.DELETE_OPERATE_TYPE)) { //处理组织删除日志 } else if (type.equals(Constants.UPDATE_OPERATE_TYPE)) { //处理组织更新日志 } } } screen-manage/src/main/java/com/moral/api/config/mybatis/wrapper/NullFilterWrapper.java
New file @@ -0,0 +1,36 @@ package com.moral.api.config.mybatis.wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.enums.SqlKeyword; import com.baomidou.mybatisplus.core.enums.SqlLike; /** * @ClassName FiltNullWrapper * @Description 查询构造器,传入null并不会作为条件 * @Author 陈凯裕 * @Date 2021/3/30 10:45 * @Version TODO **/ public class NullFilterWrapper<T> extends QueryWrapper<T> { @Override protected QueryWrapper<T> likeValue(boolean condition, String column, Object val, SqlLike sqlLike) { if(val==null) condition = false; return super.likeValue(condition, column, val, sqlLike); } @Override public QueryWrapper<T> between(boolean condition, String column, Object val1, Object val2) { if(val1==null||val2==null) condition = false; return super.between(condition, column, val1, val2); } @Override public QueryWrapper<T> eq(boolean condition, String column, Object val) { if(val==null) condition = false; return super.eq(condition, column, val); } } screen-manage/src/main/java/com/moral/api/controller/AccountController.java
@@ -1,9 +1,7 @@ package com.moral.api.controller; import com.moral.api.pojo.dto.account.AccountDeleteDTO; import com.moral.api.pojo.dto.account.AccountInsertDTO; import com.moral.api.pojo.dto.account.AccountQueryDTO; import com.moral.api.pojo.dto.account.AccountUpdateDTO; import com.moral.api.pojo.dto.account.*; import com.moral.api.pojo.dto.organization.OrganizationDTO; import com.moral.api.pojo.form.account.AccountDeleteForm; import com.moral.api.pojo.form.account.AccountInsertForm; import com.moral.api.pojo.form.account.AccountQueryForm; @@ -29,68 +27,84 @@ ManageAccountService accountService; @PostMapping("insert") public ResultMessage insert(@RequestBody AccountInsertForm accountInsertForm) { if (!accountInsertForm.valid()) public ResultMessage insert(@RequestBody AccountInsertForm form) { //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否符合条件 AccountInsertDTO conditionDTO = accountInsertForm.paramValid(); //判断参数是否有效 AccountInsertDTO conditionDTO = form.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } AccountInsertDTO accountInsertDTO = accountService.insertAccount(accountInsertForm); //处理插入业务 AccountDTO dto = accountService.insertAccount(form); AccountInsertVO accountInsertVO = AccountInsertVO.convert(accountInsertDTO); //转换前端需要参数 AccountInsertVO accountInsertVO = AccountInsertVO.convert(dto); return new ResultMessage(accountInsertDTO.getCode(), accountInsertDTO.getMsg(), accountInsertVO); return new ResultMessage(dto.getCode(), dto.getMsg(), accountInsertVO); } @GetMapping("query") public ResultMessage query(AccountQueryForm accountQueryForm) { if (!accountQueryForm.valid()) @PostMapping("update") public ResultMessage update(@RequestBody AccountUpdateForm form) { //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); AccountQueryDTO accountQueryDTO = accountService.queryAccount(accountQueryForm); //判断参数是否有效 AccountUpdateDTO conditionDTO = form.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } //处理更新业务 AccountDTO dto = accountService.updateAccount(form); //转换前端需要的参数 AccountUpdateVO vo = AccountUpdateVO.convert(dto); return new ResultMessage(dto.getCode(), dto.getMsg(), vo); } @PostMapping("delete") public ResultMessage delete(@RequestBody AccountDeleteForm form) { //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //处理删除业务 AccountDTO dto = accountService.deleteAccount(form); //转换前端需要的参数 AccountDeleteVO vo = AccountDeleteVO.convert(dto); return new ResultMessage(dto.getCode(), dto.getMsg(), vo); } @GetMapping("query") public ResultMessage query(AccountQueryForm form) { //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //处理查询业务 AccountQueryDTO accountQueryDTO = accountService.queryAccount(form); //转换前端需要的参数 AccountQueryVO accountQueryVO = AccountQueryVO.convert(accountQueryDTO); return new ResultMessage(accountQueryDTO.getCode(), accountQueryDTO.getMsg(), accountQueryVO); } @PostMapping("update") public ResultMessage update(@RequestBody AccountUpdateForm accountUpdateRequest) { if (!accountUpdateRequest.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否符合条件 AccountUpdateDTO conditionDTO = accountUpdateRequest.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } AccountUpdateDTO accountUpdateDTO = accountService.updateAccount(accountUpdateRequest); AccountUpdateVO accountUpdateVO = AccountUpdateVO.convert(accountUpdateDTO); return new ResultMessage(accountUpdateDTO.getCode(), accountUpdateDTO.getMsg(), accountUpdateVO); } @PostMapping("delete") public ResultMessage delete(@RequestBody AccountDeleteForm accountDeleteForm) { if (!accountDeleteForm.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); AccountDeleteDTO accountDeleteDTO = accountService.deleteAccount(accountDeleteForm); AccountDeleteVO accountDeleteVO = AccountDeleteVO.convert(accountDeleteDTO); return new ResultMessage(accountDeleteDTO.getCode(), accountDeleteDTO.getMsg(), accountDeleteVO); } } screen-manage/src/main/java/com/moral/api/controller/OrganizationController.java
@@ -1,5 +1,6 @@ package com.moral.api.controller; import com.moral.api.aop.log.OperationLogAnno; import com.moral.api.pojo.dto.organization.OrganizationDTO; import com.moral.api.pojo.dto.organization.OrganizationQueryDTO; import com.moral.api.pojo.form.organization.OrganizationDeleteForm; @@ -8,14 +9,18 @@ import com.moral.api.pojo.form.organization.OrganizationUpdateForm; import com.moral.api.pojo.vo.organization.OrganizationDeleteVO; import com.moral.api.pojo.vo.organization.OrganizationInsertVO; import com.moral.api.pojo.vo.organization.OrganizationQueryVO; import com.moral.api.pojo.vo.organization.OrganizationUpdateVO; import com.moral.api.service.OrganizationService; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; /** * @ClassName OrganizationController @@ -33,58 +38,61 @@ OrganizationService organizationService; @PostMapping("insert") public ResultMessage insert(@RequestBody OrganizationInsertForm organizationInsertForm) { //判断参数是否缺少参数 if (!organizationInsertForm.valid()) @OperationLogAnno(module = Constants.ORGANIZATION_MODULE_NAME,type = Constants.INSERT_OPERATE_TYPE) public ResultMessage insert(@RequestBody OrganizationInsertForm form, HttpServletRequest request) { //请求参数存入request中 request.setAttribute("parameters",form); //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否有效 OrganizationDTO conditionDTO = organizationInsertForm.paramValid(); OrganizationDTO conditionDTO = form.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } //处理插入业务 OrganizationDTO organizationDTO = organizationService.insertOrganization(organizationInsertForm); OrganizationDTO dto = organizationService.insertOrganization(form); //转换前端需要的参数 OrganizationInsertVO organizationInsertVO = OrganizationInsertVO.convert(organizationDTO); OrganizationInsertVO vo = OrganizationInsertVO.convert(dto); return new ResultMessage(organizationDTO.getCode(),organizationDTO.getMsg(),organizationInsertVO); return new ResultMessage(dto.getCode(),dto.getMsg(),vo); } @PostMapping("update") public ResultMessage update(@RequestBody OrganizationUpdateForm organizationUpdateForm){ //判断参数是否缺少参数 if (!organizationUpdateForm.valid()) public ResultMessage update(@RequestBody OrganizationUpdateForm form){ //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否有效 OrganizationDTO conditionDTO = organizationUpdateForm.paramValid(); OrganizationDTO conditionDTO = form.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } //处理更新业务 OrganizationDTO organizationDTO = organizationService.updateOrganization(organizationUpdateForm); OrganizationDTO dto = organizationService.updateOrganization(form); //转换前端需要的参数 OrganizationUpdateVO organizationUpdateVO = OrganizationUpdateVO.convert(organizationDTO); OrganizationUpdateVO vo = OrganizationUpdateVO.convert(dto); return new ResultMessage(organizationDTO.getCode(),organizationDTO.getMsg(),organizationUpdateVO); return new ResultMessage(dto.getCode(),dto.getMsg(),vo); } @PostMapping("delete") public ResultMessage delete(@RequestBody OrganizationDeleteForm organizationDeleteForm){ //判断参数是否缺少参数 if (!organizationDeleteForm.valid()) public ResultMessage delete(@RequestBody OrganizationDeleteForm form){ //判断是否缺少参数 if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //处理删除业务 OrganizationDTO dto = organizationService.deleteOrganization(organizationDeleteForm); OrganizationDTO dto = organizationService.deleteOrganization(form); //转换前端需要的参数 OrganizationDeleteVO vo = OrganizationDeleteVO.convert(dto); @@ -93,24 +101,19 @@ } @GetMapping("query") public ResultMessage query(OrganizationQueryForm organizationQueryForm){ public ResultMessage query(OrganizationQueryForm form){ //判断是否缺少参数 if (!organizationQueryForm.valid()) if (!form.valid()) return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); //判断参数是否有效 OrganizationDTO conditionDTO = organizationQueryForm.paramValid(); if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); } //处理查询业务 OrganizationQueryDTO organizationQueryDTO = organizationService.queryOrganization(organizationQueryForm); OrganizationQueryDTO dto = organizationService.queryOrganization(form); //转换前端需要参数 OrganizationQueryVO vo = OrganizationQueryVO.convert(dto); return null; return new ResultMessage(dto.getCode(),dto.getMsg(),vo); } } screen-manage/src/main/java/com/moral/api/entity/ManageLog.java
@@ -14,7 +14,7 @@ * </p> * * @author moral * @since 2021-03-09 * @since 2021-03-31 */ @Data @EqualsAndHashCode(callSuper = false) @@ -29,19 +29,24 @@ private Integer id; /** * 操作类型 */ private String type; /** * 操作模块 */ private String module; /** * 操作描述 */ private String content; /** * 组织Id */ private Integer organizationId; /** * 操作人员id */ private Integer operateId; private Integer accountId; /** * Ip地址 screen-manage/src/main/java/com/moral/api/mapper/ManageLogMapper.java
@@ -9,7 +9,7 @@ * </p> * * @author moral * @since 2021-03-09 * @since 2021-03-31 */ public interface ManageLogMapper extends BaseMapper<ManageLog> { screen-manage/src/main/java/com/moral/api/pojo/dto/organization/OrganizationDTO.java
@@ -35,13 +35,6 @@ * 父组织 * */ private Organization parentOrganization; /* * 子组织 * */ private List<Organization> childOrganizations; /* * 管理员 * */ private User admin; } screen-manage/src/main/java/com/moral/api/pojo/form/account/AccountInsertForm.java
@@ -1,8 +1,10 @@ package com.moral.api.pojo.form.account; import com.moral.api.entity.ManageAccount; import com.moral.api.pojo.dto.account.AccountInsertDTO; import com.moral.constant.ResponseCodeEnum; import com.moral.util.AESUtils; import com.moral.util.MD5Utils; import com.moral.util.RegexUtils; import lombok.Data; import org.springframework.beans.factory.annotation.Value; @@ -19,7 +21,7 @@ * @Version TODO **/ @Data public class AccountInsertForm implements Serializable{ public class AccountInsertForm { private String account; @@ -90,4 +92,15 @@ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return dto; } public ManageAccount formConvertEntity(){ ManageAccount manageAccount = new ManageAccount(); manageAccount.setAccount(account); manageAccount.setPassword(MD5Utils.saltMD5(AESUtils.decrypt(password))); manageAccount.setUserName(userName); manageAccount.setEmail(email); manageAccount.setMobile(mobile); manageAccount.setWechat(wechat); return manageAccount; } } screen-manage/src/main/java/com/moral/api/pojo/form/account/AccountQueryForm.java
@@ -1,9 +1,16 @@ package com.moral.api.pojo.form.account; import com.fasterxml.jackson.annotation.JsonFormat; import com.moral.api.entity.ManageAccount; import com.moral.api.pojo.dto.account.AccountDTO; import com.moral.constant.ResponseCodeEnum; import com.moral.util.RegexUtils; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.util.ObjectUtils; import java.io.Serializable; import java.util.Date; /** * @ClassName AccountQueryRequest @@ -13,15 +20,11 @@ * @Version TODO **/ @Data public class AccountQueryForm implements Serializable { public class AccountQueryForm { private Integer page; private Integer size; private Integer accountId; private String account; private String userName; @@ -32,6 +35,14 @@ private String wechat; private String isDelete; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date createStartTime; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date createEndTime; private String order; @@ -46,4 +57,5 @@ return false; return true; } } screen-manage/src/main/java/com/moral/api/pojo/form/account/AccountUpdateForm.java
@@ -1,9 +1,11 @@ package com.moral.api.pojo.form.account; import com.moral.api.entity.ManageAccount; import com.moral.api.pojo.dto.account.AccountInsertDTO; import com.moral.api.pojo.dto.account.AccountUpdateDTO; import com.moral.constant.ResponseCodeEnum; import com.moral.util.AESUtils; import com.moral.util.MD5Utils; import com.moral.util.RegexUtils; import lombok.Data; import org.springframework.util.ObjectUtils; @@ -35,15 +37,15 @@ private List<Integer> roleIds; public boolean valid() { if(ObjectUtils.isEmpty(accountId)) if (ObjectUtils.isEmpty(accountId)) return false; if( ObjectUtils.isEmpty(userName)&& ObjectUtils.isEmpty(password)&& ObjectUtils.isEmpty(email)&& ObjectUtils.isEmpty(mobile)&& ObjectUtils.isEmpty(wechat)&& ObjectUtils.isEmpty(roleIds) if ( ObjectUtils.isEmpty(userName) && ObjectUtils.isEmpty(password) && ObjectUtils.isEmpty(email) && ObjectUtils.isEmpty(mobile) && ObjectUtils.isEmpty(wechat) && ObjectUtils.isEmpty(roleIds) ) return false; return true; @@ -68,16 +70,27 @@ } } //判断密码是否符合规则 if (!ObjectUtils.isEmpty(password)){ if(!RegexUtils.checkPassword(AESUtils.decrypt(password))){ if (!ObjectUtils.isEmpty(password)) { if (!RegexUtils.checkPassword(AESUtils.decrypt(password))) { dto.setCode(ResponseCodeEnum.PASSWORD_INVALID.getCode()); dto.setMsg(ResponseCodeEnum.PASSWORD_INVALID.getMsg()); return dto; } } dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return dto; } public ManageAccount formConvertEntity() { ManageAccount manageAccount = new ManageAccount(); manageAccount.setId(accountId); if (!ObjectUtils.isEmpty(password)) manageAccount.setPassword(MD5Utils.saltMD5(AESUtils.decrypt(password))); manageAccount.setUserName(userName); manageAccount.setEmail(email); manageAccount.setMobile(mobile); manageAccount.setWechat(wechat); return manageAccount; } } screen-manage/src/main/java/com/moral/api/pojo/form/login/LoginForm.java
@@ -13,7 +13,7 @@ * @Version TODO **/ @Data public class LoginForm implements Serializable { public class LoginForm { private String account; screen-manage/src/main/java/com/moral/api/pojo/form/login/LogoutForm.java
@@ -13,7 +13,7 @@ * @Version TODO **/ @Data public class LogoutForm implements Serializable { public class LogoutForm { private String accountId; screen-manage/src/main/java/com/moral/api/pojo/form/organization/OrganizationInsertForm.java
@@ -20,7 +20,7 @@ * @Version TODO **/ @Data public class OrganizationInsertForm implements Serializable { public class OrganizationInsertForm { private Integer parentId; screen-manage/src/main/java/com/moral/api/pojo/form/organization/OrganizationQueryForm.java
@@ -1,14 +1,16 @@ package com.moral.api.pojo.form.organization; import com.fasterxml.jackson.annotation.JsonFormat; import com.moral.api.entity.Organization; import com.moral.api.pojo.dto.organization.OrganizationDTO; import com.moral.constant.ResponseCodeEnum; import com.moral.util.DateUtils; import com.moral.util.RegexUtils; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.util.ObjectUtils; import java.util.Date; /** * @ClassName OrganizationQueryForm @@ -18,7 +20,7 @@ * @Version TODO **/ @Data public class OrganizationQueryForm { public class OrganizationQueryForm { private Integer page; @@ -46,6 +48,22 @@ private String isDelete; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date createStartTime; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date createEndTime; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date expireStartTime; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date expireEndTime; private String order; private String orderType; @@ -59,43 +77,5 @@ return true; } public OrganizationDTO paramValid() { OrganizationDTO dto = new OrganizationDTO(); //判断电话号是否符合条件 if (!ObjectUtils.isEmpty(phone)) { if (!RegexUtils.checkMobile(phone) && !RegexUtils.checkPhone(phone)) { dto.setCode(ResponseCodeEnum.PHONE_INVALID.getCode()); dto.setMsg(ResponseCodeEnum.PHONE_INVALID.getMsg()); return dto; } } //判断邮箱是否符合条件 if (!ObjectUtils.isEmpty(email)) { if (!RegexUtils.checkEmail(email)) { dto.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode()); dto.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg()); return dto; } } dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return dto; } public Organization formConvertEntity() { Organization organization = new Organization(); organization.setParentId(parentId); organization.setName(name); organization.setProvinceCode(provinceCode); organization.setCityCode(cityCode); organization.setAreaCode(areaCode); organization.setTownCode(townCode); organization.setVillageCode(villageCode); organization.setPhone(phone); organization.setEmail(email); organization.setWechat(wechat); organization.setIsDelete(isDelete); return organization; } } screen-manage/src/main/java/com/moral/api/pojo/vo/account/AccountDeleteVO.java
@@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.moral.api.entity.ManageAccount; import com.moral.api.pojo.dto.account.AccountDTO; import com.moral.api.pojo.dto.account.AccountDeleteDTO; import com.moral.constant.ResponseCodeEnum; import lombok.Data; @@ -19,8 +20,7 @@ public class AccountDeleteVO extends AccountVO { public static AccountDeleteVO convert(AccountDeleteDTO dto) { public static AccountDeleteVO convert(AccountDTO dto) { if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode()) return null; AccountDeleteVO vo = new AccountDeleteVO(); screen-manage/src/main/java/com/moral/api/pojo/vo/account/AccountInsertVO.java
@@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.moral.api.entity.ManageRole; import com.moral.api.pojo.dto.account.AccountDTO; import com.moral.api.pojo.dto.account.AccountInsertDTO; import com.moral.constant.ResponseCodeEnum; import lombok.Data; @@ -29,7 +30,7 @@ * @Date: 2021/3/15 */ public static AccountInsertVO convert(AccountInsertDTO dto) { public static AccountInsertVO convert(AccountDTO dto) { if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode()) return null; screen-manage/src/main/java/com/moral/api/pojo/vo/account/AccountQueryVO.java
@@ -1,13 +1,17 @@ package com.moral.api.pojo.vo.account; import com.fasterxml.jackson.annotation.JsonInclude; import com.moral.api.entity.ManageAccount; import com.moral.api.entity.ManageRole; import com.moral.api.pojo.dto.account.AccountDTO; import com.moral.api.pojo.dto.account.AccountQueryDTO; import com.moral.constant.ResponseCodeEnum; import lombok.Data; import org.springframework.util.ObjectUtils; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** @@ -43,7 +47,7 @@ List<AccountDTO> accountDTOs = dto.getAccountDTOS(); if (!ObjectUtils.isEmpty(accountDTOs)) { for (AccountDTO accountDTO : accountDTOs) { AccountVO vo = AccountVO.convert(accountDTO); AccountVO vo = convertToQueryPage(accountDTO); accountVOs.add(vo); } } @@ -55,4 +59,31 @@ vo.setSize(size); return vo; } public static AccountVO convertToQueryPage(AccountDTO dto) { if (dto.getAccount() == null) return null; AccountInsertVO vo = new AccountInsertVO(); ManageAccount account = dto.getAccount(); List<ManageRole> roles = dto.getRoles(); List<String> roleNames = new ArrayList<>(); if (!ObjectUtils.isEmpty(roles)) { roles.forEach(role -> roleNames.add(role.getName())); } vo.setId(account.getId()); vo.setUserName(account.getUserName()); vo.setEmail(account.getEmail()); vo.setMobile(account.getMobile()); vo.setWechat(account.getWechat()); vo.setRoleNames(roleNames); //Date转换String Date createTime = account.getCreateTime(); Date updateTime = account.getUpdateTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String createTimeStr = sdf.format(createTime); String updateTimeStr = sdf.format(updateTime); vo.setCreateTime(createTimeStr); vo.setUpdateTime(updateTimeStr); return vo; } } screen-manage/src/main/java/com/moral/api/pojo/vo/account/AccountUpdateVO.java
@@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.moral.api.entity.ManageRole; import com.moral.api.pojo.dto.account.AccountDTO; import com.moral.api.pojo.dto.account.AccountInsertDTO; import com.moral.api.pojo.dto.account.AccountUpdateDTO; import com.moral.constant.ResponseCodeEnum; @@ -23,7 +24,7 @@ public class AccountUpdateVO extends AccountVO { public static AccountUpdateVO convert(AccountUpdateDTO dto) { public static AccountUpdateVO convert(AccountDTO dto) { if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode()) return null; screen-manage/src/main/java/com/moral/api/pojo/vo/account/AccountVO.java
@@ -39,30 +39,5 @@ private String updateTime; public static AccountVO convert(AccountDTO dto) { if (dto.getAccount() == null) return null; AccountVO vo = new AccountVO(); ManageAccount account = dto.getAccount(); List<ManageRole> roles = dto.getRoles(); List<String> roleNames = new ArrayList<>(); if (!ObjectUtils.isEmpty(roles)) { roles.forEach(role -> roleNames.add(role.getName())); } vo.setId(account.getId()); vo.setUserName(account.getUserName()); vo.setEmail(account.getEmail()); vo.setMobile(account.getMobile()); vo.setWechat(account.getWechat()); vo.setRoleNames(roleNames); //Date转换String Date createTime = account.getCreateTime(); Date updateTime = account.getUpdateTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String createTimeStr = sdf.format(createTime); String updateTimeStr = sdf.format(updateTime); vo.setCreateTime(createTimeStr); vo.setUpdateTime(updateTimeStr); return vo; } } screen-manage/src/main/java/com/moral/api/pojo/vo/organization/OrganizationDeleteVO.java
@@ -19,6 +19,7 @@ return null; OrganizationDeleteVO vo = new OrganizationDeleteVO(); Organization organization = dto.getOrganization(); vo.setName(organization.getName()); vo.setId(organization.getId()); return vo; screen-manage/src/main/java/com/moral/api/pojo/vo/organization/OrganizationInsertVO.java
@@ -18,6 +18,7 @@ return null; OrganizationInsertVO vo = new OrganizationInsertVO(); Organization organization = dto.getOrganization(); vo.setId(organization.getId()); vo.setName(organization.getName()); return vo; screen-manage/src/main/java/com/moral/api/pojo/vo/organization/OrganizationQueryVO.java
New file @@ -0,0 +1,87 @@ package com.moral.api.pojo.vo.organization; import com.fasterxml.jackson.annotation.JsonInclude; import com.moral.api.entity.Organization; import com.moral.api.pojo.dto.organization.OrganizationDTO; import com.moral.api.pojo.dto.organization.OrganizationQueryDTO; import com.moral.constant.ResponseCodeEnum; import com.moral.util.DateUtils; import lombok.Data; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @ClassName OrganizationQueryVO * @Description TODO * @Author 陈凯裕 * @Date 2021/3/26 13:52 * @Version TODO **/ @Data @JsonInclude(JsonInclude.Include.NON_EMPTY) public class OrganizationQueryVO { private long pages; private long total; private long current; private long size; private List<OrganizationVO> organizations; public static OrganizationQueryVO convert(OrganizationQueryDTO dto) { if (dto.getCode() != ResponseCodeEnum.SUCCESS.getCode()) return null; OrganizationQueryVO vo = new OrganizationQueryVO(); long page = dto.getPage(); long total = dto.getTotal(); long current = dto.getCurrent(); long size = dto.getSize(); List<OrganizationDTO> organizationDTOS = dto.getOrganizationDTOS(); List<OrganizationVO> organizationVOS = new ArrayList<>(); for (OrganizationDTO organizationDTO : organizationDTOS) { OrganizationVO organizationVO = convertToQueryPage(organizationDTO); organizationVOS.add(organizationVO); } vo.setCurrent(current); vo.setOrganizations(organizationVOS); vo.setPages(page); vo.setSize(size); vo.setTotal(total); return vo; } /** * @Description: 转换查询界面需要展现的参数 * @Param: [dto] * @return: com.moral.api.pojo.vo.organization.OrganizationVO * @Author: 陈凯裕 * @Date: 2021/3/26 */ private static OrganizationVO convertToQueryPage(OrganizationDTO dto) { OrganizationVO vo = new OrganizationVO(); Organization organization = dto.getOrganization(); Organization parentOrganization = dto.getParentOrganization(); Date createTime = organization.getCreateTime(); Date expireTime = organization.getExpireTime(); String createTimeStr = DateUtils.dateToDateString(createTime, "yyyy-MM-dd"); String exipreTimeStr = DateUtils.dateToDateString(expireTime, "yyyy-MM-dd"); vo.setName(organization.getName()); if (!ObjectUtils.isEmpty(parentOrganization)) vo.setParentName(parentOrganization.getName()); vo.setPhone(organization.getPhone()); vo.setEmail(organization.getEmail()); vo.setWechat(organization.getWechat()); vo.setAddress(organization.getAddress()); vo.setCreateTime(createTimeStr); vo.setExpireTime(exipreTimeStr); return vo; } } screen-manage/src/main/java/com/moral/api/pojo/vo/organization/OrganizationUpdateVO.java
@@ -19,6 +19,7 @@ return null; OrganizationUpdateVO vo = new OrganizationUpdateVO(); Organization organization = dto.getOrganization(); vo.setId(organization.getId()); vo.setName(organization.getName()); return vo; screen-manage/src/main/java/com/moral/api/pojo/vo/organization/OrganizationVO.java
@@ -24,6 +24,8 @@ private String name; private String parentName; private Integer provinceCode; private Integer cityCode; screen-manage/src/main/java/com/moral/api/service/ManageAccountService.java
@@ -45,7 +45,7 @@ * @Author: 陈凯裕 * @Date: 2021/3/13 */ AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm); AccountDTO insertAccount(AccountInsertForm accountInsertForm); /** * @Description: 查询账号 @@ -63,7 +63,7 @@ * @Author: 陈凯裕 * @Date: 2021/3/15 */ AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm); AccountDTO updateAccount(AccountUpdateForm accountUpdateForm); /** * @Description: 删除账号 @@ -72,5 +72,5 @@ * @Author: 陈凯裕 * @Date: 2021/3/16 */ AccountDeleteDTO deleteAccount(AccountDeleteForm accountDeleteForm); AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm); } screen-manage/src/main/java/com/moral/api/service/ManageLogService.java
@@ -9,7 +9,7 @@ * </p> * * @author moral * @since 2021-03-09 * @since 2021-03-31 */ public interface ManageLogService extends IService<ManageLog> { screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java
@@ -22,11 +22,10 @@ import com.moral.api.pojo.form.login.LogoutForm; import com.moral.api.service.ManageAccountService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; import com.moral.util.AESUtils; import com.moral.util.MD5Utils; import com.moral.util.TokenUtils; import com.moral.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,12 +56,12 @@ /** * @Description: 登陆 * @Param: [parameters] * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 陈凯裕 * @Date: 2021/3/11 */ * @Description: 登陆接口 * @Param: [loginForm] * @return: com.moral.api.pojo.dto.login.LoginDTO * @Author: 陈凯裕 * @Date: 2021/3/30 */ @Override public LoginDTO login(LoginForm loginForm) { LoginDTO loginDTO = new LoginDTO(); @@ -129,7 +128,7 @@ /** * @Description: 注销 * @Param: [parameters] * @return: java.util.Map<java.lang.String , java.lang.Object> * @return: * @Author: 陈凯裕 * @Date: 2021/3/11 */ @@ -150,40 +149,28 @@ */ @Override @Transactional public AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm) { AccountInsertDTO accountInsertDTO = new AccountInsertDTO(); public AccountDTO insertAccount(AccountInsertForm accountInsertForm) { AccountDTO accountDTO = new AccountDTO(); //取参 String account = accountInsertForm.getAccount(); String AESPassword = accountInsertForm.getPassword(); String password = MD5Utils.saltMD5(AESUtils.decrypt(AESPassword)); String userName = accountInsertForm.getUserName(); String email = accountInsertForm.getEmail(); String mobile = accountInsertForm.getMobile(); String wechat = accountInsertForm.getWechat(); ManageAccount manageAccount = accountInsertForm.formConvertEntity(); List<String> roleIdsStr = accountInsertForm.getRoleIds(); /*判断账号是否存在*/ ManageAccount existAccount = new ManageAccount(); existAccount.setAccount(account); existAccount.setAccount(manageAccount.getAccount()); existAccount.setIsDelete(Constants.NOT_DELETE); QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); wrapper.setEntity(existAccount); List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper); if (!ObjectUtils.isEmpty(exitAccounts)) { accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode()); accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); return accountInsertDTO; ManageAccount exitAccountResult = manageAccountMapper.selectOne(wrapper); if (!ObjectUtils.isEmpty(exitAccountResult)) { accountDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode()); accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); return accountDTO; } //封装account ManageAccount manageAccount = new ManageAccount(); manageAccount.setAccount(account); manageAccount.setPassword(password); manageAccount.setUserName(userName); manageAccount.setEmail(email); manageAccount.setMobile(mobile); manageAccount.setWechat(wechat); //插入 manageAccountMapper.insert(manageAccount); //封装account_role /*String to Integer*/ List<ManageRole> roles = null; @@ -204,11 +191,11 @@ roles = manageRoleMapper.selectBatchIds(roleIds); } //封装返回结果 accountInsertDTO.setAccount(manageAccount); accountInsertDTO.setRoles(roles); accountInsertDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountInsertDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return accountInsertDTO; accountDTO.setAccount(manageAccount); accountDTO.setRoles(roles); accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return accountDTO; } /** @@ -221,11 +208,10 @@ @Override public AccountQueryDTO queryAccount(AccountQueryForm accountQueryForm) { AccountQueryDTO accountQueryDTO = new AccountQueryDTO(); //取参 Integer pageCount = accountQueryForm.getPage(); Integer size = accountQueryForm.getSize(); Integer accountId = accountQueryForm.getAccountId(); String account = accountQueryForm.getAccount(); String userName = accountQueryForm.getUserName(); String email = accountQueryForm.getEmail(); String mobile = accountQueryForm.getMobile(); @@ -233,49 +219,34 @@ String isDelete = accountQueryForm.getIsDelete(); String order = accountQueryForm.getOrder(); String orderType = accountQueryForm.getOrderType(); Date createStartTime = accountQueryForm.getCreateStartTime(); Date createEndTime = DateUtils.getDateOfDay(accountQueryForm.getCreateEndTime(), 1); //查询用户 //组装查询条件 Page<ManageAccount> page = new Page<>(pageCount, size); QueryWrapper<ManageAccount> wrapper = new QueryWrapper(); if (!ObjectUtils.isEmpty(accountId)) { wrapper.eq("id", accountId); NullFilterWrapper<ManageAccount> wrapper = new NullFilterWrapper<>(); wrapper.like("user_name", userName); wrapper.like("email", email); wrapper.like("mobile", mobile); wrapper.like("wechat", wechat); wrapper.between("create_time", createStartTime, createEndTime); if (!ObjectUtils.isEmpty(order) && !ObjectUtils.isEmpty(orderType)) { //排序顺序条件构造 if (orderType.equals(Constants.ORDER_ASC)) wrapper.orderByAsc(ConvertUtils.toLine(order)); else wrapper.orderByDesc(ConvertUtils.toLine(order)); } if (!ObjectUtils.isEmpty(userName)) { wrapper.like("user_name", userName); } if (!ObjectUtils.isEmpty(account)) { wrapper.like("account", account); } if (!ObjectUtils.isEmpty(email)) { wrapper.like("email", email); } if (!ObjectUtils.isEmpty(mobile)) { wrapper.like("mobile", mobile); } if (!ObjectUtils.isEmpty(wechat)) { wrapper.like("wechat", wechat); } if (!ObjectUtils.isEmpty(order)) { if (!ObjectUtils.isEmpty(orderType)) { if (orderType.equals(Constants.ORDER_ASC)) wrapper.orderByAsc(order); else wrapper.orderByDesc(order); } } if (!ObjectUtils.isEmpty(isDelete)) if (!ObjectUtils.isEmpty(isDelete))//逻辑删除条件构造 wrapper.eq("is_delete", isDelete); else wrapper.eq("is_delete", Constants.NOT_DELETE); //查询结果 Page resultPage = manageAccountMapper.selectPage(page, wrapper); //查询用户对应的角色 List<ManageAccount> accounts = resultPage.getRecords(); List<AccountDTO> accountDTOS = new ArrayList<>(); @@ -288,6 +259,7 @@ accountDTOS.add(accountDTO); } } //封装返回结果 accountQueryDTO.setAccountDTOS(accountDTOS); accountQueryDTO.setCurrent(resultPage.getCurrent()); @@ -309,64 +281,58 @@ */ @Override @Transactional public AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm) { AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO(); public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) { AccountDTO accountDTO = new AccountDTO(); //取参 Integer accountId = accountUpdateForm.getAccountId(); String password = accountUpdateForm.getPassword(); String email = accountUpdateForm.getEmail(); String mobile = accountUpdateForm.getMobile(); String wechat = accountUpdateForm.getWechat(); String userName = accountUpdateForm.getUserName(); ManageAccount manageAccount = accountUpdateForm.formConvertEntity(); List<Integer> roleIds = accountUpdateForm.getRoleIds(); //判断要更新的用户是否存在 QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>(); ManageAccount exitManageAccount = new ManageAccount(); exitManageAccount.setId(accountId); exitManageAccount.setId(manageAccount.getId()); exitManageAccount.setIsDelete(Constants.NOT_DELETE); exitWrapper.setEntity(exitManageAccount); List<ManageAccount> manageAccounts = manageAccountMapper.selectList(exitWrapper); if (ObjectUtils.isEmpty(manageAccounts)) { accountUpdateDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); accountUpdateDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountUpdateDTO; accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountDTO; } //转换password if(!ObjectUtils.isEmpty(password)){ password = MD5Utils.saltMD5(AESUtils.decrypt(password)); } //更新ManageAccount表 ManageAccount manageAccount = new ManageAccount(); manageAccount.setPassword(password); manageAccount.setEmail(email); manageAccount.setMobile(mobile); manageAccount.setWechat(wechat); manageAccount.setUserName(userName); QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); wrapper.eq("id", accountId); manageAccountMapper.update(manageAccount, wrapper); manageAccountMapper.updateById(manageAccount); //如果角色有变动,则更新ManageAccountRole表 /*删除该用户的所有角色*/ if (!ObjectUtils.isEmpty(roleIds)) { QueryWrapper<ManageAccountRole> deleteWrapper = new QueryWrapper<>(); deleteWrapper.eq("account_id", accountId); manageAccountRoleMapper.delete(deleteWrapper); /* * 如果roleIds为null,则是该账号角色没有发生改变 * 如果roleIds为空,则是该账号所有的角色都被移除 * 如果roleIds有元素,则是该账号的角色有更新 * */ List<ManageRole> roles = null; if (roleIds != null) { UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>(); deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE); manageAccountRoleMapper.update(null, deleteWrapper); /*重新添加角色*/ for (Integer roleId : roleIds) { ManageAccountRole manageAccountRole = new ManageAccountRole(); manageAccountRole.setAccountId(accountId); manageAccountRole.setAccountId(manageAccount.getId()); manageAccountRole.setRoleId(roleId); manageAccountRoleMapper.insert(manageAccountRole); } //获取用户所有角色 List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds); accountUpdateDTO.setRoles(manageRoles); if (roleIds.size() != 0) roles = manageRoleMapper.selectBatchIds(roleIds); } else { roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); } accountDTO.setRoles(roles); //封装返回结果 accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId)); return accountUpdateDTO; accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountDTO.setAccount(manageAccountMapper.selectById(manageAccount.getId())); return accountDTO; } @@ -379,8 +345,8 @@ */ @Override @Transactional public AccountDeleteDTO deleteAccount(AccountDeleteForm accountDeleteForm) { AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO(); public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) { AccountDTO accountDTO = new AccountDTO(); //取参 Integer accountId = accountDeleteForm.getAccountId(); //查询是否存在 @@ -391,24 +357,24 @@ queryWrapper.setEntity(manageAccount); ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper); if (ObjectUtils.isEmpty(existManageAccount)) { accountDeleteDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); accountDeleteDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountDeleteDTO; accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountDTO; } //逻辑删除账号 existManageAccount.setIsDelete(Constants.DELETE); UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); deleteAccountWrapper.set("is_delete", Constants.DELETE).eq("id", manageAccount.getId()); deleteAccountWrapper.eq("id", accountId); deleteAccountWrapper.set("is_delete", Constants.DELETE); manageAccountMapper.update(null, deleteAccountWrapper); //逻辑删除账号相关角色 UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>(); deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId()); manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper); //封装返回结果 accountDeleteDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDeleteDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountDeleteDTO.setAccount(existManageAccount); return accountDeleteDTO; accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountDTO.setAccount(existManageAccount); return accountDTO; } screen-manage/src/main/java/com/moral/api/service/impl/ManageLogServiceImpl.java
@@ -12,7 +12,7 @@ * </p> * * @author moral * @since 2021-03-09 * @since 2021-03-31 */ @Service public class ManageLogServiceImpl extends ServiceImpl<ManageLogMapper, ManageLog> implements ManageLogService { screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; import com.moral.api.entity.Organization; import com.moral.api.mapper.OrganizationMapper; import com.moral.api.pojo.dto.organization.OrganizationDTO; @@ -15,11 +16,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; import com.moral.util.ConvertUtils; import com.moral.util.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; /** @@ -55,8 +60,8 @@ existOrganization.setName(organization.getName()); existOrganization.setIsDelete(Constants.NOT_DELETE); queryWrapper.setEntity(existOrganization); List<Organization> existOrganizations = organizationMapper.selectList(queryWrapper); if (!ObjectUtils.isEmpty(existOrganizations)) { Organization existOrganizationResult = organizationMapper.selectOne(queryWrapper); if (!ObjectUtils.isEmpty(existOrganizationResult)) { organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_EXIST.getCode()); organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg()); return organizationDTO; @@ -86,18 +91,19 @@ } /** * @Description: 更新客户组织 * @Param: [organizationUpdateForm] * @return: com.moral.api.pojo.dto.organization.OrganizationDTO * @Author: 陈凯裕 * @Date: 2021/3/24 */ * @Description: 更新客户组织 * @Param: [organizationUpdateForm] * @return: com.moral.api.pojo.dto.organization.OrganizationDTO * @Author: 陈凯裕 * @Date: 2021/3/24 */ @Override @Transactional public OrganizationDTO updateOrganization(OrganizationUpdateForm organizationUpdateForm) { OrganizationDTO organizationDTO = new OrganizationDTO(); //form转entity Organization organization = organizationUpdateForm.formConvertEntity(); //查询组织是否存在 QueryWrapper<Organization> existWrapper = new QueryWrapper<>(); Organization existOrganization = new Organization(); @@ -105,15 +111,16 @@ existOrganization.setIsDelete(Constants.NOT_DELETE); existWrapper.setEntity(existOrganization); existOrganization = organizationMapper.selectOne(existWrapper); if(ObjectUtils.isEmpty(existOrganization)){ if (ObjectUtils.isEmpty(existOrganization)) { organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode()); organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); return organizationDTO; } //如果更改了父组织,查询父组织是否存在 Integer parentId = organization.getParentId(); Organization parentOrganization = new Organization(); if (!ObjectUtils.isEmpty(parentId)&&parentId!=0) { if (!ObjectUtils.isEmpty(parentId) && parentId != 0) { QueryWrapper<Organization> existParentWrapper = new QueryWrapper<>(); parentOrganization.setId(parentId); parentOrganization.setIsDelete(Constants.NOT_DELETE); @@ -125,8 +132,10 @@ return organizationDTO; } } //更新组织 organizationMapper.updateById(organization); //获取更新后的组合 organization = organizationMapper.selectById(organization.getId()); @@ -139,12 +148,12 @@ } /** * @Description: 删除客户组织 * @Param: [organizationDeleteForm] * @return: com.moral.api.pojo.dto.organization.OrganizationDTO * @Author: 陈凯裕 * @Date: 2021/3/25 */ * @Description: 删除客户组织 * @Param: [organizationDeleteForm] * @return: com.moral.api.pojo.dto.organization.OrganizationDTO * @Author: 陈凯裕 * @Date: 2021/3/25 */ @Override @Transactional public OrganizationDTO deleteOrganization(OrganizationDeleteForm form) { @@ -158,27 +167,27 @@ QueryWrapper queryExistWrapper = new QueryWrapper(); queryExistWrapper.setEntity(existOrganization); existOrganization = organizationMapper.selectOne(queryExistWrapper); if(ObjectUtils.isEmpty(existOrganization)){ if (ObjectUtils.isEmpty(existOrganization)) { dto.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode()); dto.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); return dto; } //逻辑删除组织 UpdateWrapper deleteWrapper = new UpdateWrapper(); deleteWrapper.eq("id",id); deleteWrapper.set("is_delete",Constants.DELETE); organizationMapper.update(null,deleteWrapper); deleteWrapper.eq("id", id); deleteWrapper.set("is_delete", Constants.DELETE); organizationMapper.update(null, deleteWrapper); //判断是否删除所有子组织,如果不删除则将子组织parentId赋0 if(form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)){ if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) { UpdateWrapper deleteChildrenWrapper = new UpdateWrapper(); deleteChildrenWrapper.eq("parent_id",id); deleteChildrenWrapper.set("is_delete",Constants.DELETE); organizationMapper.update(null,deleteChildrenWrapper); }else{ deleteChildrenWrapper.eq("parent_id", id); deleteChildrenWrapper.set("is_delete", Constants.DELETE); organizationMapper.update(null, deleteChildrenWrapper); } else { UpdateWrapper updateChildrenWrapper = new UpdateWrapper(); updateChildrenWrapper.eq("parent_id",id); updateChildrenWrapper.set("parent_id",0); organizationMapper.update(null,updateChildrenWrapper); updateChildrenWrapper.eq("parent_id", id); updateChildrenWrapper.set("parent_id", 0); organizationMapper.update(null, updateChildrenWrapper); } dto.setOrganization(existOrganization); @@ -188,26 +197,90 @@ } /** * @Description: 查询客户组织 * @Param: [organizationQueryForm] * @return: com.moral.api.pojo.dto.organization.OrganizationQueryDTO * @Author: 陈凯裕 * @Date: 2021/3/25 */ * @Description: 查询客户组织 * @Param: [organizationQueryForm] * @return: com.moral.api.pojo.dto.organization.OrganizationQueryDTO * @Author: 陈凯裕 * @Date: 2021/3/25 */ @Override public OrganizationQueryDTO queryOrganization(OrganizationQueryForm organizationQueryForm) { OrganizationQueryDTO dto = new OrganizationQueryDTO(); //取参 Organization organization = organizationQueryForm.formConvertEntity(); Integer pageCount = organizationQueryForm.getPage(); Integer size = organizationQueryForm.getSize(); Integer parentId = organizationQueryForm.getParentId(); String name = organizationQueryForm.getName(); Integer provinceCode = organizationQueryForm.getProvinceCode(); Integer cityCode = organizationQueryForm.getCityCode(); Integer areaCode = organizationQueryForm.getAreaCode(); Long townCode = organizationQueryForm.getTownCode(); Long villageCode = organizationQueryForm.getVillageCode(); String phone = organizationQueryForm.getPhone(); String email = organizationQueryForm.getEmail(); String wechat = organizationQueryForm.getWechat(); String isDelete = organizationQueryForm.getIsDelete(); String order = organizationQueryForm.getOrder(); String orderType = organizationQueryForm.getOrderType(); Date createStartTime = organizationQueryForm.getCreateStartTime(); Date createEndTime = DateUtils.getDateOfDay(organizationQueryForm.getCreateEndTime(), 1); Date expireStartTime = organizationQueryForm.getExpireStartTime(); Date expireEndTime = DateUtils.getDateOfDay(organizationQueryForm.getExpireEndTime(), 1); //查询用户 Page<Organization> page = new Page<>(pageCount,size); QueryWrapper<Organization> queryWrapper = new QueryWrapper<>(); return null; //查询条件 Page<Organization> page = new Page<>(pageCount, size); NullFilterWrapper<Organization> queryWrapper = new NullFilterWrapper<>(); queryWrapper.eq("parent_id", parentId); queryWrapper.like("name", name); queryWrapper.eq("province_code", provinceCode); queryWrapper.eq("city_code", cityCode); queryWrapper.eq("area_code", areaCode); queryWrapper.eq("town_code", townCode); queryWrapper.eq("village_code", villageCode); queryWrapper.like("phone", phone); queryWrapper.like("email", email); queryWrapper.like("wechat", wechat); queryWrapper.between("create_time", createStartTime, createEndTime); queryWrapper.between("expire_time", expireStartTime, expireEndTime); if (!ObjectUtils.isEmpty(isDelete)) { queryWrapper.eq("is_delete", isDelete); } else { queryWrapper.eq("is_delete", Constants.NOT_DELETE); } //排序顺序 if (!ObjectUtils.isEmpty(order)) { if (!ObjectUtils.isEmpty(orderType)) { if (orderType.equals(Constants.ORDER_ASC)) queryWrapper.orderByAsc(ConvertUtils.toLine(order)); else queryWrapper.orderByDesc(ConvertUtils.toLine(order)); } } //查询结果 Page<Organization> resultPage = organizationMapper.selectPage(page, queryWrapper); List<Organization> organizations = resultPage.getRecords(); List<OrganizationDTO> organizationDTOS = new ArrayList<>(); //查找所有组织的父组织 for (Organization child : organizations) { OrganizationDTO resultDto = new OrganizationDTO(); Organization parent = organizationMapper.selectById(child.getParentId()); resultDto.setOrganization(child); resultDto.setParentOrganization(parent); organizationDTOS.add(resultDto); } dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); dto.setOrganizationDTOS(organizationDTOS); dto.setCurrent(page.getCurrent()); dto.setPage(page.getPages()); dto.setSize(page.getSize()); dto.setTotal(page.getTotal()); return dto; } screen-manage/src/main/resources/application-dev.yml
@@ -129,6 +129,7 @@ - /organization/insert - /organization/update - /organization/delete - /organization/query - /role/getAllManageRole - /role/getManageRoleByNameFuzzy screen-manage/src/main/resources/mapper/ManageLogMapper.xml
@@ -5,9 +5,10 @@ <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.moral.api.entity.ManageLog"> <id column="id" property="id" /> <result column="type" property="type" /> <result column="module" property="module" /> <result column="content" property="content" /> <result column="organization_id" property="organizationId" /> <result column="operate_id" property="operateId" /> <result column="account_id" property="accountId" /> <result column="ip" property="ip" /> <result column="create_time" property="createTime" /> </resultMap>