Commit 2919af32 by 丁伟峰

容量接口修改

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