You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
5.0 KiB
Plaintext
175 lines
5.0 KiB
Plaintext
package ${packageName}.service.impl;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
#foreach ($column in $columns)
|
|
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
#break
|
|
#end
|
|
#end
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
#if($table.sub)
|
|
import java.util.ArrayList;
|
|
import com.ruoyi.common.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;
|
|
|
|
/**
|
|
* ${functionName}Service业务层处理
|
|
*
|
|
* @author ${author}
|
|
* @date ${datetime}
|
|
*/
|
|
@Service
|
|
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service
|
|
{
|
|
@Autowired
|
|
private ${ClassName}Mapper ${className}Mapper;
|
|
|
|
/**
|
|
* 查询${functionName}
|
|
*
|
|
* @param ${pkColumn.javaField} ${functionName}ID
|
|
* @return ${functionName}
|
|
*/
|
|
@Override
|
|
public ${ClassName} selectById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
|
return ${className}Mapper.selectById(${pkColumn.javaField});
|
|
}
|
|
|
|
/**
|
|
* 分页查询${functionName}列表
|
|
*
|
|
* @param ${className} ${functionName}
|
|
* @return ${functionName}
|
|
*/
|
|
@Override
|
|
public IPage<${ClassName}> selectList(IPage<${ClassName}> page, ${ClassName} ${className}) {
|
|
return ${className}Mapper.select${ClassName}Page(page, ${className});
|
|
}
|
|
|
|
/**
|
|
* 查询所有${functionName}列表
|
|
*
|
|
* @param ${className} ${functionName}
|
|
* @return ${functionName}
|
|
*/
|
|
@Override
|
|
public List<${ClassName}> selectListAll(${ClassName} ${className}) {
|
|
return ${className}Mapper.select${ClassName}List(${className});
|
|
}
|
|
|
|
/**
|
|
* 新增${functionName}
|
|
*
|
|
* @param ${className} ${functionName}
|
|
* @return 结果
|
|
*/
|
|
#if($table.sub)
|
|
@Transactional
|
|
#end
|
|
@Override
|
|
public int insert(${ClassName} ${className}) {
|
|
#foreach ($column in $columns)
|
|
#if($column.javaField == 'createTime')
|
|
${className}.setCreateTime(DateUtils.getNowDate());
|
|
#end
|
|
#end
|
|
#if($table.sub)
|
|
int rows = ${className}Mapper.insert(${className});
|
|
insert${subClassName}(${className});
|
|
return rows;
|
|
#else
|
|
return ${className}Mapper.insert(${className});
|
|
#end
|
|
}
|
|
|
|
/**
|
|
* 修改${functionName}
|
|
*
|
|
* @param ${className} ${functionName}
|
|
* @return 结果
|
|
*/
|
|
#if($table.sub)
|
|
@Transactional
|
|
#end
|
|
@Override
|
|
public int update(${ClassName} ${className}) {
|
|
#foreach ($column in $columns)
|
|
#if($column.javaField == 'updateTime')
|
|
${className}.setUpdateTime(DateUtils.getNowDate());
|
|
#end
|
|
#end
|
|
#if($table.sub)
|
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
|
|
insert${subClassName}(${className});
|
|
#end
|
|
return ${className}Mapper.updateById(${className});
|
|
}
|
|
|
|
/**
|
|
* 批量删除${functionName}
|
|
*
|
|
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID
|
|
* @return 结果
|
|
*/
|
|
#if($table.sub)
|
|
@Transactional
|
|
#end
|
|
@Override
|
|
public int deleteByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
|
|
#if($table.sub)
|
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
|
#end
|
|
return ${className}Mapper.deleteBatchIds(Arrays.asList(${pkColumn.javaField}s));
|
|
}
|
|
|
|
/**
|
|
* 删除${functionName}信息
|
|
*
|
|
* @param ${pkColumn.javaField} ${functionName}ID
|
|
* @return 结果
|
|
*/
|
|
#if($table.sub)
|
|
@Transactional
|
|
#end
|
|
@Override
|
|
public int deleteById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
|
#if($table.sub)
|
|
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
|
#end
|
|
return ${className}Mapper.deleteById(${pkColumn.javaField});
|
|
}
|
|
#if($table.sub)
|
|
|
|
/**
|
|
* 新增${subTable.functionName}信息
|
|
*
|
|
* @param ${className} ${functionName}对象
|
|
*/
|
|
public void insert${subClassName}(${ClassName} ${className}) {
|
|
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
|
|
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
|
|
if (StringUtils.isNotNull(${subclassName}List)) {
|
|
List<${subClassName}> list = new ArrayList<${subClassName}>();
|
|
for (${subClassName} ${subclassName} :${subclassName}List)
|
|
{
|
|
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
|
|
list.add(${subclassName});
|
|
}
|
|
if (list.size() > 0) {
|
|
${className}Mapper.batch${subClassName}(list);
|
|
}
|
|
}
|
|
}
|
|
#end
|
|
}
|