package cn.iocoder.yudao.module.system.controller.admin.yk;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.yk.vo.YkDeliveryStatsDetailReqVO;
import cn.iocoder.yudao.module.system.controller.admin.yk.vo.deliveryPerson.*;
import cn.iocoder.yudao.module.system.dal.dataobject.yk.YkDeliveryStaffInfoDO;
import cn.iocoder.yudao.module.system.service.yk.DeliveryPersonInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.Date;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 送餐员信息")
@RestController
@Validated
public class DeliveryStaffController {

    @Resource
    private DeliveryPersonInfoService deliveryPersonInfoService;

    @PostMapping("/ykCenter/delivery/staff/add")
    @Operation(summary = "创建送餐员信息")
    @TenantIgnore
    public CommonResult<Long> createDeliveryPersonInfo(@RequestBody DeliveryPersonInfoCreateReqVO createReqVO) {
        return success(deliveryPersonInfoService.createDeliveryPersonInfo(createReqVO));
    }


    @PutMapping("/ykCenter/delivery/staff/update")
    @Operation(summary = "更新送餐员信息")
    @TenantIgnore
    public CommonResult<Boolean> updateDeliveryPersonInfo(@Valid @RequestBody DeliveryPersonInfoUpdateReqVO updateReqVO) {
        deliveryPersonInfoService.updateDeliveryPersonInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/ykCenter/delivery/staff/delete")
    @Operation(summary = "删除送餐员信息")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteDeliveryPersonInfo(@RequestParam("id") Long id) {
        deliveryPersonInfoService.deleteDeliveryPersonInfo(id);
        return success(true);
    }

//    @GetMapping("/ykCenter/delivery/stats/detail")
//    @Operation(summary = "获得送餐员信息")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @TenantIgnore
//    public CommonResult<DeliveryPersonInfoRespVO> getDeliveryPersonInfo(@RequestParam("id") Long id) {
//        YkDeliveryStaffInfoDO deliveryPersonInfo = deliveryPersonInfoService.getDeliveryPersonInfo(id);
//        return success(BeanUtils.toBean(deliveryPersonInfo, DeliveryPersonInfoRespVO.class));
//    }

    @GetMapping("/ykCenter/delivery/stats/detail")
    @Operation(summary = "获取送餐统计详情")
    @TenantIgnore
    public CommonResult<Map<String, Object>> getDeliveryStatsDetail(@Valid YkDeliveryStatsDetailReqVO reqVO) {
        Map<String, Object> result = deliveryPersonInfoService.getDeliveryStatsDetail(reqVO);
        return success(result);
    }


    @GetMapping("/ykCenter/meal/stats/range")
    @Operation(summary = "获取送餐统计详情（时间段）")
    @TenantIgnore
    public CommonResult<Map<String, Object>> getDeliveryStatsRangeDetail(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate,@RequestParam(value = "tenantId",required = false) Long tenantId) {
        tenantId = tenantId == null ? TenantContextHolder.getTenantId() : tenantId;
        Map<String, Object> result = deliveryPersonInfoService.getDeliveryStatsRangeDetail(startDate,endDate,tenantId);
        return success(result);
    }

    @GetMapping("/ykCenter/meal/stats")
    @Operation(summary = "获取送餐统计详情(日)")
    @TenantIgnore
    public CommonResult<Map<String, Object>> getDeliveryStatsRangeDetail(@RequestParam("date") String date,@RequestParam(value = "tenantId",required = false) Long tenantId) {
        tenantId = tenantId == null ? TenantContextHolder.getTenantId() : tenantId;
        Map<String, Object> result = deliveryPersonInfoService.getDeliveryStatsRangeDetail(date,tenantId);
        return success(result);
    }


    @GetMapping("/ykCenter/delivery/staff/manage-list")
    @Operation(summary = "获得送餐员信息分页")
    @TenantIgnore
    public CommonResult<PageResult<DeliveryPersonInfoRespVO>> getDeliveryPersonInfoPage(@Valid DeliveryPersonInfoPageReqVO pageVO) {
        PageResult<YkDeliveryStaffInfoDO> pageResult = deliveryPersonInfoService.getDeliveryPersonInfoPage(pageVO);
        return success(BeanUtils.toBean(pageResult, DeliveryPersonInfoRespVO.class));
    }



}