Commit d327c81e by 丁伟峰

增加了容量查询接口实现

1 parent 5d15fe0f
Showing with 250 additions and 25 deletions
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.CapacityStatQueryReqDTO;
import com.alibaba.cloud.integration.order.service.CapacityQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CapacityController {
@Autowired
private CapacityQueryService capacityQueryService;
@PostMapping("/capacity/query")
public Result<?> capacityQuery(@Validated @RequestBody CapacityStatQueryReqDTO reqDTO) {
Result<?> res = null;
try {
res = capacityQueryService.getTeamStatData(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
......@@ -19,7 +19,7 @@ package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityOrderQueryReqDTO;
import com.alibaba.cloud.integration.order.service.OrderService;
import com.alibaba.cloud.integration.order.service.CapacityQueryService;
......@@ -59,7 +59,7 @@ public class OrderCreateController {
}
@PostMapping("/order/service/capacity/query")
public Result<?> capacityQuery(@Validated @RequestBody CapacityQueryReqDTO capacityQueryReqDTO) {
public Result<?> capacityQuery(@Validated @RequestBody CapacityOrderQueryReqDTO capacityQueryReqDTO) {
Result<?> res = null;
try {
res = capacityQueryService.getOneCapacityData(capacityQueryReqDTO);
......
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.CapacityOrgStatEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
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);
}
......@@ -2,7 +2,10 @@ package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -11,4 +14,7 @@ import java.util.List;
public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntity, Long> {
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);
}
......@@ -13,12 +13,12 @@ import org.springframework.stereotype.Repository;
public interface OrderChangeDao extends JpaRepository<OrderChangeEntity, Integer> {
@Query("select a from OrderChangeEntity a join OrderRequestEntity b on a.orderId=b.orderId where b.orgClusterId = :clusterId")
Page<OrderChangeEntity> findAllByClusterId(Pageable pageable, String clusterId);
Page<OrderChangeEntity> findAllByClusterId(String clusterId, Pageable pageable);
@Query("select a from OrderChangeEntity a join OrderRequestEntity b on a.orderId=b.orderId where b.orgBranchId = :branchId")
Page<OrderChangeEntity> findAllByBranchId(Pageable pageable, String branchId);
Page<OrderChangeEntity> findAllByBranchId(String branchId, Pageable pageable);
@Query("select a from OrderChangeEntity a join OrderRequestEntity b on a.orderId=b.orderId where b.orgGroupId = :groupId")
Page<OrderChangeEntity> findAllByGroupId(Pageable pageable, String groupId);
Page<OrderChangeEntity> findAllByGroupId(String groupId, Pageable pageable);
}
......@@ -3,7 +3,7 @@ package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
@Data
public class CapacityQueryReqDTO {
public class CapacityOrderQueryReqDTO {
private String location;
private String address;
private String brand;
......
......@@ -7,7 +7,7 @@ import java.util.List;
@Data
@Accessors(chain = true)
public class CapacityQueryRespDTO {
public class CapacityQueryOrderRespDTO {
private String beginDate;
private String endDate;
private String remark;
......
package com.alibaba.cloud.integration.order.dto;
@lombok.Data
public class CapacityStatQueryReqDTO {
private String beginDate;
private String endDate;
/**
* cluster/branch/group
*/
private String levelType;
/**
* clusterId/branchId/groupId
*/
private String levelValue;
private Integer page;
private Integer pageSize;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.experimental.Accessors;
import java.util.List;
@lombok.Data
@Accessors(chain = true)
public class CapacityStatQueryRespDTO {
private List<?> content;
private String levelType;
private long pageCurrent;
private long pages;
private long pageSize;
private long total;
@lombok.Data
@Accessors(chain = true)
public static class Content {
private long capAdjust;
private long capTotal;
private long capUsed;
private String createTime;
private String date;
private long engineerNum;
private String groupName;
private String layer;
private String teamName;
}
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import javax.persistence.*;
import java.util.Date;
@Data
@Entity
@Table(name="capacity_org_stat")
public class CapacityOrgStatEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 日期
*/
private String workday;
/**
* 类别-分部、小组、工作队
*/
private String type;
/**
* 组织id
*/
private String orgId;
/**
* 技能标签(辅助展示)
*/
private String layer;
/**
* 技术员数量
*/
private Integer engineerCount;
/**
* 总容量
*/
private Integer capTotal;
/**
* 已占容量
*/
private Integer capUsedTotal;
/**
* 剩余可约容量
*/
private Integer capLeft;
/**
* 已约单量
*/
private Integer orderCount;
/**
* 备注
*/
private String memo;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
......@@ -6,11 +6,6 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @description 容量-工作队时间段容量
* @author zhengkai.blog.csdn.net
* @date 2023-05-15
*/
@Entity
@Data
@Table(name = "capacity_team_stat")
......
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityOrderQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityStatQueryReqDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
public interface CapacityQueryService {
......@@ -12,5 +13,7 @@ public interface CapacityQueryService {
* @return
* @throws JsonProcessingException
*/
Result<?> getOneCapacityData(CapacityQueryReqDTO capacityQueryReqDTO);
Result<?> getOneCapacityData(CapacityOrderQueryReqDTO capacityQueryReqDTO);
Result<?> getTeamStatData(CapacityStatQueryReqDTO capacityStatQueryReqDTO);
}
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.CapacityTeamStatDao;
import com.alibaba.cloud.integration.order.dao.MapBlockInfoDao;
import com.alibaba.cloud.integration.order.dao.ProductCategoryDao;
import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.CapacityQueryRespDTO;
import com.alibaba.cloud.integration.order.dao.*;
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.service.CapacityQueryService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
......@@ -33,25 +38,68 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
private CapacityTeamStatDao capacityTeamStatDao;
@Autowired
private CapacityOrgStatDao capacityOrgStatDao;
@Autowired
private ProductCategoryDao productCategoryDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private OrgTeamDao orgTeamDao;
@Override
public Result<?> getOneCapacityData(CapacityQueryReqDTO reqDTO) {
public Result<?> getOneCapacityData(CapacityOrderQueryReqDTO reqDTO) {
/*
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/
String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
String teamId = getTeamByLayer(reqDTO.getLocation(), reqDTO.getAddress(), layer);
CapacityQueryRespDTO capacityQueryRespDTO = new CapacityQueryRespDTO();
CapacityQueryOrderRespDTO capacityQueryRespDTO = new CapacityQueryOrderRespDTO();
capacityQueryRespDTO.setBeginDate(capacityQueryRespDTO.getBeginDate()).setEndDate(reqDTO.getEndDate());
capacityQueryRespDTO.setCalendar(getTimeRangeByTeamSkill(teamId, reqDTO.getSkill(), reqDTO.getBeginDate(), reqDTO.getEndDate()));
capacityQueryRespDTO.setRemark(String.format("%s-%s", teamId, layer));
return Result.success(capacityQueryRespDTO);
}
@Override
public Result<?> getTeamStatData(CapacityStatQueryReqDTO capacityStatQueryReqDTO) {
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);
} else {
stats = capacityTeamStatDao.findByTeamIdAndWorkdayBetween(capacityStatQueryReqDTO.getLevelValue(), capacityStatQueryReqDTO.getBeginDate(), capacityStatQueryReqDTO.getEndDate(), pageable);
}
CapacityStatQueryRespDTO data = new CapacityStatQueryRespDTO();
data.setLevelType(capacityStatQueryReqDTO.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) {
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 {
CapacityTeamStatEntity e = (CapacityTeamStatEntity) item;
// capacity_team_stat表中的team_id,直接就是字符串
content.setDate(e.getWorkday()).setLayer(e.getLayer()).setTeamName(e.getTeamId())
.setCapTotal(e.getCapTotal()).setCapUsed(e.getCapUsed()).setCapAdjust(e.getCapAdjust()).setEngineerNum(e.getEngineerCount()).setCreateTime(e.getCreateTime().toString());
}
contents.add(content);
}
data.setContent(contents);
return Result.success(data);
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
......@@ -145,18 +193,18 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
* @param endDate
* @return
*/
private List<CapacityQueryRespDTO.CalendarDTO> getTimeRangeByTeamSkill(String teamId, String layer, String beginDate, String endDate) {
Map<String, CapacityQueryRespDTO.CalendarDTO> dayMaps = new HashMap<>();
private List<CapacityQueryOrderRespDTO.CalendarDTO> getTimeRangeByTeamSkill(String teamId, String layer, String beginDate, String endDate) {
Map<String, CapacityQueryOrderRespDTO.CalendarDTO> dayMaps = new HashMap<>();
List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndLayerAndWorkdayBetween(teamId, layer, beginDate, endDate);
for (CapacityTeamStatEntity e : capacityTeamStatEntityList) {
CapacityQueryRespDTO.TimeDTO timeDTO = new CapacityQueryRespDTO.TimeDTO();
CapacityQueryOrderRespDTO.TimeDTO timeDTO = new CapacityQueryOrderRespDTO.TimeDTO();
timeDTO.setType(getSpanType(e.getCapLeft(), e.getCapTotal()));
Object[] timeSpans = getTimeSpanInfo(e.getWorkday(), e.getTimeSpan(), e.getTimeSpanDetail());
timeDTO.setText((String) timeSpans[0]);
timeDTO.setBegin((String) timeSpans[1]);
timeDTO.setEnd((String) timeSpans[2]);
if (!dayMaps.containsKey(e.getWorkday())) {
CapacityQueryRespDTO.CalendarDTO calendarDTO = new CapacityQueryRespDTO.CalendarDTO();
CapacityQueryOrderRespDTO.CalendarDTO calendarDTO = new CapacityQueryOrderRespDTO.CalendarDTO();
calendarDTO.setDate(e.getWorkday());
calendarDTO.setWeek(getWeekday(e.getWorkday()));
dayMaps.put(e.getWorkday(), calendarDTO);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!