static.template.server.tree.TreeDemoServiceImpl.tp Maven / Gradle / Ivy
package {packPath}.{rootModule}.{moduleName}.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import io.github.wslxm.springbootplus2.core.base.model.BasePage;
import io.github.wslxm.springbootplus2.core.constant.SymbolConst;
import io.github.wslxm.springbootplus2.core.base.service.impl.BaseServiceImpl;
import io.github.wslxm.springbootplus2.core.utils.XjBeanUtil;
import io.github.wslxm.springbootplus2.core.utils.tree.TreeUtil;
import {packPath}.{rootModule}.{moduleName}.mapper.{tableNameUp}Mapper;
import {packPath}.{rootModule}.{moduleName}.service.{tableNameUp}Service;
import {packPath}.{rootModule}.{moduleName}.model.entity.{tableNameUp};
import {packPath}.{rootModule}.{moduleName}.model.vo.{tableNameUp}VO;
import {packPath}.{rootModule}.{moduleName}.model.dto.{tableNameUp}DTO;
import {packPath}.{rootModule}.{moduleName}.model.query.{tableNameUp}Query;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/**
* {tableComment} ServiceImpl
*
*
* {describe}
*
* @author {author}
* @email {email}
* @date {date}
*/
@Service
public class {tableNameUp}ServiceImpl extends BaseServiceImpl<{tableNameUp}Mapper, {tableNameUp}> implements {tableNameUp}Service {
{filterCrud}
@Override
public List<{tableNameUp}VO> tree({tableNameUp}Query query) {
LambdaQueryWrapper<{tableNameUp}> queryWrapper = new LambdaQueryWrapper<{tableNameUp}>().orderByDesc({tableNameUp}::getCreateTime);
List<{tableNameUp}> list = this.list(queryWrapper);
List<{tableNameUp}VO> listVo = XjBeanUtil.listVo(list, {tableNameUp}VO.class);
return listVo.size() > 0 ? TreeUtil.nextTree(listVo, "0").getChildren() : listVo;
}
@Override
public BasePage<{tableNameUp}VO> findPage({tableNameUp}Query query) {
LambdaQueryWrapper<{tableNameUp}> queryWrapper = new LambdaQueryWrapper<{tableNameUp}>().orderByDesc({tableNameUp}::getCreateTime);
{findPageMybatisPlus}
Page<{tableNameUp}> page = this.page(new Page<>(query.getCurrent(), query.getSize()), queryWrapper);
return XjBeanUtil.pageVo(page, {tableNameUp}VO.class);
}
@Override
public {tableNameUp}VO findId(String id) {
return XjBeanUtil.convert(this.getById(id), {tableNameUp}VO.class);
}
@Override
public String insert({tableNameUp}DTO dto) {
{tableNameUp} entity = dto.convert({tableNameUp}.class);
boolean b = this.save(entity);
return entity.getId();
}
@Override
public boolean upd(String id, {tableNameUp}DTO dto) {
{tableNameUp} entity = dto.convert({tableNameUp}.class);
entity.setId(id);
return this.updateById(entity);
}
@Override
public boolean del(String id) {
List<{tableNameUp}> list = this.list(new LambdaQueryWrapper<{tableNameUp}>().select({tableNameUp}::getId, {tableNameUp}::getPid));
List<{tableNameUp}VO> listVos = XjBeanUtil.listVo(list, {tableNameUp}VO.class);
List nextIds = TreeUtil.getNextIds(listVos, id);
nextIds.add(id);
return this.removeBatchByIds(nextIds);
}
{filterCrud}
}