|
@@ -86,6 +86,7 @@ import com.minto.core.common.AppContext;
|
|
|
import com.minto.core.constants.BaseConstants;
|
|
|
import com.minto.core.ds.DBAgent;
|
|
|
import com.minto.core.event.SystemFrameWorkEvent;
|
|
|
+import com.minto.core.po.BasePO;
|
|
|
import com.minto.core.util.*;
|
|
|
import com.minto.core.util.concurrent.Worker;
|
|
|
import com.minto.tap.collaboration.api.CollaborationApi;
|
|
@@ -98,6 +99,7 @@ import com.minto.tip.common.exceptions.BusinessException;
|
|
|
import com.minto.tip.common.util.annotation.Transactional;
|
|
|
import com.minto.tip.event.EventDispatcher;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.hibernate.criterion.Criterion;
|
|
@@ -114,12 +116,16 @@ import org.springframework.util.CollectionUtils;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.sql.SQLException;
|
|
|
import java.text.MessageFormat;
|
|
|
+import java.text.NumberFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import static com.minto.app.organization.OrgConstants.DEFAULT_ACCOUNT_ID;
|
|
|
|
|
@@ -14832,4 +14838,215 @@ public class TaskByTypeManagerImpl implements ITaskByTypeManager{
|
|
|
public List<TaskReportBean> findReportByTaskIdAndPhaseIdAndPhaseConfigId(Map<String, Object> params) {
|
|
|
return taskReportDao.findReportByTaskIdAndPhaseIdAndPhaseConfigId(params);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> checkRepeatTaskByName(List<Long> taskIds, Long taskType){
|
|
|
+ List<Map<String, Object>> res = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> tasks = taskSummaryDao.findAllTaskSummaryExcludeDeleted();
|
|
|
+ Map<Boolean, List<Map<String, Object>>> map =
|
|
|
+ tasks.stream().collect(Collectors.groupingBy(e -> taskIds.contains(e.get("id"))));
|
|
|
+ List<Map<String, Object>> sourceTasks = map.get(Boolean.TRUE);
|
|
|
+ List<Map<String, Object>> targetTasks =
|
|
|
+ map.get(Boolean.FALSE).stream().filter(e -> e.get("title") != null).collect(
|
|
|
+ Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(sourceTasks) || CollectionUtils.isEmpty(tasks)){
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ //通过相似度算法匹配相似的督办任务
|
|
|
+ //FIXME 可能性能较差
|
|
|
+ Map<Long, List<Long>> idmap = new HashMap<>();
|
|
|
+ sourceTasks.forEach(a -> {
|
|
|
+ Long id = (Long)a.get("id");
|
|
|
+ String s = a.get("title").toString();
|
|
|
+ int l = s.length();
|
|
|
+ targetTasks.forEach(b -> {
|
|
|
+ String t = b.get("title").toString();
|
|
|
+ double d = levenshteinDistance(s, t);
|
|
|
+ //d = jaccardSimilarity(s,t);
|
|
|
+ if((l <= 10 && d > 70) || (10 < l && l <= 20 && d > 75) || (20 < l && d > 80)){
|
|
|
+ //认为相似
|
|
|
+ List<Long> longs = idmap.get(id);
|
|
|
+ if(longs == null){
|
|
|
+ longs = new ArrayList<>();
|
|
|
+ idmap.put(id, longs);
|
|
|
+ }
|
|
|
+ longs.add((Long)b.get("id"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ //构建返回数据
|
|
|
+ if(!idmap.isEmpty()){
|
|
|
+ idmap.forEach((k, v) -> {
|
|
|
+ Map<String, Object> smap = new HashMap<>();
|
|
|
+ smap.put("id", k);
|
|
|
+ List<Map<String, Object>> taskDatas = new ArrayList<>();
|
|
|
+ List<Long> tIds = Lists.newArrayList();
|
|
|
+ tIds.add(k);
|
|
|
+ tIds.addAll(v);
|
|
|
+ tIds.forEach(e -> {
|
|
|
+ TaskSummaryBean summary = taskSummaryDao.findTaskSummaryById(e);
|
|
|
+ Map<String, Object> data = buildImportReportData(summary, taskType);
|
|
|
+ taskDatas.add(data);
|
|
|
+ });
|
|
|
+ smap.put("tasks", taskDatas);
|
|
|
+ res.add(smap);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> buildImportReportData(TaskSummaryBean summary, Long taskType){
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("id", summary.getId());
|
|
|
+ List<TaskTypeRelationBean> relations = findTaskTypeRelByTaskId(summary.getId());
|
|
|
+ Set<Long> collect = relations.stream().map(TaskTypeRelationBean::getTypeId).collect(Collectors.toSet());
|
|
|
+ if(StringUtils.isNumeric(summary.getTaskTypeId())){
|
|
|
+ collect.add(Long.valueOf(summary.getTaskTypeId()));
|
|
|
+ }
|
|
|
+ String typeNames = findTaskTypeByIds(new ArrayList<>(collect))
|
|
|
+ .stream().map(TaskTypeBean::getName).collect(Collectors.joining(","));
|
|
|
+ data.put("type", typeNames);
|
|
|
+ List<Map<String, Object>> extendDatas = taskListManager.findTemplateData4Task(summary.getId(), taskType, "task");
|
|
|
+ extendDatas.forEach(d -> {
|
|
|
+ Object value = d.get("value");
|
|
|
+ String name = d.get("name").toString();
|
|
|
+ data.put(name, value);
|
|
|
+ if("select".equals(d.get("showType"))){
|
|
|
+ if(value instanceof Map){
|
|
|
+ Object names = ((Map<?, ?>)value).get("names");
|
|
|
+ if(names instanceof List){
|
|
|
+ data.put(name, StringUtils.join(names,","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if("personOrOrgs".equals(d.get("showType"))){
|
|
|
+ if(value instanceof Map){
|
|
|
+ data.put(name, ((Map<?, ?>)value).get("names"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用编辑距离来计算相似度
|
|
|
+ * @param s
|
|
|
+ * @param t
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private double levenshteinDistance(String s, String t){
|
|
|
+ int n = s.length();
|
|
|
+ int m = t.length();
|
|
|
+ if(n == 0)
|
|
|
+ return m;
|
|
|
+ if(m == 0)
|
|
|
+ return n;
|
|
|
+
|
|
|
+ int[][] dp = new int[n + 1][m + 1];
|
|
|
+ for(int i = 0; i <= n; i++){
|
|
|
+ dp[i][0] = i;
|
|
|
+ }
|
|
|
+ for(int j = 0; j <= m; j++){
|
|
|
+ dp[0][j] = j;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 1; i <= n; i++){
|
|
|
+ for(int j = 1; j <= m; j++){
|
|
|
+ if(s.charAt(i - 1) == t.charAt(j - 1)){
|
|
|
+ dp[i][j] = dp[i - 1][j - 1];
|
|
|
+ } else{
|
|
|
+ dp[i][j] = 1 + Math.min(
|
|
|
+ Math.min(dp[i - 1][j], dp[i][j - 1]),
|
|
|
+ dp[i - 1][j - 1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int levenshteinDistance = dp[n][m];
|
|
|
+ int length = Math.max(s.length(), t.length());
|
|
|
+
|
|
|
+ NumberFormat numberFormat = NumberFormat.getInstance();
|
|
|
+ // 设置精确到小数点后2位
|
|
|
+ numberFormat.setMaximumFractionDigits(2);
|
|
|
+ return Double.parseDouble(numberFormat.format(((float)1 - (float)levenshteinDistance / (float)length) * 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> updateTask4Merge(HttpServletRequest request){
|
|
|
+ Map<String, Object> res = new HashMap<>();
|
|
|
+ Long taskType = ReqUtil.getLong(request,"taskType");
|
|
|
+ Long[] idArray = ReqUtil.getLongArray(request, "ids[]");
|
|
|
+ List<TaskSummaryBean> tasks = taskSummaryDao.findTaskSummariesById(idArray);
|
|
|
+ Map<Long, TaskSummaryBean> taskMap = tasks.stream().collect(Collectors.toMap(BasePO::getId, e -> e));
|
|
|
+ Long titleTaskId = ReqUtil.getLong(request, "titleId");
|
|
|
+ TaskSummaryBean task = taskMap.get(titleTaskId);
|
|
|
+
|
|
|
+ Long typeTaskId = ReqUtil.getLong(request, "typeId");
|
|
|
+ if(!titleTaskId.equals(typeTaskId)){
|
|
|
+ //更新任务类型
|
|
|
+ TaskSummaryBean sourceTask = taskMap.get(typeTaskId);
|
|
|
+ if(!StringUtils.equals(task.getTaskTypeId(), sourceTask.getTaskTypeId())){
|
|
|
+ task.setTaskTypeId(sourceTask.getTaskTypeId());
|
|
|
+ taskSummaryDao.updateTaskSummaryBean(task);
|
|
|
+ }
|
|
|
+ deleteTaskTypeRel(new Long[]{titleTaskId});
|
|
|
+ List<TaskTypeRelationBean> soureTaskTypes = findTaskTypeRelByTaskId(typeTaskId);
|
|
|
+ Set<Long> sourceTaskTypeIds =soureTaskTypes.stream().map(TaskTypeRelationBean::getTypeId).collect(Collectors.toSet());
|
|
|
+ if(!CollectionUtils.isEmpty(sourceTaskTypeIds)){
|
|
|
+ List<Object> collect = sourceTaskTypeIds.stream().map(e -> {
|
|
|
+ TaskTypeRelationBean bean = new TaskTypeRelationBean();
|
|
|
+ bean.setId(UUIDUtil.UUIDLong());
|
|
|
+ bean.setTaskId(titleTaskId);
|
|
|
+ bean.setTypeId(e);
|
|
|
+ return bean;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ taskManager.saveOrUpdateAll(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long contentTaskId = ReqUtil.getLong(request, "contentId");
|
|
|
+ if(!titleTaskId.equals(contentTaskId)){
|
|
|
+ //更新工作任务(content)
|
|
|
+ CommonContentBean sourceBean = contentManager.findCommonContentBeanById(contentTaskId);
|
|
|
+ CommonContentBean bean = contentManager.findCommonContentBeanById(titleTaskId);
|
|
|
+ bean.setContent(sourceBean == null ? "" : sourceBean.getContent());
|
|
|
+ contentManager.updateCommonContentBean(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> extendMap = new HashMap<>();
|
|
|
+ Long directoryTaskId = ReqUtil.getLong(request, "directoryId");
|
|
|
+ if(!titleTaskId.equals(directoryTaskId)){
|
|
|
+ //更新任务分档(field_1000)
|
|
|
+ List<Map<String, Object>> extendDatas = taskListManager.findTemplateData4Task(directoryTaskId, taskType, "task");
|
|
|
+ Map<String, Object> extendData =
|
|
|
+ extendDatas.stream().filter(e->"field_1000".equals(e.get("name"))).findFirst().orElse(new HashMap<>());
|
|
|
+ if(extendData != null && extendData.get("value") instanceof Map){
|
|
|
+ Object names = ((Map)extendData.get("value")).get("ids");
|
|
|
+ if(names instanceof List){
|
|
|
+ extendMap.put("field_1000", ((List)names).stream().map(String::valueOf).collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long fromTaskId = ReqUtil.getLong(request, "fromId");
|
|
|
+ if(!titleTaskId.equals(fromTaskId)){
|
|
|
+ List<Map<String, Object>> extendDatas = taskListManager.findTemplateData4Task(directoryTaskId, taskType,
|
|
|
+ "task");
|
|
|
+ Map<String, Object> extendData =
|
|
|
+ extendDatas.stream().filter(e -> "field_51".equals(e.get("name"))).findFirst()
|
|
|
+ .orElse(new HashMap<>());
|
|
|
+ extendMap.put("field_51", extendData.get("realValue"));
|
|
|
+ }
|
|
|
+ if(MapUtils.isNotEmpty(extendMap)){
|
|
|
+ saveExtendDataByTemplate(task, extendMap,false);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> ids = Stream.of(idArray).collect(Collectors.toList());
|
|
|
+ ids.remove(titleTaskId);
|
|
|
+ taskManager.deleteTaskById(ids.toArray(new Long[0]), true);
|
|
|
+ task = taskSummaryDao.findTaskSummaryById(titleTaskId);
|
|
|
+ Map<String, Object> data = buildImportReportData(task, taskType);
|
|
|
+ res.put("ids", ids);
|
|
|
+ res.put("task", data);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|