|  |  |  | 
|---|
|  |  |  | map.put("orderMoney", 0); // 订单金额 | 
|---|
|  |  |  | map.put("commissionMoney", 0); // 分佣金额 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | BigDecimal orderMoney = orderQuantity.stream().map(TErpProcurement::getPayMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); | 
|---|
|  |  |  | BigDecimal orderMoney = orderQuantity.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO,BigDecimal::add); | 
|---|
|  |  |  | map.put("orderMoney", orderMoney); | 
|---|
|  |  |  | BigDecimal commissionMoney = orderQuantity.stream().map(TErpProcurement::getSupplierMoney).filter(Objects::nonNull).reduce(BigDecimal::add).get(); | 
|---|
|  |  |  | 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:金额") | 
|---|
|  |  |  | @ApiOperation(value = "诊所/供应商最近30天采购统计", notes = "supplierThirtyProcurementStatistics:订单,supplierThirtyMoneyProcurementStatistics:金额") | 
|---|
|  |  |  | @PostMapping(value = "/supplierThirtyProcurementStatistics") | 
|---|
|  |  |  | public R<Map<String, Object>> supplierThirtyProcurementStatistics() { | 
|---|
|  |  |  | Long userId = tokenService.getLoginUser().getUserId(); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 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.setOrderCount(0); | 
|---|
|  |  |  | supplierThirtyProcurementStatistics.add(vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<SupplierThirtyMoneyProcurementStatisticsVO> moneyVOS = supplierThirtyMoneyProcurementStatistics.stream().filter(vo -> timeNow.toLocalDate().isEqual(vo.getPayTime())).collect(Collectors.toList()); | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  | clinicSalesStatisticsVO.setSalesMoney(totalMoney); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 查询销售前十占比 | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsTypeVOS = sysOrderService.supplierSalesStatisticsGoodsType(crmClinic.getId(), startTime, endTime); | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsTypeVOS = sysOrderService.clinicSalesStatisticsGoodsType(crmClinic.getId(), startTime, endTime); | 
|---|
|  |  |  | // 判断集合是否大于9 | 
|---|
|  |  |  | if (clinicSalesStatisticsGoodsTypeVOS.size() > 9) { | 
|---|
|  |  |  | // 其余的添加到其他 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 查询30天销售统计 | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountVOS; | 
|---|
|  |  |  | if (query.getTimeType() == 1 || query.getTimeType() == 2 || query.getTimeType() == 3) { | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.clinicSalesStatisticsGoodsCount(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.supplierSalesStatisticsGoodsCountMonth(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | clinicSalesStatisticsGoodsCountVOS = sysOrderService.clinicSalesStatisticsGoodsCountMonth(crmClinic.getId(), startTime, endTime, query.getGoodsName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); | 
|---|
|  |  |  | SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy.MM"); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Param("startTime")String startTime, | 
|---|
|  |  |  | @Param("endTime")String endTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> supplierSalesStatisticsGoodsType(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsType(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | @Param("startTime")String startTime, | 
|---|
|  |  |  | @Param("endTime")String endTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCount(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCount(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | @Param("startTime")String startTime, | 
|---|
|  |  |  | @Param("endTime")String endTime, | 
|---|
|  |  |  | @Param("goodsName")String goodsName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCountMonth(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountMonth(@Param("clinicId")String clinicId, | 
|---|
|  |  |  | @Param("startTime")String startTime, | 
|---|
|  |  |  | @Param("endTime")String endTime, | 
|---|
|  |  |  | @Param("goodsName")String goodsName); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal clinicSalesStatisticsMoney(String clinicId, String startTime, String endTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> supplierSalesStatisticsGoodsType(String clinicId, String startTime, String endTime); | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsType(String clinicId, String startTime, String endTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCount(String clinicId, String startTime, String endTime, String goodsName); | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCount(String clinicId, String startTime, String endTime, String goodsName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCountMonth(String clinicId, String startTime, String endTime, String goodsName); | 
|---|
|  |  |  | List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountMonth(String clinicId, String startTime, String endTime, String goodsName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsTypeVO> supplierSalesStatisticsGoodsType(String clinicId, String startTime, String endTime) { | 
|---|
|  |  |  | return this.baseMapper.supplierSalesStatisticsGoodsType(clinicId,startTime,endTime); | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsTypeVO> clinicSalesStatisticsGoodsType(String clinicId, String startTime, String endTime) { | 
|---|
|  |  |  | return this.baseMapper.clinicSalesStatisticsGoodsType(clinicId,startTime,endTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCount(String clinicId, String startTime, String endTime, String goodsName) { | 
|---|
|  |  |  | return this.baseMapper.supplierSalesStatisticsGoodsCount(clinicId,startTime,endTime,goodsName); | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCount(String clinicId, String startTime, String endTime, String goodsName) { | 
|---|
|  |  |  | return this.baseMapper.clinicSalesStatisticsGoodsCount(clinicId,startTime,endTime,goodsName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCountMonth(String clinicId, String startTime, String endTime, String goodsName) { | 
|---|
|  |  |  | return this.baseMapper.supplierSalesStatisticsGoodsCountMonth(clinicId,startTime,endTime,goodsName); | 
|---|
|  |  |  | public List<ClinicSalesStatisticsGoodsCountVO> clinicSalesStatisticsGoodsCountMonth(String clinicId, String startTime, String endTime, String goodsName) { | 
|---|
|  |  |  | return this.baseMapper.clinicSalesStatisticsGoodsCountMonth(clinicId,startTime,endTime,goodsName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|
|  |  |  | and t1.status in (3,4,5) | 
|---|
|  |  |  | and t1.pay_time between #{startTime} and #{endTime} | 
|---|
|  |  |  | <if test="query.roleType != null and query.roleType == 4"> | 
|---|
|  |  |  | <if test="roleType != null and roleType == 4"> | 
|---|
|  |  |  | and t1.supplier_id = #{supplierAndClinicId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="query.roleType != null and query.roleType == 5"> | 
|---|
|  |  |  | <if test="roleType != null and roleType == 5"> | 
|---|
|  |  |  | and t1.clinic_id = #{supplierAndClinicId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | group by date_format(t1.pay_time, '%m.%d') | 
|---|
|  |  |  | 
|---|
|  |  |  | where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|
|  |  |  | and t1.status in (3,4,5) | 
|---|
|  |  |  | and t1.pay_time between #{startTime} and #{endTime} | 
|---|
|  |  |  | <if test="query.roleType != null and query.roleType == 4"> | 
|---|
|  |  |  | <if test="roleType != null and roleType == 4"> | 
|---|
|  |  |  | and t1.supplier_id = #{supplierAndClinicId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="query.roleType != null and query.roleType == 5"> | 
|---|
|  |  |  | <if test="roleType != null and roleType == 5"> | 
|---|
|  |  |  | and t1.clinic_id = #{supplierAndClinicId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | group by date_format(t1.pay_time, '%m.%d') | 
|---|
|  |  |  | 
|---|
|  |  |  | select count(1) | 
|---|
|  |  |  | from t_sys_order tso | 
|---|
|  |  |  | left join t_sys_order_goods tsog on tso.id = tsog.order_id | 
|---|
|  |  |  | left join t_erp_goods teg on tepg.goods_id = teg.id | 
|---|
|  |  |  | left join t_erp_goods teg on tsog.goods_id = teg.id | 
|---|
|  |  |  | where tso.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|
|  |  |  | and tso.clinic_id in <foreach collection="clinicIds" open="(" separator="," item="id" close=")">#{id}</foreach> | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | 
|---|
|  |  |  | select count(1) | 
|---|
|  |  |  | from t_sys_order tso | 
|---|
|  |  |  | left join t_sys_order_goods tsog on tso.id = tsog.order_id | 
|---|
|  |  |  | left join t_erp_goods teg on tepg.goods_id = teg.id | 
|---|
|  |  |  | left join t_erp_goods teg on tsog.goods_id = teg.id | 
|---|
|  |  |  | where tso.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|
|  |  |  | and tso.clinic_id in <foreach collection="clinicIds" open="(" separator="," item="id" close=")">#{id}</foreach> | 
|---|
|  |  |  | group by teg.type_id | 
|---|
|  |  |  | 
|---|
|  |  |  | and pay_time between #{startTime} and #{endTime} | 
|---|
|  |  |  | and clinic_id = #{clinicId} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="supplierSalesStatisticsGoodsType" | 
|---|
|  |  |  | <select id="clinicSalesStatisticsGoodsType" | 
|---|
|  |  |  | resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsTypeVO"> | 
|---|
|  |  |  | select count(1), tegt.type_name | 
|---|
|  |  |  | from t_sys_order tso | 
|---|
|  |  |  | 
|---|
|  |  |  | group by teg.type_id | 
|---|
|  |  |  | order by count(1) desc | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="supplierSalesStatisticsGoodsCount" | 
|---|
|  |  |  | <select id="clinicSalesStatisticsGoodsCount" | 
|---|
|  |  |  | resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsCountVO"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | date_format(t1.pay_time, '%m.%d') as `time`, | 
|---|
|  |  |  | date_format(t1.pay_time, '%Y-%m-%d') as payTime, | 
|---|
|  |  |  | sum(t2.purchase_count) as goodsCount | 
|---|
|  |  |  | sum(t2.sale_count) as goodsCount | 
|---|
|  |  |  | from t_sys_order t1 | 
|---|
|  |  |  | left join t_sys_order_goods t2 on t1.id = t2.order_id | 
|---|
|  |  |  | where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|
|  |  |  | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | group by date_format(t1.pay_time, '%m.%d') | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="supplierSalesStatisticsGoodsCountMonth" | 
|---|
|  |  |  | <select id="clinicSalesStatisticsGoodsCountMonth" | 
|---|
|  |  |  | resultType="com.ruoyi.system.vo.ClinicSalesStatisticsGoodsCountVO"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | date_format(t1.pay_time, '%Y.%m') as `time`, | 
|---|
|  |  |  | sum(t2.purchase_count) as goodsCount | 
|---|
|  |  |  | sum(t2.sale_count) as goodsCount | 
|---|
|  |  |  | from t_sys_order t1 | 
|---|
|  |  |  | left join t_sys_order_goods t2 on t1.id = t2.order_id | 
|---|
|  |  |  | where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} | 
|---|