package com.ningdatech.carapi.driver.controller;


import java.util.List;

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

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.driver.manage.DriverArchivesManage;
import com.ningdatech.carapi.driver.model.dto.DriverBasicInfoDTO;
import com.ningdatech.carapi.driver.model.po.*;
import com.ningdatech.carapi.driver.model.vo.ResArchivalInfoDetailVO;
import com.ningdatech.carapi.driver.model.vo.ResArchivalInfoSearchListVO;
import com.ningdatech.carapi.driver.model.vo.ResDriverTrainingRegistrationListVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentAnalysisVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentDeadVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleViolationVO;
import com.ningdatech.carapi.sys.entity.enumeration.ImportTemplateEnum;
import com.ningdatech.log.annotation.WebLog;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * @author LiuXinXin
 * @since 2022-10-09
 */
@RequestMapping("/api/v1/driver/archives")
@RestController
@Api(tags = "驾驶员管理-档案管理(新接口)")
@Validated
@RequiredArgsConstructor
public class DriverArchivesController {

    private final DriverArchivesManage driverArchivesManage;

    @PostMapping("/archival-info/search")
    @ApiOperation("档案管理查询")
    public PageVo<ResArchivalInfoSearchListVO> archivalInfoSearch(@Valid @RequestBody ReqArchivalInfoSearchPO po) {
        return driverArchivesManage.archivalInfoSearch(po);
    }

    @PostMapping("/training/registration")
    @ApiOperation("驾驶员培训报名/申请跳槽/继续教育报名/换证培训报名(新接口)")
    @WebLog(value = "驾驶员培训报名/申请跳槽/继续教育报名/换证培训报名", modular = "驾驶员管理-档案管理")
    public void driverTrainingRegistration
            (@Valid @RequestBody ReqDriverTrainingRegistrationPO po) {
        driverArchivesManage.driverTrainingRegistration(po);
    }

    @PostMapping("/training/registration/un-deal/list")
    @ApiOperation("驾驶员培训报名-审核列表筛选(新接口)")
    public PageVo<ResDriverTrainingRegistrationListVO> driverTrainingRegistrationUnDealList
            (@Valid @RequestBody ReqDriverTrainingRegistrationListPO po) {
        return driverArchivesManage.driverTrainingRegistrationUnDealList(po);
    }

    @PostMapping("/archival-info/detail/review")
    @ApiOperation("驾驶员档案审核详情(新接口)")
    public ResArchivalInfoDetailVO getArchivalInfoReviewDetail(@Valid @RequestBody ReqGetArchivalInfoReviewDetailPO request) {
        return driverArchivesManage.getArchivalInfoReviewDetail(request);
    }

    @PostMapping("/archival-info/detail/{driverId}")
    @ApiOperation("获取驾驶员档案详情")
    public ResArchivalInfoDetailVO getArchivalInfoReviewDetail(@PathVariable("driverId") Long driverId) {
        return driverArchivesManage.getDriverArchivalInfo(driverId);
    }

    @PostMapping("/archival-info/detail/id-card/{idCard}")
    @ApiOperation("根据身份证号获取驾驶员档案详情")
    public ResArchivalInfoDetailVO getArchivalInfoReviewDetailByIdCard(@PathVariable("idCard") String idCard) {
        return driverArchivesManage.getDriverArchivalInfoByIdCard(idCard);
    }

    @PostMapping("/training/preliminary-trial")
    @ApiOperation("驾驶员材料初审(新接口)")
    public void driverTrainingPreliminaryTrial(@Valid @RequestBody ReqDriverTrainingPreliminaryTrialPO po) {
        driverArchivesManage.driverTrainingPreliminaryTrial(po);
    }

    @PostMapping("/training/in-review")
    @ApiOperation("驾驶员材料复审（新接口）")
    @WebLog(value = "驾驶员材料复审", modular = "驾驶员管理-档案管理")
    public void driverTrainingInReview(@Valid @RequestBody ReqDriverInReviewingPO po) {
        driverArchivesManage.driverTrainingInReview(po);
    }

