1 Introduction

Most large-scale farms in China commonly use biogas engineering to treat faecal sewage, but this method also generates large amounts of biogas slurry and residue. Effectively disposing of these digestates is a problem that plagues farmers. There are two traditional treatment methods: one is to apply these digestates to farmland, and the other is to use advanced treatment to meet discharge standards. If digestates are applied to farmland, a large amount of farmland is needed to completely degrade the high-concentration pollutants contained therein. In particular, current planting and breeding practices are severely disconnected, and there is not enough farmland around pig farms to accommodate and degrade pollutants (Hu et al. 2017; Yi et al. 2017; Zhang et al. 2019). If advanced treatment is used to bring discharge up to the standard, the treatment cost is high, and large amounts of NH4+-N and PO43−-P resources in digestates are wasted. Nitrogen (N) and phosphorus (P) are indispensable elements for living organisms, and phosphorus is a nonrenewable resource (Zhang et al. 2020) that could be depleted in the next few decades (Cooper et al. 2011; Liu et al. 2020). Therefore, the efficient recovery of NH4+-N and PO43−-P nutrients in piggery digestates and reductions in piggery waste would reduce treatment costs and improve resource utilization of piggery faecal sewage. This is of profound significance for environmental protection and waste resource utilization.

The technologies of NH4+-N and PO43−-P recovery from biogas slurry mainly include biological treatment (Jiao et al. 2011), membrane separation (Rothrock et al. 2013), chemical precipitation (Ichihashi and Hirooka 2012; Lin et al. 2017), and electrolytic adsorption (Sarkhot et al. 2013). Among these, magnesium ammonium phosphate (MAP) precipitation is considered to be one of the most promising NH4+-N and PO43−-P recovery methods (Wang et al. 2021). While recovering NH4+-N and PO43−-P, MAP precipitation can also produce the valuable slow-release functional fertilizer struvite (Talboys et al. 2016). Relevant studies have shown that the MAP precipitation method can efficiently recover NH4+-N and PO43−-P from piggery biogas slurry. Huang et al. (2016) used Mg3(PO4)2 as the active ingredient and recovered 78.0% of the total nitrogen in piggery biogas slurry. Luo et al. (2019b) provided a MAP precipitation phosphorus source through fermented superphosphate and recovered 61.6% of the phosphorus and 61.5% of the nitrogen in biogas slurry. Similarly, by adding MgCl2 as the magnesium source of MAP precipitation, 65.0% of the phosphorus and 67.0% of the nitrogen in piggery slurry could be recovered (Liu et al. 2011). These results indicate that due to the high ammonia nitrogen concentration in biogas slurry, the molar ratio of Mg:N:P is much greater than 1:1:1. Therefore, when MAP precipitation is used to recover NH4+-N and PO43−-P from piggery biogas slurry, Mg2+ and PO43− in the reaction system are the limiting factors. To increase the recovery of NH4+-N, researchers commonly add phosphorus and magnesium salts as the phosphorus and magnesium sources for MAP precipitation to increase the concentrations of Mg2+ and PO43− in the reaction system. However, these phosphates and magnesium salts are generally pure chemicals with high cost (Huang et al. 2011; Yetilmezsoy and Sapci-Zengin 2009), which limits the application of MAP precipitation technology in piggery wastewater.

Piggery biogas engineering produces a large amount of biogas residue every year. Taking a large-scale piggery with 4000 pigs in Guangdong Province as an example, the accumulation of biogas residue in three years reached 350 tons. Managing these biogas residues is a challenge for every farmer. During anaerobic fermentation of pig manure, most of the phosphorus is deposited in biogas residue. The phosphorus content in biogas residue can reach 2–5% (w/w) (Deng et al. 2015), which constitutes a P-rich waste. Furthermore, biogas residue is rich in carbon, which is ideal for preparing biochar. Therefore, after carbonization, biogas residue biochar (BRC) can be used as the phosphorus source for the MAP reaction; this approach reduces the cost of the phosphorus source and uses biogas residue generated inside the piggery to treat biogas slurry, thereby realizing the in situ treatment concept of "using waste to treat waste". In a previous study, the author used ultrasound to release phosphorus from biogas residue, which improved the NH4+-N and PO43−-P recovery of biogas slurry (Luo et al. 2019a) and verified the feasibility of biogas residue as a phosphorus source. However, the use of BRC made from biogas residue as the phosphorus source for MAP precipitation to improve the efficiency of NH4+-N and PO43−-P recovery from digestates has not been reported. Most relevant studies focused on utilizing biochar to recover ammonia nitrogen and phosphate from wastewater via adsorption process or MAP precipitation process. For example, Xu et al. (2018) used magnesium oxide-loaded sawdust biochar to recover ammonia nitrogen and phosphate from urine. The recovery mechanism mainly involves the reaction of magnesium ions on the magnesium biochar with nitrogen and phosphorus to form struvite. However, the relatively low concentration of phosphate in urine limited the removal efficiency of ammonia nitrogen to only 1% due to the lack of a phosphorus source. Therefore, the use of biochar from biogas residues as a phosphorus source for MAP precipitation in this study is innovative. Regarding the choice of magnesium source, inexpensive and easily available magnesite powder (MP) is a suitable material. Gunay et al. (2008) used MP (mainly MgCO3) as a magnesium source for the treatment of leachate to remove NH4+-N. The ammonia nitrogen recovery reached 91.0%, and the cost of magnesium decreased by approximately 90.0%. In related studies, biochar could adsorb NH4+-N and PO43−-P in wastewater (Saarela et al. 2020). Therefore, in the MAP precipitation process using BRC as a phosphorus source, does functionalized BRC adsorb NH4+-N and PO43−-P in biogas slurry via chemical precipitation and physisorption to realize the simultaneous and coordinated recovery of NH4+-N and PO43−-P from biogas slurry and residue?

