package com.qmth.sop.business.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.reflect.TypeToken;
import com.qmth.sop.business.activiti.service.ActivitiService;
import com.qmth.sop.business.bean.dto.DataPermissionDto;
import com.qmth.sop.business.bean.dto.OrgUserNameDto;
import com.qmth.sop.business.bean.params.FlowApproveParam;
import com.qmth.sop.business.bean.result.*;
import com.qmth.sop.business.entity.*;
import com.qmth.sop.business.mapper.TBDingApplyMapper;
import com.qmth.sop.business.service.*;
import com.qmth.sop.common.contant.SpringContextHolder;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.*;
import com.qmth.sop.common.util.GsonUtil;
import com.qmth.sop.common.util.ServletUtil;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 考勤补卡申请表 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2023-08-01
 */
@Service
public class TBDingApplyServiceImpl extends ServiceImpl<TBDingApplyMapper, TBDingApply> implements TBDingApplyService {

    @Resource
    TFCustomFlowEntityService tfCustomFlowEntityService;

    @Resource
    ActivitiService activitiService;

    @Resource
    TBDingService tbDingService;

    @Resource
    BasicAttachmentService basicAttachmentService;

    @Resource
    TaskService taskService;

    @Resource
    TBDingApplyService tbDingApplyService;

    @Resource
    TBCrmService tbCrmService;

    @Resource
    TBUserArchivesService tbUserArchivesService;

    @Resource
    SysUserService sysUserService;

    @Resource
    SysUserRoleService sysUserRoleService;

    @Resource
    TFFlowApproveService tfFlowApproveService;

    @Resource
    TFFlowLogService tfFlowLogService;

