修复驳回是,选择跨节点驳回无法撤回钉钉待办任务问题

This commit is contained in:
wulin 2021-03-15 14:27:12 +08:00
parent 1a8c3f913f
commit 1da0560585
12 changed files with 127 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.flow.model.FlowModel;
import com.lz.modules.flow.service.RecordAuthService;
import com.lz.modules.flow.service.StaffRoleService;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.sys.dao.SysUserDao;
import com.lz.modules.sys.entity.app.ResultDetail;
import com.lz.modules.sys.entity.app.ResultRecord;
@ -35,12 +36,17 @@ import com.lz.modules.sys.service.SysUserService;
import com.lz.modules.sys.service.app.ResultDetailService;
import com.lz.modules.sys.service.app.ResultRecordService;
import com.lz.modules.third.entity.ThirdAppConfig;
import com.lz.modules.third.entity.ThirdMsgSendRecord;
import com.lz.modules.third.service.ThirdAppConfigService;
import com.lz.modules.third.service.ThirdMsgSendRecordService;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
@ -81,6 +87,17 @@ public class TestController {
@Autowired
private IEquipmentInfoService equipmentInfoService;
@Autowired
private DingTalkUtil dingTalkUtil;
@Autowired
private ThirdAppConfigService thirdAppConfigService;
@Autowired
private ThirdMsgSendRecordService thirdMsgSendRecordService;
@Value("${dingtalk.appid}")
private String appid;
@RequestMapping("/test/xx")
public void test() {
ResultRecord resultRecord = new ResultRecord();
@ -90,6 +107,16 @@ public class TestController {
resultRecordService.insertResultRecord(resultRecord);
}
@GetMapping("/test/cleanMSG")
public void cleanMSG(@RequestParam Long id) {
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig);
if(token != null && token.length() > 0){
ThirdMsgSendRecord thirdMsgSendRecord = thirdMsgSendRecordService.selectThirdMsgSendRecordById(id);
dingTalkUtil.updateWorkMSG(thirdMsgSendRecord, token);
}
}
@RequestMapping("/test/department")
public void department() {

View File

@ -2,6 +2,7 @@ package com.lz.modules.app.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lz.modules.flow.entity.FlowRecord;
import com.lz.modules.flow.entity.FlowStart;
import com.lz.modules.sys.entity.app.ResultRecord;
import lombok.Data;
@ -54,6 +55,8 @@ public class StaffSimpleInfo implements Serializable {
private FlowStart flowStart;
//当前操作的流程id
private Long flowRecordId;
//当前操作flowRecord
private FlowRecord flowRecord;

View File

@ -111,4 +111,8 @@ public interface FlowRecordMapper extends BaseMapper<FlowRecord> {
List<FlowRecord> selectFlowRecordByRecordIdsStatus(@Param("recordIds") List<Long> recordIds, @Param("status") int status);
List<FlowRecord> selectFlowRecordByRecordIdsFlowProcessAndStatus(List<Long> recordIds, Long flowProcess, int status);
FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndStatus(@Param("recordId") Long recordId, @Param("approvalId") Long approvalId, @Param("status") int status);
FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess(@Param("recordId") Long recordId,@Param("approvalId") Long approvalId, @Param("flowProcess") Integer flowProcess);
}

View File

@ -107,4 +107,10 @@ public interface FlowRecordService extends IService<FlowRecord> {
List<FlowRecord> selectFlowRecordByRecordIdsStatus(List<Long> recordIds, int status);
List<FlowRecord> selectFlowRecordByRecordIdsFlowProcessAndStatus(List<Long> recordIds, Long flowProcess, int status);
FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndStatus(Long recordId, Long approvalId, int status);
FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess(Long workId, Long staffId, Integer flowProcess);
}

View File

@ -281,4 +281,14 @@ public class FlowRecordServiceImpl extends ServiceImpl<FlowRecordMapper, FlowRec
return flowRecordMapper.selectFlowRecordByRecordIdsFlowProcessAndStatus(recordIds, flowProcess, status);
}
@Override
public FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndStatus(Long recordId, Long approvalId, int status){
return flowRecordMapper.selectFlowRecordByRecordIdAndApprovalIdAndStatus(recordId, approvalId, status);
}
@Override
public FlowRecord selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess(Long recordId, Long approvalId, Integer flowProcess){
return flowRecordMapper.selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess(recordId, approvalId, flowProcess);
}
}

View File

@ -879,10 +879,22 @@ public class DingtalkBusiness {
return "error";
}
//流程流转发送消息
public String sendWorkMSGWithAsyn(Long resultRecordId , int type) {
logger.info("流程流转发送消息");
/*public String sendWorkMSGWithAsyn(Long resultRecordId , int type) {
logger.info("流程流转发送消息recordId{}", resultRecordId);
return sendWorkMSGWithAsyn(resultRecordId, 0L, type);
}*/
public String sendWorkMSGWithAsyn(FlowRecord flowRecord , int type) {
logger.info("流程流转发送消息recordId{}", flowRecord);
StaffSimpleInfo fromStaff = staffService.selectStaffSimpleInfo(flowRecord.getApprovalStaffId());//查询来自那里
ResultRecord resultRecord = resultRecordService.selectResultRecordById(flowRecord.getRecordId());
FlowStart flowStart = flowStartService.selectFlowStartById(resultRecord.getStartId());
fromStaff.setFlowStart(flowStart);
fromStaff.setFlowRecord(flowRecord);
fromStaff.setResultRecord(resultRecord);
return sendWorkMSGWithAsyn(fromStaff, null, type);
}
@ -1193,6 +1205,8 @@ public class DingtalkBusiness {
FlowRecord flowRecord = flowRecordService.selectFlowRecordById(fromStaff.getFlowRecordId());//
}else{
logger.info("流程正常流转");
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByRecordIdStatus(fromStaff.getResultRecord().getId(), 2);
//取消上一步骤发送的待办任务
List<FlowRecord> cancelRecords;
@ -1201,7 +1215,30 @@ public class DingtalkBusiness {
cancelRecords = flowRecordService.selectLastFlowRecordsById(fromStaff.getResultRecord().getId());
}else{
if(workMsgTypeEnum.getType() == WorkMsgTypeEnum.REJECT.getType()){//被拒
logger.info("任务驳回");
logger.info("任务驳回 recordId {}", fromStaff.getResultRecord().getId());
//下面的方法主要是为了解决驳回时驳回到指定节点时可能导致的无法取消待办任务的问题
List<ThirdMsgSendRecord> thirdMsgSendRecords =
thirdMsgSendRecordService.selectThirdMsgSendRecordsByRecordId(
fromStaff.getResultRecord().getId(),1, 1);
logger.info("取消本次绩效的最后一条待办任务通知信息,记录条数{}", thirdMsgSendRecords.size());
for (ThirdMsgSendRecord thirdMsgSendRecord:thirdMsgSendRecords
) {
FlowRecord flowRecord =
flowRecordService.selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess(thirdMsgSendRecord.getWorkId(),
thirdMsgSendRecord.getStaffId(), fromStaff.getFlowRecord().getFlowProcess());
logger.info("更新的钉钉消息{} 流程记录信息{}", thirdMsgSendRecord,flowRecord);
if(flowRecord == null || //当前流程节点已处理但是不存在的取消
flowRecord.getType().intValue() == 1 //如果是或签那么都取消
|| (flowRecord.getType().intValue() != 1 &&
flowRecord.getApprovalStaffId().longValue() == fromStaff.getId().longValue())//不是或签但是是操作本人那么取消
){
dingTalkUtil.updateWorkMSG(thirdMsgSendRecord, token);
}
}
cancelRecords = flowRecordService.selectFirstFlowRecordsByIdAndFlowIndex(fromStaff.getResultRecord().getId()
, flowRecords.get(0).getFlowIndex().intValue() + 1, 0);//获取下一步的数据
}else{
@ -1211,6 +1248,7 @@ public class DingtalkBusiness {
}
}
logger.info("查询到可能需要更新的待办任务数量{}", cancelRecords.size());
if(cancelRecords.size() > 0){
int flowIndex = cancelRecords.get(0).getFlowIndex().intValue();

View File

@ -954,7 +954,8 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
private R rejectN(ApprovalDto approvalDto) {
log.info("驳回到前n个节点 " + JSON.toJSONString(approvalDto));
FlowRecord currFlowRecord =
flowRecordService.selectFlowRecordByRecordIdAndApprovalIdAndStatus(approvalDto.getResultRecordId(), approvalDto.getLoginUserId(), 2);
FlowRecord f = flowRecordService.selectFlowRecordById(approvalDto.getFlowRecordId());
ResultRecord resultRecord = resultRecordService.selectResultRecordById(f.getRecordId());
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByRecordIdGeFlowIndex(f.getRecordId(), f.getFlowIndex());
@ -1000,7 +1001,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
}
}
resultRecordService.resetData(resultRecord.getId(), 2);
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.REJECT.getType());
dingtalkBusiness.sendWorkMSGWithAsyn(currFlowRecord, WorkMsgTypeEnum.REJECT.getType());
return R.ok();
}
@ -1056,7 +1057,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
}
}
resultRecordService.resetData(resultRecord.getId(), 2);
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.RESET.getType());
dingtalkBusiness.sendWorkMSGWithAsyn(f, WorkMsgTypeEnum.RESET.getType());
return R.ok();
}
@ -1097,7 +1098,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
resultRecord.setFlowProcess(0);
resultRecordService.updateResultRecordById(resultRecord);
resultRecordService.resetData(resultRecordId, approvalDto.getClearFlag());
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.RESET.getType());
dingtalkBusiness.sendWorkMSGWithAsyn(flowRecord == null ? flowRecords.get(0):flowRecord, WorkMsgTypeEnum.RESET.getType());
return R.ok();
}
@ -1235,13 +1236,13 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
// 找到当前下一个节点为0的 flowIndex
FlowRecord nextFlowRecord = flowRecordService.selectFlowRecordByRecordIdMinIdStatus(approvalDto.getResultRecordId(), preFlowRecord.getId(), 0);
if (nextFlowRecord == null) {
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.PROCESS.getType()); //流程己经结束调用
dingtalkBusiness.sendWorkMSGWithAsyn(flowRecords.get(0), WorkMsgTypeEnum.PROCESS.getType()); //流程己经结束调用
log.info("流程己经结束2");
return R.ok("流程己经结束");
}
List<FlowRecord> nextFlowRecords = flowRecordService.selectFlowRecordByRecordIdStatusFlowIndex(approvalDto.getResultRecordId(), 0, nextFlowRecord.getFlowIndex());
if (CollectionUtils.isEmpty(nextFlowRecords)) {
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.PROCESS.getType());//流程己经结束调用
dingtalkBusiness.sendWorkMSGWithAsyn(nextFlowRecords.get(0), WorkMsgTypeEnum.PROCESS.getType());//流程己经结束调用
log.info("流程己经结束3");
return R.ok("流程己经结束");
}
@ -1256,7 +1257,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
resultRecord.setCurrentApprovalStaffId(nextFlowRecords.size() == 1 ? currentFlowRecord.getApprovalStaffId() : null);
resultRecord.setCurrentApprovalStaffName(nextFlowRecords.size() == 1 ? currentFlowRecord.getApprovalStaffName() : null);
resultRecordService.updateCoverResultRecordById(resultRecord);
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), WorkMsgTypeEnum.PROCESS.getType());
dingtalkBusiness.sendWorkMSGWithAsyn(currentFlowRecord, WorkMsgTypeEnum.PROCESS.getType());
return R.ok();
}
@ -1291,7 +1292,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
FlowChart flowChart = flowService.selectFlowChartByChartId(lastFlowRecord.getFlowId());
resultRecord.setFlowProcess(flowChart.getFlowProcess());
resultRecordService.updateCoverResultRecordById(resultRecord);
dingtalkBusiness.sendWorkMSGWithAsyn(resultRecord.getId(), new Integer(5).equals(approvalDto.getStatus()) ? WorkMsgTypeEnum.REJECT.getType() : WorkMsgTypeEnum.RECALL.getType());
dingtalkBusiness.sendWorkMSGWithAsyn(currentFlowRecord, new Integer(5).equals(approvalDto.getStatus()) ? WorkMsgTypeEnum.REJECT.getType() : WorkMsgTypeEnum.RECALL.getType());
}
}
return R.ok();