In this study, we prepared BRC by carbonizing biogas residue to enrich the phosphorus content. Then, MP and BRC were pretreated with different acids to release Mg2+ and PO43−-P, respectively, for MAP precipitation. Finally, NH4+-N and PO43−-P in the biogas slurry and biogas residue were recovered through MAP precipitation and functionalized BRC adsorption. The effects of different acids, acid leaching times and liquid-to-solid ratios (L/S) of the leaching agent on Mg2+ and PO43−-P release with MP and BRC were studied in acid leaching experiments, and the effects of BRC dosage (before acid leaching), pH and reaction time on the recoveries of NH4+-N and PO43−-P in the MAP reaction were studied. Finally, structural characterizations and composition analyses of the recovered products were carried out to clarify the mechanisms of NH4+-N and PO43−-P recovery. Notably, to the authors’ knowledge, this is the first attempt to use P-rich BRC as a phosphorus source for MAP reactions to achieve efficient nutrient recovery from P-rich biogas slurry, which has rarely been achieved using conventional techniques, as mentioned in previous literature. The main purposes were to reduce external inputs and accelerate the conversion of internal resources; to improve the efficiency of NH4+-N and PO43−-P recovery; and to realize the utility and high value of biogas residue and biogas slurry. From this research perspective, this study is novel and provides an economically feasible and innovative method for the practical application of MAP precipitation technology to nutrient recovery from piggery waste.

2 Materials and methods

2.1 Experimental materials

Biogas slurry was taken from the digested piggery wastewater of the HDPE-covered lagoon digester (base film thickness of 1.5 mm; upper film thickness of 2.5 mm; length*width*depth = 83*30*6 m; residence time of > 60 d) of a pig farm in Qingyuan City. The biogas slurry was passed through a 5 mm sieve to remove large floating particles before use and stored at 4 ℃. Its physical and chemical properties are shown in Table 1. Biogas residue (BR) was also taken from the HDPE-covered lagoon digester of the abovementioned pig farm. After BR was transported to the laboratory, it was air-dried, ground through a 20-mesh sieve and then stored in a sealed bag. The physical and chemical properties of BR were determined, as shown in Table 2. Magnesite powder (MP) was acquired from Boermei Reagent Co., Ltd. in Shenyang City and was ground with a 100-mesh sieve. Table 3 shows the composition of MP, which is mainly composed of MgCO3; and the Mg content was approximately 30%. All reagents used in this experiment were analytical reagents (ARs).

Table 1 Water quality parameters of biogas slurry
Table 2 Basic physical and chemical parameters of biogas residue
Table 3 Basic chemical composition of magnesite powder

2.2 Experimental methods

2.2.1 Preparation and characteristics of BRC

For the preparation process and property analysis of BRC, please refer to Appendix C. As shown in Table A.1, carbonization enriched the C and P contents in biogas residue (Al-Wabel et al. 2013; Li et al. 2016). Element analyses showed that the C content increased from 31.4% in BR to 40.8% in BRC, total phosphorus (TP) increased from 36.7 g/kg in BR to 71.3 g/kg in BRC, and the contents of H, N, and O decreased. Due to the high carbonization temperature used, the decomposition of organic matter was enhanced. During dehydration and decarboxylation, oxygen-containing functional groups lose large amounts of H and O elements (Wang et al. 2013), and a large number of inorganic substances remain. Therefore, the concentrations of C and P increased, and the proportion of ash increased. These results are consistent with the research results of Titiladunayo et al. (2012) and Al-Wabel et al. (2013). After carbonization, BRC was a C-rich and P-rich substance and an ideal source of phosphorus for MAP precipitation. The X-ray diffraction (XRD) patterns for BR and BRC shown in Fig. B.1 demonstrated that the main crystals of BR and BRC were calcite and dolomite, and BR contained a range of amorphous components (which should be organic). In the scanning electron microscopy (SEM) images, BR appeared as clumps, but after carbonization, BRC was loose and porous, which conformed to the structural characteristics seen after carbonization (Antonangelo et al. 2019).

2.2.2 Acid leaching experiments (optimization of leaching agent)

MP and BRC leaching of magnesium and phosphorus: Oxalic acid (OA), citric acid (CA), sulfuric acid (H2SO4), hydrochloric acid (HCl), oxalic acid + sulfuric acid (OA + H2SO4) and oxalic acid + hydrochloric acid (OA + HCl) were used as leaching agents. The H+ concentration was uniformly 1 mol/L. Pure water was used as a control (CK). Please refer to Appendix D for the process of the acid leaching experiment. The liquid-to-solid ratios (L/S) of the leaching agent to MP and BRC were 1:40 and 1:10, respectively. The acid leaching time was 1 h. After acid leaching, the concentrations of PO43−-P, Mg2+ and Ca2+ in the filtrate were determined.

Evaluation of NH4+-N and PO43−-P recoveries of different leaching agents: The filtrate remaining after leaching MP and BRC with the different leaching agents noted above was used as the magnesium source and phosphorus source for MAP precipitation, and biogas slurry was used for MAP precipitation. The efficiencies for the recovery of NH4+-N and PO43−-P were used to determine the best leaching agent. The MAP experimental process is shown in Appendix E. After the reaction, various indicators in the filtrate were measured, and the NH4+-N and PO43−-P recoveries were used to determine the best leaching agent. The precipitated products were collected and dried naturally at room temperature.

Changes in the form of phosphorus in BRC: The Standards, Measurements, and Testing protocol (Gang et al. 2016; He et al. 2004) was used to analyse the changes in the form of phosphorus before and after the leaching of BRC and to determine the main phosphorus forms involved in the reaction.

