一、创建his-medicine模块
0) 在创建好的若依后端项目中创建一个maven模块his-medicine
1)his模块的整合步骤
①)his的依赖
这个是若依项目所有系统模块都需要添加的依赖,domain和controller继承的类就在这里面。
<!-- 通用工具--> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common</artifactId> </dependency>
②)安装his模块
③) 在ruoyi-admin模块中引入his模块
实质上在项目运行时,实际运行的是ruoyi-admin项目,所有其他模块的文件最终都放到此模块下。
2)实现his的思路
his医院信息管理系统的业务对象包括生产厂家、供应商、药品、订单、订单详情等等,要想完成一个his,首先需要把所有的业务对象的增删改查基础代码写出来,单表的增删改查过程可以直接使用代码生成器,但是代码生成器有时候前端会漏写,后端有可能包路径不对,可以尝试自己手动写一个系统对象,熟悉若依的系统框架到底是怎么运行的;
然后再考虑复杂的业务场景。
二、生产厂家系统:
1)数据库sql建表语句
drop table if exists his_medicine_factory CREATE TABLE `his_medicine_factory` ( `factory_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '厂家ID', `factory_name` varchar(100) DEFAULT NULL COMMENT '厂家名称', `factory_code` varchar(50) NOT NULL COMMENT '厂家编码', `factory_person` varchar(50) NOT NULL COMMENT '厂家联系人', `factory_phone` char(11) DEFAULT '00' COMMENT '联系方式', `factory_keyword` varchar(50) DEFAULT '' COMMENT '厂家关键字', `factory_address` varchar(100) DEFAULT '' COMMENT '厂家地址', `status` char(1) DEFAULT '0' COMMENT '(0正常 1 禁用)', `create_by` varchar(64) DEFAULT '' COMMENT '创建者', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `update_by` varchar(64) DEFAULT '' COMMENT '更新者', `update_time` datetime DEFAULT NULL COMMENT '更新时间', `remark` varchar(500) DEFAULT NULL COMMENT '备注', PRIMARY KEY (`factory_id`) ) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8 COMMENT='生产厂家信息表';
2)单表增删改查的实现
写一个生产厂家的管理系统可以对照写好的部门系统SysPost格式,从后端到前端不管是代码的格式还是界面elementplus标签 岗位系统是比较好的参考例子。
〇)domain
通过若依写好的岗位管理系统发现所有实体类都继承了BaseEntity
BaseEntity主要用来存放一些公共的属性值,对应的也就是数据库中表中的公共字段
那根据数据库创建的实体类MedicineFactory也继承BaseEntity
package com.ruoyi.domain; import com.ruoyi.common.core.domain.BaseEntity; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import java.sql.Date; /** * @author rk * @description: TODO * @date 2024/8/28 19:08 */ @Data @NoArgsConstructor @AllArgsConstructor public class MedicineFactory extends BaseEntity { private Long factoryId; private String factoryName; private String factoryCode; private String factoryPerson; private String factoryPhone; private String factoryKeyword; private String factoryAddress; private String status; private String createBy; private Date createTime; private String updateBy; private Date updateTime; private String remake; @DateTimeFormat(pattern = "yyyy-MM-dd") private Date startTime; @DateTimeFormat(pattern = "yyyy-MM-dd" ) private Date endTime; }
①mapper 没有影响 ,照写
<?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.ruoyi.mapper.HisMedicineFactoryMapper"> <resultMap id="factory" type="com.ruoyi.domain.MedicineFactory"> <id column="factory_id" property="factoryId"></id> <result column="factory_name" property="factoryName"></result> <result column="factory_code" property="factoryCode"></result> <result column="factory_person" property="factoryPerson"></result> <result column="factory_phone" property="factoryPhone"></result> <result column="factory_keyword" property="factoryKeyword"></result> <result column="factory_address" property="factoryAddress"></result> <result column="create_by" property="createBy"></result> <result column="create_time" property="createTime"></result> <result column="update_by" property="updateBy"></result> <result column="update_time" property="updateTime"></result> <result column="remark" property="remark"></result> <!-- <association property="" resultMap=""></association>--> </resultMap> <sql id="selectFactory"> select factory_id,factory_name,factory_code,factory_person, factory_phone ,factory_keyword,factory_address,create_by,create_time, update_by,update_time,remark,status from his_medicine_factory </sql> <select id="selectFactoryList" resultMap="factory"> <include refid="selectFactory"></include> <where> <if test="factoryName!=null and factoryName!=''"> and factory_name like concat('%',#{factoryName},'%') </if> <if test="factoryKeyword!=null and factoryKeyword!=''"> and factory_keyword = #{factoryKeyword} </if> <if test="factoryPhone!=null and factoryPhone!=''"> and factory_phone = #{factoryPhone} </if> <if test="status!=null and status!=''"> and status = #{status} </if> <if test="params.startTime!=null and params.startTime!=''"> and create_time >= #{params.startTime} </if> <if test="params.endTime!=null and params.endTime!=''"> and create_time <= #{params.endTime} </if> </where> </select> <update id="updateFactory"> update his_medicine_factory <set> <if test="factoryCode != null and factoryCode != ''">factory_code = #{factoryCode},</if> <if test="factoryPerson != null and factoryPerson != ''">factory_person = #{factoryPerson},</if> <if test="factoryKeyword != null and factoryKeyword !=''">factory_keyword = #{factoryKeyword},</if> <if test="factoryAddress != null and factoryAddress !=''">factory_address = #{factoryAddress},</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 factory_id = #{factoryId} </update> <insert id="addFactory"> insert into his_medicine_factory values(0,#{factoryName},#{factoryCode},#{factoryPerson},#{factoryPhone},#{factoryKeyword}, #{factoryAddress},#{status},#{createBy},sysdate(), 0,NULL,#{remake}) </insert> <delete id="deleteFactoryById"> delete from his_medicine_factory where factory_id = #{id} </delete> <select id="selectFactoryById" resultMap="factory"> <include refid="selectFactory"></include> where factory_id = #{id} </select> </mapper>
package com.ruoyi.mapper; import com.ruoyi.domain.MedicineFactory; import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper public interface HisMedicineFactoryMapper { List<MedicineFactory> selectFactoryList(MedicineFactory medicineFactory); int updateFactory(MedicineFactory medicineFactory); int addFactory(MedicineFactory medicineFactory); int deleteFactoryById(Long id); MedicineFactory selectFactoryById(Long id); }
②service 没有影响 ,照写
package com.ruoyi.service; import com.ruoyi.domain.MedicineFactory; import java.util.List; public interface IHisMedicineFactory { List<MedicineFactory> selectFactoryList(MedicineFactory medicineFactory); int updateFactory(MedicineFactory medicineFactory); int addFactory(MedicineFactory medicineFactory); int deleteFactoryById(Long id); MedicineFactory selectFactoryById(Long id); }
package com.ruoyi.service.impl; import com.ruoyi.mapper.HisMedicineFactoryMapper; import com.ruoyi.service.IHisMedicineFactory; import com.ruoyi.domain.MedicineFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** * @author rk * @description: TODO * @date 2024/8/28 20:26 */ @Service public class HisMedicineFactoryImpl implements IHisMedicineFactory { @Autowired private HisMedicineFactoryMapper hisMedicineFactoryMapper; @Override public List<MedicineFactory> selectFactoryList(MedicineFactory medicineFactory) { return hisMedicineFactoryMapper.selectFactoryList(medicineFactory); } @Override public int updateFactory(MedicineFactory medicineFactory) { return hisMedicineFactoryMapper.updateFactory(medicineFactory); } @Override public int addFactory(MedicineFactory medicineFactory) { return hisMedicineFactoryMapper.addFactory(medicineFactory); } @Override public int deleteFactoryById(Long id) { return hisMedicineFactoryMapper.deleteFactoryById(id); } @Override public MedicineFactory selectFactoryById(Long id) { return hisMedicineFactoryMapper.selectFactoryById(id); } }
③controller
controller类的代码放在ruoyi-admin目录下;
需要继承BaseController ;
每个单元方法上添加检验权限标识符的注解@PreAuthorize
package com.ruoyi.web.controller.medicine; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.domain.MedicineFactory; import com.ruoyi.service.IHisMedicineFactory; import com.ruoyi.system.domain.SysPost; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; /** * @author rk * @description: TODO * @date 2024/8/28 20:34 */ @RestController @RequestMapping("medicine/factory") public class MedicineController extends BaseController { @Autowired private IHisMedicineFactory hisMedicineFactory; /** * */ @PreAuthorize("@ss.hasPermi('medicine:factory:list')") @GetMapping("/list") public TableDataInfo list(MedicineFactory medicineFactory) { startPage(); List<MedicineFactory> list = hisMedicineFactory.selectFactoryList(medicineFactory); return getDataTable(list); } /** * 根据岗位编号获取详细信息 */ @PreAuthorize("@ss.hasPermi('medicine:factory:list')") @GetMapping(value = "/list/{id}") public AjaxResult getInfo(@PathVariable Long id) { return success(hisMedicineFactory.selectFactoryById(id)); } @PreAuthorize("@ss.hasPermi('medicine:factory:add')") @PostMapping public AjaxResult add(@Validated @RequestBody MedicineFactory medicineFactory) { medicineFactory.setCreateBy(getUsername()); return toAjax(hisMedicineFactory.addFactory(medicineFactory)); } /** * 修改岗位 */ @PreAuthorize("@ss.hasPermi('medicine:factory:edit')") @PutMapping public AjaxResult edit(@Validated @RequestBody MedicineFactory medicineFactory) { medicineFactory.setUpdateBy(getUsername()); return toAjax(hisMedicineFactory.updateFactory(medicineFactory)); } /** * 删除岗位 */ @PreAuthorize("@ss.hasPermi('medicine:factory:remove')") @DeleteMapping("/{id}") public AjaxResult remove(@PathVariable Long id) { return toAjax(hisMedicineFactory.deleteFactoryById(id)); } }
3)对应的前端界面
〇)界面效果
①)登录若依管理系统手动添加对应的路由地址和url
②) 前端代码
界面的elementplus标签和script内语法可以参照岗位系统的前端界面post.vue代码。