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

import com.unis.base.common.vo.QybgsqListVO;
import com.unis.base.common.vo.QybgsqShowVO;
import com.unis.base.common.vo.QybgsqVO;
import com.unis.base.server.service.QybgsqService;
import com.unis.common.constant.BaseStatusConstant;
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.Date;
import java.util.List;

/**
 * TY_QYBGSQ-企业变更申请表
 * @author lipenghe at 
 */
@RestController
@RequestMapping("")
@Api( tags = "企业变更申请表---企业变更申请表")
public class QybgsqController {

    @Autowired
    private QybgsqService qybgsqService;

    /*@ApiOperation(value = "企业变更申请表---企业变更申请表---选择性保存,包含新增和修改", notes = "企业变更申请表")
    @PostMapping("/qybgsq/saveEntitySelective")
    public ResponseWrapper saveEntitySelective(
        @RequestBody QybgsqVO qybgsqVO) {
        return qybgsqService.saveEntitySelectiveResult(qybgsqVO);
    }*/

    @ApiOperation(value = "企业变更申请表---企业变更申请表---选择性插入字段", notes = "企业变更申请表")
    @PostMapping("/qybgsq/insertEntitySelective")
    public ResponseWrapper insertEntitySelective(
        @Validated({InsertGroup.class}) @RequestBody QybgsqVO qybgsqVO
        , BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            return ResponseWrapper.validateFail(bindingResult.getAllErrors());
        }else{
            qybgsqVO.setSfty("-999");
            qybgsqVO.setSqsj(new Date());
            return qybgsqService.insertEntitySelectiveResult(qybgsqVO);
        }
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---批量插入全部字段", notes = "企业变更申请表")
    @PostMapping("/qybgsq/insertBatchEntityList")
    public ResponseWrapper insertBatchEntityList(
        @RequestBody List<QybgsqVO> qybgsqVOList) {
        return qybgsqService.insertBatchEntityListResult(qybgsqVOList);
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---根据实体不为空的属性,选择性更新字段", notes = "企业变更申请表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/updateByEntitySelective")
    public ResponseWrapper updateByEntitySelective(
        @Validated({UpdateGroup.class}) @RequestBody QybgsqVO qybgsqVO
        , BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            return ResponseWrapper.validateFail(bindingResult.getAllErrors());
        }else{
            qybgsqVO.setSpsj(new Date());
            return qybgsqService.updateByEntitySelectiveResult(qybgsqVO, null);
        }
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---更改状态", notes = "企业变更申请表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/updateStatusByEntity")
    public ResponseWrapper updateStatusByEntity(
        @RequestBody QybgsqVO qybgsqVO) {
        if(qybgsqVO!= null){
            return qybgsqService.updateStatusByEntityResult(qybgsqVO, null);
        }else{
            return ResponseWrapper.invalid();
        }
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---[真删除]根据实体的某些属性进行单条或者批量删除", notes = "企业变更申请表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/deleteByEntity")
    public ResponseWrapper deleteByEntity(
        @RequestBody QybgsqShowVO qybgsqShowVO){
        if(qybgsqShowVO!= null){
            QybgsqVO qybgsqVO= JsonUtils.parse(
                JsonUtils.serialize(qybgsqShowVO), QybgsqVO.class);
            qybgsqVO.setStatus(Integer.valueOf(BaseStatusConstant.STATUS_DELETED));
            return qybgsqService.deleteByEntityResult(qybgsqVO, null);
        }else{
            return ResponseWrapper.invalid();
        }
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---根据实体(唯一标示)查询一条数据", notes = "企业变更申请表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/selectById")
    public ResponseWrapper selectById(
        @RequestBody QybgsqShowVO qybgsqShowVO){
        if(qybgsqShowVO!= null){
            QybgsqVO qybgsqVO= JsonUtils.parse(
                JsonUtils.serialize(qybgsqShowVO), QybgsqVO.class);
            return qybgsqService.selectByIdResult(qybgsqVO);
        }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 = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/selectPageByEntity")
    public ResponseWrapper selectPageByEntity(
        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
        ,@RequestParam(value = "pageSize", defaultValue = "10") int pageSize
        ,@RequestBody QybgsqListVO qybgsqListVO) {
        QybgsqVO qybgsqVO= JsonUtils.parse(
            JsonUtils.serialize(qybgsqListVO), QybgsqVO.class);
        return qybgsqService.selectPageByEntityResult(pageNum, pageSize, qybgsqVO, "SQID DESC");
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---根据实体的某些属性查询列表", notes = "企业变更申请表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sqid", value = "变更申请id#<主键><唯一><检索><非空>", dataType = "String", paramType = "header")
    })
    @PostMapping("/qybgsq/selectByEntity")
    public ResponseWrapper selectByEntity(
        @RequestBody QybgsqListVO qybgsqListVO) {
        QybgsqVO qybgsqVO= JsonUtils.parse(
            JsonUtils.serialize(qybgsqListVO), QybgsqVO.class);
        return qybgsqService.selectByEntityResult(qybgsqVO);
    }

    @ApiOperation(value = "企业变更申请表---企业变更申请表---初始化数据", notes = "企业变更申请表")
    @PostMapping("/qybgsq/selectInitData")
    public ResponseWrapper selectInitData(
        @RequestBody QybgsqVO qybgsqVO){
        if(qybgsqVO!= null){
            return qybgsqService.selectInitDataResult(qybgsqVO);
        }else{
            return ResponseWrapper.invalid();
        }
    }

}
