templates.crud.serviceImpl.ftl Maven / Gradle / Ivy
package ${cfg.packageName}.service.${cfg.folderName}.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.yes.tools.page.CommonPage;
import ${cfg.packageName}.common.page.PageParam;
import org.yes.tools.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${cfg.packageName}.common.entity.${cfg.folderName}.${entity};
import ${cfg.packageName}.common.dto.${cfg.folderName}.${entity?replace('Entity','Dto')};
import ${cfg.packageName}.common.vo.${cfg.folderName}.${entity?replace('Entity','Vo')};
import ${cfg.packageName}.service.${cfg.folderName}.dao.${table.mapperName};
import ${cfg.packageName}.service.${cfg.folderName}.service.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
/**
*
* ${table.comment!} 服务实现类
*
*
* @author ${author}
* @since ${date}
*/
@Service(value = "${cfg.folderName}${table.serviceImplName}")
@DS("${cfg.folderName}")
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
<#if !cfg.isView>
@Override
public ${entity?replace('Entity','Vo')} create(${entity?replace('Entity','Dto')} ${entity?replace('Entity','Dto') ? uncap_first}) {
${entity} ${entity ? uncap_first} = BeanCopyUtils.copyAs(${entity?replace('Entity','Dto') ? uncap_first}, ${entity}.class);
this.baseMapper.insert(${entity ? uncap_first});
return BeanCopyUtils.copyAs(${entity ? uncap_first}, ${entity?replace('Entity','Vo')}.class);
}
@Override
public ${entity?replace('Entity','Vo')} editById(${entity?replace('Entity','Dto')} ${entity?replace('Entity','Dto') ? uncap_first}) {
<#list table.fields as field><#if field.keyFlag>
${entity} ${entity ? uncap_first} = this.baseMapper.selectById(${entity?replace('Entity','Dto') ? uncap_first}.get${field.propertyName ? cap_first}());
#if>#list>
BeanCopyUtils.copyProperties(${entity?replace('Entity','Dto') ? uncap_first}, ${entity ? uncap_first});
this.baseMapper.updateById(${entity ? uncap_first});
return BeanCopyUtils.copyAs(${entity ? uncap_first}, ${entity?replace('Entity','Vo')}.class);
}
@Override
public ${entity?replace('Entity','Vo')} findById(Long id) {
${entity} ${entity ? uncap_first} = this.baseMapper.selectById(id);
return BeanCopyUtils.copyAs(${entity ? uncap_first}, ${entity?replace('Entity','Vo')}.class);
}
#if>
@Override
public IPage<${entity?replace('Entity','Vo')}> queryByPage(PageParam pageParam, ${entity?replace('Entity','Dto')} dto) {
LambdaQueryWrapper<${entity}> queryWrapper = Wrappers.lambdaQuery();
IPage<${entity}> page = new Page<>(pageParam.getPage(), pageParam.getLimit());
IPage<${entity}> ${entity ? uncap_first}Page = this.baseMapper.selectPage(page, queryWrapper);
IPage<${entity?replace('Entity','Vo')}> ${entity?replace('Entity','VoPage') ? uncap_first} = new Page<>();
CommonPage.copyIPage(${entity ? uncap_first}Page, ${entity?replace('Entity','VoPage') ? uncap_first}, ${entity?replace('Entity','Vo')}.class);
return ${entity?replace('Entity','VoPage') ? uncap_first};
}
}
#if>