/*
* Copyright (c) ${Company} Corporation ${Year} . All rights reserved.
*
*/
package ${genPackage}.${javaClassRef.getClassName()};

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * ${javaClassRef.getComment()} => Restful 类型 HTTP/HTTPS 接口
 *
 * @author ${Author}
 * @since ${Version}
 */
@Api(tags = "${javaClassRef.getComment()}")
@RequestMapping("/v1/${javaClassRef.getClassName()}s")
@RestController
public class ${javaClassRef.getClassName()}RestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(${javaClassRef.getClassName()}RestfulCtrl.class);

  @Autowired
  private ${javaClassRef.getClassName()}ApiService apiService;

  /**
   * Restful接口-post： 新增${javaClassRef.getComment()}
   *
   * @param inputDto         接口数据传输对象
   * @return 主键
   */
  @ApiOperation(value = "新增：${javaClassRef.getComment()}")
  @PostMapping(
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<String> add(
      @RequestBody @Validated ${javaClassRef.getClassName()}AddDto inputDto)
  {
    ResultWrapper<String> wrapper = new ResultWrapper<>();
    String uuid = apiService.add(inputDto);
    return wrapper.success(uuid);
  }

  /**
   * Restful接口-put： 更新${javaClassRef.getComment()}
   *
   * @param inputDto         接口数据传输对象
   * @return 修改的记录数量
   */
  @ApiOperation(value = "更新：${javaClassRef.getComment()}")
  @PutMapping(
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> update(
      @RequestBody @Validated ${javaClassRef.getClassName()}UpdateDto inputDto) throws IllegalAccessException
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.updateByPK(inputDto);
    return wrapper.success(count);
  }

  /**
   * Restful接口-get： 获取${javaClassRef.getComment()}
   *
   * @param uuid       主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "获取：${javaClassRef.getComment()}")
  @GetMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<${javaClassRef.getClassName()}DetailDto> findByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<${javaClassRef.getClassName()}DetailDto> wrapper = new ResultWrapper<>();
    ${javaClassRef.getClassName()}DetailDto dto = apiService.findByPK(uuid);
    return wrapper.success(dto);
  }

  /**
   * Restful接口-delete： 删除${javaClassRef.getComment()}
   *
   * @param uuid       主键
   * @return 删除的记录数量
   */
  @ApiOperation(value = "删除：${javaClassRef.getComment()}")
  @DeleteMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.deleteByPK(uuid);
    return wrapper.success(count);
  }
}