2.3 Acid leaching experiment (optimization of leaching parameters)

The best leaching agent identified in Sect. 2.2.2 was selected for this acid leaching experiment, which included the following parameters: the L/S of MP to leaching agent was 40, 20, 10, 6.7 and 5; the volume of leaching agent was fixed at 10.0 mL; and the leaching time was 1, 3, 6, 12, 18, 24 and 48 h. Please refer to Appendix D for the leaching process. The optimum leaching time and L/S of MP were determined from the concentrations of Mg2+ and Ca2+ in the filtrate (the concentrations were measured by adding 100 mL of pure water). Then, BRC was leached with filtrate under the following conditions: the L/S of BRC to leaching filtrate was set to 40, 20, 10, 6.7 and 5; the fixed filtrate volume was 10.0 mL; and the leaching time was 1, 3, 6, 12, 18, 24 and 48 h. Please refer to Appendix D for the leaching process. The optimal leaching time and L/S of BRC were determined from the concentrations of PO43−-P, Mg2+ and Ca2+ in the filtrate (the concentrations were measured by adding 100 mL of pure water). Thus, the optimal leaching parameters for MP and BRC were determined.

2.4 Simultaneous recovery of NH4 +-N and PO4 3−-P from biogas slurry

After optimizing the MP and BRC acid leaching parameters, the leaching filtrate was used as the source of phosphorus and magnesium for MAP precipitation and recovery of NH4+-N and PO43−-P from biogas slurry; factors influencing MAP precipitation were explored, including BRC dosage (before acid leaching), pH, and reaction time. Different levels of parameters were established: the dosage of BRC (before acid leaching) was 0.0, 0.25, 0.50, 1.0, 1.5, and 2.0 g/L; the pH was 8.5, 9.0, 9.5, 10.0, and 10.5; and the reaction time was 1, 3, 6, 12, 18, 24, and 48 h. The reaction process is described in Appendix E. After the reaction, various indicators in the filtrate were quantified, and the best conditions were determined from the NH4+-N and PO43—P recoveries. The collected precipitated product was naturally air-dried at room temperature for testing.

2.5 Physical characterization and chemical analyses

A Fourier transform infrared spectroscopy (FTIR) spectrometer (Brook VERTEX80, Germany), a scanning electron microscopy–energy dispersive spectroscopy (SEM–EDX) analyser and an X-ray diffraction (XRD) instrument (Rigaku Ultima IV, Japan) were used to characterize and analyse the components of BRC under different acid leaching treatments before and after NH4+-N and PO43−-P recovery. Differences in the surface morphologies and compositions of different treatment materials were explored to clarify the mechanism by which acid leaching-functionalized BRC recovers NH4+-N and PO43−-P.

3 Analytical methods

All water indicators were measured according to the corresponding standards (Apha 2012). NH4+-N was determined with the Nessler's reagent colorimetric method. The molybdenum blue colorimetric method was used to determine total phosphorus and water-soluble phosphorus. The pH was determined using a PHS-3C precision pH metre (China, Changzhou). For analyses of the basic physical and chemical parameters of biogas residue, refer to the relevant chapters in "Soil Agricultural Chemical Analysis" (Johnson 2010). The concentrations of Mg2+ and Ca2+ were measured with an atomic absorption spectrophotometer. Experimental data were analysed with SPSS software, and Origin 9.0 was used for graphing.

4 Results and discussion

4.1 Acid leaching functionalization releases Mg2+ and PO4 3−-P from MP and BRC

4.1.1 Leaching effect of Mg2+

As shown in Fig. 1A, different acids leached Mg2+ effectively, and 80–90% of the Mg2+ content was leached from MP. CK (H2O) showed almost no leaching of Mg2+. In the acid leaching process, H+ reacted with MgCO3 in MP and BRC to release Mg2+, as shown in Eq. (1). Among organic acids, OA is preferable to CA in terms of the Mg2+ leaching effect. Since OA is the strongest natural organic acid, its acidity is stronger than that of CA (Kootstra et al. 2019; Zeng et al. 2021). At the same H+ concentration, the leaching of Mg2+ by HCl was more efficient than that by H2SO4. The reason is that H2SO4 forms sulfate precipitates when leaching metal ions, which may attach to the surfaces of MP and BRC to inhibit Mg2+ leaching. The chloride in HCl does not form insoluble salts, and thus, more Mg2+ was dissolved. Compared with organic acids, mixed acids (OA + H2SO4, OA + HCl) significantly improved the leaching of Mg2+, and the results were also better than those for inorganic acids. OA + HCl led to the dissolution of Mg2+ after the acid leaching of MP (after-MP) and after the acid leaching of BRC (after-MP-BRC), and the Mg2+ concentrations reached 216 mg/L and 251 mg/L, respectively. The mixture of organic acid and inorganic acid enhanced the acidity over that of a single acid, thereby promoting more effective leaching of Mg2+.

Fig. 1
figure 1

A Effects of different leaching agents on leaching of Mg2+ and Ca2+ by MP and BRC. B Effects of different leaching agents on PO43−-P release from BRC. C Effects of different leaching agents on phosphorus forms. D Effects of different leaching agents on NH4+-N recovery by MAP precipitation. E Effect of different leaching agents on recovery of PO43−-P by MAP precipitation

