| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.*; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static java.util.stream.Collectors.groupingBy; |
| | | |
| | | @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; |
| | | private final TCrmBranchService crmBranchService; |
| | | private final TErpProcurementCommissionService erpProcurementCommissionService; |
| | | private final TCrmChangePointsService crmChangePointsService; |
| | | private final TCrmSalespersonService crmSalespersonService; |
| | | |
| | | @Autowired |
| | | public DataStatisticsController(TErpProcurementService erpProcurementService, TokenService tokenService, ISysUserService sysUserService, TCrmSupplierService crmSupplierService, TCrmClinicService crmClinicService, TSysAppUserService sysAppUserService, TCrmClinicPointsService crmClinicPointsService, TSysOrderService sysOrderService, TCrmBranchService crmBranchService, TErpProcurementCommissionService erpProcurementCommissionService, TCrmChangePointsService crmChangePointsService, TCrmSalespersonService crmSalespersonService) { |
| | | this.erpProcurementService = erpProcurementService; |
| | | this.tokenService = tokenService; |
| | | this.sysUserService = sysUserService; |
| | | this.crmSupplierService = crmSupplierService; |
| | | this.crmClinicService = crmClinicService; |
| | | this.sysAppUserService = sysAppUserService; |
| | | this.crmClinicPointsService = crmClinicPointsService; |
| | | this.sysOrderService = sysOrderService; |
| | | this.crmBranchService = crmBranchService; |
| | | this.erpProcurementCommissionService = erpProcurementCommissionService; |
| | | this.crmChangePointsService = crmChangePointsService; |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | } |
| | | |
| | | /** |
| | | * 供应商采购统计 |
| | | */ |
| | | @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).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | map.put("orderMoney", orderMoney); |
| | | BigDecimal commissionMoney = orderQuantity.stream().map(TErpProcurement::getSupplierMoney).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | 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 -> Objects.nonNull(vo.getPayTime()) && 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 -> Objects.nonNull(vo.getPayTime()) && 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); |
| | | // 判断集合是否大于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(Arrays.asList(crmClinic.getId())); |
| | | Integer totalCount = sysOrderService.clinicSalesStatisticsCount(Arrays.asList(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.clinicSalesStatisticsGoodsType(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.clinicSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime, query.getGoodsName()); |
| | | } else { |
| | | clinicSalesStatisticsGoodsCountVOS = sysOrderService.clinicSalesStatisticsGoodsCountMonth(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)); |
| | | 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)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 分公司管理员-首页统计(第一部分) |
| | | */ |
| | | @ApiOperation(value = "分公司管理员-首页统计(第一部分)") |
| | | @PostMapping(value = "/branchAdminStatisticsOne") |
| | | public R<BranchAdminStatisticsOneVo> branchAdminStatisticsOne(@RequestBody @Validated BranchAdminStatisticsOneQuery query) { |
| | | BranchAdminStatisticsOneVo branchAdminStatisticsOneVo = new BranchAdminStatisticsOneVo(); |
| | | // 找出分公司下的所有员工 -》 所有诊所-》订单(状态 3=待发货 4=已发货 5=已入库) |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 2) { |
| | | TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) |
| | | .eq(TCrmBranch::getUserId, user.getUserId())); |
| | | if (branch != null) { |
| | | List<TCrmClinic> list = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).eq(TCrmClinic::getBranchId, branch.getId())); |
| | | if (!list.isEmpty()) { |
| | | List<String> crmClinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); |
| | | |
| | | // 获取最近一年的时间 |
| | | LocalDateTime time = LocalDateTime.now().minusYears(1); |
| | | List<TErpProcurement> procurementList = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().between(TErpProcurement::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())).ne(TErpProcurement::getStatus, 6).isNotNull(TErpProcurement::getPayTime).in(TErpProcurement::getClinicId, crmClinicIds)); |
| | | List<TErpProcurementCommission> list1 = erpProcurementCommissionService.list(new LambdaQueryWrapper<TErpProcurementCommission>().eq(TErpProcurementCommission::getBranchSalespersonId, branch.getId()).eq(TErpProcurementCommission::getCommissionType, 1).between(TErpProcurementCommission::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now()))); |
| | | |
| | | // list1 获取本月的 |
| | | List<TErpProcurementCommission> list2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(time.toLocalDate())).collect(Collectors.toList()); |
| | | branchAdminStatisticsOneVo.setMonthMoney(list2.stream().map(TErpProcurementCommission::getMoney).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); |
| | | |
| | | |
| | | if (!procurementList.isEmpty()) { |
| | | List<TErpProcurement> collect = null; |
| | | List<TErpProcurementCommission> collect2 = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // procurementList算出今日的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | collect2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | |
| | | // procurementList算出昨天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | collect2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 最近7天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | collect2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | collect2 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 最近一年 |
| | | collect = procurementList; |
| | | collect2 = list1; |
| | | break; |
| | | } |
| | | branchAdminStatisticsOneVo.setOrderCount(collect.size()); |
| | | branchAdminStatisticsOneVo.setMoneyProcurement(collect.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | branchAdminStatisticsOneVo.setBranchMoney(collect2.stream().map(TErpProcurementCommission::getMoney).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); |
| | | |
| | | |
| | | // 获取公司业务员 |
| | | List<String> salesIds = crmSalespersonService.list(new LambdaQueryWrapper<TCrmSalesperson>().eq(TCrmSalesperson::getBranchId, branch.getId())).stream().map(TCrmSalesperson::getId).collect(Collectors.toList()); |
| | | if (salesIds.isEmpty()) { |
| | | salesIds.add("0"); |
| | | } |
| | | List<TErpProcurementCommission> list3 = erpProcurementCommissionService.list(new LambdaQueryWrapper<TErpProcurementCommission>().in(TErpProcurementCommission::getBranchSalespersonId, salesIds).eq(TErpProcurementCommission::getCommissionType, 2).between(TErpProcurementCommission::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now()))); |
| | | |
| | | List<TErpProcurement> collect1 = null; |
| | | List<TErpProcurementCommission> collect3 = null; |
| | | switch (query.getStaffType()) { |
| | | case 1: |
| | | // procurementList算出今日的 |
| | | collect1 = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | collect3 = list3.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // procurementList算出昨天的 |
| | | collect1 = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | collect3 = list3.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 最近7天的 |
| | | collect1 = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | collect3 = list3.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | collect1 = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | collect3 = list3.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 最近一年 |
| | | collect1 = procurementList; |
| | | collect3 = list3; |
| | | break; |
| | | } |
| | | |
| | | branchAdminStatisticsOneVo.setStaffOrderCount(collect1.size()); |
| | | branchAdminStatisticsOneVo.setStaffMoneyProcurement(collect1.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | branchAdminStatisticsOneVo.setStaffMoney(collect3.stream().map(TErpProcurementCommission::getMoney).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); |
| | | |
| | | long count = crmSalespersonService.count(new LambdaQueryWrapper<TCrmSalesperson>().eq(TCrmSalesperson::getBranchId, branch.getId())); |
| | | branchAdminStatisticsOneVo.setStaffCount((int) count); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | return R.ok(branchAdminStatisticsOneVo); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 分公司管理员-首页统计(第二部分) |
| | | */ |
| | | @ApiOperation(value = "分公司管理员-首页统计(第二部分)") |
| | | @PostMapping(value = "/branchAdminStatisticsTwo") |
| | | public R<BranchAdminStatisticsTwoVo> branchAdminStatisticsTwo(@RequestBody @Validated BranchAdminStatisticsTwoQuery query) { |
| | | BranchAdminStatisticsTwoVo branchAdminStatisticsTwoVo = new BranchAdminStatisticsTwoVo(); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 2) { |
| | | TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) |
| | | .eq(TCrmBranch::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | if (branch != null) { |
| | | LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class); |
| | | if (query.getSalespersonId() != null && !query.getSalespersonId().isEmpty()) { |
| | | eq.eq(TCrmClinic::getSalespersonId, query.getSalespersonId()); |
| | | } else { |
| | | eq.eq(TCrmClinic::getBranchId, branch.getId()); |
| | | } |
| | | |
| | | List<TCrmClinic> list = crmClinicService.list(eq); |
| | | branchAdminStatisticsTwoVo.setClinicNum(list.size()); |
| | | |
| | | // 金额 |
| | | ArrayList<SupplierThirtyMoneyProcurementStatisticsVO> moneyProcurementStatisticsVOS = new ArrayList<>(); |
| | | ArrayList<SupplierThirtyProcurementStatisticsVO> orderProcurementStatisticsVOS = new ArrayList<>(); |
| | | |
| | | List<String> crmClinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); |
| | | if (crmClinicIds.isEmpty()) { |
| | | crmClinicIds.add("0"); |
| | | } |
| | | // 获取最近一年的时间 |
| | | LocalDateTime time = LocalDateTime.now().minusYears(1); |
| | | List<TErpProcurement> procurementList = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().between(TErpProcurement::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())).ne(TErpProcurement::getStatus, 6).isNotNull(TErpProcurement::getPayTime).in(TErpProcurement::getClinicId, crmClinicIds)); |
| | | |
| | | if (!list.isEmpty()) { |
| | | if (!procurementList.isEmpty()) { |
| | | List<TErpProcurement> collect = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // procurementList算出今日的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // procurementList算出昨天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 最近7天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 最近一年 |
| | | collect = procurementList; |
| | | break; |
| | | } |
| | | branchAdminStatisticsTwoVo.setOrderCount(collect.size()); |
| | | branchAdminStatisticsTwoVo.setMoneyProcurement(collect.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | } |
| | | } |
| | | |
| | | |
| | | List<TErpProcurement> collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(30))).collect(Collectors.toList()); |
| | | for (int i = 29; i >= 0; i--) { |
| | | String string = LocalDate.now().minusDays(i).toString(); |
| | | SupplierThirtyMoneyProcurementStatisticsVO thirtyMoneyProcurementStatisticsVO = new SupplierThirtyMoneyProcurementStatisticsVO(); |
| | | thirtyMoneyProcurementStatisticsVO.setTime(string); |
| | | thirtyMoneyProcurementStatisticsVO.setMoneyTotal(collect.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.parse(string))).map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | moneyProcurementStatisticsVOS.add(thirtyMoneyProcurementStatisticsVO); |
| | | |
| | | SupplierThirtyProcurementStatisticsVO thirtyProcurementStatisticsVO = new SupplierThirtyProcurementStatisticsVO(); |
| | | thirtyProcurementStatisticsVO.setTime(string); |
| | | thirtyProcurementStatisticsVO.setOrderCount((int) collect.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.parse(string))).count()); |
| | | orderProcurementStatisticsVOS.add(thirtyProcurementStatisticsVO); |
| | | |
| | | } |
| | | branchAdminStatisticsTwoVo.setThirtyMoneyProcurementStatisticsVOS(moneyProcurementStatisticsVOS); |
| | | branchAdminStatisticsTwoVo.setThirtyProcurementStatisticsVOS(orderProcurementStatisticsVOS); |
| | | |
| | | } |
| | | |
| | | } |
| | | return R.ok(branchAdminStatisticsTwoVo); |
| | | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "分公司管理员-首页统计(第三部分)") |
| | | @PostMapping(value = "/branchAdminStatisticsThree") |
| | | public R<BranchAdminStatisticsThreeVo> branchAdminStatisticsThree(@RequestBody @Validated BranchAdminStatisticsThreeQuery query) { |
| | | BranchAdminStatisticsThreeVo vo = new BranchAdminStatisticsThreeVo(); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM"); |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 2) { |
| | | TCrmBranch branch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class) |
| | | .eq(TCrmBranch::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | if (branch != null) { |
| | | LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class); |
| | | eq.eq(TCrmClinic::getBranchId, branch.getId()); |
| | | List<TCrmClinic> list = crmClinicService.list(eq); |
| | | |
| | | List<String> clinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); |
| | | if (clinicIds.isEmpty()) { |
| | | return R.ok(vo); |
| | | } |
| | | // 查询这个诊所的所有订单并算出商品种类数 和 商品数 |
| | | List<TErpProcurementGoods> erpProcurementGoods = erpProcurementService.branchAdminStatisticsThree(clinicIds); |
| | | |
| | | // 根据商品id算出商品种类数 |
| | | vo.setGoodsTypeCount((int) erpProcurementGoods.stream().map(TErpProcurementGoods::getGoodsId).distinct().count()); |
| | | |
| | | // 算出商品数 |
| | | vo.setGoodsCount(erpProcurementGoods.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | List<TErpProcurementGoods> collect = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // 通过payTime是今日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // 通过payTime是昨日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 通过payTime是近7天的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 通过payTime是近半年的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 通过payTime是近一年的数据 |
| | | collect = erpProcurementGoods; |
| | | break; |
| | | } |
| | | vo.setMoneyProcurement(collect.stream().map(TErpProcurementGoods::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | //collect 通过goodsId 分组并 根据purchaseCount 倒叙 |
| | | Map<String, List<TErpProcurementGoods>> collect2 = collect.stream().collect(groupingBy(TErpProcurementGoods::getGoodsId)); |
| | | List<ClinicSalesStatisticsGoodsTypeVO> thirtyMoneyProcurementStatisticsVOS = collect2.entrySet().stream().map(entry -> { |
| | | ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | clinicSalesStatisticsGoodsTypeVO.setGoodsCount(entry.getValue().stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | clinicSalesStatisticsGoodsTypeVO.setTypeName(entry.getValue().get(0).getGoodsName()); |
| | | return clinicSalesStatisticsGoodsTypeVO; |
| | | }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList()); |
| | | // 总数 |
| | | int sum = collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum(); |
| | | int sum1 = thirtyMoneyProcurementStatisticsVOS.stream().mapToInt(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).sum(); |
| | | if (sum - sum1 > 0) { |
| | | ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1); |
| | | clinicSalesStatisticsGoodsTypeVO.setTypeName("其他"); |
| | | thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO); |
| | | } |
| | | vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS); |
| | | |
| | | |
| | | ArrayList<ProcurementStatisticsVO> procurementStatisticsVOS = new ArrayList<>(); |
| | | // 是否做了搜索 |
| | | if (query.getName() != null && !query.getName().isEmpty()) { |
| | | collect = collect.stream().filter(e -> e.getGoodsName().equals(query.getName())).collect(Collectors.toList()); |
| | | } |
| | | if (query.getType() == 1) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().toString()); |
| | | procurementStatisticsVO.setCount(collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | if (query.getType() == 2) { |
| | | // 昨日的数据 |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(1).toString()); |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | |
| | | if (query.getType() == 3) { |
| | | // 近7天的数据 |
| | | for (int i = 6; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(i).toString()); |
| | | int finalI = i; |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(finalI))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | if (query.getType() == 4) { |
| | | // 按月算 |
| | | for (int i = 5; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | |
| | | if (query.getType() == 5) { |
| | | // 按月算 |
| | | for (int i = 11; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | vo.setThirtyProcurementStatisticsVOS(procurementStatisticsVOS); |
| | | } |
| | | |
| | | } |
| | | return R.ok(vo); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 平台管理员-首页统计(第一部分) |
| | | */ |
| | | @ApiOperation(value = "平台管理员-首页统计(第一部分)") |
| | | @PostMapping(value = "/platformAdminStatisticsOne") |
| | | public R<PlatformAdminStatisticsOneVo> platformAdminStatisticsOne(@RequestBody @Validated BranchAdminStatisticsOneQuery query) { |
| | | PlatformAdminStatisticsOneVo branchAdminStatisticsOneVo = new PlatformAdminStatisticsOneVo(); |
| | | // 找出分公司下的所有员工 -》 所有诊所-》订单(状态 3=待发货 4=已发货 5=已入库) |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 1) { |
| | | List<TCrmClinic> list = crmClinicService.list(); |
| | | if (!list.isEmpty()) { |
| | | |
| | | long branchCount = crmBranchService.count(); |
| | | |
| | | long staffCount = crmSalespersonService.count(); |
| | | |
| | | List<TErpProcurement> procurementList = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().ne(TErpProcurement::getStatus, 6).isNotNull(TErpProcurement::getPayTime)); |
| | | if (procurementList.isEmpty()) { |
| | | return R.ok(branchAdminStatisticsOneVo); |
| | | } |
| | | BigDecimal bigDecimal = procurementList.stream().map(TErpProcurement::getPayMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); |
| | | branchAdminStatisticsOneVo.setAllMoney(bigDecimal); |
| | | branchAdminStatisticsOneVo.setBranchCount((int) branchCount); |
| | | branchAdminStatisticsOneVo.setStaffCount((int) staffCount); |
| | | |
| | | List<TErpProcurement> collect = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // procurementList算出今日的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | |
| | | // procurementList算出昨天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 最近7天的 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | collect = procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 最近一年 |
| | | collect = procurementList; |
| | | break; |
| | | } |
| | | branchAdminStatisticsOneVo.setOrderCount(collect.size()); |
| | | branchAdminStatisticsOneVo.setMoneyProcurement(collect.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | branchAdminStatisticsOneVo.setPlatformMoney(collect.stream().map(TErpProcurement::getMoney).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); |
| | | branchAdminStatisticsOneVo.setSupplierMoney(collect.stream().map(TErpProcurement::getSupplierMoney).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); |
| | | |
| | | |
| | | List<TErpProcurementCommission> list1 = erpProcurementCommissionService.list(); |
| | | List<TErpProcurementCommission> collect3 = null; |
| | | switch (query.getStaffType()) { |
| | | case 1: |
| | | // procurementList算出今日的 |
| | | collect3 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // procurementList算出昨天的 |
| | | collect3 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 最近7天的 |
| | | collect3 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | collect3 = list1.stream().filter(commission -> commission.getCreateTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 最近一年 |
| | | collect3 = list1; |
| | | break; |
| | | } |
| | | |
| | | branchAdminStatisticsOneVo.setBranchMoney(collect3.stream().filter(e -> e.getCommissionType() == 1).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); |
| | | branchAdminStatisticsOneVo.setStaffMoney(collect3.stream().filter(e -> e.getCommissionType() == 2).map(TErpProcurementCommission::getMoney).reduce(BigDecimal::add).get()); |
| | | } |
| | | |
| | | |
| | | } |
| | | return R.ok(branchAdminStatisticsOneVo); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 平台管理员-首页统计(第二部分) |
| | | */ |
| | | @ApiOperation(value = "平台管理员-首页统计(第二部分)") |
| | | @PostMapping(value = "/platformAdminStatisticsTwo") |
| | | public R<PlatformAdminStatisticsTwoVo> platformAdminStatisticsTwo(@RequestBody @Validated PlatformAdminStatisticsTwoQuery query) { |
| | | PlatformAdminStatisticsTwoVo branchAdminStatisticsOneVo = new PlatformAdminStatisticsTwoVo(); |
| | | // 找出分公司下的所有员工 -》 所有诊所-》订单(状态 3=待发货 4=已发货 5=已入库) |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 1) { |
| | | LambdaQueryWrapper<TCrmClinic> w = new LambdaQueryWrapper<>(); |
| | | if (query.getBranchId() != null && !query.getBranchId().isEmpty()) { |
| | | w.eq(TCrmClinic::getBranchId, query.getBranchId()); |
| | | } |
| | | if (query.getSalespersonId() != null && !query.getSalespersonId().isEmpty()) { |
| | | w.eq(TCrmClinic::getSalespersonId, query.getSalespersonId()); |
| | | } |
| | | List<TCrmClinic> list = crmClinicService.list(w); |
| | | branchAdminStatisticsOneVo.setClinicNum(list.size()); |
| | | |
| | | if (!list.isEmpty()) { |
| | | List<String> clinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); |
| | | // 获取最近30的时间 |
| | | LocalDateTime time = LocalDateTime.now().minusDays(30); |
| | | List<TErpProcurement> procurementList = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().between(TErpProcurement::getCreateTime, DateUtils.localDateTimeToDate(time), DateUtils.localDateTimeToDate(LocalDateTime.now())).ne(TErpProcurement::getStatus, 6).isNotNull(TErpProcurement::getPayTime).in(TErpProcurement::getClinicId, clinicIds)); |
| | | if (procurementList.isEmpty()) { |
| | | return R.ok(branchAdminStatisticsOneVo); |
| | | } |
| | | |
| | | |
| | | String startTime = null; |
| | | String endTime = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // 获取今天的开始和结束时间 |
| | | startTime = LocalDate.now() + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | // 通过CreateTime查询今天的数据 |
| | | break; |
| | | case 2: |
| | | // 获取昨天的开始和结束时间 |
| | | startTime = LocalDate.now().minusDays(1) + " 00:00:00"; |
| | | endTime = LocalDate.now().minusDays(1) + " 23:59:59"; |
| | | break; |
| | | case 3: |
| | | // 最近7天的开始和结束时间 |
| | | startTime = LocalDate.now().minusDays(6) + " 00:00:00"; |
| | | endTime = LocalDate.now() + " 23:59:59"; |
| | | break; |
| | | case 4: |
| | | // 最近半年 |
| | | startTime = LocalDate.now().minusMonths(6) + " 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; |
| | | } |
| | | List<TErpProcurementCommission> collect3 = erpProcurementCommissionService.list(new LambdaQueryWrapper<TErpProcurementCommission>() |
| | | .between(TErpProcurementCommission::getCreateTime, startTime, endTime)); |
| | | List<TCrmChangePoints> pointsList = crmChangePointsService.list(new LambdaQueryWrapper<TCrmChangePoints>().eq(TCrmChangePoints::getChangeType,1) |
| | | .between(TCrmChangePoints::getCreateTime, startTime, endTime)); |
| | | if(query.getBranchId()!=null && !query.getBranchId().isEmpty()){ |
| | | BigDecimal bigDecimal = collect3.stream().filter(e -> e.getCommissionType() == 1 && e.getBranchSalespersonId().equals(query.getBranchId())).map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | branchAdminStatisticsOneVo.setBranchMoney(bigDecimal); |
| | | |
| | | int sum = pointsList.stream().filter(e -> e.getBranchSalespersonId().equals(query.getBranchId()) && e.getUserType() == 1).mapToInt(TCrmChangePoints::getChangeValue).sum(); |
| | | branchAdminStatisticsOneVo.setBranchPoints(sum); |
| | | |
| | | }else { |
| | | branchAdminStatisticsOneVo.setBranchMoney(collect3.stream().filter(e -> e.getCommissionType() == 1).map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | int sum = pointsList.stream().filter(e -> e.getUserType() == 1).mapToInt(TCrmChangePoints::getChangeValue).sum(); |
| | | branchAdminStatisticsOneVo.setBranchPoints(sum); |
| | | } |
| | | if(query.getSalespersonId()!=null && !query.getSalespersonId().isEmpty()){ |
| | | BigDecimal bigDecimal = collect3.stream().filter(e -> e.getCommissionType() == 2 && e.getBranchSalespersonId().equals(query.getSalespersonId())).map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | branchAdminStatisticsOneVo.setStaffMoney(bigDecimal); |
| | | |
| | | int sum = pointsList.stream().filter(e -> e.getBranchSalespersonId().equals(query.getSalespersonId()) && e.getUserType() == 2).mapToInt(TCrmChangePoints::getChangeValue).sum(); |
| | | branchAdminStatisticsOneVo.setStaffPoints(sum); |
| | | }else { |
| | | branchAdminStatisticsOneVo.setStaffMoney(collect3.stream().filter(e -> e.getCommissionType() == 2).map(TErpProcurementCommission::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | int sum = pointsList.stream().filter(e -> e.getUserType() == 2).mapToInt(TCrmChangePoints::getChangeValue).sum(); |
| | | branchAdminStatisticsOneVo.setStaffPoints(sum); |
| | | } |
| | | |
| | | |
| | | ArrayList<SupplierThirtyProcurementStatisticsVO> orderProcurementStatisticsVOS = new ArrayList<>(); |
| | | ArrayList<SupplierThirtyMoneyProcurementStatisticsVO> moneyProcurementStatisticsVOS = new ArrayList<>(); |
| | | for (int i = 29; i >= 0; i--) { |
| | | String string = LocalDate.now().minusDays(i).toString(); |
| | | SupplierThirtyMoneyProcurementStatisticsVO thirtyMoneyProcurementStatisticsVO = new SupplierThirtyMoneyProcurementStatisticsVO(); |
| | | thirtyMoneyProcurementStatisticsVO.setTime(string); |
| | | thirtyMoneyProcurementStatisticsVO.setMoneyTotal(procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.parse(string))).map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | moneyProcurementStatisticsVOS.add(thirtyMoneyProcurementStatisticsVO); |
| | | |
| | | SupplierThirtyProcurementStatisticsVO thirtyProcurementStatisticsVO = new SupplierThirtyProcurementStatisticsVO(); |
| | | thirtyProcurementStatisticsVO.setTime(string); |
| | | thirtyProcurementStatisticsVO.setOrderCount((int) procurementList.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.parse(string))).count()); |
| | | orderProcurementStatisticsVOS.add(thirtyProcurementStatisticsVO); |
| | | |
| | | } |
| | | branchAdminStatisticsOneVo.setThirtyMoneyProcurementStatisticsVOS(moneyProcurementStatisticsVOS); |
| | | branchAdminStatisticsOneVo.setThirtyProcurementStatisticsVOS(orderProcurementStatisticsVOS); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | return R.ok(branchAdminStatisticsOneVo); |
| | | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "平台管理员-首页统计(第三部分)") |
| | | @PostMapping(value = "/platformAdminStatisticsThree") |
| | | public R<BranchAdminStatisticsThreeVo> platformAdminStatisticsThree(@RequestBody @Validated BranchAdminStatisticsThreeQuery query) { |
| | | BranchAdminStatisticsThreeVo vo = new BranchAdminStatisticsThreeVo(); |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM"); |
| | | Integer roleType = user.getRoleType(); |
| | | if (roleType == 1) { |
| | | LambdaQueryWrapper<TCrmClinic> eq = Wrappers.lambdaQuery(TCrmClinic.class); |
| | | if(query.getBranchId()!=null && !query.getBranchId().isEmpty()){ |
| | | eq.eq(TCrmClinic::getBranchId, query.getBranchId()); |
| | | } |
| | | List<TCrmClinic> list = crmClinicService.list(eq); |
| | | |
| | | List<String> clinicIds = list.stream().map(TCrmClinic::getId).collect(Collectors.toList()); |
| | | if (clinicIds.isEmpty()) { |
| | | return R.ok(vo); |
| | | } |
| | | // 查询这个诊所的所有订单并算出商品种类数 和 商品数 |
| | | List<TErpProcurementGoods> erpProcurementGoods = erpProcurementService.branchAdminStatisticsThree(clinicIds); |
| | | |
| | | // 根据商品id算出商品种类数 |
| | | vo.setGoodsTypeCount((int) erpProcurementGoods.stream().map(TErpProcurementGoods::getGoodsId).distinct().count()); |
| | | |
| | | // 算出商品数 |
| | | vo.setGoodsCount(erpProcurementGoods.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | List<TErpProcurementGoods> collect = null; |
| | | switch (query.getType()) { |
| | | case 1: |
| | | // 通过payTime是今日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now())).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | // 通过payTime是昨日的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | // 通过payTime是近7天的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusDays(7))).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | // 通过payTime是近半年的数据 |
| | | collect = erpProcurementGoods.stream().filter(procurement -> procurement.getPayTime().toLocalDate().isAfter(LocalDate.now().minusMonths(6))).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | // 通过payTime是近一年的数据 |
| | | collect = erpProcurementGoods; |
| | | break; |
| | | } |
| | | vo.setMoneyProcurement(collect.stream().map(TErpProcurementGoods::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | //collect 通过goodsId 分组并 根据purchaseCount 倒叙 |
| | | Map<String, List<TErpProcurementGoods>> collect2 = collect.stream().collect(groupingBy(TErpProcurementGoods::getGoodsId)); |
| | | List<ClinicSalesStatisticsGoodsTypeVO> thirtyMoneyProcurementStatisticsVOS = collect2.entrySet().stream().map(entry -> { |
| | | ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | clinicSalesStatisticsGoodsTypeVO.setGoodsCount(entry.getValue().stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | clinicSalesStatisticsGoodsTypeVO.setTypeName(entry.getValue().get(0).getGoodsName()); |
| | | return clinicSalesStatisticsGoodsTypeVO; |
| | | }).sorted(Comparator.comparing(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).reversed()).limit(9).collect(Collectors.toList()); |
| | | // 总数 |
| | | int sum = collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum(); |
| | | int sum1 = thirtyMoneyProcurementStatisticsVOS.stream().mapToInt(ClinicSalesStatisticsGoodsTypeVO::getGoodsCount).sum(); |
| | | if (sum - sum1 > 0) { |
| | | ClinicSalesStatisticsGoodsTypeVO clinicSalesStatisticsGoodsTypeVO = new ClinicSalesStatisticsGoodsTypeVO(); |
| | | clinicSalesStatisticsGoodsTypeVO.setGoodsCount(sum - sum1); |
| | | clinicSalesStatisticsGoodsTypeVO.setTypeName("其他"); |
| | | thirtyMoneyProcurementStatisticsVOS.add(clinicSalesStatisticsGoodsTypeVO); |
| | | } |
| | | vo.setThirtyMoneyProcurementStatisticsVOS(thirtyMoneyProcurementStatisticsVOS); |
| | | |
| | | |
| | | ArrayList<ProcurementStatisticsVO> procurementStatisticsVOS = new ArrayList<>(); |
| | | // 是否做了搜索 |
| | | if (query.getName() != null && !query.getName().isEmpty()) { |
| | | collect = collect.stream().filter(e -> e.getGoodsName().equals(query.getName())).collect(Collectors.toList()); |
| | | } |
| | | if (query.getType() == 1) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().toString()); |
| | | procurementStatisticsVO.setCount(collect.stream().mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | if (query.getType() == 2) { |
| | | // 昨日的数据 |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(1).toString()); |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(1))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | |
| | | if (query.getType() == 3) { |
| | | // 近7天的数据 |
| | | for (int i = 6; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | procurementStatisticsVO.setTime(LocalDate.now().minusDays(i).toString()); |
| | | int finalI = i; |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> e.getPayTime().toLocalDate().isEqual(LocalDate.now().minusDays(finalI))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | if (query.getType() == 4) { |
| | | // 按月算 |
| | | for (int i = 5; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | |
| | | if (query.getType() == 5) { |
| | | // 按月算 |
| | | for (int i = 11; i >= 0; i--) { |
| | | ProcurementStatisticsVO procurementStatisticsVO = new ProcurementStatisticsVO(); |
| | | LocalDateTime localDate = LocalDateTime.now().minusMonths(i); |
| | | Date date = DateUtils.localDateTimeToDate(localDate); |
| | | String time = formatMonth.format(date); |
| | | procurementStatisticsVO.setTime(time); |
| | | // 按月算 年和月都要匹配 |
| | | procurementStatisticsVO.setCount(collect.stream().filter(e -> time.equals(formatMonth.format(DateUtils.localDateTimeToDate(e.getPayTime())))).mapToInt(TErpProcurementGoods::getPurchaseCount).sum()); |
| | | procurementStatisticsVOS.add(procurementStatisticsVO); |
| | | } |
| | | } |
| | | vo.setThirtyProcurementStatisticsVOS(procurementStatisticsVOS); |
| | | } |
| | | |
| | | return R.ok(vo); |
| | | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "通过分公司id查询业务员列表") |
| | | @GetMapping(value = "/getSalespersonListByBranchId") |
| | | public R<List<TCrmSalesperson>> getSalespersonListByBranchId(@RequestParam String branchId) { |
| | | List<TCrmSalesperson> list = crmSalespersonService.list(new LambdaQueryWrapper<TCrmSalesperson>().eq(TCrmSalesperson::getBranchId, branchId)); |
| | | return R.ok(list); |
| | | } |
| | | } |