package com.ankaibei.workFlow.webadmin.ankaibei.mapper;

import com.ankaibei.workFlow.webadmin.ankaibei.entity.ManHourInfoEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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 javax.transaction.Transactional;
import java.util.Date;
import java.util.Map;

/**
 * @author
 * @version 1.0
 * @description:
 * @date 2022/9/21 15:34
 */
public interface ManHourMapper extends JpaRepository<ManHourInfoEntity, Integer>, JpaSpecificationExecutor<ManHourInfoEntity> {


    @Query(value = "SELECT man.man_id manId,man.project_user projrctUser,man.project_name " +
            "projectName,man.man_hour manHour,man.create_date create_date,man.flow_task_status flowTaskStatus,man.process_instance_id processInstanceId ,man.process_definition_id processDefinitionId " +
            "from man_hour_info man WHERE  1=1 and if( ?1 !='', man.flow_task_status = ?1 , 1=1) and if( ?2 !='', man.create_date >=?2 , 1=1)  and if( ?3 !='', man.end_date <=?3 , 1=1)  order by man.create_date desc "
            ,countQuery = "SELECT count(1) from man_hour_info man WHERE  1=1 and if( ?1 !='', man.flow_task_status = ?1 , 1=1) and if( ?2 !='', man.create_date >=?2 , 1=1)  and if( ?3 !='', man.end_date <=?3 , 1=1)"
            ,nativeQuery = true)
    Page<Map<String,String>>  findManHourAll(Integer flowTaskStatus, Date createDate, String endDate, Pageable page);

    @Transactional
    @Modifying
    @Query(value = "update man_hour_info SET flow_task_status = ?1 WHERE man_id = ?2", nativeQuery = true)
    void updateManHourFlowStatus(String flowTaskStatus, Integer manId);

}
