4. Find the value of the real number $a$ such that the graph of the function
$$
f(x)=(x+a)(|x-a+1|+|x-3|)-2 x+4 a
$$

is centrally symmetric.
When $x \leqslant \min \{a-1,3\}$,
$$
f(x)=-2 x^{2}-a x+a^{2}+6 a \text {; }
$$

When $x \geqslant \max \{a-1,3\}$,
$$
f(x)=2 x^{2}+(a-4) x-a^{2}+2 a \text {. }
$$

It can be seen that the graph of the function $f(x)$ consists of two parabolic arcs on the left and right sides, and a line segment in the middle. The graph of the function $f(x)$ is a centrally symmetric figure if and only if its center of symmetry is the midpoint $M$ of the middle line segment, and the vertices $A$ and $B$ of the parabolic arcs on the left and right sides are also symmetric about point $M$.
Since $x_{M}=\frac{(a-1)+3}{2}=\frac{a+2}{2}$,
$$
x_{A}=-\frac{a}{4}, x_{B}=-\frac{a-4}{4} \text {, }
$$

Therefore, $\frac{x_{A}+x_{B}}{2}=x_{M}$. Solving this, we get $a=-\frac{2}{3}$.
Upon verification, this satisfies the requirements.