Browse Source

优化equal和hashCode方法

zhangqiankun 3 years ago
parent
commit
366c064bfa

+ 7 - 3
src/main/java/com/persagy/calendar/controller/WorkCalendarDateController.java

@@ -131,9 +131,13 @@ public class WorkCalendarDateController {
 			return ResponseUtil.errorResult(ResponseCode.A0402.getCode(), "开始作息日期不合法,历史时间不允许再添加自定义作息时间点");
 		}
 		// 判断工作历类型是否存在
-		WorkCalendar calendar = this.workCalendarService.getById(createVO.getCalendarId(), createVO.getGroupCode(), createVO.getProjectId());
-		if (calendar == null) {
-			throw new BusinessException("工作历类型不存在");
+		int dictTypeLevel = this.workCalendarDictService.getDictTypeLevel(createVO.getGroupCode(), createVO.getDictType());
+		WorkCalendar calendar = null;
+		if (dictTypeLevel == 2) {
+			calendar = this.workCalendarService.getById(createVO.getCalendarId(), createVO.getGroupCode(), createVO.getProjectId());
+			if (calendar == null) {
+				throw new BusinessException("工作历类型不存在");
+			}
 		}
 		this.workCalendarDateHandler.batchCreateCalendarMoreDate(createVO, calendar);
 		return ResponseUtil.successResult("添加成功");

+ 2 - 2
src/main/java/com/persagy/calendar/handle/WorkCalendarDateHandler.java

@@ -711,8 +711,8 @@ public class WorkCalendarDateHandler {
 		calendarDate.setProjectId(createVO.getProjectId());
 		calendarDate.setCalendarId(createVO.getCalendarId());
 		calendarDate.setCustomFlag(WorkCalendarConstant.CUSTOM_CALENDAR_DATE_YES);
-		calendarDate.setCalendarName(calendar.getCalendarName());
-		calendarDate.setCalendarDesc(calendar.getCalendarDesc());
+		calendarDate.setCalendarName(calendar == null ? "" : calendar.getCalendarName());
+		calendarDate.setCalendarDesc(calendar == null ? "" : calendar.getCalendarDesc());
 		calendarDate.setDictType(createVO.getDictType());
 		calendarDate.setDictCode(createVO.getDictCode());
 		calendarDate.setWorkDate(currentDay);

+ 26 - 26
src/main/java/com/persagy/calendar/pojo/dto/WorkCalendarDate.java

@@ -423,51 +423,51 @@ public class WorkCalendarDate extends BaseEntity<WorkCalendarDate> {
 		}
 		
 		WorkCalendarDate other = (WorkCalendarDate) obj;
-		if (calendarId == null) {
-			if (other.calendarId != null) {
+		if (StringUtil.isBlank(calendarId)) {
+			if (StringUtil.isNotBlank(other.calendarId)) {
 				return false;
 			}
-		} else if (!calendarId.equals(other.calendarId)) {
+		} else if (!calendarId.equals(other.calendarId == null ? "" : other.calendarId)) {
 			return false;
 		}
 		
-		if (dictCode == null) {
-			if (other.dictCode != null) {
+		if (StringUtil.isBlank(dictCode)) {
+			if (StringUtil.isNotBlank(other.dictCode)) {
 				return false;
 			}
-		} else if (!dictCode.equals(other.dictCode)) {
+		} else if (!dictCode.equals(other.dictCode == null ? "" : other.dictCode)) {
 			return false;
 		}
-
-		if (dictType == null) {
-			if (other.dictType != null) {
+		
+		if (StringUtil.isBlank(dictType)) {
+			if (StringUtil.isNotBlank(other.dictType)) {
 				return false;
 			}
-		} else if (!dictType.equals(other.dictType)) {
+		} else if (!dictType.equals(other.dictType == null ? "" : other.dictType)) {
 			return false;
 		}
 
-		if (groupCode == null) {
-			if (other.groupCode != null) {
+		if (StringUtil.isBlank(groupCode)) {
+			if (StringUtil.isNotBlank(other.groupCode)) {
 				return false;
 			}
-		} else if (!groupCode.equals(other.groupCode)) {
+		} else if (!groupCode.equals(other.groupCode == null ? "" : other.groupCode)) {
 			return false;
 		}
-		
-		if (projectId == null) {
-			if (other.projectId != null) {
+
+		if (StringUtil.isBlank(projectId)) {
+			if (StringUtil.isNotBlank(other.projectId)) {
 				return false;
 			}
-		} else if (!projectId.equals(other.projectId)) {
+		} else if (!projectId.equals(other.projectId == null ? "" : other.projectId)) {
 			return false;
 		}
 		
-		if (workDate == null) {
-			if (other.workDate != null) {
+		if (StringUtil.isBlank(workDate)) {
+			if (StringUtil.isNotBlank(other.workDate)) {
 				return false;
 			}
-		} else if (!workDate.equals(other.workDate)) {
+		} else if (!workDate.equals(other.workDate == null ? "" : other.workDate)) {
 			return false;
 		}
 		
@@ -481,12 +481,12 @@ public class WorkCalendarDate extends BaseEntity<WorkCalendarDate> {
 	public int hashCode() {
 		final int prime = 31;
 		int result = 1;
-		result = prime * result + ((calendarId == null) ? 0 : calendarId.hashCode());
-		result = prime * result + ((dictCode == null) ? 0 : dictCode.hashCode());
-		result = prime * result + ((dictType == null) ? 0 : dictType.hashCode());
-		result = prime * result + ((groupCode == null) ? 0 : groupCode.hashCode());
-		result = prime * result + ((projectId == null) ? 0 : projectId.hashCode());
-		result = prime * result + ((workDate == null) ? 0 : workDate.hashCode());
+		result = prime * result + ((StringUtil.isBlank(calendarId)) ? 0 : calendarId.hashCode());
+		result = prime * result + ((StringUtil.isBlank(dictCode)) ? 0 : dictCode.hashCode());
+		result = prime * result + ((StringUtil.isBlank(dictType)) ? 0 : dictType.hashCode());
+		result = prime * result + ((StringUtil.isBlank(groupCode)) ? 0 : groupCode.hashCode());
+		result = prime * result + ((StringUtil.isBlank(projectId)) ? 0 : projectId.hashCode());
+		result = prime * result + ((StringUtil.isBlank(workDate)) ? 0 : workDate.hashCode());
 		return result;
 	}