package com.dayou.controller;

import com.dayou.dto.CommissionDeclareDTO;
import com.dayou.vo.CommissionDeclareDetailVO;
import com.dayou.vo.CommissionDeclareTodoCheckVO;
import com.dayou.vo.CommissionDeclareVO;
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 org.springframework.web.bind.annotation.RestController;
import com.dayou.service.ICommissionDeclareService;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * 提成申报
 *
 * @author wucl
 * @since 2024-05-15
 */
@RestController
@RequestMapping("commissionDeclare")
@Slf4j
public class CommissionDeclareController extends BaseController {
    @Autowired
    private ICommissionDeclareService commissionDeclareService;

    /**
    * 大中型市场人员提成申报列表
    */
    @GetMapping("/major/market")
    public RestResponse<Page<CommissionDeclareVO>> majorMarketDeclarePage(CommissionDeclareVO commissionDeclare, Page page){
        Page<CommissionDeclareVO> pages=commissionDeclareService.majorMarketDeclarePage(page,commissionDeclare);
        return RestResponse.data(pages);
    }

    /**
     * 根据部门id查询大中型市场人员提成申报信息
     */
    @GetMapping("/major/market/byDepartment")
    public RestResponse<Page<CommissionDeclareVO>> majorMarketDeclarePageByDepartment(CommissionDeclareVO commissionDeclare, Page page){
        Page<CommissionDeclareVO> pages=commissionDeclareService.majorMarketDeclarePageByDepartment(page,commissionDeclare);
        return RestResponse.data(pages);
    }

    /**
     * 根据部门id查询大中型市场人员提成申报信息导出
     */
    @GetMapping("/major/market/byDepartment/export")
    public void majorMarketDeclarePageByDepartmentExport(CommissionDeclareVO commissionDeclare, HttpServletResponse response) throws IOException {
        List<CommissionDeclareVO> result = commissionDeclareService.majorMarketDeclarePageByDepartmentExport(commissionDeclare);
        exportPlus(response,"市场部门提成申报",result, CommissionDeclareVO.class);
    }

    /**
     * 大中型评估人员提成申报列表
     */
    @GetMapping("/major/evaluate")
    public RestResponse<Page<CommissionDeclareVO>> majorEvaluateDeclarePage(CommissionDeclareVO commissionDeclare, Page page){
        Page<CommissionDeclareVO> pages=commissionDeclareService.majorEvaluateDeclarePage(page,commissionDeclare);
        return RestResponse.data(pages);
    }

    /**
     * 根据部门id查询大中型评估人员提成申报信息
     */
    @GetMapping("/major/evaluate/byDepartment")
    public RestResponse<Page<CommissionDeclareVO>> majorEvaluateDeclarePageByDepartment(CommissionDeclareVO commissionDeclare, Page page){
        Page<CommissionDeclareVO> pages=commissionDeclareService.majorEvaluateDeclarePageByDepartment(page,commissionDeclare);
        return RestResponse.data(pages);
    }

    /**
     * 根据部门id查询大中型评估人员提成申报信息导出
     */
    @GetMapping("/major/evaluate/byDepartment/export")
    public void majorEvaluateDeclarePageByDepartmentExport(CommissionDeclareVO commissionDeclare, HttpServletResponse response) throws IOException {
        List<CommissionDeclareVO> result = commissionDeclareService.majorEvaluateDeclarePageByDepartmentExport(commissionDeclare);
        exportPlus(response,"评估部门提成申报",result, CommissionDeclareVO.class);
    }

    /**
     * 大中型提成申报
     * @param declareDTO
     * @return
     */

    @PostMapping("/major")
    public synchronized RestResponse<Boolean> commissionDeclare(@RequestBody @Valid CommissionDeclareDTO declareDTO){
        Long ret = commissionDeclareService.commissionDeclare(declareDTO);
        return RestResponse.data(ret!=null);
    }

