Pārlūkot izejas kodu

fix: 批量任务审核-修复若干问题

lixuesong 3 gadi atpakaļ
vecāks
revīzija
036cc12497

+ 133 - 77
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmDeptTaskTypeConfigServiceImpl.java

@@ -11,7 +11,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation;
+import com.qunzhixinxi.hnqz.admin.entity.WmDaAgent;
 import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEnt;
 import com.qunzhixinxi.hnqz.admin.entity.WmDeptTaskTypeConfig;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
@@ -20,10 +22,13 @@ import com.qunzhixinxi.hnqz.admin.entity.WmTaskType;
 import com.qunzhixinxi.hnqz.admin.entity.dto.WmDeptTaskTypeConfigDTO;
 import com.qunzhixinxi.hnqz.admin.entity.dto.WmDeptTaskTypeConfigJsonDTO;
 import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
+import com.qunzhixinxi.hnqz.admin.enums.DeptLevelEnum;
 import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
 import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
 import com.qunzhixinxi.hnqz.admin.enums.ScorePackageStatusEnum;
+import com.qunzhixinxi.hnqz.admin.mapper.SysDeptMapper;
 import com.qunzhixinxi.hnqz.admin.mapper.SysDeptRelationMapper;
+import com.qunzhixinxi.hnqz.admin.mapper.WmDaAgentMapper;
 import com.qunzhixinxi.hnqz.admin.mapper.WmDaDrugEntMapper;
 import com.qunzhixinxi.hnqz.admin.mapper.WmDeptTaskTypeConfigMapper;
 import com.qunzhixinxi.hnqz.admin.mapper.WmTaskMapper;
