package com.unis.base.server.controller;

import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.*;
import com.unis.base.server.service.PersonMeetingService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnelMeeting")
@Api(value = "会议和培训信息", tags = "会议和培训信息")
@Slf4j
public class PersonMeetingController {
    @Autowired
    private PersonMeetingService personMeetingService;

   /* @ApiOperation(value = "培训反馈分页")
    @PostMapping(value = "/saveMeeting")
    public ResponseWrapper saveMeeting(@RequestBody PersonMeetingVO personMeetingVO) {
        try {
            personMeetingService.saveMeeting(personMeetingVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }*/

    @ApiOperation(value = "培训反馈分页")
    @PostMapping(value = "/meetingRecord")
    public ResponseWrapper meetingRecodrd(@RequestBody PageRecordSVO recordVO) {
        try {
            List<MeetingRecordVO> recordVOS = personMeetingService.meetingRecodrd(recordVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), recordVOS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训反馈详情分页")
    @PostMapping(value = "/meetingDetialRecodrd")
    public ResponseWrapper meetingDetialRecodrd(@RequestBody TrainDetialVO trainDetialVO) {
        try {
            List<MeetingRecordVO> recordVOS = personMeetingService.meetingDetialRecodrd(trainDetialVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), recordVOS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "保存或提交培训反馈")
    @PostMapping(value = "/inmeetingDetialRecodrd")
    public ResponseWrapper inmeetingDetialRecodrd(@RequestBody SaveRecordVO saveRecordVO) {
        try {
            personMeetingService.inmeetingDetialRecodrd(saveRecordVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "导出培训结果反馈")
    @PostMapping(value = "/commeetingDetialRecodrd")
    public ResponseWrapper commeetingDetialRecodrd(@RequestParam("fid") String fid) {
        try {
            List<MainRecordVO> mainRecordVOS = personMeetingService.commeetingDetialRecodrd(fid);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), mainRecordVOS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "删除培训反馈")
    @PostMapping(value = "/deletmeetingDetialRecodrd")
    public ResponseWrapper deletmeetingDetialRecodrd(@RequestBody DelGetRecordVO getRecordVO) {
        try {
            personMeetingService.deletmeetingDetialRecodrd(getRecordVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训结果反馈分页")
    @PostMapping(value = "/meetingResultRecodrd")
    public ResponseWrapper meetingResultRecodrd(@RequestBody PageResultRecodrdVO resultRecodrdVO) {
        try {
            PageInfo<ResultRecodrdVO> recordVOS = personMeetingService.meetingResultRecodrd(resultRecodrdVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), recordVOS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训结果反馈详情")
    @PostMapping(value = "/PersonmeetingRecodrd")
    public ResponseWrapper PersonmeetingRecodrd(@RequestBody MeetingRecodrdVO meetingRecodrdVO) {
        try {
            PageInfo<InsertRecordVO> voPageInfo = personMeetingService.PersonmeetingRecodrd(meetingRecodrdVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), voPageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }


    @ApiOperation(value = "新增个人培训结果反馈")
    @PostMapping(value = "/SavePersonmeetingRecodrd")
    public ResponseWrapper SavePersonmeetingRecodrd(@RequestBody InRecordVO inRecordVO) {
        try {
            personMeetingService.SavePersonmeetingRecodrd(inRecordVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "导出培训反馈")
    @PostMapping(value = "/sentPersonmeetingRecodrd")
    public ResponseWrapper sentPersonmeetingRecodrd(@RequestParam("fid") String fid) {
        try {
            List<MeetingRecordVO> meetingRecordVOS = personMeetingService.sentPersonmeetingRecodrd(fid);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), meetingRecordVOS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "删除个人培训结果反馈")
    @PostMapping(value = "/delPersonmeetingRecodrd")
    public ResponseWrapper delPersonmeetingRecodrd(@RequestBody InsertRecordVO insertRecordVO) {
        try {
            personMeetingService.delPersonmeetingRecodrd(insertRecordVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训统计")
    @PostMapping(value = "/CountPersonmeetingRecodrd")
    public ResponseWrapper CountPersonmeetingRecodrd(@RequestBody CountPersonmeetingVO countPersonmeetingVO) {
        try {
            PageInfo<CountPersonVO> countPersonVOPageInfo = personMeetingService.CountPersonmeetingRecodrd(countPersonmeetingVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), countPersonVOPageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训分页")
    @PostMapping(value = "/pageMeeting")
    public ResponseWrapper pageMeeting(@RequestParam("pageNum") Integer pageNum,
                                       @RequestParam("pageSize") Integer pageSize,
                                       @RequestParam(value = "trainName", required = false) String trainName,
                                       @RequestParam(value = "status", required = false) String status,
                                       @RequestParam(value = "trainPersonDeptCode", required = false) String trainPersonDeptCode) {
        try {
            PageInfo<TrainVO> pageMeeting = personMeetingService.pageMeeting(pageNum, pageSize, trainName, status, trainPersonDeptCode);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), pageMeeting);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }

    @ApiOperation(value = "培训计划分页", notes = "培训计划分页")
    @PostMapping(value = "/page_info")
    public ResponseWrapper pageInfo(@RequestBody TrainMainQueryVo viewObj,
                                    @RequestParam("pageNum")Integer pageNum,
                                    @RequestParam("pageSize") Integer pageSize){
        try {
            PageInfo<TrainMainVo> pageInfos = personMeetingService.pageInfoForPx(viewObj, pageNum, pageSize);
            return ResponseWrapper.success(pageInfos);
        } catch (Exception e) {
            log.error(e.getMessage());
            e.printStackTrace();
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"查询信息失败",null);
    }

   /* @ApiOperation(value = "查询培训详情")
    @PostMapping(value = "/selectMeeting")
    public ResponseWrapper selectMeeting(@RequestParam("meetingName") String meetingName) {
        try {
            List<PersonMeetingVO> pageMeeting = personMeetingService.selectMeeting(meetingName);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), pageMeeting);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
    }*/


}