Figure 1A shows that when Mg2+ was dissolved, Ca2+ was also dissolved. After the acid leaching of BRC, the Ca2+ concentrations obtained with CA, H2SO4, and HCl were higher, 308 mg/L, 137 mg/L and 398 mg/L, respectively. However, the concentrations of Ca2+ in leaching agents containing OA were low, only 3.00 mg/L (OA), 33.6 mg/L (OA + H2SO4) and 29.2 mg/L (OA + HCl). This is because the oxalate ions from OA can form complex precipitates with Ca2+ (Liang et al. 2019) (as shown in Eq. (2) and (3)). The Ksp values for calcium oxalate and calcium sulfate are 2.32 × 10–9 and 4.93 × 10–5 (298.15 K), respectively. Therefore, compared with H2SO4, Ca2+ in the OA system more easily forms calcium oxalate precipitates. Prior studies have shown that a high concentration of Ca2+ in the system inhibits the formation of struvite (Corre et al. 2005). OA + HCl has the advantage of ensuring efficient dissolution of Mg2+ while reducing the concentration of Ca2+ in the system, and thus, OA + HCl was a more suitable leaching agent.

$${\text{MgCO}}_{{3}} + {\text{ 2 H}}^{ + } = {\text{ Mg}}^{{{2} + }} + {\text{ CO}}_{{2}} \uparrow + {\text{ H}}_{{2}} {\text{O}}$$
(1)
$${\text{3 OA }} + {\text{ Ca}}_{{3}} \left( {{\text{PO}}_{{4}} } \right)_{{2}} = {\text{ 3 Ca}}\left( {{\text{C}}_{{2}} {\text{O}}_{{4}} } \right)_{{}} \downarrow + {\text{ 2 H}}_{{3}} {\text{PO}}_{{4}}$$
(2)
$${\text{OA }} + {\text{ CaCO}}_{{3}} = {\text{ Ca}}\left( {{\text{C}}_{{2}} {\text{O}}_{{4}} } \right)_{{}} \downarrow + {\text{ H}}_{{2}} {\text{O }} + {\text{ CO}}_{{2}} \uparrow$$
(3)

4.1.2 PO4 3−-P leaching effect and changes in the phosphorus species distribution in BRC

Different leaching agents were used to acid leach MP and then leach BRC to dissolve PO43−-P from BRC ash. As shown in Fig. 1B, CK (H2O) had almost no effect on PO43−-P release from BRC, but other acids effectively improved the efficiency of PO43−-P leaching from BRC. Among them, OA + HCl showed the highest PO43−-P leaching level, with a concentration of 701 mg/L, and the PO43−-P leaching efficiency reached 98.2%. The PO43−-P leaching efficiency of OA (87.3%) was 13.4% higher than that of CA (72.9%), which is similar to the results of previous studies (Martinez et al. 2014). Typically, OA pKa1 (1.23) < CA pKa1 (3.15); the smaller pKa1 is, the larger the ionization constant, the easier it is to ionize H+, and the stronger the acidity. The PO43−-P leaching efficiency of HCl was 9.7% higher than that of H2SO4. HCl is more acidic than H2SO4 at the same H+ molar concentration, and thus, it dissolved more PO43−-P from BRC. Furthermore, the PO43−-P leaching efficiency of OA was higher than that of H2SO4, and these results were similar to the experimental results of Liang et al. (2019). Since the Ksp values of calcium oxalate and calcium sulfate are 2.32 × 10–9 and 4.93 × 10–5 (298.15 K), respectively, calcium oxalate precipitated more readily, which promoted acidolysis (Eq. (4)) and calcium phosphate (ACP) dissolution (Eq. (5)), leading to higher PO43−-P leaching efficiency. Therefore, the OA + HCl mixed acid showed the highest PO43−-P leaching efficiency.

$${\text{OA}} \rightleftharpoons {\text{2 COO}}^{ - } + {\text{2H}}^{ + }$$
(4)
$${\text{6 H}}^{ + } + {\text{ Ca}}_{{3}} \left( {{\text{PO}}_{{4}} } \right)_{{2}} \rightleftharpoons {\text{3 Ca}}^{{{2} + }} + {\text{2 H}}_{{3}} {\text{PO}}_{{4}}$$
(5)
$${\text{Ca}}^{{{2} + }} + {\text{ 2 COO}}^{ - } \rightleftharpoons {\text{Ca}}\left( {{\text{COO}}} \right)_{{2}} \downarrow$$
(6)

As shown in Fig. 1C, the TP content doubled after the carbonization of BR to BRC, which was consistent with the results described in Sect. 2.2.1. Carbonization treatment increased the phosphorus content. Furthermore, most of the organic phosphorus (OP) was converted into inorganic phosphorus (IP) in BR, indicating that orthophosphate monoester and pyrophosphate in BR were converted into orthophosphate by heating (Gang et al. 2016). After carbonization, phosphorus in BRC was mainly IP, and IP was mainly composed of apatite inorganic phosphorus (AP) and nonapatite inorganic phosphorus (NAIP), which is a similar composition to the phosphorus forms present in another sludge (Jin et al. 2017). After leaching BRC with acid, the NAIP content greatly decreased, and AP was completely dissolved by acid, indicating that the phosphorus involved in the reaction was mainly NAIP and AP and that AP was more easily leached (Zeng et al. 2021). After leaching BRC with the mixed acids OA + H2SO4 or OA + HCl, more than 96% of the phosphorus was dissolved, which exceeded the efficiencies of single acids.

4.1.3 Effect of leaching with different acids on NH4 +-N and PO4 3−-P recovery

