/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.dm.informationApproval.repository;

import me.zhengjie.modules.dm.informationApproval.domain.DmInformationApproval;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://el-admin.vip
* @author xwx
* @date 2021-04-23
**/
public interface DmInformationApprovalRepository extends JpaRepository<DmInformationApproval, Long>, JpaSpecificationExecutor<DmInformationApproval> {

    /**
     * todo 修改审批人
     */
    @Modifying
    @Query(value = "update dm_information_approval set approval_user = ?1 where request_id = ?2",nativeQuery = true)
    void editApprovalUser(String approvalUser,Long requestId);

    /**
     * todo 重置
     * @param infoId
     */
    @Modifying
    @Query(value = "update dm_information_approval set status = '00',approval_remark = ''  where is_new = '1' and  info_id = ?1",nativeQuery = true)
    void reset(Long infoId);

    /**
     * todo 刷新任务信息
     */
    @Modifying
    @Query(value = "update dm_information_approval set task_id = ?3 , proc_inst_id=?4  where is_new = '1' and  info_id = ?1 and approval_user = ?2 ",nativeQuery = true)
    void resetTask(Long infoId,String approvalUser,String taskId,String procInstId);

    @Query(value="select * from dm_information_approval where info_id = ?1 and  approval_user = ?2 and is_new = '1' ",nativeQuery = true)
    List<DmInformationApproval> findInfoByReqAndUser(Long infoId, String approvalUser);



}