    /**
     * 新增考勤异常补卡申请
     *
     * @param tbDingApply
     * @return
     * @throws InterruptedException
     */
    @Override
    @Transactional
    public Boolean saveDingApply(TBDingApply tbDingApply) throws Exception {
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        TBDing tbDing = tbDingService.getById(tbDingApply.getDingId());
        String sopNo = Objects.nonNull(tbDing) ? tbDing.getSopNo() : tbDingApply.getSopNo();
        String crmNo = Objects.nonNull(tbDing) ? tbDing.getCrmNo() : tbDingApply.getCrmNo();

        int count = tbDingService.findRemainCount(sysUser.getId(), sopNo);
        if (count == 0) {
            throw ExceptionResultEnum.ERROR.exception("该用户剩余补卡次数为0");
        }
        CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(sopNo, crmNo);
        Optional.ofNullable(crmProjectResult).orElseThrow(ExceptionResultEnum.CRM_NO_NO_DATA::exception);

        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId(), sysUser.getId(), sopNo);
        List<String> approveUserIds = new ArrayList<>(sysUserRoleList);
        FlowApproveParam flowApproveParam = new FlowApproveParam(tbDingApply.getFlowDeploymentId(), FlowApprovePassEnum.START, approveUserIds, crmNo);
        flowApproveParam.setApproveRemark(FlowApprovePassEnum.START.getTitle());
        Map<String, Object> map = activitiService.taskApprove(flowApproveParam);
        TFCustomFlowEntity tfCustomFlowEntity = (TFCustomFlowEntity) map.get(SystemConstant.FLOW_ENTITY);
        if (!CollectionUtils.isEmpty(tbDingApply.getAttachmentIdList())) {
            List<BasicAttachment> basicAttachmentList = basicAttachmentService.listByIds(tbDingApply.getAttachmentIdList());
            List<String> paths = new ArrayList<>(basicAttachmentList.size());
            for (BasicAttachment b : basicAttachmentList) {
                paths.add(basicAttachmentService.filePreview(b));
            }
            tbDingApply.setAttachmentPaths(StringUtils.join(paths, ";"));
        }
        tbDingApply.setCode(tfCustomFlowEntity.getCode(), tbDingApply.getAttachmentIdList(), sysUser.getId());
        tfCustomFlowEntity.setObjId(tbDingApply.getId());
        tfCustomFlowEntityService.updateById(tfCustomFlowEntity);
        return tbDingApplyService.save(tbDingApply);
    }

    /**
     * 异常待审核接口
     *
     * @param iPage
     * @param serviceId
     * @param name
     * @param supplierId
     * @param customName
     * @param startTime
     * @param endTime
     * @param applyStartTime
     * @param applyEndTime
     * @return
     */
    @Override
    public IPage<DingApplyUnDoneResult> flowTaskUnDoneList(IPage<Map> iPage, Long serviceId, String name, Long supplierId, String customName, Long startTime, Long endTime, Long applyStartTime, Long applyEndTime) throws Exception {
        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
        if (dpr.getHasThirdPmo()) {
            // 乙方PMO
            Long userSupplierId = requestUser.getSupplierId();
            if (userSupplierId == null || userSupplierId == 0) {
                throw ExceptionResultEnum.ERROR.exception(String.format("请先在用户管理中绑定[%s]对应的供应商",RoleTypeEnum.THIRD_PMO.getDesc()));
            }
            supplierId = userSupplierId;
        }
        IPage<DingApplyUnDoneResult> dingApplyUnDoneResultIPage = this.baseMapper.flowTaskUnDoneList(iPage, serviceId, name, supplierId, customName, startTime, endTime, applyStartTime, applyEndTime, dpr);
        if (Objects.nonNull(dingApplyUnDoneResultIPage) && !CollectionUtils.isEmpty(dingApplyUnDoneResultIPage.getRecords())) {
            for (DingApplyUnDoneResult d : dingApplyUnDoneResultIPage.getRecords()) {
                TFFlowLog tfFlowLog = tfFlowLogService.findByLastFlowLog(d.getFlowId());
                if (Objects.nonNull(tfFlowLog) && Objects.nonNull(tfFlowLog.getPendApproveId())) {
                    List<String> userList = Arrays.asList(tfFlowLog.getPendApproveId().split(SystemConstant.LIST_JOIN_SPLIT));
                    List<OrgUserNameDto> orgUserNameDtoList = sysUserService.findOrgUserName(userList.stream().map(s -> Long.parseLong(s)).collect(Collectors.toList()));
                    List<String> userName = orgUserNameDtoList.stream().map(s -> s.getOrgUserName()).collect(Collectors.toList());
                    d.setApproveUserName(StringUtils.join(userName, SystemConstant.LIST_JOIN_SPLIT));
                }
                String taskIds = d.getTaskIdArray();
                if (Objects.nonNull(taskIds) && taskIds.contains(SystemConstant.LIST_JOIN_SPLIT)) {
                    String[] taskStrs = taskIds.split(SystemConstant.LIST_JOIN_SPLIT);
                    boolean match = false;
                    for (int i = 0; i < taskStrs.length; i++) {
                        Task task = taskService.createTaskQuery().taskId(taskStrs[i]).singleResult();
                        if (task.getAssignee().equals(requestUser.getId().toString())) {
                            d.setTaskId(Long.parseLong(task.getId()));
                            match = true;
                            d.setMyself(true);
                            break;
                        }
                    }
                    if (!match) {
                        d.setTaskId(Long.parseLong(taskStrs[0]));
                    }
                } else if (Objects.nonNull(taskIds)) {
                    Task task = taskService.createTaskQuery().taskId(taskIds).singleResult();
                    if (Objects.nonNull(task.getAssignee()) && task.getAssignee().equals(requestUser.getId().toString())) {
                        d.setMyself(true);
                    } else {
                        List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
                        if (!CollectionUtils.isEmpty(identityLinkList)) {
                            for (IdentityLink i : identityLinkList) {
                                if (i.getUserId().equals(requestUser.getId().toString())) {
                                    d.setMyself(true);
                                }
                            }
                        }
                    }
                    d.setTaskId(Long.parseLong(taskIds));
                }
            }
        }
        return dingApplyUnDoneResultIPage;
    }

    /**
     * 异常已审核接口
     *
     * @param iPage
     * @param serviceId
     * @param name
     * @param supplierId
     * @param dingExceptionApprove
     * @param customName
     * @param startTime
     * @param endTime
     * @param applyStartTime
     * @param applyEndTime
     * @return
     */
    @Override
    public IPage<DingApplyDoneResult> flowTaskDoneList(IPage<Map> iPage, Long serviceId, String name, Long supplierId, DingExceptionApproveEnum dingExceptionApprove, String customName, Long startTime, Long endTime, Long applyStartTime, Long applyEndTime) throws Exception {
        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
        if (dpr.getHasThirdPmo()) {
            // 乙方PMO
            Long userSupplierId = requestUser.getSupplierId();
            if (userSupplierId == null || userSupplierId == 0) {
                throw ExceptionResultEnum.ERROR.exception(String.format("请先在用户管理中绑定[%s]对应的供应商",RoleTypeEnum.THIRD_PMO.getDesc()));
            }
            supplierId = userSupplierId;
        }
        IPage<DingApplyDoneResult> dingApplyDoneResultIPage = this.baseMapper.flowTaskDoneList(iPage, serviceId, name, supplierId, Objects.nonNull(dingExceptionApprove) ? dingExceptionApprove.name() : null, customName, startTime, endTime, applyStartTime, applyEndTime, dpr);
        if (Objects.nonNull(dingApplyDoneResultIPage) && !CollectionUtils.isEmpty(dingApplyDoneResultIPage.getRecords())) {
            for (DingApplyDoneResult d : dingApplyDoneResultIPage.getRecords()) {
                String string = tfFlowLogService.findByLastFlowLogApproveUser(d.getFlowId());
                if (Objects.nonNull(string)) {
                    List<String> userList = Arrays.asList(string.split(SystemConstant.LIST_JOIN_SPLIT));
                    List<OrgUserNameDto> orgUserNameDtoList = sysUserService.findOrgUserName(userList.stream().map(s -> Long.parseLong(s)).collect(Collectors.toList()));
                    List<String> userName = orgUserNameDtoList.stream().map(s -> s.getOrgUserName()).collect(Collectors.toList());
                    d.setApproveUsersName(StringUtils.join(userName, SystemConstant.LIST_JOIN_SPLIT));
                }
                if (Objects.nonNull(d.getApproveInfo())) {
                    String[] strs = d.getApproveInfo().split(";");
                    d.setDingExceptionApprove(strs[0]);
                    d.setApproveTime(Long.parseLong(strs[1]));
                    d.setApproveInfo(null);
                }
            }
        }
        return dingApplyDoneResultIPage;
    }

    /**
     * 考勤异常审核接口
     *
     * @param taskId
     * @param dingExceptionApprove
     * @param userId
     * @return
     * @throws InterruptedException
     */
    @Override
    @Transactional
    public Boolean flowApprove(Long taskId, DingExceptionApproveEnum dingExceptionApprove, Long userId) throws InterruptedException {
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        userId = Objects.nonNull(sysUser) ? sysUser.getId() : userId;
        TBDingApplyService tbDingApplyService = SpringContextHolder.getBean(TBDingApplyService.class);
        return tbDingApplyService.taskApprove(taskId, userId, dingExceptionApprove);
    }

    /**
     * 更新考勤异常打卡时间
     *
     * @param tbDingApply
     * @param dingExceptionApprove
     * @return
     */
    @Override
    @Transactional
    public Boolean updateDingExceptionTime(TBDingApply tbDingApply, DingExceptionApproveEnum dingExceptionApprove) {
        if (dingExceptionApprove == DingExceptionApproveEnum.PASS) {
            TBDing tbDing = tbDingService.getById(tbDingApply.getDingId());
            if (Objects.nonNull(tbDing)) {
                if (tbDingApply.getType() == InOutTypeEnum.IN) {
                    tbDing.setSignInTime(tbDingApply.getApplyTime());
                    tbDing.setSignInAddress("(补卡)");
                } else if (tbDingApply.getType() == InOutTypeEnum.OUT) {
                    tbDing.setSignOutTime(tbDingApply.getApplyTime());
                    tbDing.setSignOutAddress("(补卡)");
                }
                tbDingService.updateById(tbDing);
            } else {
                TBCrm tbCrm = tbCrmService.getOne(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, tbDingApply.getCrmNo()));
                Optional.ofNullable(tbCrm).orElseThrow(ExceptionResultEnum.CRM_NO_NO_DATA::exception);

                SysUser sysUser = sysUserService.getById(tbDingApply.getCreateId());
                Optional.ofNullable(sysUser).orElseThrow(ExceptionResultEnum.USER_NO_EXISTS::exception);

                List<SysRole> sysRoleList = sysUserRoleService.listRoleByUserId(sysUser.getId());
                if (CollectionUtils.isEmpty(sysRoleList)) {
                    throw ExceptionResultEnum.ERROR.exception("用户角色不存在");
                }
                TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, tbDingApply.getSopNo()));
                Optional.ofNullable(tfCustomFlowEntity).orElseThrow(ExceptionResultEnum.FLOW_ENTITY_NO_DATA::exception);

                TBUserArchives tbUserArchives = tbUserArchivesService.getOne(new QueryWrapper<TBUserArchives>().lambda().eq(TBUserArchives::getMobileNumber, sysUser.getMobileNumber()));
                tbDing = new TBDing(tbDingApply.getSopNo(), tbDingApply.getCrmNo(), tbCrm.getServiceId(), tbUserArchives.getId(), sysRoleList.get(0).getType(), sysUser.getId(), tfCustomFlowEntity.getFlowId());
                tbDing.setSignDate(DateFormatUtils.format(tbDingApply.getApplyTime(), SystemConstant.DEFAULT_DATE_DAY_PATTERN));
                tbDing.setSignYear(DateFormatUtils.format(tbDingApply.getApplyTime(), SystemConstant.DEFAULT_DATE_YEAR_PATTERN));
                if (tbDingApply.getType() == InOutTypeEnum.IN) {
                    tbDing.setSignInTime(tbDingApply.getApplyTime());
                    tbDing.setSignInAddress("(补卡)");
                } else if (tbDingApply.getType() == InOutTypeEnum.OUT) {
                    tbDing.setSignOutTime(tbDingApply.getApplyTime());
                    tbDing.setSignOutAddress("(补卡)");
                }
                tbDingService.save(tbDing);
                tbDingApply.setDingId(tbDing.getId());
            }
        }
        tbDingApply.setApprove(dingExceptionApprove);
        return tbDingApplyService.updateById(tbDingApply);
    }

    /**
     * 考勤异常审核接口
     *
     * @param taskIds
     * @param dingExceptionApprove
     * @param userId
     * @return
     * @throws InterruptedException
     */
    @Override
    @Transactional
    public Boolean flowBatchApprove(List<Long> taskIds, DingExceptionApproveEnum dingExceptionApprove, Long userId) throws InterruptedException {
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        userId = Objects.nonNull(sysUser) ? sysUser.getId() : userId;
        TBDingApplyService tbDingApplyService = SpringContextHolder.getBean(TBDingApplyService.class);
        for (Long l : taskIds) {
            tbDingApplyService.taskApprove(l, userId, dingExceptionApprove);
        }
        return true;
    }

    /**
     * 审批公用方法
     *
     * @param taskId
     * @param userId
     * @param dingExceptionApprove
     * @return
     * @throws InterruptedException
     */
    @Override
    public Boolean taskApprove(Long taskId, Long userId, DingExceptionApproveEnum dingExceptionApprove) throws InterruptedException {
        Optional.ofNullable(taskId).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_ID_IS_NULL.exception());

        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        Task task = taskService.createTaskQuery().taskId(String.valueOf(taskId)).singleResult();
        Optional.ofNullable(task).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());

        List<String> taskApproveUserList = activitiService.getTaskApprove(task);
        if (!CollectionUtils.isEmpty(taskApproveUserList) && !taskApproveUserList.contains(sysUser.getId().toString())) {
            throw ExceptionResultEnum.FLOW_DATA_NOT_ME.exception();
        }

        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, Long.parseLong(task.getProcessInstanceId())));
        Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());

        TBDingApply tbDingApply = this.getOne(new QueryWrapper<TBDingApply>().lambda().eq(TBDingApply::getDingExceptionNo, tfCustomFlowEntity.getCode()));
        Optional.ofNullable(tbDingApply).orElseThrow(() -> ExceptionResultEnum.DING_APPLY_NO_DATA.exception());

        CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(tfCustomFlowEntity.getCode(), tfCustomFlowEntity.getCrmNo());
        Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
        Optional.ofNullable(crmProjectResult.getRegionCoordinatorId()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("crm区域协调人数据为空"));

        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId(), tbDingApply.getCreateId(), tbDingApply.getSopNo());
        List<String> approveUserIds = new ArrayList<>();
        approveUserIds.addAll(sysUserRoleList);
        activitiService.taskApprove(new FlowApproveParam(taskId, FlowApprovePassEnum.PASS, approveUserIds, tfCustomFlowEntity.getCrmNo(), dingExceptionApprove.getTitle()));

        TBDingApplyService tbDingApplyService = SpringContextHolder.getBean(TBDingApplyService.class);
        return tbDingApplyService.updateDingExceptionTime(tbDingApply, dingExceptionApprove);
    }

    /**
     * 考勤异常申请详情接口
     *
     * @param id
     * @return
     */
    @Override
    public TBDingApplyViewResult view(Long id) {
        TBDingApply tbDingApply = this.getById(id);
        Optional.ofNullable(tbDingApply).orElseThrow(() -> ExceptionResultEnum.DING_APPLY_NO_DATA.exception());

        CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(tbDingApply.getSopNo(), tbDingApply.getCrmNo());
        Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());

        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getCode, tbDingApply.getDingExceptionNo()));
        Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());

        //获取当前流程节点
        TFFlowApprove tfFlowApprove = tfFlowApproveService.getOne(new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, tfCustomFlowEntity.getFlowId()));
        Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());

        FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
        LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
        FlowTaskResult currFlowTaskResult = null;
        List<FlowTaskResult> flowTaskHistoryList = null;
        List<Long> taskIdList = null;

        //获取流程审批历史
        List<TFFlowViewLogResult> flowApproveHistoryList = null;
        Map<Integer, Integer> approveSetupMap = new HashMap<>();
        List<TFFlowLogResult> tfFlowLogResultList = tfFlowLogService.findByObjectId(tfCustomFlowEntity.getId());
        if (!CollectionUtils.isEmpty(tfFlowLogResultList)) {
            flowApproveHistoryList = GsonUtil.fromJson(GsonUtil.toJson(tfFlowLogResultList), new TypeToken<List<TFFlowViewLogResult>>() {
            }.getType());
            for (TFFlowViewLogResult t : flowApproveHistoryList) {
                t.setMessageType(FlowMsgTypeEnum.STANDARD);
                approveSetupMap.put(t.getApproveSetup(), t.getApproveSetup());
                if (Objects.nonNull(t.getApproveOperation())) {
                    t.setApproveRemark(t.getApproveOperation().getTitle());
                }
            }
        }
        for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
            FlowTaskResult flowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
            if (flowTaskResult.getSetup() > 0) {
                //正在审批的表单
                if (Objects.nonNull(tfFlowApprove.getSetup()) && flowTaskResult.getSetup().intValue() == tfFlowApprove.getSetup().intValue()) {
                    currFlowTaskResult = flowTaskResult;
                    List<Task> taskList = taskService.createTaskQuery().processInstanceId(String.valueOf(tfCustomFlowEntity.getFlowId())).list();
                    if (!CollectionUtils.isEmpty(taskList)) {
                        taskIdList = taskList.stream().map(s -> Long.parseLong(s.getId())).collect(Collectors.toList());
                    }
                } else if (approveSetupMap.containsKey(flowTaskResult.getSetup())) {//已经审批过的表单
                    flowTaskHistoryList = CollectionUtils.isEmpty(flowTaskHistoryList) ? new ArrayList<>(approveSetupMap.size()) : flowTaskHistoryList;
                    flowTaskHistoryList.add(flowTaskResult);
                }
            }
        }
        TFFlowLog tfFlowLog = tfFlowLogService.findByLastFlowLog(tfFlowApprove.getFlowId());
        if (Objects.nonNull(tfFlowLog) && Objects.nonNull(tfFlowLog.getPendApproveId())) {
            List<String> userList = Arrays.asList(tfFlowLog.getPendApproveId().split(SystemConstant.LIST_JOIN_SPLIT));
            List<OrgUserNameDto> orgUserNameDtoList = sysUserService.findOrgUserName(userList.stream().map(s -> Long.parseLong(s)).collect(Collectors.toList()));
            List<String> userName = orgUserNameDtoList.stream().map(s -> s.getOrgUserName()).collect(Collectors.toList());
            tbDingApply.setApproveUserName(StringUtils.join(userName, SystemConstant.LIST_JOIN_SPLIT));
        }
        TBDing tbDing = tbDingService.getById(tbDingApply.getDingId());
        if (Objects.nonNull(tbDing)) {
            tbDingApply.setExceptionTime(tbDing.getSignDate());
        }
        return new TBDingApplyViewResult(crmProjectResult, tbDingApply, taskIdList, flowTaskHistoryList, currFlowTaskResult, flowApproveHistoryList);
    }
}
