package ${packageName}.service.impl;

import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.muyu.common.core.utils.DateUtils;
#break
#end
#end
import org.springframework.stereotype.Service;
#if($table.sub)
import java.util.ArrayList;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName};
#end
import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;

/**
 * ${functionName}Service业务层处理
 *
 * @author ${author}
 * @date ${datetime}
 */
@Service
public class ${ClassName}ServiceImpl
        extends ServiceImpl<${ClassName}Mapper, ${ClassName}>
        implements I${ClassName}Service {

    /**
     * 精确查询${functionName}
     *
     * @param ${pkColumn.javaField} ${functionName}主键
     * @return ${functionName}
     */
    @Override
    public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField})
    {
        LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(${pkColumn.javaField}, "${pkColumn.javaField}不可为空");
        queryWrapper.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField});
        return this.getOne(queryWrapper);
    }


    /**
     * 查询${functionName}列表
     *
     * @param ${className} ${functionName}
     * @return ${functionName}
     */
    @Override
    public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
    {
        LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>();
#foreach($column in $columns)
    #set($queryType=$column.queryType)
    #set($javaField=$column.javaField)
    #set($javaType=$column.javaType)
    #set($columnName=$column.columnName)
    #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
    #if($column.query)
    #if($column.queryType == "EQ")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.eq(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "NE")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.ne(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "GT")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.gt(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "GTE")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.ge(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "LT")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.lt(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "LTE")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.le(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #elseif($queryType == "LIKE")
        if (StringUtils.isNotEmpty(${className}.get${AttrName}())){
            queryWrapper.like(${ClassName}::get${AttrName}, ${className}.get${AttrName}());
        }
    #end
    #end
#end
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param ${className} ${functionName}
     * @return ${functionName}
    */
    @Override
    public Boolean checkIdUnique(${ClassName} ${className}) {
        LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(${ClassName}::get${pkColumn.capJavaField}, ${className}.get${pkColumn.capJavaField}());
        return this.count(queryWrapper) > 0;
    }

}
