package com.gkhy.safePlatform.emergency.service.impl; import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.utils.BeanCopyUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.emergency.entity.*; import com.gkhy.safePlatform.emergency.model.dto.resp.*; import com.gkhy.safePlatform.emergency.query.EmergencyDrillExecuteCountQuery; import com.gkhy.safePlatform.emergency.service.EmergencyCountService; import com.gkhy.safePlatform.emergency.service.baseService.EmergencyDrillExecuteInfoService; import com.gkhy.safePlatform.emergency.utils.TimeUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.text.SimpleDateFormat; import java.util.*; @Service("emergencyCountService") public class EmergencyCountServiceImpl implements EmergencyCountService { @Autowired private EmergencyDrillExecuteInfoService emergencyDrillExecuteInfoService; @DubboReference(check = false) private AccountDepartmentService accountDepartmentService; @Override public ResultVO countEmergencyDrillExecute(EmergencyDrillExecuteCountQuery query) { EmergencyDrillExecuteCountRespDTO emergencyDrillExecuteCountRespDTO = new EmergencyDrillExecuteCountRespDTO(); // 根据最新的应急演练实施的创建时间与当前时间 获取间隔天数 Integer days = emergencyDrillExecuteInfoService.selectEmergencyDrillExecuteIntervalTime(); emergencyDrillExecuteCountRespDTO.setDays(days); // 根据时间类型(年/月),部门id 获取统计结果 List list = new ArrayList<>(); // 获取部门id集合 List deptIds = new ArrayList<>(); ResultVO> rpcResult = accountDepartmentService.listDepAndSubDepIds(query.getDeptId()); if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) { if (rpcResult.getData() != null) { deptIds = (List) rpcResult.getData(); } }else{ throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST); } // 获取时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); Date date = new Date(); int year = Integer.parseInt(sdf.format(date)); if (query.getType()==1){ // 月 String startTime = TimeUtils.getYearFirst(year); String endTime = TimeUtils.getYearLast(year); list = emergencyDrillExecuteInfoService.selectByMonthAndDept(startTime,endTime,deptIds); } if (query.getType()==2){ // 年 String startTime = TimeUtils.getYearFirst(year-10); String endTime = TimeUtils.getYearLast(year); list = emergencyDrillExecuteInfoService.selectByYearAndDept(startTime,endTime,deptIds); } if (!CollectionUtils.isEmpty(list)){ List dataList = BeanCopyUtils.copyBeanList(list,EmergencyDrillExecuteCountDataRespDTO.class); emergencyDrillExecuteCountRespDTO.setDataList(dataList); }else{ emergencyDrillExecuteCountRespDTO.setDataList(new ArrayList<>()); } return new ResultVO<>(ResultCodes.OK,emergencyDrillExecuteCountRespDTO); } }