package cn.ezhizao.project.business.carrier.controller;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.carrier.domain.BizCarrier;
import cn.ezhizao.project.business.carrier.domain.BizCarrierReject;
import cn.ezhizao.project.business.carrier.service.IBizCarrierRejectService;
import cn.ezhizao.project.business.carrier.service.IBizCarrierService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 企业租户Controller
 *
 * @author ezhizao
 * @date 2024-01-09
 */
@RestController
@RequestMapping("/business/carrierReject")
public class BizCarrierRejectController extends BaseController
{
    @Resource
    private IBizCarrierRejectService bizCarrierRejectService;
    @Resource
    private IBizCarrierService carrierService;
    /**
     * 查询企业租户列表
     */
    @Log(title = "载具废弃查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizCarrierReject bizCarrierReject) throws NoSuchFieldException, IllegalAccessException
    {
        startPage();
        List<BizCarrierReject> list = bizCarrierRejectService.getList(bizCarrierReject);
        return getDataTable(list);
    }

    /**
     * 导出企业租户列表
     */
    @PreAuthorize("@ss.hasPermi('business:carrierReject:export')")
    @Log(title = "载具废弃导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCarrierReject bizCarrierReject) throws NoSuchFieldException, IllegalAccessException
    {
        List<BizCarrierReject> list = bizCarrierRejectService.getList(bizCarrierReject);
        ExcelUtil<BizCarrierReject> util = new ExcelUtil<BizCarrierReject>(BizCarrierReject.class);
        util.exportExcel(response, list, "企业租户数据");
    }

    /**
     * 获取企业租户详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:carrierReject:query')")
    @Log(title = "载具废弃查询详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCarrierRejectService.getById(id));
    }

    /**
     * 新增企业租户
     */
    @PreAuthorize("@ss.hasPermi('business:carrierReject:add')")
    @Log(title = "载具废弃保存", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save")
    public AjaxResult add(@RequestBody BizCarrierReject bizCarrierReject) throws NoSuchFieldException, IllegalAccessException
    {

            BizCarrier carrier = new BizCarrier();
            carrier.setId(bizCarrierReject.getCarrierId());
            BizCarrier bizCarrier = carrierService.getList(carrier).get(0);
            bizCarrier.setIsAbandoned(bizCarrierReject.getIsAbandoned());
            carrierService.updateById(bizCarrier);

        return toAjax(bizCarrierRejectService.save(bizCarrierReject));
    }

    /**
     * 修改企业租户
     */
    @PreAuthorize("@ss.hasPermi('business:reject:edit')")
    @Log(title = "载具废弃修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCarrierReject bizCarrierReject) throws NoSuchFieldException, IllegalAccessException
    {
        return toAjax(bizCarrierRejectService.updateById(bizCarrierReject));
    }

    /**
     * 删除企业租户
     */
    @PreAuthorize("@ss.hasPermi('business:reject:remove')")
    @Log(title = "载具废弃删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCarrierRejectService.removeBatchByIds(ids));
    }
}
