package cn.com.ty.lift.business.maintenance.dao.mapper;


import cn.com.ty.lift.business.maintenance.dao.third.MaintenanceTask;
import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceRecord;
import cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceCount;
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest;
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest;
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.ScanRecordRequest;
import cn.com.ty.lift.business.maintenance.dao.entity.model.response.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * MyBatis Mapper 接口 - 表：maintenance_record
 * @author bieao
 * @since 2019-12-12 11:27:30
 */
public interface MaintenanceRecordMapper extends BaseMapper<MaintenanceRecord> {

    /**
     * @param request 公司id和电梯id
     * @return MaintenanceRecordResponse 保养信息
     * @description 根据公司id和电梯id查询上次保养信息
     * @date 2020/1/6 5:37 下午
     */
    MaintenanceRecordResponse findRecordByCompanyId(@Param("request") MaintenanceRecordRequest request);

    /**
     * @param request 用户id和维保状态
     * @return RestResponse 保养任务列表
     * @description 根据用户id和维保状态查询保养任务列表
     * @date 2020/4/24 5:03 下午
     */
    IPage<MaintenanceAppResponse> findRecordByWorkerId(IPage<MaintenancePlanResponse> page, @Param("request") MaintenanceRecordRequest request);

    /**
     * @param request 用户id
     * @return RestResponse 保养任务列表
     * @description 根据用户id查询保养任务列表
     * @date 2020/4/24 5:03 下午
     */
    List<MaintenanceCount> countRecordByWorkerId(@Param("request") MaintenanceRecordRequest request);

    /**
     * 根据电梯id和维保状态是完成的查询保养任务列表
     * @param request 用户id和维保状态
     * @return RestResponse 保养任务列表
     */
    IPage<ScanRecordResponse> findRecordByLiftId(IPage<ScanRecordResponse> page, @Param("request") ScanRecordRequest request);

    /**
     * @param request 公司id和电梯id
     * @return MaintenanceRecordResponse 项目信息
     * @description 根据公司id和电梯id项目名称、项目id、电梯位置
     * @date 2020/3/9 11:59 上午
     */
    MaintenanceRecordResponse findProjectByCompanyId(@Param("request") MaintenanceRecordRequest request);

    IPage<MtRecordResponse> pageRecordByCondition(IPage<MtRecordResponse> page, @Param("cond") MtRecordRequest request);

    long countRecordByCondition(@Param("cond") MtRecordRequest request);

    MtRecordResponse infoById(@Param("cond") MtRecordRequest request);

    List<MtRecordResponse> listByIds(MtRecordRequest request);

    IPage<MtRecordResponse> pageByLift(IPage<MtRecordResponse> page, @Param("cond") MtRecordRequest request);

    MaintenanceTask queryMaintenanceTask(@Param("mtCompanyId") Long mtCompanyId,@Param("liftId") Long liftId);

    @Select("SELECT img_url FROM mt_record_img WHERE mt_record_id = #{recordId}")
    List<String> getMaintenanceRecordUrl(Long recordId);

    @Select("SELECT code FROM lift_certificate WHERE owner_id = #{workerId1}")
    String getCardId(Long workerId1);

    @Select("SELECT value FROM global_set WHERE code = 'workLift' AND company_id = #{mtCompanyId}")
    String getGlobalSet(Long mtCompanyId);
}