package com.dayou.controller;

import com.dayou.annotation.DataPermission;
import com.dayou.annotation.IgnoreAuth;
import com.dayou.dto.ItemDTO;
import com.dayou.vo.BrokerageSequenceVO;
import com.dayou.vo.ItemVO;
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.IItemBrokerageSequenceService;
import com.dayou.entity.ItemBrokerageSequence;
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 java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

import static com.dayou.common.Constants.MANAGER_OFFICE;

/**
 * 项目提成流水
 *
 * @author wucl
 * @since 2023-03-03
 */
@RestController
@RequestMapping("itemBrokerageSequence")
@Slf4j
public class ItemBrokerageSequenceController extends BaseController {
    @Autowired
    private IItemBrokerageSequenceService itemBrokerageSequenceService;

    /**
    * 项目提成流水列表
    */
    @DataPermission
    @GetMapping("")
    public RestResponse<Page<BrokerageSequenceVO>> page(BrokerageSequenceVO brokerageSequenceVO, Page page){
        Page<BrokerageSequenceVO> pages=itemBrokerageSequenceService.selectPage(page,brokerageSequenceVO);
        return RestResponse.data(pages);
    }

    /**
     * 项目提成结算抵扣
     */
    @DataPermission
    @GetMapping("/deduction")
    public RestResponse<List<BrokerageSequenceVO>> deduction(BrokerageSequenceVO brokerageSequenceVO){
        List<BrokerageSequenceVO> list = itemBrokerageSequenceService.deduction(brokerageSequenceVO);
        return RestResponse.data(list);
    }
    /**
     * 项目提成流水详情
     */
    @GetMapping("/{id}")
    public RestResponse<ItemBrokerageSequence> detail(@PathVariable Long id){
        ItemBrokerageSequence xItemBrokerageSequence =itemBrokerageSequenceService.detail(id);
        return RestResponse.data(xItemBrokerageSequence);
     }

    /**
     * 项目提成流水新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ItemBrokerageSequence itemBrokerageSequence) {
        Boolean ret = itemBrokerageSequenceService.add(itemBrokerageSequence);
        return RestResponse.data(ret);
    }

    /**
     * 项目提成流水更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ItemBrokerageSequence itemBrokerageSequence) {
        Boolean ret = itemBrokerageSequenceService.update(itemBrokerageSequence);
        return RestResponse.data(ret);
    }

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

    /**
     * 提成结算导出
     */
    @DataPermission
    @GetMapping("/export")
    public void exportData(BrokerageSequenceVO brokerageSequenceVO, HttpServletResponse response) throws IOException {
        List<BrokerageSequenceVO> list = itemBrokerageSequenceService.xList(brokerageSequenceVO);
        exportPlus(response,"提成结算",list,BrokerageSequenceVO.class);
    }

    /**
     * 提成结算接口，开发测试用
     * @return
     */
    @IgnoreAuth
    @GetMapping("/settle")
    public RestResponse<Set<Long>> settle(){
        itemBrokerageSequenceService.doAbleItemBrokerageSettle();
        Set<Long> longs = itemBrokerageSequenceService.doNonMarketerAheadSettle();
        return RestResponse.data(longs);
    }

}