The filtrate remaining after acid leaching of MP and BRC was used as the source of magnesium and phosphorus for MAP precipitation, and the process is shown in Eqs. (7), (8) and (9). The system must be alkaline (pH = 8.0–10) to form struvite precipitates (Gunay et al. 2008; Song et al. 2007). The recovery of NH4+-N and PO43−-P by different leaching agents is shown in Fig. 1D. The NH4+-N recovery of the treatment containing OA was over 64.0%. Among the systems tested, the recovery of NH4+-N in (OA-HCl)-MAP was most efficient at 86.9%, representing an increase of 53.6% compared with that of CK-MAP (33.3%). The NH4+-N concentration was 39.6 mg/L in (OA-HCl)-MAP. The NH4+-N recoveries of CA-MAP, H2SO4-MAP, and HCl-MAP were 30.3%, 33.3%, and 11.5%, respectively. Since a large amount of Ca2+ was dissolved after leaching BRC (see Fig. 1A), Ca2+ inhibited the formation of struvite. Corre et al. (2005) found that when the molar ratio of Ca/Mg was ≥ 1, no more crystalline struvite was formed, but a substance defined as amorphous calcium phosphate was formed. When OA is used, oxalate ions form precipitates with Ca2+, thus preventing inhibition of struvite formation by Ca2+. Therefore, OA did not exhibit Ca2+ leaching, as shown in Fig. 1A. In terms of PO43−-P recovery (Fig. 1E), the recovery of all leaching agents except for CA-MAP was greater than 95.0% because most phosphate radicals form phosphate precipitates under alkaline conditions, and OA-MAP, (OA-H2SO4)-MAP, and (OA-HCl)-MAP mostly form struvite precipitates. The recovery of PO43−-P in CA-MAP was low, perhaps because CA combined with the active sites of newly formed crystals and increased the supersaturation required for phosphate crystallization precipitation, which inhibited the crystallization process (Van and Valsami-Jones 2001). (OA-HCl)-MAP showed the best PO43−-P recovery of 98.8%, and the residual phosphate concentration was 9.10 mg/L. In summary, to ensure that the leaching agent maximized PO43−-P and Mg2+ leaching and reduced Ca2+ leaching and because (OA-HCl)-MAP exhibited the most efficient recovery of NH4+-N and PO43−-P, OA + HCl was used in subsequent experiments.

$${\text{Mg}}^{{{2} + }} + {\text{ NH}}_{{4}}^{ + } + {\text{PO}}_{{4}}^{{{3} - }} + {\text{6 H}}_{{2}} {\text{O}} \to {\text{MgNH}}_{{4}} {\text{PO}}_{{4}} \cdot{\text{6 H}}_{{2}} 0 \downarrow$$
(7)
$${\text{Mg}}^{{{2} + }} + {\text{ NH}}_{{4}}^{ + } + {\text{HPO}}_{{4}}^{{{2} - }} + {\text{6 H}}_{{2}} {\text{O}} \to {\text{MgNH}}_{{4}} {\text{PO}}_{{4}} \cdot{\text{6 H}}_{{2}} 0 \downarrow \, + {\text{H}}^{ + }$$
(8)
$${\text{Mg}}^{{{2} + }} + {\text{ NH}}_{{4}}^{ + } + {\text{H}}_{{2}} {\text{PO}}_{{4}}^{ - } + {\text{6 H}}_{{2}} {\text{O}} \to {\text{MgNH}}_{{4}} {\text{PO}}_{{4}} \cdot{\text{6 H}}_{{2}} 0 \downarrow \, + {\text{2H}}^{ + }$$
(9)

4.2 Optimized leaching procedure

As shown in Fig. 2A, with increasing leaching time, the Mg2+ leaching concentrations obtained with different L/S values first increased and then moderated, but L/S = 5 reached the highest point in 1 h. Greater amounts of MP (lower L/S values) consistently corresponded to a smaller increase in Mg2+ leaching. This is because Ca2+ was leached first and precipitated as calcium oxalate, part of which adhered to MP, reduced the contact area between H+ and MP and slowed Mg2+ leaching. However, for a given H+ concentration, a greater dosage of MP in the early stage of the reaction (smaller L/S) increased the contact area between H+ and MP, and more Mg2+ was dissolved. Due to the continuous formation of calcium oxalate, the concentration of leached Mg2+ tended to be constant. As shown in Fig. 2B, as the leaching time increased, calcium oxalate continued to form, and the Ca2+ concentration obtained with different L/S values also decreased. Therefore, considering the Mg2+ leaching efficiency and reaction cost, the optimal MP leaching time was 3 h with L/S = 10, which resulted in a Mg2+ leaching concentration of 264 mg/L and Ca2+ leaching concentration of 5.50 mg/L.

Fig. 2
figure 2

Effects of liquid-to-solid ratios (L/S) in the OA-HCl leaching agent and leaching time on leaching of Mg2+ A and Ca2+ B by MP

Under the optimal conditions for leaching MP with OA-HCl, i.e., a leaching time of 3 h and L/S = 10, the filtrate was leached first, and then BRC was leached. The results are shown in Fig. 3. As the leaching time increased, the leaching of Mg2+ and Ca2+ at different L/S values gradually decreased, while the leaching of PO43−-P basically did not change with time. The maximum leaching concentrations of PO43−-P, Mg2+, and Ca2+ were reached within 1 h, indicating that leaching was completed in a short time. As time passed, the leaching efficiency worsened. Therefore, to maximize the Mg2+ leaching efficiency and minimize the cost, the optimal leaching time was set to 1 h at L/S = 6.7; under these conditions, the leaching concentration of Mg2+ was 326 mg/L, that of Ca2+ was 8.20 mg/L, and that of PO43−-P was 1056 mg/L.

Fig. 3
figure 3

Effect of liquid-to-solid ratios (L/S) and leaching time for filtrate from leaching of BRC on leaching of A Mg2+, B PO43−-P, and C Ca2+

4.3 Simultaneous recovery of NH4 +-N and PO4 3−-P from biogas slurry

4.3.1 Further optimization of the NH4 +-N and PO4 3−-P recovery procedure

