| | |
| | | import com.emergencyrepair.business.mapper.ProductNodeMapper; |
| | | import com.emergencyrepair.business.mapper.TeamMajorMapper; |
| | | import com.emergencyrepair.common.BusinessException; |
| | | import com.emergencyrepair.common.audit.CurrentUserContext; |
| | | import com.emergencyrepair.system.entity.SysMenu; |
| | | import com.emergencyrepair.system.entity.SysErrorLog; |
| | | import com.emergencyrepair.system.entity.SysLoginLog; |
| | |
| | | menu.setMenuType(menu.getId() == null ? 1 : menu.getMenuType()); |
| | | } |
| | | boolean isRoot = menu.getPid() == null || menu.getPid() == 0L; |
| | | if (menu.getMenuType() == 2) { |
| | | if (isRoot) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | if (menu.getId() != null && !isRoot && menu.getId().equals(menu.getPid())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单"); |
| | | } |
| | | SysMenu parent = null; |
| | | if (!isRoot) { |
| | | parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent == null) { |
| | | throw new BusinessException("上级菜单不存在"); |
| | | } |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (menu.getId() != null && isMenuDescendant(menu.getPid(), menu.getId())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单的下级"); |
| | | } |
| | | } |
| | | if (menu.getMenuType() == 2) { |
| | | if (parent == null || parent.getMenuType() == null || parent.getMenuType() != 1) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | } |
| | |
| | | } |
| | | menu.setUrl(null); |
| | | menu.setIcon(null); |
| | | } else if (!isRoot) { |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | } else if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | menu.setUpdateTime(now); |
| | |
| | | menuMapper.updateById(menu); |
| | | } |
| | | return menuMapper.selectById(menu.getId()); |
| | | } |
| | | |
| | | private boolean isMenuDescendant(Long candidateId, Long ancestorId) { |
| | | Long cursor = candidateId; |
| | | int guard = 0; |
| | | while (cursor != null && cursor != 0L && guard++ < 64) { |
| | | if (cursor.equals(ancestorId)) { |
| | | return true; |
| | | } |
| | | SysMenu current = menuMapper.selectById(cursor); |
| | | cursor = current == null ? null : current.getPid(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | if (!StringUtils.hasText(xNo)) { |
| | | return productTreeRoots(); |
| | | } |
| | | List<ProductNode> rootNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .and(wrapper -> wrapper.isNull(ProductNode::getParentId).or().eq(ProductNode::getParentId, 0L)) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | List<ProductNode> sideNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .in(ProductNode::getLayer, Arrays.asList("side", "SIDE")) |
| | | .eq(ProductNode::getName, xNo.trim()) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | Map<Long, ProductNode> roots = uniqueProductNodes(rootNodes); |
| | | Map<Long, ProductNode> sides = uniqueProductNodes(sideNodes); |
| | | Set<Long> branchIds = new HashSet<>(); |
| | | branchIds.addAll(roots.keySet()); |
| | | branchIds.addAll(sides.keySet()); |
| | | Map<Long, Map<String, Object>> rootRows = new LinkedHashMap<>(); |
| | | for (ProductNode root : sortProductNodes(roots.values())) { |
| | | rootRows.put(root.getId(), mapProduct(root, branchIds)); |
| | | } |
| | | for (ProductNode side : sortProductNodes(sides.values())) { |
| | | ProductNode root = findProductRoot(side); |
| | | Map<String, Object> rootRow = root == null ? null : rootRows.get(root.getId()); |
| | | if (rootRow != null) { |
| | | children(rootRow).add(mapProduct(side, branchIds)); |
| | | } |
| | | } |
| | | return new ArrayList<>(rootRows.values()); |
| | | return mapProductTreeNodes(sideNodes, Collections.emptySet()); |
| | | } |
| | | |
| | | public List<String> productXNumbers() { |
| | |
| | | public Map<String, Object> userPage(String keyword, Long deptId, Long roleId, int current, int size) { |
| | | List<Object> args = new ArrayList<>(); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("SELECT u.USER_ID, u.USER_NAME, u.NICK_NAME, u.DEPT_ID, d.DEPT_NAME, u.PHONENUMBER, u.STATUS, u.LOGIN_DATE "); |
| | | sql.append("SELECT u.USER_ID, u.USER_NAME, u.NICK_NAME, u.DEPT_ID, d.DEPT_NAME, u.PHONENUMBER, u.STATUS, u.LOGIN_DATE, "); |
| | | sql.append("ue.ENGINEERING_MAJOR, ue.TEAM_MAJOR, ue.RESPONSIBLE_X_NO, CASE WHEN ue.USER_ID IS NULL THEN 0 ELSE 1 END AS EXT_CONFIGURED "); |
| | | sql.append("FROM CSICZB_ZB.SYS_USER u LEFT JOIN CSICZB_ZB.SYS_DEPT d ON d.DEPT_ID = u.DEPT_ID "); |
| | | sql.append("LEFT JOIN LX.T_SYS_USER_EXT ue ON ue.USER_ID = u.USER_ID AND (ue.DEL_FLAG = 0 OR ue.DEL_FLAG IS NULL) "); |
| | | sql.append("WHERE (u.DEL_FLAG = '0' OR u.DEL_FLAG IS NULL) "); |
| | | if (StringUtils.hasText(keyword)) { |
| | | sql.append("AND (u.USER_NAME LIKE ? OR u.NICK_NAME LIKE ?) "); |
| | |
| | | row.put("status", rs.getString("STATUS")); |
| | | java.sql.Timestamp loginDate = rs.getTimestamp("LOGIN_DATE"); |
| | | row.put("loginDate", loginDate == null ? null : loginDate.toLocalDateTime().toString().replace('T', ' ')); |
| | | row.put("engineeringMajor", rs.getString("ENGINEERING_MAJOR")); |
| | | row.put("teamMajor", rs.getString("TEAM_MAJOR")); |
| | | row.put("responsibleXNo", rs.getString("RESPONSIBLE_X_NO")); |
| | | row.put("extConfigured", rs.getInt("EXT_CONFIGURED") == 1); |
| | | row.put("roles", new ArrayList<Map<String, Object>>()); |
| | | return row; |
| | | }); |
| | |
| | | |
| | | public List<Map<String, Object>> depts() { |
| | | return jdbcTemplate.query( |
| | | "SELECT DEPT_ID, DEPT_NAME, PARENT_ID, ORDER_NUM, DEPT_TYPE, LEADER, PHONE, STATUS, DEPT_CODE FROM CSICZB_ZB.SYS_DEPT WHERE (DEL_FLAG = '0' OR DEL_FLAG IS NULL) ORDER BY ORDER_NUM, DEPT_ID", |
| | | "SELECT d.DEPT_ID, d.DEPT_NAME, d.PARENT_ID, d.ORDER_NUM, d.DEPT_TYPE, d.LEADER, d.PHONE, d.STATUS, d.DEPT_CODE, " |
| | | + "e.RESPONSIBLE_X_NO, CASE WHEN e.DEPT_ID IS NULL THEN 0 ELSE 1 END AS EXT_CONFIGURED " |
| | | + "FROM CSICZB_ZB.SYS_DEPT d " |
| | | + "LEFT JOIN LX.T_SYS_DEPT_EXT e ON e.DEPT_ID = d.DEPT_ID AND (e.DEL_FLAG = 0 OR e.DEL_FLAG IS NULL) " |
| | | + "WHERE (d.DEL_FLAG = '0' OR d.DEL_FLAG IS NULL) ORDER BY d.ORDER_NUM, d.DEPT_ID", |
| | | (rs, rowNum) -> { |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("id", String.valueOf(rs.getLong("DEPT_ID"))); |
| | |
| | | row.put("phone", rs.getString("PHONE")); |
| | | row.put("status", rs.getString("STATUS")); |
| | | row.put("deptCode", rs.getString("DEPT_CODE")); |
| | | row.put("responsibleXNo", rs.getString("RESPONSIBLE_X_NO")); |
| | | row.put("extConfigured", rs.getInt("EXT_CONFIGURED") == 1); |
| | | return row; |
| | | }); |
| | | } |
| | | |
| | | public Map<String, Object> deptExt(Long deptId) { |
| | | List<Map<String, Object>> rows = jdbcTemplate.query( |
| | | "SELECT d.DEPT_NAME, e.RESPONSIBLE_X_NO FROM CSICZB_ZB.SYS_DEPT d " |
| | | + "LEFT JOIN LX.T_SYS_DEPT_EXT e ON e.DEPT_ID = d.DEPT_ID AND (e.DEL_FLAG = 0 OR e.DEL_FLAG IS NULL) " |
| | | + "WHERE d.DEPT_ID = ? AND (d.DEL_FLAG = '0' OR d.DEL_FLAG IS NULL)", |
| | | new Object[]{deptId}, (rs, rowNum) -> { |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("deptId", String.valueOf(deptId)); |
| | | row.put("deptName", rs.getString("DEPT_NAME")); |
| | | row.put("responsibleXNo", rs.getString("RESPONSIBLE_X_NO")); |
| | | row.put("configured", StringUtils.hasText(rs.getString("RESPONSIBLE_X_NO"))); |
| | | return row; |
| | | }); |
| | | if (rows.isEmpty()) { |
| | | throw new BusinessException("部门不存在"); |
| | | } |
| | | return rows.get(0); |
| | | } |
| | | |
| | | @Transactional |
| | | public void saveDeptExt(Long deptId, String responsibleXNo) { |
| | | assertExternalDept(deptId); |
| | | String xNo = normalizeExtValue(responsibleXNo); |
| | | assertKnownXNo(xNo); |
| | | String username = CurrentUserContext.get(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | int delFlag = xNo == null ? 1 : 0; |
| | | int updated = jdbcTemplate.update( |
| | | "UPDATE LX.T_SYS_DEPT_EXT SET RESPONSIBLE_X_NO = ?, DEL_FLAG = ?, UPDATE_BY = ?, UPDATE_TIME = ? WHERE DEPT_ID = ?", |
| | | xNo, delFlag, username, now, deptId); |
| | | if (updated == 0) { |
| | | jdbcTemplate.update( |
| | | "INSERT INTO LX.T_SYS_DEPT_EXT (DEPT_ID, RESPONSIBLE_X_NO, CREATE_BY, UPDATE_BY, DEL_FLAG, CREATE_TIME, UPDATE_TIME) VALUES (?, ?, ?, ?, ?, ?, ?)", |
| | | deptId, xNo, username, username, delFlag, now, now); |
| | | } |
| | | } |
| | | |
| | | public Map<String, Object> userExt(Long userId) { |
| | | List<Map<String, Object>> rows = jdbcTemplate.query( |
| | | "SELECT u.USER_NAME, u.NICK_NAME, e.ENGINEERING_MAJOR, e.TEAM_MAJOR, e.RESPONSIBLE_X_NO " |
| | | + "FROM CSICZB_ZB.SYS_USER u " |
| | | + "LEFT JOIN LX.T_SYS_USER_EXT e ON e.USER_ID = u.USER_ID AND (e.DEL_FLAG = 0 OR e.DEL_FLAG IS NULL) " |
| | | + "WHERE u.USER_ID = ? AND (u.DEL_FLAG = '0' OR u.DEL_FLAG IS NULL)", |
| | | new Object[]{userId}, (rs, rowNum) -> { |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("userId", String.valueOf(userId)); |
| | | row.put("userName", rs.getString("USER_NAME")); |
| | | row.put("nickName", rs.getString("NICK_NAME")); |
| | | row.put("engineeringMajor", rs.getString("ENGINEERING_MAJOR")); |
| | | row.put("teamMajor", rs.getString("TEAM_MAJOR")); |
| | | row.put("responsibleXNo", rs.getString("RESPONSIBLE_X_NO")); |
| | | boolean configured = StringUtils.hasText(rs.getString("ENGINEERING_MAJOR")) |
| | | || StringUtils.hasText(rs.getString("TEAM_MAJOR")) |
| | | || StringUtils.hasText(rs.getString("RESPONSIBLE_X_NO")); |
| | | row.put("configured", configured); |
| | | return row; |
| | | }); |
| | | if (rows.isEmpty()) { |
| | | throw new BusinessException("用户不存在"); |
| | | } |
| | | return rows.get(0); |
| | | } |
| | | |
| | | @Transactional |
| | | public void saveUserExt(Long userId, String engineeringMajor, String teamMajor, String responsibleXNo) { |
| | | assertExternalUser(userId); |
| | | String engineering = normalizeExtValue(engineeringMajor); |
| | | String team = normalizeExtValue(teamMajor); |
| | | String xNo = normalizeExtValue(responsibleXNo); |
| | | assertKnownEngineeringMajor(engineering); |
| | | assertKnownTeamMajor(team); |
| | | assertKnownXNo(xNo); |
| | | boolean configured = engineering != null || team != null || xNo != null; |
| | | String username = CurrentUserContext.get(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | int updated = jdbcTemplate.update( |
| | | "UPDATE LX.T_SYS_USER_EXT SET ENGINEERING_MAJOR = ?, TEAM_MAJOR = ?, RESPONSIBLE_X_NO = ?, DEL_FLAG = ?, UPDATE_BY = ?, UPDATE_TIME = ? WHERE USER_ID = ?", |
| | | engineering, team, xNo, configured ? 0 : 1, username, now, userId); |
| | | if (updated == 0) { |
| | | jdbcTemplate.update( |
| | | "INSERT INTO LX.T_SYS_USER_EXT (USER_ID, ENGINEERING_MAJOR, TEAM_MAJOR, RESPONSIBLE_X_NO, CREATE_BY, UPDATE_BY, DEL_FLAG, CREATE_TIME, UPDATE_TIME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
| | | userId, engineering, team, xNo, username, username, configured ? 0 : 1, now, now); |
| | | } |
| | | } |
| | | |
| | | private void assertExternalDept(Long deptId) { |
| | | if (deptId == null) { |
| | | throw new BusinessException("请选择部门"); |
| | | } |
| | | Integer count = jdbcTemplate.queryForObject( |
| | | "SELECT COUNT(*) FROM CSICZB_ZB.SYS_DEPT WHERE DEPT_ID = ? AND (DEL_FLAG = '0' OR DEL_FLAG IS NULL)", |
| | | Integer.class, deptId); |
| | | if (count == null || count == 0) { |
| | | throw new BusinessException("部门不存在"); |
| | | } |
| | | } |
| | | |
| | | private void assertExternalUser(Long userId) { |
| | | if (userId == null) { |
| | | throw new BusinessException("请选择用户"); |
| | | } |
| | | Integer count = jdbcTemplate.queryForObject( |
| | | "SELECT COUNT(*) FROM CSICZB_ZB.SYS_USER WHERE USER_ID = ? AND (DEL_FLAG = '0' OR DEL_FLAG IS NULL)", |
| | | Integer.class, userId); |
| | | if (count == null || count == 0) { |
| | | throw new BusinessException("用户不存在"); |
| | | } |
| | | } |
| | | |
| | | private void assertKnownXNo(String xNo) { |
| | | if (xNo != null && !productXNumbers().contains(xNo)) { |
| | | throw new BusinessException("rk_X号必须从产品结构树的side节点中选择"); |
| | | } |
| | | } |
| | | |
| | | private void assertKnownEngineeringMajor(String value) { |
| | | if (value != null && listEngineeringMajors().stream().map(EngineeringMajor::getName) |
| | | .filter(StringUtils::hasText).noneMatch(item -> value.equals(item.trim()))) { |
| | | throw new BusinessException("工程专业不在可选范围内"); |
| | | } |
| | | } |
| | | |
| | | private void assertKnownTeamMajor(String value) { |
| | | if (value != null && listTeamMajors().stream().map(TeamMajor::getName) |
| | | .filter(StringUtils::hasText).noneMatch(item -> value.equals(item.trim()))) { |
| | | throw new BusinessException("rk_T队专业不在可选范围内"); |
| | | } |
| | | } |
| | | |
| | | private String normalizeExtValue(String value) { |
| | | return StringUtils.hasText(value) ? value.trim() : null; |
| | | } |
| | | |
| | | public List<String> userRoleIds(Long userId) { |
| | | if (userId == null) { |
| | | return new ArrayList<>(); |