当前位置: 首页 > news >正文

采用若依vue 快速开发系统功能模块

文章目录

            • 运行若依项目
          • 科室管理
            • 科室查询-后端代码实现
            • 科室查询-前端代码实现
            • 科室名称状态搜索
            • 科室删除-后端代码实现
            • 科室删除-前端代码实现
            • 科室新增-后端代码实现
            • 科室新增-前端代码实现
            • 科室修改-后端代码实现
            • 前端代码实现
            • 角色权限实现


运行若依项目

运行redis 创建数据库 修改数据库配置 启动后端 启动前端

先创建目录

在这里插入图片描述

新增菜单

在这里插入图片描述
新建角色 勾选所需的菜单
在这里插入图片描述

新建用户

在这里插入图片描述

分配角色

在这里插入图片描述

退出重新登录即可看到

在这里插入图片描述

新建模型和表字段

在这里插入图片描述

服务端代码文件分类 domain (pojo) controller mapper service

设计模型视图表结构

在这里插入图片描述
在这里插入图片描述

导出sql文件

在这里插入图片描述

navicat 执行sql语句创建下面的表

CREATE TABLE `his_depts` (`depts_id` int(11) NOT NULL COMMENT '科室编号---deptsId',`depts_name` varchar(255) NOT NULL COMMENT '科室名称---deptsName',`depts_code` varchar(255) NOT NULL COMMENT '科室编码---deptsCode',`depts_num` int(11) NOT NULL DEFAULT '0' COMMENT '科室挂号量 ---deptsNum',`depts_leader` varchar(255) DEFAULT NULL COMMENT '科室领导---deptsLeader',`depts_phone` varchar(255) DEFAULT NULL COMMENT '科室电话---deptsPhone',`status` int(11) NOT NULL COMMENT '科室状态---status',`create_by` varchar(255) DEFAULT NULL COMMENT '创建者---createBy',`create_time` datetime DEFAULT NULL COMMENT '创建时间--createTime',`update_by` varbinary(255) DEFAULT NULL COMMENT '更新者---updateBy',`update_time` datetime DEFAULT NULL COMMENT '更新时间--updateTime'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO his_depts VALUES 
(101,"内科","HIS-Nk",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(102,"外科","HIS-WK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(103,"儿科","HIS-EK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(104,"妇科","HIS-FK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(105,"眼科","HIS-YK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(106,"耳鼻喉科","HIS-EBHK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(107,"口腔科","HIS-KQK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(108,"皮肤科","HIS-PFK",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW()),
(109,"其他","HIS-OTHER",0,"雷哥","17512344321",1,"admin",NOW(),"admin",NOW());
科室管理
科室查询-后端代码实现

仿照岗位管理实现 对应表sys_post

在这里插入图片描述

在这里插入图片描述

通过代码生成器 导入表

复制HisDepts.java 代码到domain类

package com.ruoyi.system.domain;import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;/*** 【请填写功能名称】对象 his_depts* * @author ruoyi* @date 2025-04-13*/
public class HisDepts extends BaseEntity
{private static final long serialVersionUID = 1L;/** 科室编号---deptsId */@Excel(name = "科室编号---deptsId")private Long deptsId;/** 科室名称---deptsName */@Excel(name = "科室名称---deptsName")private String deptsName;/** 科室编码---deptsCode */@Excel(name = "科室编码---deptsCode")private String deptsCode;/** 科室挂号量 ---deptsNum */@Excel(name = "科室挂号量 ---deptsNum")private Long deptsNum;/** 科室领导---deptsLeader */@Excel(name = "科室领导---deptsLeader")private String deptsLeader;/** 科室电话---deptsPhone */@Excel(name = "科室电话---deptsPhone")private String deptsPhone;/** 科室状态---status */@Excel(name = "科室状态---status")private Long status;public void setDeptsId(Long deptsId) {this.deptsId = deptsId;}public Long getDeptsId() {return deptsId;}public void setDeptsName(String deptsName) {this.deptsName = deptsName;}public String getDeptsName() {return deptsName;}public void setDeptsCode(String deptsCode) {this.deptsCode = deptsCode;}public String getDeptsCode() {return deptsCode;}public void setDeptsNum(Long deptsNum) {this.deptsNum = deptsNum;}public Long getDeptsNum() {return deptsNum;}public void setDeptsLeader(String deptsLeader) {this.deptsLeader = deptsLeader;}public String getDeptsLeader() {return deptsLeader;}public void setDeptsPhone(String deptsPhone) {this.deptsPhone = deptsPhone;}public String getDeptsPhone() {return deptsPhone;}public void setStatus(Long status) {this.status = status;}public Long getStatus() {return status;}@Overridepublic String toString() {return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE).append("deptsId", getDeptsId()).append("deptsName", getDeptsName()).append("deptsCode", getDeptsCode()).append("deptsNum", getDeptsNum()).append("deptsLeader", getDeptsLeader()).append("deptsPhone", getDeptsPhone()).append("status", getStatus()).append("createBy", getCreateBy()).append("createTime", getCreateTime()).append("updateBy", getUpdateBy()).append("updateTime", getUpdateTime()).toString();}
}

仿照SysPostMapper格式 创建HisDeptsMapper文件 到mapper文件夹里

创建mapper 和 mapper.xml

package com.ruoyi.system.mapper;import com.ruoyi.system.domain.HisDepts;
import org.apache.ibatis.annotations.Mapper;import java.util.List;/*** @author Admin* @title: HisDeptsMapper* @projectName RuoYi-Vue-master* @description: HisDeptsMapper* @date 2025/4/13 13:35*/
@Mapper
public interface HisDeptsMapper {List<HisDepts> selectHisDeptsList(HisDepts hisDepts);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.HisDeptsMapper"><select id="selectHisDeptsList" resultType="hisDepts">select * from his_depts<where><if test="deptsName != null and deptsName != ''">and depts_name like concat('%', #{deptName}, '%')</if><if test="status != null">and status = #{status}</if></where></select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.HisDeptsMapper"><sql id="selectHisDeptsVo">select depts_id, depts_name, depts_code, depts_num, depts_leader, depts_phone, status, create_by, create_time, update_by, update_time from his_depts</sql><select id="selectHisDeptsList" resultType="hisDepts"><include refid="selectHisDeptsVo"/><where><if test="deptsName != null and deptsName != ''">and depts_name like concat('%', #{deptName}, '%')</if><if test="status != null">and status = #{status}</if></where></select>
</mapper>

创建service文件 和实现类

package com.ruoyi.system.service;import com.ruoyi.system.domain.HisDepts;import java.util.List;/*** @author Admin* @title: IHisDeptsService* @projectName RuoYi-Vue-master* @description: IHisDeptsService* @date 2025/4/13 13:49*/
public interface IHisDeptsService {List<HisDepts> selectDeptsList(HisDepts hisDepts);
}

仿照创建controller

package com.ruoyi.web.controller.system;import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.HisDepts;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.IHisDeptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;/*** @author Admin* @title: HisDeptController* @projectName RuoYi-Vue-master* @description: HisDeptController* @date 2025/4/13 19:00*/
@RestController
@RequestMapping("/his/depts")
public class HisDeptController extends BaseController {@Autowiredprivate IHisDeptsService hisDeptsService;/*** 获取科室列表*///@PreAuthorize("@ss.hasPermi('system:post:list')")@GetMapping("/list")public TableDataInfo list(HisDepts hisDepts){startPage();List<HisDepts> list = hisDeptsService.selectDeptsList(hisDepts);return getDataTable(list);}
}
科室查询-前端代码实现

新建菜单 系统设置

在系统设置下新增菜单 科室管理

参考岗位管理路由参数/system/post

分析若依代码

岗位管理组件路径 system/post/index

对应数据库下的组件参数

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

复制前端代码post下的index.vue

仿照 岗位管理post前端代码 在views目录下创建his/depts/index.vue

修改科室管理组件路径参数为 his/depts/index

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

点击菜单 科室管理 即可看到页面显示

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

修改前端代码

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

状态值获取

<el-select v-model="queryParams.status" placeholder="科室状态" clearable><el-optionv-for="dict in dict.type.sys_normal_disable":key="dict.value":label="dict.label":value="dict.value"/></el-select>

获取状态函数为main.js下

import { getDicts } from "@/api/system/dict/data";// 根据字典类型查询字典数据信息
export function getDicts(dictType) {return request({url: '/system/dict/data/type/' + dictType,method: 'get'})
}

取字典里的数据由前端封装函数调用 即获取到

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

去掉导出按钮

修改表单列表

获取岗位列表代码

import { listPost, getPost, delPost, addPost, updatePost } from "@/api/system/post";// 查询参数
queryParams: {pageNum: 1,pageSize: 10,postCode: undefined,postName: undefined,status: undefined
},created() {this.getList();},getList() {this.loading = true;listPost(this.queryParams).then(response => {this.postList = response.rows;this.total = response.total;this.loading = false;});},

复制api/system/post.js 到his下depts.js

修改为科室代码

import { listPost, getPost, delPost, addPost, updatePost } from "@/api/his/depts";
// 查询科室列表
export function listPost(query) {return request({url: '/his/depts/list',method: 'get',params: query})
}

打印列表显示为空 console.log(response.rows) 更换匹配参数

      <el-table-column type="selection" width="55" align="center" /><el-table-column label="科室ID" align="center" prop="deptsId" /><el-table-column label="科室名称" align="center" prop="deptsName" /><el-table-column label="科室编号" align="center" prop="deptsCode" /><el-table-column label="科室挂号量" align="center" prop="deptsNum" /><el-table-column label="负责人" align="center" prop="deptsLeader" /><el-table-column label="电话" align="center" prop="deptsPhone" /><el-table-column label="状态" align="center" prop="status"><template slot-scope="scope"><dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/></template></el-table-column><el-table-column label="创建时间" align="center" prop="createTime" width="180"><template slot-scope="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template></el-table-column>

打印数据为空 后端mapper没有对应

修改后端代码 列名和实体名不一样 采用resultMap映射

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.HisDeptsMapper"><resultMap type="HisDepts" id="HisDeptsResult"><result property="deptsId"    column="depts_id"    /><result property="deptsName"    column="depts_name"    /><result property="deptsCode"    column="depts_code"    /><result property="deptsNum"    column="depts_num"    /><result property="deptsLeader"    column="depts_leader"    /><result property="deptsPhone"    column="depts_phone"    /><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"    /></resultMap><sql id="selectHisDeptsVo">select depts_id, depts_name, depts_code, depts_num, depts_leader, depts_phone, status, create_by, create_time, update_by, update_time from his_depts</sql><select id="selectHisDeptsList" resultMap="HisDeptsResult"><include refid="selectHisDeptsVo"/><where><if test="deptsName != null and deptsName != ''">and depts_name like concat('%', #{deptsName}, '%')</if><if test="status != null">and status = #{status}</if></where></select>
</mapper>

完整前端代码

<template><div class="app-container"><el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"><el-form-item label="科室名称" prop="postCode"><el-inputv-model="queryParams.postCode"placeholder="请输入科室名称"clearable@keyup.enter.native="handleQuery"/></el-form-item><el-form-item label="状态" prop="status"><el-select v-model="queryParams.status" placeholder="科室状态" clearable><el-optionv-for="dict in dict.type.sys_normal_disable":key="dict.value":label="dict.label":value="dict.value"/></el-select></el-form-item><el-form-item><el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button><el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button></el-form-item></el-form><el-row :gutter="10" class="mb8"><el-col :span="1.5"><el-buttontype="primary"plainicon="el-icon-plus"size="mini"@click="handleAdd"v-hasPermi="['system:post:add']">新增</el-button></el-col><el-col :span="1.5"><el-buttontype="success"plainicon="el-icon-edit"size="mini":disabled="single"@click="handleUpdate"v-hasPermi="['system:post:edit']">修改</el-button></el-col><el-col :span="1.5"><el-buttontype="danger"plainicon="el-icon-delete"size="mini":disabled="multiple"@click="handleDelete"v-hasPermi="['system:post:remove']">删除</el-button></el-col><right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar></el-row><el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange"><el-table-column type="selection" width="55" align="center" /><el-table-column label="科室ID" align="center" prop="deptsId" /><el-table-column label="科室名称" align="center" prop="deptsName" /><el-table-column label="科室编号" align="center" prop="deptsCode" /><el-table-column label="科室挂号量" align="center" prop="deptsNum" /><el-table-column label="负责人" align="center" prop="deptsLeader" /><el-table-column label="电话" align="center" prop="deptsPhone" /><el-table-column label="状态" align="center" prop="status"><template slot-scope="scope"><dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/></template></el-table-column><el-table-column label="创建时间" align="center" prop="createTime" width="180"><template slot-scope="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template></el-table-column><el-table-column label="操作" align="center" class-name="small-padding fixed-width"><template slot-scope="scope"><el-buttonsize="mini"type="text"icon="el-icon-edit"@click="handleUpdate(scope.row)"v-hasPermi="['system:post:edit']">修改</el-button><el-buttonsize="mini"type="text"icon="el-icon-delete"@click="handleDelete(scope.row)"v-hasPermi="['system:post:remove']">删除</el-button></template></el-table-column></el-table><paginationv-show="total>0":total="total":page.sync="queryParams.pageNum":limit.sync="queryParams.pageSize"@pagination="getList"/><!-- 添加或修改岗位对话框 --><el-dialog :title="title" :visible.sync="open" width="500px" append-to-body><el-form ref="form" :model="form" :rules="rules" label-width="80px"><el-form-item label="岗位名称" prop="postName"><el-input v-model="form.postName" placeholder="请输入岗位名称" /></el-form-item><el-form-item label="岗位编码" prop="postCode"><el-input v-model="form.postCode" placeholder="请输入编码名称" /></el-form-item><el-form-item label="岗位顺序" prop="postSort"><el-input-number v-model="form.postSort" controls-position="right" :min="0" /></el-form-item><el-form-item label="岗位状态" prop="status"><el-radio-group v-model="form.status"><el-radiov-for="dict in dict.type.sys_normal_disable":key="dict.value":label="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><div slot="footer" class="dialog-footer"><el-button type="primary" @click="submitForm">确 定</el-button><el-button @click="cancel">取 消</el-button></div></el-dialog></div>
</template><script>
import { listPost, getPost, delPost, addPost, updatePost } from "@/api/his/depts";export default {name: "Post",dicts: ['sys_normal_disable'],data() {return {// 遮罩层loading: true,// 选中数组ids: [],// 非单个禁用single: true,// 非多个禁用multiple: true,// 显示搜索条件showSearch: true,// 总条数total: 0,// 岗位表格数据postList: [],// 弹出层标题title: "",// 是否显示弹出层open: false,// 查询参数queryParams: {pageNum: 1,pageSize: 10,postCode: undefined,postName: undefined,status: undefined},// 表单参数form: {},// 表单校验rules: {postName: [{ required: true, message: "岗位名称不能为空", trigger: "blur" }],postCode: [{ required: true, message: "岗位编码不能为空", trigger: "blur" }],postSort: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }]}};},created() {this.getList();},methods: {/** 查询岗位列表 */getList() {this.loading = true;listPost(this.queryParams).then(response => {console.log(response.rows)this.postList = response.rows;this.total = response.total;this.loading = false;});},// 取消按钮cancel() {this.open = false;this.reset();},// 表单重置reset() {this.form = {postId: undefined,postCode: undefined,postName: undefined,postSort: 0,status: "0",remark: undefined};this.resetForm("form");},/** 搜索按钮操作 */handleQuery() {this.queryParams.pageNum = 1;this.getList();},/** 重置按钮操作 */resetQuery() {this.resetForm("queryForm");this.handleQuery();},// 多选框选中数据handleSelectionChange(selection) {this.ids = selection.map(item => item.postId)this.single = selection.length!=1this.multiple = !selection.length},/** 新增按钮操作 */handleAdd() {this.reset();this.open = true;this.title = "添加岗位";},/** 修改按钮操作 */handleUpdate(row) {this.reset();const postId = row.postId || this.idsgetPost(postId).then(response => {this.form = response.data;this.open = true;this.title = "修改岗位";});},/** 提交按钮 */submitForm: function() {this.$refs["form"].validate(valid => {if (valid) {if (this.form.postId != undefined) {updatePost(this.form).then(response => {this.$modal.msgSuccess("修改成功");this.open = false;this.getList();});} else {addPost(this.form).then(response => {this.$modal.msgSuccess("新增成功");this.open = false;this.getList();});}}});},/** 删除按钮操作 */handleDelete(row) {const postIds = row.postId || this.ids;this.$modal.confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?').then(function() {return delPost(postIds);}).then(() => {this.getList();this.$modal.msgSuccess("删除成功");}).catch(() => {});},/** 导出按钮操作 */handleExport() {this.download('system/post/export', {...this.queryParams}, `post_${new Date().getTime()}.xlsx`)}}
};
</script>

接口代码

import request from '@/utils/request'// 查询科室列表
export function listPost(query) {return request({url: '/his/depts/list',method: 'get',params: query})
}// 查询岗位详细
export function getPost(postId) {return request({url: '/system/post/' + postId,method: 'get'})
}// 新增岗位
export function addPost(data) {return request({url: '/system/post',method: 'post',data: data})
}// 修改岗位
export function updatePost(data) {return request({url: '/system/post',method: 'put',data: data})
}// 删除岗位
export function delPost(postId) {return request({url: '/system/post/' + postId,method: 'delete'})
}
科室名称状态搜索
<el-form-item label="科室名称" prop="postCode"><el-inputv-model="queryParams.deptsName"placeholder="请输入科室名称"clearable@keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status"><el-select v-model="queryParams.status" placeholder="科室状态" clearable><el-optionv-for="dict in dict.type.sys_normal_disable":key="dict.value":label="dict.label":value="dict.value"/></el-select>
</el-form-item>
科室删除-后端代码实现

mapper文件

@Mapper
public interface HisDeptsMapper {List<HisDepts> selectHisDeptsList(HisDepts hisDepts);int deleteHisDeptsById(Long deptsId);
}

xml文件

<delete id="deleteHisDeptsById" parameterType="Long">delete from his_depts where depts_id = #{deptsId}
</delete>

service方法

/*** 删除科室信息** @param deptsId* @return 结果*/
public int deleteDeptsById(Long deptsId);

impl实现类

@Override
public int deleteDeptsById(Long deptsId) {return hisDeptsMapper.deleteHisDeptsById(deptsId);
}

controller借口方法

/*** 科室删除*/
//@PreAuthorize("@ss.hasPermi('system:post:remove')")
@Log(title = "科室管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{deptsId}")
public AjaxResult remove(@PathVariable Long deptsId)
{return toAjax(hisDeptsService.deleteDeptsById(deptsId));
}
科室删除-前端代码实现
import { listPost, getPost, delPost, addPost, updatePost } from "@/api/his/depts";
/** 删除按钮操作 */
handleDelete(row) {const postIds = row.deptsId || this.ids;this.$modal.confirm('是否确认删除科室编号为"' + postIds + '"的数据项?').then(function() {return delPost(postIds);
}).then(() => {this.getList();this.$modal.msgSuccess("删除成功");}).catch(() => {});
},
// 删除科室
export function delPost(postId) {return request({url: '/his/depts/' + postId,method: 'delete'})
}
科室新增-后端代码实现

修改HisDeptsMapper.java代码

int insertHisDepts(HisDepts hisDepts);

修改HisDeptsMapper.xml代码

<insert id="insertHisDepts" parameterType="HisDepts">insert into his_depts<trim prefix="(" suffix=")" suffixOverrides=","><if test="deptsId != null">depts_id,</if><if test="deptsName != null and deptsName != ''">depts_name,</if><if test="deptsCode != null and deptsCode != ''">depts_code,</if><if test="deptsNum != null">depts_num,</if><if test="deptsLeader != null">depts_leader,</if><if test="deptsPhone != null">depts_phone,</if><if test="status != null">status,</if><if test="createBy != null">create_by,</if><if test="createTime != null">create_time,</if><if test="updateBy != null">update_by,</if><if test="updateTime != null">update_time,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="deptsId != null">#{deptsId},</if><if test="deptsName != null and deptsName != ''">#{deptsName},</if><if test="deptsCode != null and deptsCode != ''">#{deptsCode},</if><if test="deptsNum != null">#{deptsNum},</if><if test="deptsLeader != null">#{deptsLeader},</if><if test="deptsPhone != null">#{deptsPhone},</if><if test="status != null">#{status},</if><if test="createBy != null">#{createBy},</if><if test="createTime != null">#{createTime},</if><if test="updateBy != null">#{updateBy},</if><if test="updateTime != null">#{updateTime},</if></trim>
</insert>

添加接口IHisDeptsService.java

/*** 新增科室信息* @param hisDepts* @return*/
public int insertHisDepts(HisDepts hisDepts);

实现接口HisDeptsServiceImpl.java

/*** 科室新增* @param hisDepts* @return*/
@Override
public int insertHisDepts(HisDepts hisDepts) {return hisDeptsMapper.insertHisDepts(hisDepts);
}

仿照岗位管理SysPostController 修改controller类代码

//@PreAuthorize("@ss.hasPermi('system:post:add')")
@Log(title = "科室新增", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody HisDepts hisDepts)
{//if (!postService.checkPostNameUnique(post))//{//    return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");//}//else if (!postService.checkPostCodeUnique(post))//{//    return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");//}//添加创建人名称hisDepts.setCreateBy(getUsername());hisDepts.setCreateTime(new Date());return toAjax(hisDeptsService.insertHisDepts(hisDepts));
}

这里引入@Validated注解 实体类 可以添加@NotBlank 注解

@NotBlank(message = "科室名称不能为空")
@Excel(name = "科室名称---deptsName")
private String deptsName;

修改数据库表设计 id设置自增1 时间设置timestamp格式

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

科室新增-前端代码实现

修改表单代码

<el-form ref="form" :model="form" :rules="rules" label-width="80px"><el-form-item label="岗位名称" prop="deptsName"><el-input v-model="form.deptsName" placeholder="请输入科室名称" /></el-form-item><el-form-item label="科室编码" prop="deptsCode"><el-input v-model="form.deptsCode" placeholder="请输入科室编码" /></el-form-item><el-form-item label="负责人" prop="deptsLeader"><el-input v-model="form.deptsLeader" placeholder="请输入负责人" /></el-form-item><el-form-item label="电话" prop="deptsPhone"><el-input v-model="form.deptsPhone" placeholder="请输入电话" /></el-form-item><el-form-item label="挂号量" prop="deptsNum"><el-input v-model="form.deptsNum" placeholder="请输入挂号量" /></el-form-item><el-form-item label="科室状态" prop="status"><el-radio-group v-model="form.status"><el-radiov-for="dict in dict.type.sys_normal_disable":key="dict.value":label="dict.value">{{dict.label}}</el-radio></el-radio-group></el-form-item>
</el-form>

表单重置代码修改

// 表单重置
reset() {this.form = {deptsId: undefined,deptsCode: undefined,deptsName: undefined,deptsLeader: undefined,deptsPhone: undefined,deptsNum: 0,status: "0",};this.resetForm("form");
},

表单校验

// 表单校验
rules: {deptsName: [{ required: true, message: "科室名称不能为空", trigger: "blur" }],deptsCode: [{ required: true, message: "科室编码不能为空", trigger: "blur" }],deptsNum: [{ required: true, message: "挂号量不能为空", trigger: "blur" }]
}

提交按钮代码修改

/** 提交按钮 */submitForm: function() {this.$refs["form"].validate(valid => {if (valid) {if (this.form.deptsId != undefined) {updatePost(this.form).then(response => {this.$modal.msgSuccess("修改成功");this.open = false;this.getList();});} else {addPost(this.form).then(response => {this.$modal.msgSuccess("新增成功");this.open = false;this.getList();});}}});},

新增岗位api接口路径代码修改

// 新增岗位
export function addPost(data) {return request({url: '/his/depts',method: 'post',data: data})
}
科室修改-后端代码实现

科室信息回显

HisDeptsMapper.xml

<select id="selectHisDeptsById" resultMap="HisDeptsResult"><include refid="selectHisDeptsVo"/>where depts_id = #{deptsId}
</select>

HisDeptsMapper.java

HisDepts selectHisDeptsById(Long deptsId);

IHisDeptsService.java

HisDepts selectHisDeptsById(Long deptsId);

IHisDeptsServiceImpl.java

@Override
public HisDepts selectHisDeptsById(Long deptsId) {return hisDeptsMapper.selectHisDeptsById(deptsId);
}

HisDeptController.java

/*** 根据科室id回显信息* @param deptsId* @return*/
//@PreAuthorize("@ss.hasPermi('system:post:query')")
@GetMapping(value = "/{deptsId}")
public AjaxResult getInfo(@PathVariable Long deptsId)
{return success(hisDeptsService.selectHisDeptsById(deptsId));
}

修改科室

<update id="updateHisDepts">update his_depts<trim prefix="SET" suffixOverrides=","><if test="deptsName != null and deptsName != ''">depts_name = #{deptsName},</if><if test="deptsCode != null and deptsCode != ''">depts_code = #{deptsCode},</if><if test="deptsNum != null">depts_num = #{deptsNum},</if><if test="deptsLeader != null">depts_leader = #{deptsLeader},</if><if test="deptsPhone != null">depts_phone = #{deptsPhone},</if><if test="status != null">status = #{status},</if><if test="createBy != null">create_by = #{createBy},</if><if test="createTime != null">create_time = #{createTime},</if><if test="updateBy != null">update_by = #{updateBy},</if><if test="updateTime != null">update_time = #{updateTime},</if></trim>where depts_id = #{deptsId}</update>

HisDeptsMapper.java

int updateHisDepts(HisDepts hisDepts);

IHisDeptsService.java

 int updateHisDepts(HisDepts hisDepts);

IHisDeptsServiceImpl.java

@Override
public int updateHisDepts(HisDepts hisDepts) {return hisDeptsMapper.updateHisDepts(hisDepts);
}

HisDeptController.java

/*** 修改科室*/
//@PreAuthorize("@ss.hasPermi('system:post:edit')")
@Log(title = "科室管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody HisDepts hisDepts)
{//if (!postService.checkPostNameUnique(post))//{//    return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");//}//else if (!postService.checkPostCodeUnique(post))//{//    return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");//}hisDepts.setUpdateBy(getUsername());hisDepts.setUpdateTime(new Date());return toAjax(hisDeptsService.updateHisDepts(hisDepts));
}
前端代码实现
/** 修改按钮操作 */
handleUpdate(row) {this.reset();const deptsId = row.deptsId || this.idsgetPost(deptsId).then(response => {this.form = response.data;this.form.status = this.form.status.toString();this.open = true;this.title = "修改岗位";});
},
// 查询岗位详细
export function getPost(postId) {return request({url: '/his/depts/' + postId,method: 'get'})
}
// 修改科室
export function updatePost(data) {return request({url: '/his/depts',method: 'put',data: data})
}
角色权限实现

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

普通用户没有界面权限 按钮权限操作

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

权限跟随菜单 修改菜单权限

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

给角色添加菜单权限

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

放开权限注解

/*** 获取科室列表*/
@PreAuthorize("@ss.hasPermi('his:depts:list')")
@GetMapping("/list")
public TableDataInfo list(HisDepts hisDepts) {startPage();List<HisDepts> list = hisDeptsService.selectDeptsList(hisDepts);return getDataTable(list);
}

前端放开权限代码

<el-col :span="1.5"><el-buttontype="primary"plainicon="el-icon-plus"size="mini"@click="handleAdd"v-hasPermi="['his:depts:add']">新增</el-button></el-col><el-col :span="1.5"><el-buttontype="success"plainicon="el-icon-edit"size="mini":disabled="single"@click="handleUpdate"v-hasPermi="['his:depts:edit']">修改</el-button></el-col><el-col :span="1.5"><el-buttontype="danger"plainicon="el-icon-delete"size="mini":disabled="multiple"@click="handleDelete"v-hasPermi="['his:depts:remove']">删除</el-button></el-col><el-table-column label="操作" align="center" class-name="small-padding fixed-width"><template slot-scope="scope"><el-buttonsize="mini"type="text"icon="el-icon-edit"@click="handleUpdate(scope.row)"v-hasPermi="['his:depts:edit']">修改</el-button><el-buttonsize="mini"type="text"icon="el-icon-delete"@click="handleDelete(scope.row)"v-hasPermi="['his:depts:remove']">删除</el-button></template></el-table-column>

添加权限按钮

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

角色添加上权限按钮

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

放开权限代码

@PreAuthorize("@ss.hasPermi('his:depts:list')")
@PreAuthorize("@ss.hasPermi('his:depts:add')")
@PreAuthorize("@ss.hasPermi('his:depts:query')")
@PreAuthorize("@ss.hasPermi('his:depts:edit')")
@PreAuthorize("@ss.hasPermi('his:depts:remove')")

相关文章:

  • 安全测试的全面知识体系及实现路径
  • visual studio 2022更改项目名称,灾难性故障(异常来自HRESULT)
  • [dp16_两个数组] 通配符匹配 | 交错字符串 | 两个字符串的最小ASCII删除和
  • Linux中NFS服务设置
  • 3.学习笔记--Spring-AOP总结(p39)-Spring事务简介(P40)-Spring事务角色(P41)-Spring事务属性(P42)
  • vue MarkdownIt标签多出了<p>标签导致高度变丑
  • 【实战篇】导入dbc文件
  • 路由过滤实验
  • 【从零实现高并发内存池】thread cache、central cache 和 page cache 回收策略详解
  • 硅基光子学微环谐振器(MRR)技术进展与前沿热点
  • 将python项目打包成Windows后台服务
  • linux常用指令:文件目录类、文件查看类、压缩和解压类
  • Java设计开发商城抢票功能
  • 【文献笔记】LLM-based control code generation using image recognition
  • Redis——五种数据类型
  • 实验五 8255和LED数码管显示实验
  • AOSP的Doze模式-DeepIdle 初识
  • 从彩色打印单行标准九九表学习〖代码情书〗的书写范式(Python/DeepSeek)
  • 定制化 Docsify 文档框架实战分享
  • async-profiler火焰图找出耗CPU方法
  • 普京与卢卡申科举行会晤,将扩大在飞机制造等领域合作
  • 上海市十六届人大常委会第二十一次会议表决通过有关人事任免事项
  • 杨国荣︱学术上的立此存照——《故旧往事,欲说还休》读后
  • 走访中广核风电基地:701台风机如何乘风化电,点亮3000万人绿色生活
  • 当AI开始深度思考,人类如何守住自己的慢思考能力?
  • 《奇袭白虎团》原型人物之一赵顺合辞世,享年95岁