package com.dayou.controller;

import com.dayou.annotation.DataPermission;
import com.dayou.vo.BrokerageDetailVO;
import com.dayou.vo.BrokerageGeneralVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IItemBrokerageDetailService;
import com.dayou.entity.ItemBrokerageDetail;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 项目提成明细
 *
 * @author wucl
 * @since 2023-03-03
 */
@RestController
@RequestMapping("itemBrokerageDetail")
@Slf4j
public class ItemBrokerageDetailController extends BaseController {
    @Autowired
    private IItemBrokerageDetailService itemBrokerageDetailService;

    /**
    * 项目提成明细列表
    */
    @DataPermission
    @GetMapping("")
    public RestResponse<Page<BrokerageDetailVO>> page(BrokerageDetailVO itemBrokerageDetailVO, Page page){
        Page<BrokerageDetailVO> pages=itemBrokerageDetailService.selectPage(page,itemBrokerageDetailVO);
        return RestResponse.data(pages);
    }

    /**
     * 提成明细导出
     */
    @DataPermission
    @GetMapping("/export")
    public void exportData(BrokerageDetailVO itemBrokerageDetailVO, HttpServletResponse response) throws IOException {
        List<BrokerageDetailVO> list = itemBrokerageDetailService.xList(itemBrokerageDetailVO);
        exportPlus(response,"提成明细",list,BrokerageDetailVO.class);
    }
    /**
     * 项目提成明细详情
     */
    @GetMapping("/{id}")
    public RestResponse<ItemBrokerageDetail> detail(@PathVariable Long id){
        ItemBrokerageDetail xItemBrokerageDetail =itemBrokerageDetailService.detail(id);
        return RestResponse.data(xItemBrokerageDetail);
     }

    /**
     * 项目提成明细新增
     */
    @Deprecated
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ItemBrokerageDetail itemBrokerageDetail) {
        Boolean ret = itemBrokerageDetailService.add(itemBrokerageDetail);
        return RestResponse.data(ret);
    }

    /**
     * 项目提成明细更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ItemBrokerageDetail itemBrokerageDetail) {
        Boolean ret = itemBrokerageDetailService.update(itemBrokerageDetail);
        return RestResponse.data(ret);
    }

    /**
     * 项目提成明细删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = itemBrokerageDetailService.delete(id);
        return RestResponse.data(ret);
    }


}