View File

@ -42,4 +42,8 @@ public interface ThirdMsgSendRecordMapper extends BaseMapper<ThirdMsgSendRecord>
List<ThirdMsgSendRecord> selectThirdMsgSendRecordsByRecordIds(@Param("list") List<Long> recordIds,
@Param("type") int type,
@Param("status") int status);
List<ThirdMsgSendRecord> selectThirdMsgSendRecordsByRecordId(@Param("recordId") Long recordId,
@Param("type") int type,
@Param("status") int status);
}

View File

@ -42,4 +42,6 @@ public interface ThirdMsgSendRecordService extends IService<ThirdMsgSendRecord>
ThirdMsgSendRecord selectThirdMsgSendRecordByWorkIdAndStaffIdAndTypeAndStatus(Long workId, Long staffId, int workType, int status);
List<ThirdMsgSendRecord> selectThirdMsgSendRecordsByRecordIds(List<Long> recordIds, int type, int status);
List<ThirdMsgSendRecord> selectThirdMsgSendRecordsByRecordId(Long recordId, int type, int status);
}

View File

@ -102,4 +102,9 @@ public class ThirdMsgSendRecordServiceImpl extends ServiceImpl<ThirdMsgSendRecor
return thirdMsgSendRecordMapper.selectThirdMsgSendRecordsByRecordIds(recordIds, type, status);
}
@Override
public List<ThirdMsgSendRecord> selectThirdMsgSendRecordsByRecordId(Long recordId, int type, int status){
return thirdMsgSendRecordMapper.selectThirdMsgSendRecordsByRecordId(recordId, type, status);
}
}

View File

@ -394,5 +394,17 @@
</select>
<select id="selectFlowRecordByRecordIdAndApprovalIdAndStatus" resultType="com.lz.modules.flow.entity.FlowRecord">
select * from lz_flow_record where is_delete = 0
and record_id = #{recordId} and approval_staff_id = #{approvalId} and status = #{status}
</select>
<select id="selectFlowRecordByRecordIdAndApprovalIdAndFlowProcess" resultType="com.lz.modules.flow.entity.FlowRecord">
select * from lz_flow_record where is_delete = 0
and record_id = #{recordId} and approval_staff_id = #{approvalId} and flow_process = #{flowProcess} limit 1
</select>
</mapper>

View File

@ -201,5 +201,9 @@
)
</select>
<select id="selectThirdMsgSendRecordsByRecordId" resultType="ThirdMsgSendRecord" >
select * from third_msg_send_record where status=#{status} and is_delete = 0 and work_type = #{type} and work_id = #{recordId}
</select>
</mapper>