Bläddra i källkod

首页拆分,依据数据字典home_page_type

wanglt 5 månader sedan
förälder
incheckning
3bd1a4a15c

+ 36 - 0
sql/sys_post_home_page.sql

@@ -0,0 +1,36 @@
+/*
+ Navicat Premium Data Transfer
+
+ Source Server         : 0本地5.7.17
+ Source Server Type    : MySQL
+ Source Server Version : 50717
+ Source Host           : localhost:3307
+ Source Schema         : ygtx_gxt
+
+ Target Server Type    : MySQL
+ Target Server Version : 50717
+ File Encoding         : 65001
+
+ Date: 01/11/2025 17:32:09
+*/
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for sys_post_home_page
+-- ----------------------------
+DROP TABLE IF EXISTS `sys_post_home_page`;
+CREATE TABLE `sys_post_home_page`  (
+  `post_id` bigint(20) NOT NULL COMMENT '岗位ID',
+  `home_page_type` varchar(20) NOT NULL COMMENT '首页ID',
+  `status` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '状态(0正常 1停用)',
+  `create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '创建者',
+  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
+  `update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '更新者',
+  `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
+  `remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
+  PRIMARY KEY (`post_id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
+
+SET FOREIGN_KEY_CHECKS = 1;

+ 31 - 0
sql/sys_post_home_page_menu.sql

@@ -0,0 +1,31 @@
+-- 菜单 SQL
+-- 岗位首页配置菜单及权限
+
+-- 查找系统管理菜单ID(通常为1)
+-- 假设系统管理菜单ID为1,如果不同请相应调整
+SET @systemMenuId = 1;
+
+-- 二级菜单:岗位首页配置
+INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+VALUES ('岗位首页配置', @systemMenuId, 10, 'postHomePage', 'system/postHomePage/index', 1, 0, 'C', '0', '0', 'system:postHomePage:list', 'guide', 'admin', sysdate(), '', null, '岗位首页配置菜单');
+
+-- 获取刚插入的菜单ID,用于后续按钮权限
+SET @postHomePageMenuId = LAST_INSERT_ID();
+
+-- 按钮权限
+INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+VALUES
+('岗位首页配置查询', @postHomePageMenuId, 1, '#', '', 1, 0, 'F', '0', '0', 'system:postHomePage:query', '#', 'admin', sysdate(), '', null, ''),
+('岗位首页配置新增', @postHomePageMenuId, 2, '#', '', 1, 0, 'F', '0', '0', 'system:postHomePage:add', '#', 'admin', sysdate(), '', null, ''),
+('岗位首页配置修改', @postHomePageMenuId, 3, '#', '', 1, 0, 'F', '0', '0', 'system:postHomePage:edit', '#', 'admin', sysdate(), '', null, ''),
+('岗位首页配置删除', @postHomePageMenuId, 4, '#', '', 1, 0, 'F', '0', '0', 'system:postHomePage:remove', '#', 'admin', sysdate(), '', null, ''),
+('岗位首页配置导出', @postHomePageMenuId, 5, '#', '', 1, 0, 'F', '0', '0', 'system:postHomePage:export', '#', 'admin', sysdate(), '', null, '');
+
+-- 说明:
+-- 1. parent_id 为系统管理菜单ID,请根据实际情况调整
+-- 2. 执行此脚本后,需要在角色管理中为相应角色分配菜单权限
+-- 3. is_frame: 是否为外链(0是 1否)
+-- 4. is_cache: 是否缓存(0缓存 1不缓存)
+-- 5. menu_type: 菜单类型(M目录 C菜单 F按钮)
+-- 6. visible: 菜单状态(0显示 1隐藏)
+-- 7. status: 菜单状态(0正常 1停用)

+ 181 - 0
ygtx-admin/src/main/java/com/ygtx/web/controller/system/SysPostHomePageController.java

@@ -0,0 +1,181 @@
+package com.ygtx.web.controller.system;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ygtx.common.core.domain.entity.SysUser;
+import com.ygtx.common.core.domain.model.LoginUser;
+import com.ygtx.common.utils.SecurityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ygtx.common.annotation.Log;
+import com.ygtx.common.core.controller.BaseController;
+import com.ygtx.common.core.domain.AjaxResult;
+import com.ygtx.common.core.page.TableDataInfo;
+import com.ygtx.common.enums.BusinessType;
+import com.ygtx.common.utils.poi.ExcelUtil;
+import com.ygtx.system.domain.SysPost;
+import com.ygtx.system.domain.SysPostHomePage;
+import com.ygtx.system.service.ISysPostService;
+import com.ygtx.system.service.ISysPostHomePageService;
+
+/**
+ * 岗位首页配置Controller
+ * 
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/system/postHomePage")
+public class SysPostHomePageController extends BaseController
+{
+    private static final Logger logger = LoggerFactory.getLogger(SysPostHomePageController.class);
+    
+    @Autowired
+    private ISysPostHomePageService sysPostHomePageService;
+    
+    @Autowired
+    private ISysPostService sysPostService;
+
+    /**
+     * 查询岗位首页配置列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(SysPostHomePage sysPostHomePage)
+    {
+        startPage();
+        List<SysPostHomePage> list = sysPostHomePageService.selectSysPostHomePageList(sysPostHomePage);
+        return getDataTable(list);
+    }
+    
+    /**
+     * 查询岗位列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:list')")
+    @GetMapping("/postList")
+    public AjaxResult postList(SysPost sysPost)
+    {
+        sysPost.setStatus("0");
+        List<SysPost> list = sysPostService.selectPostList(sysPost);
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * 导出岗位首页配置列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:export')")
+    @Log(title = "岗位首页配置", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, SysPostHomePage sysPostHomePage)
+    {
+        List<SysPostHomePage> list = sysPostHomePageService.selectSysPostHomePageList(sysPostHomePage);
+        ExcelUtil<SysPostHomePage> util = new ExcelUtil<SysPostHomePage>(SysPostHomePage.class);
+        util.exportExcel(response, list, "岗位首页配置数据");
+    }
+
+    /**
+     * 获取岗位首页配置详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:query')")
+    @GetMapping(value = "/{postId}")
+    public AjaxResult getInfo(@PathVariable("postId") Long postId)
+    {
+        return AjaxResult.success(sysPostHomePageService.selectSysPostHomePageById(postId));
+    }
+
+    /**
+     * 新增岗位首页配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:add')")
+    @Log(title = "岗位首页配置", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@Validated @RequestBody SysPostHomePage sysPostHomePage)
+    {
+        try {
+            // 设置创建者信息
+            String username = getUsername();
+            sysPostHomePage.setCreateBy(username);
+            
+            int result = sysPostHomePageService.insertSysPostHomePage(sysPostHomePage);
+            if (result > 0) {
+                return AjaxResult.success("操作成功");
+            } else {
+                return AjaxResult.error("操作失败");
+            }
+        } catch (Exception e) {
+            logger.error("新增岗位首页配置失败", e);
+            return AjaxResult.error("操作失败: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 修改岗位首页配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:edit')")
+    @Log(title = "岗位首页配置", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@Validated @RequestBody SysPostHomePage sysPostHomePage)
+    {
+        try {
+            // 设置更新者信息
+            String username = getUsername();
+            sysPostHomePage.setUpdateBy(username);
+            
+            int result = sysPostHomePageService.updateSysPostHomePage(sysPostHomePage);
+            if (result > 0) {
+                return AjaxResult.success("操作成功");
+            } else {
+                return AjaxResult.error("操作失败");
+            }
+        } catch (Exception e) {
+            logger.error("修改岗位首页配置失败", e);
+            return AjaxResult.error("操作失败: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 删除岗位首页配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:postHomePage:remove')")
+    @Log(title = "岗位首页配置", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{postIds}")
+    public AjaxResult remove(@PathVariable String postIds)
+    {
+        // 将字符串转换为Long数组
+        String[] ids = postIds.split(",");
+        Long[] postIdsArray = new Long[ids.length];
+        for (int i = 0; i < ids.length; i++) {
+            postIdsArray[i] = Long.parseLong(ids[i]);
+        }
+        return toAjax(sysPostHomePageService.deleteSysPostHomePageByIds(postIdsArray));
+    }
+
+    @GetMapping("/getHomePage")
+    public AjaxResult getHomePage()
+    {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        SysUser user = loginUser.getUser();
+        List<Long> postIds = sysPostService.selectPostListByUserId(user.getUserId());
+        if (postIds!=null && !postIds.isEmpty()) {
+            SysPostHomePage postHomePage = new SysPostHomePage();
+            postHomePage.setPostId(postIds.get(0));
+            postHomePage.setStatus("0");
+            List<SysPostHomePage> list = sysPostHomePageService.selectSysPostHomePageList(postHomePage);
+            if (list!=null && !list.isEmpty()) {
+                return AjaxResult.success(list.get(0));
+            }
+        }
+        return AjaxResult.error("当前用户岗位未配置首页数据");
+    }
+}

+ 78 - 0
ygtx-system/src/main/java/com/ygtx/system/domain/SysPostHomePage.java

@@ -0,0 +1,78 @@
+package com.ygtx.system.domain;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ygtx.common.annotation.Excel;
+import com.ygtx.common.annotation.Excel.ColumnType;
+import com.ygtx.common.core.domain.BaseEntity;
+
+/**
+ * 岗位首页配置表 sys_post_home_page
+ * 
+ * @author ruoyi
+ */
+public class SysPostHomePage extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 岗位ID */
+    @Excel(name = "岗位ID", cellType = ColumnType.NUMERIC)
+    @NotNull(message = "岗位ID不能为空")
+    private Long postId;
+
+    /** 首页ID */
+    @Excel(name = "首页ID", cellType = ColumnType.NUMERIC)
+    @NotBlank(message = "首页ID不能为空")
+    private String homePageType;
+
+    /** 状态(0正常 1停用) */
+    @Excel(name = "状态", readConverterExp = "0=正常,1=停用")
+    @NotBlank(message = "状态不能为空")
+    private String status;
+
+    public Long getPostId()
+    {
+        return postId;
+    }
+
+    public void setPostId(Long postId)
+    {
+        this.postId = postId;
+    }
+
+    public String getHomePageType()
+    {
+        return homePageType;
+    }
+
+    public void setHomePageType(String homePageType)
+    {
+        this.homePageType = homePageType;
+    }
+
+    public String getStatus()
+    {
+        return status;
+    }
+
+    public void setStatus(String status)
+    {
+        this.status = status;
+    }
+    
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("postId", getPostId())
+            .append("homePageType", getHomePageType())
+            .append("status", getStatus())
+            .append("createBy", getCreateBy())
+            .append("createTime", getCreateTime())
+            .append("updateBy", getUpdateBy())
+            .append("updateTime", getUpdateTime())
+            .append("remark", getRemark())
+            .toString();
+    }
+}

+ 60 - 0
ygtx-system/src/main/java/com/ygtx/system/mapper/SysPostHomePageMapper.java

@@ -0,0 +1,60 @@
+package com.ygtx.system.mapper;
+
+import java.util.List;
+import com.ygtx.system.domain.SysPostHomePage;
+
+/**
+ * 岗位首页配置 数据层
+ * 
+ * @author ruoyi
+ */
+public interface SysPostHomePageMapper
+{
+    /**
+     * 查询岗位首页配置数据集合
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 岗位首页配置数据集合
+     */
+    public List<SysPostHomePage> selectSysPostHomePageList(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 通过岗位ID查询岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 岗位首页配置信息
+     */
+    public SysPostHomePage selectSysPostHomePageById(Long postId);
+
+    /**
+     * 新增岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    public int insertSysPostHomePage(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 修改岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    public int updateSysPostHomePage(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 删除岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 结果
+     */
+    public int deleteSysPostHomePageById(Long postId);
+
+    /**
+     * 批量删除岗位首页配置信息
+     * 
+     * @param postIds 需要删除的岗位ID数组
+     * @return 结果
+     */
+    public int deleteSysPostHomePageByIds(Long[] postIds);
+}

+ 60 - 0
ygtx-system/src/main/java/com/ygtx/system/service/ISysPostHomePageService.java

@@ -0,0 +1,60 @@
+package com.ygtx.system.service;
+
+import java.util.List;
+import com.ygtx.system.domain.SysPostHomePage;
+
+/**
+ * 岗位首页配置 服务层
+ * 
+ * @author ruoyi
+ */
+public interface ISysPostHomePageService
+{
+    /**
+     * 查询岗位首页配置信息集合
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 岗位首页配置信息集合
+     */
+    public List<SysPostHomePage> selectSysPostHomePageList(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 通过岗位ID查询岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 岗位首页配置信息
+     */
+    public SysPostHomePage selectSysPostHomePageById(Long postId);
+
+    /**
+     * 新增保存岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    public int insertSysPostHomePage(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 修改保存岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    public int updateSysPostHomePage(SysPostHomePage sysPostHomePage);
+
+    /**
+     * 删除岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 结果
+     */
+    public int deleteSysPostHomePageById(Long postId);
+
+    /**
+     * 批量删除岗位首页配置信息
+     * 
+     * @param postIds 需要删除的岗位ID数组
+     * @return 结果
+     */
+    public int deleteSysPostHomePageByIds(Long[] postIds);
+}

+ 125 - 0
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysPostHomePageServiceImpl.java

@@ -0,0 +1,125 @@
+package com.ygtx.system.service.impl;
+
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ygtx.system.domain.SysPostHomePage;
+import com.ygtx.system.mapper.SysPostHomePageMapper;
+import com.ygtx.system.service.ISysPostHomePageService;
+
+/**
+ * 岗位首页配置 服务层处理
+ * 
+ * @author ruoyi
+ */
+@Service
+public class SysPostHomePageServiceImpl implements ISysPostHomePageService
+{
+    private static final Logger logger = LoggerFactory.getLogger(SysPostHomePageServiceImpl.class);
+    
+    @Autowired
+    private SysPostHomePageMapper sysPostHomePageMapper;
+
+    /**
+     * 查询岗位首页配置信息集合
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 岗位首页配置信息集合
+     */
+    @Override
+    public List<SysPostHomePage> selectSysPostHomePageList(SysPostHomePage sysPostHomePage)
+    {
+        return sysPostHomePageMapper.selectSysPostHomePageList(sysPostHomePage);
+    }
+
+    /**
+     * 通过岗位ID查询岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 岗位首页配置信息
+     */
+    @Override
+    public SysPostHomePage selectSysPostHomePageById(Long postId)
+    {
+        return sysPostHomePageMapper.selectSysPostHomePageById(postId);
+    }
+
+    /**
+     * 新增保存岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    @Override
+    public int insertSysPostHomePage(SysPostHomePage sysPostHomePage)
+    {
+        logger.info("开始新增岗位首页配置,岗位ID: {}", sysPostHomePage.getPostId());
+        
+        // 检查是否已存在该岗位的配置
+        SysPostHomePage existing = sysPostHomePageMapper.selectSysPostHomePageById(sysPostHomePage.getPostId());
+        if (existing != null) {
+            logger.info("岗位首页配置已存在,执行更新操作,岗位ID: {}", sysPostHomePage.getPostId());
+            // 如果已存在,则更新而不是插入
+            int result = sysPostHomePageMapper.updateSysPostHomePage(sysPostHomePage);
+            logger.info("更新操作完成,影响行数: {}", result);
+            if (result <= 0) {
+                throw new RuntimeException("更新岗位首页配置失败");
+            }
+            return result;
+        }
+        
+        logger.info("岗位首页配置不存在,执行插入操作,岗位ID: {}", sysPostHomePage.getPostId());
+        int result = sysPostHomePageMapper.insertSysPostHomePage(sysPostHomePage);
+        logger.info("插入操作完成,影响行数: {}", result);
+        // 检查插入结果
+        if (result <= 0) {
+            throw new RuntimeException("插入岗位首页配置失败");
+        }
+        return result;
+    }
+
+    /**
+     * 修改保存岗位首页配置信息
+     * 
+     * @param sysPostHomePage 岗位首页配置信息
+     * @return 结果
+     */
+    @Override
+    public int updateSysPostHomePage(SysPostHomePage sysPostHomePage)
+    {
+        logger.info("开始更新岗位首页配置,岗位ID: {}", sysPostHomePage.getPostId());
+        int result = sysPostHomePageMapper.updateSysPostHomePage(sysPostHomePage);
+        logger.info("更新操作完成,影响行数: {}", result);
+        // 检查更新结果
+        if (result <= 0) {
+            throw new RuntimeException("更新岗位首页配置失败,可能记录不存在");
+        }
+        return result;
+    }
+
+    /**
+     * 删除岗位首页配置信息
+     * 
+     * @param postId 岗位ID
+     * @return 结果
+     */
+    @Override
+    public int deleteSysPostHomePageById(Long postId)
+    {
+        return sysPostHomePageMapper.deleteSysPostHomePageById(postId);
+    }
+
+    /**
+     * 批量删除岗位首页配置信息
+     * 
+     * @param postIds 需要删除的岗位ID数组
+     * @return 结果
+     */
+    @Override
+    public int deleteSysPostHomePageByIds(Long[] postIds)
+    {
+        return sysPostHomePageMapper.deleteSysPostHomePageByIds(postIds);
+    }
+}

+ 24 - 14
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysPostServiceImpl.java

@@ -1,6 +1,9 @@
 package com.ygtx.system.service.impl;
 
 import java.util.List;
+
+import com.ygtx.system.domain.SysPostHomePage;
+import com.ygtx.system.service.ISysPostHomePageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ygtx.common.constant.UserConstants;
@@ -25,6 +28,9 @@ public class SysPostServiceImpl implements ISysPostService
     @Autowired
     private SysUserPostMapper userPostMapper;
 
+    @Autowired
+    private ISysPostHomePageService postHomePageService;
+
     /**
      * 查询岗位信息集合
      * 
@@ -184,22 +190,26 @@ public class SysPostServiceImpl implements ISysPostService
     @Override
     public int getHomePostType(Long userId) {
         List<Long> postIds = selectPostListByUserId(userId);
-        int result = 0;
+//        int result = 0;
         if (!postIds.isEmpty()) {
-            for (Long postId:postIds) {
-                SysPost post = selectPostById(postId);
-                if (post!=null) {
-                    if (post.getPostName().contains("主任")) {
-                        result = 2;
-                        break;
-                    } else if (post.getPostName().contains("班长")) {
-                        if (result<1) {
-                            result = 1;
-                        }
-                    }
-                }
+            SysPostHomePage postHomePage = postHomePageService.selectSysPostHomePageById(postIds.get(0));
+            if (postHomePage!=null) {
+                return Integer.parseInt(postHomePage.getHomePageType());
             }
+//            for (Long postId:postIds) {
+//                SysPost post = selectPostById(postId);
+//                if (post!=null) {
+//                    if (post.getPostName().contains("主任")) {
+//                        result = 2;
+//                        break;
+//                    } else if (post.getPostName().contains("班长")) {
+//                        if (result<1) {
+//                            result = 1;
+//                        }
+//                    }
+//                }
+//            }
         }
-        return result;
+        return 999;
     }
 }

+ 84 - 0
ygtx-system/src/main/resources/mapper/system/SysPostHomePageMapper.xml

@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ygtx.system.mapper.SysPostHomePageMapper">
+
+	<resultMap type="SysPostHomePage" id="SysPostHomePageResult">
+		<id     property="postId"         column="post_id"        />
+		<result property="homePageType"   column="home_page_type" />
+		<result property="status"         column="status"         />
+		<result property="createBy"       column="create_by"      />
+		<result property="createTime"     column="create_time"    />
+		<result property="updateBy"       column="update_by"      />
+		<result property="updateTime"     column="update_time"    />
+		<result property="remark"         column="remark"         />
+	</resultMap>
+	
+	<sql id="selectSysPostHomePageVo">
+        select post_id, home_page_type, status, create_by, create_time, update_by, update_time, remark 
+		from sys_post_home_page
+    </sql>
+	
+	<select id="selectSysPostHomePageList" parameterType="SysPostHomePage" resultMap="SysPostHomePageResult">
+	    <include refid="selectSysPostHomePageVo"/>
+		<where>
+			<if test="postId != null and postId != ''">
+				AND post_id = #{postId}
+			</if>
+			<if test="homePageType != null and homePageType != ''">
+				AND home_page_type = #{homePageType}
+			</if>
+			<if test="status != null and status != ''">
+				AND status = #{status}
+			</if>
+		</where>
+	</select>
+	
+	<select id="selectSysPostHomePageById" parameterType="Long" resultMap="SysPostHomePageResult">
+		<include refid="selectSysPostHomePageVo"/>
+		where post_id = #{postId}
+	</select>
+	
+	<insert id="insertSysPostHomePage" parameterType="SysPostHomePage">
+ 		insert into sys_post_home_page(
+ 			post_id,
+ 			home_page_type,
+ 			status,
+ 			<if test="remark != null">remark,</if>
+ 			<if test="createBy != null and createBy != ''">create_by,</if>
+ 			create_time
+ 		) values (
+ 			#{postId},
+ 			#{homePageType},
+ 			#{status},
+ 			<if test="remark != null">#{remark},</if>
+ 			<if test="createBy != null and createBy != ''">#{createBy},</if>
+ 			sysdate()
+ 		)
+	</insert>
+	
+	<update id="updateSysPostHomePage" parameterType="SysPostHomePage">
+ 		update sys_post_home_page
+ 		<set>
+ 			<if test="homePageType != null and homePageType != ''">home_page_type = #{homePageType},</if>
+ 			<if test="status != null and status != ''">status = #{status},</if>
+ 			<if test="remark != null">remark = #{remark},</if>
+ 			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+ 			update_time = sysdate()
+ 		</set>
+ 		where post_id = #{postId}
+	</update>
+ 	
+	<delete id="deleteSysPostHomePageById" parameterType="Long">
+		delete from sys_post_home_page where post_id = #{postId}
+	</delete>
+	
+	<delete id="deleteSysPostHomePageByIds" parameterType="Long">
+ 		delete from sys_post_home_page where post_id in
+ 		<foreach collection="array" item="postId" open="(" separator="," close=")">
+ 			#{postId}
+        </foreach> 
+ 	</delete>
+
+</mapper>

+ 61 - 0
ygtx-ui/src/api/system/postHomePage.js

@@ -0,0 +1,61 @@
+import request from '@/utils/request'
+
+// 查询岗位首页配置列表
+export function listPostHomePage(query) {
+  return request({
+    url: '/system/postHomePage/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询岗位列表
+export function listPost(query) {
+  return request({
+    url: '/system/postHomePage/postList',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询岗位首页配置详细
+export function getPostHomePage(postId) {
+  return request({
+    url: '/system/postHomePage/' + postId,
+    method: 'get'
+  })
+}
+
+// 获取当前用户的首页配置
+export function getCurrentUserHomePage() {
+  return request({
+    url: '/system/postHomePage/getHomePage',
+    method: 'get'
+  })
+}
+
+// 新增岗位首页配置
+export function addPostHomePage(data) {
+  return request({
+    url: '/system/postHomePage',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改岗位首页配置
+export function updatePostHomePage(data) {
+  return request({
+    url: '/system/postHomePage',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除岗位首页配置
+export function delPostHomePage(postIds) {
+  return request({
+    url: '/system/postHomePage/' + postIds.join(','),
+    method: 'delete'
+  })
+}

+ 20 - 6
ygtx-ui/src/views/index.vue

@@ -7,6 +7,7 @@ import { ref, computed } from 'vue'
 import { mapState } from 'pinia'
 import useUserStore from '@/store/modules/user'
 import { getRouteNameByPostType } from '@/utils/routeMap'
+import { getCurrentUserHomePage } from '@/api/system/postHomePage'
 import Index0 from './index0.vue'
 import Index1 from './index1.vue'
 import Index2 from './index2.vue'
@@ -29,16 +30,29 @@ export default {
     })
 
     // 获取首页路由名称
-    const fetchHomePageRouteName = async (postType) => {
+    const fetchHomePageRouteName = async () => {
       try {
-        homePageRouteName.value = await getRouteNameByPostType(postType)
+        // 调用后端接口获取首页配置
+        const response = await getCurrentUserHomePage()
+        console.log(response);
+        if (response.code === 200 && response.data) {
+          // 使用返回数据中的homePageType值
+          const homePageType = response.data.homePageType
+          homePageRouteName.value = await getRouteNameByPostType(homePageType)
+        } else {
+          // 接口调用成功但无数据时使用默认首页
+          console.warn('未获取到首页配置数据,使用默认首页')
+          homePageRouteName.value = 'Index0'
+        }
       } catch (error) {
-        console.error('获取首页路由名称失败:', error)
-        // 出错时使用默认首页
+        console.error('获取首页配置失败:', error)
+        // 接口调用失败时使用默认首页
         homePageRouteName.value = 'Index0'
       }
     }
 
+    console.log(homePageRouteName.value);
+
     return {
       homePageRouteName,
       currentComponent,
@@ -51,7 +65,7 @@ export default {
   async mounted() {
     // 组件挂载时获取首页路由名称
     if (this.fetchHomePageRouteName) {
-      this.fetchHomePageRouteName(this.postType)
+      this.fetchHomePageRouteName()
     }
   },
   watch: {
@@ -59,7 +73,7 @@ export default {
     postType: {
       handler: async function(newVal) {
         if (this.fetchHomePageRouteName) {
-          this.fetchHomePageRouteName(newVal)
+          this.fetchHomePageRouteName()
         }
       },
       immediate: true

+ 388 - 0
ygtx-ui/src/views/system/postHomePage/index.vue

@@ -0,0 +1,388 @@
+<template>
+  <div class="app-container">
+    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-position="top">
+      <el-form-item label="岗位ID" prop="postId" label-position="top">
+        <el-select v-model="queryParams.postId" placeholder="请选择岗位" clearable>
+          <el-option
+            v-for="post in postOptions"
+            :key="post.postId"
+            :label="post.postName"
+            :value="post.postId"
+          />
+        </el-select>
+      </el-form-item>
+      <el-form-item label="首页ID" prop="homePageType" label-position="top">
+        <el-select v-model="queryParams.homePageType" placeholder="请选择首页类型" clearable>
+          <el-option
+            v-for="dict in home_page_type"
+            :key="dict.value"
+            :label="dict.label"
+            :value="dict.value"
+          />
+        </el-select>
+      </el-form-item>
+      <el-form-item label="状态" prop="status" label-position="top">
+        <el-select v-model="queryParams.status" placeholder="状态" clearable>
+          <el-option
+            v-for="dict in sys_normal_disable"
+            :key="dict.value"
+            :label="dict.label"
+            :value="dict.value"
+          />
+        </el-select>
+      </el-form-item>
+      <el-form-item label-position="top">
+        <div class="item-search">&nbsp;</div>
+        <div class="item-search">
+          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
+          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
+        </div>
+      </el-form-item>
+    </el-form>
+
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          icon="Plus"
+          @click="handleAdd"
+          v-hasPermi="['system:postHomePage:add']"
+        >新增</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="success"
+          icon="Edit"
+          :disabled="single"
+          @click="handleUpdate"
+          v-hasPermi="['system:postHomePage:edit']"
+        >修改</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="danger"
+          icon="Delete"
+          :disabled="multiple"
+          @click="handleDelete"
+          v-hasPermi="['system:postHomePage:remove']"
+        >删除</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          icon="Download"
+          @click="handleExport"
+          v-hasPermi="['system:postHomePage:export']"
+        >导出</el-button>
+      </el-col>
+      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
+    <el-table v-loading="loading" :data="postHomePageList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" />
+      <el-table-column label="岗位ID" prop="postId">
+        <template #default="scope">
+          {{ getPostNameById(scope.row.postId) }}
+        </template>
+      </el-table-column>
+      <el-table-column label="首页ID" prop="homePageType">
+        <template #default="scope">
+          <dict-tag :options="home_page_type" :value="scope.row.homePageType" />
+        </template>
+      </el-table-column>
+      <el-table-column label="状态" prop="status">
+        <template #default="scope">
+          <dict-tag :options="sys_normal_disable" :value="scope.row.status" />
+        </template>
+      </el-table-column>
+      <el-table-column label="创建者" prop="createBy" />
+      <el-table-column label="创建时间" prop="createTime" width="180">
+        <template #default="scope">
+          <span>{{ parseTime(scope.row.createTime) }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="更新者" prop="updateBy" />
+      <el-table-column label="更新时间" prop="updateTime" width="180">
+        <template #default="scope">
+          <span>{{ parseTime(scope.row.updateTime) }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="备注" prop="remark" />
+      <el-table-column label="操作" width="180" class-name="small-padding fixed-width">
+        <template #default="scope">
+          <el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['system:postHomePage:edit']"><i class="fa fa-edit"></i>编辑</el-button>
+          <el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['system:postHomePage:remove']"><i class="fa fa-trash"></i>删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination
+      v-show="total > 0"
+      :total="total"
+      v-model:page="queryParams.pageNum"
+      v-model:limit="queryParams.pageSize"
+      @pagination="getList"
+    />
+
+    <!-- 添加或修改岗位首页配置对话框 -->
+    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
+      <el-form ref="postHomePageRef" :model="form" :rules="rules" label-width="80px">
+        <el-form-item label="岗位ID" prop="postId">
+          <el-select v-model="form.postId" placeholder="请选择岗位" clearable>
+            <el-option
+              v-for="post in postOptions"
+              :key="post.postId"
+              :label="post.postName"
+              :value="post.postId"
+            />
+          </el-select>
+        </el-form-item>
+        <el-form-item label="首页ID" prop="homePageType">
+          <el-select v-model="form.homePageType" placeholder="请选择首页类型" clearable>
+            <el-option
+              v-for="dict in home_page_type"
+              :key="dict.value"
+              :label="dict.label"
+              :value="dict.value"
+            />
+          </el-select>
+        </el-form-item>
+        <el-form-item label="状态" prop="status">
+          <el-radio-group v-model="form.status">
+            <el-radio
+              v-for="dict in sys_normal_disable"
+              :key="dict.value"
+              :value="dict.value"
+              >{{ dict.label }}</el-radio
+            >
+          </el-radio-group>
+        </el-form-item>
+        <el-form-item label="备注" prop="remark">
+          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" @click="submitForm">确 定</el-button>
+          <el-button @click="cancel">取 消</el-button>
+        </div>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script setup name="PostHomePage">
+import { listPostHomePage, addPostHomePage, delPostHomePage, getPostHomePage, updatePostHomePage, listPost } from "@/api/system/postHomePage"
+
+const { proxy } = getCurrentInstance()
+const { sys_normal_disable, home_page_type } = proxy.useDict("sys_normal_disable", "home_page_type")
+
+const postHomePageList = ref([])
+const open = ref(false)
+const loading = ref(true)
+const showSearch = ref(true)
+const ids = ref([])
+const single = ref(true)
+const multiple = ref(true)
+const total = ref(0)
+const title = ref("")
+const postOptions = ref([])
+
+const data = reactive({
+  form: {},
+  queryParams: {
+    pageNum: 1,
+    pageSize: 10,
+    postId: undefined,
+    homePageType: undefined,
+    status: undefined
+  },
+  rules: {
+    postId: [{ required: true, message: "岗位ID不能为空", trigger: "blur" }],
+    homePageType: [{ required: true, message: "首页ID不能为空", trigger: "blur" }],
+    status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
+  }
+})
+
+const { queryParams, form, rules } = toRefs(data)
+
+/** 根据岗位ID获取岗位名称 */
+function getPostNameById(postId) {
+  const post = postOptions.value.find(item => item.postId === postId)
+  return post ? post.postName : postId
+}
+
+/** 获取岗位列表 */
+function getPostList() {
+  listPost({ status: "0" }).then(response => {
+    postOptions.value = response.data
+  })
+}
+
+/** 查询岗位首页配置列表 */
+function getList() {
+  loading.value = true
+  // 确保postId是数字类型
+  const params = { ...queryParams.value }
+  if (params.postId != null && typeof params.postId !== 'number') {
+    params.postId = Number(params.postId)
+  }
+  
+  listPostHomePage(params).then(response => {
+    postHomePageList.value = response.rows
+    total.value = response.total
+    loading.value = false
+  })
+}
+
+/** 取消按钮 */
+function cancel() {
+  open.value = false
+  reset()
+}
+
+/** 表单重置 */
+function reset() {
+  form.value = {
+    postId: undefined,
+    homePageType: undefined,
+    status: "0", // 默认正常状态
+    remark: undefined
+  }
+  proxy.resetForm("postHomePageRef")
+}
+
+/** 搜索按钮操作 */
+function handleQuery() {
+  queryParams.value.pageNum = 1
+  // 确保postId是数字类型
+  if (queryParams.value.postId != null && typeof queryParams.value.postId !== 'number') {
+    queryParams.value.postId = Number(queryParams.value.postId)
+  }
+  
+  getList()
+}
+
+/** 重置按钮操作 */
+function resetQuery() {
+  proxy.resetForm("queryRef")
+  handleQuery()
+}
+
+/** 多选框选中数据 */
+function handleSelectionChange(selection) {
+  ids.value = selection.map(item => item.postId)
+  single.value = selection.length != 1
+  multiple.value = !selection.length
+}
+
+/** 新增按钮操作 */
+function handleAdd() {
+  reset()
+  open.value = true
+  title.value = "添加岗位首页配置"
+}
+
+/** 修改按钮操作 */
+function handleUpdate(row) {
+  reset()
+  const postId = row.postId || (ids.value.length > 0 ? ids.value[0] : null)
+  if (postId) {
+    // 确保postId是数字类型
+    const id = typeof postId === 'number' ? postId : Number(postId)
+    getPostHomePage(id).then(response => {
+      form.value = response.data
+      open.value = true
+      title.value = "修改岗位首页配置"
+    })
+  } else {
+    proxy.$modal.msgWarning("请选择要修改的数据")
+  }
+}
+
+/** 提交按钮 */
+function submitForm() {
+  proxy.$refs["postHomePageRef"].validate(valid => {
+    if (valid) {
+      // 确保postId是数字类型
+      const formData = { ...form.value }
+      if (formData.postId != null && typeof formData.postId !== 'number') {
+        formData.postId = Number(formData.postId)
+      }
+      
+      // 确保所有必需字段都有值
+      if (!formData.postId) {
+        proxy.$modal.msgError("请选择岗位")
+        return
+      }
+      
+      if (!formData.homePageType) {
+        proxy.$modal.msgError("请选择首页类型")
+        return
+      }
+      
+      if (!formData.status) {
+        formData.status = "0" // 默认正常状态
+      }
+      
+      // 根据当前操作类型决定调用新增还是修改接口
+      // 如果是新增操作(title为"添加岗位首页配置"),调用新增接口
+      if (title.value === "添加岗位首页配置") {
+        addPostHomePage(formData).then(response => {
+          if (response.code === 200) {
+            proxy.$modal.msgSuccess("新增成功")
+            open.value = false
+            getList()
+          } else {
+            proxy.$modal.msgError("新增失败: " + response.msg)
+          }
+        }).catch(error => {
+          proxy.$modal.msgError("新增失败: " + error.message)
+        })
+      } else {
+        // 否则是修改操作
+        updatePostHomePage(formData).then(response => {
+          if (response.code === 200) {
+            proxy.$modal.msgSuccess("修改成功")
+            open.value = false
+            getList()
+          } else {
+            proxy.$modal.msgError("修改失败: " + response.msg)
+          }
+        }).catch(error => {
+          proxy.$modal.msgError("修改失败: " + error.message)
+        })
+      }
+    }
+  })
+}
+
+/** 删除按钮操作 */
+function handleDelete(row) {
+  const postIds = row.postId ? [row.postId] : ids.value
+  if (postIds && postIds.length > 0) {
+    proxy.$modal.confirm('是否确认删除岗位ID为"' + postIds.join(', ') + '"的数据项?').then(function() {
+      return delPostHomePage(postIds)
+    }).then(() => {
+      getList()
+      proxy.$modal.msgSuccess("删除成功")
+    }).catch(() => {})
+  } else {
+    proxy.$modal.msgWarning("请选择要删除的数据")
+  }
+}
+
+/** 导出按钮操作 */
+function handleExport() {
+  // 确保postId是数字类型
+  const params = { ...queryParams.value }
+  if (params.postId != null && typeof params.postId !== 'number') {
+    params.postId = Number(params.postId)
+  }
+  
+  proxy.download("system/postHomePage/export", params, `postHomePage_${new Date().getTime()}.xlsx`)
+}
+
+getPostList()
+getList()
+</script>