SSM框架审批功能代码
时间: 2023-11-04 16:46:10 浏览: 91
以下是基于SSM框架的审批功能代码,供参考:
1. 审批流程的数据库设计:
CREATE TABLE `approval` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '审批ID',
`title` varchar(50) NOT NULL COMMENT '审批标题',
`description` varchar(200) DEFAULT NULL COMMENT '审批描述',
`applicant` varchar(20) NOT NULL COMMENT '申请人',
`apply_time` datetime NOT NULL COMMENT '申请时间',
`approver` varchar(20) DEFAULT NULL COMMENT '审批人',
`status` varchar(20) NOT NULL COMMENT '审批状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='审批流程表';
2. 审批流程的DAO接口:
public interface ApprovalDao {
// 新增审批流程
int insertApproval(Approval approval);
// 根据审批ID查询审批流程
Approval selectApprovalById(Integer id);
// 更新审批流程
int updateApproval(Approval approval);
// 查询待审批流程列表
List<Approval> selectPendingApprovals(String approver);
}
3. 审批流程的DAO实现类:
@Repository
public class ApprovalDaoImpl implements ApprovalDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public int insertApproval(Approval approval) {
String sql = "INSERT INTO approval(title, description, applicant, apply_time, status) VALUES (?, ?, ?, ?, ?)";
return jdbcTemplate.update(sql, approval.getTitle(), approval.getDescription(), approval.getApplicant(), approval.getApplyTime(), approval.getStatus());
}
@Override
public Approval selectApprovalById(Integer id) {
String sql = "SELECT * FROM approval WHERE id = ?";
return jdbcTemplate.queryForObject(sql, new Object[]{id}, new BeanPropertyRowMapper<>(Approval.class));
}
@Override
public int updateApproval(Approval approval) {
String sql = "UPDATE approval SET approver = ?, status = ? WHERE id = ?";
return jdbcTemplate.update(sql, approval.getApprover(), approval.getStatus(), approval.getId());
}
@Override
public List<Approval> selectPendingApprovals(String approver) {
String sql = "SELECT * FROM approval WHERE approver = ? AND status = '待审批'";
return jdbcTemplate.query(sql, new Object[]{approver}, new BeanPropertyRowMapper<>(Approval.class));
}
}
4. 审批流程的Service层接口:
public interface ApprovalService {
// 新增审批流程
int addApproval(Approval approval);
// 根据审批ID查询审批流程
Approval getApprovalById(Integer id);
// 更新审批流程
int updateApproval(Approval approval);
// 查询待审批流程列表
List<Approval> getPendingApprovals(String approver);
}
5. 审批流程的Service层实现类:
@Service
public class ApprovalServiceImpl implements ApprovalService {
@Autowired
private ApprovalDao approvalDao;
@Override
public int addApproval(Approval approval) {
return approvalDao.insertApproval(approval);
}
@Override
public Approval getApprovalById(Integer id) {
return approvalDao.selectApprovalById(id);
}
@Override
public int updateApproval(Approval approval) {
return approvalDao.updateApproval(approval);
}
@Override
public List<Approval> getPendingApprovals(String approver) {
return approvalDao.selectPendingApprovals(approver);
}
}
6. 审批流程的Controller:
@Controller
@RequestMapping("/approval")
public class ApprovalController {
@Autowired
private ApprovalService approvalService;
// 跳转到审批页面
@GetMapping("/page")
public String toApprovalPage() {
return "approval";
}
// 提交审批申请
@PostMapping("/add")
@ResponseBody
public String addApproval(Approval approval) {
approval.setApplyTime(new Date());
approval.setStatus("待审批");
int result = approvalService.addApproval(approval);
if (result > 0) {
return "success";
} else {
return "fail";
}
}
// 查询待审批列表
@GetMapping("/pending")
@ResponseBody
public List<Approval> getPendingApprovals(String approver) {
List<Approval> approvalList = approvalService.getPendingApprovals(approver);
return approvalList;
}
// 审批流程
@PostMapping("/approval")
@ResponseBody
public String approval(Approval approval) {
int result = approvalService.updateApproval(approval);
if (result > 0) {
return "success";
} else {
return "fail";
}
}
}
以上就是基于SSM框架的审批功能代码,其中包括审批流程的数据库设计、DAO接口和实现类、Service层接口和实现类以及Controller。需要注意的是,以上代码仅供参考,具体实现需要根据实际情况进行调整。
阅读全文