package com.ningdatech.carapi.driver.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.driver.entity.BehaviorAnalysisProcessingMode;
import com.ningdatech.carapi.driver.entity.DriverAbnormalBehaviorAnalysisNoticeDTO;
import com.ningdatech.carapi.driver.entity.DriverAbnormalBehaviorAnalysisOverseeDTO;
import com.ningdatech.carapi.driver.entity.DriverAbnormalBehaviorAnalysisPageParamDTO;
import com.ningdatech.carapi.driver.manage.BehaviourAnalysisManage;
import com.ningdatech.carapi.driver.model.vo.BehaviourAnalysisVO;
import com.ningdatech.carapi.driver.model.vo.DriverAbnormalBehaviorAnalysisDetailVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author CMM
 * @Classname BehaviourManageController
 * @Description
 * @Date 2022/11/07 16:30
 */
@RestController
@RequestMapping(value = "/api/v1/driver/behaviour")
@Api(tags = "驾驶员管理-行为管理")
@Validated
@RequiredArgsConstructor
public class BehaviourManageController {

    private final BehaviourAnalysisManage behaviourAnalysisManage;

    @ApiOperation("行为分析")
    @GetMapping("/behaviour-analysis-list")
    public PageVo<BehaviourAnalysisVO> behaviourAnalysisList(
            @Valid @ModelAttribute DriverAbnormalBehaviorAnalysisPageParamDTO param) {
        return behaviourAnalysisManage.behaviorAnalysisList(param);
    }

    @ApiOperation("驾驶员异常行为分析详情")
    @GetMapping("/analysis-info/detail/{id}")
    public DriverAbnormalBehaviorAnalysisDetailVO behaviourAnalysisDetail(@Valid @PathVariable Long id){
        return behaviourAnalysisManage.getBehaviourAnalysisDetail(id);
    }

    @ApiOperation("驾驶员异常行为分析督办")
    @PostMapping("/analysis/oversee")
    public Boolean behaviorAnalysisOversee(@Valid @RequestBody DriverAbnormalBehaviorAnalysisOverseeDTO param){
        return behaviourAnalysisManage.oversee(param, LoginUserUtil.getUserId());
    }

    @ApiOperation("获取驾驶员异常行为分析处理方式-全局配置")
    @GetMapping("/analysis/get/processing-mode")
    public List<BehaviorAnalysisProcessingMode> processingModeDetail(){
        return behaviourAnalysisManage.processingModeDetail();
    }

    @ApiModelProperty("添加驾驶员异常行为分析处理方式")
    @GetMapping("/addProcessingMode")
    public Boolean addProcessingMode(@Valid String req){
        return behaviourAnalysisManage.addProcessingMode(req);
    }

    @ApiModelProperty("删除驾驶员异常行为分析处理方式")
    @DeleteMapping("/deleteProcessingMode/{id}")
    public Boolean addProcessingMode(@Valid @PathVariable Integer id){
        return behaviourAnalysisManage.deleteProcessingMode(id);
    }

    @ApiOperation("驾驶员异常行为分析处理详情")
    @PostMapping("/analysis/deal")
    public Boolean behaviorAnalysisNotice(@Valid @RequestBody DriverAbnormalBehaviorAnalysisNoticeDTO param){
        return behaviourAnalysisManage.deal(param,LoginUserUtil.getUserId());
    }

    @ApiOperation("行为分析列表导出")
    @GetMapping("/behaviour-analysis-list-export")
    public void exportBehaviourAnalysisList(DriverAbnormalBehaviorAnalysisPageParamDTO req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,behaviourAnalysisManage::driverAbnormalBehaviorAnalysisListExport);
    }
}
