| | |
| | | import com.yuanchu.limslaboratory.mapper.InspectionMaterialMapper; |
| | | import com.yuanchu.limslaboratory.mapper.QualificationRateStatisticsMapper; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.MapHandlerDto; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.SelectProjectByCodeAndNameDto; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.SelectQualificationRateDto; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.SeriesDto; |
| | | import com.yuanchu.limslaboratory.pojo.ImInfo; |
| | | import com.yuanchu.limslaboratory.pojo.InspectionMaterial; |
| | | import com.yuanchu.limslaboratory.service.QualificationRateStatisticsService; |
| | | import com.yuanchu.limslaboratory.utils.ArrayListUtil; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.NumberFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | |
| | | @Resource |
| | | private InspectionMaterialMapper inspectionMaterialMapper; |
| | | |
| | | private static final List<String> TYPE_LIST =Arrays.asList("原材料","成品","委托品"); |
| | | private static final List<Integer> TYPE_INT_LIST =Arrays.asList(0,1,2); |
| | | @Resource |
| | | private QualificationRateStatisticsMapper qualificationRateStatisticsMapper; |
| | | |
| | |
| | | |
| | | @Override |
| | | public Map<String, Object> getTestSampleStatistics(SelectQualificationRateDto dto) { |
| | | System.out.println(dto); |
| | | return null; |
| | | Map<String, Object> mapResult = new HashMap<>(16); |
| | | List<Map<String, Object>> mapList = qualificationRateStatisticsMapper.selectTestSamp(dto); |
| | | if(mapList.size()<=0){ |
| | | mapResult.put("noData",false); |
| | | return mapResult; |
| | | } |
| | | mapResult.put("xAxis",TYPE_LIST); |
| | | List<Map<String, Object>>list=new ArrayList<>(); |
| | | Map<String, Object>mapPass=new HashMap<>(3); |
| | | mapPass.put("name","合格"); |
| | | mapPass.put("type","bar"); |
| | | Map<String, Object>mapNoPass=new HashMap<>(3); |
| | | mapNoPass.put("name","不合格"); |
| | | mapNoPass.put("type","bar"); |
| | | List<Integer>passInteger=new ArrayList<>(); |
| | | List<Integer>noPasInteger=new ArrayList<>(); |
| | | AtomicInteger integerPass = new AtomicInteger(0); |
| | | AtomicInteger integerNoPass = new AtomicInteger(0); |
| | | for (int i = 0; i < TYPE_INT_LIST.size(); i++) { |
| | | int finalI = i; |
| | | mapList.stream().filter(m->Objects.equals(String.valueOf(m.get("type")),String.valueOf(TYPE_INT_LIST.get(finalI)))) |
| | | .forEach(m->{ |
| | | if(Objects.equals(m.get("inspectionStatus"),0)){ |
| | | integerNoPass.incrementAndGet(); |
| | | } |
| | | if(Objects.equals(m.get("inspectionStatus"),1)){ |
| | | integerPass.incrementAndGet(); |
| | | } |
| | | }); |
| | | passInteger.add(integerPass.get()); |
| | | noPasInteger.add(integerNoPass.get()); |
| | | integerPass.set(0); |
| | | integerNoPass.set(0); |
| | | } |
| | | mapPass.put("data",passInteger); |
| | | mapNoPass.put("data",noPasInteger); |
| | | list.add(mapPass); |
| | | list.add(mapNoPass); |
| | | mapResult.put("series",list); |
| | | mapResult.put("noData",true); |
| | | return mapResult; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getSupplierNoPassStatistics(SelectQualificationRateDto dto) { |
| | | Map<String, Object> allMap = new HashMap<>(16); |
| | | List<Map<String, Object>> mapList = qualificationRateStatisticsMapper.selectSupplierByCondition(dto); |
| | | mapList.forEach(System.out::println); |
| | | System.out.println("================================="); |
| | | if(mapList.size()<=0){ |
| | | allMap.put("noData",false); |
| | | return allMap; |
| | | } |
| | | //去重取出供应商 |
| | | List<Map<String, Object>> supplierDistinct = ArrayListUtil.oneObjectsDistinctByProperty(MapHandlerDto::comparingBySupplier, mapList); |
| | | List<String> supplierList = new ArrayList<String>(); |
| | | supplierDistinct.forEach(l -> { |
| | | supplierList.add(String.valueOf(l.get("supplier"))); |
| | | }); |
| | | //x轴 |
| | | allMap.put("xAxis", supplierList); |
| | | List<SeriesDto>seriesDtoList=new ArrayList<SeriesDto>(2); |
| | | SeriesDto seriesDto2=new SeriesDto("不合格数量"); |
| | | SeriesDto seriesDto=new SeriesDto("合格数量"); |
| | | List<SeriesDto> seriesDtoList = new ArrayList<SeriesDto>(2); |
| | | //title |
| | | SeriesDto seriesDto = new SeriesDto("合格数量"); |
| | | SeriesDto seriesDto2 = new SeriesDto("不合格数量"); |
| | | // 取出对应合格数量不合格数量 |
| | | List<Long>pass=new ArrayList<>(); |
| | | List<Long>noPass=new ArrayList<>(); |
| | | AtomicLong integerPass=new AtomicLong(0L); |
| | | AtomicLong integerNoPass=new AtomicLong(0L); |
| | | List<Long> pass = new ArrayList<>(); |
| | | List<Long> noPass = new ArrayList<>(); |
| | | AtomicLong integerPass = new AtomicLong(0L); |
| | | AtomicLong integerNoPass = new AtomicLong(0L); |
| | | supplierList.forEach(s -> { |
| | | mapList.stream() |
| | | .filter(l -> Objects.equals(l.get("supplier"), s)) |
| | | .forEach(l -> { |
| | | if(Objects.equals(l.get("inspectionStatus"),1)){ |
| | | if (Objects.equals(l.get("inspectionStatus"), 1)) { |
| | | integerPass.incrementAndGet(); |
| | | }else { |
| | | } else if(Objects.equals(l.get("inspectionStatus"), 0)) { |
| | | integerNoPass.incrementAndGet(); |
| | | } |
| | | }); |
| | |
| | | integerNoPass.set(0L); |
| | | integerPass.set(0L); |
| | | }); |
| | | seriesDto.setData(pass); |
| | | seriesDto2.setData(noPass); |
| | | List<Double> percentPass = new ArrayList<>(); |
| | | List<Double> percentNoPass = new ArrayList<>(); |
| | | for (int i = 0; i < pass.size(); i++) { |
| | | long total = (pass.get(i) + noPass.get(i)); |
| | | double passNO = 0.00; |
| | | if (pass.get(i) != 0L) { |
| | | passNO = Double.parseDouble(getPercent(pass.get(i), total).replace("%", "")); |
| | | } |
| | | double noPassNO = 0.00; |
| | | if (noPass.get(i) != 0L) { |
| | | noPassNO = Double.parseDouble(getPercent(noPass.get(i), total).replace("%", "")); |
| | | } |
| | | percentPass.add(passNO); |
| | | percentNoPass.add(noPassNO); |
| | | } |
| | | seriesDto.setData(percentPass); |
| | | seriesDto2.setData(percentNoPass); |
| | | seriesDtoList.add(seriesDto); |
| | | seriesDtoList.add(seriesDto2); |
| | | System.out.println("数量=======>"); |
| | | System.out.println(seriesDtoList); |
| | | return null; |
| | | allMap.put("series", seriesDtoList); |
| | | allMap.put("noData",true); |
| | | return allMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getNoPassProjectStatistics(SelectQualificationRateDto dto) { |
| | | return null; |
| | | Map<String, Object> allMap = new HashMap<>(16); |
| | | List<ImInfo> imInfos = qualificationRateStatisticsMapper.selectProjectionsByCondition(dto); |
| | | if(imInfos.size()<=0){ |
| | | allMap.put("noData",false); |
| | | return allMap; |
| | | } |
| | | List<String>NameList = new ArrayList<>(); |
| | | List<SelectProjectByCodeAndNameDto>projectByCodeAndNameDtos=new ArrayList<>(); |
| | | imInfos.forEach(l->{ |
| | | NameList.add(l.getImCode()+"-"+l.getImName()); |
| | | projectByCodeAndNameDtos.add(new SelectProjectByCodeAndNameDto(l.getImCode(),l.getImName())); |
| | | }); |
| | | List<ImInfo> imInfosAll = qualificationRateStatisticsMapper.selectProjection(projectByCodeAndNameDtos,dto); |
| | | int total = imInfosAll.size(); |
| | | List<Integer>noPas=new ArrayList<>(); |
| | | AtomicInteger i=new AtomicInteger(0); |
| | | NameList.forEach(n->{ |
| | | imInfos.stream() |
| | | .filter(im-> Objects.equals(n,im.getImCode()+"-"+im.getImName())) |
| | | .forEach(im->{ |
| | | i.set(im.getIprInfos().size()); |
| | | }); |
| | | noPas.add(i.get()); |
| | | i.set(0); |
| | | }); |
| | | List<Map<String, Object>>doubleList=new ArrayList<>(); |
| | | for (int j = 0; j < noPas.size(); j++) { |
| | | Map<String, Object>map=new HashMap<>(); |
| | | map.put("name",NameList.get(j)); |
| | | map.put("value",Double.parseDouble(getPercent(noPas.get(j),total).replace("%",""))); |
| | | doubleList.add(map); |
| | | } |
| | | allMap.put("legend",NameList); |
| | | allMap.put("series",doubleList); |
| | | allMap.put("noData",true); |
| | | return allMap; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getSampleOptions() { |
| | | List<Map<String, Object>> sampleOptions = qualificationRateStatisticsMapper.getSampleOptions(); |
| | | //去重样品 |
| | | List<Map<String, Object>> sampleOptionsDistinct = ArrayListUtil.oneObjectsDistinctByProperty(MapHandlerDto::comparingByCode, sampleOptions); |
| | | sampleOptionsDistinct.forEach(System.out::println); |
| | | return sampleOptionsDistinct; |
| | | } |
| | | |
| | | } |
| | | public static String getPercent(long x, long y) { |
| | | double d1 = x * 1.0; |
| | | double d2 = y * 1.0; |
| | | NumberFormat percentInstance = NumberFormat.getPercentInstance(); |
| | | // 设置保留几位小数,这里设置的是保留两位小数 |
| | | percentInstance.setMinimumFractionDigits(2); |
| | | return percentInstance.format(d1 / d2); |
| | | } |
| | | } |