package com.tofly.xrtygis.custom.controller.gs;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.xrtygis.custom.entity.CustomDutyroster;
import com.tofly.xrtygis.custom.entity.DelParam;
import com.tofly.xrtygis.custom.entity.gs.GsBean;
import com.tofly.xrtygis.custom.entity.gs.Jbgl;
import com.tofly.xrtygis.custom.service.CustomGsService;
import com.tofly.xrtygis.entity.Gardetemplate;
import com.tofly.xrtygis.entity.Rxjbgl;
import com.tofly.xrtygis.entity.Rxknowledge;
import com.tofly.xrtygis.entity.Rxwtgl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@RestController
@AllArgsConstructor
@RequestMapping("/gsrx")
@Api(tags = "热线--供水热线服务")
public class CustomGsServiceController {
    private final CustomGsService customGsService;


    /**
     * 新增评分模板
     * @param gardetemplate
     * @return
     */
    @PostMapping("/gradeTemplate")
    @ApiOperation(value = "评分模板")
    @ToFlyAppLog(title = "新增评分模板")
    public ResultRespone gradeTemplate(@RequestBody Gardetemplate  gardetemplate) {
        return ResultRespone.success(customGsService.gradeTemplate(gardetemplate));
    }
    @GetMapping("/getGradeTemplate")
    @ApiOperation(value = "获取评分模板")
    @ToFlyAppLog(title = "获取评分模板")
    public ResultRespone getGradeTemplate() {
        return ResultRespone.success(customGsService.getGradeTemplate());
    }


    /**
     * 创建排班记录
     * @param gsBean
     * @return
     */
    //(title = "排班管理；创建/修改排班")
    @PostMapping("/dutymanager")
    @ApiOperation(value = "排班管理，创建/修改排班")
    @ToFlyAppLog(title = "排班管理，创建/修改排班")

    public ResultRespone dutymanager(@RequestBody GsBean gsBean) {
        return ResultRespone.success(customGsService.dutymanager(gsBean));
    }


    @PostMapping("/importdutymanager")
    @ApiOperation(value = "导入排班信息")
    @ToFlyAppLog(title = "导入排班信息")
    public ResultRespone importDutyManager(MultipartFile file){
        return ResultRespone.success(customGsService.importDutyManagerInfo(file));
    }


    /**
     * 通过起始时间、工作人员、截止时间条件获取排班信息
     * @param dutyroster
     * @return
     */
    @PostMapping("/dutymanager1")
    @ApiOperation(value = "获取排班信息")
    @ToFlyAppLog(title = "获取排班信息")
    public ResultRespone getDuty(@RequestBody CustomDutyroster dutyroster) {
        return ResultRespone.success(customGsService.getDuty(dutyroster));
    }

    @PostMapping("/dutyMonth")
    @ApiOperation(value = "获取当月所有排班信息")
    @ToFlyAppLog(title = "获取当月所有排班信息")
    public ResultRespone dutyMonth(@RequestBody CustomDutyroster dutyroster) {
        Date month = dutyroster.getMonth();
        Long user = dutyroster.getDutyUser();
        return ResultRespone.success(customGsService.dutyMonth(month , user));
    }

