package com.dayou.controller;

import com.dayou.annotation.DataPermission;
import com.dayou.annotation.IgnoreAuth;
import com.dayou.vo.BrokerageGeneralVO;
import com.dayou.vo.BrokerageSequenceVO;
import org.apache.ibatis.annotations.Param;
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.IItemBrokerageGeneralService;
import com.dayou.entity.ItemBrokerageGeneral;
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("itemBrokerageGeneral")
@Slf4j
public class ItemBrokerageGeneralController extends BaseController {
    @Autowired
    private IItemBrokerageGeneralService itemBrokerageGeneralService;

    /**
    * 项目提成总表列表
    */
    @DataPermission
    @GetMapping("")
    public RestResponse<Page<BrokerageGeneralVO>> page(BrokerageGeneralVO brokerageGeneralVO, Page page){
        Page<BrokerageGeneralVO> pages=itemBrokerageGeneralService.selectPage(page,brokerageGeneralVO);
        return RestResponse.data(pages);
    }

    /**
     * 提成总览导出
     */
    @DataPermission
    @GetMapping("/export")
    public void exportData(BrokerageGeneralVO brokerageGeneralVO, HttpServletResponse response) throws IOException {
        List<BrokerageGeneralVO> list = itemBrokerageGeneralService.xList(brokerageGeneralVO);
        exportPlus(response,"提成总览",list,BrokerageGeneralVO.class);
    }
    /**
     * 项目提成总表详情
     */
    @GetMapping("/{id}")
    public RestResponse<ItemBrokerageGeneral> detail(@PathVariable Long id){
        ItemBrokerageGeneral xItemBrokerageGeneral =itemBrokerageGeneralService.detail(id);
        return RestResponse.data(xItemBrokerageGeneral);
     }

    /**
     * 项目提成总表新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ItemBrokerageGeneral itemBrokerageGeneral) {
        Boolean ret = itemBrokerageGeneralService.add(itemBrokerageGeneral);
        return RestResponse.data(ret);
    }

    /**
     * 项目提成总表更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ItemBrokerageGeneral itemBrokerageGeneral) {
        Boolean ret = itemBrokerageGeneralService.update(itemBrokerageGeneral);
        return RestResponse.data(ret);
    }

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

    /**
     * 客户经理预提状态修改
     * @param id
     * @param marketerStatus
     * @return
     */
    @GetMapping("/marketer/status")
    public RestResponse<Boolean> updateMarketerStatus(Long id,Boolean marketerStatus){
        Boolean result = itemBrokerageGeneralService.updateMarketerStatus(id,marketerStatus);
        return RestResponse.data(result);
    }

}

