上节课我们在前端页面看到了表格中的报销申请分页数据,即便设置上查询条件也能正常查询出数据。那么接下来我们应该去做CRUD中的添加功能,也就是创建报销申请。报销申请是需要领导审批的,因此需要我们写异步线程任务类,调用工作流项目,创建审批报销申请的工作流实例。
TbUserDao
类中的searchUserInfo()
、searchDeptManagerId()
、searchGmId()
方法,我们在创建会议申请的时候就调用过,所以这些DAO方法我们不用管。
在TbReimDao.xml
文件中,定义更新报销记录instance_id
字段值的SQL语句。
<update id="updateReimInstanceId" parameterType="HashMap"> UPDATE tb_reim SET instance_id = #{instanceId} WHERE id = #{id} </update>
代码块预览 复制
- 1
- 2
- 3
- 4
- 5
在TbReimDao.java
接口中,声明DAO方法。
public interface TbReimDao { …… public int updateReimInstanceId(HashMap param); }
代码块预览 复制
- 1
- 2
- 3
- 4
创建报销申请,既要向tb_reim
表保存数据,还要创建工作流实例,所以我们先把异步线程任务类创建出来,调用工作流项目的Web方法。
URI路径:/workflow/startReimProcess
序号 | 参数 | 类型 | 含义 |
---|---|---|---|
1 | url | String | 接收审批结果的URL地址 |
2 | creatorId | String | 申请人userId |
3 | creatorName | String | 申请人姓名 |
4 | code | String | 慕课网授权字符串 |
5 | tcode | String | 课程授权字符串 |
6 | title | String | 报销申请标题 |
7 | managerId | int | 部门经理的userId |
8 | gmId | int | 总经理的userId |
在com.example.emos.api.task
包中创建ReimWorkflowTask.java
类,代码如下:
@Component @Slf4j public class ReimWorkflowTask { @Value("${emos.code}") private String code; @Value("${emos.tcode}") private String tcode; @Value("${workflow.url}") private String workflow; @Value("${emos.recieveNotify}") private String recieveNotify; @Autowired private TbUserDao userDao; @Autowired private TbReimDao reimDao; @Async("AsyncTaskExecutor") public void startReimWorkflow(int id, int creatorId) { HashMap info = userDao.searchUserInfo(creatorId); JSONObject json = new JSONObject(); json.set("url", recieveNotify); json.set("creatorId", creatorId); json.set("creatorName", info.get("name").toString()); json.set("code", code); json.set("tcode", tcode); json.set("title", info.get("dept").toString() + info.get("name").toString() + "的报销"); Integer managerId = userDao.searchDeptManagerId(creatorId); json.set("managerId", managerId); Integer gmId = userDao.searchGmId(); json.set("gmId", gmId); String url = workflow + "/workflow/startReimProcess"; HttpResponse resp = HttpRequest.post(url).header("Content-Type", "application/json") .body(json.toString()).execute(); if (resp.getStatus() == 200) { json = JSONUtil.parseObj(resp.body()); String instanceId = json.getStr("instanceId"); HashMap param = new HashMap(); param.put("id", id); param.put("instanceId", instanceId); int rows = reimDao.updateReimInstanceId(param); if (rows != 1) { throw new EmosException("保存报销申请工作流实例ID失败"); } } else { log.error(resp.body()); } } }
代码块预览 复制
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54