    /**
     * 通过id删除人员排班信息表：TF_YWPN_DUTYROSTER_W
     * @param id id
     * @return ResultRespone
     */
    //(title="通过id删除人员排班信息表" )
    @ApiOperation(value = "通过ID删除人员排班信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    @ToFlyAppLog(title = "通过ID删除人员排班信息表")
    public ResultRespone removeById(@PathVariable Long id) {
        return ResultRespone.success(customGsService.removeById(id));
    }
    /**
     * 填写交接班记录
     * @param jbgl
     * @param request
     * @return
     */
    //(title = "填写交接班记录")
    @PostMapping(value = "/handOver",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "填写交接班记录")
    @ToFlyAppLog(title = "填写交接班记录")
    public ResultRespone addHandOver(Rxjbgl jbgl, HttpServletRequest request) {
        return ResultRespone.success(customGsService.addHandOver(jbgl,request));
    }

    @GetMapping("/handOver")
    @ApiOperation(value = "获取交接班记录")
    @ToFlyAppLog(title = "获取交接班记录")
    public ResultRespone getHandOver(Page page,HttpServletResponse response, Jbgl jbgl , String templateFlag) {
        return ResultRespone.success(customGsService.getHandOver(page ,response , jbgl , templateFlag));
    }

    @PostMapping("/updateHandOver")
    //(title = "接班人员接受/拒绝")
    @ApiOperation(value = "接班人员接受/拒绝")
    @ToFlyAppLog(title = "接班人员接受/拒绝")
    public ResultRespone updateHandOver(@RequestBody Rxjbgl jbgl) {
        return ResultRespone.success(customGsService.updateHandOver(jbgl));
    }
    @PostMapping("/updateHandOverTwo")
    @ApiOperation(value = "修改交班记录")
    @ToFlyAppLog(title = "修改交班记录")
    public ResultRespone updateHandOverTwo(@RequestBody Rxjbgl jbgl) {
        return ResultRespone.success(customGsService.updateHandOverTwo(jbgl));
    }


    //(title = "新增知识库")
    @PostMapping(value = "/knowledge",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "新增知识库")
    @ToFlyAppLog(title = "新增知识库")
    public ResultRespone addKnowledge(Rxknowledge rxknowledge, HttpServletRequest request) {
        return ResultRespone.success(customGsService.addKnowledge(rxknowledge,request));
    }

    @GetMapping(value = "/knowledge")
    @ApiOperation(value = "查看全部知识库")
    @ToFlyAppLog(title = "查看全部知识库")
    public ResultRespone getKnowledge() {
        return ResultRespone.success(customGsService.getKnowledge());
    }
    //(title = "删除知识库")
    @DeleteMapping(value = "/knowledge/{id}")
    @ApiOperation(value = "删除知识库")
    @ToFlyAppLog(title = "删除知识库")
    public ResultRespone delKnowledge(@PathVariable("id") Long id) {
        return ResultRespone.success(customGsService.delKnowledge(id));
    }

    /**
     * @param rxknowledge
     * @param request
     * @return
     */
    //(title = "修改知识库")
    @PutMapping(value = "/knowledge",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "修改知识库")
    @ToFlyAppLog(title = "修改知识库")
    public ResultRespone updateKnowledge(Rxknowledge rxknowledge, HttpServletRequest request) {
        return ResultRespone.success(customGsService.updateKnowledge(rxknowledge,request));
    }
    //(title = "删除知识库图片")
    @PutMapping(value = "/delKnowledgePic")
    @ApiOperation(value = "删除知识库图片")
    @ToFlyAppLog(title = "删除知识库图片")
    public ResultRespone delKnowledgePic(@RequestBody DelParam delParam) {
        Long id=delParam.getId();
        String filePath=delParam.getFilePath();
        return ResultRespone.success(customGsService.delKnowledgePic(id,filePath));
    }


    @GetMapping(value = "/knowledgeByTitle")
    @ApiOperation(value = "根据标题名称模糊查询知识库")
    @ToFlyAppLog(title = "根据标题名称模糊查询知识库")
    public ResultRespone getKnowledgeByTitle(String title) {
        return ResultRespone.success(customGsService.getKnowledgeByTitle(title));
    }


    //(title = "新增问题")
    @PostMapping(value = "/problem",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "新增问题")
    @ToFlyAppLog(title = "新增问题")
    public ResultRespone addProblem(Rxwtgl wtgl, HttpServletRequest request) {
        return ResultRespone.success(customGsService.addProlem(wtgl,request));
    }

    @PostMapping("/replyProlem")
    @ApiOperation("回复问题")
    public ResultRespone  replyProlem(@RequestBody Rxwtgl wtgl){
        return ResultRespone.success(customGsService.replyProlem(wtgl));
    }

    /**
     * 可根据问题内容模糊查询问题
     * @param wtgl
     * @param page
     * @return
     */
    //(title = "查看问题")
    @GetMapping(value = "/problem")
    @ApiOperation(value = "查看问题")
    @ToFlyAppLog(title = "查看问题")
    public ResultRespone getProblem(Rxwtgl wtgl, Page page) {
        return ResultRespone.success(customGsService.getProblem(wtgl,page));
    }

    //(title = "问题审核")
    @PutMapping(value = "/problem")
    @ApiOperation(value = "问题审核")
    @ToFlyAppLog(title = "问题审核")
    public ResultRespone updateProblem(@RequestBody Rxwtgl wtgl,Long pid) {
        return ResultRespone.success(customGsService.updateProblem(wtgl,pid));
    }



}