    /**
     * 提成申报删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = commissionDeclareService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 申报详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public RestResponse<CommissionDeclareDetailVO> detail(@PathVariable("id") Long id){
        CommissionDeclareDetailVO detail = commissionDeclareService.detail(id);
        return RestResponse.data(detail);
    }

    /**
     * 大中型提成申报待审核列表
     */
    @GetMapping("/major/check")
    public RestResponse<Page<CommissionDeclareTodoCheckVO>> todoCheckPage(CommissionDeclareTodoCheckVO checkVO, Page page){
        Page<CommissionDeclareTodoCheckVO> ret = commissionDeclareService.todoCheckPage(page,checkVO);
        return RestResponse.data(ret);
    }

    /**
     * 大中型提成申报待审核列表(综合首页)
     */
    @GetMapping("/major/check/list")
    public RestResponse<List<CommissionDeclareTodoCheckVO>> todoCheckList(){
        List<CommissionDeclareTodoCheckVO> ret = commissionDeclareService.todoCheckList();
        return RestResponse.data(ret);
    }

    /**
     * 更新大中型绩效申报
     * @param declareDTO dto
     * @return RestResponse<Boolean>
     */
    @PutMapping("/major/check/update")
    public RestResponse<Boolean> updateMajorCommissionDeclare(@RequestBody CommissionDeclareDTO declareDTO) {
        return RestResponse.data(commissionDeclareService.updateMajorCommissionDeclare(declareDTO));
    }

    /**
     * 获取资产评估人员提成申报列表
     */
    @GetMapping("/assets/evaluate")
    public RestResponse<Page<CommissionDeclareVO>> assetsEvaluateDeclarePage(CommissionDeclareVO commissionDeclare, Page page){
        Page<CommissionDeclareVO> pages=commissionDeclareService.assetsEvaluateDeclarePage(page,commissionDeclare);
        return RestResponse.data(pages);
    }

    /**
     * 资产业务市场人员提成申报列表
     */
    @GetMapping("/assets/market")
    public RestResponse<Page<CommissionDeclareVO>> assetsMarketDeclarePage(Page page, CommissionDeclareVO commissionDeclare) {
        return RestResponse.data(commissionDeclareService.assetsMarketDeclarePage(page, commissionDeclare));
    }

    /**
     * 资产业务新增绩效分配申报
     * @param declareDTO dto
     * @return RestResponse<Boolean>
     */
    @PostMapping("/assets")
    public synchronized RestResponse<Boolean> assetsCommissionDeclare(@RequestBody CommissionDeclareDTO declareDTO) {
        Long ret = commissionDeclareService.assetsCommissionDeclare(declareDTO);
        return RestResponse.data(ret!=null);
    }

    /**
     * 资产提成申报待审核列表
     */
    @GetMapping("/assets/check")
    public RestResponse<Page<CommissionDeclareTodoCheckVO>> assetsTodoCheckPage(CommissionDeclareTodoCheckVO checkVO, Page page){
        Page<CommissionDeclareTodoCheckVO> ret = commissionDeclareService.assetsTodoCheckPage(page,checkVO);
        return RestResponse.data(ret);
    }

    /**
     * 资产待办绩效申报集合
     * @return RestResponse<List<CommissionDeclareTodoCheckVO>>
     */
    @GetMapping("/assets/check/list")
    public RestResponse<List<CommissionDeclareTodoCheckVO>> assetsTodoCheckList() {
        return RestResponse.data(commissionDeclareService.assetsTodoCheckList());
    }

    /**
     * 更新资产绩效申报提成比列与下限信息
     * @param declareDTO dto
     * @return RestResponse<Boolean>
     */
    @PutMapping("/assets/check/update")
    public RestResponse<Boolean> updateAssetsCommissionDeclare(@RequestBody CommissionDeclareDTO declareDTO) {
        return RestResponse.data(commissionDeclareService.updateAssetsCommissionDeclare(declareDTO));
    }
}

