package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
import cn.ysk.cashier.pojo.shop.TbFullShopId;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author Administrator
* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Mapper
* @createDate 2024-08-08 11:14:32
* @Entity cn.ysk.cashier.mybatis.entity.TbShopOpenId
*/
public interface TbShopOpenIdMapper extends BaseMapper<TbShopOpenId> {

    @Update("update tb_shop_open_id set status=#{state} where shop_id=#{shopId} and status != #{state}")
    int updateShopState(@Param("shopId") Integer shopId, @Param("state") Integer state);

    @Update("update tb_shop_open_id set status=#{state} and shop_id=#{shopId} and id=#{id}")
    int updateStateById(@Param("state") Integer state, @Param("shopId") Integer shopId, @Param("id") Integer id);

    @Update("update tb_shop_open_id set type")
    int updateTypeByShopId(@Param("shopId") Integer shopId, @Param("type") Integer type);

    @Select("<script>" +
            " select *,\n" +
            "        SUM(IF(type = 0, `status`, 0)) AS proState,\n" +
            "        SUM(IF(type = 1, `status`, 0)) AS conState,\n" +
            "        SUM(IF(type = 2, `status`, 0)) AS opeState,\n" +
            "        SUM(IF(type = -1, `status`, 0)) AS allState\n" +
            "        from tb_shop_open_id where shop_id=#{shopId}\n" +
            "        <if test=\"nickName !=null and nickName != ''\">\n" +
            "            and nickname like concat('%', #{nickName} '%')\n" +
            "        </if>\n" +
            "        <if test=\"openId !=null and openId != ''\">\n" +
            "            and open_id like concat('%', #{openId} '%')\n" +
            "        </if>\n" +
            "        group by shop_id, open_id" +
            "</script>")
    Page<TbFullShopId> selectAll(@Param("shopId") Integer shopId, @Param("nickName") String nickName, @Param("openId") String openId, Page<TbFullShopId> page);
}