Under the optimal conditions for OA-HCl leaching of MP and BRC, the leaching filtrate, BRC and biogas slurry were subjected to MAP precipitation for 1 h at pH = 9. Different BRC dosages (before acid leaching) were set to determine the optimal BRC dosage for MAP precipitation. The molar ratios of Mg:N:P in the corresponding systems were 3.9:2.7:1.0, 2.6:4.0:1.0, 1.5:2.0:1.0, 1.1:1.2:1.0 and 0.9:1.1:1.0 after adding 2.5 g/L, 5 g/L, 10 g/L, 15 g/L and 20 g/L BRC, respectively. Figure 4A, B show that the NH4+-N recovery increased with increasing amounts of BRC added, and the recovery no longer changed when BRC addition reached a particular level. The PO43−-P recovery first rose and then fell. When 15 g/L BRC was added, the efficiency for the recovery of NH4+-N increased from 41.6% to 94.6%, and that for PO43−-P was 98.3%. At this time, the residual concentration of NH4+-N reached its lowest value of 16.3 mg/L, and the residual concentration of PO43−-P was 18.9 mg/L. Further increases in dosage made little contribution to the PO43−-P and NH4+-N recovery efficiencies; in contrast, it reduced the PO43−-P recovery and increased the concentration of residual PO43−-P. The Mg:N:P molar ratio showed that as more BRC was added, the PO43−-P concentration in the system increased, and the Mg:N:P molar ratio approached 1:1:1, which led to formation of more struvite. Therefore, the NH4+-N recovery continued to increase. However, when the dosage was increased to 15 g/L, the Mg2+ content was insufficient. The level of residual PO43−-P in solution was not sufficient for struvite formation. The NH4+-N recovery no longer increased, and the residual PO43−-P concentration increased. This phenomenon is consistent with the results of a previous investigation (Tao et al. 2009; Xu et al. 2018). Excessive BRC will waste resources, and a high residual P concentration will increase the difficulty of subsequent processing; therefore, the best BRC dosage (before acid leaching) was 15 g/L (Mg:N:P molar ratio of 1.1:1.2:1.0).

Fig. 4
figure 4

Effects of BRC dosage (before acid leaching), pH, and reaction time on the efficiencies of NH4+-N and PO43−-P recovery. A BRC dosage-NH4+-N; B BRC dosage-PO43−-P; C pH-NH4+-N; D pH-PO43−-P; E Time-NH4+-N; F Time-PO43−-P

With an optimal BRC dosage (before acid leaching) of 15 g/L and a reaction time of 1 h, different pH values were used to obtain the optimal pH for MAP precipitation. pH is a key factor affecting the formation of struvite in the system (Lin et al. 2017). As shown in Fig. 4C, D, when the pH was 8.5–9.5, NH4+-N recovery increased from 90.1% to 96.2% with increasing pH, and PO43−-P recovery increased from 94.7% to 98.9%. When the pH was 10.5, NH4+-N recovery dropped to 85%, but PO43−-P recovery increased to 99.7%. This result is similar to the conclusion of Booker et al. (1999), who found that when the pH value was increased from 8.2 to 9.5, the MAP precipitation efficiency increased from 40.0% to 80.0%. At higher pH, more Mg2+ formed Mg(OH)2, and this process competed with MAP precipitation for Mg2+. In addition, according to solubility data, when the pH is greater than 9.5, Mg3(PO4)2 precipitates are more likely to form, which is not conducive to MAP precipitation (Zhou and Wu 2012). As the pH was increased further, PO43− more easily formed salt precipitates with metal ions. Therefore, since the NH4+-N and PO43−-P recoveries were nearly optimal, the reaction pH should be controlled at an optimal value of 9.5. This result was consistent with the experimental results of Shaddel et al. (2020) and Wang et al. (2018a; b).

With the optimal BRC dosage (before acid leaching) of 15 g/L and pH = 9.5, different reaction times were used to determine the optimal reaction time for MAP precipitation. In Fig. 4E and F, the NH4+-N recovery reached 96.4% when the reaction time was 6 h, but with extension of the reaction time, the NH4+-N recovery increased slowly. The PO43−-P recovery increased from 99.0% to 99.7% with increasing reaction time up to 24 h. Struvite formation was generally completed within a short time (Lin et al. 2017). The subsequent increases in NH4+-N and PO43−-P recoveries may have been due to the loose and porous structure and high specific surface area of the functionalized BRC, which physisorbed NH4+-N and PO43−-P. However, as the functionalized BRC adsorption level reached equilibrium, the NH4+-N and PO43−-P recoveries remained unchanged. Therefore, when the reaction time exceeded 6 h, NH4+-N recovery was basically unchanged, and when the reaction time exceeded 24 h, PO43−-P recovery was basically unchanged. Nevertheless, when the reaction time is excessive, more power is consumed. Considering the recoveries of NH4+-N and PO43−-P and the cost of power, a reaction time of 6 h was chosen

4.3.2 Technical advantages of recovering NH4 +-N and PO4 3−-P

In summary, the optimal parameters for the acid leaching of MP and BRC to recover NH4+-N and PO43−-P nutrients from piggery biogas should be set as follows: a mixed acid with 0.5 mol/L OA and 0.5 mol/L HCl was used as the leaching agent. The MP was first leached to dissolve Mg2+, and the leaching time was 3 h with L/S = 10. After leaching, the filtrate was then used to leach BRC and dissolve PO43−-P, and the leaching time was 1 h with L/S = 6.7. Finally, filtrate and leaching-functionalized BRC were used for MAP precipitation and NH4+-N and PO43−-P recovery from biogas slurry. BRC dose was 15 g/L (the Mg:N:P molar ratio was 1.1:1.2:1), the reaction pH was 9.5, and the reaction time was 6 h. After running under these optimal conditions, the residual concentration of PO43−-P was 7.41 g/L (TP 7.80 g/L), the PO43−-P recovery was 99.3%, the residual concentration of NH4+-N was 11.1 g/L, and the NH4+-N recovery was 96.4%. Our technology efficiently recovered NH4+-N and PO43−-P from biogas slurry and biogas residue. At the same time, we also found that our technology improved the water quality (NH4+-N and TP) of piggery biogas slurry to meet the discharge standards in GB 18596-2001, "Fouling Standards for Pollutants in the Livestock Breeding Industry" (80 mg/L NH4+-N, 8 mg/L TP). This provides the possibility of replacing advanced treatment units for pig farm wastewater in the future.

