Commit b79800ef by 刘鑫

fix(工作队添加人员): 工作队添加人员时进行校验

1 parent aa078d92
...@@ -71,7 +71,7 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ ...@@ -71,7 +71,7 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" LEFT JOIN engineer_info ei ON esg.engineer_code = ei.engineer_code\n" + " LEFT JOIN engineer_info ei ON esg.engineer_code = ei.engineer_code\n" +
" LEFT JOIN org_team_engineer ote ON ote.engineer_code = ei.engineer_code \n" + " LEFT JOIN org_team_engineer ote ON ote.engineer_code = ei.engineer_code \n" +
" WHERE si.brand = :brand AND si.type= :productType AND si.skill = :skill \n" + " WHERE si.brand = :brand AND si.type= :productType AND si.skill = :skill \n" +
" AND ote.team_id = :teamId ", nativeQuery = true) " AND ote.team_id = :teamId AND ote.status = 1", nativeQuery = true)
Set<EngineerInfoEntity> listByBrandAndTypeAndSkillAndTeamId(@Param("brand") String brand, @Param("productType") String productType, Set<EngineerInfoEntity> listByBrandAndTypeAndSkillAndTeamId(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("teamId") String teamId); @Param("skill") String skill, @Param("teamId") String teamId);
...@@ -107,6 +107,6 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ ...@@ -107,6 +107,6 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
* @return 工作队下没有工程师则返回空 * @return 工作队下没有工程师则返回空
*/ */
@Query(value = "SELECT ei.* from org_team_engineer ote left join engineer_info ei ON ote.engineer_code = ei.engineer_code " + @Query(value = "SELECT ei.* from org_team_engineer ote left join engineer_info ei ON ote.engineer_code = ei.engineer_code " +
"WHERE ote.team_id = :teamId AND ote.engineer_code = :engineerCode", nativeQuery = true) "WHERE ote.team_id = :teamId AND ote.engineer_code = :engineerCode AND ote.`status` = 1", nativeQuery = true)
EngineerInfoEntity selectEngineerByEngineerCodeAndTeamId(@Param("engineerCode") String engineerCode, @Param("teamId") String teamId); EngineerInfoEntity selectEngineerByEngineerCodeAndTeamId(@Param("engineerCode") String engineerCode, @Param("teamId") String teamId);
} }
...@@ -51,6 +51,7 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer>, JpaSp ...@@ -51,6 +51,7 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer>, JpaSp
* @param engineerCode 工程师代码 * @param engineerCode 工程师代码
* @return 工程师所在工作队信息 * @return 工程师所在工作队信息
*/ */
@Query(value = "SELECT ot.* FROM org_team ot LEFT JOIN org_team_engineer ote ON ote.team_id = ot.team_id WHERE ote.engineer_code = :engineerCode", nativeQuery = true) @Query(value = "SELECT ot.* FROM org_team_engineer ote LEFT JOIN org_team ot ON ote.team_id = ot.team_id WHERE ote.engineer_code = :engineerCode " +
" AND ote.`status` = 1 AND ot.status = 1 ", nativeQuery = true)
Set<OrgTeamEntity> selectTeamByEngineerCode(String engineerCode); Set<OrgTeamEntity> selectTeamByEngineerCode(String engineerCode);
} }
...@@ -10,6 +10,14 @@ public class ScheduleEngineerOverviewResp { ...@@ -10,6 +10,14 @@ public class ScheduleEngineerOverviewResp {
private String engineerCode; private String engineerCode;
private String startTime; private String startTime;
private String endTime; private String endTime;
/**
* 手机号
*/
private String phoneNumber;
/**
* 技能等级
*/
private String skillLevel;
private List<LabelValueDTO> dynamics; private List<LabelValueDTO> dynamics;
private List<TimeLineDTO> orders; private List<TimeLineDTO> orders;
private List<Order> orderDetails; private List<Order> orderDetails;
......
package com.dituhui.pea.order.service.impl; package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtils; import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dto.*; import com.dituhui.pea.order.dao.OrgGroupDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.OrgTeamEngineerDao;
import com.dituhui.pea.order.dao.OrgWarehouseInfoDao;
import com.dituhui.pea.order.dto.BusinessTeamAddDTO;
import com.dituhui.pea.order.dto.BusinessTeamConfigInitDTO;
import com.dituhui.pea.order.dto.BusinessTeamConfigSubmitDTO;
import com.dituhui.pea.order.dto.BusinessTeamDeleteDTO;
import com.dituhui.pea.order.dto.BusinessTeamDetailDTO;
import com.dituhui.pea.order.dto.BusinessTeamUpdateDTO;
import com.dituhui.pea.order.dto.BusinessTeamWarehousesDTO;
import com.dituhui.pea.order.dto.BusinessTeamsDTO;
import com.dituhui.pea.order.entity.OrgGroupEntity; import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.OrgTeamEngineerEntity; import com.dituhui.pea.order.entity.OrgTeamEngineerEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity; import com.dituhui.pea.order.entity.OrgTeamEntity;
...@@ -12,6 +24,7 @@ import com.dituhui.pea.order.entity.OrgWarehouseInfoEntity; ...@@ -12,6 +24,7 @@ import com.dituhui.pea.order.entity.OrgWarehouseInfoEntity;
import com.dituhui.pea.order.service.BusinessTeamService; import com.dituhui.pea.order.service.BusinessTeamService;
import com.dituhui.pea.order.service.CommonService; import com.dituhui.pea.order.service.CommonService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -20,10 +33,18 @@ import org.springframework.data.domain.Pageable; ...@@ -20,10 +33,18 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.MessageFormat;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.dituhui.pea.order.config.OrderConfig.TEAMTYPE_PEA; import static com.dituhui.pea.order.config.OrderConfig.TEAMTYPE_PEA;
...@@ -190,20 +211,47 @@ public class BusinessTeamServiceImpl implements BusinessTeamService { ...@@ -190,20 +211,47 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
// 技术员列表 // 技术员列表
if (req.getEngineerCodes() != null && !req.getEngineerCodes().isEmpty()) { if (req.getEngineerCodes() != null && !req.getEngineerCodes().isEmpty()) {
updateTeamEngineers(req.getTeamId(), req.getEngineerCodes()); updateTeamEngineers(entity, req.getEngineerCodes());
} }
return Result.success(null); return Result.success(null);
} }
public void updateTeamEngineers(String teamId, List<String> engineerCodes) { public void updateTeamEngineers(OrgTeamEntity targetTeam, List<String> engineerCodes) {
// 获取现有的工作队和技术员之间的所有关系 // 获取现有的工作队和技术员之间的所有关系
List<OrgTeamEngineerEntity> existingRelations = orgTeamEngineerDao.findAllByTeamId(teamId); final String targetTeamId = String.valueOf(targetTeam.getId());
List<String> targetTeamWorkDayOfWeek = List.of(targetTeam.getWorkdays().split(","));
List<OrgTeamEngineerEntity> existingRelations = orgTeamEngineerDao.findAllByTeamId(targetTeamId);
// 查询工程师在其它工作队的工作时间以及当前工作队的工作时间
final String message = "工号为{0}的工程师在{1}工作队的周{2}已有工作日安排";
List<String> warnMessage = new ArrayList<>();
for (String engineerCode : engineerCodes) {
Set<OrgTeamEntity> teamEntitySet = orgTeamDao.selectTeamByEngineerCode(engineerCode);
if (CollectionUtils.isEmpty(teamEntitySet)) {
continue;
}
//移除当前工作队并校验工作队工作时间
teamEntitySet.stream()
.filter(t -> !Objects.equals(targetTeamId, t.getTeamId()))
.forEach(team -> {
//返回任何一个有工作日冲突的工作队
List<String> fixedWorkDayOfWeek = List.of(team.getWorkdays().split(","));
List<String> workDays = targetTeamWorkDayOfWeek.stream().filter(dayOfWeek -> fixedWorkDayOfWeek.stream().anyMatch(fixDay -> Objects.equals(fixDay, dayOfWeek)))
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(workDays)) {
warnMessage.add(MessageFormat.format(message, engineerCode, team.getTeamName(), StringUtils.join(workDays, ",")));
}
});
}
if (!CollectionUtils.isEmpty(warnMessage)) {
throw new BusinessException(StringUtils.join(warnMessage, ";"));
}
// 构建新的关系映射 // 构建新的关系映射
Map<String, OrgTeamEngineerEntity> newRelationsMap = new HashMap<>(); Map<String, OrgTeamEngineerEntity> newRelationsMap = new HashMap<>();
for (String engineerCode : engineerCodes) { for (String engineerCode : engineerCodes) {
OrgTeamEngineerEntity relation = new OrgTeamEngineerEntity(); OrgTeamEngineerEntity relation = new OrgTeamEngineerEntity();
relation.setTeamId(teamId); relation.setTeamId(targetTeamId);
relation.setEngineerCode(engineerCode); relation.setEngineerCode(engineerCode);
relation.setCreateTime(LocalDateTime.now()); relation.setCreateTime(LocalDateTime.now());
relation.setUpdateTime(LocalDateTime.now()); relation.setUpdateTime(LocalDateTime.now());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!