/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtygis.controller;

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.pojo.GdglinfoExtendDto;
import com.tofly.xrtygis.commons.Constant;
import com.tofly.xrtygis.entity.TfPublicLeakageInfo;
import com.tofly.xrtygis.entity.dto.PublicLeakageOrderDto;
import com.tofly.xrtygis.entity.dto.TfPublicLeakageInfoDto;
import com.tofly.xrtygis.exception.BusinessException;
import com.tofly.xrtygis.service.TfPublicLeakageInfoService;
import lombok.AllArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 公众参与漏点信息管理
 *
 * @author admin
 * @date Thu Mar 24 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfpublicleakageinfo")
@Api(tags="公众参与漏点信息管理接口")
public class TfPublicLeakageInfoController extends BaseController {

    private final TfPublicLeakageInfoService tfPublicLeakageInfoService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfPublicLeakageInfoDto 公众参与漏点信息管理
    * @return
    */
    @GetMapping("/page" )
    @ToFlyAppLog(title="分页查询" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfPublicLeakageInfoPage(Page page, @ModelAttribute TfPublicLeakageInfoDto tfPublicLeakageInfoDto) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.getTfPublicLeakageInfoPage(page,tfPublicLeakageInfoDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }
    }


    /**
     * 通过id查询公众参与漏点信息管理
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ToFlyAppLog(title="通过ID查询" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.getById(id));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 查询公众统计相关信息
     * @param
     * @return ResultRespone
     */
    @PostMapping("/getPublicCensus" )
    @ApiOperation(value = "查询公众统计相关信息")
    @ToFlyAppLog(title="查询公众统计相关信息" )
    public ResultRespone getPublicCensus(@RequestBody TfPublicLeakageInfoDto tfPublicLeakageInfoDto) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.getPublicCensus(tfPublicLeakageInfoDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 添加公众漏点审核
     * @param
     * @return ResultRespone
     */
    @PostMapping("/savePublicLeakageAudit" )
    @ApiOperation(value = "添加公众漏点审核")
    @ToFlyAppLog(title="添加公众漏点审核" )
    public ResultRespone savePublicLeakageAudit(GdglinfoExtendDto gdglinfoExtendDto) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.savePublicLeakageAudit(gdglinfoExtendDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

    /**
     * 奖励水量工单
     * @param
     * @return ResultRespone
     */
    @PostMapping("/saveRewardWaterOder" )
    @ApiOperation(value = "奖励水量工单")
    @ToFlyAppLog(title="奖励水量工单" )
    public ResultRespone saveRewardWaterOder(@Valid PublicLeakageOrderDto dto, @RequestParam(value = "fileList", required = false) List<MultipartFile> fileList) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.saveRewardWaterOder(dto,fileList));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }

    }

//    /**
//     * 重新提交公众漏点信息
//     * @param
//     * @return ResultRespone
//     */
//    @PostMapping("/updateNewPublicLeakage" )
//    @ApiOperation(value = "重新提交公众漏点信息")
//    @ToFlyAppLog(title="重新提交公众漏点信息" )
//    public ResultRespone updateNewPublicLeakage(@RequestBody TfPublicLeakageInfo tfPublicLeakageInfo) {
//        try{
//            return ResultRespone.success(tfPublicLeakageInfoService.updateNewPublicLeakage(tfPublicLeakageInfo));
//        }catch (Exception e){
//            e.printStackTrace();
//            return ResultRespone.failed(e.getMessage());
//        }
//
//    }


