package com.ruoyi.web.controller.warehouse.agreement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems;
import com.ruoyi.warehouseBusiness.domain.dto.TWarehouseAgreementitem;
import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementitemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 仓储费明细表Controller
 *
 * @author ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/warehouseBusiness/agreementitems")
public class TWarehouseAgreementitemsController extends BaseController {
    @Autowired
    private ITWarehouseAgreementitemsService tWarehouseAgreementitemsService;

    /**
     * 查询仓储费明细表列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseAgreementitems tWarehouseAgreementitems) {
        startPage();
        List<Map<String, Object>> list = tWarehouseAgreementitemsService.selectTWarehouseAgreementitemsList1(tWarehouseAgreementitems);
        return getDataTable(list);
    }

    /**
     * 查询仓储费明细表列表
     */
    @GetMapping("/warehousebills/list")
    public TableDataInfo list(TWarehouseAgreementitem tWarehouseAgreementitem) {
        if(null!=tWarehouseAgreementitem.getfTaskType() &&  tWarehouseAgreementitem.getfTaskType() == 1 ){
            if(tWarehouseAgreementitem.getfFleet()==null || tWarehouseAgreementitem.getfFleet().equals("") ){
                List<Map<String, Object>> list = new ArrayList<>();
                return getDataTable(list);
            }
        } else if(null!=tWarehouseAgreementitem.getfTaskType() &&  tWarehouseAgreementitem.getfTaskType() == 2) {
            if(tWarehouseAgreementitem.getfLabour()==null || tWarehouseAgreementitem.getfLabour().equals("") ){
                List<Map<String, Object>> list = new ArrayList<>();
                return getDataTable(list);
            }
        }
        startPage();
        List<Map<String, Object>> list = tWarehouseAgreementitemsService.selectTWarehouseAgreementitemList(tWarehouseAgreementitem);
        return getDataTable(list);
    }


    /**
     * 导出仓储费明细表列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:export')")
    @Log(title = "仓储费明细表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWarehouseAgreementitems tWarehouseAgreementitems) {
        List<TWarehouseAgreementitems> list = tWarehouseAgreementitemsService.selectTWarehouseAgreementitemsList(tWarehouseAgreementitems);
        ExcelUtil<TWarehouseAgreementitems> util = new ExcelUtil<TWarehouseAgreementitems>(TWarehouseAgreementitems.class);
        return util.exportExcel(list, "agreementitems");
    }

    /**
     * 获取仓储费明细表详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehouseAgreementitemsService.selectTWarehouseAgreementitemsById(fId));
    }

    /**
     * 新增仓储费明细表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:add')")
    @Log(title = "仓储费明细表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWarehouseAgreementitems tWarehouseAgreementitems) {
        return toAjax(tWarehouseAgreementitemsService.insertTWarehouseAgreementitems(tWarehouseAgreementitems));
    }

    /**
     * 修改仓储费明细表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:edit')")
    @Log(title = "仓储费明细表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehouseAgreementitems tWarehouseAgreementitems) {
        return toAjax(tWarehouseAgreementitemsService.updateTWarehouseAgreementitems(tWarehouseAgreementitems));
    }

    /**
     * 删除仓储费明细表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:agreementitems:remove')")
    @Log(title = "仓储费明细表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tWarehouseAgreementitemsService.deleteTWarehouseAgreementitemsByIds(fIds));
    }
}
