Zhang Quanyi () (852 – April 29, 926), né Zhang Juyan () or Zhang Yan (), known as Zhang Zongshi () during Later Liang, courtesy name Guowei (), formally Prince Zhongsu of Qi (), was a late Tang Dynasty warlord who later was a senior official during the succeeding Later Liang and Later Tang. He was credited for rebuilding the city of Luoyang from utter destruction from the warfares in the late Tang period into a prosperous city.

During Tang Dynasty

Background and service under Huang Chao

Zhang Quanyi was born in 852, during the reign of Emperor Xuānzong. His biography in the History of the Five Dynasties indicated that he was originally named Zhang Juyan, and his biography in the New History of the Five Dynasties indicated that he was originally named Zhang Yan. His family was from Linpu (臨濮, in modern Heze, Shandong), and both his grandfather Zhang Lian () and father Zhang Cheng () were farmers. Zhang Quanyi himself served as a farm inspector for the Linpu County government, but in his service was often insulted by the county magistrate. Therefore, when, late in the Qianfu era (874-879) of Emperor Xuānzong's grandson Emperor Xizong, when the region was overrun by the major agrarian rebel Huang Chao, Zhang joined Huang's army. After Huang captured the Tang imperial capital Chang'an and forced Emperor Xizong to flee to Chengdu around the new year 881, Huang established a new state of Qi with himself as emperor. Zhang served in Huang's government as the minister of civil service affairs (吏部尚書, Libu Shangshu) and the director of transportation.

Zhang Quanyi

Service under Zhuge Shuang and Zhuge Zhongfang

After Huang Chao was eventually defeated by Tang forces and chased out of Chang'an, Zhang Quanyi joined the army of the Tang general Zhuge Shuang the military governor (Jiedushi) of Heyang Circuit (河陽, headquartered in modern Jiaozuo, Henan). He distinguished himself serving under Zhuge, and Zhuge eventually made him the prefect of Ze Prefecture (澤州, in modern Jincheng, Shanxi).

Zhang Quanyi

Zhuge died in 886. Zhang and another officer of Zhuge's, Liu Jing (), supported Zhuge's son Zhuge Zhongfang () as acting military governor. Liu, however, controlled the governance of the circuit, drawing resentment from other officers. Late in 886, Liu became suspicious of the officer Li Hanzhi, and he decided to use Luoyang as a base to launch a surprise attack on Li's base at Minchi (澠池, in modern Luoyang). Li defeated him, however, forcing him to abandon Luoyang and flee north of the Yellow River back to the circuit capital Heyang. Li gave chase, and was about to chase the Yellow River, when Liu sent Zhang to try to stop Li. However, as Zhang also resented Liu's hold on the circuit governance, he instead joined Li, and they jointly attacked Heyang but could not capture it. They then withdrew to Huai Prefecture (懷州, in modern Luoyang).

Zhang Quanyi

As this Heyang Circuit internecine confrontation was going on, the former Tang general Qin Zongquan, who had declared himself emperor at Fengguo Circuit (奉國, headquartered in modern Zhumadian, Henan), sent his general Sun Ru toward Heyang, and Sun soon captured the city. Zhuge Zhongfang fled to Xuanwu Circuit (宣武, headquartered in modern Kaifeng, Henan). Sun thereafter claimed the title of military governor of Heyang. However, Zhang and Li occupied Huai and Ze Prefectures, respectively, and resisted Sun. After Qin thereafter suffered a major defeat at the hands of Xuanwu's military governor Zhu Quanzhong, Sun withdrew from Heyang. Zhang and Li rejoined forces, with Li taking over Heyang and Zhang taking over Luoyang; they then jointly sought aid from the major warlord Li Keyong the military governor of Hedong Circuit (河東, headquartered in modern Taiyuan, Shanxi). Li Keyong sent his officer An Jinjun () to take over Ze Prefecture as prefect and to aid Li Hanzhi and Zhang; he also commissioned Li Hanzhi as the military governor of Heyang and Zhang as the mayor of Henan Municipality (河南, i.e., Luoyang).