package com.jeeplus.test.reimbursement.reimbursementInfo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.core.excel.utils.EasyPoiUtil;
import com.jeeplus.test.program.configuration.projectList.domain.ProgramProjectListInfo;
import com.jeeplus.test.program.configuration.projectList.service.dto.ExportFileDto;
import com.jeeplus.test.reimbursement.reimbursementInfo.service.ReimbursementInfoService;
import com.jeeplus.test.reimbursement.reimbursementInfo.service.dto.QueryListDto;
import com.jeeplus.test.reimbursement.reimbursementInfo.service.dto.RetureListDto;
import com.jeeplus.test.reimbursement.reimbursementInfo.service.dto.SaveInfoDto;
import com.jeeplus.test.reimbursement.reimbursementInfo.service.dto.TreeUserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(tags ="报销申请")
@RequestMapping(value = "/reimbursement/info")
public class ReimbursementInfoController {

    @Resource
    private ReimbursementInfoService service;

    /**
     * 列表查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "列表查询")
    @GetMapping("/list")
    public ResponseEntity<IPage<RetureListDto>> list(Page<RetureListDto> page, QueryListDto dto) throws Exception{
        IPage<RetureListDto> iPage = service.list(page, dto);
        return ResponseEntity.ok(iPage);
    }

    /**
     * 新增/修改
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增、修改")
    @PostMapping("/save")
    public ResponseEntity<String> save(@RequestBody SaveInfoDto dto) throws Exception{
        String s = service.save(dto);
        return ResponseUtil.newInstance().add("businessTable", "reimbursement_info").add("businessId", s).ok ("操作成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @GetMapping("/remove")
    public ResponseEntity<String> remove(@RequestParam String id){
        String s = service.remove(id);
        return ResponseEntity.ok(s);
    }

    /**
     * 查询
     * @param id
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/findById")
    public ResponseEntity<SaveInfoDto> findById(@RequestParam String id) throws Exception{
        SaveInfoDto dto = service.findById(id);
        return ResponseEntity.ok(dto);
    }

    @ApiOperation(value = "发票号判断")
    @GetMapping("/checkNumber")
    public ResponseEntity<Boolean> checkNumber(@RequestParam String number) {
        Boolean is = service.checkNumber(number);
        return ResponseEntity.ok(is);
    }

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusById")
    public void updateStatusById(@RequestBody RetureListDto dto) {
        service.updateStatusById(dto);
    }

    @ApiOperation(value = "用户树形")
    @GetMapping(value = "/userTree")
    public ResponseEntity<List<TreeUserDto>> userTree(@RequestParam String name) {
        List<TreeUserDto> list = service.userTree(name);
        return ResponseEntity.ok(list);
    }

    @ApiOperation(value = "文件下载")
    @GetMapping(value = "/exportFile")
    public void exportFileUploadList(QueryListDto dto, HttpServletResponse response) throws Exception {
        List<RetureListDto> infos = service.exportList(dto);
        EasyPoiUtil.exportExcel(infos, "报销申请列表信息",  "报销申请列表信息", RetureListDto.class, "", response );
    }

    @ApiOperation(value = "关联报销")
    @GetMapping(value = "/relationReimbursementList")
    public ResponseEntity<IPage<RetureListDto>> relationReimbursementList(Page<RetureListDto> page, @RequestParam("id") String id) {
        IPage<RetureListDto> listDtoIPage = service.relationReimbursementList(page, id);
        return ResponseEntity.ok(listDtoIPage);
    }
}
