| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.DataStatisticsQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api(tags = "数据统计") |
| | | @RestController |
| | | @RequestMapping("/t-crm-branch-area") |
| | | @RequestMapping("/data-statistics") |
| | | public class DataStatisticsController { |
| | | |
| | | private final TErpProcurementService erpProcurementService; |
| | | private final TokenService tokenService; |
| | | private final ISysUserService sysUserService; |
| | | private final TCrmSupplierService crmSupplierService; |
| | | private final TCrmClinicService crmClinicService; |
| | | private final TSysAppUserService sysAppUserService; |
| | | private final TCrmClinicPointsService crmClinicPointsService; |
| | | private final TSysOrderService sysOrderService; |
| | | |
| | | @Autowired |
| | | public DataStatisticsController(TErpProcurementService erpProcurementService, TokenService tokenService, ISysUserService sysUserService, TCrmSupplierService crmSupplierService, TCrmClinicService crmClinicService, TSysAppUserService sysAppUserService, TCrmClinicPointsService crmClinicPointsService, TSysOrderService sysOrderService) { |
| | | this.erpProcurementService = erpProcurementService; |
| | | this.tokenService = tokenService; |
| | | this.sysUserService = sysUserService; |
| | | this.crmSupplierService = crmSupplierService; |
| | | this.crmClinicService = crmClinicService; |
| | | this.sysAppUserService = sysAppUserService; |
| | | this.crmClinicPointsService = crmClinicPointsService; |
| | | this.sysOrderService = sysOrderService; |
| | | } |
| | | |
| | | /** |
| | | * 供应商采购统计 |
| | | */ |
| | | @ApiOperation(value = "供应商采购统计", notes = "orderTotal:总数;orderQuantity:订单数;orderMoney:订单金额;commissionMoney:分佣金额") |
| | | @PostMapping(value = "/supplierProcurementStatistics") |
| | | public R<Map<String, Object>> supplierProcurementStatistics(@Validated @RequestBody DataStatisticsQuery query) { |
| | | |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | String startTime = null; |
| | | String endTime = null; |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | startTime = LocalDate.now() + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 2: |
| | | startTime = LocalDate.now().minusDays(1) + " 00:00:00"; |
| | | endTime = LocalDate.now().minusDays(1) + " 23:59:59"; |
| | | break; |
| | | case 3: |
| | | startTime = LocalDate.now().minusDays(6) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 4: |
| | | startTime = LocalDate.now().minusMonths(5) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 5: |
| | | startTime = LocalDate.now().minusYears(1) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | } |
| | | |
| | | TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, userId)); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | |
| | | List<TErpProcurement> orderTotal = erpProcurementService.list(Wrappers.lambdaQuery(TErpProcurement.class) |
| | | .eq(TErpProcurement::getSupplierId, crmSupplier.getId()) |
| | | .in(TErpProcurement::getStatus, 3,4,5)); |
| | | map.put("orderTotal", orderTotal.size()); // 总数 |
| | | List<TErpProcurement> orderQuantity = erpProcurementService.list(Wrappers.lambdaQuery(TErpProcurement.class) |
| | | .eq(TErpProcurement::getSupplierId, crmSupplier.getId()) |
| | | .between(TErpProcurement::getPayTime, startTime, endTime) |
| | | .in(TErpProcurement::getStatus, 3,4,5)); |
| | | map.put("orderQuantity", orderQuantity.size()); // 订单数 |
| | | |
| | | if(CollectionUtils.isEmpty(orderTotal)){ |
| | | map.put("orderMoney", 0); // 订单金额 |
| | | map.put("commissionMoney", 0); // 分佣金额 |
| | | }else { |
| | | BigDecimal orderMoney = orderQuantity.stream().map(TErpProcurement::getPayMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); |
| | | map.put("orderMoney", orderMoney); |
| | | BigDecimal commissionMoney = orderQuantity.stream().map(TErpProcurement::getSupplierMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); |
| | | map.put("commissionMoney", commissionMoney); |
| | | } |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 供应商采购统计 |
| | | */ |
| | | @ApiOperation(value = "供应商最近额30天采购统计",notes = "supplierThirtyProcurementStatistics:订单,supplierThirtyMoneyProcurementStatistics:金额") |
| | | @PostMapping(value = "/supplierThirtyProcurementStatistics") |
| | | public R<Map<String,Object>> supplierThirtyProcurementStatistics() { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | Integer roleType = tokenService.getLoginUser().getUser().getRoleType(); |
| | | |
| | | String startTime = LocalDate.now().minusDays(29) + " 00:00:00"; |
| | | String endTime = LocalDate.now() + " 23:59:59"; |
| | | |
| | | String supplierAndClinicId = null; |
| | | if(roleType == 4){ |
| | | TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, userId)); |
| | | supplierAndClinicId = crmSupplier.getId(); |
| | | }else { |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId)); |
| | | supplierAndClinicId = crmClinic.getId(); |
| | | } |
| | | |
| | | // 订单数 |
| | | List<SupplierThirtyProcurementStatisticsVO> supplierThirtyProcurementStatistics = erpProcurementService.supplierThirtyProcurementStatistics(supplierAndClinicId, startTime, endTime,roleType); |
| | | |
| | | // 金额 |
| | | List<SupplierThirtyMoneyProcurementStatisticsVO> supplierThirtyMoneyProcurementStatistics = erpProcurementService.supplierThirtyMoneyProcurementStatistics(supplierAndClinicId, startTime, endTime,roleType); |
| | | |
| | | LocalDateTime localDateTime = LocalDateTime.now().minusDays(29); |
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); |
| | | for (int i = 0; i < 30; i++) { |
| | | LocalDateTime timeNow = localDateTime.plusDays(i); |
| | | List<SupplierThirtyProcurementStatisticsVO> vos = supplierThirtyProcurementStatistics.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | SupplierThirtyProcurementStatisticsVO vo = new SupplierThirtyProcurementStatisticsVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); |
| | | vo.setTime(time); |
| | | vo.setOrderCount(0); |
| | | supplierThirtyProcurementStatistics.add(vo); |
| | | } |
| | | List<SupplierThirtyMoneyProcurementStatisticsVO> moneyVOS = supplierThirtyMoneyProcurementStatistics.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(moneyVOS)){ |
| | | SupplierThirtyMoneyProcurementStatisticsVO vo = new SupplierThirtyMoneyProcurementStatisticsVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); |
| | | vo.setTime(time); |
| | | vo.setMoneyTotal(BigDecimal.ZERO); |
| | | supplierThirtyMoneyProcurementStatistics.add(vo); |
| | | } |
| | | } |
| | | // 根据时间排序 |
| | | supplierThirtyProcurementStatistics.sort(Comparator.comparing(SupplierThirtyProcurementStatisticsVO::getTime)); |
| | | supplierThirtyMoneyProcurementStatistics.sort(Comparator.comparing(SupplierThirtyMoneyProcurementStatisticsVO::getTime)); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("supplierThirtyProcurementStatistics", supplierThirtyProcurementStatistics); |
| | | map.put("supplierThirtyMoneyProcurementStatistics", supplierThirtyMoneyProcurementStatistics); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 诊所患者统计 |
| | | */ |
| | | @ApiOperation(value = "诊所患者统计", notes = "userCount:患者总数;diseaseCount:慢性病患者数") |
| | | @PostMapping(value = "/clinicPatientStatistics") |
| | | public R<Map<String, Integer>> clinicPatientStatistics() { |
| | | |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId)); |
| | | |
| | | List<TSysAppUser> sysAppUsers = sysAppUserService.list(Wrappers.lambdaQuery(TSysAppUser.class) |
| | | .eq(TSysAppUser::getClinicId, crmClinic.getId())); |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | map.put("userCount", sysAppUsers.size()); |
| | | map.put("diseaseCount", sysAppUsers.stream().filter(sysAppUser -> sysAppUser.getChronicDiseaseId() != null).collect(Collectors.toList()).size()); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 诊所积分统计 |
| | | */ |
| | | @ApiOperation(value = "诊所积分统计", notes = "remainingPoints:剩余积分;usedPoints:已用积分") |
| | | @PostMapping(value = "/clinicPointsStatistics") |
| | | public R<Map<String, Integer>> clinicPointsStatistics() { |
| | | |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId)); |
| | | |
| | | List<TCrmClinicPoints> crmClinicPoints = crmClinicPointsService.clinicPointsStatistics(crmClinic.getId(),LocalDate.now() + " 23:59:59"); |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | if(CollectionUtils.isEmpty(crmClinicPoints)){ |
| | | map.put("remainingPoints", 0); |
| | | map.put("usedPoints", 0); |
| | | }else { |
| | | int pointsTotal = crmClinicPoints.stream().mapToInt(TCrmClinicPoints::getPoints).sum(); |
| | | int usePoints = crmClinicPoints.stream().mapToInt(TCrmClinicPoints::getUsePoints).sum(); |
| | | map.put("remainingPoints", pointsTotal-usePoints); |
| | | map.put("usedPoints", usePoints); |
| | | } |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 供应商销售统计总类总数 |
| | | */ |
| | | @ApiOperation(value = "供应商销售统计总类总数",notes = "typeTotalCount:总类,totalCount:总数") |
| | | @PostMapping(value = "/supplierSalesStatisticsSum") |
| | | public R<Map<String,Integer>> supplierSalesStatisticsSum() { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, userId)); |
| | | // 查询药品总类和总数 |
| | | Integer typeTotalCount = erpProcurementService.supplierSalesStatisticsTypeCount(crmSupplier.getId()); |
| | | Integer totalCount = erpProcurementService.supplierSalesStatisticsCount(crmSupplier.getId()); |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | map.put("typeTotalCount", typeTotalCount); |
| | | map.put("totalCount", totalCount); |
| | | |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 供应商销售统计 |
| | | */ |
| | | @ApiOperation(value = "供应商销售统计") |
| | | @PostMapping(value = "/supplierSalesStatistics") |
| | | public R<SupplierSalesStatisticsVO> supplierSalesStatistics(@Validated @RequestBody DataStatisticsQuery query) { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | String startTime = null; |
| | | String endTime = null; |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | startTime = LocalDate.now() + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 2: |
| | | startTime = LocalDate.now().minusDays(1) + " 00:00:00"; |
| | | endTime = LocalDate.now().minusDays(1) + " 23:59:59"; |
| | | break; |
| | | case 3: |
| | | startTime = LocalDate.now().minusDays(6) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 4: |
| | | startTime = LocalDate.now().minusMonths(5).withDayOfMonth(1) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 5: |
| | | startTime = LocalDate.now().minusYears(1).withDayOfMonth(1) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | } |
| | | TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, userId)); |
| | | SupplierSalesStatisticsVO supplierSalesStatisticsVO = new SupplierSalesStatisticsVO(); |
| | | // 销售金额 |
| | | BigDecimal totalMoney = erpProcurementService.supplierSalesStatisticsMoney(crmSupplier.getId(), startTime, endTime); |
| | | supplierSalesStatisticsVO.setSalesMoney(totalMoney); |
| | | |
| | | // 查询销售前十占比 |
| | | List<SupplierSalesStatisticsGoodsTypeVO> supplierSalesStatisticsGoodsTypeVOS = erpProcurementService.supplierSalesStatisticsGoodsType(crmSupplier.getId(), startTime, endTime); |
| | | supplierSalesStatisticsVO.setSupplierSalesStatisticsGoodsTypeVOS(supplierSalesStatisticsGoodsTypeVOS); |
| | | // 查询30天销售统计 |
| | | List<SupplierSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCountVOS; |
| | | if(query.getTimeType() == 1 || query.getTimeType() == 2 || query.getTimeType() == 3){ |
| | | supplierSalesStatisticsGoodsCountVOS = erpProcurementService.supplierSalesStatisticsGoodsCount(crmSupplier.getId(), startTime, endTime,query.getGoodsName()); |
| | | }else { |
| | | supplierSalesStatisticsGoodsCountVOS = erpProcurementService.supplierSalesStatisticsGoodsCountMonth(crmSupplier.getId(), startTime, endTime,query.getGoodsName()); |
| | | } |
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); |
| | | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy.MM"); |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | if(CollectionUtils.isEmpty(supplierSalesStatisticsGoodsCountVOS)){ |
| | | SupplierSalesStatisticsGoodsCountVO supplierSalesStatisticsGoodsCountVO = new SupplierSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(LocalDateTime.now())); |
| | | supplierSalesStatisticsGoodsCountVO.setTime(time); |
| | | supplierSalesStatisticsGoodsCountVO.setGoodsCount(0); |
| | | supplierSalesStatisticsGoodsCountVOS.add(supplierSalesStatisticsGoodsCountVO); |
| | | } |
| | | break; |
| | | case 2: |
| | | if(CollectionUtils.isEmpty(supplierSalesStatisticsGoodsCountVOS)){ |
| | | SupplierSalesStatisticsGoodsCountVO supplierSalesStatisticsGoodsCountVO = new SupplierSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(LocalDateTime.now().minusDays(1))); |
| | | supplierSalesStatisticsGoodsCountVO.setTime(time); |
| | | supplierSalesStatisticsGoodsCountVO.setGoodsCount(0); |
| | | supplierSalesStatisticsGoodsCountVOS.add(supplierSalesStatisticsGoodsCountVO); |
| | | } |
| | | break; |
| | | case 3: |
| | | LocalDateTime days = LocalDateTime.now().minusDays(6); |
| | | for (int i = 0; i < 7; i++) { |
| | | LocalDateTime timeNow = days.plusDays(i); |
| | | List<SupplierSalesStatisticsGoodsCountVO> vos = supplierSalesStatisticsGoodsCountVOS.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | SupplierSalesStatisticsGoodsCountVO vo = new SupplierSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | supplierSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | supplierSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(SupplierSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | case 4: |
| | | LocalDateTime month = LocalDateTime.now().minusMonths(5); |
| | | for (int i = 0; i < 6; i++) { |
| | | LocalDateTime timeNow = month.plusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(timeNow); |
| | | String time = formatMonth.format(date); |
| | | List<SupplierSalesStatisticsGoodsCountVO> vos = supplierSalesStatisticsGoodsCountVOS.stream().filter(vo -> time.equals(vo.getTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | SupplierSalesStatisticsGoodsCountVO vo = new SupplierSalesStatisticsGoodsCountVO(); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | supplierSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | supplierSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(SupplierSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | case 5: |
| | | LocalDateTime years = LocalDateTime.now().minusYears(1); |
| | | for (int i = 0; i < 12; i++) { |
| | | LocalDateTime timeNow = years.plusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(timeNow); |
| | | String time = formatMonth.format(date); |
| | | List<SupplierSalesStatisticsGoodsCountVO> vos = supplierSalesStatisticsGoodsCountVOS.stream().filter(vo -> time.equals(vo.getTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | SupplierSalesStatisticsGoodsCountVO vo = new SupplierSalesStatisticsGoodsCountVO(); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | supplierSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | supplierSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(SupplierSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | } |
| | | supplierSalesStatisticsVO.setSupplierSalesStatisticsGoodsCountVOS(supplierSalesStatisticsGoodsCountVOS); |
| | | return R.ok(supplierSalesStatisticsVO); |
| | | } |
| | | |
| | | /** |
| | | * 诊所销售统计总类总数 |
| | | */ |
| | | @ApiOperation(value = "诊所销售统计总类总数",notes = "typeTotalCount:总类,totalCount:总数") |
| | | @PostMapping(value = "/clinicSalesStatisticsSum") |
| | | public R<Map<String,Integer>> clinicSalesStatisticsSum() { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId)); |
| | | // 查询药品总类和总数 |
| | | Integer typeTotalCount = sysOrderService.clinicSalesStatisticsTypeCount(crmClinic.getId()); |
| | | Integer totalCount = sysOrderService.clinicSalesStatisticsCount(crmClinic.getId()); |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | map.put("typeTotalCount", typeTotalCount); |
| | | map.put("totalCount", totalCount); |
| | | |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 诊所销售统计 |
| | | */ |
| | | @ApiOperation(value = "诊所销售统计") |
| | | @PostMapping(value = "/clinicSalesStatistics") |
| | | public R<ClinicSalesStatisticsVO> clinicSalesStatistics(@Validated @RequestBody DataStatisticsQuery query) { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | |
| | | String startTime = null; |
| | | String endTime = null; |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | startTime = LocalDate.now() + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 2: |
| | | startTime = LocalDate.now().minusDays(1) + " 00:00:00"; |
| | | endTime = LocalDate.now().minusDays(1) + " 23:59:59"; |
| | | break; |
| | | case 3: |
| | | startTime = LocalDate.now().minusDays(6) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 4: |
| | | startTime = LocalDate.now().minusMonths(5).withDayOfMonth(1) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 5: |
| | | startTime = LocalDate.now().minusYears(1).withDayOfMonth(1) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | } |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId)); |
| | | ClinicSalesStatisticsVO clinicSalesStatisticsVO = new ClinicSalesStatisticsVO(); |
| | | // 销售金额 |
| | | BigDecimal totalMoney = sysOrderService.clinicSalesStatisticsMoney(crmClinic.getId(), startTime, endTime); |
| | | clinicSalesStatisticsVO.setSalesMoney(totalMoney); |
| | | |
| | | // 查询销售前十占比 |
| | | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsTypeVOS = sysOrderService.supplierSalesStatisticsGoodsType(crmClinic.getId(), startTime, endTime); |
| | | clinicSalesStatisticsVO.setClinicSalesStatisticsGoodsTypeVOS(clinicSalesStatisticsGoodsTypeVOS); |
| | | // 查询30天销售统计 |
| | | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountVOS; |
| | | if(query.getTimeType() == 1 || query.getTimeType() == 2 || query.getTimeType() == 3){ |
| | | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime,query.getGoodsName()); |
| | | }else { |
| | | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCountMonth(crmClinic.getId(), startTime, endTime,query.getGoodsName()); |
| | | } |
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); |
| | | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy.MM"); |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | if(CollectionUtils.isEmpty(clinicSalesStatisticsGoodsCountVOS)){ |
| | | ClinicSalesStatisticsGoodsCountVO clinicSalesStatisticsGoodsCountVO = new ClinicSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(LocalDateTime.now())); |
| | | clinicSalesStatisticsGoodsCountVO.setTime(time); |
| | | clinicSalesStatisticsGoodsCountVO.setGoodsCount(0); |
| | | clinicSalesStatisticsGoodsCountVOS.add(clinicSalesStatisticsGoodsCountVO); |
| | | } |
| | | break; |
| | | case 2: |
| | | if(CollectionUtils.isEmpty(clinicSalesStatisticsGoodsCountVOS)){ |
| | | ClinicSalesStatisticsGoodsCountVO clinicSalesStatisticsGoodsCountVO = new ClinicSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(LocalDateTime.now().minusDays(1))); |
| | | clinicSalesStatisticsGoodsCountVO.setTime(time); |
| | | clinicSalesStatisticsGoodsCountVO.setGoodsCount(0); |
| | | clinicSalesStatisticsGoodsCountVOS.add(clinicSalesStatisticsGoodsCountVO); |
| | | } |
| | | break; |
| | | case 3: |
| | | LocalDateTime days = LocalDateTime.now().minusDays(6); |
| | | for (int i = 0; i < 7; i++) { |
| | | LocalDateTime timeNow = days.plusDays(i); |
| | | List<ClinicSalesStatisticsGoodsCountVO> vos = clinicSalesStatisticsGoodsCountVOS.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | ClinicSalesStatisticsGoodsCountVO vo = new ClinicSalesStatisticsGoodsCountVO(); |
| | | String time = format.format(DateUtils.localDateTimeToDate(timeNow)); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | clinicSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | clinicSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(ClinicSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | case 4: |
| | | LocalDateTime month = LocalDateTime.now().minusMonths(5); |
| | | for (int i = 0; i < 6; i++) { |
| | | LocalDateTime timeNow = month.plusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(timeNow); |
| | | String time = formatMonth.format(date); |
| | | List<ClinicSalesStatisticsGoodsCountVO> vos = clinicSalesStatisticsGoodsCountVOS.stream().filter(vo -> time.equals(vo.getTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | ClinicSalesStatisticsGoodsCountVO vo = new ClinicSalesStatisticsGoodsCountVO(); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | clinicSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | clinicSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(ClinicSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | case 5: |
| | | LocalDateTime years = LocalDateTime.now().minusYears(1); |
| | | for (int i = 0; i < 12; i++) { |
| | | LocalDateTime timeNow = years.plusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(timeNow); |
| | | String time = formatMonth.format(date); |
| | | List<ClinicSalesStatisticsGoodsCountVO> vos = clinicSalesStatisticsGoodsCountVOS.stream().filter(vo -> time.equals(vo.getTime())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(vos)){ |
| | | ClinicSalesStatisticsGoodsCountVO vo = new ClinicSalesStatisticsGoodsCountVO(); |
| | | vo.setTime(time); |
| | | vo.setGoodsCount(0); |
| | | clinicSalesStatisticsGoodsCountVOS.add(vo); |
| | | } |
| | | } |
| | | clinicSalesStatisticsGoodsCountVOS.sort(Comparator.comparing(ClinicSalesStatisticsGoodsCountVO::getTime)); |
| | | break; |
| | | } |
| | | clinicSalesStatisticsVO.setClinicSalesStatisticsGoodsCountVOS(clinicSalesStatisticsGoodsCountVOS); |
| | | return R.ok(clinicSalesStatisticsVO); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(LocalDate.now().minusMonths(6)); |
| | | } |
| | | |
| | | } |