What are the consequences of settlements getting attacked?

Solution 1:

They'll destroy as many structures within the settlement and kill as many people as possible. You'll have the opportunity to repair anything that is broken in Workshop mode:

consequences

Obviously if settlers die, that's final.

For a duration of time, the happiness level of the settlement will also be impacted. This is especially the case if sufficient damage has been caused to the structures of the settlement to cause a shortage in any resources (power, water, food).

Solution 2:

During a raid, the only "structures" you will find damaged are generators, traps, purifiers, etc.

They will not tear down or damage buildings.

They do not raid your workshop, however, they and your settlers could access (steal!) items on the ground or (possibly, heard but never witnessed) items in containers.

Crops will get damaged from explosions...and will need to be repaired immediately upon returning. It matters not if the explosion was friendly fire or not. (There is/was a bug that if you did not repair it, the crop will become unrepairable.) Therefore, avoid giving settlers grenades, molotovs, etc.

All things to repaired is repaired in workshop mode and requires resources available to do so, comparable to what was used to construct the "structure". For instance, repairing a razorgrain crop requires razorgrain, or a tato for a tato plant. Repairing a turret requires the similar materials used during construction like steel, circuits, oil, gears, etc.

After a raid, you can check settlers and see what weapons they picked up. The survivor may have picked up a weapon and ammo thats better than what they had from a dead attacker, fellow settler, or what was loose in the settlement. They may (and I've seen this only once) jump into a suit of power armor if the fusion core is still inserted in the armor. They will not change clothes or armor, however.

Attackers do not prioritize attacks, or have any clever AI scheme. When attacking in number, they will almost always attack from differing angles of approach, which is a de facto feint which means you need to cover multiple directions of attack. They will attempt to destroy targets in that area of approach and move on...they will not try to gang rush through defenses to get to Z.

If there is any priority, they will attack you first, then settlers, and finally "structures". If aggro'd by any attack, they will focus on that.