package com.kxs.product.biz.controller.admin;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.common.idempotent.annotation.Idempotent;
import com.kxs.product.api.model.KxsGdReport;
import com.kxs.product.biz.constant.enums.GdReportEnum;
import com.kxs.product.biz.service.KxsGdReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 产品模块(SysGd)控制层
 *
 * @author 系统
 * @since 2024-04-23 10:44:27
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sysGd")
public class SysGdController {

    /**
     * 服务对象
     */
    private final KxsGdReportService kxsGdReportService;



    /**
     * 广电报备-列表
     *
     * @param page 分页对象
     * @param param 查询实体
     * @return 广电报备-列表
     */
    @GetMapping("/page")
    public R page(Page<KxsGdReport> page, KxsGdReport param) {
        return R.ok(kxsGdReportService.page(page,
                Wrappers.<KxsGdReport>lambdaQuery().eq(StrUtil.isNotBlank(param.getGdSn()),KxsGdReport::getGdSn, param.getGdSn())
                        .eq(KxsGdReport::getStatus, GdReportEnum.REPORT.getType())
                        .eq(param.getPutType() != null, KxsGdReport::getPutType, param.getPutType())
                        .eq(StrUtil.isNotBlank(param.getGdMobile()), KxsGdReport::getGdMobile, param.getGdMobile())
                        .eq(StrUtil.isNotBlank(param.getUserCode()), KxsGdReport::getUserCode, param.getUserCode())
                        .eq(param.getIsCheck() != null, KxsGdReport::getIsCheck, param.getIsCheck())
                        .orderByDesc(KxsGdReport::getId)
                ));
    }


    /**
     * 广电报备-编辑
     *
     * @param param 实体对象
     * @return 广电报备-编辑
     */
//    @PreAuthorize("@pms.hasPermission('sys_gd_report_edit')")
    @PutMapping("/update")
    public R update(@RequestBody KxsGdReport param) {

        return R.ok(kxsGdReportService.updateData(param));
    }

    /**
     * 广电报备-匹配数据
     *
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 广电报备-编辑
     */
    @Idempotent(key = "#startTime", expireTime = 15, info = "请于15秒后重试")
//    @PreAuthorize("@pms.hasPermission('sys_gd_report_check')")
    @GetMapping("/check")
    public R check(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {

        return kxsGdReportService.checkGdData(startTime, endTime);
    }





}

