package cn.iocoder.yudao.module.member.controller.admin.carteenmoney;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.member.controller.admin.carteenmoney.vo.CarteenMoneyPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.carteenmoney.vo.CarteenMoneyRespVO;
import cn.iocoder.yudao.module.member.controller.admin.carteenmoney.vo.DeviceMoneyPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.carteenmoney.vo.DeviceMoneyRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.carteenmoney.CarteenMoneyDO;
import cn.iocoder.yudao.module.member.service.carteenmoney.CarteenMoneyService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;


@Tag(name = "管理后台 - 门店流水")
@RestController
@RequestMapping("/t/carteen-money")
@Validated
public class CarteenMoneyController {

    @Resource
    private CarteenMoneyService carteenMoneyService;

//    @PostMapping("/create")
//    @Operation(summary = "创建门店流水")
//    @PreAuthorize("@ss.hasPermission('t:carteen-money:create')")
//    public CommonResult<Long> createCarteenMoney(@Valid @RequestBody CarteenMoneySaveReqVO createReqVO) {
//        return success(carteenMoneyService.createCarteenMoney(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新门店流水")
//    @PreAuthorize("@ss.hasPermission('t:carteen-money:update')")
//    public CommonResult<Boolean> updateCarteenMoney(@Valid @RequestBody CarteenMoneySaveReqVO updateReqVO) {
//        carteenMoneyService.updateCarteenMoney(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除门店流水")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('t:carteen-money:delete')")
//    public CommonResult<Boolean> deleteCarteenMoney(@RequestParam("id") Long id) {
//        carteenMoneyService.deleteCarteenMoney(id);
//        return success(true);
//    }

    @GetMapping("/get")
    @Operation(summary = "获得门店流水")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('t:carteen-money:query')")
    public CommonResult<CarteenMoneyRespVO> getCarteenMoney(@RequestParam("id") Long id) {
        CarteenMoneyDO carteenMoney = carteenMoneyService.getCarteenMoney(id);
        return success(BeanUtils.toBean(carteenMoney, CarteenMoneyRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得门店流水分页")
    @PreAuthorize("@ss.hasPermission('t:carteen-money:query')")
    public CommonResult<PageResult<CarteenMoneyRespVO>> getCarteenMoneyPage(@Valid CarteenMoneyPageReqVO pageReqVO) {
        PageResult<CarteenMoneyDO> pageResult = carteenMoneyService.getCarteenMoneyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CarteenMoneyRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出门店流水 Excel")
    @PreAuthorize("@ss.hasPermission('t:carteen-money:export')")
    @OperateLog(type = EXPORT)
    public void exportCarteenMoneyExcel(@Valid CarteenMoneyPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CarteenMoneyDO> list = carteenMoneyService.getCarteenMoneyPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "门店流水.xls", "数据", CarteenMoneyRespVO.class,
                        BeanUtils.toBean(list, CarteenMoneyRespVO.class));
    }


    @GetMapping("/device/money")
    @Operation(summary = "获得门店设备流水")
    @PreAuthorize("@ss.hasPermission('t:carteen-money:query')")
    public CommonResult<DeviceMoneyRespVO> getCarteenMoneyDevicePage(@Valid DeviceMoneyPageReqVO pageReqVO) {
        return success(carteenMoneyService.getCarteenMoneyDevice(pageReqVO));
    }


}