| | |
| | | */ |
| | | package org.sxkj.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | |
| | | import org.springblade.core.tool.utils.CollectionUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.sxkj.common.constant.WordOrderConstant; |
| | | import org.sxkj.common.func.Streams; |
| | | import org.sxkj.common.model.ResponseResult; |
| | | import org.sxkj.common.node.TreeStringNode; |
| | | import org.sxkj.common.utils.NodeTreeUtil; |
| | | import org.sxkj.common.utils.OrderNumUtils; |
| | | import org.sxkj.system.cache.SysCache; |
| | | import org.sxkj.system.entity.Dept; |
| | | import org.sxkj.system.excel.DeptExcel; |
| | | import org.sxkj.system.excel.DeptImportExcel; |
| | | import org.sxkj.system.mapper.DeptMapper; |
| | | import org.sxkj.system.param.DeptExportParam; |
| | | import org.sxkj.system.param.DeptPageParam; |
| | | import org.sxkj.system.service.IDeptService; |
| | | import org.sxkj.system.vo.DeptVO; |
| | | import org.sxkj.system.wrapper.DeptWrapper; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * |
| | | * @author Chill |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService { |
| | | |
| | |
| | | |
| | | |
| | | @Override |
| | | public List<DeptVO> tree(String tenantId) { |
| | | return ForestNodeMerger.merge(baseMapper.tree(tenantId)); |
| | | public List<DeptVO> tree(String tenantId, String sysType) { |
| | | return ForestNodeMerger.merge(baseMapper.tree(tenantId, sysType)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return removeByIds(Func.toLongList(ids)); |
| | | } |
| | | |
| | | /** |
| | | * 提交部门信息 |
| | | * |
| | | * @param dept 部门信息 |
| | | * @return 是否操作成功 |
| | | */ |
| | | @Override |
| | | public boolean submit(Dept dept) { |
| | | log.info("提交数据:{}", JSON.toJSONString(dept)); |
| | | // 处理父节点信息 |
| | | if (Func.isEmpty(dept.getParentId())) { |
| | | dept.setTenantId(AuthUtil.getTenantId()); |
| | | dept.setParentId(BladeConstant.TOP_PARENT_ID); |
| | |
| | | String ancestors = parent.getAncestors() + StringPool.COMMA + dept.getParentId(); |
| | | dept.setAncestors(ancestors); |
| | | } |
| | | |
| | | // 处理ID重复问题:如果ID存在但记录不存在,设置ID为null让MyBatis-Plus重新生成 |
| | | if (dept.getId() != null) { |
| | | Dept existingDept = getById(dept.getId()); |
| | | if (existingDept == null) { |
| | | dept.setId(null); |
| | | } |
| | | } |
| | | |
| | | dept.setIsDeleted(BladeConstant.DB_NOT_DELETED); |
| | | |
| | | return saveOrUpdate(dept); |
| | | } |
| | | |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param page |
| | | * @param deptPageParam |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam) { |
| | | return baseMapper.selectDeptPage(page, deptPageParam); |
| | | } |
| | | |
| | | /** |
| | | * 导入部门 |
| | | * |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | public void importDept(List<DeptImportExcel> data, Boolean isCovered) { |
| | | List<Dept> list = new ArrayList<>(); |
| | | data.forEach(deptExcel -> { |
| | | // 校验必填字段 |
| | | if (deptExcel.getDeptName() == null || deptExcel.getDeptName().trim().isEmpty()) { |
| | | throw new RuntimeException("机构名称不能为空"); |
| | | } |
| | | if (deptExcel.getAreaCode() == null || deptExcel.getAreaCode().trim().isEmpty()) { |
| | | throw new RuntimeException("所属区划编码不能为空"); |
| | | } |
| | | if (deptExcel.getRemark() == null || deptExcel.getRemark().trim().isEmpty()) { |
| | | throw new RuntimeException("机构描述不能为空"); |
| | | } |
| | | if (deptExcel.getStatus() == null || deptExcel.getStatus().trim().isEmpty()) { |
| | | throw new RuntimeException("机构状态不能为空"); |
| | | } |
| | | // 转换数据 |
| | | Dept dept = BeanUtil.copy(deptExcel, Dept.class); |
| | | dept.setStatus(1); |
| | | dept.setIsDeleted(0); |
| | | dept.setCreateTime(new Date()); |
| | | dept.setUpdateTime(new Date()); |
| | | dept.setDeptNature(2); |
| | | dept.setDeptCategory(2); |
| | | dept.setSysType(String.valueOf(6)); |
| | | list.add(dept); |
| | | }); |
| | | if (isCovered) { |
| | | this.saveOrUpdateBatch(list); |
| | | } else { |
| | | list.forEach(item -> { |
| | | String times = OrderNumUtils.initOrderNum2(WordOrderConstant.ORG_CODE); |
| | | String deptCode = WordOrderConstant.ORG_PREFIX + times; |
| | | item.setDeptCode(deptCode); |
| | | }); |
| | | this.saveBatch(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<DeptExcel> exportDept(DeptExportParam dept) { |
| | | return baseMapper.exportDept(dept); |
| | | } |
| | | |
| | | @Override |
| | | public DeptVO getDetailWithAreaName(Dept dept) { |
| | | return baseMapper.getDetailWithAreaName(dept); |
| | | } |
| | | } |