The NH4+-N and PO43−-P recovery efficiencies in this study were compared with those of other researchers in Tables 4 and 5, and they were significantly higher than those of other researchers, indicating that the use of magnesium and phosphorus sources for MAP precipitation through the acid leaching of MP and BRC maximized the NH4+-N and PO43−-P recovery efficiencies from piggery biogas slurry and realized reuse of waste resources.

Table 4 Basic physical and chemical properties of BR and BRC
Table 5 Comparison of other studies on the recovery of NH4+-N and PO43−-P from piggery wastewater

4.4 Analysis of the mechanism

4.4.1 FTIR analysis

The FTIR spectral changes of different functionalized BRC before and after the MAP reaction are shown in Fig. 5B. The 3450 cm−1 peak is attributed to the O–H stretching vibration of hydroxyls (Jung et al. 2015). Comparing the CK-BRC in Fig. 5A, the peak at 3450 cm−1 for BRC with different treatments became significantly weaker after the recovery reaction. Relevant studies have shown that -OH on the surface of carbon-based materials can facilitate the adsorption of NH4+-N and PO43−-P (Wang et al. 2018a; b), indicating that -OH participates in the adsorption of NH4+-N and PO43−-P. The broad band at 3200 cm−1–2200 cm−1 for (OA + HCl)-MAP was caused by an N–H stretching vibration; when an amino group is transformed into an ammonium ion, the N–H stretching frequency is redshifted. Furthermore, a new peak appeared at 1430 cm−1, which is attributed to an N–H bending vibration; this shows that ammonium salts were formed in the reaction. The peak near 2650 cm−1 (Fig. 5A) was generated by a C = O stretching vibration, and the peaks near 1320 and 780 cm−1 were generated by C-H bending vibrations in aromatic functional groups. Furthermore, it was found that peaks exhibited after the acid leaching treatment were stronger than those of CK, indicating that acid leaching increased the degree of aromatization for BRC. However, the peaks for each treatment became weaker after NH4+-N and PO43−-P were recovered in Fig. 5B, indicating that C = O and C-H bonds participated in the adsorption of NH4+-N and PO43−-P. There was a characteristic peak for PO43− near 1030 cm−1. The peak almost disappeared after the acid leaching treatment in Fig. 5A, but the peak was obviously stronger after the recovery of NH4+-N and PO43−-P in Fig. 5B, especially for the (OA + HCl)-MAP treatment. This shows that the acid leaching treatment released large amounts of phosphorus, but after BRC adsorption and MAP precipitation, the phosphorus in the biogas slurry and the acid leaching solution was reabsorbed and precipitated in the material. These results are consistent with those of the abovementioned acid leaching experiment and NH4+-N and PO43−-P recovery experiment. In conclusion, -OH, C = O and C-H functional groups played important roles in the adsorption of NH4+-N and PO43−-P by BRC. NH4+-N and PO43−-P in (OA + HCl)-MAP may be precipitated as ammonium and phosphorus salts in BRC materials.

Fig. 5
figure 5

A FTIR spectral changes of BRC before and after acid leaching functionalization. B FTIR spectral changes of functionalized BRC before and after MAP reaction

4.4.2 SEM–EDX analysis

As shown in Fig. 6, only OA-MAP (Fig. 6B), (OA + H2SO4)-MAP (Fig. 6F) and (OA + HCl)-MAP (Fig. 6G) precipitated crystals with inclined square crystal structures typical of struvite (Doyle et al. 2003). Among them, (OA + H2SO4)-MAP and (OA + HCl)-MAP contained more inclined square crystals than OA-MAP, and there was less adhesion of fine amorphous particles to the surface. In other treatments, most of the CK-MAP (Fig. 6A) had a loose carbon structure, and small amounts of amorphous loose particles were attached to the carbon structure and pores, indicating that almost no struvite was formed in the reaction. Most of the CA-MAP (Fig. 6C) formed small particles and clumps, which may react to form calcium citrate clumps. H2SO4-MAP (Fig. 6D) and HCl-MAP (Fig. 6E) showed large numbers of rough and loose amorphous masses, which are typical structures for hydroxyapatite and calcium phosphate (ACP). No rhombic crystal structure appeared, indicating that H2SO4-MAP and HCl-MAP treatments did not form struvite precipitates but instead formed large amounts of amorphous ACP precipitates. Based on these results and analysis of the EDX results in Fig. 6G, the mass percentages of the main constituent elements in the recovered (OA + HCl)-MAP product were C: 20.2%, N: 7.9%, O: 36.7%, Mg: 14.3%, P: 19.6%, S: 0.2%, Al: 0.1%, K: 0.9%, and Ca: 0.1%. The molar ratio Mg:N:P was 1.04:1:1.12, which is close to the 1:1:1 Mg:N:P molar ratio seen for struvite. This shows that (OA + HCl)-MAP treatment effectively recovered NH4+-N and PO43−-P nutrients from biogas slurry, thereby forming high-quality, slow-release fertilizer struvite (Li and Zhao 2003).

Fig. 6
figure 6

