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

import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.xrtymis.custom.dto.TfYwpnWaterRepDTO;
import com.tofly.xrtymis.custom.service.TfYwpnWatermeterService;
import com.tofly.xrtymis.entity.TfYwpnWaterRep;
import com.tofly.xrtymis.entity.TfYwpnWatermeter;
import lombok.AllArgsConstructor;
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.multipart.MultipartFile;

import java.util.*;

/**
 * 水表信息采集数据表：TF_YWPN _WATERMETER_W
 *
 * @author fcl
 * @date Fri Apr 16 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfywpnatermeter")
@Api(tags="水表信息采集数据表：TF_YWPN _WATERMETER_W接口")
public class TfYwpnWatermeterController {

    private final TfYwpnWatermeterService tfYwpnWatermeterService;

//    /**
//    * 分页查询
//    * @param page 分页对象
//    * @param tfYwpnatermeter 水表信息采集数据表：TF_YWPN _WATERMETER_W
//    * @return
//    */
//    @GetMapping("/page" )
//    @ApiOperation(value = "分页查询")
//    public ResultRespone getTfYwpnatermeterPage(Page page, @ModelAttribute TfYwpnatermeter tfYwpnatermeter) {
//      return ResultRespone.success(tfYwpnatermeterService.page(page, Wrappers.query(tfYwpnatermeter)));
//    }

    /**
     * 通过id查询水表采集代表点信息数据表：TF_YWPN TF_YWPN_WATERREP_W
     * @param id 水表采集代表点id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "水表采集代表点id", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return tfYwpnWatermeterService.getWaterRepById(id);
    }

    /**
     * 新增水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W
     * @param rep 水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W" )
    @ApiOperation(value = "新增水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W")
    @PostMapping("/add")
    public ResultRespone save(TfYwpnWaterRep rep) {
      return tfYwpnWatermeterService.saveInformation(rep);
    }

    /**
     * 修改水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W
     * @param repDTO 水表采集代表点信息、水表集合
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W" )
    @ApiOperation(value = "修改水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W")
    @PostMapping("/update")
    public ResultRespone updateById(List<MultipartFile> fileList, TfYwpnWaterRepDTO repDTO) {
      return tfYwpnWatermeterService.updateWaterMater(fileList,repDTO);
    }

    /**
     * 通过id删除水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W" )
    @ApiOperation(value = "通过id删除水表采集代表点信息采集数据表：TF_YWPN_WATERREP_W")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "水表采集代表点id", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeRepById(@PathVariable Long id) {
      return tfYwpnWatermeterService.removeRepById(id);
    }

//    /**
//     * 通过id批量删除水表信息采集数据表：TF_YWPN _WATERMETER_W
//     * @param ids id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id批量删除水表信息采集数据表：TF_YWPN _WATERMETER_W" )
//    @ApiOperation(value = "通过ID批量删除水表信息采集数据表：TF_YWPN _WATERMETER_W")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
//    })
//    @DeleteMapping("/deleteByIds" )
//    public ResultRespone removeById(String ids) {
//        return ResultRespone.success(tfYwpnatermeterService.removeByIds(Arrays.asList(ids.split(","))));
//    }

    /**
     * 获取RFID 根据水表编号和厂家名称
     * @param sid 水表编号
     * @return RFID
     */
    @GetMapping("/getRFID")
    @ToFlyAppLog(title = "获取RFID 根据水表编号和厂家名称")
    @ApiOperation(value = "获取RFID 根据水表编号和厂家名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid" ,value = "水表编号" ,required = true,dataType = "String"),
            @ApiImplicitParam(name = "sbcjName" ,value = "水表厂家名称" ,required = true,dataType = "String"),
            @ApiImplicitParam(name = "yhbh" ,value = "客户编号" ,dataType = "String")
    })
    public ResultRespone getRFID(@RequestParam String sid,String sbcjName,String yhbh){
        String rfid = tfYwpnWatermeterService.getRFID(sid,sbcjName,yhbh);
        return ResultRespone.success(rfid);
    }

    /**
     * 水表标定
     * @param tfYwpnWatermeter 水表采集信息
     * @return
     */
    @PostMapping("/calibration")
    @ApiOperation(value = "水表标定")
    public ResultRespone calibration(@RequestBody TfYwpnWatermeter tfYwpnWatermeter){
        return tfYwpnWatermeterService.calibration(tfYwpnWatermeter);
    }

    /**
     * 根据RFID获取水表信息
     * @param rfid 水表RFID
     * @return RFID
     */
    @GetMapping("/getInfoByRFID")
    @ApiOperation(value = "根据RFID获取水表信息 只能获取正在使用水表信息")
    public ResultRespone getWaterMeterInfoByRFID(@RequestParam String rfid){
        return tfYwpnWatermeterService.getWaterMeterInfoByRFID(rfid);
    }

}