package com.xunmei.core.resumption.controller;

import com.xunmei.common.core.vo.IdNameVo;
import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import com.xunmei.common.core.web.page.TableDataInfo;
import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionNFCDto;
import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionRecordPageDto;
import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionRoleDto;
import com.xunmei.core.resumption.service.IResumptionRecordService;
import com.xunmei.core.resumption.vo.resumptionRecord.NFCRecordVo;
import com.xunmei.core.resumption.vo.resumptionRecord.ResumptionRecordInfoVo;
import com.xunmei.core.resumption.vo.resumptionRecord.ResumptionRoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author jingyuanchao
 * @date 2022/5/11 14:24
 */
@Slf4j
@Api(description = "履职记录")
@RestController
@RequestMapping("/resumption/record")
public class ResumptionRecordController extends BaseController {
    @Resource
    IResumptionRecordService resumptionRecordService;

    @ApiOperation(value = "履职记录分页")
    @GetMapping("/page")
    public TableDataInfo page(@Valid ResumptionRecordPageDto pageDto) {
        return resumptionRecordService.selectList(pageDto);
    }

    /**
     *
     * @param id
     * @param ymd：分表字段
     * @return
     */
    @ApiOperation(value = "履职记录详情")
    @GetMapping("/{id}/{ymd}")
    public AjaxResult list(@PathVariable String id,@PathVariable String ymd) {
        List<ResumptionRecordInfoVo> list = resumptionRecordService.selectInfo(id,ymd);
        return success(list);
    }

//    @ApiOperation(value = "secBookDtInst字典表")
//    @GetMapping("/sec")
//    public JsonResponse<?> sec() {
//        return JsonResponse.success(resumptionRecordService.selectSecBookDtInstList());
//    }


    @ApiOperation(value = "履职记录角色下拉框")
    @GetMapping("/role")
    public AjaxResult role(ResumptionRoleDto roleDto) {
        List<IdNameVo> list = resumptionRecordService.selectResumptionRole(roleDto);

        return success(list);
    }

    @ApiOperation(value = "履职计划下拉框")
    @GetMapping("/plan")
    public AjaxResult plan(ResumptionRoleDto roleDto) {
        List<IdNameVo> list = resumptionRecordService.selectResumptionPlan(roleDto);
        return success(list);
    }


    @ApiOperation(value = "履职记录NFC记录")
    @GetMapping("/nfc")
    public AjaxResult nfc(ResumptionNFCDto dto) {
        List<NFCRecordVo> list = resumptionRecordService.selectNFCRecord(dto);
        return success(list);
    }
   /* @ApiOperation(value = "履职记录导出")
    @PostMapping("/export")
    public JsonResponse<?> export(@RequestBody ResumptionRecordPageDto pageDto) {
        String export = StringUtil.EMPTY_STRING;
        try {
            export = resumptionRecordService.export(pageDto);
            return JsonResponse.success(export);
        } catch (FileNotFoundException e) {
            log.error("履职记录下载失败,{}", e.getMessage());
            e.printStackTrace();
        }
        return JsonResponse.fail(export);
    }*/
   @ApiOperation(value = "履职记录导出")
   @PostMapping("/export")
   public void export(@RequestBody ResumptionRecordPageDto pageDto, HttpServletResponse response) throws Exception {

       resumptionRecordService.export(pageDto,response);
   }
}
