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

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionEquInfo;
import cn.iocoder.yudao.module.inspection.service.IInspectionEquInfoService;

/**
 * equInfoController
 *
 * @author zcy
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/admin-api/system/equInfo")
public class InspectionEquInfoController extends BaseController
{
    @Autowired
    private IInspectionEquInfoService inspectionEquInfoService;
   @Autowired
   private AppInspectionPartnerService partnerService;

    /**
     * 查询equInfo列表
     */
    @GetMapping("/list")
    public CommonResult list(Integer pageNum,Integer pageSize,InspectionEquInfo inspectionEquInfo) throws Exception {

        Page page =new Page(pageNum,pageSize);
        IPage<InspectionEquInfo> list = inspectionEquInfoService.selectInspectionEquInfoList(page,inspectionEquInfo);
        return success(list);
    }

    /**
     * 导出equInfo列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionEquInfo inspectionEquInfo)
    {
        Page page =new Page(1,100000);
        IPage<InspectionEquInfo> list = inspectionEquInfoService.selectInspectionEquInfoList(page,inspectionEquInfo);
        ExcelUtil<InspectionEquInfo> util = new ExcelUtil<InspectionEquInfo>(InspectionEquInfo.class);
        util.exportExcel(response, list.getRecords(), "equInfo数据");
    }

    /**
     * 获取equInfo详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionEquInfoService.selectInspectionEquInfoById(id));
    }

    /**
     * 新增equInfo
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody InspectionEquInfo inspectionEquInfo) throws Exception {
        ShopMallPartners partners = partnerService.shopInfo();
        inspectionEquInfo.setPartnerId(partners.getPartnerId());
        return toAjax(inspectionEquInfoService.insertInspectionEquInfo(inspectionEquInfo));
    }

    /**
     * 修改equInfo
     */
    @PostMapping("/edit")
    public CommonResult edit(@RequestBody InspectionEquInfo inspectionEquInfo) throws Exception {
        ShopMallPartners partners = partnerService.shopInfo();
        InspectionEquInfo inspectionEquInfo1 = inspectionEquInfoService.selectInspectionEquInfoById(inspectionEquInfo.getId());
        if (!partners.getPartnerId().equals(inspectionEquInfo1.getPartnerId())){
            return null;
        }
        return toAjax(inspectionEquInfoService.updateInspectionEquInfo(inspectionEquInfo));
    }

    /**
     * 删除equInfo
     */
	@DeleteMapping("/{id}")
    public CommonResult remove(@PathVariable Long id) throws Exception {
        ShopMallPartners partners = partnerService.shopInfo();
        InspectionEquInfo inspectionEquInfo1 = inspectionEquInfoService.selectInspectionEquInfoById(id);
        if (!partners.getPartnerId().equals(inspectionEquInfo1.getPartnerId())){
            return null;
        }
        return toAjax(inspectionEquInfoService.deleteInspectionEquInfoById(id));
    }
}
