| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.dto.CostStatisticsDto; |
| | | import com.yuanchu.mom.mapper.InsOrderMapper; |
| | | import com.yuanchu.mom.mapper.InsProductMapper; |
| | | import com.yuanchu.mom.mapper.InsProductUserMapper; |
| | | import com.yuanchu.mom.pojo.InsOrder; |
| | | import com.yuanchu.mom.pojo.InsProduct; |
| | | import com.yuanchu.mom.pojo.InsProductUser; |
| | | import com.yuanchu.mom.service.ReportService; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ReportServiceImpl implements ReportService { |
| | | |
| | | private InsOrderMapper insOrderMapper; |
| | | private InsProductUserMapper insProductUserMapper; |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | //æ¯æ¥ä¸å¡ç»è®¡ |
| | | @Override |
| | | public Map<String, Object> businessStatisticsByDay() { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | /*任塿¥æ¶*/ |
| | | //仿¥ä»»å¡æ¥æ¶ |
| | | Long receive = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 1).apply("DATE(create_time) = CURDATE()")); |
| | | map.put("RECEIVE", receive); |
| | | //æ¨æ¥ä»»å¡æ¥æ¶ |
| | | Long received = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 1).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY")); |
| | | received = received == 0 ? 1 : received; |
| | | //æ¯ä¾=(ä»å¤©-æ¨å¤©)/æ¨å¤© |
| | | BigDecimal ratio = new BigDecimal(receive - received).divide(new BigDecimal(received), 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("RECEIVE_RATIO", ratio); |
| | | |
| | | /*ä»»å¡å·²å®æ*/ |
| | | //仿¥ä»»å¡å®æ |
| | | Long finishe = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 4).apply("DATE(create_time) = CURDATE()")); |
| | | map.put("FINISHE", finishe); |
| | | //æ¨æ¥ä»»å¡å®æ |
| | | Long finished = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 4).apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY")); |
| | | finished = finished == 0 ? 1 : finished; |
| | | //ä»»å¡å®ææ¯ä¾=(ä»å¤©-æ¨å¤©)/æ¨å¤© |
| | | BigDecimal finishedRatio = new BigDecimal(finishe - finished).divide(new BigDecimal(finished), 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("FINISHE_RATIO", finishedRatio); |
| | | |
| | | /*ä»»å¡å©ä½*/ |
| | | //仿¥ä»»å¡å©ä½ |
| | | long surplus = receive - finishe; |
| | | map.put("SURPLUS", surplus); |
| | | //æ¨æ¥ä»»å¡å©ä½ |
| | | long surplused = received - finished; |
| | | surplused = surplused == 0 ? 1 : surplused; |
| | | //å©ä½æ¯ä¾=(ä»å¤©-æ¨å¤©)/æ¨å¤© |
| | | BigDecimal surplusRatio = new BigDecimal(surplus - surplused).divide(new BigDecimal(surplused), 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("SURPLUS_RATIO", surplusRatio); |
| | | |
| | | /*æ£æµè´¹ç¨*/ |
| | | //仿¥æ£æµè´¹ç¨ |
| | | QueryWrapper<CostStatisticsDto> costStatisticsDtoQueryWrappers = new QueryWrapper<>(); |
| | | costStatisticsDtoQueryWrappers.eq("create_time", LocalDateTime.now()); |
| | | IPage<CostStatisticsDto> page = new Page<>(); |
| | | page.setSize(-1); |
| | | page.setCurrent(-1); |
| | | IPage<CostStatisticsDto> iPage = insOrderMapper.selectCostStatistics(page, costStatisticsDtoQueryWrappers); |
| | | BigDecimal price = BigDecimal.ZERO; |
| | | for (CostStatisticsDto record : iPage.getRecords()) { |
| | | price.add(record.getPrice()); |
| | | } |
| | | map.put("PRICE", price); |
| | | //æ¨æ¥æ£æµè´¹ç¨ |
| | | QueryWrapper<CostStatisticsDto> costWrappers = new QueryWrapper<>(); |
| | | costWrappers.eq("create_time", LocalDateTime.now().minusDays(1)); |
| | | IPage<CostStatisticsDto> dtoIPage = insOrderMapper.selectCostStatistics(page, costWrappers); |
| | | BigDecimal priced = BigDecimal.ZERO; |
| | | for (CostStatisticsDto record : dtoIPage.getRecords()) { |
| | | priced.add(record.getPrice()); |
| | | } |
| | | priced = priced.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : priced; |
| | | //æ¯ä¾=(仿¥-æ¨æ¥)/æ¨æ¥ |
| | | BigDecimal priceRatio = (price.subtract(priced)).divide(priced, 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("PRICE_RATIO", priceRatio); |
| | | |
| | | /*æ£æµå·¥æ¶*/ |
| | | //仿¥æ£æµå·¥æ¶ |
| | | Double cost = 0.0; |
| | | for (CostStatisticsDto record : iPage.getRecords()) { |
| | | cost += record.getCost(); |
| | | } |
| | | map.put("COST", cost); |
| | | //æ¨æ¥æ£æµå·¥æ¶ |
| | | Double costed = 0.0; |
| | | for (CostStatisticsDto record : dtoIPage.getRecords()) { |
| | | costed += record.getCost(); |
| | | } |
| | | costed = costed == 0 ? 1 : costed; |
| | | //æ¯ä¾=(仿¥-æ¨æ¥)/æ¨æ¥ |
| | | BigDecimal costRatio = new BigDecimal(cost - costed).divide(new BigDecimal(costed), 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("COST_RATIO", costRatio); |
| | | |
| | | |
| | | /*æ£æµäººå*/ |
| | | //仿¥æ£æµäººå |
| | | Long person = insProductUserMapper.selectCount(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE()")); |
| | | map.put("PERSON", person); |
| | | //æ¨æ¥æ£æµäººå |
| | | Long persons = insProductUserMapper.selectCount(Wrappers.<InsProductUser>lambdaQuery().apply("DATE(create_time) = CURDATE() - INTERVAL 1 DAY")); |
| | | persons = persons == 0 ? 1 : persons; |
| | | //æ¯ä¾=(ä»å¤©-æ¨å¤©)/æ¨å¤© |
| | | BigDecimal personRatio = new BigDecimal(person - persons).divide(new BigDecimal(persons), 2, BigDecimal.ROUND_HALF_UP); |
| | | map.put("PERSON_RATIO", personRatio); |
| | | |
| | | /*è¿åæ¥ä»»å¡æ¥æ¶éä¸å®æé*/ |
| | | //è·åè¿åæ¥çæ¨ªåæ |
| | | LocalDate currentDate = LocalDate.now(); |
| | | List<LocalDate> lastTenDays = new ArrayList<>(); |
| | | List<Long> receTenDays = new ArrayList<>(); |
| | | List<Long> finTenDays = new ArrayList<>(); |
| | | for (int i = 9; i > -1; i--) { |
| | | lastTenDays.add(currentDate.minusDays(i)); |
| | | receTenDays.add(insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 1).apply("DATE(create_time) = CURDATE() - INTERVAL " + i + " DAY"))); |
| | | finTenDays.add(insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getState, 4).apply("DATE(create_time) = CURDATE() - INTERVAL " + i + " DAY"))); |
| | | } |
| | | map.put("DAYS", lastTenDays); |
| | | map.put("RECETENDAYS", receTenDays); |
| | | map.put("FINISHTENDAYS", finTenDays); |
| | | return map; |
| | | } |
| | | |
| | | //æ£æµé¡¹ç®ç»è®¡ |
| | | @Override |
| | | public Map<String, Object> testProductByDay() { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | /*é¡¹ç®æ¥æ¶*/ |
| | | //仿¥é¡¹ç®æ¥æ¶é |
| | | Long receive = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).apply("DATE(create_time) = CURDATE()")); |
| | | /*项ç®å®æ*/ |
| | | /*项ç®å©ä½*/ |
| | | /*仿¥é¡¹ç®åæ ¼ç*/ |
| | | /*仿¥é¡¹ç®å®æç*/ |
| | | /*仿¥é¡¹ç®å»¶æç*/ |
| | | /*è¿åæ¥çé¡¹ç®æ¥æ¶éä¸å®æé*/ |
| | | return map; |
| | | } |
| | | } |