//        /**
//     * 新增公众参与漏点信息管理
//     * @param tfPublicLeakageInfo 公众参与漏点信息管理
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="新增公众参与漏点信息管理" )
//    @ApiOperation(value = "新增公众参与漏点信息管理")
//    @PostMapping
//    public ResultRespone save(@RequestBody TfPublicLeakageInfo tfPublicLeakageInfo) {
//        try{
//            return ResultRespone.success(tfPublicLeakageInfoService.save(tfPublicLeakageInfo));
//        }catch (Exception e){
//            e.printStackTrace();
//            return ResultRespone.failed(e.getMessage());
//        }
//    }

        /**
     * 修改公众参与漏点信息管理
     * @param tfPublicLeakageInfo 公众参与漏点信息管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改公众参与漏点信息管理" )
    @ApiOperation(value = "修改公众参与漏点信息管理")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfPublicLeakageInfo tfPublicLeakageInfo) {
        try{
            return ResultRespone.success(tfPublicLeakageInfoService.updateById(tfPublicLeakageInfo));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }
    }

//    /**
//     * 通过id删除公众参与漏点信息管理
//     * @param id id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id删除公众参与漏点信息管理" )
//    @ApiOperation(value = "通过ID删除公众参与漏点信息管理")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
//    })
//    @DeleteMapping("/{id}" )
//    public ResultRespone removeById(@PathVariable Long id) {
//        try{
//            return ResultRespone.success(tfPublicLeakageInfoService.removeById(id));
//        }catch (Exception e){
//            e.printStackTrace();
//            return ResultRespone.failed(e.getMessage());
//        }
//    }

//    /**
//     * 通过id批量删除公众参与漏点信息管理
//     * @param ids id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id批量删除公众参与漏点信息管理" )
//    @ApiOperation(value = "通过ID批量删除公众参与漏点信息管理")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
//    })
//    @DeleteMapping("/deleteByIds" )
//    public ResultRespone removeById(String ids) {
//
//        try{
//            return ResultRespone.success(tfPublicLeakageInfoService.removeByIds(Arrays.asList(ids.split(","))));
//        }catch (Exception e){
//            e.printStackTrace();
//            return ResultRespone.failed(e.getMessage());
//        }
//    }

    /**
     * 新增公众参与漏点信息管理
     * @param tfPublicLeakageInfo 公众参与漏点信息管理
     * @return ResultRespone
     */
    @ApiOperation(value = "新增公众参与漏点信息管理")
    @PostMapping("/save")
    @ToFlyAppLog(title = "新增公众参与漏点信息管理")
    public ResultRespone<Object> savePublicLeakageInfo(@Valid TfPublicLeakageInfo tfPublicLeakageInfo, BindingResult result, @RequestParam(value = "fileList", required = false) List<MultipartFile> fileList) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        if (!Optional.ofNullable(super.validRest(rest, result)).isPresent()) {
            tfPublicLeakageInfoService.savaTfPublicLeakageInfo(fileList, tfPublicLeakageInfo);
        }
        return rest;

    }

//    /**
//     * 修改公众参与漏点信息管理
//     * @param tfPublicLeakageInfo 公众参与漏点信息管理
//     * @return ResultRespone
//     */
//    @ApiOperation(value = "修改公众参与漏点信息管理")
//    @PutMapping("/update")
//    @ToFlyAppLog(title = "修改公众参与漏点信息管理")
//    public ResultRespone<Object> updateByIdPublicLeakageInfo(@Valid TfPublicLeakageInfo tfPublicLeakageInfo, BindingResult result,@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList) {
//        ResultRespone<Object> rest = new ResultRespone<>();
//        // 数据校验 判空返回
//        if (!Optional.ofNullable(super.validRest(rest, result)).isPresent()) {
//            try {
//                tfPublicLeakageInfoService.updateTfPublicLeakageInfo(fileList, tfPublicLeakageInfo);
//            } catch (BusinessException e) {
//                rest.setCode(e.getRetCd());
//                rest.setMessage(e.getMsgDes());
//            }
//
//        }
//        return rest;
//
//    }

    /**
     * 通过id批量删除公众参与漏点信息管理
     * @param ids id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过id批量删除公众参与漏点信息管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    @ToFlyAppLog(title = "通过id批量删除公众参与漏点信息管理")
    public ResultRespone<Object> removeByIdListPublicLeakageInfo(String ids) {
        ResultRespone<Object> rest = new ResultRespone<>();
        List<Long> removeId = Arrays.stream(ids.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                .collect(Collectors.toList());
        try {
            tfPublicLeakageInfoService.deleteTfPublicLeakageInfo(removeId);
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
        }
        return rest;
    }

}
