package com.jiayue.ipfcst.dataexchange.controller;

import com.jiayue.ipfcst.aop.SaveValidate;
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.dataexchange.domain.TemplatePoint;
import com.jiayue.ipfcst.dataexchange.service.TemplatePointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模版点位对外接口
 *
 * @author 修唯xiuwei
 * @version 3.0
 */
@RequestMapping("dataExchange")
@RestController
public class TemplatePointController {


  /**
   * 操作服务类
   */
  @Autowired
  TemplatePointService templatePointService;


  /**
   * 批量向模版中添加点位
   *
   * @param templatePoints 模版点位集合
   * @return ResponseVO 统一返回值格式
   */
  @PutMapping(value = "templatePoints")
  @SaveValidate
  public ResponseVO addAll(@RequestBody List<TemplatePoint> templatePoints) {
    return ResponseVO.success(templatePointService.addAll(templatePoints));
  }


  /**
   * 向模版中添加点位
   *
   * @param templatePoint 模版点位
   * @return ResponseVO 统一返回值格式
   */
  @SaveValidate
  @PutMapping(value = "templatePoint")
  public ResponseVO add(@RequestBody TemplatePoint templatePoint) {
    return ResponseVO.success(templatePointService.add(templatePoint));
  }


  /**
   * 获取模版信息
   *
   * @param templatePoint 模版点位
   * @return ResponseVO 统一返回值格式
   */
  @GetMapping(value = "templatePoint")
  public ResponseVO get(@ModelAttribute() TemplatePoint templatePoint) {
    return ResponseVO.success(templatePointService.get(templatePoint));
  }


  /**
   * 修改模版点位
   *
   * @param templatePoint 模版点位
   * @return ResponseVO 统一返回值格式
   */
  @PostMapping(value = "templatePoint")
  @SaveValidate
  public ResponseVO update(@RequestBody TemplatePoint templatePoint) {
    return ResponseVO.success(templatePointService.update(templatePoint));
  }


  /**
   * 删除模版点位BY ID
   *
   * @param templatePointId 模版点位
   * @return ResponseVO 统一返回值格式
   */
  @DeleteMapping(value = "templatePointById")
  @SaveValidate
  public ResponseVO deleteById(@RequestBody Integer templatePointId) {
    templatePointService.deleteById(templatePointId);
    return ResponseVO.success();
  }


  /**
   * 删除符合条件的模版点位
   *
   * @param templatePoint 模版点位
   * @return ResponseVO 统一返回值格式
   */
  @DeleteMapping(value = "templatePoint")
  @SaveValidate
  public ResponseVO delete(@RequestBody TemplatePoint templatePoint) {
    templatePointService.delete(templatePoint);
    return ResponseVO.success();
  }

}
