|
@@ -3,24 +3,25 @@ package com.ylx.massage.service.impl;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedHashSet;
|
|
import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ylx.common.core.domain.model.LoginUser;
|
|
import com.ylx.common.core.domain.model.LoginUser;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.DateUtils;
|
|
import com.ylx.common.utils.DateUtils;
|
|
|
import com.ylx.common.utils.StringUtils;
|
|
import com.ylx.common.utils.StringUtils;
|
|
|
-import com.ylx.massage.domain.MaProject;
|
|
|
|
|
import com.ylx.massage.domain.MaTeProject;
|
|
import com.ylx.massage.domain.MaTeProject;
|
|
|
import com.ylx.massage.domain.dto.MaTechnicianMerchantAddDTO;
|
|
import com.ylx.massage.domain.dto.MaTechnicianMerchantAddDTO;
|
|
|
import com.ylx.massage.domain.dto.MaTechnicianMerchantQueryDTO;
|
|
import com.ylx.massage.domain.dto.MaTechnicianMerchantQueryDTO;
|
|
|
import com.ylx.massage.domain.dto.MassageMerchantRecommendDto;
|
|
import com.ylx.massage.domain.dto.MassageMerchantRecommendDto;
|
|
|
import com.ylx.massage.domain.vo.MaTechnicianAppAddVo;
|
|
import com.ylx.massage.domain.vo.MaTechnicianAppAddVo;
|
|
|
|
|
+import com.ylx.massage.domain.vo.MaTechnicianMerchantDetailVO;
|
|
|
import com.ylx.massage.domain.vo.MaTechnicianMerchantListVO;
|
|
import com.ylx.massage.domain.vo.MaTechnicianMerchantListVO;
|
|
|
import com.ylx.massage.domain.vo.MerchantVo;
|
|
import com.ylx.massage.domain.vo.MerchantVo;
|
|
|
-import com.ylx.massage.mapper.MaProjectMapper;
|
|
|
|
|
import com.ylx.massage.mapper.MaTeProjectMapper;
|
|
import com.ylx.massage.mapper.MaTeProjectMapper;
|
|
|
import com.ylx.project.domain.Project;
|
|
import com.ylx.project.domain.Project;
|
|
|
import com.ylx.project.mapper.ProjectMapper;
|
|
import com.ylx.project.mapper.ProjectMapper;
|
|
@@ -113,7 +114,7 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int insertMerchant(MaTechnicianMerchantAddDTO dto, LoginUser loginUser) {
|
|
public int insertMerchant(MaTechnicianMerchantAddDTO dto, LoginUser loginUser) {
|
|
|
- Set<Long> projectIds = checkMerchantAddParam(dto);
|
|
|
|
|
|
|
+ MerchantProjectSelection selection = checkMerchantAddParam(dto);
|
|
|
String userName = loginUser.getUser().getUserName();
|
|
String userName = loginUser.getUser().getUserName();
|
|
|
|
|
|
|
|
MaTechnician maTechnician = new MaTechnician();
|
|
MaTechnician maTechnician = new MaTechnician();
|
|
@@ -121,15 +122,8 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
maTechnician.setTeNickName(dto.getTeNickName().trim());
|
|
maTechnician.setTeNickName(dto.getTeNickName().trim());
|
|
|
maTechnician.setTeSex(dto.getTeSex());
|
|
maTechnician.setTeSex(dto.getTeSex());
|
|
|
maTechnician.setTePhone(dto.getTePhone().trim());
|
|
maTechnician.setTePhone(dto.getTePhone().trim());
|
|
|
- maTechnician.setOpenService(dto.getOpenService());
|
|
|
|
|
- dto.getProjectIds().forEach(projectId -> {
|
|
|
|
|
- Project project = projectMapper.selectById(projectId);
|
|
|
|
|
- if (project != null) {
|
|
|
|
|
- maTechnician.setTeProject(project.getTitle() + ",");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- //移除末尾的逗号
|
|
|
|
|
- maTechnician.setTeProject(StrUtil.removeSuffix(maTechnician.getTeProject(), ","));
|
|
|
|
|
|
|
+ maTechnician.setOpenService(joinIds(selection.getCategoryIds()));
|
|
|
|
|
+ maTechnician.setTeProject(joinProjectTitles(selection.getProjectIds(), selection.getProjectMap()));
|
|
|
|
|
|
|
|
maTechnician.setTechType(dto.getTechType());
|
|
maTechnician.setTechType(dto.getTechType());
|
|
|
maTechnician.setIsRecommend(normalizeSwitchValue(dto.getIsRecommend(), "是否推荐"));
|
|
maTechnician.setIsRecommend(normalizeSwitchValue(dto.getIsRecommend(), "是否推荐"));
|
|
@@ -154,7 +148,7 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
if (rows <= 0) {
|
|
if (rows <= 0) {
|
|
|
throw new ServiceException("新增商户失败");
|
|
throw new ServiceException("新增商户失败");
|
|
|
}
|
|
}
|
|
|
- insertProjectRelations(maTechnician.getId(), projectIds);
|
|
|
|
|
|
|
+ insertProjectRelations(maTechnician.getId(), selection.getProjectIds());
|
|
|
return rows;
|
|
return rows;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -172,6 +166,24 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
return maTechnicianMapper.selectMerchantList(pageParam, dto);
|
|
return maTechnicianMapper.selectMerchantList(pageParam, dto);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 后台查询商户详情
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param id 商户ID
|
|
|
|
|
+ * @return 商户详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public MaTechnicianMerchantDetailVO selectMerchantDetail(Long id) {
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ throw new ServiceException("商户ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ MaTechnicianMerchantDetailVO detail = maTechnicianMapper.selectMerchantDetailById(id);
|
|
|
|
|
+ if (detail == null) {
|
|
|
|
|
+ throw new ServiceException("商户不存在或已删除");
|
|
|
|
|
+ }
|
|
|
|
|
+ return detail;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改技师
|
|
* 修改技师
|
|
|
*
|
|
*
|
|
@@ -234,7 +246,7 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
return maTechnicianMapper.getMerchantRecommend(dto);
|
|
return maTechnicianMapper.getMerchantRecommend(dto);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Set<Long> checkMerchantAddParam(MaTechnicianMerchantAddDTO dto) {
|
|
|
|
|
|
|
+ private MerchantProjectSelection checkMerchantAddParam(MaTechnicianMerchantAddDTO dto) {
|
|
|
if (dto == null) {
|
|
if (dto == null) {
|
|
|
throw new ServiceException("商户参数不能为空");
|
|
throw new ServiceException("商户参数不能为空");
|
|
|
}
|
|
}
|
|
@@ -242,16 +254,12 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
checkRequiredText(dto.getTeNickName(), "昵称", 10);
|
|
checkRequiredText(dto.getTeNickName(), "昵称", 10);
|
|
|
checkRequiredText(dto.getTePhone(), "电话", 11);
|
|
checkRequiredText(dto.getTePhone(), "电话", 11);
|
|
|
checkEnumValue(dto.getTeSex(), "性别", 0, 1);
|
|
checkEnumValue(dto.getTeSex(), "性别", 0, 1);
|
|
|
- //checkEnumValue(dto.getOpenService(), "服务类目", 1, 2);
|
|
|
|
|
- //校验服务类名不能为空
|
|
|
|
|
- if (dto.getOpenService() == null) {
|
|
|
|
|
- throw new ServiceException("服务类目不能为空");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Set<Integer> categoryIds = checkOpenServiceIds(dto.getOpenService());
|
|
|
checkEnumValue(dto.getTechType(), "商户类型", 0, 1);
|
|
checkEnumValue(dto.getTechType(), "商户类型", 0, 1);
|
|
|
if (dto.getIsRecommend() != null) {
|
|
if (dto.getIsRecommend() != null) {
|
|
|
checkEnumValue(dto.getIsRecommend(), "是否推荐", 0, 1);
|
|
checkEnumValue(dto.getIsRecommend(), "是否推荐", 0, 1);
|
|
|
}
|
|
}
|
|
|
- return checkProjectIds(dto.getProjectIds());
|
|
|
|
|
|
|
+ return checkProjectIds(dto.getProjectIds(), categoryIds);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void checkRequiredText(String value, String fieldName, int maxLength) {
|
|
private void checkRequiredText(String value, String fieldName, int maxLength) {
|
|
@@ -285,10 +293,12 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 校验服务项目ID集合
|
|
* 校验服务项目ID集合
|
|
|
- * @param projectIds
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param projectIds 服务项目ID集合
|
|
|
|
|
+ * @param categoryIds 服务类目ID集合
|
|
|
* @return 有效服务项目ID集合
|
|
* @return 有效服务项目ID集合
|
|
|
*/
|
|
*/
|
|
|
- private Set<Long> checkProjectIds(List<Long> projectIds) {
|
|
|
|
|
|
|
+ private MerchantProjectSelection checkProjectIds(List<Long> projectIds, Set<Integer> categoryIds) {
|
|
|
if (projectIds == null || projectIds.isEmpty()) {
|
|
if (projectIds == null || projectIds.isEmpty()) {
|
|
|
throw new ServiceException("服务项目不能为空");
|
|
throw new ServiceException("服务项目不能为空");
|
|
|
}
|
|
}
|
|
@@ -301,17 +311,64 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
distinctProjectIds.add(projectId);
|
|
distinctProjectIds.add(projectId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*int validCount = 0;
|
|
|
|
|
|
|
+ List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
|
|
|
|
|
+ .in(Project::getId, distinctProjectIds)
|
|
|
|
|
+ .eq(Project::getIsDelete, 0));
|
|
|
|
|
+ if (projects.size() != distinctProjectIds.size()) {
|
|
|
|
|
+ throw new ServiceException("服务项目不存在或已删除");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, Project> projectMap = projects.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(project -> project.getId().longValue(), Function.identity(), (left, right) -> left));
|
|
|
|
|
+ Set<Integer> projectCategoryIds = new LinkedHashSet<>();
|
|
|
for (Long projectId : distinctProjectIds) {
|
|
for (Long projectId : distinctProjectIds) {
|
|
|
- MaProject project = maProjectMapper.selectMaProjectById(projectId);
|
|
|
|
|
- if (project != null && (project.getIsDelete() == null || project.getIsDelete() != 1)) {
|
|
|
|
|
- validCount++;
|
|
|
|
|
|
|
+ Project project = projectMap.get(projectId);
|
|
|
|
|
+ if (project == null || project.getType() == null) {
|
|
|
|
|
+ throw new ServiceException("服务项目类目不能为空");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!categoryIds.contains(project.getType())) {
|
|
|
|
|
+ throw new ServiceException("服务项目不属于所选服务类目");
|
|
|
|
|
+ }
|
|
|
|
|
+ projectCategoryIds.add(project.getType());
|
|
|
}
|
|
}
|
|
|
- if (validCount != distinctProjectIds.size()) {
|
|
|
|
|
- throw new ServiceException("服务项目不存在或已删除");
|
|
|
|
|
- }*/
|
|
|
|
|
- return distinctProjectIds;
|
|
|
|
|
|
|
+ if (!projectCategoryIds.containsAll(categoryIds)) {
|
|
|
|
|
+ throw new ServiceException("每个服务类目至少选择一个服务项目");
|
|
|
|
|
+ }
|
|
|
|
|
+ return new MerchantProjectSelection(categoryIds, distinctProjectIds, projectMap);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验服务类目ID集合
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param openService 服务类目ID集合
|
|
|
|
|
+ * @return 去重后的服务类目ID集合
|
|
|
|
|
+ */
|
|
|
|
|
+ private Set<Integer> checkOpenServiceIds(List<Integer> openService) {
|
|
|
|
|
+ if (openService == null || openService.isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("服务类目不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ Set<Integer> categoryIds = new LinkedHashSet<>();
|
|
|
|
|
+ for (Integer categoryId : openService) {
|
|
|
|
|
+ if (categoryId == null) {
|
|
|
|
|
+ throw new ServiceException("服务类目ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ categoryIds.add(categoryId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return categoryIds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String joinIds(Set<Integer> ids) {
|
|
|
|
|
+ return ids.stream()
|
|
|
|
|
+ .map(String::valueOf)
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String joinProjectTitles(Set<Long> projectIds, Map<Long, Project> projectMap) {
|
|
|
|
|
+ return projectIds.stream()
|
|
|
|
|
+ .map(projectMap::get)
|
|
|
|
|
+ .map(Project::getTitle)
|
|
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -337,4 +394,28 @@ public class MaTechnicianServiceImpl implements IMaTechnicianService
|
|
|
throw new ServiceException("新增商户服务项目失败");
|
|
throw new ServiceException("新增商户服务项目失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static class MerchantProjectSelection {
|
|
|
|
|
+ private final Set<Integer> categoryIds;
|
|
|
|
|
+ private final Set<Long> projectIds;
|
|
|
|
|
+ private final Map<Long, Project> projectMap;
|
|
|
|
|
+
|
|
|
|
|
+ private MerchantProjectSelection(Set<Integer> categoryIds, Set<Long> projectIds, Map<Long, Project> projectMap) {
|
|
|
|
|
+ this.categoryIds = categoryIds;
|
|
|
|
|
+ this.projectIds = projectIds;
|
|
|
|
|
+ this.projectMap = projectMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<Integer> getCategoryIds() {
|
|
|
|
|
+ return categoryIds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<Long> getProjectIds() {
|
|
|
|
|
+ return projectIds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<Long, Project> getProjectMap() {
|
|
|
|
|
+ return projectMap;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|