From f093da99ecb963d19d62dc0f242f00b20bc8895c Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 14 四月 2021 13:22:31 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev --- ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm | 152 +++++++++++++++++++++++++++----------------------- 1 files changed, 81 insertions(+), 71 deletions(-) diff --git a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm b/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm index 6f52b70..cbf9d32 100644 --- a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm @@ -1,15 +1,24 @@ 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 org.apache.commons.lang3.StringUtils; -import ${packageName}.mapper.${ClassName}Mapper; +import com.github.pagehelper.Page; +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涓氬姟灞傚鐞� @@ -21,89 +30,90 @@ public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { @Override - public List<${ClassName}> queryList(${ClassName} ${className}) { + 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)}) -#if($column.query) -#if($column.queryType == "EQ") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.eq(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#else - if (${className}.get$AttrName() != null){ - lqw.eq(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#end -#elseif($queryType == "NE") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.ne(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#else - if (${className}.get$AttrName() != null){ - lqw.ne(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#end -#elseif($queryType == "GT") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.gt(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#else - if (${className}.get$AttrName() != null){ - lqw.gt(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#end -#elseif($queryType == "GTE") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.ge(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#else - if (${className}.get$AttrName() != null){ - lqw.ge(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#end -#elseif($queryType == "LT") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.lt(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#else - if (${className}.get$AttrName() != null){ - lqw.lt(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } -#end -#elseif($queryType == "LTE") +#set($mpMethod=$column.queryType.toLowerCase()) +#if($queryType != 'BETWEEN') #if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.le(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } +#set($condition='StrUtil.isNotBlank(bo.get'+$AttrName+'())') #else - if (${className}.get$AttrName() != null){ - lqw.le(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } +#set($condition='bo.get'+$AttrName+'() != null') #end -#elseif($queryType == "LIKE") -#if($javaType == 'String') - if (StringUtils.isNotBlank(${className}.get$AttrName())){ - lqw.like(${ClassName}::get$AttrName ,${className}.get$AttrName()); - } + lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName()); #else - if (${className}.get$AttrName() != null){ - lqw.like(${ClassName}::get$AttrName ,${className}.get$AttrName()); + 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 -#elseif($queryType == "BETWEEN") #end #end -#end - return this.list(lqw); + 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); } } -- Gitblit v1.9.3