The task of related work generation aims to generate a comprehensive survey of related research topics automatically, saving time and effort for authors. Existing methods simplify this task by using human-annotated references in a large-scale scientific corpus as information sources, which is time-and cost-intensive. To this end, we propose a Unified Reference Retrieval and Related Work Generation Model (UR 3 WG), which combines reference retrieval and related work generation processes in a unified framework based on the large language model (LLM). Specifically, UR 3 WG first leverages the world knowledge of LLM to extend the abstract and generate the query for the subsequent retrieval stage. Then a lexicon-enhanced dense retrieval is proposed to search relevant references, where an importance-aware representation of the lexicon is introduced. We also propose multi-granularity contrastive learning to optimize our retriever. Since this task is not simply summarizing the main points in references, it should analyze the complex relationships and present them logically. We propose an instruction-tuning method to guide LLM to generate related work. Extensive experiments on two wide-applied datasets demonstrate that our UR 3 WG outperforms the state-of-the-art baselines in both generation and retrieval metrics.