@@ -38,11 +43,10 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
-import java.util.Comparator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 /**
@@ -66,6 +70,54 @@ public class WmDeptTaskTypeConfigServiceImpl extends ServiceImpl<WmDeptTaskTypeC
 
 	private final WmTaskMapper wmTaskMapper;
 
+	private final SysDeptMapper sysDeptMapper;
+
+	private final WmDaAgentMapper wmDaAgentMapper;
+
+	/**
+	 * 任务类型Map
+	 */
+	private static Map<String, List<String>> BASE_TASK_TYPE_MAP = new LinkedHashMap<>();
+
+	static {
+		List<String> meetingList = new ArrayList<String>() {{
+			add("医院科室推广会");
+			add("区域学术沙龙");
+			add("城市卫星会");
+			add("省级学科年会");
+		}};
+		BASE_TASK_TYPE_MAP.put("会议举办", meetingList);
+		List<String> interviewList = new ArrayList<String>() {{
+			add("一对一专访");
+		}};
+		BASE_TASK_TYPE_MAP.put("一对一专访", interviewList);
+		List<String> customerList = new ArrayList<String>() {{
+			add("医院拜访");
+			add("商业公司拜访");
+			add("药店拜访");
+		}};
+		BASE_TASK_TYPE_MAP.put("客户拜访", customerList);
+		List<String> producrList = new ArrayList<String>() {{
+			add("产品相册分享");
+			add("电子名片分享");
+		}};
+		BASE_TASK_TYPE_MAP.put("产品推广", producrList);
+		List<String> academicList = new ArrayList<String>() {{
+			add("学术信息交流");
+		}};
+		BASE_TASK_TYPE_MAP.put("学术信息交流", academicList);
+		List<String> marketList = new ArrayList<String>() {{
+			add("政策信息收集");
+			add("竞品信息收集");
+			add("库存信息收集");
+			add("医院信息收集");
+			add("商业公司信息收集");
+			add("产品使用信息收集");
+			add("药店调查");
+		}};
+		BASE_TASK_TYPE_MAP.put("市场信息收集", marketList);
+	}
+
 	/**
 	 * 保存任务类型配置
 	 *
@@ -117,19 +169,24 @@ public class WmDeptTaskTypeConfigServiceImpl extends ServiceImpl<WmDeptTaskTypeC
 	public WmDeptTaskTypeConfigDTO getDeptTaskTypeConfig(Integer deptId) {
 		String[] enableZbdbStatusArr = {"医院拜访", "商业公司拜访", "药店拜访", "电子名片分享", "产品相册分享", "学术信息交流",
 				"受众打开产品相册", "受众阅读文章"};
-		// 查询出当前dept对应的任务类型(药企或药企给CSO的任务类型)
-		List<SysDeptRelation> relationList = sysDeptRelationMapper.selectList(Wrappers.<SysDeptRelation>lambdaQuery()
-				.eq(SysDeptRelation::getDescendant, deptId));
-		SysDeptRelation deptRelation = relationList.stream()
-				.filter(sysDeptRelation -> !sysDeptRelation.getAncestor().equals(1))
-				.findFirst()
-				.get();
-		WmDaDrugEnt wmDaDrugEnt = wmDaDrugEntMapper.selectOne(Wrappers.<WmDaDrugEnt>lambdaQuery()
-				.eq(WmDaDrugEnt::getDeptId, deptRelation.getAncestor())
-				.eq(WmDaDrugEnt::getEnableFlag, EnableEnum.ENABLE.val()));
+		// 查询出当前dept对应的药企/代理商id
+		String durgentId = null;
+		SysDept dept = sysDeptMapper.selectById(deptId);
+		if (DeptLevelEnum.ENT.getVal().equals(dept.getLevel())) {
+			WmDaDrugEnt wmDaDrugEnt = wmDaDrugEntMapper.selectOne(Wrappers.<WmDaDrugEnt>lambdaQuery()
+					.eq(WmDaDrugEnt::getDeptId, deptId)
+					.eq(WmDaDrugEnt::getDelFlag, DelEnum.NOT_DEL.val()));
+			durgentId = wmDaDrugEnt.getId();
+		} else {
+			WmDaAgent wmDaAgent = wmDaAgentMapper.selectOne(Wrappers.<WmDaAgent>lambdaQuery()
+					.eq(WmDaAgent::getDeptId, deptId)
+					.eq(WmDaAgent::getDelFlag, DelEnum.NOT_DEL.val()));
+			durgentId = wmDaAgent.getId();
+		}
 		List<WmTaskType> taskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
 				.eq(WmTaskType::getDeptId, deptId)
-				.eq(WmTaskType::getDurgentId, wmDaDrugEnt.getId()));
+				.eq(WmTaskType::getRuleId, durgentId)
+				.eq(WmTaskType::getTaskEntId, durgentId));
 
 		WmDeptTaskTypeConfig deptTaskTypeConfig = this.getOne(Wrappers.<WmDeptTaskTypeConfig>lambdaQuery()
 				.eq(WmDeptTaskTypeConfig::getDeptId, deptId));
@@ -238,34 +295,23 @@ public class WmDeptTaskTypeConfigServiceImpl extends ServiceImpl<WmDeptTaskTypeC
 		List<Map<String, Object>> resultList = new ArrayList<>();
 		if (CollectionUtil.isNotEmpty(taskTypeList)) {
 			// 查询基础任务类型,用于匹配任务类型大类
-			List<WmTaskType> baseTaskTypeList = wmTaskTypeService.list(Wrappers.<WmTaskType>lambdaQuery()
-					.eq(WmTaskType::getEnableFlag, EnableEnum.ENABLE.val())
-					.eq(WmTaskType::getTaskTypeLevel, "1"));
-			// 根据parentId去重
-			List<WmTaskType> baseTaskTypeFilterList = baseTaskTypeList
-					.stream()
-					.collect(
-							Collectors.collectingAndThen(
-									Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WmTaskType::getParentId))), ArrayList::new
-							)
-					);
-			// 转换为key是baseId,value是taskTypelist的列表map
 			List<String> finalConfigTaskTypeIdList = configTaskTypeIdList;
 			List<String> finalAncestorConfigTaskTypeIdList = ancestorConfigTaskTypeIdList;
-			Map<String, List<WmTaskType>> tempTaskTypeMap = taskTypeList.stream()
+			List<WmTaskType> filterTaskTypeList = taskTypeList.stream()
 					.filter(wmTaskType -> wmTaskType.getParentId() != null
 							&& (
 							(finalConfigTaskTypeIdList != null && finalConfigTaskTypeIdList.contains(wmTaskType.getTaskTypeName()))
 									|| (finalAncestorConfigTaskTypeIdList != null && finalAncestorConfigTaskTypeIdList.contains(wmTaskType.getTaskTypeName()))
 					))
-					.collect(Collectors.groupingBy(WmTaskType::getParentId));
-			// 转换为list<map>
-			baseTaskTypeFilterList.forEach(taskType -> {
-				Map<String, Object> taskTypeMap = MapUtil.newHashMap(2);
-				List<WmTaskType> wmTaskTypes = tempTaskTypeMap.get(taskType.getParentId());
-				if (CollectionUtil.isNotEmpty(wmTaskTypes)) {
-					taskTypeMap.put("label", taskType.getTaskTypeName());
-					taskTypeMap.put("children", tempTaskTypeMap.get(taskType.getParentId()));
+					.collect(Collectors.toList());
+			BASE_TASK_TYPE_MAP.forEach((key, val) -> {
+				List<WmTaskType> childTypeList = filterTaskTypeList.stream()
+						.filter(wmTaskType -> val.contains(wmTaskType.getTaskTypeName()))
+						.collect(Collectors.toList());
+				if (CollectionUtil.isNotEmpty(childTypeList)) {
+					Map<String, Object> taskTypeMap = MapUtil.newHashMap(2);
+					taskTypeMap.put("label", key);
+					taskTypeMap.put("children", childTypeList);
 					resultList.add(taskTypeMap);
 				}
 			});
@@ -334,55 +380,65 @@ public class WmDeptTaskTypeConfigServiceImpl extends ServiceImpl<WmDeptTaskTypeC
 
 		// 根据不同任务类型的不同条件 拼接sql
 		QueryWrapper<WmTask> taskWrapper = Wrappers.query();
-		taskWrapper.eq("t.del_flag", DelEnum.NOT_DEL.val());
-		taskWrapper.eq("t.real_flag", "0");
-		taskWrapper.in("t.task_status", taskStatus);
 		List<WmDeptTaskTypeConfigJsonDTO> finalFilterConfigJsonDTOList = filterConfigJsonDTOList;
 		List<WmDeptTaskTypeConfigJsonDTO> finalFilterAncestorConfigList = filterAncestorConfigList;
-		taskWrapper.and(wrapper -> {
-			// 当前企业直接发包的任务 条件
-			if (finalFilterConfigJsonDTOList != null) {
-				for (WmDeptTaskTypeConfigJsonDTO configJsonDTO : finalFilterConfigJsonDTOList) {
-					// 用户类型
-					List<String> typeIdList = new ArrayList<>();
-					if (configJsonDTO.getZbdbStatusEnable() && configJsonDTO.getZbdbStatusSelect()) {
-						typeIdList.add("4");
-					}
-					if (configJsonDTO.getYydbStatusEnable() && configJsonDTO.getYydbStatusSelect()) {
-						typeIdList.add("3");
-					}
-					if (CollectionUtil.isNotEmpty(typeIdList)) {
-						wrapper.or(wrapper2 -> {
-							wrapper2.eq("t.task_type_id", configJsonDTO.getTaskTypeId());
-							wrapper2.eq("t.dept_id", deptId);
-							wrapper2.in("p.typeid", typeIdList);
-							wrapper2.isNull("p.relation_score_id");
-						});
+		if (CollectionUtil.isNotEmpty(finalFilterConfigJsonDTOList) || CollectionUtil.isNotEmpty(finalFilterAncestorConfigList)) {
+			taskWrapper.and(wrapper -> {
+				// 当前企业直接发包的任务 条件
+				if (CollectionUtil.isNotEmpty(finalFilterConfigJsonDTOList)) {
+					for (WmDeptTaskTypeConfigJsonDTO configJsonDTO : finalFilterConfigJsonDTOList) {
+						// 用户类型
+						List<String> typeIdList = new ArrayList<>();
+						if (configJsonDTO.getZbdbStatusEnable() && configJsonDTO.getZbdbStatusSelect()) {
+							typeIdList.add("4");
+						}
+						if (configJsonDTO.getYydbStatusEnable() && configJsonDTO.getYydbStatusSelect()) {
+							typeIdList.add("3");
+						}
+						if (CollectionUtil.isNotEmpty(typeIdList)) {
+							wrapper.or(wrapper2 -> {
+								wrapper2.eq("t.task_type_id", configJsonDTO.getTaskTypeId());
+								wrapper2.eq("t.dept_id", deptId);
+								wrapper2.in("p.typeid", typeIdList);
+								wrapper2.isNull("p.relation_score_id");
+							});
+						} else {
+							wrapper.or(wrapper2 -> {
+								wrapper2.ne("1", "1");
+							});
+						}
 					}
 				}
-			}
-			// 关联了上级企业的包的任务 条件
-			if (finalFilterAncestorConfigList != null) {
-				for (WmDeptTaskTypeConfigJsonDTO configJsonDTO : finalFilterAncestorConfigList) {
-					// 用户类型
-					List<String> typeIdList = new ArrayList<>();
-					if (configJsonDTO.getZbdbStatusEnable() && configJsonDTO.getZbdbStatusSelect()) {
-						typeIdList.add("4");
-					}
-					if (configJsonDTO.getYydbStatusEnable() && configJsonDTO.getYydbStatusSelect()) {
-						typeIdList.add("3");
-					}
-					if (CollectionUtil.isNotEmpty(typeIdList)) {
-						wrapper.or(wrapper2 -> {
-							wrapper2.eq("t.task_type_id", configJsonDTO.getTaskTypeId());
-							wrapper2.eq("t.dept_id", deptId);
-							wrapper2.in("p.typeid", typeIdList);
-							wrapper2.isNotNull("p.relation_score_id");
-						});
+				// 关联了上级企业的包的任务 条件
+				if (CollectionUtil.isNotEmpty(finalFilterAncestorConfigList)) {
+					for (WmDeptTaskTypeConfigJsonDTO configJsonDTO : finalFilterAncestorConfigList) {
+						// 用户类型
+						List<String> typeIdList = new ArrayList<>();
+						if (configJsonDTO.getZbdbStatusEnable() && configJsonDTO.getZbdbStatusSelect()) {
+							typeIdList.add("4");
+						}
+						if (configJsonDTO.getYydbStatusEnable() && configJsonDTO.getYydbStatusSelect()) {
+							typeIdList.add("3");
+						}
+						if (CollectionUtil.isNotEmpty(typeIdList)) {
+							wrapper.or(wrapper2 -> {
+								wrapper2.eq("t.task_type_id", configJsonDTO.getTaskTypeId());
+								wrapper2.eq("t.dept_id", deptId);
+								wrapper2.in("p.typeid", typeIdList);
+								wrapper2.isNotNull("p.relation_score_id");
+							});
+						} else {
+							wrapper.or(wrapper2 -> {
+								wrapper2.ne("1", "1");
+							});
+						}
 					}
 				}
-			}
-		});
+			});
+		}
+		taskWrapper.eq("t.del_flag", DelEnum.NOT_DEL.val());
+		taskWrapper.eq("t.real_flag", "0");
+		taskWrapper.in("t.task_status", taskStatus);
 		taskWrapper.orderByDesc("t.lookinto_date");
 		return wmTaskMapper.listWmTaskByWrapper(page, taskWrapper);
 	}