mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-11-16 06:03:44 +08:00
init 单模块项目
This commit is contained in:
118
ruoyi/src/main/resources/vm/java/serviceImpl.java.vm
Normal file
118
ruoyi/src/main/resources/vm/java/serviceImpl.java.vm
Normal file
@@ -0,0 +1,118 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import ${packageName}.bo.${ClassName}AddBo;
|
||||
import ${packageName}.bo.${ClassName}QueryBo;
|
||||
import ${packageName}.bo.${ClassName}EditBo;
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.vo.${ClassName}Vo;
|
||||
import ${packageName}.service.I${ClassName}Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ${functionName}Service业务层处理
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Service
|
||||
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service {
|
||||
|
||||
@Override
|
||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
${ClassName} db = this.baseMapper.selectById(${pkColumn.javaField});
|
||||
return BeanUtil.toBean(db, ${ClassName}Vo.class)
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<${ClassName}Vo> queryList(${ClassName}QueryBo bo) {
|
||||
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#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)})
|
||||
#set($mpMethod=$column.queryType.toLowerCase())
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($javaType == 'String')
|
||||
#set($condition='StrUtil.isNotBlank(bo.get'+$AttrName+'())')
|
||||
#else
|
||||
#set($condition='bo.get'+$AttrName+'() != null')
|
||||
#end
|
||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||
#else
|
||||
Object dataScope = bo.getParams().get("dataScope");
|
||||
lqw.apply(dataScope != null, dataScope != null ? dataScope.toString() : null);
|
||||
Map<String, Object> params = bo.getParams();
|
||||
if (params.get("begin$AttrName") != null && params.get("end$AttrName") != null) {
|
||||
lqw.between(${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
return entity2Vo(this.list(lqw));
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体类转化成视图对象
|
||||
*
|
||||
* @param collection 实体类集合
|
||||
* @return
|
||||
*/
|
||||
private List<${ClassName}Vo> entity2Vo(Collection<${ClassName}> collection) {
|
||||
List<${ClassName}Vo> voList = collection.stream()
|
||||
.map(any -> BeanUtil.toBean(any, ${ClassName}Vo.class))
|
||||
.collect(Collectors.toList());
|
||||
if (collection instanceof Page) {
|
||||
Page<${ClassName}> page = (Page<${ClassName}>)collection;
|
||||
Page<${ClassName}Vo> pageVo = new Page<>();
|
||||
BeanUtil.copyProperties(page,pageVo);
|
||||
pageVo.addAll(voList);
|
||||
voList = pageVo;
|
||||
}
|
||||
return voList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByAddBo(${ClassName}AddBo bo) {
|
||||
${ClassName} add = BeanUtil.toBean(bo, ${ClassName}.class);
|
||||
validEntityBeforeSave(add);
|
||||
return this.save(add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByEditBo(${ClassName}EditBo bo) {
|
||||
${ClassName} update = BeanUtil.toBean(bo, ${ClassName}.class);
|
||||
validEntityBeforeSave(update);
|
||||
return this.updateById(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*
|
||||
* @param entity 实体类数据
|
||||
*/
|
||||
private void validEntityBeforeSave(${ClassName} entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return this.removeByIds(ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user