| package com.zt.modules.sys.service; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.zt.common.constant.Constant; | 
| import com.zt.common.db.query.QueryFilter; | 
| import com.zt.common.exception.RenException; | 
| import com.zt.common.service.BaseService; | 
| import com.zt.common.utils.TreeUtils; | 
| import com.zt.core.context.UserContext; | 
| import com.zt.modules.sys.dao.SysJobDao; | 
| import com.zt.modules.sys.model.SysJob; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| /** | 
|  * SYS_JOB | 
|  * | 
|  * @author zt generator | 
|  * @since 1.0.0 2020-06-04 | 
|  */ | 
| @Service | 
| public class SysJobService extends BaseService<SysJobDao, SysJob> { | 
|     @Autowired | 
|     private SysJobUserService sysJobUserService; | 
|   | 
|     public List<SysJob> tree(QueryFilter queryFilter) { | 
|         List<SysJob> list = baseDao.getList(queryFilter.getParams()); | 
|         return TreeUtils.build(list); | 
|     } | 
|   | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void update(SysJob entity) { | 
|         SysJob tmp = get(entity.getId()); | 
|   | 
|         TreeUtils.updateValidate( | 
|                 baseDao.selectList(new QueryWrapper<SysJob>().eq(Constant.TableColumn.IS_DELETE, Constant.Bool.NO) | 
|                         .lambda().eq(SysJob::getTenantId, UserContext.getUser().getTenantId())), entity, tmp); | 
|   | 
|         baseDao.updateById(entity); | 
|     } | 
|   | 
|     @Transactional(rollbackFor = Exception.class) | 
|     public void delete(Long id) { | 
|         // 判断是否有子职位 | 
|         if (this.getChildPosts(id).size() > 1) { | 
|             throw new RenException("请先删除下级岗位"); | 
|         } | 
|   | 
|         // 删除职位时,删除职位用户关系表 | 
|         sysJobUserService.deleteByJobId(id); | 
|   | 
|         // 删除 | 
|         this.deleteLogic(id); | 
|     } | 
|   | 
|     private List<SysJob> getChildPosts(Long id) { | 
|         return baseDao.selectList(new QueryWrapper<SysJob>().eq(Constant.TableColumn.IS_DELETE, Constant.Bool.NO) | 
|                 .lambda().eq(SysJob::getPid, id)); | 
|     } | 
| } |