Chemicals of emerging concern (CEC) in pig farm breeding wastewater, such as antibiotics, will soon pose a serious threat to public health. It is therefore essential to consider improving the treatment efficiency of piggery wastewater in terms of microorganisms. In order to optimize the overall piggery wastewater treatment system from the perspective of the bacterial community structure and its response to environmental factors, five samples were randomly taken from each area of a piggery’s wastewater treatment system using a random sampling method. The bacterial communities’ composition and their correlation with wastewater quality were then analyzed using Illumina MiSeq high-throughput sequencing. The results showed that the bacterial community composition of each treatment unit was similar. However, differences in abundance were significant, and the bacterial community structure gradually changed with the process. Proteobacteria showed more adaptability to an anaerobic environment than Firmicutes, and the abundance of Tissierella in anaerobic zones was low. The abundance of Clostridial (39.02%) and Bacteroides (20.6%) in the inlet was significantly higher than it was in the aerobic zone and the anoxic zone (p < 0.05). Rhodocyclaceae is a key functional microbial group in a wastewater treatment system, and it is a dominant microbial group in activated sludge. Redundancy analysis (RDA) showed that chemical oxygen demand (COD) had the greatest impact on bacterial community structure. Total phosphorus (TP), total nitrogen (TN), PH and COD contents were significantly negatively correlated with Sphingobacteriia, Betaproteobacteria and Gammaproteobacteria, and significantly positively correlated with Bacteroidia and Clostridia. These results offer basic data and theoretical support for optimizing livestock wastewater treatment systems using bacterial community structures.