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.common.log.annotation.SysLog;
import com.kxs.product.api.model.KxsGdOrder;
import com.kxs.product.api.model.KxsGdReport;
import com.kxs.product.biz.constant.enums.GdReportEnum;
import com.kxs.product.biz.service.KxsGdOrderService;
import com.kxs.product.biz.service.KxsGdReportService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

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



    /**
     * 广电报备-列表
     *
     * @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(param.getStatus() != null, KxsGdReport::getStatus, param.getStatus())
                        .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 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);
    }

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

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

    /**
     * 广电报备-作废
     *
     * @param param 实体对象
     * @return 广电报备-作废
     */
    @SysLog("广电报备作废")
    @PutMapping("/cancel")
//    @PreAuthorize("@pms.hasPermission('sys_gd_report_cancel')")
    public R cancel(@RequestBody KxsGdReport param) {

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

    /**
     * 广电报备-查询电渠订单列表
     *
     */
    @GetMapping("/gdOrderPage")
//    @PreAuthorize("@pms.hasPermission('sys_gd_order_list')")
    public R gdOrderPage(Page<KxsGdOrder> page, @ParameterObject KxsGdOrder param) {

        return R.ok(kxsGdOrderService.getByPage(page, param));
    }

    /**
     * 广电报备-人工推送激活
     *
     */
    @SysLog("广电报备人工推送激活")
    @GetMapping("/toAct")
//    @PreAuthorize("@pms.hasPermission('sys_gd_to_act')")
    public R toAct(@RequestParam("id") Integer id) {

        return R.ok(kxsGdOrderService.toAct(id));
    }

    /**
     * 广电报备-查询电渠订单接口
     *
     */
    @PostMapping("/onlineSimOrder")
//    @PreAuthorize("@pms.hasPermission('sys_gd_online_sim_order')")
    public R onlineSimOrder(@RequestBody List<String> orderNos) {

        return R.ok(kxsGdOrderService.onlineSimOrder(orderNos));
    }


}

