Commit 2919af32 by 丁伟峰

容量接口修改

1 parent ed3c80ca
...@@ -12,6 +12,9 @@ import java.util.List; ...@@ -12,6 +12,9 @@ import java.util.List;
@Repository @Repository
public interface CapacityOrgStatDao extends JpaRepository<CapacityOrgStatEntity, Integer> { public interface CapacityOrgStatDao extends JpaRepository<CapacityOrgStatEntity, Integer> {
@Query("select c from CapacityOrgStatEntity c where c.type = 'group' and c.orgId = :groupId and c.workday between :beginDate and :endDate") @Query("select c from CapacityOrgStatEntity c where c.type = 'group' and c.orgId in :groupIds and c.workday between :beginDate and :endDate")
Page<?> findByGroupIdAndWorkdayBetween(String groupId, String beginDate, String endDate, Pageable page); Page<?> findByGroupIdsAndWorkdayBetween(List<String> groupIds, String beginDate, String endDate, Pageable page);
@Query("select c from CapacityOrgStatEntity c where c.type = 'branch' and c.orgId in :branchIds and c.workday between :beginDate and :endDate")
Page<?> findByBranchIdsAndWorkdayBetween(List<String> branchIds, String beginDate, String endDate, Pageable page);
} }
...@@ -14,8 +14,9 @@ public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntit ...@@ -14,8 +14,9 @@ public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntit
List<CapacityTeamStatEntity> findAllByTeamIdAndLayerAndWorkdayBetween(String teamId, String layer, String beginDate, String endDate); List<CapacityTeamStatEntity> findAllByTeamIdAndLayerAndWorkdayBetween(String teamId, String layer, String beginDate, String endDate);
@Query("select c from CapacityTeamStatEntity c where c.teamId = :teamId and c.workday between :beginDate and :endDate") @Query("select c from CapacityTeamStatEntity c where c.teamId IN :teamIds and c.workday between :beginDate and :endDate")
Page<?> findByTeamIdAndWorkdayBetween(String teamId, String beginDate, String endDate, Pageable pageable); Page<?> findByTeamIdsAndWorkdayBetween(List<String> teamIds, String beginDate, String endDate, Pageable pageable);
@Query(value = "SELECT team_id FROM capacity_team_stat where layer = :layer ORDER BY RAND() LIMIT 1", nativeQuery = true) @Query(value = "SELECT team_id FROM capacity_team_stat where layer = :layer ORDER BY RAND() LIMIT 1", nativeQuery = true)
String getRandomTeamIdByLayer(String layer); String getRandomTeamIdByLayer(String layer);
......
...@@ -3,5 +3,5 @@ package com.alibaba.cloud.integration.order.dto; ...@@ -3,5 +3,5 @@ package com.alibaba.cloud.integration.order.dto;
@lombok.Data @lombok.Data
public class OrganizationTreeReqDTO { public class OrganizationTreeReqDTO {
private String levelType; private String levelType;
private String levelId; private String levelValue;
} }
...@@ -5,7 +5,7 @@ import com.alibaba.cloud.integration.common.Result; ...@@ -5,7 +5,7 @@ import com.alibaba.cloud.integration.common.Result;
import java.util.List; import java.util.List;
public interface OrganizationService { public interface OrganizationService {
Result<?> getOrganizationTree(String levelType, String levelId); Result<?> getOrganizationTree(String levelType, String levelValue);
Result<?> getEngineersByTeams(List<String> teamIds); Result<?> getEngineersByTeams(List<String> teamIds);
......
...@@ -6,9 +6,7 @@ import com.alibaba.cloud.integration.order.dto.CapacityOrderQueryReqDTO; ...@@ -6,9 +6,7 @@ import com.alibaba.cloud.integration.order.dto.CapacityOrderQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityQueryOrderRespDTO; import com.alibaba.cloud.integration.order.dto.CapacityQueryOrderRespDTO;
import com.alibaba.cloud.integration.order.dto.CapacityStatQueryReqDTO; import com.alibaba.cloud.integration.order.dto.CapacityStatQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityStatQueryRespDTO; import com.alibaba.cloud.integration.order.dto.CapacityStatQueryRespDTO;
import com.alibaba.cloud.integration.order.entity.CapacityOrgStatEntity; import com.alibaba.cloud.integration.order.entity.*;
import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity;
import com.alibaba.cloud.integration.order.entity.OrgGroupEntity;
import com.alibaba.cloud.integration.order.service.CapacityQueryService; import com.alibaba.cloud.integration.order.service.CapacityQueryService;
import com.alibaba.cloud.integration.order.service.CommonService; import com.alibaba.cloud.integration.order.service.CommonService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -29,6 +27,7 @@ import java.util.*; ...@@ -29,6 +27,7 @@ import java.util.*;
public class CapacityQueryServiceImpl implements CapacityQueryService { public class CapacityQueryServiceImpl implements CapacityQueryService {
private final String[] fullDay = {"08:00", "18:00"}; private final String[] fullDay = {"08:00", "18:00"};
@Autowired @Autowired
private CapacityTeamStatDao capacityTeamStatDao; private CapacityTeamStatDao capacityTeamStatDao;
...@@ -48,18 +47,19 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -48,18 +47,19 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
@Autowired @Autowired
private CommonService commonService; private CommonService commonService;
@Autowired
private OrgBranchDao orgBranchDao;
@Override @Override
public Result<?> getOneCapacityData(CapacityOrderQueryReqDTO reqDTO) { public Result<?> getOneCapacityData(CapacityOrderQueryReqDTO reqDTO) {
/* // 单条容量查询
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/
log.info("===> getOneCapacityData"); log.info("===> getOneCapacityData");
String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill()); String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
String teamId = commonService.getTeamIdByInput(reqDTO.getLocation(), reqDTO.getAddress(), layer); String teamId = commonService.getTeamIdByInput(reqDTO.getLocation(), reqDTO.getAddress(), layer);
log.info("teamId[{}]layer[{}]", teamId, layer); log.info("teamId[{}]layer[{}]", teamId, layer);
CapacityQueryOrderRespDTO capacityQueryRespDTO = new CapacityQueryOrderRespDTO(); CapacityQueryOrderRespDTO capacityQueryRespDTO = new CapacityQueryOrderRespDTO();
capacityQueryRespDTO.setBeginDate(reqDTO.getBeginDate()).setEndDate(reqDTO.getEndDate()); capacityQueryRespDTO.setBeginDate(reqDTO.getBeginDate()).setEndDate(reqDTO.getEndDate());
capacityQueryRespDTO.setCalendar(getTeamCaparityByLayerAndDays(teamId, layer, reqDTO.getBeginDate(), reqDTO.getEndDate())); capacityQueryRespDTO.setCalendar(getTeamCapacityByLayerAndDays(teamId, layer, reqDTO.getBeginDate(), reqDTO.getEndDate()));
capacityQueryRespDTO.setLegend(getLengends()); capacityQueryRespDTO.setLegend(getLengends());
capacityQueryRespDTO.setRemark(String.format("%s-%s", teamId, layer)); capacityQueryRespDTO.setRemark(String.format("%s-%s", teamId, layer));
return Result.success(capacityQueryRespDTO); return Result.success(capacityQueryRespDTO);
...@@ -74,28 +74,36 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -74,28 +74,36 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
} }
@Override @Override
public Result<?> getTeamStatData(CapacityStatQueryReqDTO capacityStatQueryReqDTO) { public Result<?> getTeamStatData(CapacityStatQueryReqDTO reqDTO) {
// 根据大区/分部/分站查询,分别返回分部/分站/工作队的容量
Page<?> stats = null; Page<?> stats = null;
Pageable pageable = PageRequest.of(capacityStatQueryReqDTO.getPage() - 1, capacityStatQueryReqDTO.getPageSize()); Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getPageSize());
if ("group".equals(capacityStatQueryReqDTO.getLevelType())) { if ("cluster".equals(reqDTO.getLevelType())) {
stats = capacityOrgStatDao.findByGroupIdAndWorkdayBetween(capacityStatQueryReqDTO.getLevelValue(), capacityStatQueryReqDTO.getBeginDate(), capacityStatQueryReqDTO.getEndDate(), pageable); List<String> branchIds = getBranchIdsByClusterId(reqDTO.getLevelValue());
stats = capacityOrgStatDao.findByBranchIdsAndWorkdayBetween(branchIds, reqDTO.getBeginDate(), reqDTO.getEndDate(), pageable);
} else if ("branch".equals(reqDTO.getLevelType())) {
List<String> groupIds = getGroupIdsByBranchId(reqDTO.getLevelValue());
stats = capacityOrgStatDao.findByGroupIdsAndWorkdayBetween(groupIds, reqDTO.getBeginDate(), reqDTO.getEndDate(), pageable);
} else { } else {
stats = capacityTeamStatDao.findByTeamIdAndWorkdayBetween(capacityStatQueryReqDTO.getLevelValue(), capacityStatQueryReqDTO.getBeginDate(), capacityStatQueryReqDTO.getEndDate(), pageable); List<String> teamIds = getTeamIdsByGroupId(reqDTO.getLevelValue());
stats = capacityTeamStatDao.findByTeamIdsAndWorkdayBetween(teamIds, reqDTO.getBeginDate(), reqDTO.getEndDate(), pageable);
} }
CapacityStatQueryRespDTO data = new CapacityStatQueryRespDTO(); CapacityStatQueryRespDTO data = new CapacityStatQueryRespDTO();
data.setLevelType(capacityStatQueryReqDTO.getLevelType()); data.setLevelType(reqDTO.getLevelType());
data.setTotal(stats.getTotalElements()).setPages(stats.getTotalPages()).setPageSize(pageable.getPageSize()).setPageCurrent(stats.getNumber()); data.setTotal(stats.getTotalElements()).setPages(stats.getTotalPages()).setPageSize(pageable.getPageSize()).setPageCurrent(stats.getNumber());
List<CapacityStatQueryRespDTO.Content> contents = new ArrayList<>(); List<CapacityStatQueryRespDTO.Content> contents = new ArrayList<>();
for (Object item : stats.getContent()) { for (Object item : stats.getContent()) {
CapacityStatQueryRespDTO.Content content = new CapacityStatQueryRespDTO.Content(); CapacityStatQueryRespDTO.Content content = new CapacityStatQueryRespDTO.Content();
if (item instanceof CapacityOrgStatEntity) { if (item instanceof CapacityOrgStatEntity) {
// cluster/branch查询,都是capacity_org_stat
CapacityOrgStatEntity e = (CapacityOrgStatEntity) item; CapacityOrgStatEntity e = (CapacityOrgStatEntity) item;
OrgGroupEntity g = orgGroupDao.getByGroupId(e.getOrgId()); OrgGroupEntity g = orgGroupDao.getByGroupId(e.getOrgId());
content.setDate(e.getWorkday()).setLayer(e.getLayer()).setGroupName(g.getGroupName()) content.setDate(e.getWorkday()).setLayer(e.getLayer()).setGroupName(g.getGroupName())
.setCapTotal(e.getCapTotal()).setCapUsed(e.getCapUsedTotal()) .setCapTotal(e.getCapTotal()).setCapUsed(e.getCapUsedTotal())
.setEngineerNum(e.getEngineerCount()).setCreateTime(e.getCreateTime().toString()); .setEngineerNum(e.getEngineerCount()).setCreateTime(e.getCreateTime().toString());
} else { } else {
// group查询,是capacity_team_stat
CapacityTeamStatEntity e = (CapacityTeamStatEntity) item; CapacityTeamStatEntity e = (CapacityTeamStatEntity) item;
// capacity_team_stat表中的team_id,直接就是字符串 // capacity_team_stat表中的team_id,直接就是字符串
content.setDate(e.getWorkday()).setLayer(e.getLayer()).setTeamName(e.getTeamId()) content.setDate(e.getWorkday()).setLayer(e.getLayer()).setTeamName(e.getTeamId())
...@@ -109,6 +117,29 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -109,6 +117,29 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return Result.success(data); return Result.success(data);
} }
private List<String> getTeamIdsByGroupId(String groupId) {
List<String> teamIds = new ArrayList<>();
for (OrgTeamEntity e : orgTeamDao.findAllByGroupId(groupId)) {
teamIds.add(e.getTeamId());
}
return teamIds;
}
private List<String> getBranchIdsByClusterId(String clusterId) {
List<String> branchIds = new ArrayList<>();
for (OrgBranchEntity e : orgBranchDao.findAllByClusterId(clusterId)) {
branchIds.add(e.getBranchId());
}
return branchIds;
}
private List<String> getGroupIdsByBranchId(String branchId) {
List<String> groupIds = new ArrayList<>();
for (OrgGroupEntity e : orgGroupDao.findAllByBranchId(branchId)) {
groupIds.add(e.getGroupId());
}
return groupIds;
}
private int getSpanType(int capLeft, int capTotal) { private int getSpanType(int capLeft, int capTotal) {
float ratio = (float) capLeft / capTotal; float ratio = (float) capLeft / capTotal;
...@@ -147,7 +178,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService { ...@@ -147,7 +178,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
* @param endDate * @param endDate
* @return * @return
*/ */
private List<CapacityQueryOrderRespDTO.CalendarDTO> getTeamCaparityByLayerAndDays(String teamId, String layer, String beginDate, String endDate) { private List<CapacityQueryOrderRespDTO.CalendarDTO> getTeamCapacityByLayerAndDays(String teamId, String layer, String beginDate, String endDate) {
log.info("==> getTimeRangeByTeamSkill({}, {}, {}, {})", teamId, layer, beginDate, endDate); log.info("==> getTimeRangeByTeamSkill({}, {}, {}, {})", teamId, layer, beginDate, endDate);
Map<String, CapacityQueryOrderRespDTO.CalendarDTO> dayMaps = new HashMap<>(); Map<String, CapacityQueryOrderRespDTO.CalendarDTO> dayMaps = new HashMap<>();
List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndLayerAndWorkdayBetween(teamId, layer, beginDate, endDate); List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndLayerAndWorkdayBetween(teamId, layer, beginDate, endDate);
......
...@@ -32,7 +32,6 @@ import com.alibaba.cloud.integration.order.service.CommonService; ...@@ -32,7 +32,6 @@ import com.alibaba.cloud.integration.order.service.CommonService;
import com.alibaba.cloud.integration.order.service.OrderCreateService; import com.alibaba.cloud.integration.order.service.OrderCreateService;
import io.seata.core.context.RootContext; import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -48,9 +47,6 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -48,9 +47,6 @@ public class OrderCreateServiceImpl implements OrderCreateService {
private OrderRequestDao orderRequestDao; private OrderRequestDao orderRequestDao;
@Autowired @Autowired
private OrderTagStrategyDao orderTagStrategyDao;
@Autowired
private ProductCategoryDao productCategoryDao; private ProductCategoryDao productCategoryDao;
@Autowired @Autowired
......
...@@ -20,28 +20,24 @@ import java.util.List; ...@@ -20,28 +20,24 @@ import java.util.List;
@Slf4j @Slf4j
public class OrganizationServiceImpl implements OrganizationService { public class OrganizationServiceImpl implements OrganizationService {
private final OrgClusterDao orgClusterDao;
private final OrgBranchDao orgBranchDao;
private final OrgGroupDao orgGroupDao;
private final OrgTeamEngineerDao orgTeamEngineerDao;
private final EngineerInfoDao engineerInfoDao;
private final OrgTeamDao orgTeamDao;
@Autowired @Autowired
public OrganizationServiceImpl(OrgClusterDao orgClusterDao, OrgBranchDao orgBranchDao, OrgGroupDao orgGroupDao, OrgTeamEngineerDao orgTeamEngineerDao, EngineerInfoDao engineerInfoDao, OrgTeamDao orgTeamDao) { private OrgClusterDao orgClusterDao;
this.orgClusterDao = orgClusterDao; @Autowired
this.orgBranchDao = orgBranchDao; private OrgBranchDao orgBranchDao;
this.orgGroupDao = orgGroupDao; @Autowired
this.orgTeamEngineerDao = orgTeamEngineerDao; private OrgGroupDao orgGroupDao;
this.engineerInfoDao = engineerInfoDao; @Autowired
this.orgTeamDao = orgTeamDao; private OrgTeamEngineerDao orgTeamEngineerDao;
} @Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgTeamDao orgTeamDao;
@Override @Override
public Result<?> getOrganizationTree(String levelType, String levelId) { public Result<?> getOrganizationTree(String levelType, String levelValue) {
// 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容 // 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容
if ("group".equals(levelType)) { if ("group".equals(levelType)) {
OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelId); OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelValue);
if (orgGroupEntity == null) { if (orgGroupEntity == null) {
return Result.failed("groupId对应的信息不存在"); return Result.failed("groupId对应的信息不存在");
} }
...@@ -52,21 +48,21 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -52,21 +48,21 @@ public class OrganizationServiceImpl implements OrganizationService {
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("branch".equals(levelType)) { } else if ("branch".equals(levelType)) {
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelId); OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue);
if (orgBranchEntity == null) { if (orgBranchEntity == null) {
return Result.failed("分站信息不存在"); return Result.failed("分站信息不存在");
} }
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId()); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId());
List<?> groups = getChildByBranch(levelId); List<?> groups = getChildByBranch(levelValue);
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups))); List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("cluster".equals(levelType)) { } else if ("cluster".equals(levelType)) {
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelId); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue);
if (orgClusterEntity == null) { if (orgClusterEntity == null) {
return Result.failed("大区信息不存在"); return Result.failed("大区信息不存在");
} }
List<?> branchs = getChildByCluster(levelId); List<?> branchs = getChildByCluster(levelValue);
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else { } else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!