layui+SSM实现换病床申请具体实现代码
时间: 2023-11-23 16:06:49 浏览: 85
换病床申请功能的实现可以分为以下几个步骤:
1. 定义换病床申请表
```sql
CREATE TABLE `bed_exchange_application` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`patient_id` int(11) NOT NULL COMMENT '患者id',
`old_bed_id` int(11) NOT NULL COMMENT '原病床id',
`new_bed_id` int(11) NOT NULL COMMENT '新病床id',
`reason` varchar(255) NOT NULL COMMENT '申请原因',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态:0-待审核,1-审核通过,2-审核不通过',
`create_time` datetime NOT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='换病床申请表';
```
2. 编写实体类 BedExchangeApplication.java
```java
public class BedExchangeApplication {
private Integer id;
private Integer patientId;
private Integer oldBedId;
private Integer newBedId;
private String reason;
private Integer status;
private Date createTime;
// 省略 getter/setter 方法
}
```
3. 编写 DAO 接口 BedExchangeApplicationDao.java 和对应的 Mapper 文件 BedExchangeApplicationMapper.xml
BedExchangeApplicationDao.java
```java
public interface BedExchangeApplicationDao {
void insert(BedExchangeApplication application);
void updateStatus(@Param("id") Integer id, @Param("status") Integer status);
List<BedExchangeApplication> listByStatus(@Param("status") Integer status);
}
```
BedExchangeApplicationMapper.xml
```xml
<mapper namespace="com.example.dao.BedExchangeApplicationDao">
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
INSERT INTO bed_exchange_application(patient_id, old_bed_id, new_bed_id, reason, status, create_time)
VALUES(#{patientId}, #{oldBedId}, #{newBedId}, #{reason}, #{status}, #{createTime})
</insert>
<update id="updateStatus">
UPDATE bed_exchange_application SET status = #{status} WHERE id = #{id}
</update>
<select id="listByStatus" resultType="com.example.entity.BedExchangeApplication">
SELECT * FROM bed_exchange_application WHERE status = #{status} ORDER BY create_time DESC
</select>
</mapper>
```
4. 编写 Service 接口和实现类 BedExchangeApplicationService.java 和 BedExchangeApplicationServiceImpl.java
BedExchangeApplicationService.java
```java
public interface BedExchangeApplicationService {
void submit(BedExchangeApplication application);
void approve(Integer id);
void reject(Integer id);
List<BedExchangeApplication> listPendingApplications();
}
```
BedExchangeApplicationServiceImpl.java
```java
@Service
public class BedExchangeApplicationServiceImpl implements BedExchangeApplicationService {
@Autowired
private BedExchangeApplicationDao bedExchangeApplicationDao;
@Override
public void submit(BedExchangeApplication application) {
application.setStatus(0); // 设置为待审核状态
application.setCreateTime(new Date());
bedExchangeApplicationDao.insert(application);
}
@Override
public void approve(Integer id) {
bedExchangeApplicationDao.updateStatus(id, 1); // 审核通过,状态为1
}
@Override
public void reject(Integer id) {
bedExchangeApplicationDao.updateStatus(id, 2); // 审核不通过,状态为2
}
@Override
public List<BedExchangeApplication> listPendingApplications() {
return bedExchangeApplicationDao.listByStatus(0); // 查询所有待审核的申请
}
}
```
5. 编写 Controller 类 BedExchangeController.java
```java
@RestController
@RequestMapping("/bed_exchange")
public class BedExchangeController {
@Autowired
private BedExchangeApplicationService bedExchangeApplicationService;
@PostMapping("/submit")
public void submit(@RequestBody BedExchangeApplication application) {
bedExchangeApplicationService.submit(application);
}
@PostMapping("/approve/{id}")
public void approve(@PathVariable("id") Integer id) {
bedExchangeApplicationService.approve(id);
}
@PostMapping("/reject/{id}")
public void reject(@PathVariable("id") Integer id) {
bedExchangeApplicationService.reject(id);
}
@GetMapping("/pending")
public List<BedExchangeApplication> listPendingApplications() {
return bedExchangeApplicationService.listPendingApplications();
}
}
```
以上是基于 layui 和 SSM 框架实现换病床申请功能的详细代码实现。当用户提交换病床申请时,将数据插入到数据库中;当医生审核通过或不通过时,更新相应的状态;当用户查询待审核申请时,查询数据库获取所有状态为 0(待审核)的申请。
阅读全文