package cn.com.ty.lift.ud.motiontrail.mapper;


import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import cn.com.ty.lift.ud.motiontrail.mapper.entity.MotionTrail;
/**
 * 人员轨迹-Repository
 * 
 * @author Xson
 * @date 2020-07-15
 */
public interface MotionTrailMapper extends BaseMapper<MotionTrail> {

    /**
     * 新增人员位置
     * @param mobile
     * @param mtCompanyId
     * @param position
     * @param createTime
     * @param userId
     * @return
     */
    @Insert("insert motion_trail (mt_company_id,user_id,mobile,position,create_time) values(" +
            "#{mtCompanyId},#{userId},#{mobile},#{position},#{createTime})")
    Integer addTrail(@Param("mobile") String mobile, @Param("mtCompanyId")Long mtCompanyId,
                     @Param("position")String position,@Param("createTime") Date createTime,@Param("userId") Long userId);
    
    @Select("   SELECT * FROM motion_trail WHERE id IN(SELECT MAX(id) FROM motion_trail  WHERE mt_company_id=#{companyId} GROUP BY user_id)")
    List<MotionTrail> queryTrailByTeam(@Param("companyId")Long companyId);
}
