Example 8 Let $a_{i} \in \mathbf{R}^{+}(i=1,2, \cdots, n)$, if for any $x_{i} \geqslant 0$,
$$\sum_{i=1}^{n} r_{i}\left(x_{i}-a_{i}\right) \leqslant \sqrt{\sum_{i=1}^{n} x_{i}^{2}}-\sqrt{\sum_{i=1}^{n} a_{i}^{2}} .$$

Find $r_{i}(i=1,2, \cdots, n)$.
Let $x_{i}=0$, then $\sum_{i=1}^{n} r_{i} a_{i} \geqslant \sqrt{\sum_{i=1}^{n} a_{i}^{2}}$.
Let $x_{i}=2 a_{i}$, then $\sum_{i=1}^{n} r_{i} a_{i} \leqslant \sqrt{\sum_{i=1}^{n} a_{i}^{2}}$.
Thus, $\sum_{i=1}^{n} r_{i} a_{i}=\sqrt{\sum_{i=1}^{n} a_{i}^{2}}$.
Let $x_{i}=r_{i}$, then $\sum_{i=1}^{n} r_{i}\left(r_{i}-a_{i}\right) \leqslant \sqrt{\sum_{i=1}^{n} r_{i}^{2}}-\sqrt{\sum_{i=1}^{n} a_{i}^{2}}$,
which implies
$$\sum_{i=1}^{n} r_{i}^{2} \leqslant \sqrt{\sum_{i=1}^{n} r_{i}^{2}}$$

Thus, $\sum_{i=1}^{n} r_{i}^{2} \leqslant 1$. By the Cauchy-Schwarz inequality, we have
$$\left(\sum_{i=1}^{n} r_{i} a_{i}\right)^{2} \leqslant\left(\sum_{i=1}^{n} r_{i}^{2}\right)\left(\sum_{i=1}^{n} a_{i}^{2}\right)$$

The equality holds if and only if $r_{i}=\lambda a_{i}$.
Thus, $\sum_{i=1}^{n} r_{i}^{2} \geqslant 1$, so
$$\sum_{i=1}^{n} r_{i}^{2}=1, \lambda=\frac{1}{\sqrt{\sum_{i=1}^{n} a_{i}^{2}}}, r_{i}=\frac{a_{i}}{\sqrt{\sum_{i=1}^{n} a_{i}^{2}}}$$

Upon verification, $r_{i}=\frac{a_{i}}{\sqrt{\sum_{i=1}^{n} a_{i}^{2}}}(i=1,2, \cdots, n)$ is the solution.
The above conditions can be generalized to:
$$\sum_{i=1}^{n} r_{i}\left(x_{i}-a_{i}\right) \leqslant\left(\sum_{i=1}^{n} x_{i}^{m}\right)^{\frac{1}{m}}-\left(\sum_{i=1}^{n} a_{i}^{m}\right)^{\frac{1}{m}},$$

where $m>1$ is a given constant.
Using Hölder's inequality, we get
$$r_{i}=\left[\frac{a_{i}^{m}}{\sum_{i=1}^{n} a_{i}^{m}}\right]^{\frac{m-1}{m}}(i=1,2, \cdots, n)$$