Work distribution and path integrals in general mean-field systems