zhangqiankun 2 years ago
parent
commit
981270871b
2 changed files with 66 additions and 47 deletions
  1. 1 0
      pom.xml
  2. 65 47
      src/main/java/com/persagy/calendar/handle/WorkCalendarLabelHandler.java

+ 1 - 0
pom.xml

@@ -160,6 +160,7 @@
 			<plugin>
 				<groupId>org.springframework.boot</groupId>
 				<artifactId>spring-boot-maven-plugin</artifactId>
+				<version>2.3.4.RELEASE</version>
 				<executions>
 					<execution>
 						<goals>

+ 65 - 47
src/main/java/com/persagy/calendar/handle/WorkCalendarLabelHandler.java

@@ -8,6 +8,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -44,42 +46,49 @@ import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.util.BooleanUtil;
 
 /**
- * @version 
- * @description 
+ * @version
+ * @description
  * @company persagy
  * @author zhangqiankun
  * @since 2021年3月3日:	下午6:14:49
  */
 @Component
+@Slf4j
 public class WorkCalendarLabelHandler {
-	
+
 	public static final String LABEL_COLUMN = "GROUP_CODE, PROJECT_ID, CALENDAR_ID, DICT_TYPE, DICT_CODE, DIY_LABEL, DIY_VALUE, LABEL_DATE, CONVERT(SUBSTR(LABEL_DATE, 5, 2), SIGNED) AS labelMonth, CREATE_TIME, UPDATE_TIME, UPDATE_USER";
-	
-    @Autowired
-    private IWorkCalendarService workCalendarService;
-    
+
+	@Autowired
+	private IWorkCalendarService workCalendarService;
+
 	@Autowired
 	private IWorkCalendarLabelService workCalendarLabelService;
-	
+
 	@Autowired
 	private IWorkCalendarDictService workCalendarDictService;
-	
+
 	@Autowired
 	private WorkCalendarDateHandler workCalendarDateHandler;
-	
+
 	@Autowired
 	private IWorkCalendarObjectService workCalendarObjectService;
 
 	/**
 	 * 日期标签属性列表查询
-	 * 
+	 *
 	 * @param queryVO
 	 * @return
 	 */
 	public List<WorkCalendarLabel> queryCalendarLabelList(WorkCalendarLabelQueryVO queryVO) {
 		// 获取字典类型的级别
 		int dictTypeLevel = this.workCalendarDictService.getDictTypeLevel(queryVO.getGroupCode(), queryVO.getDictType());
-		
+
+		// 获取字典类型的级别  Bd  Pj37030300011  f5546f29cd64d75b57514cbb621da48
+		if (StringUtils.isBlank(queryVO.getProjectId()) && StringUtils.isNotBlank(queryVO.getObjId())) {
+			String objId = queryVO.getObjId();
+			queryVO.setProjectId(getProjectId(objId));
+		}
+
 		// 如果条件为对象ID,且属于工作历级别的类型,反查出工作历ID,再进行查询
 		if (StringUtil.isNotBlank(queryVO.getObjId()) && dictTypeLevel == 2) {
 			//查询出此对象对应的工作历ID和项目ID
@@ -92,24 +101,33 @@ public class WorkCalendarLabelHandler {
 			}
 			queryVO.setCalendarId(calendarObject.getCalendarId());
 		}
-		
+
 		QueryWrapper<WorkCalendarLabel> queryWrapper = new WorkCalendarLabel.Builder().createQueryWrapper().groupCodeEq(queryVO.getGroupCode())
 				.projectIdEq(queryVO.getProjectId(), dictTypeLevel).calendarIdEq(queryVO.getCalendarId(), dictTypeLevel)
 				.dictTypeEq(queryVO.getDictType()).dictCodeEq(queryVO.getDictCode()).diyLabelEq(queryVO.getDiyLabel())
 				.labelDateGe(queryVO.getLabelDateStart()).labelDateLe(queryVO.getLabelDateEnd()).builderQueryWrapper();
 		return this.workCalendarLabelService.list(queryWrapper.select(LABEL_COLUMN).orderByAsc(Lists.newArrayList("LABEL_DATE", "ID")));
 	}
-	
+
+	private String getProjectId(String objId) {
+		try {
+			return "Pj" + objId.substring(2, 12);
+		} catch (Exception ex) {
+			log.warn("WorkCalendarLabelHandler getProjectId error:", ex);
+		}
+		return "";
+	}
+
 	/**
 	 * 查询标签的有效期,仅允许查询某一项目、某一标签对应的有效期
-	 * 
+	 *
 	 * @param queryVO
 	 * @return
 	 */
 	public List<WorkCalendarLabel> queryCalendarLabelValid(WorkCalendarLabelQueryVO queryVO) {
 		// 获取字典类型的级别
 		int dictTypeLevel = this.workCalendarDictService.getDictTypeLevel(queryVO.getGroupCode(), queryVO.getDictType());
-		
+
 		if (StringUtil.isNotBlank(queryVO.getObjId()) && dictTypeLevel == 2) {
 			//查询出此对象对应的工作历ID和项目ID
 			QueryWrapper<WorkCalendarObject> objectWrapper = new WorkCalendarObject.Builder().createQueryWrapper()
@@ -121,7 +139,7 @@ public class WorkCalendarLabelHandler {
 			}
 			queryVO.setCalendarId(calendarObject.getCalendarId());
 		}
-		
+
 		QueryWrapper<WorkCalendarLabel> queryWrapper = new WorkCalendarLabel.Builder().createQueryWrapper().groupCodeEq(queryVO.getGroupCode())
 				.projectIdEq(queryVO.getProjectId(), dictTypeLevel).calendarIdEq(queryVO.getCalendarId(), dictTypeLevel)
 				.dictTypeEq(queryVO.getDictType()).dictCodeEq(queryVO.getDictCode()).diyLabelEq(queryVO.getDiyLabel())
@@ -130,10 +148,10 @@ public class WorkCalendarLabelHandler {
 		List<WorkCalendarLabel> labels = this.workCalendarLabelService.list(queryWrapper);
 		return this.convert2Response(labels);
 	}
-	
+
 	/**
 	 * 结果封装
-	 * 
+	 *
 	 * @param labels 此集合内容,必须是同一项目、同一标签类型下的数据
 	 * @return
 	 */
@@ -141,50 +159,50 @@ public class WorkCalendarLabelHandler {
 		if (CollectionUtil.isEmpty(labels)) {
 			return null;
 		}
-		
+
 		// 生成响应的数据结构
 		Map<String, WorkCalendarLabel> dictCode2Label = new HashMap<String, WorkCalendarLabel>();
 		Map<String, List<String>> dictCode2Date = new HashMap<String, List<String>>();
 		for (WorkCalendarLabel workCalendarLabel : labels) {
 			String dictCode = workCalendarLabel.getDictCode();
-			
+
 			if (!dictCode2Label.containsKey(dictCode)) {
 				dictCode2Label.put(dictCode, workCalendarLabel);
 			}
-			
+
 			if (dictCode2Date.containsKey(dictCode)) {
 				dictCode2Date.get(dictCode).add(workCalendarLabel.getLabelDate());
 			} else {
 				dictCode2Date.put(dictCode, Lists.newArrayList(workCalendarLabel.getLabelDate()));
 			}
 		}
-		
+
 		List<WorkCalendarLabel> resultList = new ArrayList<WorkCalendarLabel>();
-		
+
 		// 解析出对应code每个时间段内的最小日期和最大日期
 		Set<String> dictCodes = dictCode2Date.keySet();
 		for (String dictCode : dictCodes) {
 			List<String> labelDates = dictCode2Date.get(dictCode);
 			WorkCalendarLabel calendarLabel = dictCode2Label.get(dictCode);
-			
+
 			if (labelDates.size() == 1) {
 				resultList.add(this.convert2Response(calendarLabel, null, null));
 				continue;
 			}
 			// 先排序
 			Collections.sort(labelDates);
-			
+
 			int size = labelDates.size();
 			String preDate = labelDates.get(0);
 			String minDate = labelDates.get(0);
-			
+
 			DateTime currentDate = null;
 			DateTime preDateTime = DateUtil.parse(labelDates.get(0), DateUtil.FORMAT_DATE_YYYYMMDD);
 			for (int i = 1; i < size; i++) {
 				// 获取当前时间和日期
 				String labelDate = labelDates.get(i);
 				currentDate = DateUtil.parse(labelDate, DateUtil.FORMAT_DATE_YYYYMMDD);
-				
+
 				// 当前时间往前偏移一天,判断是否相等
 				currentDate.offset(DateField.DAY_OF_YEAR, -1);
 				if (preDateTime.equals(currentDate)) {
@@ -196,28 +214,28 @@ public class WorkCalendarLabelHandler {
 				// 无论哪种情况下,都需要为上一日期赋最新值
 				preDate = labelDate;
 				preDateTime = DateUtil.parse(labelDate, DateUtil.FORMAT_DATE_YYYYMMDD);
-				
+
 				// 最后一天无论与之前的相不相等,都应该封装响应结果
 				if (i == (size - 1)) {
 					resultList.add(this.convert2Response(calendarLabel, minDate, labelDate));
 				}
 			}
 		}
-		
+
 		return resultList;
 	}
-	
-	
+
+
 	/**
 	 * 创建或更新日期标签属性
-	 * 
+	 *
 	 * @param createVO
 	 */
 	@Transactional
 	public void updateLabelInfo(WorkCalendarLabelUpdateVO updateVO) {
 		// 获取字典类型的级别
 		int dictTypeLevel = this.workCalendarDictService.getDictTypeLevel(updateVO.getGroupCode(), updateVO.getDictType());
-		
+
 		boolean result = false;
 		if (BooleanUtil.isTrue(updateVO.getIsDelete())) {
 			Builder builder = new WorkCalendarLabel.Builder().createQueryWrapper();
@@ -235,7 +253,7 @@ public class WorkCalendarLabelHandler {
 					.dictTypeEq(updateVO.getDictType()).diyLabelEq(updateVO.getDiyLabel()).builderQueryWrapper();
 			this.workCalendarLabelService.remove(queryWrapper);
 		}
-		
+
 		WorkCalendarLabel calendarLabel = new WorkCalendarLabel();
 		BeanUtils.copyProperties(updateVO, calendarLabel);
 		String now = DateUtil.format(new Date(), DateUtil.FORMAT_DATE_YYYYMMDDHHMMSS);
@@ -251,7 +269,7 @@ public class WorkCalendarLabelHandler {
 			// 项目级
 			calendarLabel.setCalendarId("0");
 		}
-		
+
 		DateTime dateStart = DateUtil.parse(updateVO.getLabelDateStart(), DateUtil.FORMAT_DATE_YYYYMMDD);
 		DateTime dateEnd = DateUtil.parse(updateVO.getLabelDateEnd(), DateUtil.FORMAT_DATE_YYYYMMDD);
 		long betweenDay = DateUtil.between(dateStart, dateEnd, DateUnit.DAY) + 1;
@@ -265,10 +283,10 @@ public class WorkCalendarLabelHandler {
 			if (!result) {
 				throw new BusinessException("日期标签属性设置失败");
 			}
-			
+
 			dateStart.offset(DateField.DAY_OF_YEAR, 1);
 		}
-		
+
 		// 设置成功后,将自定义的标签插入到字典表中
 		if (WorkCalendarConstant.CUSTOM_CALENDAR_DATE_YES.equals(updateVO.getDiyLabel())) {
 			// 当自定义标签时,存入字典表
@@ -281,17 +299,17 @@ public class WorkCalendarLabelHandler {
 				calendarDict.setProjectId(updateVO.getProjectId());
 				calendarDict.setGroupCode(updateVO.getGroupCode());
 				calendarDict.setDictType(WorkCalendarConstant.CUSTOM_CALENDAR_DICT_TYPE);
-	    		calendarDict.setDictDesc(diyValue);
-	    		calendarDicts.add(calendarDict);
+				calendarDict.setDictDesc(diyValue);
+				calendarDicts.add(calendarDict);
 			}
 			this.workCalendarDictService.batchCreateDictTypeByDelete(calendarDicts);
 		}
-		
+
 	}
 
 	/**
 	 * 重新定义日期段内每天的属性标签
-	 * 
+	 *
 	 * @param updateVO
 	 */
 	@Transactional
@@ -309,7 +327,7 @@ public class WorkCalendarLabelHandler {
 				this.workCalendarDateHandler.batchCreateCalendarMoreDate(moreDateCreateVO, calendar);
 			}
 		}
-		
+
 		List<WorkCalendarLabelUpdateVO> labels = updateVO.getLabels();
 		if (CollectionUtil.isNotEmpty(labels)) {
 			for (WorkCalendarLabelUpdateVO labelUpdateVO : labels) {
@@ -318,7 +336,7 @@ public class WorkCalendarLabelHandler {
 			}
 		}
 	}
-	
+
 	/**
 	 * 检查数据的有效性
 	 * @param updateVO
@@ -347,13 +365,13 @@ public class WorkCalendarLabelHandler {
 				}
 			}
 		}
-		
+
 		return null;
 	}
 
 	/**
 	 * 转为响应数据
-	 * 
+	 *
 	 * @param temp
 	 * @param labelDateStart
 	 * @param labelDateEnd
@@ -367,5 +385,5 @@ public class WorkCalendarLabelHandler {
 		result.setLabelDateEnd(labelDateEnd == null ? temp.getLabelDate() : labelDateEnd);
 		return result;
 	}
-	
+
 }