package com.muyu.enterprise.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.muyu.domain.FenceGroup;
import com.muyu.domain.req.FenceGroupReq;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 围栏组Mapper接口
 *
 * @author muyu
 * @date 2024-09-19
 */
@Mapper
public interface FencegroupMapper extends MPJBaseMapper<FenceGroup> {


    /*
     * 展示围栏组信息
     * @param req
     * @return
     */
    @Select("SELECT g.fence_group_id,g.group_type,g.priority,g.`status`,f.fence_id, group_CONCAT( f.fence_name ) AS fence_name FROM fence_group g LEFT JOIN middle m ON m.fence_group_id = g.fence_group_id LEFT JOIN fence f ON m.fence_id = f.fence_id GROUP BY g.fence_group_id")
    List<FenceGroup> showGroupList(FenceGroupReq req);

//    @Insert("INSERT INTO `vehicle-basic`.`middle` (`fence_id`, `fence_group_id`) VALUES <foreach collection='fenceIds' item='id' separator=','>  (#{id},#{fenceGroupId}) </foreach>")
//    @Insert({ "<script>", "INSERT INTO user_role (user_id, role_id) VALUES ", "<foreach collection='roleIds' item='roleId' separator=','>", "(#{userId}, #{roleId})", "</foreach>", "</script>" })
    @Insert({
            "<script>",
            "INSERT INTO `vehicle-basic`.`middle` (fence_id, fence_group_id) VALUES ",
            "<foreach collection='fenceIds' item='id' separator=','>",
            "(#{id}, #{fenceGroupId})",
            "</foreach>",
            "</script>"
    })
    void addMiddle(@Param("fenceIds") Integer[] fenceIds,@Param("fenceGroupId") Long fenceGroupId);

}
