<%
var parentPkgName=GetGParamValue('EZGEN_ROOT_PKGNAME'); //上级包名
if(!parentPkgName)parentPkgName='com.ruoyi.project';
var modelPkgName=AutoCapProc(curModel.name,'JavaPackageName');
var modelCap=curModel.caption?curModel.caption:curModel.name;
var tb=curTable; //当前表
var tbPkgName=AutoCapProc(tb.name,'JavaPackageName');
var ClsName=AutoCapProc(tb.name,'ClassName'); //类名（驼峰命名，首字母大写）
var instName=AutoCapProc(tb.name,'FieldName'); //类名（驼峰命名，首字母小写）
var dispName=tb.UIDisplayName; //逻辑显示名
if(!dispName)dispName=ClsName;

var idName='id';
var idTp='Long';
var pk=tb.getPrimaryKeyField();
if(pk){
    idName=AutoCapProc(pk.name,'FieldName');
    if(pk.dataType!='cfdtInteger')
        idTp='String';
}
%>package ${parentPkgName}.${modelPkgName}.${AutoCapProc(tb.name,'JavaPackageName')}.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.project.system.menu.domain.Menu;
import com.ruoyi.project.system.menu.service.IMenuService;
import com.ruoyi.common.utils.text.Convert;
import ${parentPkgName}.${modelPkgName}.${tbPkgName}.domain.${ClsName};
import ${parentPkgName}.${modelPkgName}.${tbPkgName}.mapper.${ClsName}Mapper;
import ${parentPkgName}.${modelPkgName}.${tbPkgName}.service.I${ClsName}Service;

/**
 * ${dispName}Service业务层处理
 * 
 * @author ezdml
 * Generated by EZDML ${DateTimeToStr(_now())}
 */
@Service
public class ${ClsName}ServiceImpl implements I${ClsName}Service 
{
    @Autowired
    private ${ClsName}Mapper ${instName}Mapper;

    @Autowired
    private IMenuService menuService;

    /**
     * 根据ID查询${dispName}
     * 
     * @param ${idName} ${dispName}主键
     * @return ${dispName}
     */
    @Override
    public ${ClsName} select${ClsName}ById(${idTp} ${idName})
    {
        return ${instName}Mapper.select${ClsName}ById(${idName});
    }

    /**
     * 根据条件查询${dispName}列表
     * 
     * @param ${instName} ${dispName} 包含查询条件和分页参数
     * @return ${dispName}集合
     */
    @Override
    public List<${ClsName}> select${ClsName}List(${ClsName} ${instName})
    {
        return ${instName}Mapper.select${ClsName}List(${instName});
    }

    /**
     * 新增${dispName}
     * 
     * @param ${instName} ${dispName}
     * @return 结果
     */
    @Override
    public int insert${ClsName}(${ClsName} ${instName})
    {
        return ${instName}Mapper.insert${ClsName}(${instName});
    }

    /**
     * 修改${dispName}
     * 
     * @param ${instName} ${dispName}
     * @return 结果
     */
    @Override
    public int update${ClsName}(${ClsName} ${instName})
    {
        return ${instName}Mapper.update${ClsName}(${instName});
    }

    /**
     * 删除${dispName}
     * 
     * @param ${idName} ${dispName}主键
     * @return 结果
     */
    @Override
    public int delete${ClsName}ById(${idTp} ${idName})
    {
        return ${instName}Mapper.delete${ClsName}ById(${idName});
    }

    /**
     * 批量删除${dispName}
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int delete${ClsName}ByIds(String ids)
    {
        return ${instName}Mapper.delete${ClsName}ByIds(Convert.toStrArray(ids));
    }

    @Override
    public void initDb(){
        System.out.println("${ClsName} db init....");
        ${instName}Mapper.checkInitTableDDL();
        Menu mn;
        mn=menuService.checkInitMenu("${modelCap}", 0L, "","${curModel.id}", "M", "${modelPkgName}:${instName}","fa fa-map-signs");
        if(mn==null) {
            throw new RuntimeException("${ClsName} main menu init failed");
        }
        long pid=mn.getMenuId();
        menuService.checkInitMenu("${dispName}", pid, "/${modelPkgName}/${tbPkgName}","${tb.id}","C", "${modelPkgName}:${instName}:view","#");
        menuService.checkInitMenu("${dispName}查询", pid, "#","1","F", "${modelPkgName}:${instName}:list","#");
        menuService.checkInitMenu("${dispName}新增", pid, "#","2","F", "${modelPkgName}:${instName}:add","#");
        menuService.checkInitMenu("${dispName}修改", pid, "#","3","F", "${modelPkgName}:${instName}:edit","#");
        menuService.checkInitMenu("${dispName}删除", pid, "#","4","F", "${modelPkgName}:${instName}:remove","#");
        menuService.checkInitMenu("${dispName}导出", pid, "#","5","F", "${modelPkgName}:${instName}:export","#");
    }
}
