package cn.besteam.modules.report.biz; import cn.besteam.common.constant.CommonConstant; import cn.besteam.common.constant.DepartmentEnum; import cn.besteam.common.constant.MedicalWasteEnum; import cn.besteam.common.constant.MedicalWasteEnum.MedicalWasteAuditStatusEnum; import cn.besteam.common.util.DateUtil; import cn.besteam.modules.medical.dto.MwDataStatisticsDTO; import cn.besteam.modules.medical.entity.MwCollectRecord; import cn.besteam.modules.medical.entity.MwDataStatistics; import cn.besteam.modules.medical.mapper.MwDataStatisticsMapper; import cn.besteam.modules.medical.service.IMwCheckoutRecordItemService; import cn.besteam.modules.medical.service.IMwCheckoutRecordService; import cn.besteam.modules.medical.service.IMwCollectRecordService; import cn.besteam.modules.medical.service.IMwNoticeService; import cn.besteam.modules.medical.vo.MwCollectCollectTrajectoryParamVO; import cn.besteam.modules.report.vo.*; import cn.besteam.modules.shiro.authc.util.EnvUtils; import cn.besteam.modules.system.biz.SysDepartmentBiz; import cn.besteam.modules.system.entity.SysDepartment; import cn.besteam.modules.system.entity.SysDict; import cn.besteam.modules.system.entity.SysDictItem; import cn.besteam.modules.system.service.ISysDepartmentService; import cn.besteam.modules.system.service.ISysDictItemService; import cn.besteam.modules.system.service.ISysDictService; import cn.besteam.modules.system.util.MybatisParameterUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.google.common.collect.Lists; import com.sun.org.apache.bcel.internal.generic.NEWARRAY; import java.util.concurrent.CountDownLatch; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.text.ParseException; import java.util.*; import java.util.stream.Collectors; /** * 首页 */ @Service @Slf4j public class IndexBiz { @Autowired private IMwCheckoutRecordService mwCheckoutRecordService; @Autowired private IMwCheckoutRecordItemService mwCheckoutRecordItemService; @Autowired private ISysDictService sysDictService; @Autowired private ISysDictItemService sysDictItemService; @Autowired private ISysDepartmentService sysDepartmentService; @Autowired private IMwCollectRecordService mwCollectRecordService; @Autowired private MwDataStatisticsMapper mwDataStatisticsMapper; @Autowired private SysDepartmentBiz sysDepartmentBiz; @Autowired private IMwNoticeService mwNoticeService; /** * 指标卡 * * @return */ public IndexVO getIndex() { IndexVO vo = new IndexVO(); Date todayBegin = DateUtil.beginDate(new Date()); Date todayEnd = DateUtil.endDate(new Date()); List departmentIdList = getDepartmentList(); CountDownLatch latch = new CountDownLatch(5); new Thread(() -> { System.out.println("指标1开始执行"+Thread.currentThread().getName()); // 今日收集 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper()// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteAuditStatusEnum.PASS.getStatus())// .between(MwCollectRecord::getCreateTime, todayBegin, todayEnd); try { MybatisParameterUtils.cutInParameter(lambdaQueryWrapper, MwCollectRecord::getHospitalId, departmentIdList); } catch (Exception e) { throw new RuntimeException(e); } List todayCollectRecordList = mwCollectRecordService.list( lambdaQueryWrapper); vo.setMedicalWasteTodayCollect(todayCollectRecordList.stream().filter(item -> MedicalWasteEnum.getMedicalWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setBottleBagTodayCollect(todayCollectRecordList.stream().filter(item -> MedicalWasteEnum.getBottleBagTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setDangerousWasteTodayCollect(todayCollectRecordList.stream().filter(item -> MedicalWasteEnum.getDangerousWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); latch.countDown(); }).start(); new Thread(() -> { System.out.println("指标2开始执行"+Thread.currentThread().getName()); // 今日入库 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper()// .in(MwCollectRecord::getStatus, Arrays.asList( MedicalWasteEnum.MedicalWasteStatusEnum.STORE.getStatus(), MedicalWasteEnum.MedicalWasteStatusEnum.CHECKOUT.getStatus()))// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())// .between(MwCollectRecord::getStoreTime, todayBegin, todayEnd); try { MybatisParameterUtils.cutInParameter(lambdaQueryWrapper, MwCollectRecord::getHospitalId, departmentIdList); } catch (Exception e) { throw new RuntimeException(e); } List todayStoreRecordList = mwCollectRecordService.list( lambdaQueryWrapper); vo.setMedicalWasteTodayStore(todayStoreRecordList.stream().filter(item -> MedicalWasteEnum.getMedicalWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getStoreWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setBottleBagTodayStore(todayStoreRecordList.stream().filter(item -> MedicalWasteEnum.getBottleBagTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getStoreWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setDangerousWasteTodayStore(todayStoreRecordList.stream().filter(item -> MedicalWasteEnum.getDangerousWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getStoreWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); latch.countDown(); }).start(); new Thread(() -> { System.out.println("指标3始执行"+Thread.currentThread().getName()); // 今日出库 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper()// .eq(MwCollectRecord::getStatus, MedicalWasteEnum.MedicalWasteStatusEnum.CHECKOUT.getStatus())// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())// .between(MwCollectRecord::getCheckoutTime, todayBegin, todayEnd); try { MybatisParameterUtils.cutInParameter(lambdaQueryWrapper, MwCollectRecord::getHospitalId, departmentIdList); } catch (Exception e) { throw new RuntimeException(e); } List todayCheckoutRecordList = mwCollectRecordService.list( lambdaQueryWrapper); vo.setMedicalWasteTodayCheckout(todayCheckoutRecordList.stream().filter(item -> MedicalWasteEnum.getMedicalWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getCheckoutWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setBottleBagTodayCheckout(todayCheckoutRecordList.stream().filter(item -> MedicalWasteEnum.getBottleBagTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getCheckoutWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setDangerousWasteTodayCheckout(todayCheckoutRecordList.stream().filter(item -> MedicalWasteEnum.getDangerousWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getCheckoutWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); latch.countDown(); }).start(); new Thread(() -> { System.out.println("指标4开始执行"+Thread.currentThread().getName()); // 累计未入库 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper()// .eq(MwCollectRecord::getStatus, MedicalWasteEnum.MedicalWasteStatusEnum.COLLECT.getStatus())// .isNull(MwCollectRecord::getStoreTime)// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()); try { MybatisParameterUtils.cutInParameter(lambdaQueryWrapper, MwCollectRecord::getHospitalId, departmentIdList); } catch (Exception e) { throw new RuntimeException(e); } List nonStoreRecordList = mwCollectRecordService.list( lambdaQueryWrapper);// vo.setMedicalWasteTotalNonStore(nonStoreRecordList.stream().filter(item -> MedicalWasteEnum.getMedicalWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setBottleBagTotalNonStore(nonStoreRecordList.stream().filter(item -> MedicalWasteEnum.getBottleBagTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); vo.setDangerousWasteTotalNonStore(nonStoreRecordList.stream().filter(item -> MedicalWasteEnum.getDangerousWasteTypes().contains(item.getWasteTypeStr())).map(MwCollectRecord::getWeight) .reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); latch.countDown(); }).start(); new Thread(() -> { System.out.println("指标5开始执行" + Thread.currentThread().getName()); Double totalNonCheckout = mwCollectRecordService.getTotalNonCheckout(departmentIdList, MedicalWasteEnum.getMedicalWasteTypes()); vo.setMedicalWasteTotalNonCheckout(BigDecimal.valueOf(totalNonCheckout)); Double bottleBagTotalNonCheckout = mwCollectRecordService.getTotalNonCheckout(departmentIdList, MedicalWasteEnum.getBottleBagTypes()); vo.setBottleBagTotalNonCheckout(BigDecimal.valueOf(bottleBagTotalNonCheckout)); Double dangerousWasteTotalNonCheckout = mwCollectRecordService.getTotalNonCheckout(departmentIdList, MedicalWasteEnum.getDangerousWasteTypes()); vo.setDangerousWasteTotalNonCheckout(BigDecimal.valueOf(dangerousWasteTotalNonCheckout)); latch.countDown(); }).start(); try { latch.await(); return vo; } catch (InterruptedException e) { throw new RuntimeException(e); } } public IndexScheduleVO getIndexSchedule() { return mwNoticeService.getIndexSchedule(); } /** * 今日排行榜 * * @return */ public List getTodayRankStatistics(String startTime_,String endTime_) { Date startTime = DateUtil.beginDate(new Date()); if(startTime_!=null && startTime_!=""){ try { startTime = DateUtils.parseDate(startTime_,"yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } Date endTime = DateUtil.endDate(new Date()); if(endTime_!=null && endTime_!="") { try { endTime = DateUtils.parseDate(endTime_, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } List sysDepartmentList; SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId()); // 如果当前用户所属组织的类型为医院、部门、科室 ,则获取医院下的科室列表 if (!myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) { if (!myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { myDepartment = sysDepartmentService.getHospital(myDepartment.getParentId()); } sysDepartmentList = sysDepartmentService.list(new QueryWrapper()// .lambda()// .eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.OFFICE.getType())// .eq(SysDepartment::getIsWarehouse, 0)// .likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode())); if (CollectionUtils.isEmpty(sysDepartmentList)) { return new ArrayList<>(); } List voList = mwCollectRecordService.getOfficeRankStatistics(sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList()), startTime, endTime); Integer index=0; for(RankStatisticsVO rankStatisticsVO:voList){ index=index+1; rankStatisticsVO.setRank(index); rankStatisticsVO.setRanks(index); } return voList; } else {// 否则获取医院列表 sysDepartmentList = sysDepartmentService.list(new QueryWrapper()// .lambda()// .eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())// .likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode())); if (CollectionUtils.isEmpty(sysDepartmentList)) { return new ArrayList<>(); } IPage vo = mwCollectRecordService.getRankStatisticsList(1, 10, sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList()), startTime, endTime,null); for (int i = 0; i < vo.getRecords().size(); i++) { vo.getRecords().get(i).setKey(i); } List voList = vo.getRecords(); Integer index=0; for(RankStatisticsVO rankStatisticsVO:voList){ index=index+1; rankStatisticsVO.setRank(index); rankStatisticsVO.setRanks(index); } return voList; } } /** * 最近7日统计 * * @return */ public LastSevenDaysStatisticsVO getLastSevenDaysStatistics(String startTime_,String endTime_) { LastSevenDaysStatisticsVO vo = new LastSevenDaysStatisticsVO(); // List wasteTypeList = getWasteTypeList(); if (CollectionUtils.isEmpty(wasteTypeList)) { return vo; } Date startTime = DateUtils.addDays(DateUtil.beginDate(new Date()), -6); if(startTime_!=null){ try { startTime = DateUtils.parseDate(startTime_,"yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } Date endTime = DateUtil.endDate(new Date()); if(endTime_!=null) { try { endTime = DateUtils.parseDate(endTime_, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } // List sysDepartmentList; SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId()); // 获取医院列表 if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) { myDepartment = sysDepartmentService.getHospital(myDepartment.getParentId()); } sysDepartmentList = sysDepartmentService.list(new QueryWrapper()// .lambda()// .eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())// .likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode())); if (CollectionUtils.isEmpty(sysDepartmentList)) { return vo; } //最近7日的医废列表 List totalCollectRecordList = mwCollectRecordService.list(new QueryWrapper()// .lambda()// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())// .in(MwCollectRecord::getHospitalId, sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList()))// .between(MwCollectRecord::getCreateTime, startTime, endTime)); //医废类型统计 WasteTypeStatisticsVO wasteTypeStatisticsVO = new WasteTypeStatisticsVO(); wasteTypeStatisticsVO.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList())); List dataList = new ArrayList<>(); for (SysDictItem wasteType : wasteTypeList) { BigDecimal weight = totalCollectRecordList.stream().filter(e -> e.getWasteType().equals(wasteType.getId())).map(MwCollectRecord::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); dataList.add(WasteTypeStatisticsVO.InnerData.builder().name(wasteType.getItemText()).data(weight).build()); } wasteTypeStatisticsVO.setDataList(dataList); vo.setWasteTypeStatistics(wasteTypeStatisticsVO); //柱状图 List> source = new ArrayList<>(); source.add(Arrays.asList("product", "重量", "袋")); Date startTimeTemp = startTime; while (startTimeTemp.before(endTime)) { String key = DateUtil.format(startTimeTemp, "yyyy-MM-dd"); BigDecimal weight = totalCollectRecordList.stream().filter(e -> key.equals(DateUtil.format(e.getCreateTime(), "yyyy-MM-dd"))).map(MwCollectRecord::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); long count = totalCollectRecordList.stream().filter(e -> key.equals(DateUtil.format(e.getCreateTime(), "yyyy-MM-dd"))).count(); source.add(Arrays.asList(key, weight, count)); // startTimeTemp = DateUtils.addDays(startTimeTemp, 1); } vo.setSource(source); // return vo; } /** * 最近7日统计(小程序) * * @return */ public LastSevenDaysStatisticsVO getLastSevenDaysStatisticsX(String startTime_,String endTime_,Integer type) { LastSevenDaysStatisticsVO vo = new LastSevenDaysStatisticsVO(); // List wasteTypeList = getWasteTypeList(); if (CollectionUtils.isEmpty(wasteTypeList)) { return vo; } Date startTime = DateUtils.addDays(DateUtil.beginDate(new Date()), -6); if(startTime_!=null && startTime_!=""){ try { startTime = DateUtils.parseDate(startTime_,"yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } Date endTime = DateUtil.endDate(new Date()); if(endTime_!=null && endTime_!="") { try { endTime = DateUtils.parseDate(endTime_, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } List sysDepartmentList; SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId()); // 获取医院列表 if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) { myDepartment = sysDepartmentService.getHospital(myDepartment.getParentId()); } sysDepartmentList = sysDepartmentService.list(new QueryWrapper()// .lambda()// .eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())// .likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode())); if (CollectionUtils.isEmpty(sysDepartmentList)) { return vo; } if(type==1){ //最近7日的医废列表 List totalCollectRecordList = mwCollectRecordService.list(new QueryWrapper()// .lambda()// .eq(MwCollectRecord::getDelFlag, CommonConstant.DEL_FLAG_0)// .eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())// .in(MwCollectRecord::getHospitalId, sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList()))// .between(MwCollectRecord::getCreateTime, startTime, endTime)); //柱状图 List> source = new ArrayList<>(); source.add(Arrays.asList("product", "重量", "袋")); Date startTimeTemp = startTime; while (startTimeTemp.before(endTime)) { String key = DateUtil.format(startTimeTemp, "yyyy-MM-dd"); BigDecimal weight = totalCollectRecordList.stream().filter(e -> key.equals(DateUtil.format(e.getCreateTime(), "yyyy-MM-dd"))).map(MwCollectRecord::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); long count = totalCollectRecordList.stream().filter(e -> key.equals(DateUtil.format(e.getCreateTime(), "yyyy-MM-dd"))).count(); source.add(Arrays.asList(key, weight, count)); // startTimeTemp = DateUtils.addDays(startTimeTemp, 1); } vo.setSource(source); }else { MwCollectCollectTrajectoryParamVO trajectoryParamVO=new MwCollectCollectTrajectoryParamVO(); trajectoryParamVO.setHospitalIdList(sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList())); trajectoryParamVO.setStartTime(startTime); trajectoryParamVO.setEndTime(endTime); trajectoryParamVO.setDelFlag(CommonConstant.DEL_FLAG_0); trajectoryParamVO.setAuditStatus(MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()); List> totalCollectRecordList = mwCollectRecordService.getMedicalStatistics(trajectoryParamVO); List dateList=DateUtil.getMonthBetween(startTime_,endTime_); //柱状图 List> source = new ArrayList<>(); source.add(Arrays.asList("product", "重量", "袋")); for(String month : dateList){ String key =month; BigDecimal weight = new BigDecimal(0); long count=0l; for(Map mv:totalCollectRecordList){ if(month.equals(mv.get("month").toString())){ weight = new BigDecimal(mv.get("weights").toString()); count = Integer.valueOf(mv.get("couns").toString()); continue; } } source.add(Arrays.asList(key, weight, count)); } vo.setSource(source); } return vo; } /** * 获取所有医废类型 * * @return */ private List getWasteTypeList() { SysDict sysDict = sysDictService.getOne(new QueryWrapper().lambda().eq(SysDict::getDictCode, "MEDICAL_WASTE_TYPE")); if (sysDict == null) { return null; } //获取字典所有医废类型 return sysDictItemService.list(new QueryWrapper().lambda().eq(SysDictItem::getDictId, sysDict.getId())); } private List getDepartmentList() { List list = null; SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId()); if (myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.DEPARTMENT.getType()) || myDepartment.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) { SysDepartment hospital = sysDepartmentService.getHospital(myDepartment.getParentId()); list = Lists.newArrayList(hospital.getId()); } else { list = sysDepartmentService.getDeptIdListByTreeCode(myDepartment.getTreeCode()); } return list; } /** * 获取数据大屏 * * @return */ public MwDataStatisticsDTO getDataStatistics() { SysDepartment myDepartment = sysDepartmentService.getMyDepartment(EnvUtils.getUser().getId()); List sysDepartmentList = sysDepartmentService.list(new QueryWrapper().lambda().eq(SysDepartment::getParentId, myDepartment.getId()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()).orderByAsc(SysDepartment::getTreeCode)); String departmentIds_=""; if(sysDepartmentList!=null && sysDepartmentList.size()>0){ for(SysDepartment sysDepartment: sysDepartmentList){ departmentIds_+=sysDepartment.getId()+","; } } Integer type=1; if(myDepartment.getId()==-1){//平台数据 type=2; } List sysDepartmentDTOS=null; if(type==1){ sysDepartmentDTOS=mwDataStatisticsMapper.getDepartmentIds(myDepartment.getId()); }else if(type==2){ sysDepartmentDTOS=mwDataStatisticsMapper.getDepartmentIdsAll(myDepartment.getId()); } String departmentIds=""; if(sysDepartmentDTOS!=null && sysDepartmentDTOS.size()>0){ for(Integer id: sysDepartmentDTOS){ departmentIds+=id+","; } } MwDataStatisticsDTO mwDataStatistics=new MwDataStatisticsDTO(); if(departmentIds!=null && !departmentIds.equals("")){ departmentIds=departmentIds.substring(0,departmentIds.length()-1); List mwDataStatisticsList=mwDataStatisticsMapper.getDataStatisticsByParentIds(departmentIds,type);//=new MwDataStatistics();// Integer hospitals=0; BigDecimal totalWeight=new BigDecimal(0); Integer totalNumber=0; BigDecimal todayWeight=new BigDecimal(0); BigDecimal todayWeightPut=new BigDecimal(0); BigDecimal todayWeightOut=new BigDecimal(0); BigDecimal weightNotout=new BigDecimal(0); BigDecimal weightNotput=new BigDecimal(0); BigDecimal todayWeightNotout=new BigDecimal(0); BigDecimal todayWeightNotput=new BigDecimal(0); Integer warningWithout=0; Integer warningTimeoutPut=0; Integer warningTimeoutOut=0; Integer warningMissing=0; for(MwDataStatistics mwDataStatistics1:mwDataStatisticsList){ hospitals+=mwDataStatistics1.getHospitals(); totalNumber+=mwDataStatistics1.getTotalNumber(); warningWithout+=mwDataStatistics1.getWarningWithout(); warningTimeoutPut+=mwDataStatistics1.getWarningTimeoutPut(); warningTimeoutOut+=mwDataStatistics1.getWarningTimeoutOut(); warningMissing+=mwDataStatistics1.getWarningMissing(); totalWeight=totalWeight.add(mwDataStatistics1.getTotalWeight()); todayWeight=todayWeight.add(mwDataStatistics1.getTodayWeight()); todayWeightPut=todayWeightPut.add(mwDataStatistics1.getTodayWeightPut()); todayWeightOut=todayWeightOut.add(mwDataStatistics1.getTodayWeightOut()); weightNotout=weightNotout.add(mwDataStatistics1.getWeightNotout()); weightNotput=weightNotput.add(mwDataStatistics1.getWeightNotput()); todayWeightNotout=todayWeightNotout.add(mwDataStatistics1.getTodayWeightNotout()); todayWeightNotput=todayWeightNotput.add(mwDataStatistics1.getTodayWeightNotput()); } //最近七日数据列表 List dateList=DateUtil.getSevenDate();//最近七日日期数据 List> listSevendaysWeightAnalyse=new ArrayList<>(); List> listSevendaysWeightAnalyseOut=new ArrayList<>(); List> listSevendaysWeightAnalysePut=new ArrayList<>(); for(String date : dateList){ Map mapSevendaysWeightAnalyse=new HashMap<>(); Map mapSevendaysWeightAnalyseOut=new HashMap<>(); Map mapSevendaysWeightAnalysePut=new HashMap<>(); mapSevendaysWeightAnalyse.put("days",date); mapSevendaysWeightAnalyseOut.put("days",date); mapSevendaysWeightAnalysePut.put("days",date); Double sevendaysWeightAnalyseSum = 0d; Double sevendaysWeightAnalyseOutSum = 0d; Double sevendaysWeightAnalysePutSum = 0d; for(MwDataStatistics mwDataStatistics1:mwDataStatisticsList) { if (!"".equals(mwDataStatistics1.getSevendaysWeightAnalyse())) { JSONArray array = JSONArray.fromObject(mwDataStatistics1.getSevendaysWeightAnalyse()); for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); if (date.equals(jsonObject.get("days").toString()) || date == jsonObject.get("days").toString()) { sevendaysWeightAnalyseSum+=Double.valueOf(jsonObject.get("sums").toString()); continue; } } } if (!"".equals(mwDataStatistics1.getSevendaysWeightAnalyseOut())) { JSONArray array = JSONArray.fromObject(mwDataStatistics1.getSevendaysWeightAnalyseOut()); for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); if (date.equals(jsonObject.get("days").toString()) || date == jsonObject.get("days").toString()) { sevendaysWeightAnalyseOutSum+=Double.valueOf(jsonObject.get("sums").toString()); continue; } } } if (!"".equals(mwDataStatistics1.getSevendaysWeightAnalysePut())) { JSONArray array = JSONArray.fromObject(mwDataStatistics1.getSevendaysWeightAnalysePut()); for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); if (date.equals(jsonObject.get("days").toString()) || date == jsonObject.get("days").toString()) { sevendaysWeightAnalysePutSum+=Double.valueOf(jsonObject.get("sums").toString()); continue; } } } } mapSevendaysWeightAnalyse.put("weights",sevendaysWeightAnalyseSum); listSevendaysWeightAnalyse.add(mapSevendaysWeightAnalyse); mapSevendaysWeightAnalyseOut.put("weights",sevendaysWeightAnalyseOutSum); listSevendaysWeightAnalyseOut.add(mapSevendaysWeightAnalyseOut); mapSevendaysWeightAnalysePut.put("weights",sevendaysWeightAnalysePutSum); listSevendaysWeightAnalysePut.add(mapSevendaysWeightAnalysePut); } mwDataStatistics.setHospitals(hospitals); mwDataStatistics.setTotalWeight(totalWeight); mwDataStatistics.setTotalNumber(totalNumber); mwDataStatistics.setTodayWeight(todayWeight); mwDataStatistics.setTodayWeightPut(todayWeightPut); mwDataStatistics.setTodayWeightOut(todayWeightOut); mwDataStatistics.setWeightNotout(weightNotout); mwDataStatistics.setWeightNotput(weightNotput); mwDataStatistics.setWarningWithout(warningWithout); mwDataStatistics.setWarningTimeoutPut(warningTimeoutPut); mwDataStatistics.setWarningTimeoutOut(warningTimeoutOut); mwDataStatistics.setWarningMissing(warningMissing); mwDataStatistics.setSevendaysWeightAnalyse(listSevendaysWeightAnalyse); mwDataStatistics.setSevendaysWeightAnalysePut(listSevendaysWeightAnalysePut); mwDataStatistics.setSevendaysWeightAnalyseOut(listSevendaysWeightAnalyseOut); if(departmentIds_!=null && departmentIds_!=""){ departmentIds_=departmentIds_.substring(0,departmentIds_.length()-1); List> sevendaysWeightAnalyseList=mwDataStatisticsMapper.getTodayWeightAnalyse(departmentIds_,type,1); List> sevendaysWeightAnalysePutList=mwDataStatisticsMapper.getTodayWeightAnalyse(departmentIds_,type,2); List> sevendaysWeightAnalyseOutList=mwDataStatisticsMapper.getTodayWeightAnalyse(departmentIds_,type,3); mwDataStatistics.setTodayWeightAnalyse(sevendaysWeightAnalyseList); mwDataStatistics.setTodayWeightAnalyseNotput(sevendaysWeightAnalysePutList); mwDataStatistics.setTodayWeightAnalyseNotout(sevendaysWeightAnalyseOutList); } } return mwDataStatistics; } }