On the generators of quantum dynamical semigroups with invariant subalgebras