package com.gk.hotwork.specialWork.service.impl;
|
|
|
import com.gk.hotwork.Domain.Enum.ResultCodes;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.Vo.ResultVO;
|
import com.gk.hotwork.Service.Middle.AccountDepartmentService;
|
import com.gk.hotwork.specialWork.entity.WorkApplyCountDO;
|
import com.gk.hotwork.specialWork.enums.WorkTypeEnum;
|
import com.gk.hotwork.specialWork.model.dto.resp.DepRPCRespDTO;
|
import com.gk.hotwork.specialWork.model.dto.resp.WorkDepStatisticRespDTO;
|
import com.gk.hotwork.specialWork.model.dto.resp.WorkTypeStatisticRespDTO;
|
import com.gk.hotwork.specialWork.service.WorkStatisticService;
|
import com.gk.hotwork.specialWork.service.baseService.WorkApplyInfoService;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service("WorkStatisticService")
|
public class WorkStatisticServiceImpl implements WorkStatisticService {
|
@Autowired
|
private WorkApplyInfoService workApplyInfoService;
|
|
@Autowired
|
private AccountDepartmentService accountDepartmentService;
|
@Override
|
public ResultVO<List<WorkDepStatisticRespDTO>> getWorkApplyCountByDep() {
|
//获取所有部门
|
List<DepRPCRespDTO> depList = getDepList();
|
//统计各部门每种作业数量
|
List<WorkApplyCountDO> workApplyCountDOList = workApplyInfoService.getWorkApplyCountByDep();
|
List<WorkDepStatisticRespDTO> respDTOList = new ArrayList<>();
|
//循环部门
|
for(DepRPCRespDTO dep:depList){
|
WorkDepStatisticRespDTO respDTO = new WorkDepStatisticRespDTO();
|
respDTO.setDepId(dep.getDepId());
|
respDTO.setDepName(dep.getDepName());
|
//获取该部门下的作业数量
|
List<WorkApplyCountDO> selectDepList = workApplyCountDOList
|
.stream()
|
.filter(coutDo -> coutDo.getDepId().equals(dep.getDepId()))
|
.collect(Collectors.toList());
|
List<WorkTypeStatisticRespDTO> typeStatisticRespDTOS = new ArrayList<>();
|
//声明变量 部门总数量
|
int totalCount = 0;
|
//循环作业类型
|
for(WorkTypeEnum workTypeEnum:WorkTypeEnum.values()){
|
WorkTypeStatisticRespDTO typeStatisticRespDTO = new WorkTypeStatisticRespDTO();
|
typeStatisticRespDTO.setWorkType(workTypeEnum.getType());
|
typeStatisticRespDTO.setWorkTypeName(workTypeEnum.getName());
|
//获取该类型下的数据
|
List<WorkApplyCountDO> selectTypeList = selectDepList
|
.stream()
|
.filter(coutDo -> coutDo.getWorkType().equals(workTypeEnum.getType()))
|
.collect(Collectors.toList());
|
if(selectTypeList.size()>0){
|
typeStatisticRespDTO.setCount(selectTypeList.get(0).getCount());
|
totalCount += selectTypeList.get(0).getCount();
|
}else{
|
typeStatisticRespDTO.setCount(0);
|
}
|
typeStatisticRespDTOS.add(typeStatisticRespDTO);
|
}
|
respDTO.setTotalCount(totalCount);
|
respDTO.setTypeList(typeStatisticRespDTOS);
|
respDTOList.add(respDTO);
|
//如果有子级
|
List<DepRPCRespDTO> children = dep.getChildren();
|
if(!CollectionUtils.isEmpty(children)){
|
traverseChildren(children,workApplyCountDOList,respDTOList);
|
}
|
}
|
return new ResultVO<>(ResultCodes.OK,respDTOList);
|
}
|
|
private void traverseChildren(List<DepRPCRespDTO> depList, List<WorkApplyCountDO> workApplyCountDOList, List<WorkDepStatisticRespDTO> respDTOList) {
|
for(DepRPCRespDTO dep:depList){
|
WorkDepStatisticRespDTO respDTO = new WorkDepStatisticRespDTO();
|
respDTO.setDepId(dep.getDepId());
|
respDTO.setDepName(dep.getDepName());
|
//获取该部门下的作业数量
|
List<WorkApplyCountDO> selectDepList = workApplyCountDOList
|
.stream()
|
.filter(coutDo -> coutDo.getDepId().equals(dep.getDepId()))
|
.collect(Collectors.toList());
|
List<WorkTypeStatisticRespDTO> typeStatisticRespDTOS = new ArrayList<>();
|
//声明变量 部门总数量
|
int totalCount = 0;
|
//循环作业类型
|
for(WorkTypeEnum workTypeEnum:WorkTypeEnum.values()){
|
WorkTypeStatisticRespDTO typeStatisticRespDTO = new WorkTypeStatisticRespDTO();
|
typeStatisticRespDTO.setWorkType(workTypeEnum.getType());
|
typeStatisticRespDTO.setWorkTypeName(workTypeEnum.getName());
|
//获取该类型下的数据
|
List<WorkApplyCountDO> selectTypeList = selectDepList
|
.stream()
|
.filter(coutDo -> coutDo.getWorkType().equals(workTypeEnum.getType()))
|
.collect(Collectors.toList());
|
if(selectTypeList.size()>0){
|
typeStatisticRespDTO.setCount(selectTypeList.get(0).getCount());
|
totalCount += selectTypeList.get(0).getCount();
|
}else{
|
typeStatisticRespDTO.setCount(0);
|
}
|
typeStatisticRespDTOS.add(typeStatisticRespDTO);
|
}
|
respDTO.setTotalCount(totalCount);
|
respDTO.setTypeList(typeStatisticRespDTOS);
|
respDTOList.add(respDTO);
|
//如果有子级
|
List<DepRPCRespDTO> children = dep.getChildren();
|
if(!CollectionUtils.isEmpty(children)){
|
traverseChildren(children,workApplyCountDOList,respDTOList);
|
}
|
}
|
}
|
|
public List<DepRPCRespDTO> getDepList(){
|
List<DepRPCRespDTO> depList = new ArrayList<>();
|
try{
|
ResultVO<List<DepRPCRespDTO>> listResultVO = accountDepartmentService.depList();
|
if (listResultVO != null && listResultVO.getCode().equals(ResultCodes.OK.getCode())) {
|
if (listResultVO.getData() != null) {
|
depList = (List<DepRPCRespDTO>) listResultVO.getData();
|
}else{
|
throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
|
}
|
} else {
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
|
}catch (Exception e){
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
return depList;
|
}
|
}
|