| | |
| | | import com.gkhy.hazmat.common.utils.SecurityUtils; |
| | | import com.gkhy.hazmat.common.utils.StringUtils; |
| | | import com.gkhy.hazmat.system.domain.*; |
| | | import com.gkhy.hazmat.system.domain.vo.HzCompanyMessage; |
| | | import com.gkhy.hazmat.system.domain.vo.HzEntryRecordVO; |
| | | import com.gkhy.hazmat.system.domain.vo.HzHazmatUseVO; |
| | | import com.gkhy.hazmat.system.domain.vo.HzHomeDataVO; |
| | |
| | | private HzWarningMapper warningMapper; |
| | | |
| | | @Override |
| | | public List<HzEntryRecordVO> entryStatic() { |
| | | public List<HzEntryRecordVO> entryStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | Date currentDate=new Date(); |
| | | DateTime endTime = DateUtil.endOfDay(currentDate); |
| | |
| | | dayEntryRecordList.add(entryRecordVO); |
| | | startTime=DateUtil.offsetDay(startTime,1); |
| | | } |
| | | List<HzEntryRecordVO> entryRecordVOList= entryRecordMapper.entryCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | //todo |
| | | List<HzEntryRecordVO> entryRecordVOList= entryRecordMapper.entryCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | if(!entryRecordVOList.isEmpty()) { |
| | | Map<String, HzEntryRecordVO> resMap = entryRecordVOList.stream().collect(Collectors.toMap(item -> item.getMonth()+"_"+item.getDay(), item -> item)); |
| | | for (HzEntryRecordVO er : dayEntryRecordList) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HzEntryRecordVO> useEverydayStatic() { |
| | | public List<HzEntryRecordVO> useEverydayStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | Date currentDate=new Date(); |
| | |
| | | dayEntryRecordList.add(entryRecordVO); |
| | | startTime=DateUtil.offsetDay(startTime,1); |
| | | } |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | List<HzEntryRecordVO> entryRecordVOList= hazmatMapper.useCountEverydayStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | List<HzEntryRecordVO> entryRecordVOList= hazmatMapper.useCountEverydayStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!entryRecordVOList.isEmpty()) { |
| | | Map<String, HzEntryRecordVO> resMap = entryRecordVOList.stream().collect(Collectors.toMap(item -> item.getDay(), item -> item)); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HzHazmatUseVO> maxUseStatic() { |
| | | public List<HzHazmatUseVO> maxUseStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | |
| | |
| | | DateTime startTime = DateUtil.beginOfDay(DateUtil.offsetDay(currentDate, -6)); |
| | | String startDate= DateUtil.format(startTime, DatePattern.NORM_DATETIME_FORMAT); |
| | | String endDate=DateUtil.format(endTime,DatePattern.NORM_DATETIME_FORMAT); |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.maxUseCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.maxUseCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!hazmatUseVOList.isEmpty()) { |
| | | List<Long> basicIds = hazmatUseVOList.stream().map(HzHazmatUseVO::getBasicId).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public HzHomeDataVO homeDataStatistic() { |
| | | public HzHomeDataVO homeDataStatistic(Long companyid) { |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | Long companyId=currentUser.getCompanyId(); |
| | | Long companyId= null; |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | companyId = companyid; |
| | | }else { |
| | | companyId = currentUser.getCompanyId(); |
| | | } |
| | | Integer warehouseCount= Math.toIntExact(warehouseMapper.selectCount(Wrappers.<HzWarehouse>lambdaQuery() |
| | | .eq(true, HzWarehouse::getDelFlag, 0) |
| | | .eq(companyId!=null,HzWarehouse::getCompanyId,companyId))); |
| | |
| | | stateList.add(HazmatStatusEnum.USED.getCode()); |
| | | stateList.add(HazmatStatusEnum.DISCARD.getCode()); |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | Integer hazmatCount= Math.toIntExact(hazmatMapper.selectCount(Wrappers.<HzHazmat>lambdaQuery() |
| | | .notIn(true, HzHazmat::getState, stateList) |
| | | .eq(companyId!=null,HzHazmat::getCompanyId,companyId))); |
| | |
| | | |
| | | |
| | | @Override |
| | | public CommonPage useStatic(String startTime, String endTime) { |
| | | public CommonPage useStatic(String startTime, String endTime,Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | |
| | |
| | | throw new ApiException("只能查询90天以内数据"); |
| | | } |
| | | } |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | PageUtils.startPage(); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.useCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.useCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!hazmatUseVOList.isEmpty()) { |
| | | List<Long> basicIds = hazmatUseVOList.stream().map(HzHazmatUseVO::getBasicId).collect(Collectors.toList()); |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<HzEntryRecordVO> dayUseStatistic(Long companyId) { |
| | | SysUser currentUser = SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | Date currentDate = new Date(); |
| | | |
| | | // 设置当天的8点作为开始时间,20点作为结束时间 |
| | | DateTime beginOfDay = DateUtil.beginOfDay(currentDate); // 当天零点 |
| | | |
| | | // 从零点偏移8小时得到8点,偏移20小时得到20点 |
| | | DateTime startTime = DateUtil.offsetHour(beginOfDay, 8); // 08:00:00 |
| | | DateTime endTime = DateUtil.offsetHour(beginOfDay, 21); // 20:00:00 |
| | | |
| | | String startDate = DateUtil.format(startTime, DatePattern.NORM_DATETIME_FORMAT); |
| | | String endDate = DateUtil.format(endTime, DatePattern.NORM_DATETIME_FORMAT); |
| | | |
| | | // 设置分表ID逻辑 |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())) { |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | } else { |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | |
| | | // 生成每小时的统计列表,初始count为0 |
| | | List<HzEntryRecordVO> hourEntryList = new ArrayList<>(); |
| | | DateTime currentHour = startTime; |
| | | Integer i = hazmatMapper.countTotal(currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | while (currentHour.isBefore(endTime)) { // 从8点开始到20点前,共12个小时 |
| | | String hour = DateUtil.format(currentHour, "HH"); // 两位小时格式,如08,09,...,19 |
| | | HzEntryRecordVO entryRecordVO = new HzEntryRecordVO(); |
| | | entryRecordVO.setHour(hour); |
| | | entryRecordVO.setCount(0); |
| | | entryRecordVO.setTotalCount(i); |
| | | hourEntryList.add(entryRecordVO); |
| | | currentHour = DateUtil.offsetHour(currentHour, 1); // 增加一小时 |
| | | } |
| | | // 查询数据库,按小时统计使用量 |
| | | List<HzEntryRecordVO> entryRecordVOList = hazmatMapper.useCountHourlyStatic(startDate, endDate, currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId() |
| | | ); |
| | | hourEntryList.get(0).setTotalCount(i); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | // 将查询结果合并到初始化的每小时列表中 |
| | | if (!entryRecordVOList.isEmpty()) { |
| | | Map<String, HzEntryRecordVO> resMap = entryRecordVOList.stream() |
| | | .collect(Collectors.toMap(HzEntryRecordVO::getHour, item -> item)); |
| | | for (HzEntryRecordVO hourEntry : hourEntryList) { |
| | | HzEntryRecordVO matched = resMap.get(hourEntry.getHour()); |
| | | if (matched != null) { |
| | | hourEntry.setCount(matched.getCount()); |
| | | } |
| | | } |
| | | } |
| | | return hourEntryList; |
| | | } |
| | | |
| | | @Override |
| | | public List<HzCompanyMessage> companyMessage(Long type) { |
| | | return hazmatMapper.companyMessage(type); |
| | | } |
| | | |
| | | |
| | | private void setExcelResponseProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { |
| | | //设置内容类型 |
| | | response.setContentType("application/vnd.vnd.ms-excel"); |