/*
 * XzqhController.java
 * 版权所有 © 2011-2017 北京神舟良实信息技术有限公司
 * Copyright © 2011-2017 All Rights Reserved    京ICP备13013562号
 *  created by lipenghe with LAPTOP-DPSC399A
 */
package com.unis.base.server.controller;

import com.unis.base.common.vo.XzqhListVO;
import com.unis.base.common.vo.XzqhShowVO;
import com.unis.base.common.vo.XzqhVO;
import com.unis.base.server.service.XzqhService;
import com.unis.common.utils.JsonUtils;
import com.unis.common.utils.ResponseWrapper;
import com.unis.common.vo.groups.InsertGroup;
import com.unis.common.vo.groups.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TY_XZQHB-无表注释
 * @author lipenghe at 
 */
@RestController
@RequestMapping("")
@Api( tags = "行政区划表---无表注释")
public class XzqhController {

    @Autowired
    private XzqhService xzqhService;

    /*@ApiOperation(value = "行政区划表---无表注释---选择性保存,包含新增和修改", notes = "行政区划表")
    @PostMapping("/xzqh/saveEntitySelective")
    public ResponseWrapper saveEntitySelective(
        @RequestBody XzqhVO xzqhVO) {
        return xzqhService.saveEntitySelectiveResult(xzqhVO);
    }*/

    @ApiOperation(value = "行政区划表---无表注释---选择性插入字段", notes = "行政区划表")
    @PostMapping("/xzqh/insertEntitySelective")
    public ResponseWrapper insertEntitySelective(
        @Validated({InsertGroup.class}) @RequestBody XzqhVO xzqhVO
        , BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            return ResponseWrapper.validateFail(bindingResult.getAllErrors());
        }else{
            return xzqhService.insertEntitySelectiveResult(xzqhVO);
        }
    }

    @ApiOperation(value = "行政区划表---无表注释---批量插入全部字段", notes = "行政区划表")
    @PostMapping("/xzqh/insertBatchEntityList")
    public ResponseWrapper insertBatchEntityList(
        @RequestBody List<XzqhVO> xzqhVOList) {
        return xzqhService.insertBatchEntityListResult(xzqhVOList);
    }

    @ApiOperation(value = "行政区划表---无表注释---根据实体不为空的属性,选择性更新字段", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/updateByEntitySelective")
    public ResponseWrapper updateByEntitySelective(
        @Validated({UpdateGroup.class}) @RequestBody XzqhVO xzqhVO
        , BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            return ResponseWrapper.validateFail(bindingResult.getAllErrors());
        }else{
            return xzqhService.updateByEntitySelectiveResult(xzqhVO, null);
        }
    }

    @ApiOperation(value = "行政区划表---无表注释---更改状态", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/updateStatusByEntity")
    public ResponseWrapper updateStatusByEntity(
        @RequestBody XzqhVO xzqhVO) {
        if(xzqhVO!= null){
            return xzqhService.updateStatusByEntityResult(xzqhVO, null);
        }else{
            return ResponseWrapper.invalid();
        }
    }

    @ApiOperation(value = "行政区划表---无表注释---[真删除]根据实体的某些属性进行单条或者批量删除", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/deleteByEntity")
    public ResponseWrapper deleteByEntity(
        @RequestBody XzqhShowVO xzqhShowVO){
        if(xzqhShowVO!= null){
            XzqhVO xzqhVO= JsonUtils.parse(
                JsonUtils.serialize(xzqhShowVO), XzqhVO.class);
            return xzqhService.deleteByEntityResult(xzqhVO, null);
        }else{
            return ResponseWrapper.invalid();
        }
    }

    @ApiOperation(value = "行政区划表---无表注释---根据实体(唯一标示)查询一条数据", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/selectById")
    public ResponseWrapper selectById(
        @RequestBody XzqhShowVO xzqhShowVO){
        if(xzqhShowVO!= null){
            XzqhVO xzqhVO= JsonUtils.parse(
                JsonUtils.serialize(xzqhShowVO), XzqhVO.class);
            return xzqhService.selectByIdResult(xzqhVO);
        }else{
            return ResponseWrapper.invalid();
        }
    }

    @ApiOperation(value = "行政区划表---无表注释---根据实体的某些属性查询分页数据, pageSize, pageNum从url传", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "int", paramType = "query")
        ,@ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "int", paramType = "query")
        ,@ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "xzqh", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "fzdw", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "xzqhmc", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "fzdwbm", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/selectPageByEntity")
    public ResponseWrapper selectPageByEntity(
        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
        ,@RequestParam(value = "pageSize", defaultValue = "10") int pageSize
        ,@RequestBody XzqhListVO xzqhListVO) {
        XzqhVO xzqhVO= JsonUtils.parse(
            JsonUtils.serialize(xzqhListVO), XzqhVO.class);
        return xzqhService.selectPageByEntityResult(pageNum, pageSize, xzqhVO, "QHID DESC");
    }

    @ApiOperation(value = "行政区划表---无表注释---根据实体的某些属性查询列表", notes = "行政区划表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "qhid", value = "无字段注释 #<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "xzqh", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "fzdw", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "xzqhmc", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
        ,@ApiImplicitParam(name = "fzdwbm", value = "无字段注释 #<检索>", dataType = "String", paramType = "header")
    })
    @PostMapping("/xzqh/selectByEntity")
    public ResponseWrapper selectByEntity(
        @RequestBody XzqhListVO xzqhListVO) {
        XzqhVO xzqhVO= JsonUtils.parse(
            JsonUtils.serialize(xzqhListVO), XzqhVO.class);
        return xzqhService.selectByEntityResult(xzqhVO);
    }

    @ApiOperation(value = "行政区划表---无表注释---初始化数据", notes = "行政区划表")
    @PostMapping("/xzqh/selectInitData")
    public ResponseWrapper selectInitData(
        @RequestBody XzqhVO xzqhVO){
        if(xzqhVO!= null){
            return xzqhService.selectInitDataResult(xzqhVO);
        }else{
            return ResponseWrapper.invalid();
        }
    }

}
