All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.wslxm.springbootplus2.manage.sys.service.impl.SysDepServiceImpl Maven / Gradle / Ivy

The newest version!
package io.github.wslxm.springbootplus2.manage.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.github.wslxm.springbootplus2.core.base.model.BasePage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.wslxm.springbootplus2.core.base.service.impl.BaseServiceImpl;
import io.github.wslxm.springbootplus2.core.result.ResultType;
import io.github.wslxm.springbootplus2.core.utils.XjBeanUtil;
import io.github.wslxm.springbootplus2.core.utils.tree.XjTreeUtil;
import io.github.wslxm.springbootplus2.core.utils.validated.XjValidUtil;
import io.github.wslxm.springbootplus2.manage.sys.mapper.SysDepMapper;
import io.github.wslxm.springbootplus2.manage.sys.model.dto.SysDepDTO;
import io.github.wslxm.springbootplus2.manage.sys.model.entity.SysDep;
import io.github.wslxm.springbootplus2.manage.sys.model.query.SysDepQuery;
import io.github.wslxm.springbootplus2.manage.sys.model.vo.SysDepVO;
import io.github.wslxm.springbootplus2.manage.sys.service.SysDepService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * base--sys--组织机构 ServiceImpl
 *
 * 

* ::本代码由[兮家小二]提供的代码生成器生成,如有问题,请手动修改 ::作者CSDN:https://blog.csdn.net/qq_41463655 *

* * @author ws * @email [email protected] * @date 2022-12-29 09:57:30 */ @Service public class SysDepServiceImpl extends BaseServiceImpl implements SysDepService { @Override public List tree(SysDepQuery query) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .orderByAsc(SysDep::getSort) .orderByDesc(SysDep::getCreateTime); List list = this.list(queryWrapper); List listVo = XjBeanUtil.listVo(list, SysDepVO.class); return XjTreeUtil.nextTree(listVo, "0").getChildren(); } @Override public BasePage findPage(SysDepQuery query) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .orderByAsc(SysDep::getSort) .orderByDesc(SysDep::getCreateTime); queryWrapper.likeRight(StringUtils.isNotBlank(query.getPid()), SysDep::getPid, query.getPid()); queryWrapper.likeRight(StringUtils.isNotBlank(query.getName()), SysDep::getName, query.getName()); queryWrapper.likeRight(StringUtils.isNotBlank(query.getCode()), SysDep::getCode, query.getCode()); queryWrapper.eq(query.getDisable() != null, SysDep::getDisable, query.getDisable()); Page page = this.page(new Page<>(query.getCurrent(), query.getSize()), queryWrapper); return XjBeanUtil.pageVo(page, SysDepVO.class); } @Override public SysDepVO findId(String id) { return XjBeanUtil.convert(this.getById(id), SysDepVO.class); } @Override public String insert(SysDepDTO dto) { this.verifyCodeRepeat(dto.getCode(), null); SysDep entity = dto.convert(SysDep.class); boolean b = this.save(entity); return entity.getId(); } @Override public boolean upd(String id, SysDepDTO dto) { this.verifyCodeRepeat(dto.getCode(), id); SysDep entity = dto.convert(SysDep.class); entity.setId(id); return this.updateById(entity); } @Override public boolean del(String id) { List list = this.list(new LambdaQueryWrapper().select(SysDep::getId, SysDep::getPid)); List listVos = XjBeanUtil.listVo(list, SysDepVO.class); List nextIds = XjTreeUtil.getNextIds(listVos, id); nextIds.add(id); return this.removeBatchByIds(nextIds); } /** * 部门code重复验证 * * @author wangsong * @mail [email protected] * @date 2022/8/20 0020 14:33 验证 * @version 1.0.0 */ private void verifyCodeRepeat(String code, String excludeId) { long count = this.count(new LambdaQueryWrapper() .eq(SysDep::getCode, code) .ne(excludeId != null, SysDep::getId, excludeId) ); XjValidUtil.isTrue(count > 0, ResultType.BASE_CODE_REPEAT); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy