package cn.iocoder.yudao.module.contract.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.contract.entity.InspectionContract;
import cn.iocoder.yudao.module.contract.service.IInspectionContractService;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.service.AppInspectionPartnerService;
import cn.iocoder.yudao.module.shop.entity.ShopMallPartners;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * inspectionContractController
 *
 * @author ruoyi
 * @date 2023-08-31
 */
@RestController
@RequestMapping("/admin-api/contract/inspectionContract")
public class InspectionContractController extends BaseController
{
    @Autowired
    private IInspectionContractService inspectionContractService;
    @Autowired
    private AppInspectionPartnerService partnerList;

    /**
     * 查询inspectionContract列表
     */
//    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:list')")
    @GetMapping("/list")
    public CommonResult list(InspectionContract inspectionContract,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionContract> page = new Page<>(pageNum, pageSize);
        IPage<InspectionContract> list = inspectionContractService.selectInspectionContractList(page,inspectionContract);
        return success(list);
    }

    /**
     * 导出inspectionContract列表
     */
//    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:export')")
//    @Log(title = "inspectionContract", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionContract inspectionContract,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionContract> page = new Page<>(pageNum, pageSize);
        IPage<InspectionContract> list = inspectionContractService.selectInspectionContractList(page,inspectionContract);
        ExcelUtil<InspectionContract> util = new ExcelUtil<InspectionContract>(InspectionContract.class);
        util.exportExcel(response, list.getRecords(), "inspectionContract数据");
    }

    /**
     * 获取inspectionContract详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionContractService.selectInspectionContractById(id));
    }

    /**
     * 新增inspectionContract
     */
//    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:add')")
//    @Log(title = "inspectionContract", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody InspectionContract inspectionContract)
    {
        return toAjax(inspectionContractService.insertInspectionContract(inspectionContract));
    }

    /**
     * 修改inspectionContract
     */
//    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:edit')")
//    @Log(title = "inspectionContract", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody InspectionContract inspectionContract)
    {
        return toAjax(inspectionContractService.updateInspectionContract(inspectionContract));
    }

    /**
     * 删除inspectionContract
     */
//    @PreAuthorize("@ss.hasPermi('contract:inspectionContract:remove')")
//    @Log(title = "inspectionContract", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionContractService.deleteInspectionContractByIds(ids));
    }


    /**
     * 授权管理
     */

    @GetMapping("/partnerGetWtList")
    public CommonResult partnerGetWtList(InspectionContract inspectionContract,
                                         @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                         @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) throws Exception {
        ShopMallPartners partners = partnerList.shopInfo();
        inspectionContract.setPartnerId(partners.getPartnerId());
        Page<InspectionContract> page = new Page<>(pageNum, pageSize);
        IPage<InspectionContract> list = inspectionContractService.partnerGetWtList(page,inspectionContract);
        return success(list);
    }
}
