| | |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.production.dto.ProductProcessDto; |
| | | import com.ruoyi.production.dto.SysDeptAndUserDto; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessRouteItemMapper; |
| | |
| | | import com.ruoyi.production.pojo.ProductProcess; |
| | | import com.ruoyi.production.pojo.ProductProcessRouteItem; |
| | | import com.ruoyi.production.service.ProductProcessService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | @Autowired |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | @Autowired |
| | | private SysUserDeptMapper sysUserDeptMapper; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) { |
| | |
| | | if(CollectionUtils.isEmpty(productProcessList)){ |
| | | return AjaxResult.warn("模板错误或导入数据为空"); |
| | | } |
| | | productProcessList.forEach(productProcess -> { |
| | | if (ObjectUtils.isEmpty(productProcess)) { |
| | | throw new RuntimeException("使用模板进行导入"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcess.getName())) { |
| | | throw new RuntimeException("工序名称不能为空"); |
| | | } |
| | | }); |
| | | this.saveOrUpdateBatch(productProcessList); |
| | | return AjaxResult.success(true); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return AjaxResult.error("导入失败"); |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | productProcessMapper.deleteBatchIds(ids); |
| | | return null; |
| | | } |
| | | |
| | | public List<SysDeptAndUserDto> listDeptUserTree() { |
| | | return buildDeptUserTree(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构建完整的部门-用户树形结构 |
| | | */ |
| | | public List<SysDeptAndUserDto> buildDeptUserTree() { |
| | | // 1. 查询所有根部门(parent_id = 0) |
| | | List<SysDeptAndUserDto> rootDeptList = sysDeptMapper.selectChildrenDeptByParentId(0L); |
| | | |
| | | // 2. 递归构建每个根部门的子节点,并挂载用户 |
| | | for (SysDeptAndUserDto rootDept : rootDeptList) { |
| | | buildChildrenDept(rootDept); |
| | | loadDeptUser(rootDept); |
| | | } |
| | | |
| | | return rootDeptList; |
| | | } |
| | | |
| | | /** |
| | | * 递归构建子部门 |
| | | */ |
| | | private void buildChildrenDept(SysDeptAndUserDto parentDept) { |
| | | // 查询当前部门的子部门 |
| | | List<SysDeptAndUserDto> childrenDept = sysDeptMapper.selectChildrenDeptByParentId(parentDept.getDeptId()); |
| | | if (childrenDept == null || childrenDept.isEmpty()) { |
| | | parentDept.setChildrenList(new ArrayList<>()); |
| | | return; |
| | | } |
| | | |
| | | // 为每个子部门递归构建下级,并挂载用户 |
| | | for (SysDeptAndUserDto childDept : childrenDept) { |
| | | buildChildrenDept(childDept); |
| | | loadDeptUser(childDept); |
| | | } |
| | | |
| | | parentDept.setChildrenList(childrenDept); |
| | | } |
| | | |
| | | /** |
| | | * 为部门加载关联的用户 |
| | | */ |
| | | private void loadDeptUser(SysDeptAndUserDto dept) { |
| | | // 查询部门关联的用户ID |
| | | List<Long> userIdList = sysUserDeptMapper.selectUserIdByDeptId(dept.getDeptId()); |
| | | if (userIdList == null || userIdList.isEmpty()) { |
| | | dept.setUserList(new ArrayList<>()); |
| | | return; |
| | | } |
| | | |
| | | // 根据用户ID查询用户信息 |
| | | List<SysUser> userList = sysUserMapper.selectUserListByIds(userIdList); |
| | | dept.setUserList(userList); |
| | | } |
| | | } |