"China achieved a strategic victory by minimizing the future possibility of a two-front war against the USSR and Vietnam."
http://www.globalsecurity.org/military/world/war/prc-vietnam.htm
The above quote paints for you the very desperate situation back when China was skirmishing with Russian military in the north, and Vietnam in the south. Putting one and one together, it is not hard for China to arrive at the conclusion that something much bigger was afoot.
If "body count" is the only measure of success or failure, then, shall we declare US the victor of the Vietnam War and Russia the victor of the Afghanistan War....?
That the PLA's performance was poor is undoubted. But you must see from the POV of "war being an extension of diplomacy".
Had China had not boldly invaded Vietnam, Russia and Vietnam might have gotten ideas about attacking first. At least this was what China feared.
The invasion took both Vietnam and Russia by surprise and showed a resolve they didn't think China had against such odds.
The invasion also proved conclusively that Russia will not intervene directly in Vietnam's favour. This must have given Vietnam a lot of second thoughts about its neat little arrangements with Russia.
"Beijing's policy was actually a diplomatic success, since Moscow did not actively intervene, thus showing the practical limitations of the Soviet-Vietnamese military pact."
http://www.globalsecurity.org/military/world/war/prc-vietnam.htm
In other words, a bad invasion was better than if China had just sat on its hands doing fxxkall. It eliminated any further thoughts of a combined pact against China. Instead it put Vietnam on the defensive.
No matter how badly China did in the 1979 invasion, Vietnam clearly will not want to invite another invasion, will they? And they did not introduce any foreign powers into the border region to cause further aggravation.
Therefore, I qualify Vietnam as a "buffer" for China against foreign powers. They only have to maintain the status quo there. China is clearly in no danger of being invaded by Vietnam. And as tension continue to ease, each side can reduce the number of divisions stationed there.