| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.IntStream; |
| | | |
| | |
| | | @Override |
| | | public List<StatisticsEventsVO.ArithmeticVO> arithmeticEvent(Integer streetId, String beginTime, String endTime) { |
| | | List<StatisticsEventsVO.ArithmeticVO> list = apiDataMapper.arithmeticEvent(streetId, beginTime, endTime); |
| | | list.add(new StatisticsEventsVO.ArithmeticVO("店外经营", 0, 0.0)); |
| | | list.add(new StatisticsEventsVO.ArithmeticVO("沿街晾晒", 0, 0.0)); |
| | | list.add(new StatisticsEventsVO.ArithmeticVO("无照经营游商", 0, 0.0)); |
| | | list.add(new StatisticsEventsVO.ArithmeticVO("违规撑伞", 0, 0.0)); |
| | | List<String> dic = Arrays.asList("无照经营游商", "占道经营", "店外经营", "非机动车乱停放", "违规撑伞", "沿街晾挂", "机动车乱停放", "群发性事件"); |
| | | while (list.size() < 8) { |
| | | for (int i = 0; i < dic.size(); i++) { |
| | | int finalI = i; |
| | | long count = list.stream().filter(o -> o.getName().equals(dic.get(finalI))).count(); |
| | | if (count == 0) { |
| | | list.add(new StatisticsEventsVO.ArithmeticVO(dic.get(finalI), 0, 0.0)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // list.add(new StatisticsEventsVO.ArithmeticVO("店外经营", 0, 0.0)); |
| | | // list.add(new StatisticsEventsVO.ArithmeticVO("沿街晾晒", 0, 0.0)); |
| | | // list.add(new StatisticsEventsVO.ArithmeticVO("无照经营游商", 0, 0.0)); |
| | | // list.add(new StatisticsEventsVO.ArithmeticVO("违规撑伞", 0, 0.0)); |
| | | Integer all = list.stream().flatMapToInt(o -> IntStream.of(o.getCount())).sum(); |
| | | list.stream().forEach(o -> { |
| | | o.setRatio(new BigDecimal(((double) o.getCount() / (double) all)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | o.setRatio(new BigDecimal(((double) o.getCount() / (double) all)).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | }); |
| | | return list; |
| | | } |