SEM images of precipitated products recovered from different acid leaching treatments and EDX spectrum resulting after (OA + HCl)-MAP treatment. A CK-MAP; B OA-MAP; C CA-MAP; D H2SO4-MAP; E HCl-MAP; F (OA + H2SO4)-MAP; G (OA + HCl)-MAP; and (SEM + EDX) image.

4.4.3 XRD analysis

XRD analysis is useful for studying the properties of struvite (Doyle et al. 2003). Therefore, we further verified the main components of the precipitated crystals. XRD analyses were performed with the precipitated products of various acid leaching treatments. The XRD patterns in Fig. 7 show that the characteristic XRD diffraction peaks changed significantly with different acid leaching treatments. The main mineral phases in H2SO4-MAP and HCl-MAP were quartz, calcite, and dolomite, but there was almost no struvite. Furthermore, H2SO4-MAP also contained a small amount of gypsum, CaSO4·2H2O. The principal mineral phases in (OA + H2SO4)-MAP and (OA + HCl)-MAP were struvite, partly calcium oxalate and magnesium oxalate. On the one hand, this verified the experimental results for NH4+-N and PO43−-P recovery efficiencies with different acid leaching treatments (Sect. 4.1.3). Since a large amount of guano stone was formed in (OA + H2SO4)-MAP and (OA + HCl)-MAP, most NH4+-N was recovered by functionalized BRC in the form of ammonium salt crystals. Therefore, the NH4+-N recovery efficiencies for the two treatments were more than 50% higher than those of H2SO4-MAP and HCl-MAP. On the other hand, this also verified that (OA + HCl)-MAP effectively recovered NH4+-N and PO43−-P nutrients from the biogas slurry, formed struvite as a slow-release fertilizer and then formed biochar-based slow-release N-P fertilizer.

Fig. 7
figure 7

XRD spectra of MAP precipitated products recovered from different acid leaching treatments

4.4.4 Mechanism of functionalized BRC recovery of NH4 +-N and PO4 3−-P

According to the FTIR analyses, the -OH peak weakened significantly after the (OA + HCl)-MAP treatment, and new peaks indicated that NH4+-N and PO43−-P adsorbed on the surface of (OA + HCl)-BRC through the action of functional groups. SEM–EDS results showed that there were many inclined square crystals with the typical struvite crystal structure in (OA + HCl)-MAP, and the Mg:N:P molar ratio of the inclined square crystals was close to that of struvite. Furthermore, XRD confirmed that the main mineral phase in (OA + HCl)-MAP was struvite, parts of which were calcium oxalate and magnesium oxalate; most of the NH4+-N and PO43−-P in the solution were adsorbed onto the surface of (OA + HCl)-BRC through chemical precipitation. The combination of oxalate and calcium ions formed calcium oxalate precipitates, which weakened the inhibitory effect of Ca2+ on MAP precipitation. Based on characterization and analytical results from FTIR, SEM–EDS, and XRD, a mechanism was proposed for the (OA + HCl)-BRC recovery of NH4+-N and PO43−-P from biogas slurry. As shown in Fig. 8, the recovery of NH4+-N and PO43−-P by (OA + HCl)-BRC mainly included -OH, C = O and C-H functional group bonding and precipitation of magnesium ammonium phosphate (NH4MgPO4·6H2O).

Fig. 8
figure 8

Mechanism of functionalized BRC recovery of NH4+-N and PO43−-P nutrients from biogas slurry

In addition, the experiment on the pure adsorption of NH4+-N and PO43−-P from biogas slurry was carried out by simply adding (OA + HCl)-BRC to biogas slurry; the pH was not adjusted, but the other conditions were the optimized ones. The results showed that the efficiency of (OA + HCl)-BRC for the adsorption of NH4+-N was 7.1%, and the efficiency for the adsorption of PO43−-P was 10.2%. Table A.1 demonstrates that the BET surface area (SBET) and pore volume (PV) of BRC significantly increased after different acid leaching processes, which is helpful for recovering NH4+-N and PO43−-P from biogas slurry by physical adsorption. Therefore, in the entire (OA + HCl)-BRC system for the recovery of NH4+-N and PO43−-P, 89.3% NH4+-N and 89.1% PO43−-P were recovered through chemical precipitation, and 7.1% NH4+-N and 10.2% PO43−-P were recovered through physisorption. This shows that functionalized BRC recovered NH4+-N and PO43−-P through chemical precipitation and cooperated with biochar-based physisorption to enhance the recovery of NH4+-N and PO43−-P from biogas slurry. It is expected that the results of the present study will provide innovative technology for the practical utilization of faecal sewage resources in large-scale pig farms.

5 Conclusion

In this study, which used the technology of acid-leaching BRC to recover NH4+-N and PO43−-P from biogas slurry, the main findings are as follows: the mixed acid OA-HCl is the best leaching agent and can extract the maximum concentrations of Mg2+ and PO43−-P from MP and BRC and reduce the impact of Ca2+ on struvite formation. Under the optimal conditions for OA-HCl leaching and MAP precipitation, 99.3% of PO43−-P and 96.4% of NH4+-N can be recovered, indicating a substantial nutrient recovery effect. The acid-leaching functionalized BRC recovers most NH4+-N and PO43−-P through chemical precipitation, and the functional groups of functionalized BRC strengthen recovery, eventually forming a biochar-based slow-release N-P fertilizer rich in struvite. The main innovation of this paper is the use of functionalized P-rich biogas residue waste to treat N-rich biogas slurry, which cooperate to recover NH4+-N and PO43−-P and form biochar-based slow-release N-P fertilizer; the results can be applied to construct innovative technologies for coprocessing livestock and poultry breeding waste and utilizing high-value resources.