| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TCrmSupplier; |
| | | import com.ruoyi.system.model.TErpProcurement; |
| | | import com.ruoyi.system.query.DataStatisticsQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCrmSupplierService; |
| | | import com.ruoyi.system.service.TErpProcurementService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @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; |
| | | |
| | | @Autowired |
| | | public DataStatisticsController(TErpProcurementService erpProcurementService, TokenService tokenService, ISysUserService sysUserService, TCrmSupplierService crmSupplierService) { |
| | | this.erpProcurementService = erpProcurementService; |
| | | this.tokenService = tokenService; |
| | | this.sysUserService = sysUserService; |
| | | this.crmSupplierService = crmSupplierService; |
| | | } |
| | | |
| | | /** |
| | | * 供应商采购统计 |
| | | */ |
| | | @ApiOperation(value = "供应商采购统计") |
| | | @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(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; |
| | | } |
| | | |
| | | 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 { |
| | | // orderQuantity.stream(). |
| | | // map.put("commissionMoney", ); |
| | | // map.put("orderMoney", ); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | } |