package {{packageName}}.core.{{entity.module}}.service;

{{#each entity.allPSDEMethodDTOs as |deMethodDTO|}}
    {{#if (or (eq deMethodDTO.type 'DEFAULT') (eq deMethodDTO.type 'DEACTIONINPUT'))}}
import {{packageName}}.core.{{entity.module}}.dto.{{deMethodDTO.name}};
    {{/if}}
{{/each}}
import net.ibizsys.central.dataentity.service.IDEService;
import net.ibizsys.central.util.IEntityDTO;
import net.ibizsys.central.util.ISearchContextDTO;
import net.ibizsys.central.util.SearchContextDTO;
import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import net.ibizsys.model.dataentity.service.IPSDEMethodDTO;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Page;

/**
 * {{entity.logicName}}
{{#if entity.memo}}
 * {{entity.memo}}
{{/if}}
 * 
 */
public interface I{{entity.codeName}}Service extends IDEService<{{entity.defaultPSDEMethodDTO.name}}, SearchContextDTO> {

{{#each entity.allPSDEFields as |field|}}
    /**
     * 属性: {{field.logicName}}
     */
    String FIELD_{{upperCase field.name}} = "{{field.name}}";

{{/each}}
{{#each entity.allPSDEActions as |action|}}
    /**
     * 行为: {{action.logicName}}
     */
    String ACTION_{{upperCase action.name}} = "{{action.name}}";

{{/each}}
{{#each entity.allPSDEDataQueries as |query|}}
    /**
     * 查询: {{query.logicName}}
     */
    String DATAQUERY_{{upperCase query.name}} = "{{query.name}}";

{{/each}}
{{#each entity.allPSDEDataSets as |dataSet|}}
    /**
     * 集合: {{dataSet.logicName}}
     */
    String DATASET_{{upperCase dataSet.name}} = "{{dataSet.name}}";

{{/each}}
    @Override
    default String getDataEntityId() {
        return "{{entity.dynaModelFilePath}}";
    }

    @Override
    default IEntityDTO createEntityDTO(IPSDEMethodDTO iPSDEMethodDTO) {
        String strName = iPSDEMethodDTO.getName();
        switch (strName) {
{{#each entity.allPSDEMethodDTOs as |deMethodDTO|}}
    {{#if (or (eq deMethodDTO.type 'DEFAULT') (eq deMethodDTO.type 'DEACTIONINPUT'))}}
            case "{{deMethodDTO.name}}":
                return new {{deMethodDTO.name}}();
    {{/if}}
{{/each}}
            default:
                return null;
        }
    }

    @Override
    default ISearchContextDTO createSearchContextDTO(IPSDEMethodDTO iPSDEMethodDTO) {
        return new SearchContextDTO();
    }

    @Override
    default Object executeAction(String strActionName, IPSDEAction iPSDEAction, Object[] args) throws Throwable {
        switch (strActionName.toLowerCase()) {
{{#each entity.allPSDEActions as |deAction|}}
            {{#if deAction.enableBackend}}
            case "{{lowerCase deAction.name}}" :
              {{#if neq deAction.pSDEActionReturn.type 'VOID'}}
                return this.{srfmethodname(deAction.getCodeName())}(({getDEActionInputType(deAction)}) args[0]);
              {{else}}
                this.{srfmethodname(deAction.getCodeName())}(({getDEActionInputType(deAction)}) args[0]);
                return null;
              {{/if}}
            {{/if}}
{{/each}}
        }
        return this.getDataEntityRuntime().executeAction(strActionName, iPSDEAction, args, true);
    }

    @Override
    default Object fetchDataSet(String strDataSetName, IPSDEDataSet iPSDEDataSet, Object[] args) throws Throwable {
        switch (strDataSetName.toLowerCase()) {
{{#each entity.allPSDEDataSets as |deDataSet|}}
            case "{{lowerCase deDataSet.name}}" :
               return this.fetch{{pascalCase deDataSet.codeName}}((ISearchContextDTO) args[0]);
{{/each}}
        }
        return this.getDataEntityRuntime().fetchDataSet(strDataSetName, iPSDEDataSet, args, true);
    }

      {{#each entity.allPSDEActions as |deAction|}}
        {{#if deAction.enableBackend}}
    /**
     * {{#if deAction.logicName}}{{deAction.logicName}}{{else}}{{deAction.name}}{{/if}}
     {{#if deAction.memo}}
     * {{deAction.memo}}
     {{/if}}
     *
     * @param dto
     * @throws Throwable
     */
    default {getDEActionReturn(deAction)} {srfmethodname(deAction.getCodeName())}({getDEActionInput(deAction)}) throws Throwable {
        {{#if neq deAction.pSDEActionReturn.type 'VOID'}}return ({getDEActionReturn(deAction)}) {{/if}}this.getDataEntityRuntime().executeAction("{deAction.getName()}", null, new Object[]{{getDEActionInputParams(deAction)}}, true);
    }

        {{/if}}
      {{/each}}
{{#each entity.allPSDEDataSets as |dataSet|}}
        {{#neq dataSet.ctionHoldera 2}}
    /**
     * {{#if dataSet.logicName}}{{dataSet.logicName}}{{else}}{{dataSet.name}}{{/if}}
        {{#if dataSet.memo}}
     * {{dataSet.memo}}
        {{/if}}
     *
     * @param dto
     * @return
     * @throws Throwable
     */
    default Page<{{entity.defaultPSDEMethodDTO.name}}> fetch{{pascalCase dataSet.codeName}}(ISearchContextDTO dto) throws Throwable {
        return (Page<{{entity.defaultPSDEMethodDTO.name}}>) this.getDataEntityRuntime().fetchDataSet("{{dataSet.name}}", null, new Object[]{dto}, true);
    }

        {{/neq}}
{{/each}}
{{#each entity.allPSDEDataQueries as |dataQuery|}}
    /**
     * {{#if dataQuery.logicName}}{{dataQuery.logicName}}{{else}}{{dataQuery.name}}{{/if}}
     {{#if dataQuery.memo}}
     * {{dataQuery.memo}}
     {{/if}}
     *
     * @param dto
     * @return
     * @throws Throwable
     */
    default List<{{entity.defaultPSDEMethodDTO.name}}> select{{pascalCase dataQuery.codeName}}(ISearchContextDTO dto) throws Throwable {
        Object obj = this.getDataEntityRuntime().selectDataQuery("{{dataQuery.name}}", dto);
        return (List<{{entity.defaultPSDEMethodDTO.name}}>) obj;
    }

{{/each}}

}