package cn.newfeifan.mall.module.distri.controller.admin.consumptionerrorlog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

import cn.newfeifan.mall.module.distri.controller.admin.consumptionerrorlog.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.consumptionerrorlog.ConsumptionErrorLogDO;
import cn.newfeifan.mall.module.distri.service.consumptionerrorlog.ConsumptionErrorLogService;

@Tag(name = "管理后台 - 消费分异动日志记录")
@RestController
@RequestMapping("/distri/consumption-error-log")
@Validated
public class ConsumptionErrorLogController {

    @Resource
    private ConsumptionErrorLogService consumptionErrorLogService;

    @GetMapping("/get")
    @Operation(summary = "获得消费分异动日志记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('distri:consumption-error-log:query')")
    public CommonResult<ConsumptionErrorLogRespVO> getConsumptionErrorLog(@RequestParam("id") Long id) {
        ConsumptionErrorLogDO consumptionErrorLog = consumptionErrorLogService.getConsumptionErrorLog(id);
        return success(BeanUtils.toBean(consumptionErrorLog, ConsumptionErrorLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得消费分异动日志记录分页")
    @PreAuthorize("@ss.hasPermission('distri:consumption-error-log:query')")
    public CommonResult<PageResult<ConsumptionErrorLogRespVO>> getConsumptionErrorLogPage(@Valid ConsumptionErrorLogPageReqVO pageReqVO) {
        PageResult<ConsumptionErrorLogDO> pageResult = consumptionErrorLogService.getConsumptionErrorLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ConsumptionErrorLogRespVO.class));
    }

    @GetMapping("/testCalcConsumptionErrorLog")
    @Operation(summary = "测试计算消费分异动日志记录")
    public CommonResult<String> testCalcConsumptionErrorLog() {
        consumptionErrorLogService.calcEveryDayConsumptionPointsErrorLog();
        return success("success");
    }

}