| | |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.DataStatisticsQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.SupplierThirtyMoneyProcurementStatisticsVO; |
| | | import com.ruoyi.system.vo.SupplierThirtyProcurementStatisticsVO; |
| | | import com.ruoyi.system.vo.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | 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) { |
| | | 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.crmClinicService = crmClinicService; |
| | | this.sysAppUserService = sysAppUserService; |
| | | this.crmClinicPointsService = crmClinicPointsService; |
| | | this.sysOrderService = sysOrderService; |
| | | } |
| | | |
| | | /** |
| | |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 4: |
| | | startTime = LocalDate.now().minusMonths(6) + " 00:00:00"; |
| | | startTime = LocalDate.now().minusMonths(5) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 5: |
| | |
| | | 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); |
| | | // 判断集合是否大于9 |
| | | if(supplierSalesStatisticsGoodsTypeVOS.size() > 9){ |
| | | // 其余的添加到其他 |
| | | List<SupplierSalesStatisticsGoodsTypeVO> otherList = supplierSalesStatisticsGoodsTypeVOS.subList(9, supplierSalesStatisticsGoodsTypeVOS.size()); |
| | | SupplierSalesStatisticsGoodsTypeVO other = new SupplierSalesStatisticsGoodsTypeVO(); |
| | | other.setTypeName("其他"); |
| | | other.setGoodsCount(otherList.stream().mapToInt(SupplierSalesStatisticsGoodsTypeVO::getGoodsCount).sum()); |
| | | supplierSalesStatisticsGoodsTypeVOS.add(other); |
| | | supplierSalesStatisticsGoodsTypeVOS = supplierSalesStatisticsGoodsTypeVOS.subList(0, 9); |
| | | } |
| | | 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); |
| | | // 判断集合是否大于9 |
| | | if(clinicSalesStatisticsGoodsTypeVOS.size() > 9){ |
| | | // 其余的添加到其他 |
| | | List<ClinicSalesStatisticsGoodsTypeVO> otherList = clinicSalesStatisticsGoodsTypeVOS.subList(9, clinicSalesStatisticsGoodsTypeVOS.size()); |
| | | ClinicSalesStatisticsGoodsTypeVO other = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | other.setTypeName("其他"); |
| | | other.setGoodsCount(otherList.stream().mapToInt(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).sum()); |
| | | clinicSalesStatisticsGoodsTypeVOS.add(other); |
| | | clinicSalesStatisticsGoodsTypeVOS = clinicSalesStatisticsGoodsTypeVOS.subList(0, 9); |
| | | } |
| | | 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().minusDays(30)); |
| | | System.out.println(LocalDate.now().minusMonths(6)); |
| | | List<Integer> list = new ArrayList<>(); |
| | | for (int i = 0; i < 6; i++) { |
| | | list.add(i); |
| | | } |
| | | System.out.println(list.subList(2,list.size())); |
| | | System.out.println(list.subList(0,2 )); |
| | | } |
| | | |
| | | } |