package com.bofeng.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.bofeng.entity.QzTask;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface QzTaskDao extends BaseMapper<QzTask> {

    List<QzTask> selectAll(Long uptownId);

    QzTask queryByTaskId(Long taskId);

    List<QzTask> queryByHouseNumber(@Param("houseNumber") String houseNumber, @Param("status") Integer status);

    Integer updateStatusById(@Param("taskId") Long taskId, @Param("status") Integer status);

    List<QzTask> queryQzTaskByStatus(@Param("taskStatus") Integer taskStatus);

    List<QzTask> queryQzTask(@Param("taskStatus") Integer taskStatus, @Param("taskTitle") String taskTitle, @Param("userId") Long userId);

    //当前用户名称
    QzTask selectUserName(@Param("userId") Long userId);

    //当前用户门牌id 门牌号
    QzTask selectHome(@Param("userId") Long userId);

    // todo 当用户是物业角色时的role_id尚未确认
    @Select("SELECT task_status,count(1) as num from qz_task a \n" +
            "inner join sys_uptown_house b on b.house_id=a.house_id\n" +
            "inner join sys_uptown_unit c on c.unit_id=b.unit_id\n" +
            "inner join sys_uptown d on d.uptown_id=c.uptown_id\n" +
            //"where d.uptown_id=#{uptownId} and DATE_FORMAT(a.time_create,'%Y-%m-%d')=#{queryDate}\n" +
            //"where \n" +
            //"d.uptown_id in (select property_id from sys_user_role where role_id=4 and user_id=#{userId})\n" +
            "group by task_status")
    List<Map> queryUserHelpAnaly(@Param("userId") Long userId, @Param("queryDate") String queryDate);

}