package org.dromara.payment.task.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.payment.task.domain.vo.MerTaskEnrollVo;
import org.dromara.payment.task.domain.bo.MerTaskEnrollBo;
import org.dromara.payment.task.service.IMerTaskEnrollService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 任务的报名
 * 前端访问路由地址为:/payment/taskEnroll
 *
 * @author LionLi
 * @date 2024-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/taskEnroll")
public class MerTaskEnrollController extends BaseController {

    private final IMerTaskEnrollService merTaskEnrollService;

    /**
     * 查询任务的报名列表
     */
//    @SaCheckPermission("payment:taskEnroll:list")
    @GetMapping("/list")
    public TableDataInfo<MerTaskEnrollVo> list(MerTaskEnrollBo bo, PageQuery pageQuery) {
        return merTaskEnrollService.queryPageList(bo, pageQuery);
    }

    /**
     * @description 交付查询 成功接单的用户
     * @author wuchuang
     * @param
     * @return
     * @time 2024/5/23 16:12
     */
    //    @SaCheckPermission("payment:taskEnroll:successlist")
    @GetMapping("/successlist")
    public TableDataInfo<MerTaskEnrollVo> successlist(MerTaskEnrollBo bo, PageQuery pageQuery) {
        return merTaskEnrollService.queryPageSuccessList(bo, pageQuery);
    }

    /**
     * 获取完工报告
     *
     * @param id 主键
     */
//    @SaCheckPermission("payment:taskEnroll:query")
    @GetMapping("/queryConfirmation")
    public R<MerTaskEnrollVo> queryConfirmation(@RequestParam(value = "id", required = true) Long id) {
        return R.ok(merTaskEnrollService.queryById(id));
    }


    /**
     * 审核 竞标人
     */
//    @SaCheckPermission("payment:taskEnroll:check")
    @Log(title = "任务审核竞标人", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/check")
    public R<Void> check(@Validated(EditGroup.class) @RequestBody MerTaskEnrollBo bo) {
        return toAjax(merTaskEnrollService.checkEnrollByBo(bo));
    }

    /**
     * 验收
     */
//    @SaCheckPermission("payment:taskEnroll:acceptance")
    @Log(title = "任务验收", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/acceptance")
    public R<Void> acceptance(@Validated(EditGroup.class) @RequestBody MerTaskEnrollBo bo) {
        return toAjax(merTaskEnrollService.acceptanceEnrollByBo(bo));
    }


    /**
     * 导出任务的报名列表
     */
    @SaCheckPermission("payment:taskEnroll:export")
    @Log(title = "任务的报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MerTaskEnrollBo bo, HttpServletResponse response) {
        List<MerTaskEnrollVo> list = merTaskEnrollService.queryList(bo);
        ExcelUtil.exportExcel(list, "任务的报名", MerTaskEnrollVo.class, response);
    }



    /**
     * 新增任务的报名
     */
    @SaCheckPermission("payment:taskEnroll:add")
    @Log(title = "任务的报名", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MerTaskEnrollBo bo) {
        return toAjax(merTaskEnrollService.insertByBo(bo));
    }

    /**
     * 修改任务的报名
     */
    @SaCheckPermission("payment:taskEnroll:edit")
    @Log(title = "任务的报名", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MerTaskEnrollBo bo) {
        return toAjax(merTaskEnrollService.updateByBo(bo));
    }

    /**
     * 删除任务的报名
     *
     * @param ids 主键串
     */
    @SaCheckPermission("payment:taskEnroll:remove")
    @Log(title = "任务的报名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(merTaskEnrollService.deleteWithValidByIds(List.of(ids), true));
    }
}
