| | |
| | | package ${packageName}.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | #if($table.crud || $table.sub) |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.core.page.PagePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | #end |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | 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.bo.${ClassName}Bo; |
| | | import ${packageName}.domain.vo.${ClassName}Vo; |
| | | 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; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | |
| | | /** |
| | | * ${functionName}Service业务层处理 |
| | |
| | | * @date ${datetime} |
| | | */ |
| | | @Service |
| | | public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { |
| | | public class ${ClassName}ServiceImpl extends ServicePlusImpl<${ClassName}Mapper, ${ClassName}, ${ClassName}Vo> implements I${ClassName}Service { |
| | | |
| | | @Override |
| | | public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ |
| | | ${ClassName} db = this.baseMapper.selectById(${pkColumn.javaField}); |
| | | return entity2Vo(Collections.singletonList(db)).get(0); |
| | | return getVoById(${pkColumn.javaField}); |
| | | } |
| | | |
| | | #if($table.crud || $table.sub) |
| | | @Override |
| | | public List<${ClassName}Vo> queryList(${ClassName}QueryBo bo) { |
| | | public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo) { |
| | | PagePlus<${ClassName}, ${ClassName}Vo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo)); |
| | | return PageUtils.buildDataInfo(result); |
| | | } |
| | | #end |
| | | |
| | | @Override |
| | | public List<${ClassName}Vo> queryList(${ClassName}Bo bo) { |
| | | return listVo(buildQueryWrapper(bo)); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery(); |
| | | #foreach($column in $columns) |
| | | #if($column.query) |
| | |
| | | #set($mpMethod=$column.queryType.toLowerCase()) |
| | | #if($queryType != 'BETWEEN') |
| | | #if($javaType == 'String') |
| | | #set($condition='StrUtil.isNotBlank(bo.get'+$AttrName+'())') |
| | | #set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())') |
| | | #else |
| | | #set($condition='bo.get'+$AttrName+'() != null') |
| | | #end |
| | | lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName()); |
| | | #else |
| | | 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")); |
| | | } |
| | | lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null, |
| | | ${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; |
| | | return lqw; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean insertByAddBo(${ClassName}AddBo bo) { |
| | | public Boolean insertByBo(${ClassName}Bo bo) { |
| | | ${ClassName} add = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(add); |
| | | return this.save(add); |
| | | return save(add); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateByEditBo(${ClassName}EditBo bo) { |
| | | public Boolean updateByBo(${ClassName}Bo bo) { |
| | | ${ClassName} update = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(update); |
| | | return this.updateById(update); |
| | | return updateById(update); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return this.removeByIds(ids); |
| | | return removeByIds(ids); |
| | | } |
| | | } |