| | |
| | | package ${packageName}.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.core.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; |
| | | import com.ruoyi.common.mybatis.core.page.TableDataInfo; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | #end |
| | | import org.springframework.stereotype.Service; |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | 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.List; |
| | |
| | | * @author ${author} |
| | | * @date ${datetime} |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class ${ClassName}ServiceImpl extends ServicePlusImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { |
| | | public class ${ClassName}ServiceImpl implements I${ClassName}Service { |
| | | |
| | | private final ${ClassName}Mapper baseMapper; |
| | | |
| | | /** |
| | | * 查询${functionName} |
| | | */ |
| | | @Override |
| | | public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ |
| | | return getVoById(${pkColumn.javaField}, ${ClassName}Vo.class); |
| | | return baseMapper.selectVoById(${pkColumn.javaField}); |
| | | } |
| | | |
| | | #if($table.crud || $table.sub) |
| | | /** |
| | | * 查询${functionName}列表 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}QueryBo bo) { |
| | | PagePlus<${ClassName}, ${ClassName}Vo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ${ClassName}Vo.class); |
| | | return PageUtils.buildDataInfo(result); |
| | | public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo); |
| | | Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | #end |
| | | |
| | | /** |
| | | * 查询${functionName}列表 |
| | | */ |
| | | @Override |
| | | public List<${ClassName}Vo> queryList(${ClassName}QueryBo bo) { |
| | | return listVo(buildQueryWrapper(bo), ${ClassName}Vo.class); |
| | | public List<${ClassName}Vo> queryList(${ClassName}Bo bo) { |
| | | LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo); |
| | | return baseMapper.selectVoList(lqw); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}QueryBo bo) { |
| | | private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery(); |
| | | #foreach($column in $columns) |
| | |
| | | #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 |
| | |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | | * 新增${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean insertByAddBo(${ClassName}AddBo bo) { |
| | | public Boolean insertByBo(${ClassName}Bo bo) { |
| | | ${ClassName} add = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(add); |
| | | return save(add); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | #set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)}) |
| | | if (flag) { |
| | | bo.set$pk(add.get$pk()); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 修改${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean updateByEditBo(${ClassName}EditBo bo) { |
| | | public Boolean updateByBo(${ClassName}Bo bo) { |
| | | ${ClassName} update = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(update); |
| | | return updateById(update); |
| | | return baseMapper.updateById(update) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 保存前的数据校验 |
| | | * |
| | | * @param entity 实体类数据 |
| | | */ |
| | | private void validEntityBeforeSave(${ClassName} entity){ |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | |
| | | /** |
| | | * 批量删除${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return removeByIds(ids); |
| | | return baseMapper.deleteBatchIds(ids) > 0; |
| | | } |
| | | } |