{{#unless nested}}
{{#neq apiEntity.entity.storage "NONE"}}
package {{packageName}}.{{lowerCase apiEntity.api.codeName}}.rest;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import {{packageName}}.{{lowerCase apiEntity.api.codeName}}.dto.*;
import {{packageName}}.{{lowerCase apiEntity.api.codeName}}.mapping.*;
import {{packageName}}.core.{{apiEntity.entity.module}}.domain.{{apiEntity.entity.codeName}};
import {{packageName}}.core.{{apiEntity.entity.module}}.service.I{{apiEntity.entity.codeName}}Service;
import {{packageName}}.core.{{apiEntity.entity.module}}.filter.{{apiEntity.entity.codeName}}SearchContext;
import cn.ibizlab.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"{{apiEntity.entity.logicName}}" })
@RestController("{{lowerCase apiEntity.api.codeName}}-{{lowerCase apiEntity.codeName}}")
@RequestMapping("")
public class {{apiEntity.codeName}}Resource {

    @Autowired
    public I{{apiEntity.entity.codeName}}Service {{camelCase apiEntity.entity.codeName}}Service;

{{#each apiEntity.dtos}}
    {{#eq type "DEFAULT"}}
    @Autowired
    @Lazy
    public {{codeName}}Mapping {{camelCase codeName}}Mapping;

    {{/eq}}
{{/each}}

{{#each apiEntity.methods}}
    @ApiOperation(value = "{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "{{apiEntity.entity.logicName}}")
    @RequestMapping(method = RequestMethod.{{requestMethod}}, value = "{{requestPath}}")
    public ResponseEntity {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}@Validated @RequestBody {{#eq input.type "DTO"}}{{body}}{{/eq}}{{#eq input.type "KEYFIELD"}}{{#eq pSDEAction.actionType "USERCUSTOM"}}{{body}}{{/eq}}{{/eq}}{{#eq input.type "DTOS"}}List<{{body}}>{{/eq}} {{#eq input.type "DTO"}}{{camelCase body}}{{/eq}}{{#eq input.type "KEYFIELD"}}{{#eq pSDEAction.actionType "USERCUSTOM"}}{{camelCase body}}{{/eq}}{{/eq}}{{#eq input.type "DTOS"}}list{{/eq}}{{/if}}) {
    {{!行为}}
    {{#eq methodType "DEACTION"}}
    {{!行为参数准备}}
    {{#eq input.type "DTO"}}
        {{apiEntity.entity.codeName}} {{camelCase apiEntity.entity.codeName}} = {{camelCase input.psDEMethodDTO.name}}Mapping.toDomain({{camelCase body}});
    {{#each pathVariables}}
        {{#if @last}}
        {{camelCase apiEntity.entity.codeName}}.set{{pascalCase name}}({{camelCase name}});
        {{/if}}
    {{/each}}
        {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{camelCase apiEntity.entity.codeName}});
    {{/eq}}
    {{#eq input.type "DTOS"}}
        {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}Batch({{camelCase input.psDEMethodDTO.name}}Mapping.toDomain(list));
    {{/eq}}
    {{#eq input.type "KEYFIELD"}}
        {{#eq return.type "DTO"}}
            {{#if body}}
                {{apiEntity.entity.codeName}} {{camelCase apiEntity.entity.codeName}} = {{camelCase body}}Mapping.toDomain({{camelCase body}});
                {{#each pathVariables}}
                    {{#if @last}}
        {{camelCase apiEntity.entity.codeName}}.set{{pascalCase name}}({{camelCase name}});
                    {{/if}}
                {{/each}}
        {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{camelCase apiEntity.entity.codeName}});
            {{/if}}
            {{#unless body}}
        {{apiEntity.entity.codeName}} {{camelCase apiEntity.entity.codeName}} = {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{camelCase apiEntity.entity.keyField.codeName}});
            {{/unless}}
        {{/eq}}
        {{#neq return.type "DTO"}}
        {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{camelCase apiEntity.entity.keyField.codeName}});
        {{/neq}}
    {{/eq}}
    {{!返回处理}}
    {{#eq return.type "DTO"}}
        return ResponseEntity.status(HttpStatus.OK).body({{camelCase return.psDEMethodDTO.name}}Mapping.toDto({{camelCase apiEntity.entity.codeName}}));
    {{/eq}}
    {{#eq return.type "DTOS"}}
        return ResponseEntity.status(HttpStatus.OK).body(true);
    {{/eq}}
    {{#eq return.type "SIMPLE"}}
        return ResponseEntity.status(HttpStatus.OK).body(0);
    {{/eq}}
    {{#eq return.type "KEYFIELD"}}

    {{/eq}}
    {{#eq return.type "VOID"}}
        return ResponseEntity.status(HttpStatus.OK).body(true);
    {{/eq}}
    {{#eq return.type "USER"}}
        return ResponseEntity.status(HttpStatus.OK).body({{camelCase body}}Mapping.toDto({{camelCase apiEntity.entity.codeName}}));
    {{/eq}}
    {{/eq}}
    {{!数据集}}
    {{#eq methodType "FETCH"}}
        {{#each pathVariables}}
            {{#if @last}}
        {{camelCase body}}.set{{pascalCase name}}EQ({{camelCase name}});
            {{/if}}
        {{/each}}
        Page<{{apiEntity.entity.codeName}}> domains = {{camelCase apiEntity.entity.codeName}}Service.search{{pascalCase pSDEDataSet.codeName}}({{camelCase body}}) ;
            List<{{return.psDEMethodDTO.name}}> list = {{camelCase return.psDEMethodDTO.name}}Mapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf({{camelCase body}}.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf({{camelCase body}}.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    {{/eq}}
    {{!SELECT法}}
    {{#eq methodType "SELECT"}}
        return ResponseEntity.status(HttpStatus.OK).body(null);
    {{/eq}}
    }

{{/each}}

}
{{/neq}}
{{/unless}}