    @PostMapping("/quit/{driverId}")
    @ApiOperation("驾驶员离职")
    public void driverQuit(@PathVariable("driverId") Long driverId) {
        driverArchivesManage.driverQuit(driverId);
    }

    @PostMapping("/induction")
    @ApiOperation("驾驶员入职")
    public void driverInduction(@Valid @RequestBody ReqDriverInductionPO po) {
        driverArchivesManage.driverInduction(po);
    }

    @PostMapping("/changed-job")
    @ApiOperation("驾驶员跳槽")
    public void changedJob(@Valid @RequestBody ReqChangedJobPO request) {
        driverArchivesManage.changedJob(request);
    }

    /**
     * 查询驾驶员违章记录档案
     *
     * @param driverId,violationType
     * @return
     */
    @ApiOperation(value = "查询驾驶员违章记录档案", notes = "查询驾驶员违章记录档案")
    @GetMapping("/violation")
    public List<NdVehicleViolationVO> getViolation(@Valid @RequestParam Long driverId, @Valid @RequestParam Integer violationType) {
        return driverArchivesManage.getViolation(driverId, violationType);
    }

    /**
     * 查询驾驶员事故记录档案
     *
     * @param driverId
     * @return
     */
    @ApiOperation(value = "查询驾驶员事故记录档案", notes = "查询驾驶员事故记录档案")
    @GetMapping("/accident-driver/{driverId}")
    public List<NdVehicleAccidentVO> getAccidentVehicle(@Valid @PathVariable Long driverId) {
        return driverArchivesManage.getAccidentVehicle(driverId);
    }

    /**
     * 查询驾驶员死亡事故记录档案
     *
     * @param driverId
     * @return
     */
    @ApiOperation(value = "查询驾驶员死亡事故记录档案", notes = "查询驾驶员死亡事故记录档案")
    @GetMapping("/accident-dead/{driverId}")
    public List<NdVehicleAccidentDeadVO> getAccidentDead(@Valid @PathVariable Long driverId) {
        return driverArchivesManage.getAccidentDead(driverId);
    }

    /**
     * 查询驾驶员事故分析记录档案
     *
     * @param driverId
     * @return
     */
    @ApiOperation(value = "查询驾驶员事故分析记录档案", notes = "查询驾驶员事故分析记录档案")
    @GetMapping("/accident-analysis/{driverId}")
    public List<NdVehicleAccidentAnalysisVO> getAccidentAnalysis(@Valid @PathVariable Long driverId) {
        return driverArchivesManage.getAccidentAnalysis(driverId);
    }

    @ApiOperation("驾驶员模版数据导入")
    @PostMapping("/importTemplateData")
    @WebLog(value = "驾驶员模版数据导入", modular = "驾驶员管理-档案管理")
    public String importTemplateData(@RequestParam("template") ImportTemplateEnum template, MultipartFile file, HttpServletResponse response) {
        return driverArchivesManage.importDriverArchivesData(template, file, response);
    }

    @ApiOperation(value = "驾驶员档案列表导出", notes = "驾驶员档案列表导出")
    @GetMapping("/exportDriverArchives")
    @WebLog
    public void exportDriverArchives(@Valid @ModelAttribute ReqArchivalInfoSearchPO req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, driverArchivesManage::exportDriverArchives);
    }

    @ApiOperation(value = "驾驶员档案数据录入", notes = "驾驶员档案数据录入")
    @PostMapping("/addDriverArchives")
    public Boolean addDriverArchives(@Valid @RequestBody ReqAddDriverArchivesPO param) {
        return driverArchivesManage.addDriverArchives(param);
    }

    @ApiOperation(value = "驾驶员基本信息编辑", notes = "驾驶员基本信息编辑")
    @PostMapping("/modifyDriverBasicInfo")
    public ResArchivalInfoDetailVO modifyDriverBasicInfo(@Valid @RequestBody DriverBasicInfoDTO data) {
        return driverArchivesManage.modifyDriverBasicInfo(data);
    }
}
