Derbyshire's Wayne Madsen batted for for just 59 runs to help his side reach 231-7 on the penultimate day against Surrey, a lead of 161.