All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.mybatis.serviceImpl.ftl Maven / Gradle / Ivy

package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import java.util.List;
import ${package.Parent}.vo.*;
import ${package.Parent}.dto.*;
import matrix.boot.common.dto.PageDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import matrix.boot.common.utils.AssertUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import matrix.boot.jdbc.orm.mybatis.converter.PageConvert;

/**
 * ${table.comment!}
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#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} {

    @Override
    public PageDto<${javaName}Dto> list${javaName}ByCondition(${javaName}QueryVo queryVo) {
        QueryWrapper<${javaName}Entity> queryWrapper = new QueryWrapper<>();
        Page<${javaName}Entity> page = page(PageConvert.paramsConvert(queryVo, ${javaName}Entity.class), queryWrapper);
        return PageConvert.resultConvert(page, ${javaName}Dto.class);
    }

    @Override
    public void save${javaName}(${javaName}SaveVo saveVo) {
        ${javaName}Entity data;
        if (StringUtils.isEmpty(saveVo.getId())) {
            data = new ${javaName}Entity();
        } else {
            data = getById(saveVo.getId());
            AssertUtil.state(data != null, "data not exist");
            assert data != null;
        }
        BeanUtils.copyProperties(saveVo, data);
        saveOrUpdate(data);
    }

    @Override
    public ${javaName}Dto detailById(String field, String id) {
        QueryWrapper<${javaName}Entity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(field, id);
        ${javaName}Entity entity = getOne(queryWrapper, false);
        AssertUtil.state(entity != null, "no data");
        ${javaName}Dto result = new ${javaName}Dto();
        assert entity != null;
        BeanUtils.copyProperties(entity, result);
        return result;
    }

    @Override
    <#if enableKeyToString == true>
    public void deleteByIds(List ids) {
    <#else>
    public void deleteByIds(List ids) {
    
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        removeByIds(ids);
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy