package cn.iocoder.yudao.module.cont.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.cont.entity.BaseContTemp;
import cn.iocoder.yudao.module.cont.service.BaseContTempService;
import cn.iocoder.yudao.module.cont.vo.BaseContTempPageReqVO;
import cn.iocoder.yudao.module.cont.vo.BaseContTempRespVO;
import cn.iocoder.yudao.module.cont.vo.BaseContTempSaveReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 合同模板")
@RestController
@RequestMapping("/base/cont-temp")
@Validated
public class BaseContTempController {

    @Resource
    private BaseContTempService contTempService;


    /**
     * 合同模板分页列表查询
     *
     * @param pageReqVO BaseContTempPageReqVO实体
     * @param pageNo    分页参数
     * @param pageSize  分页参数
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 10:46 2024/8/8
     **/
    @GetMapping("/page")
    @Operation(summary = "获得合同模板分页")
    @PreAuthorize("@ss.hasPermission('base:cont-temp:query')")
    public CommonResult<IPage<?>> getContTempPage(BaseContTempPageReqVO pageReqVO,
                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<BaseContTempRespVO> page = new Page<>(pageNo, pageSize);
        return success(contTempService.getContTempPage(pageReqVO, page));
    }

    /**
     * 创建合同模板
     *
     * @param createReqVO BaseContTempSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 17:11 2024/8/8
     **/
    @PostMapping("/create")
    @Operation(summary = "创建合同模板")
    @PreAuthorize("@ss.hasPermission('base:cont-temp:create')")
    public CommonResult<Boolean> createContTemp(@Valid @RequestBody BaseContTempSaveReqVO createReqVO) {
        contTempService.saveConTemp(createReqVO);
        return success(true);
    }

    /**
     * 编辑合同模板
     *
     * @param updateReqVO BaseContTempSaveReqVO
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 17:11 2024/8/8
     **/
    @PutMapping("/update")
    @Operation(summary = "更新合同模板")
    @PreAuthorize("@ss.hasPermission('base:cont-temp:update')")
    public CommonResult<Boolean> updateContTemp(@Valid @RequestBody BaseContTempSaveReqVO updateReqVO) {
        contTempService.saveConTemp(updateReqVO);
        return success(true);
    }

    /**
     * 删除合同模板
     *
     * @param id 合同模板id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 17:12 2024/8/8
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除合同模板")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:cont-temp:delete')")
    public CommonResult<Boolean> deleteContTemp(@RequestParam("id") String id) {
        contTempService.deleteContTemp(id);
        return success(true);
    }

    /**
     * 通过id查询合同模板
     *
     * @param id id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.cont.vo.BaseContTempRespVO>
     * @author PQZ
     * @date 17:12 2024/8/8
     **/
    @GetMapping("/get")
    @Operation(summary = "获得合同模板")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:cont-temp:query')")
    public CommonResult<BaseContTempRespVO> getContTemp(@RequestParam("id") String id) {
        BaseContTemp contTemp = contTempService.getContTemp(id);
        return success(BeanUtils.toBean(contTemp, BaseContTempRespVO.class));
    }


}