controller:

    1. @RequestMapping(value = "/reProcessSubmitList", method = RequestMethod.POST)
    2. @ApiOperation("批量提交")
    3. public ObjectRestResponse batchAuitByMq(@Validated @RequestBody Td51CustRiskUpdateDTO td51CustRiskUpdateDTO) throws Exception {
    4. ObjectRestResponse objectRestResponse = null;
    5. //批量提交
    6. String message = "";
    7. boolean locked = false;
    8. String value = UUID.randomUUID().toString();
    9. try{
    10. locked = redisDistributedLocker.tryLock(TASK_KEY_EXTRACTHALF+"_"+orgKey, value, 30, TimeUnit.MINUTES);
    11. if (!locked) {
    12. throw new BusinessException("正在执行一键提交,请勿重复点击!");
    13. }else{
    14. message = custRiskProcessService.batchAuitByMq(td51CustRiskUpdateDTO);
    15. }
    16. }catch(Exception e){
    17. log.error("批量提交错误,{}",e);
    18. }finally {
    19. if (locked) {
    20. log.info("删除批量提交redis锁开始key===" + TASK_KEY_EXTRACTHALF);
    21. redisDistributedLocker.releaseLock(TASK_KEY_EXTRACTHALF+"_"+orgKey, value);
    22. log.info("删除批量提交redis锁结束key===" + TASK_KEY_EXTRACTHALF);
    23. }
    24. }
    25. objectRestResponse = new ObjectRestResponse(HttpStatus.HTTP_OK, "评级结果开始一键提交", message);
    26. return objectRestResponse;
    27. }

    service层:

    1. @Override
    2. public String batchAuitByMq(Td51CustRiskUpdateDTO td51CustRiskUpdateDTO) {
    3. String message = "";
    4. /**
    5. * 判断是否重置批量任务进度
    6. */
    7. if (ObjectUtil.isNotNull(td51CustRiskUpdateDTO)) {
    8. Long resultCount = selectTd51CustRiskPageCount(td51CustRiskPageDTO);
    9. if (resultCount != null && resultCount > 0) {
    10. Long resultNum = td51CustRiskProcessMapper.selectTd51CustRiskPageCount(td51CustRiskPageDTO);
    11. if (resultNum != null && resultNum > 0) {
    12. message = "风险事件处理初审与复核不能是同一人操作!";
    13. } else {
    14. message = "正在进行一键提交,请稍后";
    15. }
    16. } else {
    17. message = "没有符合条件的客户信息需要批量处理!";
    18. return message;
    19. }
    20. td51CustRiskPageDTO.setAuditUser("");
    21. //另起线程进行数据处理。
    22. new CustRiskProcessServiceImpl.MyThread(userInfo, td51CustRiskPageDTO, hierarchy) {
    23. @Override
    24. public void run() {
    25. try {
    26. //数据提交
    27. batchSubmit(resultCount, td51CustRiskPageDTO,td51CustRiskUpdateDTO);
    28. } catch (Exception e) {
    29. log.error("一键提交失败,错误信息为,{}", e);
    30. //如果报错删除td54BatchSchedule表中此机构的数据,让其可以再次提交
    31. td54BatchScheduleMapper.deleteScheduleByOrgkey(td51CustRiskPageDTO.getOrgKey());
    32. throw new RuntimeException(e);
    33. }
    34. }
    35. }.start();
    36. }
    37. return message;
    38. }